@staticbolt/docs 0.0.1-beta.2 → 0.0.1-beta.3
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/package.json +1 -1
- package/sources/parts/callouts/callouts.part.html +2 -2
- package/sources/parts/color-scheme-switch/color-scheme-switch.part.html +1 -6
- package/sources/parts/pagination-links/pagination-links.part.html +6 -6
- package/sources/parts/sidebar/sidebar.part.html +8 -5
- package/sources/parts/table-of-content/table-of-content-desktop.part.html +8 -7
- package/sources/parts/table-of-content/table-of-content-mobile.part.html +6 -2
package/package.json
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
<script type="application/x-typescript" build-time>
|
|
3
3
|
for (const callout of document.querySelectorAll("details.callout")) {
|
|
4
4
|
const accordion = document.createElement("sv-accordion");
|
|
5
|
-
accordion.setAttribute("data-callout", callout.getAttribute("data-callout"));
|
|
6
|
-
accordion.setAttribute("class", callout.getAttribute("class"));
|
|
5
|
+
accordion.setAttribute("data-callout", callout.getAttribute("data-callout") || "");
|
|
6
|
+
accordion.setAttribute("class", callout.getAttribute("class") || "");
|
|
7
7
|
accordion.setAttribute("heading-level", "none");
|
|
8
8
|
|
|
9
9
|
if (callout.hasAttribute("open")) {
|
|
@@ -77,12 +77,7 @@
|
|
|
77
77
|
|
|
78
78
|
document.addEventListener("DOMContentLoaded", onReady, { once: true, passive: true });
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
* @param {() => void} update
|
|
82
|
-
* @param {number} x
|
|
83
|
-
* @param {number} y
|
|
84
|
-
*/
|
|
85
|
-
async function viewTransition(update, x, y) {
|
|
80
|
+
async function viewTransition(update: () => void, x: number, y: number) {
|
|
86
81
|
if (!document.startViewTransition || matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
87
82
|
update();
|
|
88
83
|
return;
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
// ::: Get current link and populate previous/next links :::
|
|
30
30
|
import { join, dirname, normalize } from "node:path";
|
|
31
31
|
|
|
32
|
-
const paginationPrev = document.querySelector(".pagination-link-prev")
|
|
33
|
-
const paginationPrevTitle = paginationPrev.querySelector(".link-title")
|
|
32
|
+
const paginationPrev = document.querySelector(".pagination-link-prev")!;
|
|
33
|
+
const paginationPrevTitle = paginationPrev.querySelector(".link-title")!;
|
|
34
34
|
|
|
35
|
-
const paginationNext = document.querySelector(".pagination-link-next")
|
|
36
|
-
const paginationNextTitle = paginationNext.querySelector(".link-title")
|
|
35
|
+
const paginationNext = document.querySelector(".pagination-link-next")!;
|
|
36
|
+
const paginationNextTitle = paginationNext.querySelector(".link-title")!;
|
|
37
37
|
|
|
38
38
|
// You can find `.sidebar` in the documentation layout
|
|
39
39
|
const navigationLinks = document.querySelectorAll(".sidebar a.sidebar-link");
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
const previousLink = navigationLinks[linkIndex - 1];
|
|
51
51
|
if (previousLink) {
|
|
52
52
|
const prevHref = previousLink.getAttribute("href");
|
|
53
|
-
paginationPrev.setAttribute("href", prevHref);
|
|
53
|
+
paginationPrev.setAttribute("href", prevHref || "#");
|
|
54
54
|
|
|
55
55
|
const prevTitle = previousLink.getAttribute("data-title") || previousLink.textContent;
|
|
56
56
|
paginationPrevTitle.textContent = prevTitle;
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
const nextLink = navigationLinks[linkIndex + 1];
|
|
63
63
|
if (nextLink) {
|
|
64
64
|
const nextHref = nextLink.getAttribute("href");
|
|
65
|
-
paginationNext.setAttribute("href", nextHref);
|
|
65
|
+
paginationNext.setAttribute("href", nextHref || "#");
|
|
66
66
|
|
|
67
67
|
const nextTitle = nextLink.getAttribute("data-title") || nextLink.textContent;
|
|
68
68
|
paginationNextTitle.textContent = nextTitle;
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
const navigationLinks = document.querySelectorAll(".sidebar a");
|
|
23
23
|
const currentFile = normalize(__filepath);
|
|
24
24
|
|
|
25
|
-
for (const [
|
|
25
|
+
for (const [, link] of navigationLinks.entries()) {
|
|
26
26
|
const linkPath = join(dirname(__filepath), link.attributes.href, "index.html");
|
|
27
27
|
if (linkPath !== currentFile) continue;
|
|
28
28
|
|
|
@@ -43,8 +43,10 @@
|
|
|
43
43
|
|
|
44
44
|
<!-- ::: Persist sidebar navigation state across page loads. ::: -->
|
|
45
45
|
<script type="application/x-typescript">
|
|
46
|
+
import type { Accordion } from "@staticview/ui/accordion";
|
|
47
|
+
|
|
46
48
|
(() => {
|
|
47
|
-
const accordions = document.querySelectorAll<
|
|
49
|
+
const accordions = document.querySelectorAll<Accordion>(".sidebar-accordion");
|
|
48
50
|
|
|
49
51
|
// ::: Restore the accordion's previous open state. :::
|
|
50
52
|
try {
|
|
@@ -67,7 +69,7 @@
|
|
|
67
69
|
|
|
68
70
|
// ::: Save accordion open state when toggled. :::
|
|
69
71
|
const accordionToggleHandler = () => {
|
|
70
|
-
const state = {};
|
|
72
|
+
const state: Record<string, boolean> = {};
|
|
71
73
|
|
|
72
74
|
for (const [accordionIndex, accordion] of accordions.entries()) {
|
|
73
75
|
state[accordionIndex] = accordion.opened;
|
|
@@ -81,7 +83,8 @@
|
|
|
81
83
|
}
|
|
82
84
|
|
|
83
85
|
// ::: Restore sidebar scroll position. :::
|
|
84
|
-
const sidebar = document.querySelector(".sidebar");
|
|
86
|
+
const sidebar = document.querySelector<HTMLElement>(".sidebar");
|
|
87
|
+
if (!sidebar) return;
|
|
85
88
|
|
|
86
89
|
const onReady = () => {
|
|
87
90
|
// First rAF: end of current task, second rAF: after first paint
|
|
@@ -97,7 +100,7 @@
|
|
|
97
100
|
|
|
98
101
|
// ::: Save sidebar scroll position. :::
|
|
99
102
|
const sidebarScrollHandler = () => {
|
|
100
|
-
sessionStorage.setItem("sidebar-scroll", sidebar.scrollTop);
|
|
103
|
+
sessionStorage.setItem("sidebar-scroll", String(sidebar.scrollTop));
|
|
101
104
|
};
|
|
102
105
|
|
|
103
106
|
sidebar.addEventListener("scroll", sidebarScrollHandler, { passive: true });
|
|
@@ -71,17 +71,18 @@
|
|
|
71
71
|
const links = document.querySelectorAll(".toc-list a");
|
|
72
72
|
|
|
73
73
|
// Mobile TOC current title
|
|
74
|
-
const currentTitle = document.querySelector(".toc-current-title");
|
|
74
|
+
const currentTitle = document.querySelector<HTMLElement>(".toc-current-title");
|
|
75
75
|
|
|
76
76
|
const headings = Array.from(links)
|
|
77
|
-
.map(a => document.getElementById(a.getAttribute("href")
|
|
78
|
-
.filter(Boolean);
|
|
77
|
+
.map(a => document.getElementById(a.getAttribute("href")?.slice(1) ?? ""))
|
|
78
|
+
.filter(Boolean) as HTMLElement[];
|
|
79
79
|
|
|
80
|
-
function setActive(id) {
|
|
80
|
+
function setActive(id: string) {
|
|
81
81
|
for (const link of links) {
|
|
82
82
|
const active = link.getAttribute("href") === "#" + id;
|
|
83
83
|
link.classList.toggle("active", active);
|
|
84
|
-
|
|
84
|
+
|
|
85
|
+
if (active && currentTitle) {
|
|
85
86
|
currentTitle.textContent = link.textContent;
|
|
86
87
|
}
|
|
87
88
|
}
|
|
@@ -90,8 +91,8 @@
|
|
|
90
91
|
function update() {
|
|
91
92
|
if (!headings.length) return;
|
|
92
93
|
|
|
93
|
-
|
|
94
|
-
scrollPaddingTop = parseFloat(
|
|
94
|
+
const scrollPaddingTopStyle = getComputedStyle(document.documentElement).getPropertyValue("scroll-padding-top");
|
|
95
|
+
let scrollPaddingTop = parseFloat(scrollPaddingTopStyle.replace("px", "").trim());
|
|
95
96
|
scrollPaddingTop = !isFinite(scrollPaddingTop) ? 50 : scrollPaddingTop + 2;
|
|
96
97
|
|
|
97
98
|
let active = headings[0];
|
|
@@ -13,12 +13,16 @@
|
|
|
13
13
|
|
|
14
14
|
<!-- ::: Close the accordion when a link is clicked ::: -->
|
|
15
15
|
<script type="application/x-typescript" module>
|
|
16
|
-
|
|
16
|
+
import type { Accordion } from "@staticview/ui/accordion";
|
|
17
|
+
|
|
18
|
+
const tocAccordion = document.querySelector<Accordion>(".toc-accordion");
|
|
17
19
|
const tocLinks = document.querySelectorAll(".toc-accordion a");
|
|
18
20
|
|
|
19
21
|
for (const link of tocLinks) {
|
|
20
22
|
link.addEventListener("click", () => {
|
|
21
|
-
tocAccordion
|
|
23
|
+
if (tocAccordion) {
|
|
24
|
+
tocAccordion.opened = false;
|
|
25
|
+
}
|
|
22
26
|
});
|
|
23
27
|
}
|
|
24
28
|
</script>
|