@xiee/utils 1.11.4 → 1.12.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/css/book.css +46 -0
- package/css/book.min.css +1 -0
- package/js/heading-anchor.js +2 -1
- package/js/heading-anchor.min.js +1 -1
- package/js/toc-highlight.js +14 -4
- package/js/toc-highlight.min.js +1 -1
- package/package.json +1 -1
package/css/book.css
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
body {
|
|
2
|
+
font-size: 1em;
|
|
3
|
+
font-family: Palatino, Georgia, serif;
|
|
4
|
+
}
|
|
5
|
+
.footnotes, code, .side, .body .side {
|
|
6
|
+
font-size: .85em;
|
|
7
|
+
}
|
|
8
|
+
a {
|
|
9
|
+
color: steelblue;
|
|
10
|
+
}
|
|
11
|
+
.frontmatter, .chapter {
|
|
12
|
+
min-height: calc(100vh - 1em);
|
|
13
|
+
}
|
|
14
|
+
.frontmatter {
|
|
15
|
+
background-image: radial-gradient(#b6cee2 1px, #fff 1px);
|
|
16
|
+
background-size: 2em 2em;
|
|
17
|
+
background-color: #fff;
|
|
18
|
+
padding-bottom: 0;
|
|
19
|
+
}
|
|
20
|
+
.frontmatter > div {
|
|
21
|
+
margin: 0 -1em;
|
|
22
|
+
background-color: #ebf6f9;
|
|
23
|
+
padding: 1em;
|
|
24
|
+
}
|
|
25
|
+
.frontmatter .title {
|
|
26
|
+
padding: 20vh 1em 1em;
|
|
27
|
+
margin-top: -1em;
|
|
28
|
+
}
|
|
29
|
+
#TOC a {
|
|
30
|
+
text-decoration: none;
|
|
31
|
+
}
|
|
32
|
+
#TOC ul ul {
|
|
33
|
+
border-left: 1px solid lightsteelblue;
|
|
34
|
+
}
|
|
35
|
+
#TOC .active {
|
|
36
|
+
color: limegreen;
|
|
37
|
+
}
|
|
38
|
+
#TOC li li .active {
|
|
39
|
+
border-left: 3px solid;
|
|
40
|
+
margin-left: calc(-1em - 3px);
|
|
41
|
+
padding-left: 1em;
|
|
42
|
+
}
|
|
43
|
+
#TOC li:not(.open) ul {
|
|
44
|
+
display: none;
|
|
45
|
+
}
|
|
46
|
+
/* TODO: style for h1.part and printing */
|
package/css/book.min.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
body{font-size:1em;font-family:Palatino,Georgia,serif}.body .side,.footnotes,.side,code{font-size:.85em}a{color:#4682b4}.chapter,.frontmatter{min-height:calc(100vh - 1em)}.frontmatter{background-image:radial-gradient(#b6cee2 1px,#fff 1px);background-size:2em 2em;background-color:#fff;padding-bottom:0}.frontmatter>div{margin:0 -1em;background-color:#ebf6f9;padding:1em}.frontmatter .title{padding:20vh 1em 1em;margin-top:-1em}#TOC a{text-decoration:none}#TOC ul ul{border-left:1px solid #b0c4de}#TOC .active{color:#32cd32}#TOC li li .active{border-left:3px solid;margin-left:calc(-1em - 3px);padding-left:1em}#TOC li:not(.open) ul{display:none}
|
package/js/heading-anchor.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
document.querySelectorAll('h1,h2,h3,h4,h5,h6').forEach(h => {
|
|
2
|
-
if (h.id
|
|
2
|
+
if (h.id && !h.querySelector('.anchor'))
|
|
3
|
+
h.insertAdjacentHTML('beforeend', ` <span class="anchor"><a href="#${h.id}">#</a></span>`);
|
|
3
4
|
});
|
package/js/heading-anchor.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
document.querySelectorAll("h1,h2,h3,h4,h5,h6").forEach((
|
|
1
|
+
document.querySelectorAll("h1,h2,h3,h4,h5,h6").forEach((e=>{e.id&&!e.querySelector(".anchor")&&e.insertAdjacentHTML("beforeend",` <span class="anchor"><a href="#${e.id}">#</a></span>`)}));
|
package/js/toc-highlight.js
CHANGED
|
@@ -5,17 +5,27 @@
|
|
|
5
5
|
if (!toc) return;
|
|
6
6
|
const links = toc.querySelectorAll('a');
|
|
7
7
|
if (!links.length) return;
|
|
8
|
+
const lis = toc.querySelectorAll('li');
|
|
8
9
|
|
|
10
|
+
// record which elements are currently in the viewport
|
|
11
|
+
const ids = [];
|
|
9
12
|
// create a new Intersection Observer instance
|
|
10
13
|
const observer = new IntersectionObserver(els => els.forEach(el => {
|
|
11
|
-
const id = el.target.id;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
const id = el.target.id, i = ids.indexOf(id);
|
|
15
|
+
el.isIntersecting ? ids.push(id) : (i > -1 && ids.splice(i, 1));
|
|
16
|
+
const n = ids.length;
|
|
17
|
+
if (!n) return;
|
|
18
|
+
links.forEach(a => {
|
|
19
|
+
const action = (a.getAttribute('href') === '#' + ids[n - 1]) ? 'add' : 'remove';
|
|
20
|
+
a.classList[action]('active');
|
|
21
|
+
});
|
|
22
|
+
lis.forEach(li => {
|
|
23
|
+
li.classList[li.querySelector('.active') ? 'add' : 'remove']('open');
|
|
14
24
|
});
|
|
15
25
|
}));
|
|
16
26
|
|
|
17
27
|
// observe all section headings
|
|
18
28
|
d.querySelectorAll('h1,h2,h3,h4,h5,h6').forEach(h => {
|
|
19
|
-
h.nodeType === 1 && observer.observe(h);
|
|
29
|
+
h.nodeType === 1 && h.id && observer.observe(h);
|
|
20
30
|
});
|
|
21
31
|
})(document);
|
package/js/toc-highlight.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(e=>{const t=e.querySelector("#TableOfContents, #TOC");if(!t)return;const r=t.querySelectorAll("a");if(!r.length)return;const n=new IntersectionObserver((e=>e.forEach((e=>{const t=e.target.id;
|
|
1
|
+
(e=>{const t=e.querySelector("#TableOfContents, #TOC");if(!t)return;const r=t.querySelectorAll("a");if(!r.length)return;const c=t.querySelectorAll("li"),o=[],n=new IntersectionObserver((e=>e.forEach((e=>{const t=e.target.id,n=o.indexOf(t);e.isIntersecting?o.push(t):n>-1&&o.splice(n,1);const s=o.length;s&&(r.forEach((e=>{const t=e.getAttribute("href")==="#"+o[s-1]?"add":"remove";e.classList[t]("active")})),c.forEach((e=>{e.classList[e.querySelector(".active")?"add":"remove"]("open")})))}))));e.querySelectorAll("h1,h2,h3,h4,h5,h6").forEach((e=>{1===e.nodeType&&e.id&&n.observe(e)}))})(document);
|