marksites 0.2.3 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/cli.js +0 -0
- package/dist/features/annotations/index.js +24 -6
- package/dist/features/file-tree/index.js +20 -5
- package/dist/features/header/index.js +2 -2
- package/dist/template/styles.d.ts +1 -1
- package/dist/template/styles.js +16 -10
- package/dist/utils/icons.d.ts +1 -0
- package/dist/utils/icons.js +3 -0
- package/package.json +1 -1
- package/dist/features/annotations.d.ts +0 -9
- package/dist/features/annotations.js +0 -78
- package/dist/features/code-blocks.d.ts +0 -5
- package/dist/features/code-blocks.js +0 -89
- package/dist/features/file-tree.d.ts +0 -7
- package/dist/features/file-tree.js +0 -325
- package/dist/features/header.d.ts +0 -6
- package/dist/features/header.js +0 -47
- package/dist/features/sidebar.d.ts +0 -13
- package/dist/features/sidebar.js +0 -55
- package/dist/features/table-of-contents.d.ts +0 -16
- package/dist/features/table-of-contents.js +0 -91
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import GithubSlugger from "github-slugger";
|
|
2
|
-
import { escapeHtml, plainTextFromHtml } from "../utils/html.js";
|
|
3
|
-
function renderTableOfContents(items, title, minDepth) {
|
|
4
|
-
if (items.length === 0)
|
|
5
|
-
return "";
|
|
6
|
-
const links = items
|
|
7
|
-
.map(({ depth, id, text }) => ` <li style="--toc-level: ${depth - minDepth}"><a href="#${escapeHtml(id)}">${escapeHtml(text)}</a></li>`)
|
|
8
|
-
.join("\n");
|
|
9
|
-
const escapedTitle = escapeHtml(title);
|
|
10
|
-
return `<nav class="table-of-contents sidebar-panel" id="sidebar-panel-toc" role="tabpanel" aria-labelledby="sidebar-tab-toc" aria-label="${escapedTitle}">
|
|
11
|
-
<div class="toc-panel">
|
|
12
|
-
<ul>
|
|
13
|
-
${links}
|
|
14
|
-
</ul>
|
|
15
|
-
</div>
|
|
16
|
-
</nav>
|
|
17
|
-
`;
|
|
18
|
-
}
|
|
19
|
-
function renderTableOfContentsScript() {
|
|
20
|
-
return `<script>
|
|
21
|
-
(() => {
|
|
22
|
-
const navigation = document.querySelector('.table-of-contents');
|
|
23
|
-
if (!navigation) return;
|
|
24
|
-
|
|
25
|
-
const panel = navigation.querySelector('.toc-panel');
|
|
26
|
-
const links = [...panel.querySelectorAll('a[href^="#"]')];
|
|
27
|
-
const entries = links
|
|
28
|
-
.map((link) => ({ link, heading: document.getElementById(link.getAttribute('href').slice(1)) }))
|
|
29
|
-
.filter((entry) => entry.heading);
|
|
30
|
-
if (entries.length === 0) return;
|
|
31
|
-
|
|
32
|
-
let scheduled = false;
|
|
33
|
-
const update = () => {
|
|
34
|
-
scheduled = false;
|
|
35
|
-
const marker = Math.min(160, window.innerHeight * 0.25);
|
|
36
|
-
let active = entries[0];
|
|
37
|
-
|
|
38
|
-
for (const entry of entries) {
|
|
39
|
-
if (entry.heading.getBoundingClientRect().top > marker) break;
|
|
40
|
-
active = entry;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
for (const entry of entries) {
|
|
44
|
-
if (entry === active) entry.link.setAttribute('aria-current', 'location');
|
|
45
|
-
else entry.link.removeAttribute('aria-current');
|
|
46
|
-
}
|
|
47
|
-
const navigationRect = navigation.getBoundingClientRect();
|
|
48
|
-
const activeRect = active.link.getBoundingClientRect();
|
|
49
|
-
if (!navigation.hidden && (activeRect.top < navigationRect.top || activeRect.bottom > navigationRect.bottom)) {
|
|
50
|
-
navigation.scrollTop += activeRect.top - navigationRect.top - navigation.clientHeight / 2;
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
const schedule = () => {
|
|
54
|
-
if (scheduled) return;
|
|
55
|
-
scheduled = true;
|
|
56
|
-
requestAnimationFrame(update);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
addEventListener('scroll', schedule, { passive: true });
|
|
60
|
-
addEventListener('resize', schedule);
|
|
61
|
-
update();
|
|
62
|
-
})();
|
|
63
|
-
</script>`;
|
|
64
|
-
}
|
|
65
|
-
export function createTableOfContentsFeature(renderer, config) {
|
|
66
|
-
const items = [];
|
|
67
|
-
const slugger = new GithubSlugger();
|
|
68
|
-
renderer.heading = ({ tokens, depth }) => {
|
|
69
|
-
const renderedText = renderer.parser.parseInline(tokens);
|
|
70
|
-
const plainText = plainTextFromHtml(renderedText);
|
|
71
|
-
const id = slugger.slug(plainText);
|
|
72
|
-
if (config.enabled &&
|
|
73
|
-
depth >= config.minDepth &&
|
|
74
|
-
depth <= config.maxDepth) {
|
|
75
|
-
items.push({ depth, id, text: plainText });
|
|
76
|
-
}
|
|
77
|
-
return `<h${depth} id="${escapeHtml(id)}">${renderedText}</h${depth}>\n`;
|
|
78
|
-
};
|
|
79
|
-
return {
|
|
80
|
-
render() {
|
|
81
|
-
const markup = config.enabled
|
|
82
|
-
? renderTableOfContents(items, config.title, config.minDepth)
|
|
83
|
-
: "";
|
|
84
|
-
return {
|
|
85
|
-
markup,
|
|
86
|
-
script: markup ? renderTableOfContentsScript() : "",
|
|
87
|
-
title: config.title,
|
|
88
|
-
};
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
}
|