jekyll-theme-modootoday 1.5.0 → 1.7.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +103 -1
- data/README.ja.md +150 -0
- data/README.ko.md +20 -17
- data/README.md +19 -16
- data/RULES.md +8 -2
- data/_includes/modootoday/assets/build.html +6 -0
- data/_includes/modootoday/assets/registry.html +21 -7
- data/_includes/modootoday/assets/scripts.html +5 -0
- data/_includes/modootoday/assets/sheets.html +9 -3
- data/_includes/modootoday/assets/site-scripts.html +8 -3
- data/_includes/modootoday/blog/subscribe.html +5 -0
- data/_includes/modootoday/brand/icon.html +2 -1
- data/_includes/modootoday/chart/figure.html +4 -0
- data/_includes/modootoday/chart/table.html +14 -0
- data/_includes/modootoday/chrome/banner-text.html +16 -0
- data/_includes/modootoday/chrome/banner.html +5 -0
- data/_includes/modootoday/chrome/showcase.html +13 -0
- data/_includes/modootoday/config.html +9 -5
- data/_includes/modootoday/detail/cta.html +1 -1
- data/_includes/modootoday/detail/facts.html +1 -0
- data/_includes/modootoday/detail/jsonld.html +6 -1
- data/_includes/modootoday/detail/page.html +1 -0
- data/_includes/modootoday/detail/tickets.html +6 -0
- data/_includes/modootoday/docs-extra/feed-entries.html +24 -0
- data/_includes/modootoday/docs-extra/head.html +7 -1
- data/_includes/modootoday/head-meta.html +25 -14
- data/_includes/modootoday/i18n/ar.html +1 -1
- data/_includes/modootoday/i18n/de.html +1 -1
- data/_includes/modootoday/i18n/el.html +1 -1
- data/_includes/modootoday/i18n/es.html +1 -1
- data/_includes/modootoday/i18n/fa.html +1 -1
- data/_includes/modootoday/i18n/fr.html +1 -1
- data/_includes/modootoday/i18n/id.html +1 -1
- data/_includes/modootoday/i18n/it.html +1 -1
- data/_includes/modootoday/i18n/ja.html +1 -1
- data/_includes/modootoday/i18n/ko.html +1 -1
- data/_includes/modootoday/i18n/ml.html +1 -1
- data/_includes/modootoday/i18n/pl.html +1 -1
- data/_includes/modootoday/i18n/pt-BR.html +1 -1
- data/_includes/modootoday/i18n/ro.html +1 -1
- data/_includes/modootoday/i18n/ru.html +1 -1
- data/_includes/modootoday/i18n/th.html +1 -1
- data/_includes/modootoday/i18n/tr.html +1 -1
- data/_includes/modootoday/i18n/uk.html +1 -1
- data/_includes/modootoday/i18n/ur-Latn.html +1 -1
- data/_includes/modootoday/i18n/vi.html +1 -1
- data/_includes/modootoday/i18n/zh-CN.html +1 -1
- data/_includes/modootoday/i18n/zh-TW.html +1 -1
- data/_includes/modootoday/i18n.html +176 -136
- data/_includes/modootoday/jsonld/graph.html +1 -1
- data/_includes/modootoday/links/content.html +6 -2
- data/_includes/modootoday/markdown/anchors.html +26 -0
- data/_includes/modootoday/markdown/c/chart.html +24 -0
- data/_includes/modootoday/markdown/c/install.html +6 -0
- data/_includes/modootoday/markdown/c/widget.html +22 -0
- data/_includes/modootoday/markdown/components.html +4 -2
- data/_includes/modootoday/markdown/figures/diagrams.html +32 -0
- data/_includes/modootoday/markdown/figures/math.html +34 -0
- data/_includes/modootoday/markdown/figures.html +8 -0
- data/_includes/modootoday/markdown/inline/chart.html +30 -0
- data/_includes/modootoday/markdown/inline/widget.html +19 -0
- data/_includes/modootoday/markdown/inline.html +5 -1
- data/_includes/modootoday/markdown/sections.html +10 -4
- data/_includes/modootoday/meta/feed-url.html +13 -0
- data/_includes/modootoday/meta/feedback.html +14 -0
- data/_includes/modootoday/meta/feeds.html +14 -0
- data/_includes/modootoday/meta/github.html +15 -0
- data/_includes/modootoday/meta/og-image.html +15 -0
- data/_includes/modootoday/meta/releases-feed.html +5 -0
- data/_includes/modootoday/page-meta.html +22 -4
- data/_includes/modootoday/pwa/head.html +7 -0
- data/_includes/modootoday/pwa/manifest.json +54 -0
- data/_includes/modootoday/pwa/offline-assets.html +10 -0
- data/_includes/modootoday/pwa/precache.html +21 -0
- data/_includes/modootoday/pwa/sw.js +36 -0
- data/_includes/modootoday/render/chart.html +15 -0
- data/_includes/modootoday/render/math.html +21 -5
- data/_includes/modootoday/render/mermaid.html +4 -3
- data/_includes/modootoday/site/dir.html +5 -0
- data/_includes/modootoday/stylesheets.html +5 -1
- data/_includes/modootoday/t.html +1 -1
- data/_includes/modootoday/theme-color.html +1 -0
- data/_includes/modootoday/version.html +1 -1
- data/_layouts/archive.html +2 -1
- data/_layouts/author.html +1 -0
- data/_layouts/blog.html +1 -0
- data/_layouts/default.html +12 -9
- data/_layouts/doc.html +1 -0
- data/_layouts/feed.html +14 -5
- data/_layouts/pages/offline.html +14 -0
- data/_layouts/redirect.html +1 -2
- data/_sass/modootoday/blog/_cards.scss +2 -1
- data/_sass/modootoday/components/chrome/_showcase.scss +40 -0
- data/_sass/modootoday/components/content/_anchor.scss +9 -0
- data/_sass/modootoday/components/data/_chart.scss +25 -0
- data/_sass/modootoday/components/doc/_sidebar.scss +3 -1
- data/_sass/modootoday/components/doc/_toc.scss +4 -0
- data/_sass/modootoday/components/figure/_figure-svg.scss +2 -0
- data/_sass/modootoday/components/media/_diagram.scss +16 -0
- data/_sass/modootoday/components/media/_widget.scss +7 -0
- data/_sass/modootoday/components/section/showcase/_install.scss +14 -0
- data/_sass/modootoday/components/section/structure/_timeline.scss +7 -3
- data/_sass/modootoday/layout/_page-meta.scss +5 -1
- data/_sass/modootoday/print/_sheet.scss +17 -0
- data/_sass/modootoday/pwa/_toast.scss +16 -0
- data/_sass/modootoday.scss +1 -0
- data/assets/css/modootoday/chrome/print.scss +5 -0
- data/assets/css/modootoday/chrome/showcase.scss +8 -0
- data/assets/css/modootoday/chrome/toast.scss +8 -0
- data/assets/css/modootoday/content/anchor.scss +7 -0
- data/assets/css/modootoday/data/chart.scss +7 -0
- data/assets/css/modootoday/media/widget.scss +7 -0
- data/assets/css/modootoday/showcase/install.scss +7 -0
- data/assets/js/modootoday/chrome/showcase.js +15 -0
- data/assets/js/modootoday/chrome/theme-init.js +3 -2
- data/assets/js/modootoday/content/scroll-region.js +68 -11
- data/assets/js/modootoday/data/chart-table.js +16 -0
- data/assets/js/modootoday/data/chart.js +106 -0
- data/assets/js/modootoday/pwa/install.js +60 -0
- data/assets/js/modootoday/pwa/offline.js +33 -0
- data/assets/js/modootoday/pwa/register.js +79 -0
- data/assets/js/modootoday/pwa/update-toast.js +75 -0
- data/assets/js/modootoday/pwa/worker.js +150 -0
- data/assets/js/modootoday/structure/toc-spy.js +121 -0
- data/assets/modootoday/icon-192.png +0 -0
- data/assets/modootoday/icon-512.png +0 -0
- data/assets/modootoday/icon-maskable-512.png +0 -0
- data/i18n/ar.yml +33 -3
- data/i18n/de.yml +33 -3
- data/i18n/el.yml +33 -3
- data/i18n/en.yml +33 -3
- data/i18n/es.yml +33 -3
- data/i18n/fa.yml +33 -3
- data/i18n/fr.yml +33 -3
- data/i18n/glossary.yml +21 -3
- data/i18n/id.yml +33 -3
- data/i18n/it.yml +33 -3
- data/i18n/ja.yml +33 -3
- data/i18n/ko.yml +33 -3
- data/i18n/ml.yml +33 -3
- data/i18n/pl.yml +33 -3
- data/i18n/pt-BR.yml +33 -3
- data/i18n/ro.yml +33 -3
- data/i18n/ru.yml +33 -3
- data/i18n/th.yml +33 -3
- data/i18n/tr.yml +33 -3
- data/i18n/uk.yml +33 -3
- data/i18n/ur-Latn.yml +33 -3
- data/i18n/vi.yml +33 -3
- data/i18n/zh-CN.yml +33 -3
- data/i18n/zh-TW.yml +33 -3
- data/lib/modootoday/check/build/build_output.rb +13 -4
- data/lib/modootoday/check/build/feeds.rb +63 -0
- data/lib/modootoday/check/build/links.rb +74 -0
- data/lib/modootoday/check/build/pwa/manifest.rb +61 -0
- data/lib/modootoday/check/build/pwa/precache.rb +38 -0
- data/lib/modootoday/check/build/pwa/worker.rb +55 -0
- data/lib/modootoday/check/build/pwa.rb +55 -0
- data/lib/modootoday/check/build/showcase.rb +27 -0
- data/lib/modootoday/check/build/structured_data/nested.rb +29 -0
- data/lib/modootoday/check/build/structured_data.rb +6 -3
- data/lib/modootoday/check/build/{aliases.rb → stubs/aliases.rb} +1 -1
- data/lib/modootoday/check/build/{records.rb → stubs/records.rb} +1 -1
- data/lib/modootoday/check/build/{twins.rb → stubs/twins.rb} +1 -1
- data/lib/modootoday/check/build/third_party.rb +1 -1
- data/lib/modootoday/check/cli.rb +9 -3
- data/lib/modootoday/check/config/keys/appearance/brand.rb +28 -0
- data/lib/modootoday/check/config/keys/appearance/chrome.rb +11 -1
- data/lib/modootoday/check/config/keys/appearance/showcase.rb +57 -0
- data/lib/modootoday/check/config/keys/appearance/switches.rb +11 -1
- data/lib/modootoday/check/config/keys/figures/chart.rb +16 -0
- data/lib/modootoday/check/config/keys/figures/diagrams.rb +31 -0
- data/lib/modootoday/check/config/keys/figures/renderers.rb +10 -0
- data/lib/modootoday/check/config/keys/pages/blog.rb +11 -0
- data/lib/modootoday/check/config/keys/pages/content.rb +11 -0
- data/lib/modootoday/check/config/keys/pages/edit_url.rb +17 -2
- data/lib/modootoday/check/config/keys/pages/feedback.rb +24 -0
- data/lib/modootoday/check/config/keys/pages/languages.rb +2 -0
- data/lib/modootoday/check/config/keys/serving/delivery.rb +8 -1
- data/lib/modootoday/check/config/keys/serving/pwa.rb +118 -0
- data/lib/modootoday/check/config/keys.rb +9 -1
- data/lib/modootoday/check/config/renderers.rb +36 -12
- data/lib/modootoday/check/config/site_config.rb +2 -1
- data/lib/modootoday/check/config/validate.rb +4 -1
- data/lib/modootoday/check/layouts/detail.rb +24 -6
- data/lib/modootoday/check/layouts/directory.rb +1 -1
- data/lib/modootoday/check/page/a11y/new_window.rb +4 -2
- data/lib/modootoday/check/page/chart.rb +91 -0
- data/lib/modootoday/check/page/component_rules.rb +5 -1
- data/lib/modootoday/check/page/figures/diagrams.rb +72 -0
- data/lib/modootoday/check/page/figures/freshness.rb +55 -0
- data/lib/modootoday/check/page/figures/math_static.rb +88 -0
- data/lib/modootoday/check/page/math_notation.rb +1 -1
- data/lib/modootoday/check/page/pages.rb +22 -0
- data/lib/modootoday/check/page/widget.rb +66 -0
- data/lib/modootoday/check.rb +7 -3
- data/lib/modootoday/figures.rb +88 -0
- data/lib/modootoday/markdown.rb +3 -0
- data/lib/modootoday/stubs/cli.rb +5 -4
- data/lib/modootoday/stubs/pwa.rb +57 -0
- data/lib/modootoday/stubs.rb +3 -2
- metadata +88 -5
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Table to chart data, by the rule modootoday-check applies: labels in the first column, series in the header row,
|
|
2
|
+
// numbers once "," and "%" are removed; any other cell is a gap.
|
|
3
|
+
const text = (cell) => (cell ? cell.textContent.replace(/[,%\s]/g, "") : "");
|
|
4
|
+
|
|
5
|
+
export function tableData(table) {
|
|
6
|
+
const [head, ...rows] = table.rows;
|
|
7
|
+
const series = [...(head ? head.cells : [])].slice(1).map((c) => ({ name: c.textContent.trim(), values: [] }));
|
|
8
|
+
const labels = rows.map((row) => row.cells[0].textContent.trim());
|
|
9
|
+
for (const row of rows) {
|
|
10
|
+
series.forEach((s, i) => {
|
|
11
|
+
const t = text(row.cells[i + 1]);
|
|
12
|
+
s.values.push(t === "" || !Number.isFinite(+t) ? null : +t);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return { labels, series };
|
|
16
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// Draws each figure.mt-chart table with the site's Chart.js (loaded first by render/chart.html) and folds the table
|
|
2
|
+
// into a details element. Without Chart.js, or under forced colours, the table stays the chart.
|
|
3
|
+
import { tableData } from "./chart-table.js";
|
|
4
|
+
import { onThemeChange } from "../theme/current.js";
|
|
5
|
+
|
|
6
|
+
const DASH = [[], [6, 3], [2, 2], [8, 3, 2, 3]];
|
|
7
|
+
const fill = (s, v) => s.replace(/\[(\w+)\]/g, (m, k) => v[k] ?? m);
|
|
8
|
+
|
|
9
|
+
// Colours are the hooks chart.css resolves on the figure for the current scheme; area fills a #rrggbb hook at 20%.
|
|
10
|
+
export function chartConfig(fig, data, still) {
|
|
11
|
+
const cs = getComputedStyle(fig);
|
|
12
|
+
const hook = (n) => cs.getPropertyValue(`--mt-chart-s${n}`).trim();
|
|
13
|
+
const color = (i) => hook((i % 8) + 1);
|
|
14
|
+
const type = fig.dataset.type;
|
|
15
|
+
const opts = fig.dataset.opts || "";
|
|
16
|
+
const round = /pie|doughnut/.test(type);
|
|
17
|
+
const rtl = cs.direction == "rtl";
|
|
18
|
+
const datasets = data.series.map((s, i) => ({
|
|
19
|
+
label: s.name,
|
|
20
|
+
data: s.values,
|
|
21
|
+
borderColor: color(i),
|
|
22
|
+
backgroundColor: round ? data.labels.map((_, j) => color(j)) : type == "area" ? color(i).replace(/^#\w{6}$/, "$&33") : color(i),
|
|
23
|
+
borderWidth: round ? 0 : 2,
|
|
24
|
+
fill: type == "area",
|
|
25
|
+
borderDash: DASH[i % 4],
|
|
26
|
+
}));
|
|
27
|
+
const ticks = { color: hook("t") };
|
|
28
|
+
const grid = { color: hook("g") };
|
|
29
|
+
const axis = { stacked: opts.includes("stacked"), grid, border: grid, ticks };
|
|
30
|
+
// A line series legend key is a short stroke in its dash pattern; a dashed box outline reads as noise. Point-style
|
|
31
|
+
// keys take the point's style, so the series' dash and width are put back on each key.
|
|
32
|
+
const keys = (chart) => chart.constructor.defaults.plugins.legend.labels.generateLabels(chart).map((k) => ({ ...k, lineDash: DASH[k.datasetIndex % 4], lineWidth: 2 }));
|
|
33
|
+
const labels = round || type == "bar" ? ticks : { ...ticks, usePointStyle: true, pointStyle: "line", pointStyleWidth: 28, generateLabels: keys };
|
|
34
|
+
const options = { maintainAspectRatio: false, indexAxis: opts.includes("horizontal") ? "y" : "x", plugins: { legend: { rtl, labels }, tooltip: { rtl } } };
|
|
35
|
+
options.scales = round ? {} : { x: axis, y: { ...axis } };
|
|
36
|
+
if (still) {
|
|
37
|
+
options.animation = false;
|
|
38
|
+
}
|
|
39
|
+
return { type: round || type == "bar" ? type : "line", data: { labels: data.labels, datasets }, options };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function init(root) {
|
|
43
|
+
const doc = root.ownerDocument || root;
|
|
44
|
+
const win = doc.defaultView || {};
|
|
45
|
+
const query = (q) => win.matchMedia && win.matchMedia(q).matches;
|
|
46
|
+
if (typeof win.Chart != "function" || query("(forced-colors: active)")) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const drawn = [];
|
|
50
|
+
const ds = doc.documentElement.dataset;
|
|
51
|
+
// A chart is drawn as it nears the viewport: each draw lays out the whole page, which on a long page blocks input.
|
|
52
|
+
const later = new Map();
|
|
53
|
+
const io = win.IntersectionObserver && new win.IntersectionObserver((es) => es.forEach((e) => {
|
|
54
|
+
if (e.isIntersecting) {
|
|
55
|
+
io.unobserve(e.target);
|
|
56
|
+
later.get(e.target)();
|
|
57
|
+
}
|
|
58
|
+
}), { rootMargin: "200px" });
|
|
59
|
+
const named = new Map();
|
|
60
|
+
for (const fig of root.querySelectorAll("figure.mt-chart")) {
|
|
61
|
+
const box = fig.querySelector(".mt-chart-canvas");
|
|
62
|
+
const holder = fig.querySelector(".mt-chart-data");
|
|
63
|
+
const table = holder && holder.querySelector("table");
|
|
64
|
+
const data = table && tableData(table);
|
|
65
|
+
if (!box || !data || !data.series.length) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const canvas = doc.createElement("canvas");
|
|
69
|
+
const cap = fig.querySelector("figcaption");
|
|
70
|
+
canvas.setAttribute("role", "img");
|
|
71
|
+
const name = cap ? cap.textContent.trim() : data.series.map((s) => s.name).join(", ");
|
|
72
|
+
canvas.setAttribute("aria-label", name);
|
|
73
|
+
box.append(canvas);
|
|
74
|
+
box.hidden = false;
|
|
75
|
+
const details = doc.createElement("details");
|
|
76
|
+
details.append(doc.createElement("summary"), ...holder.childNodes);
|
|
77
|
+
details.firstChild.textContent = holder.dataset.label;
|
|
78
|
+
holder.append(details);
|
|
79
|
+
named.set(details.firstChild, fill(ds.mtRegionNamed || "[label], [name]", { label: holder.dataset.label, name }));
|
|
80
|
+
const draw = (still) => new win.Chart(canvas, chartConfig(fig, data, still || query("(prefers-reduced-motion: reduce)")));
|
|
81
|
+
const item = { draw };
|
|
82
|
+
drawn.push(item);
|
|
83
|
+
later.set(box, () => (item.chart = draw()));
|
|
84
|
+
if (io) {
|
|
85
|
+
io.observe(box);
|
|
86
|
+
} else {
|
|
87
|
+
later.get(box)();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// Each disclosure is named after its chart, so two charts on a page do not read as the same toggle.
|
|
91
|
+
const count = {};
|
|
92
|
+
const seen = {};
|
|
93
|
+
named.forEach((n) => (count[n] = (count[n] || 0) + 1));
|
|
94
|
+
named.forEach((n, summary) => {
|
|
95
|
+
seen[n] = (seen[n] || 0) + 1;
|
|
96
|
+
summary.setAttribute("aria-label", count[n] > 1 ? fill(ds.mtRegionNth || "[name] [n]", { name: n, n: seen[n] }) : n);
|
|
97
|
+
});
|
|
98
|
+
onThemeChange(() => drawn.forEach((d) => {
|
|
99
|
+
if (d.chart) {
|
|
100
|
+
d.chart.destroy();
|
|
101
|
+
d.chart = d.draw(true);
|
|
102
|
+
}
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
init(document);
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// c: install sections. The Install button shows only while the browser offers installing (beforeinstallprompt; an offer
|
|
2
|
+
// that came before this module ran is kept on the manifest link by pwa/register.js) and prompts only on a click. Inside
|
|
3
|
+
// the installed app the sections hide. Nothing is stored and the user agent is never read.
|
|
4
|
+
const APP = "(display-mode: standalone), (display-mode: minimal-ui)";
|
|
5
|
+
|
|
6
|
+
export function init(root) {
|
|
7
|
+
const doc = root.ownerDocument || root;
|
|
8
|
+
const win = doc.defaultView;
|
|
9
|
+
const buttons = [...root.querySelectorAll("button.mt-install")];
|
|
10
|
+
if (!buttons.length) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (win.navigator.standalone === true || win.matchMedia?.(APP).matches) {
|
|
14
|
+
for (const b of buttons) {
|
|
15
|
+
b.closest(".mt-c-install")?.setAttribute("hidden", "");
|
|
16
|
+
}
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
let offer = null;
|
|
20
|
+
const show = (e) => {
|
|
21
|
+
offer = e;
|
|
22
|
+
for (const b of buttons) {
|
|
23
|
+
b.hidden = !e;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
win.addEventListener("beforeinstallprompt", (e) => {
|
|
27
|
+
e.preventDefault();
|
|
28
|
+
show(e);
|
|
29
|
+
});
|
|
30
|
+
win.addEventListener("appinstalled", () => show(null));
|
|
31
|
+
for (const b of buttons) {
|
|
32
|
+
b.addEventListener("click", async () => {
|
|
33
|
+
const e = offer;
|
|
34
|
+
if (!e) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
offer = null;
|
|
38
|
+
try {
|
|
39
|
+
await e.prompt();
|
|
40
|
+
await e.userChoice;
|
|
41
|
+
} catch {
|
|
42
|
+
// A prompt the browser refuses (already shown) leaves the page as it is.
|
|
43
|
+
}
|
|
44
|
+
const focused = doc.activeElement == b;
|
|
45
|
+
show(null);
|
|
46
|
+
// The button is gone; its hint keeps the reader's place.
|
|
47
|
+
const hint = b.parentElement.querySelector(".mt-install-hint");
|
|
48
|
+
if (focused && hint) {
|
|
49
|
+
hint.tabIndex = -1;
|
|
50
|
+
hint.focus();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
const early = doc.querySelector("link[rel=manifest]")?.mtInstall;
|
|
55
|
+
if (early) {
|
|
56
|
+
show(early);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
init(document);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// The offline page's list of pages this site's worker keeps (layout pages/offline). Titles are read from the cached
|
|
2
|
+
// copies with DOMParser and inserted as text, never as markup.
|
|
3
|
+
export async function init(root) {
|
|
4
|
+
const doc = root.ownerDocument || root;
|
|
5
|
+
const win = doc.defaultView;
|
|
6
|
+
const box = root.querySelector("[data-mt-offline]");
|
|
7
|
+
const link = doc.querySelector("link[rel=manifest][data-mt-scope]");
|
|
8
|
+
if (!box || !link || !win.caches) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const list = box.querySelector("ul");
|
|
12
|
+
const pages = "mt:" + link.dataset.mtScope + ":pages:";
|
|
13
|
+
const seen = new Set();
|
|
14
|
+
for (const name of await win.caches.keys()) {
|
|
15
|
+
const cache = name.startsWith(pages) ? await win.caches.open(name) : null;
|
|
16
|
+
for (const req of cache ? await cache.keys() : []) {
|
|
17
|
+
const url = new win.URL(req.url);
|
|
18
|
+
if (!/\/$|\.html$/.test(url.pathname) || url.pathname.endsWith("/offline/") || seen.has(url.href)) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
seen.add(url.href);
|
|
22
|
+
const html = await (await cache.match(req)).text();
|
|
23
|
+
const title = new win.DOMParser().parseFromString(html, "text/html").title || url.pathname;
|
|
24
|
+
const a = doc.createElement("a");
|
|
25
|
+
a.href = url.href;
|
|
26
|
+
a.textContent = title;
|
|
27
|
+
list.appendChild(doc.createElement("li")).appendChild(a);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
box.hidden = !list.children.length;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
init(document);
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Registers the site's service worker after load (modootoday.pwa). A first, uncontrolled visit posts the URLs it fetched to
|
|
2
|
+
// the worker; a waiting worker and a lost network get a notice (pwa/update-toast.js); a window shown after an hour checks
|
|
3
|
+
// for a new sw.js. An early install offer is kept for pwa/install.js.
|
|
4
|
+
const HOUR = 36e5;
|
|
5
|
+
|
|
6
|
+
export function init(root) {
|
|
7
|
+
const doc = root.ownerDocument || root;
|
|
8
|
+
const win = doc.defaultView;
|
|
9
|
+
const sw = win.navigator.serviceWorker;
|
|
10
|
+
const link = doc.querySelector("link[rel=manifest][data-mt-sw]");
|
|
11
|
+
if (!link || !sw) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
// The browser can offer installing before pwa/install.js runs; keep the offer for it, only where a button waits.
|
|
15
|
+
if (doc.querySelector("button.mt-install")) {
|
|
16
|
+
win.addEventListener("beforeinstallprompt", (e) => {
|
|
17
|
+
e.preventDefault();
|
|
18
|
+
link.mtInstall = e;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
const scope = new win.URL(link.dataset.mtScope, win.location.href).href;
|
|
22
|
+
const first = !sw.controller;
|
|
23
|
+
const toast = () => import("./update-toast.js");
|
|
24
|
+
// The offline page says so itself.
|
|
25
|
+
const offline = () => {
|
|
26
|
+
if (!doc.querySelector("[data-mt-offline]")) {
|
|
27
|
+
toast().then((m) => m.offline(doc)).catch(() => {});
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
win.addEventListener("offline", offline);
|
|
31
|
+
if (win.navigator.onLine === false) {
|
|
32
|
+
offline();
|
|
33
|
+
}
|
|
34
|
+
const watch = (reg) => {
|
|
35
|
+
// Only new theme files (a second assets cache) make a worker wait. Loading the notice through the leaving worker
|
|
36
|
+
// while another takes over by itself keeps it busy, and Chromium then never activates the new one.
|
|
37
|
+
const notify = async () => {
|
|
38
|
+
const names = reg.waiting && sw.controller ? await win.caches.keys().catch(() => []) : [];
|
|
39
|
+
if (names.filter((n) => n.startsWith("mt:" + link.dataset.mtScope + ":assets:")).length > 1) {
|
|
40
|
+
toast().then((m) => m.update(doc, reg)).catch(() => {});
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
reg.addEventListener("updatefound", () => {
|
|
44
|
+
const next = reg.installing;
|
|
45
|
+
next?.addEventListener("statechange", () => {
|
|
46
|
+
if (next.state == "installed") {
|
|
47
|
+
notify();
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
notify();
|
|
52
|
+
let checked = Date.now();
|
|
53
|
+
doc.addEventListener("visibilitychange", () => {
|
|
54
|
+
if (doc.visibilityState == "visible" && Date.now() - checked > HOUR) {
|
|
55
|
+
checked = Date.now();
|
|
56
|
+
reg.update().catch(() => {});
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
const start = () => {
|
|
61
|
+
sw.register(link.dataset.mtSw, { scope }).then((reg) => {
|
|
62
|
+
watch(reg);
|
|
63
|
+
return first ? sw.ready : null;
|
|
64
|
+
}).then((reg) => {
|
|
65
|
+
const page = win.location.href.split("#")[0];
|
|
66
|
+
const urls = win.performance.getEntriesByType("resource").map((e) => e.name).concat(page);
|
|
67
|
+
if (reg && reg.active) {
|
|
68
|
+
reg.active.postMessage({ type: "mt:warm", urls: urls.filter((u) => u.startsWith(scope)) });
|
|
69
|
+
}
|
|
70
|
+
}).catch(() => {});
|
|
71
|
+
};
|
|
72
|
+
if (doc.readyState == "complete") {
|
|
73
|
+
start();
|
|
74
|
+
} else {
|
|
75
|
+
win.addEventListener("load", start, { once: true });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
init(document);
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// The PWA notice (pwa/register.js): one status line, shown once its sheet loads; it never takes focus or reloads by itself.
|
|
2
|
+
const LINK = "link[rel=manifest][data-mt-toast-css]";
|
|
3
|
+
|
|
4
|
+
export function close(doc) {
|
|
5
|
+
doc.querySelector(".mt-toast")?.replaceChildren();
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// The region goes in empty, so screen readers announce the text that follows.
|
|
9
|
+
function region(doc) {
|
|
10
|
+
let box = doc.querySelector(".mt-toast");
|
|
11
|
+
if (!box) {
|
|
12
|
+
box = doc.createElement("div");
|
|
13
|
+
box.className = "mt-toast";
|
|
14
|
+
box.setAttribute("role", "status");
|
|
15
|
+
doc.body.append(box);
|
|
16
|
+
box.mtSheet = new Promise((done) => {
|
|
17
|
+
const css = doc.createElement("link");
|
|
18
|
+
css.rel = "stylesheet";
|
|
19
|
+
css.href = doc.querySelector(LINK).dataset.mtToastCss;
|
|
20
|
+
css.addEventListener("load", done);
|
|
21
|
+
css.addEventListener("error", done);
|
|
22
|
+
doc.head.append(css);
|
|
23
|
+
});
|
|
24
|
+
doc.addEventListener("keydown", (e) => {
|
|
25
|
+
if (e.key == "Escape" && !e.defaultPrevented) {
|
|
26
|
+
close(doc);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return box;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function show(doc, text, buttons) {
|
|
34
|
+
const box = region(doc);
|
|
35
|
+
await box.mtSheet;
|
|
36
|
+
const p = doc.createElement("p");
|
|
37
|
+
p.textContent = text;
|
|
38
|
+
const row = doc.createElement("div");
|
|
39
|
+
row.className = "mt-toast-actions";
|
|
40
|
+
for (const [label, fn] of buttons) {
|
|
41
|
+
const b = row.appendChild(doc.createElement("button"));
|
|
42
|
+
b.type = "button";
|
|
43
|
+
b.textContent = label;
|
|
44
|
+
b.addEventListener("click", fn);
|
|
45
|
+
}
|
|
46
|
+
box.replaceChildren(p, row);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// pwa/register.js loads this only when the waiting worker brings new theme files (a second assets cache).
|
|
50
|
+
export async function update(doc, reg) {
|
|
51
|
+
const win = doc.defaultView;
|
|
52
|
+
const d = doc.querySelector(LINK).dataset;
|
|
53
|
+
if (!reg.waiting) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const reload = () => {
|
|
57
|
+
win.navigator.serviceWorker.addEventListener("controllerchange", () => win.location.reload(), { once: true });
|
|
58
|
+
if (reg.waiting) {
|
|
59
|
+
reg.waiting.postMessage({ type: "mt:skip" });
|
|
60
|
+
} else {
|
|
61
|
+
win.location.reload();
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
await show(doc, d.mtUpdate, [[d.mtReload, reload], [d.mtLater, () => close(doc)]]);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// A lost network, as the browser reports it (pwa/register.js). A waiting update keeps its notice.
|
|
68
|
+
export async function offline(doc) {
|
|
69
|
+
const d = doc.querySelector(LINK).dataset;
|
|
70
|
+
if (doc.querySelector(".mt-toast button")) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
doc.defaultView.addEventListener("online", () => close(doc), { once: true });
|
|
74
|
+
await show(doc, d.mtOfflineNotice, [[d.mtClose, () => close(doc)]]);
|
|
75
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// Service worker strategies; the site's sw.js sets self.MT_PWA (docs: recipes/pwa).
|
|
2
|
+
((sw) => {
|
|
3
|
+
const C = sw.MT_PWA;
|
|
4
|
+
const prefix = "mt:" + C.scope + ":";
|
|
5
|
+
const ASSETS = prefix + "assets:" + C.assets;
|
|
6
|
+
// Pages follow the theme files, not the build: a deploy that keeps them keeps what a reader saved for offline.
|
|
7
|
+
const PAGES = prefix + "pages:" + C.assets;
|
|
8
|
+
const MEDIA = prefix + "media";
|
|
9
|
+
const THEME = new RegExp("^" + C.scope + "assets/(css|js)/modootoday");
|
|
10
|
+
const NETWORK = /(\.md|\/llms[^/]*\.txt|\/feed[^/]*\.xml|\/sitemap\.xml|\.webmanifest|\/sw\.js)$/;
|
|
11
|
+
const MEDIA_FILE = /\.(png|jpe?g|gif|webp|avif|svg|ico|woff2?|ttf|otf)$/;
|
|
12
|
+
const pinned = C.precache.map((u) => new URL(u, sw.location).href);
|
|
13
|
+
const noop = () => {};
|
|
14
|
+
|
|
15
|
+
const kind = (req) => {
|
|
16
|
+
const url = new URL(req.url);
|
|
17
|
+
const path = url.pathname;
|
|
18
|
+
if (req.method != "GET" || url.origin != sw.location.origin || !path.startsWith(C.scope) || req.headers.has("range")) {
|
|
19
|
+
return "";
|
|
20
|
+
}
|
|
21
|
+
if (THEME.test(path)) {
|
|
22
|
+
return "assets";
|
|
23
|
+
}
|
|
24
|
+
if (NETWORK.test(path)) {
|
|
25
|
+
return "";
|
|
26
|
+
}
|
|
27
|
+
if (req.mode == "navigate" || /\/$|\.html$/.test(path)) {
|
|
28
|
+
return "page";
|
|
29
|
+
}
|
|
30
|
+
if (path == C.scope + "search.json") {
|
|
31
|
+
return "search";
|
|
32
|
+
}
|
|
33
|
+
return req.destination == "image" || req.destination == "font" || MEDIA_FILE.test(path) ? "media" : "site";
|
|
34
|
+
};
|
|
35
|
+
const bucket = (k) => (k == "assets" ? ASSETS : k == "media" ? MEDIA : PAGES);
|
|
36
|
+
const ok = (res) => res && res.ok && !res.redirected;
|
|
37
|
+
// Never recreate a cache a kill or newer worker deleted: install opens ASSETS first, so without it this worker is leaving.
|
|
38
|
+
const cached = (name, req) => caches.match(req, { cacheName: name });
|
|
39
|
+
// Re-putting moves an entry last, so trimming the first keeps the recently used.
|
|
40
|
+
const put = async (name, req, res, max) => {
|
|
41
|
+
if (!(await caches.has(ASSETS))) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const cache = await caches.open(name);
|
|
45
|
+
await cache.delete(req);
|
|
46
|
+
await cache.put(req, res);
|
|
47
|
+
const old = (await cache.keys()).filter((k) => !pinned.includes(k.url));
|
|
48
|
+
for (const k of old.slice(0, max ? Math.max(0, old.length - max) : 0)) {
|
|
49
|
+
await cache.delete(k);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const store = async (k, req) => {
|
|
53
|
+
const res = await fetch(req);
|
|
54
|
+
if (!ok(res)) {
|
|
55
|
+
throw new Error(req.url);
|
|
56
|
+
}
|
|
57
|
+
await put(bucket(k), req, res);
|
|
58
|
+
};
|
|
59
|
+
const offline = (url) => {
|
|
60
|
+
const path = new URL(url).pathname;
|
|
61
|
+
const best = Object.keys(C.offline).filter((p) => path.startsWith(p)).sort((a, b) => b.length - a.length)[0];
|
|
62
|
+
return cached(PAGES, C.offline[best]);
|
|
63
|
+
};
|
|
64
|
+
const fresh = async (e, k) => {
|
|
65
|
+
const req = e.request;
|
|
66
|
+
const nav = req.mode == "navigate";
|
|
67
|
+
let res;
|
|
68
|
+
try {
|
|
69
|
+
res = (nav && (await e.preloadResponse)) || (await fetch(req));
|
|
70
|
+
} catch (err) {
|
|
71
|
+
const copy = await cached(PAGES, req);
|
|
72
|
+
if (copy || !nav) {
|
|
73
|
+
return copy || Promise.reject(err);
|
|
74
|
+
}
|
|
75
|
+
return offline(req.url);
|
|
76
|
+
}
|
|
77
|
+
if (ok(res)) {
|
|
78
|
+
e.waitUntil(put(PAGES, req, res.clone(), k == "page" ? 50 : 0).catch(noop));
|
|
79
|
+
} else if (res.status >= 500) {
|
|
80
|
+
return (await cached(PAGES, req)) || res;
|
|
81
|
+
}
|
|
82
|
+
return res;
|
|
83
|
+
};
|
|
84
|
+
const kept = async (e, k) => {
|
|
85
|
+
const req = e.request;
|
|
86
|
+
const name = bucket(k);
|
|
87
|
+
const copy = await cached(name, req);
|
|
88
|
+
if (copy && k == "assets") {
|
|
89
|
+
return copy;
|
|
90
|
+
}
|
|
91
|
+
const net = fetch(req).then((res) => {
|
|
92
|
+
if (ok(res)) {
|
|
93
|
+
e.waitUntil(put(name, req, res.clone(), k == "media" ? 60 : 0).catch(noop));
|
|
94
|
+
}
|
|
95
|
+
return res;
|
|
96
|
+
});
|
|
97
|
+
e.waitUntil(net.catch(noop));
|
|
98
|
+
return copy || net;
|
|
99
|
+
};
|
|
100
|
+
// Only a missing offline page fails the install. With the theme files of the worker before (their cache is there) only
|
|
101
|
+
// pages changed, which are network first, so this worker takes over at once; new theme files wait for the notice.
|
|
102
|
+
sw.addEventListener("install", (e) => {
|
|
103
|
+
const pages = Object.values(C.offline);
|
|
104
|
+
e.waitUntil((async () => {
|
|
105
|
+
if (await caches.has(ASSETS)) {
|
|
106
|
+
sw.skipWaiting();
|
|
107
|
+
}
|
|
108
|
+
await caches.open(ASSETS);
|
|
109
|
+
await Promise.all(C.precache.map((u) => {
|
|
110
|
+
const req = new Request(u, { cache: "reload" });
|
|
111
|
+
const done = store(kind(req) || "page", req);
|
|
112
|
+
return pages.includes(u) ? done : done.catch(noop);
|
|
113
|
+
}));
|
|
114
|
+
})());
|
|
115
|
+
});
|
|
116
|
+
sw.addEventListener("activate", (e) => {
|
|
117
|
+
const keep = [ASSETS, PAGES, MEDIA];
|
|
118
|
+
e.waitUntil((async () => {
|
|
119
|
+
for (const n of await caches.keys()) {
|
|
120
|
+
if (n.startsWith(prefix) && !keep.includes(n)) {
|
|
121
|
+
await caches.delete(n);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
await (sw.registration.navigationPreload && sw.registration.navigationPreload.enable());
|
|
125
|
+
await sw.clients.claim();
|
|
126
|
+
})());
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
sw.addEventListener("fetch", (e) => {
|
|
130
|
+
try {
|
|
131
|
+
const k = kind(e.request);
|
|
132
|
+
if (k) {
|
|
133
|
+
e.respondWith((k == "page" || k == "site" ? fresh(e, k) : kept(e, k)).catch(() => fetch(e.request)));
|
|
134
|
+
}
|
|
135
|
+
} catch (err) {}
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// mt:skip: Reload in pwa/update-toast.js. mt:warm: what the first, uncontrolled page loaded (an offline start is styled).
|
|
139
|
+
sw.addEventListener("message", (e) => {
|
|
140
|
+
if (e.data && e.data.type == "mt:skip") {
|
|
141
|
+
sw.skipWaiting();
|
|
142
|
+
}
|
|
143
|
+
const urls = e.data && e.data.type == "mt:warm" && Array.isArray(e.data.urls) ? e.data.urls : [];
|
|
144
|
+
e.waitUntil(Promise.all(urls.map((u) => {
|
|
145
|
+
const req = new Request(u);
|
|
146
|
+
const k = kind(req);
|
|
147
|
+
return k ? store(k, req).catch(noop) : 0;
|
|
148
|
+
})));
|
|
149
|
+
});
|
|
150
|
+
})(self);
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// "On this page": the link of the section being read gets aria-current="location" (adr:modootoday/20261110172642).
|
|
2
|
+
// Observers only wake it; one frame then reads the heading positions. It never scrolls the page.
|
|
3
|
+
const decode = (s) => {
|
|
4
|
+
try {
|
|
5
|
+
return decodeURIComponent(s);
|
|
6
|
+
} catch (e) {
|
|
7
|
+
return s;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
const idOf = (a) => decode(a.getAttribute("href").slice(1));
|
|
11
|
+
|
|
12
|
+
// Per list, the link that marks each heading: the sticky column hides h3, so there an h3 marks its h2.
|
|
13
|
+
function links(list) {
|
|
14
|
+
const column = !!list.closest(".mt-doc-aside");
|
|
15
|
+
const map = new Map();
|
|
16
|
+
let h2;
|
|
17
|
+
for (const a of list.querySelectorAll("li > a[href^='#']")) {
|
|
18
|
+
const h3 = a.parentNode.classList.contains("mt-toc-h3");
|
|
19
|
+
h2 = h3 ? h2 : a;
|
|
20
|
+
map.set(idOf(a), (column && h3 && h2) || a);
|
|
21
|
+
}
|
|
22
|
+
return { list, column, map };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function init(root) {
|
|
26
|
+
const doc = root.ownerDocument || root;
|
|
27
|
+
const win = doc.defaultView;
|
|
28
|
+
const html = doc.documentElement;
|
|
29
|
+
const lists = [...root.querySelectorAll(".mt-toc, .mt-toc-mobile")].map(links);
|
|
30
|
+
if (!lists.length || !win.IntersectionObserver) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const ids = new Set(lists.flatMap((l) => [...l.map.keys()]));
|
|
34
|
+
const heads = [...ids].map((id) => [id, doc.getElementById(id)]).filter((h) => h[1]);
|
|
35
|
+
const top = (i) => heads[i][1].getBoundingClientRect().top;
|
|
36
|
+
let current;
|
|
37
|
+
let pin = -1;
|
|
38
|
+
let queued;
|
|
39
|
+
const line = () => {
|
|
40
|
+
const header = doc.querySelector(".mt-header");
|
|
41
|
+
const rem = parseFloat(win.getComputedStyle(html).fontSize) || 16;
|
|
42
|
+
return Math.max(0, header ? header.getBoundingClientRect().bottom : 0) + rem;
|
|
43
|
+
};
|
|
44
|
+
const mark = (i) => {
|
|
45
|
+
const id = i < 0 ? null : heads[i][0];
|
|
46
|
+
if (id === current) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
current = id;
|
|
50
|
+
for (const { list, column, map } of lists) {
|
|
51
|
+
list.querySelectorAll("[aria-current]").forEach((a) => a.removeAttribute("aria-current"));
|
|
52
|
+
const a = map.get(id);
|
|
53
|
+
if (a) {
|
|
54
|
+
a.setAttribute("aria-current", "location");
|
|
55
|
+
}
|
|
56
|
+
// The column scrolls on its own; the marked link is kept inside its visible part, without smooth scrolling.
|
|
57
|
+
if (a && column) {
|
|
58
|
+
const r = a.getBoundingClientRect();
|
|
59
|
+
const b = list.getBoundingClientRect();
|
|
60
|
+
list.scrollTop += Math.min(0, r.top - b.top) || Math.max(0, r.bottom - b.bottom);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const update = () => {
|
|
65
|
+
queued = false;
|
|
66
|
+
const y = line() + 1;
|
|
67
|
+
const view = win.innerHeight;
|
|
68
|
+
const bottom = view + win.scrollY >= html.scrollHeight - 2;
|
|
69
|
+
let at = -1;
|
|
70
|
+
heads.forEach((h, i) => {
|
|
71
|
+
// A heading with no box (in a closed tab panel) reports a top of 0 and would read as already passed.
|
|
72
|
+
if (!h[1].getClientRects().length) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (top(i) <= y || (bottom && win.scrollY > 0 && top(i) < view)) {
|
|
76
|
+
at = i;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
// A followed link the page cannot bring up to the line (a short last section) stays marked while it is in view.
|
|
80
|
+
if (pin >= 0 && bottom && top(pin) >= 0 && top(pin) < view) {
|
|
81
|
+
at = pin;
|
|
82
|
+
} else {
|
|
83
|
+
pin = -1;
|
|
84
|
+
}
|
|
85
|
+
mark(at);
|
|
86
|
+
};
|
|
87
|
+
const wake = () => {
|
|
88
|
+
if (!queued) {
|
|
89
|
+
queued = true;
|
|
90
|
+
win.requestAnimationFrame(update);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const jump = (id) => {
|
|
94
|
+
const i = heads.findIndex((h) => h[0] === id);
|
|
95
|
+
if (i >= 0) {
|
|
96
|
+
pin = i;
|
|
97
|
+
mark(i);
|
|
98
|
+
}
|
|
99
|
+
wake();
|
|
100
|
+
};
|
|
101
|
+
const io = new win.IntersectionObserver(wake, { rootMargin: `-${Math.round(line())}px 0px 0px 0px`, threshold: [0, 1] });
|
|
102
|
+
heads.forEach((h) => io.observe(h[1]));
|
|
103
|
+
const foot = doc.querySelector(".mt-footer");
|
|
104
|
+
if (foot) {
|
|
105
|
+
io.observe(foot);
|
|
106
|
+
}
|
|
107
|
+
for (const { list } of lists) {
|
|
108
|
+
list.addEventListener("click", (e) => {
|
|
109
|
+
const a = e.target.closest("a[href^='#']");
|
|
110
|
+
if (a) {
|
|
111
|
+
jump(idOf(a));
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
const hash = () => jump(decode(win.location.hash.slice(1)));
|
|
116
|
+
win.addEventListener("hashchange", hash);
|
|
117
|
+
win.addEventListener("scrollend", wake);
|
|
118
|
+
hash();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
init(document);
|
|
Binary file
|
|
Binary file
|
|
Binary file
|