@tenphi/renderer 0.19.0 → 0.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
//#region src/client/table-of-contents.ts
|
|
2
|
+
var CookbookTableOfContents = class extends HTMLElement {
|
|
3
|
+
#entries = [];
|
|
4
|
+
#active;
|
|
5
|
+
#listeners;
|
|
6
|
+
#frame = 0;
|
|
7
|
+
connectedCallback() {
|
|
8
|
+
this.#listeners?.abort();
|
|
9
|
+
this.#listeners = new AbortController();
|
|
10
|
+
this.#entries = Array.from(this.querySelectorAll("nav a[href^=\"#\"]")).flatMap((link) => {
|
|
11
|
+
const heading = document.getElementById(decodeURIComponent(link.hash.slice(1)));
|
|
12
|
+
return heading ? [{
|
|
13
|
+
link,
|
|
14
|
+
heading
|
|
15
|
+
}] : [];
|
|
16
|
+
});
|
|
17
|
+
if (this.#entries.length === 0) return;
|
|
18
|
+
const options = { signal: this.#listeners.signal };
|
|
19
|
+
window.addEventListener("scroll", this.#schedule, {
|
|
20
|
+
...options,
|
|
21
|
+
passive: true
|
|
22
|
+
});
|
|
23
|
+
window.addEventListener("resize", this.#schedule, options);
|
|
24
|
+
window.addEventListener("hashchange", this.#schedule, options);
|
|
25
|
+
this.#schedule();
|
|
26
|
+
}
|
|
27
|
+
disconnectedCallback() {
|
|
28
|
+
this.#listeners?.abort();
|
|
29
|
+
cancelAnimationFrame(this.#frame);
|
|
30
|
+
}
|
|
31
|
+
#schedule = () => {
|
|
32
|
+
if (!this.#frame) this.#frame = requestAnimationFrame(this.#sync);
|
|
33
|
+
};
|
|
34
|
+
#sync = () => {
|
|
35
|
+
this.#frame = 0;
|
|
36
|
+
const marker = (document.querySelector(".header")?.getBoundingClientRect().bottom ?? 0) + 24;
|
|
37
|
+
let current = this.#entries[0];
|
|
38
|
+
for (const entry of this.#entries) {
|
|
39
|
+
if (entry.heading.getBoundingClientRect().top > marker + 2) break;
|
|
40
|
+
current = entry;
|
|
41
|
+
}
|
|
42
|
+
if (window.scrollY > 0 && window.scrollY + window.innerHeight >= document.documentElement.scrollHeight - 2) current = this.#entries.at(-1);
|
|
43
|
+
if (!current || current.link === this.#active) return;
|
|
44
|
+
this.#active?.removeAttribute("aria-current");
|
|
45
|
+
current.link.setAttribute("aria-current", "location");
|
|
46
|
+
this.#active = current.link;
|
|
47
|
+
const sidebar = this.closest(".right-sidebar");
|
|
48
|
+
if (!sidebar || sidebar.getClientRects().length === 0) return;
|
|
49
|
+
const sidebarRect = sidebar.getBoundingClientRect();
|
|
50
|
+
const linkRect = current.link.getBoundingClientRect();
|
|
51
|
+
if (linkRect.top < sidebarRect.top + 16) sidebar.scrollTop += linkRect.top - sidebarRect.top - 16;
|
|
52
|
+
else if (linkRect.bottom > sidebarRect.bottom - 16) sidebar.scrollTop += linkRect.bottom - sidebarRect.bottom + 16;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
if (!customElements.get("cookbook-table-of-contents")) customElements.define("cookbook-table-of-contents", CookbookTableOfContents);
|
|
56
|
+
//#endregion
|
|
57
|
+
export {};
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=table-of-contents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-of-contents.js","names":[],"sources":["../../src/client/table-of-contents.ts"],"sourcesContent":["class CookbookTableOfContents extends HTMLElement {\n #entries: Array<{ link: HTMLAnchorElement; heading: HTMLElement }> = [];\n #active?: HTMLAnchorElement;\n #listeners?: AbortController;\n #frame = 0;\n\n connectedCallback() {\n this.#listeners?.abort();\n this.#listeners = new AbortController();\n this.#entries = Array.from(\n this.querySelectorAll<HTMLAnchorElement>('nav a[href^=\"#\"]'),\n ).flatMap((link) => {\n const heading = document.getElementById(\n decodeURIComponent(link.hash.slice(1)),\n );\n return heading ? [{ link, heading }] : [];\n });\n if (this.#entries.length === 0) return;\n\n const options = { signal: this.#listeners.signal };\n window.addEventListener(\"scroll\", this.#schedule, {\n ...options,\n passive: true,\n });\n window.addEventListener(\"resize\", this.#schedule, options);\n window.addEventListener(\"hashchange\", this.#schedule, options);\n this.#schedule();\n }\n\n disconnectedCallback() {\n this.#listeners?.abort();\n cancelAnimationFrame(this.#frame);\n }\n\n #schedule = () => {\n if (!this.#frame) this.#frame = requestAnimationFrame(this.#sync);\n };\n\n #sync = () => {\n this.#frame = 0;\n const header = document.querySelector<HTMLElement>(\".header\");\n const marker = (header?.getBoundingClientRect().bottom ?? 0) + 24;\n let current = this.#entries[0];\n for (const entry of this.#entries) {\n if (entry.heading.getBoundingClientRect().top > marker + 2) break;\n current = entry;\n }\n if (\n window.scrollY > 0 &&\n window.scrollY + window.innerHeight >=\n document.documentElement.scrollHeight - 2\n )\n current = this.#entries.at(-1);\n if (!current || current.link === this.#active) return;\n\n this.#active?.removeAttribute(\"aria-current\");\n current.link.setAttribute(\"aria-current\", \"location\");\n this.#active = current.link;\n\n const sidebar = this.closest<HTMLElement>(\".right-sidebar\");\n if (!sidebar || sidebar.getClientRects().length === 0) return;\n const sidebarRect = sidebar.getBoundingClientRect();\n const linkRect = current.link.getBoundingClientRect();\n if (linkRect.top < sidebarRect.top + 16)\n sidebar.scrollTop += linkRect.top - sidebarRect.top - 16;\n else if (linkRect.bottom > sidebarRect.bottom - 16)\n sidebar.scrollTop += linkRect.bottom - sidebarRect.bottom + 16;\n };\n}\n\nif (!customElements.get(\"cookbook-table-of-contents\"))\n customElements.define(\"cookbook-table-of-contents\", CookbookTableOfContents);\n"],"mappings":";AAAA,IAAM,0BAAN,cAAsC,YAAY;CAChD,WAAqE,CAAC;CACtE;CACA;CACA,SAAS;CAET,oBAAoB;EAClB,KAAK,YAAY,MAAM;EACvB,KAAK,aAAa,IAAI,gBAAgB;EACtC,KAAK,WAAW,MAAM,KACpB,KAAK,iBAAoC,oBAAkB,CAC7D,CAAC,CAAC,SAAS,SAAS;GAClB,MAAM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AM,WAAW,QAAQ,KAAK,sBAAsB;EACpD,IAAI,SAAS,MAAM,YAAY,MAAM,IACnC,QAAQ,aAAa,SAAS,MAAM,YAAY,MAAM;OACnD,IAAI,SAAS,SAAS,YAAY,SAAS,IAC9C,QAAQ,aAAa,SAAS,SAAS,YAAY,SAAS;CAChE;AACF;AAEA,IAAI,CAAC,eAAe,IAAI,4BAA4B,GAClD,eAAe,OAAO,8BAA8B,uBAAuB"}
|
|
@@ -781,7 +781,11 @@ export default function GlobalStyles() {
|
|
|
781
781
|
whiteSpace: "nowrap",
|
|
782
782
|
},
|
|
783
783
|
HoverLink: { $: "a:hover", color: "#text" },
|
|
784
|
-
CurrentLink: {
|
|
784
|
+
CurrentLink: {
|
|
785
|
+
$: 'a[aria-current="location"]',
|
|
786
|
+
color: "#accent-text",
|
|
787
|
+
preset: "small / strong",
|
|
788
|
+
},
|
|
785
789
|
}),
|
|
786
790
|
);
|
|
787
791
|
|
package/dist/routes/Page.astro
CHANGED
|
@@ -58,14 +58,14 @@ const indexed = route.id !== "/404" && data.pagefind !== false && !data.draft;
|
|
|
58
58
|
<aside class="right-sidebar-container cookbook-print-hidden">
|
|
59
59
|
<div class="right-sidebar">
|
|
60
60
|
<MobileTableOfContents />
|
|
61
|
-
<
|
|
61
|
+
<cookbook-table-of-contents class="right-sidebar-panel">
|
|
62
62
|
<h2>{Astro.locals.t("tableOfContents.onThisPage")}</h2>
|
|
63
63
|
<nav
|
|
64
64
|
aria-label={Astro.locals.t("tableOfContents.onThisPage")}
|
|
65
65
|
>
|
|
66
66
|
<TableOfContents items={route.toc.items} />
|
|
67
67
|
</nav>
|
|
68
|
-
</
|
|
68
|
+
</cookbook-table-of-contents>
|
|
69
69
|
</div>
|
|
70
70
|
</aside>
|
|
71
71
|
)
|
|
@@ -116,5 +116,8 @@ const indexed = route.id !== "/404" && data.pagefind !== false && !data.draft;
|
|
|
116
116
|
</div>
|
|
117
117
|
</div>
|
|
118
118
|
</PageFrame>
|
|
119
|
+
<script>
|
|
120
|
+
import "../client/table-of-contents.js";
|
|
121
|
+
</script>
|
|
119
122
|
</body>
|
|
120
123
|
</html>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tenphi/renderer",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.1",
|
|
4
4
|
"description": "Astro renderer and Tasty theme for Cookbook",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"@fontsource-variable/jetbrains-mono": "^5.3.0",
|
|
62
62
|
"@fontsource-variable/onest": "^5.3.0",
|
|
63
63
|
"@pagefind/default-ui": "1.5.2",
|
|
64
|
-
"@tenphi/docs": "0.19.
|
|
64
|
+
"@tenphi/docs": "0.19.1",
|
|
65
65
|
"@tenphi/eslint-plugin-tasty": "1.1.0",
|
|
66
66
|
"@tenphi/glaze": "2.0.0",
|
|
67
67
|
"@tenphi/tasty": "3.8.0",
|