@intellectual-frontiers/docs 0.0.0-stage → 0.2.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.
- package/LICENSE +75 -0
- package/README.md +8 -2
- package/dist/build.d.ts +63 -0
- package/dist/build.js +103 -0
- package/dist/check.d.ts +63 -0
- package/dist/check.js +54 -0
- package/dist/cli.d.ts +51 -0
- package/dist/cli.js +165 -0
- package/dist/config.d.ts +196 -0
- package/dist/config.js +229 -0
- package/dist/emit/html.d.ts +67 -0
- package/dist/emit/html.js +338 -0
- package/dist/emit/markdown.d.ts +19 -0
- package/dist/emit/markdown.js +124 -0
- package/dist/emit/search.d.ts +15 -0
- package/dist/emit/search.js +29 -0
- package/dist/extract/api.d.ts +74 -0
- package/dist/extract/api.js +261 -0
- package/dist/extract/specs.d.ts +141 -0
- package/dist/extract/specs.js +208 -0
- package/dist/highlight.d.ts +22 -0
- package/dist/highlight.js +77 -0
- package/dist/layered.d.ts +94 -0
- package/dist/layered.js +14 -0
- package/dist/lens/guides.d.ts +23 -0
- package/dist/lens/guides.js +49 -0
- package/dist/lens/layered.d.ts +16 -0
- package/dist/lens/layered.js +354 -0
- package/dist/lens/program.d.ts +23 -0
- package/dist/lens/program.js +124 -0
- package/dist/lens/releases.d.ts +10 -0
- package/dist/lens/releases.js +37 -0
- package/dist/lens.d.ts +30 -0
- package/dist/lens.js +1 -0
- package/dist/links.d.ts +96 -0
- package/dist/links.js +182 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +12 -0
- package/dist/markdown.d.ts +43 -0
- package/dist/markdown.js +301 -0
- package/dist/mod.d.ts +32 -0
- package/dist/mod.js +9 -0
- package/dist/model.d.ts +159 -0
- package/dist/model.js +39 -0
- package/dist/pages/api.d.ts +41 -0
- package/dist/pages/api.js +162 -0
- package/dist/pages/areas.d.ts +39 -0
- package/dist/pages/areas.js +119 -0
- package/dist/pages/overview.d.ts +24 -0
- package/dist/pages/overview.js +283 -0
- package/dist/pages/specs.d.ts +31 -0
- package/dist/pages/specs.js +358 -0
- package/dist/site.d.ts +31 -0
- package/dist/site.js +288 -0
- package/dist/sources.d.ts +53 -0
- package/dist/sources.js +159 -0
- package/dist/theme/site.css +275 -0
- package/dist/theme/site.js +174 -0
- package/dist/tsdoc.d.ts +67 -0
- package/dist/tsdoc.js +94 -0
- package/ifc-docs.mjs +4 -0
- package/package.json +66 -4
- package/src/build.ts +117 -0
- package/src/check.ts +84 -0
- package/src/cli.ts +145 -0
- package/src/config.ts +370 -0
- package/src/emit/html.ts +398 -0
- package/src/emit/markdown.ts +129 -0
- package/src/emit/search.ts +38 -0
- package/src/extract/api.ts +297 -0
- package/src/extract/specs.ts +299 -0
- package/src/highlight.ts +98 -0
- package/src/layered.ts +102 -0
- package/src/lens/guides.ts +70 -0
- package/src/lens/layered.ts +341 -0
- package/src/lens/program.ts +137 -0
- package/src/lens/releases.ts +54 -0
- package/src/lens.ts +34 -0
- package/src/links.ts +234 -0
- package/src/main.ts +12 -0
- package/src/markdown.ts +320 -0
- package/src/mod.ts +53 -0
- package/src/model.ts +154 -0
- package/src/pages/api.ts +179 -0
- package/src/pages/areas.ts +133 -0
- package/src/pages/overview.ts +276 -0
- package/src/pages/specs.ts +366 -0
- package/src/site.ts +285 -0
- package/src/sources.ts +157 -0
- package/src/theme/site.css +275 -0
- package/src/theme/site.js +174 -0
- package/src/tsdoc.ts +131 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Finding } from "./check.js";
|
|
2
|
+
import { type About, type AboutArea, type PackageSource } from "./config.js";
|
|
3
|
+
/** A package read: where it is, its `About`, and the file that holds it, from the root. */
|
|
4
|
+
export interface Package {
|
|
5
|
+
/** Its folder, from the root: `""` for the root itself. */
|
|
6
|
+
readonly dir: string;
|
|
7
|
+
/** Its name in the site's addresses. */
|
|
8
|
+
readonly slug: string;
|
|
9
|
+
/** Its `About`. */
|
|
10
|
+
readonly about: About;
|
|
11
|
+
/** The file its `About` is written in, from the root: its `about.ts`, or the configuration. */
|
|
12
|
+
readonly file: string;
|
|
13
|
+
}
|
|
14
|
+
/** An area of a package, with the package it is in. */
|
|
15
|
+
export interface Area extends AboutArea {
|
|
16
|
+
/** The package. */
|
|
17
|
+
readonly pkg: Package;
|
|
18
|
+
/** The folder of its first entry point, from the root: the files of the area. */
|
|
19
|
+
readonly dir: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Whether a file, from the root, is inside a folder, from the root (`""` holds everything).
|
|
23
|
+
*
|
|
24
|
+
* @param dir - the folder
|
|
25
|
+
* @param file - the file
|
|
26
|
+
*/
|
|
27
|
+
export declare const inside: (dir: string, file: string) => boolean;
|
|
28
|
+
/**
|
|
29
|
+
* A package's `About`: the value its configuration gives, or the one its `about.ts` exports.
|
|
30
|
+
*
|
|
31
|
+
* @param root - the repository's root
|
|
32
|
+
* @param src - the package
|
|
33
|
+
* @param configFile - the configuration's file, from the root, which holds an `About` value
|
|
34
|
+
* @param found - where findings go
|
|
35
|
+
*/
|
|
36
|
+
export declare function readPackage(root: string, src: PackageSource, configFile: string, found: Finding[]): Promise<Package | undefined>;
|
|
37
|
+
/** The areas of the packages, in order. */
|
|
38
|
+
export declare function areasOf(packages: readonly Package[]): Area[];
|
|
39
|
+
/**
|
|
40
|
+
* What a package's `about` says that the code does not hold.
|
|
41
|
+
*
|
|
42
|
+
* @param root - the repository's root
|
|
43
|
+
* @param pkg - the package
|
|
44
|
+
* @param lintRules - the folder of the lint rules, from the root; a lint rule is not checked without it
|
|
45
|
+
*/
|
|
46
|
+
export declare function checkAbout(root: string, pkg: Package, lintRules?: string): Finding[];
|
|
47
|
+
/**
|
|
48
|
+
* The TypeScript files of an area's folder that document it: everything but tests and generated files.
|
|
49
|
+
*
|
|
50
|
+
* @param root - the repository's root
|
|
51
|
+
* @param dir - the area's folder, from the root
|
|
52
|
+
*/
|
|
53
|
+
export declare function areaFiles(root: string, dir: string): string[];
|
package/dist/sources.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx, extraExtensions, ignoreCase) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
if (extraExtensions) {
|
|
4
|
+
for (var extension in extraExtensions) {
|
|
5
|
+
var suffix = path.slice(-extension.length);
|
|
6
|
+
if (suffix === extension || ignoreCase && suffix.toLowerCase() === extension.toLowerCase()) {
|
|
7
|
+
var output = extraExtensions[extension];
|
|
8
|
+
return output === extension ? path : path.slice(0, -extension.length) + output;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
13
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return path;
|
|
17
|
+
};
|
|
18
|
+
// Spec: 0001-docs FR-001
|
|
19
|
+
/**
|
|
20
|
+
* The packages a site is made from (commons 0011-documentation FR-004, FR-005, FR-027), each read from its `about.ts` or from the
|
|
21
|
+
* `About` value its configuration gives, and the findings of holding an `about` to the code: a folder, an entry point or an example that
|
|
22
|
+
* does not exist, a command that is not a script of the package, a rule enforced by a test, a lint rule or a compiler option that does not
|
|
23
|
+
* exist.
|
|
24
|
+
*
|
|
25
|
+
* @module
|
|
26
|
+
*/
|
|
27
|
+
import { absurd } from "@intellectual-frontiers/core";
|
|
28
|
+
import { fs, path } from "@intellectual-frontiers/system";
|
|
29
|
+
import { isAbout, under } from "./config.js";
|
|
30
|
+
/**
|
|
31
|
+
* Whether a file, from the root, is inside a folder, from the root (`""` holds everything).
|
|
32
|
+
*
|
|
33
|
+
* @param dir - the folder
|
|
34
|
+
* @param file - the file
|
|
35
|
+
*/
|
|
36
|
+
export const inside = (dir, file) => dir === "" || file.startsWith(`${dir}/`);
|
|
37
|
+
/**
|
|
38
|
+
* A package's `About`: the value its configuration gives, or the one its `about.ts` exports.
|
|
39
|
+
*
|
|
40
|
+
* @param root - the repository's root
|
|
41
|
+
* @param src - the package
|
|
42
|
+
* @param configFile - the configuration's file, from the root, which holds an `About` value
|
|
43
|
+
* @param found - where findings go
|
|
44
|
+
*/
|
|
45
|
+
export async function readPackage(root, src, configFile, found) {
|
|
46
|
+
const { dir, slug } = src;
|
|
47
|
+
if (src.about.kind === "value")
|
|
48
|
+
return { dir, slug, about: src.about.value, file: configFile };
|
|
49
|
+
const where = src.about.file;
|
|
50
|
+
const file = path.join(root, where);
|
|
51
|
+
if (!fs.existsSync(file)) {
|
|
52
|
+
found.push({ where, problem: { kind: "no-about" } });
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
const mod = await import(__rewriteRelativeImportExtension(path.toFileUrl(file).href));
|
|
57
|
+
const about = typeof mod === "object" && mod !== null && "about" in mod ? mod.about : undefined;
|
|
58
|
+
if (!isAbout(about)) {
|
|
59
|
+
found.push({ where, problem: { kind: "no-about" } });
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
return { dir, slug, about, file: where };
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
found.push({ where, problem: { kind: "import-failed", error: e instanceof Error ? e.message : String(e) } });
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** The areas of the packages, in order. */
|
|
70
|
+
export function areasOf(packages) {
|
|
71
|
+
return packages.flatMap((pkg) => (pkg.about.areas ?? []).map((a) => ({ ...a, pkg, dir: under(pkg.dir, a.folder ?? (a.entryPoints[0] ?? "").split("/").slice(0, -1).join("/")) })));
|
|
72
|
+
}
|
|
73
|
+
/** The scripts of a package's `package.json`. */
|
|
74
|
+
function scriptsOf(root, dir) {
|
|
75
|
+
try {
|
|
76
|
+
const pkg = JSON.parse(fs.readTextFileSync(path.join(root, under(dir, "package.json"))));
|
|
77
|
+
const scripts = typeof pkg === "object" && pkg !== null && "scripts" in pkg ? pkg.scripts : undefined;
|
|
78
|
+
return new Set(typeof scripts === "object" && scripts !== null ? Object.keys(scripts) : []);
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return new Set();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** Whether what a rule names as its enforcer exists, and how to name it in a finding. */
|
|
85
|
+
function enforcerExists(root, pkg, e, lintRules) {
|
|
86
|
+
switch (e.kind) {
|
|
87
|
+
case "test":
|
|
88
|
+
return [fs.existsSync(path.join(root, pkg.dir, e.file)), e.file];
|
|
89
|
+
case "lint":
|
|
90
|
+
return [lintRules === undefined || fs.existsSync(path.join(root, lintRules, `${e.rule}.ts`)), `the lint rule ${e.rule}`];
|
|
91
|
+
case "compiler": {
|
|
92
|
+
const config = ["tsconfig.json", "../tsconfig.json"].map((f) => path.join(root, pkg.dir, f)).filter((f) => fs.existsSync(f));
|
|
93
|
+
return [config.some((f) => fs.readTextFileSync(f).includes(`"${e.option}"`)), `the compiler option ${e.option}`];
|
|
94
|
+
}
|
|
95
|
+
case "review":
|
|
96
|
+
return [true, "review"];
|
|
97
|
+
default:
|
|
98
|
+
return absurd(e);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* What a package's `about` says that the code does not hold.
|
|
103
|
+
*
|
|
104
|
+
* @param root - the repository's root
|
|
105
|
+
* @param pkg - the package
|
|
106
|
+
* @param lintRules - the folder of the lint rules, from the root; a lint rule is not checked without it
|
|
107
|
+
*/
|
|
108
|
+
export function checkAbout(root, pkg, lintRules) {
|
|
109
|
+
const where = pkg.file;
|
|
110
|
+
const found = [];
|
|
111
|
+
const at = (rel) => fs.existsSync(path.join(root, pkg.dir, rel));
|
|
112
|
+
for (const f of pkg.about.folders ?? [])
|
|
113
|
+
if (!at(f.path))
|
|
114
|
+
found.push({ where, problem: { kind: "folder-missing", folder: f.path } });
|
|
115
|
+
const scripts = scriptsOf(root, pkg.dir);
|
|
116
|
+
for (const c of pkg.about.commands ?? []) {
|
|
117
|
+
const script = /^bun run ([\w:.-]+)/.exec(c.run)?.[1];
|
|
118
|
+
if (script !== undefined && !scripts.has(script))
|
|
119
|
+
found.push({ where, problem: { kind: "command-missing", command: c.run } });
|
|
120
|
+
}
|
|
121
|
+
for (const r of pkg.about.rules ?? []) {
|
|
122
|
+
for (const e of r.enforcedBy) {
|
|
123
|
+
const [ok, name] = enforcerExists(root, pkg, e, lintRules);
|
|
124
|
+
if (!ok)
|
|
125
|
+
found.push({ where, problem: { kind: "enforcer-missing", enforcer: name } });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
const examples = [...(pkg.about.examples ?? []), ...(pkg.about.areas ?? []).flatMap((a) => a.examples ?? [])];
|
|
129
|
+
for (const x of examples)
|
|
130
|
+
if (!at(x.file))
|
|
131
|
+
found.push({ where, problem: { kind: "example-missing", file: x.file } });
|
|
132
|
+
for (const a of pkg.about.areas ?? []) {
|
|
133
|
+
for (const e of a.entryPoints)
|
|
134
|
+
if (!at(e))
|
|
135
|
+
found.push({ where, problem: { kind: "entry-point-missing", file: e } });
|
|
136
|
+
}
|
|
137
|
+
return found;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* The TypeScript files of an area's folder that document it: everything but tests and generated files.
|
|
141
|
+
*
|
|
142
|
+
* @param root - the repository's root
|
|
143
|
+
* @param dir - the area's folder, from the root
|
|
144
|
+
*/
|
|
145
|
+
export function areaFiles(root, dir) {
|
|
146
|
+
const out = [];
|
|
147
|
+
const walk = (rel) => {
|
|
148
|
+
const entries = [...fs.readDirSync(path.join(root, rel))].sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
149
|
+
for (const e of entries) {
|
|
150
|
+
const child = under(rel, e.name);
|
|
151
|
+
if (e.isDirectory && e.name !== "node_modules" && !e.name.startsWith("."))
|
|
152
|
+
walk(child);
|
|
153
|
+
else if (e.isFile && e.name.endsWith(".ts") && !e.name.includes(".test.") && !e.name.includes(".auto."))
|
|
154
|
+
out.push(child);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
walk(dir);
|
|
158
|
+
return out;
|
|
159
|
+
}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
/* The look of commons' documentation (commons 0011-documentation FR-017, FR-034): neutral, the text people read on white (or on near-black
|
|
2
|
+
in the dark scheme, which follows the reader's system and can be set with the button), the navigation on a light grey, thin borders, system
|
|
3
|
+
fonts. Every colour is a token here. */
|
|
4
|
+
:root {
|
|
5
|
+
--page: #ffffff;
|
|
6
|
+
--chrome: #fafafa;
|
|
7
|
+
--border: #e5e5e5;
|
|
8
|
+
--border-strong: #d4d4d4;
|
|
9
|
+
--text: #171717;
|
|
10
|
+
--muted: #525252;
|
|
11
|
+
--faint: #737373;
|
|
12
|
+
--accent: #171717;
|
|
13
|
+
--link: #1d4ed8;
|
|
14
|
+
--code-bg: #f5f5f5;
|
|
15
|
+
--code-text: #262626;
|
|
16
|
+
--hover: #f0f0f0;
|
|
17
|
+
--current: #ededed;
|
|
18
|
+
--good-bg: #ecfdf3; --good-text: #166534; --good-border: #bbf7d0;
|
|
19
|
+
--warn-bg: #fffbeb; --warn-text: #92400e; --warn-border: #fde68a;
|
|
20
|
+
--info-bg: #eff6ff; --info-text: #1e40af; --info-border: #bfdbfe;
|
|
21
|
+
--sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
|
22
|
+
--mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
|
|
23
|
+
--top-bg: rgba(250, 250, 250, 0.92);
|
|
24
|
+
--stripe: #fcfcfc; --row-hover: #f5f7fa;
|
|
25
|
+
--shadow: rgba(0, 0, 0, 0.15); --backdrop: rgba(0, 0, 0, 0.25);
|
|
26
|
+
--top: 56px;
|
|
27
|
+
--side: 248px;
|
|
28
|
+
--toc: 220px;
|
|
29
|
+
--content: 1360px;
|
|
30
|
+
--prose: 100ch;
|
|
31
|
+
--radius: 8px;
|
|
32
|
+
color-scheme: light;
|
|
33
|
+
}
|
|
34
|
+
:root[data-theme="dark"] {
|
|
35
|
+
--page: #0a0a0a; --chrome: #111111; --border: #262626; --border-strong: #404040;
|
|
36
|
+
--text: #ededed; --muted: #a3a3a3; --faint: #8a8a8a; --accent: #ededed; --link: #7aa7ff;
|
|
37
|
+
--code-bg: #171717; --code-text: #e5e5e5; --hover: #1c1c1c; --current: #262626;
|
|
38
|
+
--good-bg: #052e16; --good-text: #86efac; --good-border: #14532d;
|
|
39
|
+
--warn-bg: #2a1a04; --warn-text: #fcd34d; --warn-border: #78350f;
|
|
40
|
+
--info-bg: #0b1b3a; --info-text: #93c5fd; --info-border: #1e3a8a;
|
|
41
|
+
--top-bg: rgba(10, 10, 10, 0.92); --stripe: #0e0e0e; --row-hover: #151b26;
|
|
42
|
+
--shadow: rgba(0, 0, 0, 0.6); --backdrop: rgba(0, 0, 0, 0.6);
|
|
43
|
+
color-scheme: dark;
|
|
44
|
+
}
|
|
45
|
+
@media (prefers-color-scheme: dark) {
|
|
46
|
+
:root:not([data-theme="light"]) {
|
|
47
|
+
--page: #0a0a0a; --chrome: #111111; --border: #262626; --border-strong: #404040;
|
|
48
|
+
--text: #ededed; --muted: #a3a3a3; --faint: #8a8a8a; --accent: #ededed; --link: #7aa7ff;
|
|
49
|
+
--code-bg: #171717; --code-text: #e5e5e5; --hover: #1c1c1c; --current: #262626;
|
|
50
|
+
--good-bg: #052e16; --good-text: #86efac; --good-border: #14532d;
|
|
51
|
+
--warn-bg: #2a1a04; --warn-text: #fcd34d; --warn-border: #78350f;
|
|
52
|
+
--info-bg: #0b1b3a; --info-text: #93c5fd; --info-border: #1e3a8a;
|
|
53
|
+
--top-bg: rgba(10, 10, 10, 0.92); --stripe: #0e0e0e; --row-hover: #151b26;
|
|
54
|
+
--shadow: rgba(0, 0, 0, 0.6); --backdrop: rgba(0, 0, 0, 0.6);
|
|
55
|
+
color-scheme: dark;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
*, *::before, *::after { box-sizing: border-box; }
|
|
59
|
+
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--top) + 16px); }
|
|
60
|
+
body { margin: 0; background: var(--page); color: var(--text); font: 16px/1.65 var(--sans); }
|
|
61
|
+
a { color: var(--link); text-decoration: none; }
|
|
62
|
+
a:hover { text-decoration: underline; }
|
|
63
|
+
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; border-radius: 4px; }
|
|
64
|
+
code, kbd, pre { font-family: var(--mono); font-size: 0.875em; }
|
|
65
|
+
.skip { position: absolute; left: -9999px; }
|
|
66
|
+
.skip:focus { left: 16px; top: 8px; z-index: 30; background: var(--page); padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); }
|
|
67
|
+
|
|
68
|
+
/* the top bar */
|
|
69
|
+
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 20px; height: var(--top); padding: 0 20px;
|
|
70
|
+
background: var(--top-bg); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
|
|
71
|
+
.brand { font-weight: 650; color: var(--text); white-space: nowrap; letter-spacing: -0.01em; }
|
|
72
|
+
.brand:hover { text-decoration: none; }
|
|
73
|
+
.sections { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
|
|
74
|
+
.section-link { color: var(--muted); padding: 6px 10px; border-radius: 6px; font-size: 14px; white-space: nowrap; }
|
|
75
|
+
.section-link:hover { background: var(--hover); color: var(--text); text-decoration: none; }
|
|
76
|
+
.section-link.current { color: var(--text); font-weight: 600; background: var(--current); }
|
|
77
|
+
.search-button { margin-left: auto; display: flex; align-items: center; gap: 24px; padding: 6px 8px 6px 12px; border: 1px solid var(--border);
|
|
78
|
+
border-radius: var(--radius); background: var(--page); color: var(--faint); font: 14px var(--sans); cursor: pointer; min-width: 200px; }
|
|
79
|
+
.search-button:hover { border-color: var(--border-strong); }
|
|
80
|
+
kbd { border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font-size: 12px; color: var(--muted); background: var(--chrome); }
|
|
81
|
+
.repo { color: var(--muted); font-size: 14px; }
|
|
82
|
+
.menu-button { display: none; width: 36px; height: 36px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--page); cursor: pointer; }
|
|
83
|
+
.menu-button span, .menu-button span::before, .menu-button span::after { display: block; width: 16px; height: 2px; background: var(--text); margin: 0 auto; position: relative; content: ""; }
|
|
84
|
+
.menu-button span::before { position: absolute; top: -5px; }
|
|
85
|
+
.menu-button span::after { position: absolute; top: 5px; }
|
|
86
|
+
|
|
87
|
+
/* the three columns */
|
|
88
|
+
.layout { display: grid; grid-template-columns: var(--side) minmax(0, 1fr) var(--toc); min-height: calc(100vh - var(--top)); }
|
|
89
|
+
.sidebar { position: sticky; top: var(--top); height: calc(100vh - var(--top)); overflow-y: auto; padding: 20px 12px 40px;
|
|
90
|
+
background: var(--chrome); border-right: 1px solid var(--border); font-size: 14px; }
|
|
91
|
+
.nav-group { margin-bottom: 6px; }
|
|
92
|
+
.nav-group > summary { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 5px 10px; border-radius: 6px; cursor: pointer; list-style: none; }
|
|
93
|
+
.nav-group > summary::-webkit-details-marker { display: none; }
|
|
94
|
+
.nav-group > summary::before { content: "▸"; color: var(--faint); font-size: 11px; margin-right: 6px; }
|
|
95
|
+
.nav-group[open] > summary::before { content: "▾"; }
|
|
96
|
+
.nav-group > summary:hover { background: var(--hover); }
|
|
97
|
+
.nav-group > summary .nav-title { flex: 1; }
|
|
98
|
+
.nav-count { font-size: 11px; color: var(--faint); font-variant-numeric: tabular-nums; }
|
|
99
|
+
.nav-sub { margin: 2px 0 6px 14px !important; padding-left: 8px !important; border-left: 1px solid var(--border); }
|
|
100
|
+
.nav-kind { margin: 8px 0 2px; padding: 0 10px; font-size: 11px; font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: 0.04em; }
|
|
101
|
+
.nav-title { margin: 0; padding: 0; font-size: 12px; font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: 0.04em; }
|
|
102
|
+
.sidebar ul { list-style: none; margin: 0; padding: 0; }
|
|
103
|
+
.sidebar a { display: block; padding: 5px 10px; border-radius: 6px; color: var(--muted); line-height: 1.4; }
|
|
104
|
+
.sidebar a:hover { background: var(--hover); color: var(--text); text-decoration: none; }
|
|
105
|
+
.sidebar a.current { background: var(--current); color: var(--text); font-weight: 600; }
|
|
106
|
+
.content { background: var(--page); min-width: 0; }
|
|
107
|
+
article { max-width: var(--content); margin: 0 auto; padding: 40px 48px 96px; }
|
|
108
|
+
/* prose stays at a comfortable measure; tables, code, diagrams, cards and entries take the whole width */
|
|
109
|
+
article > p, article > ul, article > ol, article > h1, article > h2, article > h3, article > h4, .entry-body > p, .entry-body > ul, .entry-body > ol,
|
|
110
|
+
.callout > p, .page-head + p { max-width: var(--prose); }
|
|
111
|
+
.toc { position: sticky; top: var(--top); height: calc(100vh - var(--top)); overflow-y: auto; padding: 40px 16px 40px 8px; font-size: 13px; background: var(--page); }
|
|
112
|
+
.toc-title { margin: 0 0 8px; font-weight: 600; color: var(--text); }
|
|
113
|
+
.toc ul { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--border); }
|
|
114
|
+
.toc li a { display: block; padding: 3px 0 3px 12px; color: var(--faint); margin-left: -1px; border-left: 1px solid transparent; line-height: 1.4; overflow-wrap: anywhere; }
|
|
115
|
+
.toc li.toc-3 a { padding-left: 24px; }
|
|
116
|
+
.toc li a:hover { color: var(--text); text-decoration: none; }
|
|
117
|
+
.toc li a.active { color: var(--text); border-left-color: var(--accent); }
|
|
118
|
+
|
|
119
|
+
/* the text */
|
|
120
|
+
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 8px; }
|
|
121
|
+
h1 { font-size: 2rem; line-height: 1.2; letter-spacing: -0.02em; margin: 0; font-weight: 700; }
|
|
122
|
+
h2 { font-size: 1.45rem; letter-spacing: -0.015em; margin: 2.2em 0 0.6em; padding-top: 0.2em; line-height: 1.3; }
|
|
123
|
+
h3 { font-size: 1.15rem; margin: 1.8em 0 0.5em; line-height: 1.35; }
|
|
124
|
+
h4 { font-size: 1rem; margin: 1.5em 0 0.4em; }
|
|
125
|
+
h2, h3, h4 { position: relative; }
|
|
126
|
+
.anchor { position: absolute; left: -1em; color: var(--faint); opacity: 0; padding-right: 0.2em; }
|
|
127
|
+
h2:hover .anchor, h3:hover .anchor, h4:hover .anchor { opacity: 1; text-decoration: none; }
|
|
128
|
+
p, ul, ol { margin: 0 0 1em; }
|
|
129
|
+
ul, ol { padding-left: 1.4em; }
|
|
130
|
+
li { margin: 0.25em 0; }
|
|
131
|
+
li > ul, li > ol { margin: 0.25em 0 0; }
|
|
132
|
+
:not(pre) > code { background: var(--code-bg); border: 1px solid var(--border); border-radius: 4px; padding: 0.08em 0.35em; color: var(--code-text); overflow-wrap: anywhere; }
|
|
133
|
+
a code { color: var(--link); }
|
|
134
|
+
.muted { color: var(--faint); font-weight: 400; }
|
|
135
|
+
.meta { font-size: 13.5px; color: var(--faint); line-height: 1.5; }
|
|
136
|
+
.meta code { font-size: 12px; }
|
|
137
|
+
a.ext::after { content: "↗"; font-size: 0.75em; margin-left: 0.15em; color: var(--faint); }
|
|
138
|
+
figure { margin: 0 0 1.2em; }
|
|
139
|
+
.code figcaption { font: 12px var(--mono); color: var(--muted); background: var(--chrome); border: 1px solid var(--border); border-bottom: 0;
|
|
140
|
+
border-radius: var(--radius) var(--radius) 0 0; padding: 6px 12px; }
|
|
141
|
+
.code figcaption + pre { border-top-left-radius: 0; border-top-right-radius: 0; }
|
|
142
|
+
pre { position: relative; margin: 0; padding: 14px 16px; overflow-x: auto; background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius);
|
|
143
|
+
line-height: 1.55; color: var(--code-text); tab-size: 2; }
|
|
144
|
+
pre code { font-size: 13.5px; background: none; border: 0; padding: 0; }
|
|
145
|
+
.copy { position: absolute; top: 8px; right: 8px; padding: 3px 8px; font: 12px var(--sans); color: var(--muted); background: var(--page);
|
|
146
|
+
border: 1px solid var(--border); border-radius: 6px; cursor: pointer; opacity: 0; transition: opacity 0.15s; }
|
|
147
|
+
pre:hover .copy, .copy:focus { opacity: 1; }
|
|
148
|
+
/* code coloured when the site is built (FR-037): each run carries its colour for the light scheme (--l) and for the dark (--d) */
|
|
149
|
+
.t { color: var(--l); }
|
|
150
|
+
.t.i { font-style: italic; }
|
|
151
|
+
.t.b { font-weight: 600; }
|
|
152
|
+
:root[data-theme="dark"] .t { color: var(--d); }
|
|
153
|
+
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .t { color: var(--d); } }
|
|
154
|
+
@media print { .t { color: var(--l) !important; } }
|
|
155
|
+
.table-wrap { overflow-x: auto; margin: 0 0 1.2em; border: 1px solid var(--border); border-radius: var(--radius); }
|
|
156
|
+
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 14.5px; line-height: 1.55; }
|
|
157
|
+
th, td { text-align: left; vertical-align: top; padding: 10px 14px; border-bottom: 1px solid var(--border); }
|
|
158
|
+
th { position: sticky; top: 0; background: var(--chrome); font-weight: 600; color: var(--muted); font-size: 12.5px; text-transform: uppercase;
|
|
159
|
+
letter-spacing: 0.03em; white-space: nowrap; }
|
|
160
|
+
tbody tr:nth-child(even) td { background: var(--stripe); }
|
|
161
|
+
tbody tr:hover td { background: var(--row-hover); }
|
|
162
|
+
td code { white-space: nowrap; }
|
|
163
|
+
td code.long { white-space: normal; overflow-wrap: anywhere; }
|
|
164
|
+
tr:last-child td { border-bottom: 0; }
|
|
165
|
+
td:first-child code { white-space: nowrap; overflow-wrap: normal; }
|
|
166
|
+
|
|
167
|
+
/* badges, callouts, cards */
|
|
168
|
+
.badges, .badge-row { display: inline-flex; flex-wrap: wrap; gap: 6px; }
|
|
169
|
+
.badge { display: inline-block; font: 600 11.5px/1.6 var(--sans); padding: 0 8px; border-radius: 999px; border: 1px solid var(--border);
|
|
170
|
+
background: var(--chrome); color: var(--muted); white-space: nowrap; }
|
|
171
|
+
.badge-good { background: var(--good-bg); color: var(--good-text); border-color: var(--good-border); }
|
|
172
|
+
.badge-warn { background: var(--warn-bg); color: var(--warn-text); border-color: var(--warn-border); }
|
|
173
|
+
.badge-info { background: var(--info-bg); color: var(--info-text); border-color: var(--info-border); }
|
|
174
|
+
.callout { border: 1px solid var(--border); border-left: 3px solid var(--border-strong); border-radius: var(--radius); padding: 12px 16px; margin: 0 0 1.2em; background: var(--page); }
|
|
175
|
+
.callout > :last-child { margin-bottom: 0; }
|
|
176
|
+
.callout-title { font-weight: 600; margin: 0 0 0.4em; font-size: 14px; }
|
|
177
|
+
.callout-limit { border-left-color: #f59e0b; }
|
|
178
|
+
.callout-warn { border-left-color: #ef4444; }
|
|
179
|
+
.callout-note { border-left-color: #3b82f6; }
|
|
180
|
+
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; margin: 0 0 1.5em; }
|
|
181
|
+
.card { display: flex; flex-direction: column; }
|
|
182
|
+
.card-link { display: flex; flex-direction: column; gap: 6px; height: 100%; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius);
|
|
183
|
+
color: var(--text); background: var(--page); transition: border-color 0.15s, background 0.15s; }
|
|
184
|
+
.card-link:hover { border-color: var(--border-strong); background: var(--chrome); text-decoration: none; }
|
|
185
|
+
.card-title { font-weight: 600; }
|
|
186
|
+
.card-text { color: var(--muted); font-size: 14px; line-height: 1.5; }
|
|
187
|
+
.card-text em { font-style: normal; }
|
|
188
|
+
.card-children { display: flex; flex-direction: column; gap: 8px; margin: 8px 0 0 14px; padding-left: 12px; border-left: 1px solid var(--border); }
|
|
189
|
+
.card-children .card-link { padding: 10px 12px; }
|
|
190
|
+
|
|
191
|
+
/* entries of the API and requirements */
|
|
192
|
+
.entry { border-top: 1px solid var(--border); padding-top: 18px; margin-top: 26px; }
|
|
193
|
+
.entry-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
|
|
194
|
+
.entry-name { font-weight: 600; }
|
|
195
|
+
.entry-name code { font-size: 15px; background: none; border: 0; padding: 0; color: var(--text); }
|
|
196
|
+
.sig { margin-bottom: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
197
|
+
.sig-long summary { cursor: pointer; margin-bottom: 8px; font-size: 13px; }
|
|
198
|
+
.entry-body > :last-child { margin-bottom: 0; }
|
|
199
|
+
|
|
200
|
+
/* tabs, diagrams, trees */
|
|
201
|
+
.tabs { margin: 0 0 1.2em; }
|
|
202
|
+
.tab-list { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 10px; overflow-x: auto; }
|
|
203
|
+
.tab-list button { font: 500 13px var(--sans); color: var(--muted); background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 12px; cursor: pointer; margin-bottom: -1px; }
|
|
204
|
+
.tab-list button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
|
|
205
|
+
.diagram { border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; background: var(--page); }
|
|
206
|
+
.diagram-wrap { overflow-x: auto; cursor: zoom-in; text-align: center; font-family: var(--sans); }
|
|
207
|
+
.diagram-wrap svg { max-width: 100%; height: auto; }
|
|
208
|
+
.diagram-wrap.expanded { cursor: zoom-out; }
|
|
209
|
+
.diagram-wrap.expanded svg { max-width: none; }
|
|
210
|
+
.diagram figcaption { color: var(--muted); font-size: 13px; margin-top: 8px; text-align: center; }
|
|
211
|
+
.diagram-source summary { cursor: pointer; font-size: 12px; color: var(--faint); margin-top: 8px; }
|
|
212
|
+
.tree ul { list-style: none; margin: 0; padding-left: 18px; border-left: 1px solid var(--border); }
|
|
213
|
+
.tree > ul { border-left: 0; padding-left: 0; }
|
|
214
|
+
.tree li { margin: 6px 0; }
|
|
215
|
+
.tree-node { display: inline-flex; flex-wrap: wrap; gap: 8px; align-items: baseline; }
|
|
216
|
+
.tree-note { color: var(--muted); font-size: 14px; }
|
|
217
|
+
|
|
218
|
+
/* the search */
|
|
219
|
+
dialog.search { width: min(640px, calc(100vw - 32px)); max-height: min(560px, calc(100vh - 96px)); margin-top: 72px; padding: 0; border: 1px solid var(--border);
|
|
220
|
+
border-radius: 12px; box-shadow: 0 20px 50px var(--shadow); background: var(--page); color: var(--text); }
|
|
221
|
+
dialog.search::backdrop { background: var(--backdrop); }
|
|
222
|
+
dialog.search input { width: 100%; border: 0; border-bottom: 1px solid var(--border); padding: 14px 16px; font: 16px var(--sans); outline: none; }
|
|
223
|
+
.results { list-style: none; margin: 0; padding: 6px; max-height: 420px; overflow-y: auto; }
|
|
224
|
+
.results a { display: block; padding: 8px 10px; border-radius: 6px; color: var(--text); }
|
|
225
|
+
.results a:hover, .results a.selected { background: var(--hover); text-decoration: none; }
|
|
226
|
+
.results .r-title { font-weight: 550; }
|
|
227
|
+
.results .r-where { display: block; font-size: 12px; color: var(--faint); }
|
|
228
|
+
.search-hint { margin: 0; padding: 8px 16px; font-size: 12px; color: var(--faint); border-top: 1px solid var(--border); }
|
|
229
|
+
|
|
230
|
+
/* narrower screens */
|
|
231
|
+
@media (max-width: 1599px) {
|
|
232
|
+
.layout { grid-template-columns: var(--side) minmax(0, 1fr); }
|
|
233
|
+
.toc { display: none; }
|
|
234
|
+
}
|
|
235
|
+
@media (max-width: 900px) {
|
|
236
|
+
.layout { grid-template-columns: minmax(0, 1fr); }
|
|
237
|
+
.menu-button { display: block; flex: none; }
|
|
238
|
+
.sidebar { display: none; position: fixed; top: var(--top); left: 0; right: 0; bottom: 0; z-index: 15; height: auto; border-right: 0; }
|
|
239
|
+
body.menu-open .sidebar { display: block; }
|
|
240
|
+
.repo { display: none; }
|
|
241
|
+
.search-button { min-width: 0; gap: 8px; }
|
|
242
|
+
.search-button span { display: none; }
|
|
243
|
+
.search-button::before { content: "⌕"; font-size: 16px; color: var(--muted); }
|
|
244
|
+
.sections { flex: 1; min-width: 0; }
|
|
245
|
+
}
|
|
246
|
+
@media (max-width: 640px) {
|
|
247
|
+
.top { gap: 10px; padding: 0 16px; }
|
|
248
|
+
.brand { display: none; }
|
|
249
|
+
article { padding: 28px 16px 72px; }
|
|
250
|
+
th, td { padding: 8px 10px; }
|
|
251
|
+
h1 { font-size: 1.6rem; }
|
|
252
|
+
.anchor { display: none; }
|
|
253
|
+
}
|
|
254
|
+
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
|
|
255
|
+
@media print {
|
|
256
|
+
:root { --page: #ffffff; --text: #000000; --muted: #333333; --faint: #555555; --link: #000000; --code-bg: #f5f5f5; --code-text: #000000; color-scheme: light; }
|
|
257
|
+
.top, .sidebar, .toc, .skip, .copy, .theme-button, .search-button, .menu-button { display: none !important; }
|
|
258
|
+
.layout { display: block; }
|
|
259
|
+
article { max-width: none; padding: 0; }
|
|
260
|
+
a { color: inherit; text-decoration: underline; }
|
|
261
|
+
article a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 0.8em; color: #333333; }
|
|
262
|
+
pre, table, figure, .entry { break-inside: avoid; }
|
|
263
|
+
h1, h2, h3, h4 { break-after: avoid; }
|
|
264
|
+
}
|
|
265
|
+
.theme-button { width: 36px; height: 36px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--page); color: var(--muted); cursor: pointer; font: 16px/1 var(--sans); }
|
|
266
|
+
.theme-button:hover { border-color: var(--border-strong); color: var(--text); }
|
|
267
|
+
|
|
268
|
+
.search-kind { margin: 0 12px 8px; padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--page); color: var(--text); font: 13px var(--sans); }
|
|
269
|
+
dialog.search form { display: flex; flex-wrap: wrap; align-items: center; }
|
|
270
|
+
dialog.search form input[type="search"] { flex: 1 1 60%; }
|
|
271
|
+
|
|
272
|
+
.table-filter { display: block; margin: 8px 0; padding: 7px 10px; width: min(360px, 100%); border: 1px solid var(--border); border-radius: var(--radius); background: var(--page); color: var(--text); font: 14px var(--sans); }
|
|
273
|
+
.table-filter + .table-wrap tbody tr[hidden] { display: none; }
|
|
274
|
+
.table-wrap.compact td, .table-wrap.compact th { padding: 5px 10px; font-size: 13px; line-height: 1.45; }
|
|
275
|
+
.table-wrap.compact td code { font-size: 12px; }
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
// The one script of commons' documentation (commons 0011-documentation FR-017, FR-034): the theme, the menu on narrow screens, tabs, copy buttons, the
|
|
2
|
+
// table of contents following the reader, the search ("/" opens it, "t" switches the theme, "[" and "]" go to the previous and next page; search.json is a file of the site), and a click on a diagram to see it at full size. A page reads whole without it; nothing here asks another host for anything.
|
|
3
|
+
(() => {
|
|
4
|
+
"use strict";
|
|
5
|
+
const root = document.documentElement.dataset.root || "";
|
|
6
|
+
|
|
7
|
+
// the theme: the reader's system decides until they choose, and the choice is kept in this browser only
|
|
8
|
+
const scheme = () => document.documentElement.dataset.theme || (matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light");
|
|
9
|
+
const toggleTheme = () => {
|
|
10
|
+
const next = scheme() === "dark" ? "light" : "dark";
|
|
11
|
+
document.documentElement.dataset.theme = next;
|
|
12
|
+
try {
|
|
13
|
+
localStorage.setItem("theme", next);
|
|
14
|
+
} catch {
|
|
15
|
+
// storage may be unavailable: the choice then lasts for this page only
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
document.querySelector(".theme-button")?.addEventListener("click", toggleTheme);
|
|
19
|
+
|
|
20
|
+
// a filter above a table: the rows whose text has every word typed stay, the others are hidden
|
|
21
|
+
for (const box of document.querySelectorAll(".table-filter")) {
|
|
22
|
+
const rows = [...(box.nextElementSibling?.querySelectorAll("tbody tr") ?? [])];
|
|
23
|
+
box.addEventListener("input", () => {
|
|
24
|
+
const words = box.value.toLowerCase().split(/\s+/).filter(Boolean);
|
|
25
|
+
for (const row of rows) row.hidden = !words.every((w) => row.textContent.toLowerCase().includes(w));
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// the menu
|
|
30
|
+
const menu = document.querySelector(".menu-button");
|
|
31
|
+
if (menu) {
|
|
32
|
+
menu.addEventListener("click", () => {
|
|
33
|
+
const open = document.body.classList.toggle("menu-open");
|
|
34
|
+
menu.setAttribute("aria-expanded", String(open));
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// tabs
|
|
39
|
+
for (const tabs of document.querySelectorAll("[data-tabs]")) {
|
|
40
|
+
const buttons = [...tabs.querySelectorAll(":scope > .tab-list > button")];
|
|
41
|
+
const panels = [...tabs.querySelectorAll(":scope > .tab-panel")];
|
|
42
|
+
const select = (i) => {
|
|
43
|
+
buttons.forEach((b, j) => b.setAttribute("aria-selected", String(i === j)));
|
|
44
|
+
panels.forEach((p, j) => (p.hidden = i !== j));
|
|
45
|
+
};
|
|
46
|
+
buttons.forEach((b, i) => b.addEventListener("click", () => select(i)));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// copy buttons
|
|
50
|
+
for (const pre of document.querySelectorAll("figure.code pre, pre.sig")) {
|
|
51
|
+
const b = document.createElement("button");
|
|
52
|
+
b.type = "button";
|
|
53
|
+
b.className = "copy";
|
|
54
|
+
b.textContent = "Copy";
|
|
55
|
+
b.addEventListener("click", async () => {
|
|
56
|
+
try {
|
|
57
|
+
await navigator.clipboard.writeText(pre.querySelector("code")?.textContent ?? "");
|
|
58
|
+
b.textContent = "Copied";
|
|
59
|
+
} catch {
|
|
60
|
+
b.textContent = "Select and copy";
|
|
61
|
+
}
|
|
62
|
+
setTimeout(() => (b.textContent = "Copy"), 1500);
|
|
63
|
+
});
|
|
64
|
+
pre.appendChild(b);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// the table of contents
|
|
68
|
+
const links = [...document.querySelectorAll(".toc a")];
|
|
69
|
+
if (links.length > 0 && "IntersectionObserver" in window) {
|
|
70
|
+
const byId = new Map(links.map((a) => [decodeURIComponent(a.hash.slice(1)), a]));
|
|
71
|
+
const seen = new Set();
|
|
72
|
+
const io = new IntersectionObserver((entries) => {
|
|
73
|
+
for (const e of entries) e.isIntersecting ? seen.add(e.target.id) : seen.delete(e.target.id);
|
|
74
|
+
const first = [...byId.keys()].find((id) => seen.has(id));
|
|
75
|
+
if (first) links.forEach((a) => a.classList.toggle("active", byId.get(first) === a));
|
|
76
|
+
}, { rootMargin: "-56px 0px -60% 0px" });
|
|
77
|
+
for (const id of byId.keys()) {
|
|
78
|
+
const el = document.getElementById(id);
|
|
79
|
+
if (el) io.observe(el);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// the search
|
|
84
|
+
const dialog = document.querySelector("dialog.search");
|
|
85
|
+
const input = dialog?.querySelector("input");
|
|
86
|
+
const list = dialog?.querySelector(".results");
|
|
87
|
+
const kind = dialog?.querySelector(".search-kind");
|
|
88
|
+
let index = null;
|
|
89
|
+
let selected = 0;
|
|
90
|
+
const load = async () => {
|
|
91
|
+
if (index) return index;
|
|
92
|
+
try {
|
|
93
|
+
const r = await fetch(`${root}search.json`);
|
|
94
|
+
index = (await r.json()).map(([title, url, where, kind]) => ({ title, url, where, kind, group: kind.replace(/ of .*$/, "").replace(/\s*\(.*\)$/, "").trim(), key: title.toLowerCase() }));
|
|
95
|
+
} catch {
|
|
96
|
+
index = [];
|
|
97
|
+
}
|
|
98
|
+
return index;
|
|
99
|
+
};
|
|
100
|
+
const esc = (s) => s.replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c]);
|
|
101
|
+
const render = async () => {
|
|
102
|
+
const q = input.value.trim().toLowerCase();
|
|
103
|
+
const all = await load();
|
|
104
|
+
if (q === "") {
|
|
105
|
+
list.innerHTML = "";
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const words = q.split(/\s+/);
|
|
109
|
+
const only = kind?.value ?? "";
|
|
110
|
+
const scored = [];
|
|
111
|
+
for (const e of all) {
|
|
112
|
+
if (only !== "" && e.group !== only) continue;
|
|
113
|
+
const hay = `${e.key} ${e.where.toLowerCase()}`;
|
|
114
|
+
if (!words.every((w) => hay.includes(w))) continue;
|
|
115
|
+
const s = e.key === q ? 0 : e.key.startsWith(q) ? 1 : e.key.includes(q) ? 2 : 3;
|
|
116
|
+
scored.push([s, e.title.length, e]);
|
|
117
|
+
}
|
|
118
|
+
scored.sort((a, b) => a[0] - b[0] || a[1] - b[1]);
|
|
119
|
+
selected = 0;
|
|
120
|
+
list.innerHTML = scored.slice(0, 40).map(([, , e], i) =>
|
|
121
|
+
`<li><a href="${esc(root + e.url)}"${i === 0 ? ' class="selected"' : ""}><span class="r-title">${esc(e.title)}</span><span class="r-where">${esc(e.kind)} · ${esc(e.where)}</span></a></li>`
|
|
122
|
+
).join("") || '<li class="r-none"><span class="r-where">Nothing found.</span></li>';
|
|
123
|
+
};
|
|
124
|
+
const open = () => {
|
|
125
|
+
if (!dialog) return;
|
|
126
|
+
dialog.showModal();
|
|
127
|
+
input.select();
|
|
128
|
+
void load().then((all) => {
|
|
129
|
+
if (kind && kind.options.length === 1) {
|
|
130
|
+
for (const k of [...new Set(all.map((e) => e.group))].sort()) kind.add(new Option(k, k));
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
kind?.addEventListener("change", () => void render());
|
|
135
|
+
document.querySelector(".search-button")?.addEventListener("click", open);
|
|
136
|
+
document.addEventListener("keydown", (e) => {
|
|
137
|
+
const typing = /^(INPUT|TEXTAREA|SELECT)$/.test(document.activeElement?.tagName ?? "");
|
|
138
|
+
if (e.key === "/" && !typing && !dialog?.open) {
|
|
139
|
+
e.preventDefault();
|
|
140
|
+
open();
|
|
141
|
+
} else if (e.key === "t" && !typing && !dialog?.open && !e.metaKey && !e.ctrlKey && !e.altKey) {
|
|
142
|
+
toggleTheme();
|
|
143
|
+
} else if ((e.key === "[" || e.key === "]") && !typing && !dialog?.open) {
|
|
144
|
+
// the previous and the next page of the side navigation
|
|
145
|
+
const links = [...document.querySelectorAll(".sidebar a")];
|
|
146
|
+
const at = links.findIndex((a) => a.classList.contains("current"));
|
|
147
|
+
const go = links[at + (e.key === "]" ? 1 : -1)];
|
|
148
|
+
if (at >= 0 && go) location.href = go.href;
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
input?.addEventListener("input", render);
|
|
152
|
+
input?.addEventListener("keydown", (e) => {
|
|
153
|
+
const items = [...list.querySelectorAll("a")];
|
|
154
|
+
if (items.length === 0) return;
|
|
155
|
+
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
156
|
+
e.preventDefault();
|
|
157
|
+
selected = (selected + (e.key === "ArrowDown" ? 1 : items.length - 1)) % items.length;
|
|
158
|
+
items.forEach((a, i) => a.classList.toggle("selected", i === selected));
|
|
159
|
+
items[selected].scrollIntoView({ block: "nearest" });
|
|
160
|
+
} else if (e.key === "Enter") {
|
|
161
|
+
e.preventDefault();
|
|
162
|
+
location.href = items[selected].href;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
dialog?.addEventListener("click", (e) => {
|
|
166
|
+
if (e.target === dialog) dialog.close();
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// diagrams: drawn when the site is built; a click shows one at full size, or fits it again
|
|
170
|
+
for (const wrap of document.querySelectorAll(".diagram-wrap")) {
|
|
171
|
+
wrap.title = "Click to see the diagram at full size, or to fit it again";
|
|
172
|
+
wrap.addEventListener("click", () => wrap.classList.toggle("expanded"));
|
|
173
|
+
}
|
|
174
|
+
})();
|