@xiee/utils 1.11.0 → 1.11.2
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/default.css +23 -29
- package/css/default.min.css +1 -1
- package/js/copy-button.js +10 -3
- package/js/copy-button.min.js +1 -1
- package/package.json +1 -1
package/css/default.css
CHANGED
|
@@ -8,28 +8,29 @@ body {
|
|
|
8
8
|
}
|
|
9
9
|
body, .footnotes, code { font-size: .9em; }
|
|
10
10
|
li li { font-size: .95em; }
|
|
11
|
-
*, *:before, *:after {
|
|
12
|
-
box-sizing: inherit;
|
|
13
|
-
}
|
|
11
|
+
*, *:before, *:after { box-sizing: inherit; }
|
|
14
12
|
pre, img { max-width: 100%; }
|
|
15
|
-
pre, pre:hover {
|
|
16
|
-
|
|
17
|
-
word-break: break-all;
|
|
18
|
-
}
|
|
19
|
-
pre code {
|
|
20
|
-
display: block;
|
|
21
|
-
overflow-x: auto;
|
|
22
|
-
}
|
|
13
|
+
pre, pre:hover { white-space: pre-wrap; word-break: break-all; }
|
|
14
|
+
pre code { display: block; overflow-x: auto; }
|
|
23
15
|
code { font-family: 'DejaVu Sans Mono', 'Droid Sans Mono', 'Lucida Console', Consolas, Monaco, monospace; }
|
|
24
|
-
:not(pre) > code, code[class] { background-color: #
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
16
|
+
:not(pre) > code, code[class], .box > div { background-color: #f8f8f8; }
|
|
17
|
+
pre > code:not([class]), pre > .language-plain, .box { background-color: inherit; border: 1px solid #eee; }
|
|
18
|
+
pre > .message { border-color: #9eeaf9; }
|
|
19
|
+
pre > .warning { background: #fff3cd; border-color: #fff3cd; }
|
|
20
|
+
pre > .error { background: #f8d7da; border-color: #f8d7da; }
|
|
21
|
+
.fenced-chunk { border-left: 1px solid #666; }
|
|
22
|
+
.code-fence {
|
|
23
|
+
opacity: .4;
|
|
24
|
+
border: 1px dashed #666;
|
|
25
|
+
border-left: 2px solid;
|
|
26
|
+
}
|
|
27
|
+
.code-fence:hover { opacity: inherit; }
|
|
28
|
+
.box { margin: 1em 0; }
|
|
29
|
+
.box > :first-child > p:first-child, .box > :last-child > p:last-child { padding: 1em; }
|
|
30
|
+
.box > :first-child, .box > :first-child > p:first-child { margin-top: 0; }
|
|
31
|
+
.box > :last-child, .box > :last-child > p:last-child { margin-bottom: 0; }
|
|
32
|
+
.figure > p { text-align: center; }
|
|
33
|
+
table { margin: auto; border-top: 1px solid #666; }
|
|
33
34
|
table thead th { border-bottom: 1px solid #ddd; }
|
|
34
35
|
th, td { padding: 5px; }
|
|
35
36
|
thead, tfoot, tr:nth-child(even) { background: #eee; }
|
|
@@ -48,17 +49,10 @@ table, .body h2 { border-bottom: 1px solid #666; }
|
|
|
48
49
|
.body .appendix, .appendix ~ h2 { border-bottom-style: dashed; }
|
|
49
50
|
.footnote-ref a::before { content: "["; }
|
|
50
51
|
.footnote-ref a::after { content: "]"; }
|
|
51
|
-
section.footnotes::before {
|
|
52
|
-
content: "";
|
|
53
|
-
display: block;
|
|
54
|
-
max-width: 20em;
|
|
55
|
-
}
|
|
52
|
+
section.footnotes::before { content: ""; display: block; max-width: 20em; }
|
|
56
53
|
|
|
57
54
|
@media print {
|
|
58
|
-
body {
|
|
59
|
-
font-size: 12pt;
|
|
60
|
-
max-width: 100%;
|
|
61
|
-
}
|
|
55
|
+
body { font-size: 12pt; max-width: 100%; }
|
|
62
56
|
tr, img { page-break-inside: avoid; }
|
|
63
57
|
}
|
|
64
58
|
@media only screen and (min-width: 992px) {
|
package/css/default.min.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
body{font-family:sans-serif;max-width:800px;margin:auto;padding:1em;line-height:1.5;box-sizing:border-box}.footnotes,body,code{font-size:.9em}li li{font-size:.95em}*,:after,:before{box-sizing:inherit}img,pre{max-width:100%}pre,pre:hover{white-space:pre-wrap;word-break:break-all}pre code{display:block;overflow-x:auto}code{font-family:'DejaVu Sans Mono','Droid Sans Mono','Lucida Console',Consolas,Monaco,monospace}
|
|
1
|
+
body{font-family:sans-serif;max-width:800px;margin:auto;padding:1em;line-height:1.5;box-sizing:border-box}.footnotes,body,code{font-size:.9em}li li{font-size:.95em}*,:after,:before{box-sizing:inherit}img,pre{max-width:100%}pre,pre:hover{white-space:pre-wrap;word-break:break-all}pre code{display:block;overflow-x:auto}code{font-family:'DejaVu Sans Mono','Droid Sans Mono','Lucida Console',Consolas,Monaco,monospace}.box>div,:not(pre)>code,code[class]{background-color:#f8f8f8}.box,pre>.language-plain,pre>code:not([class]){background-color:inherit;border:1px solid #eee}pre>.message{border-color:#9eeaf9}pre>.warning{background:#fff3cd;border-color:#fff3cd}pre>.error{background:#f8d7da;border-color:#f8d7da}.fenced-chunk{border-left:1px solid #666}.code-fence{opacity:.4;border:1px dashed #666;border-left:2px solid}.code-fence:hover{opacity:inherit}.box{margin:1em 0}.box>:first-child>p:first-child,.box>:last-child>p:last-child{padding:1em}.box>:first-child,.box>:first-child>p:first-child{margin-top:0}.box>:last-child,.box>:last-child>p:last-child{margin-bottom:0}.figure>p{text-align:center}table{margin:auto;border-top:1px solid #666}table thead th{border-bottom:1px solid #ddd}td,th{padding:5px}tfoot,thead,tr:nth-child(2n){background:#eee}blockquote{color:#666;margin:0;padding-left:1em;border-left:.5em solid #eee}.footnotes::before,hr{border:1px dashed #ddd}.frontmatter{text-align:center}#TOC .numbered li{list-style:none}#TOC .numbered{padding-left:0}#TOC .numbered ul{padding-left:1em}.body h2,table{border-bottom:1px solid #666}.appendix~h2,.body .appendix{border-bottom-style:dashed}.footnote-ref a::before{content:"["}.footnote-ref a::after{content:"]"}section.footnotes::before{content:"";display:block;max-width:20em}@media print{body{font-size:12pt;max-width:100%}img,tr{page-break-inside:avoid}}@media only screen and (min-width:992px){pre{white-space:pre}}
|
package/js/copy-button.js
CHANGED
|
@@ -3,18 +3,25 @@
|
|
|
3
3
|
const cfg = d.currentScript?.dataset;
|
|
4
4
|
d.querySelectorAll(cfg?.selector || 'pre>code').forEach(el => {
|
|
5
5
|
const btn = d.createElement('span'), cls = btn.classList,
|
|
6
|
-
c1 = 'copy-success', c2 = 'copy-fail'
|
|
6
|
+
c1 = 'copy-success', c2 = 'copy-fail', pre = el.parentNode,
|
|
7
|
+
is_code = el.tagName === 'CODE' && pre?.tagName === 'PRE';
|
|
7
8
|
btn.className = 'copy-button';
|
|
8
9
|
// temporarily add a class to the button (as a feedback to copy action)
|
|
9
10
|
function feedback(c) {
|
|
10
11
|
cls.add(c); setTimeout(() => cls.remove(c), 1000);
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
+
// for code.code-fence in div.fenced-chunk (from litedown), copy the whole chunk's source
|
|
14
|
+
function getText() {
|
|
15
|
+
return (is_code && el.classList.contains('code-fence') && pre.parentNode?.classList.contains('fenced-chunk')) ?
|
|
16
|
+
[...pre.parentNode.querySelectorAll('code[class]')]
|
|
17
|
+
.map(code => code.innerText.replace(/\n$/, '')).join('\n') : el.innerText;
|
|
18
|
+
}
|
|
19
|
+
btn.onclick = () => navigator.clipboard.writeText(getText()).then(
|
|
13
20
|
() => feedback(c1), () => feedback(c2)
|
|
14
21
|
);
|
|
15
22
|
// add the button to <pre> for <code> because <code>'s innerHTML' may be
|
|
16
23
|
// changed later, e.g., by syntax highlighting libraries
|
|
17
|
-
const p =
|
|
24
|
+
const p = is_code ? pre : el;
|
|
18
25
|
// add the button only if it has not been added
|
|
19
26
|
p.querySelector('.copy-button') || p.append(btn);
|
|
20
27
|
getComputedStyle(p).position === 'static' && (p.style.position = 'relative');
|
package/js/copy-button.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(e=>{const t=e.currentScript?.dataset;e.querySelectorAll(t?.selector||"pre>code").forEach((t=>{const
|
|
1
|
+
(e=>{const t=e.currentScript?.dataset;e.querySelectorAll(t?.selector||"pre>code").forEach((t=>{const c=e.createElement("span"),o=c.classList,n=t.parentNode,a="CODE"===t.tagName&&"PRE"===n?.tagName;function s(e){o.add(e),setTimeout((()=>o.remove(e)),1e3)}c.className="copy-button",c.onclick=()=>navigator.clipboard.writeText(a&&t.classList.contains("code-fence")&&n.parentNode?.classList.contains("fenced-chunk")?[...n.parentNode.querySelectorAll("code[class]")].map((e=>e.innerText.replace(/\n$/,""))).join("\n"):t.innerText).then((()=>s("copy-success")),(()=>s("copy-fail")));const r=a?n:t;r.querySelector(".copy-button")||r.append(c),"static"===getComputedStyle(r).position&&(r.style.position="relative")}))})(document);
|