@xiee/utils 1.2.8 → 1.2.10
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/.github/workflows/npm-publish.yml +1 -0
- package/README.md +3 -4
- package/build.sh +15 -0
- package/css/circled-numbers.min.css +1 -0
- package/css/faq.min.css +1 -0
- package/css/key-buttons.min.css +1 -0
- package/js/alt-title.min.js +1 -0
- package/js/center-img.js +22 -18
- package/js/center-img.min.js +1 -0
- package/js/comment-utils.min.js +1 -0
- package/js/custom-disqus.min.js +1 -0
- package/js/external-link.min.js +1 -0
- package/js/faq.min.js +1 -0
- package/js/fix-footnote.js +4 -26
- package/js/fix-footnote.min.js +1 -0
- package/js/fix-toc.min.js +1 -0
- package/js/hash-notes.min.js +1 -0
- package/js/header-link.min.js +1 -0
- package/js/key-buttons.min.js +1 -0
- package/js/load-highlight.min.js +1 -0
- package/js/load-typekit.min.js +1 -0
- package/js/math-code.min.js +1 -0
- package/js/no-highlight.min.js +1 -0
- package/js/post-nav.min.js +1 -0
- package/js/right-quote.min.js +1 -0
- package/js/toggle-notes.min.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -50,9 +50,7 @@ introduction here](https://yihui.org/en/2021/10/faq-list/).
|
|
|
50
50
|
|
|
51
51
|
## fix-footnote.js
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
when footnotes do not contain any ASCII characters, in which case Hugo is unable
|
|
55
|
-
to render unique `id`s for the footnote items (the `id` is `fn:-`).
|
|
53
|
+
Add `[ ]` to footnote numbers and move the return symbols in footnotes.
|
|
56
54
|
|
|
57
55
|
## fix-toc.js
|
|
58
56
|
|
|
@@ -75,7 +73,8 @@ attributes.
|
|
|
75
73
|
Find keyboard keys in `<code></code>` and convert the tag to `<kbd></kbd>`,
|
|
76
74
|
e.g., convert `<code>Ctrl + C</code>` to `<kbd>Ctrl</kbd>` + `<kbd>C</kbd>`.
|
|
77
75
|
With `key-buttons.css`, the keys will be styled as boxes with shadows like
|
|
78
|
-
buttons.
|
|
76
|
+
buttons. You can learn more details [in this
|
|
77
|
+
post](https://yihui.org/en/2023/02/key-buttons/).
|
|
79
78
|
|
|
80
79
|
## load-highlight.js
|
|
81
80
|
|
package/build.sh
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#TableOfContents,#TableOfContents~p:first-of-type{counter-reset:circled-numbers}#TableOfContents>ul>li>ul>li::before,h2:not([class])::before{counter-increment:circled-numbers;content:counter(circled-numbers);border-radius:50%;border:1px dashed #999;color:#333;background:#fff;display:inline-block;min-width:1.75em;line-height:1.75em;margin-right:.5em;text-align:center;font-size:.8em}h2:not([class])::before{vertical-align:bottom;color:#fff;border:none;background:#999}#TableOfContents>ul>li>ul>li{display:inline-block}
|
package/css/faq.min.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.faq-button{cursor:pointer}.faq-list>li>:first-child{display:block;cursor:pointer;background:#fafafa;margin:-.5em;padding:.5em}.faq-list>:not(.faq-clicked)>*{display:none}.faq-button{float:right;margin-left:1em}.faq-list .anchor{display:none}.faq-list>li:hover>.anchor{display:inline}.faq-list>li{border:1px solid #eee;padding:.5em}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
kbd{border:2px solid #ccc;box-shadow:2px 2px #999;display:inline-block;padding:0 5px;border-radius:.25em;min-width:1.5em;text-align:center;margin-right:.15em}kbd:hover{position:relative;top:2px;left:2px}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(){for(var t,e=document.getElementsByTagName("img"),l=0;l<e.length;l++)(t=e[l]).title||(t.title=t.alt)}();
|
package/js/center-img.js
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
|
-
(function() {
|
|
1
|
+
(function(d) {
|
|
2
|
+
function one_child(el) {
|
|
3
|
+
if (el.childElementCount !== 1) return false;
|
|
4
|
+
const nodes = el.childNodes;
|
|
5
|
+
if (nodes.length === 1) return true;
|
|
6
|
+
for (let i in nodes) {
|
|
7
|
+
let node = nodes[i];
|
|
8
|
+
if (node.nodeName === '#text' && !/^\s$/.test(node.textContent)) return false;
|
|
9
|
+
}
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
2
12
|
function center_el(tagName) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
tag = tags[i];
|
|
6
|
-
var parent = tag.parentElement;
|
|
13
|
+
d.querySelectorAll(tagName).forEach(tag => {
|
|
14
|
+
let parent = tag.parentElement;
|
|
7
15
|
// center an image if it is the only element of its parent
|
|
8
|
-
if (parent
|
|
16
|
+
if (one_child(parent)) {
|
|
9
17
|
// if there is a link on image, check grandparent
|
|
10
|
-
|
|
18
|
+
const parentA = parent.nodeName === 'A';
|
|
11
19
|
if (parentA) {
|
|
12
20
|
parent = parent.parentElement;
|
|
13
|
-
if (parent
|
|
21
|
+
if (!one_child(parent)) return;
|
|
14
22
|
parent.firstElementChild.style.border = 'none';
|
|
15
23
|
}
|
|
16
24
|
if (parent.nodeName === 'P') {
|
|
@@ -21,15 +29,11 @@
|
|
|
21
29
|
}
|
|
22
30
|
}
|
|
23
31
|
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
var tagNames = ['img', 'embed', 'object'];
|
|
27
|
-
for (var i = 0; i < tagNames.length; i++) {
|
|
28
|
-
center_el(tagNames[i]);
|
|
32
|
+
});
|
|
29
33
|
}
|
|
34
|
+
['img', 'embed', 'object'].forEach(tag => center_el(tag));
|
|
30
35
|
// also center paragraphs that contain `* * *`
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
})();
|
|
36
|
+
d.querySelectorAll('p').forEach(p => {
|
|
37
|
+
if (p.innerText === '* * *') p.style.textAlign = 'center';
|
|
38
|
+
});
|
|
39
|
+
})(document);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e){function t(e){if(1!==e.childElementCount)return!1;const t=e.childNodes;if(1===t.length)return!0;for(let e in t){let n=t[e];if("#text"===n.nodeName&&!/^\s$/.test(n.textContent))return!1}return!0}["img","embed","object"].forEach((n=>{return r=n,void e.querySelectorAll(r).forEach((e=>{let n=e.parentElement;if(t(n)){const o="A"===n.nodeName;if(o){if(n=n.parentElement,!t(n))return;n.firstElementChild.style.border="none"}"P"===n.nodeName&&(n.style.textAlign="center",o||"img"!==r||(n.innerHTML='<a href="'+e.src+'" style="border: none;">'+e.outerHTML+"</a>"))}}));var r})),e.querySelectorAll("p").forEach((e=>{"* * *"===e.innerText&&(e.style.textAlign="center")}))}(document);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(t){const e=t.querySelector("section.comments");if(!e)return;if(function(){let t=!0;try{t=window.self!==window.top}catch(t){}return t}())return void e.remove();location.hash.match(/^#comment-[0-9]+$/)&&e.scrollIntoView();const r=e.querySelector("script[data-src]");if(!r)return;const n=r.dataset.src,c=t.createElement("script"),o=r.attributes;for(let t=0;t<o.length;t++)c.setAttribute(o[t].name,o[t].value);c.src=n,r.remove(),e.appendChild(c)}(document);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e){if(!function(){var e=!0;try{e=window.self!==window.top}catch(e){}return e}()){var t=e.getElementById("disqus_thread"),n=t.nextElementSibling,r=e.querySelector("section.comments"),o=r.querySelectorAll('input[type="radio"]');n.setAttribute("data-timestamp",+new Date);var i,c=function(){return r.querySelector("#tab-2").checked=!0,"add"},s=function(e){"layout"===e.name&&r.classList["layout-2"===e.id?c():"remove"]("comment-full")},a=function(){s(this),l();var e=JSON.stringify(function(){var e={};return o.forEach((function(t){e[t.id]=t.checked})),e}());try{localStorage.setItem("comment-prefs",e)}catch(e){}},l=function(){var e=r.classList.contains("comment-full");r.querySelectorAll('input[name="tabs"]').forEach((function(t,n){if(e||t.checked){var o=r.querySelector(".panel:nth-of-type("+(n+1)+") > script[data-src]");o&&o.dataset.src&&(o.src=o.dataset.src,o.removeAttribute("data-src"))}}))};(i=localStorage.getItem("comment-prefs"))&&(i=JSON.parse(i),o.forEach((function(e){i[e.id]&&(e.checked=!0,s(e))}))),o.forEach((function(e){e.addEventListener("change",a)}));var d=!1,u=function(e){d||(r.querySelector(".tabs").style.display="",l(),d=!0,e&&t.scrollIntoView())};if(n.onerror=function(n){var r=e.createElement("script");r.src="//cdn.jsdelivr.net/gh/yihui/DisqusJS@1.3.3/src/disqus.min.js",t.appendChild(r);try{localStorage.setItem("dsqjs_mode","dsqjs")}catch(n){}r.onload=function(t){var n=e.createElement("link");n.rel="stylesheet",n.href="//cdn.jsdelivr.net/gh/yihui/DisqusJS@1.3.3/src/disqusjs.min.css",e.head.appendChild(n),disqus_config.DisqusJSInit()},r.onerror=function(e){t.innerText="Sorry, but you cannot make comments because Disqus failed to load for some reason. It is known to be blocked in certain regions. If you are sure it is not blocked in your region, please refresh the page. Alternatively, you can comment with Utterances. 您可能需要翻墙发表 Disqus 评论;若没有梯子,不妨尝试使用 Github 登录 Utterances 评论。",t.style.border="1px dashed",t.style.padding=".5em",t.style.background="lightyellow",c()}},n.onload=function(n){var o=e.getElementById("disqus_count");if(o){var i=e.createElement("script");i.src="//yihui.disqus.com/count.js",i.id="dsq-count-scr",t.appendChild(i),new MutationObserver((()=>{""==o.innerText||o.innerText>0||(c(),l(),r.append(r.querySelector("#tab-2 ~ .panel")),r.querySelector(".tabs").remove(),r.querySelector(".panel").style.display="block")})).observe(o,{characterData:!0,childList:!0})}},location.hash.match(/^#comment-[0-9]+$/))return u(!0);var m=function(){if(!d){var e=r.getBoundingClientRect();e.top<window.innerHeight&&e.bottom>=0&&u()}};window.addEventListener("load",m),e.addEventListener("scroll",m)}}(document);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e){const t=/^(https?:)?\/\//;e.querySelectorAll("a").forEach((e=>{t.test(e.getAttribute("href"))&&(e.target="_blank"),0===e.childElementCount&&(e.innerText=e.innerText.replace(t,"").replace(/#.*$/,""))}))}(document);
|
package/js/faq.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(t=>{const n="faq-list",e="faq-clicked";function l(l,o){const c=l.children;if(0===c.length)return;for(let t of c)if(t.childElementCount<2)return;let i=l.classList;if(i.length>0&&!i.contains(n))return;i.add(n);const s=t.createElement("span");let a=!1;s.className="faq-button",s.innerText="⊕",s.onclick=function(){a=!a,this.innerText=a?"⊖":"⊕";for(const t of l.children)t.classList.toggle(e,a)},l.before(s);for(let t=0;t<c.length;t++){let n=c[t],l="faq-"+(o?o+"-":"")+(t+1),i=n.firstElementChild;i.innerHTML+=' <span class="anchor" id="'+l+'"><a href="#'+l+'">#</a></span>',location.hash==="#"+l&&(n.scrollIntoView(),n.classList.add(e)),i.onclick=function(t){n.classList.toggle(e)}}}const o=t.querySelectorAll(["div","main","section","article"].map((t=>t+":not(.footnotes) > ol")).join(","));for(let t=0;t<o.length;t++){l(o[t],o.length>1?t+1:0)}})(document);
|
package/js/fix-footnote.js
CHANGED
|
@@ -1,30 +1,8 @@
|
|
|
1
1
|
(function(d) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (tagName === 'sup') {
|
|
7
|
-
if (tag.className !== 'footnote-ref' || tag.id !== 'fnref:-') continue;
|
|
8
|
-
tag.id += n;
|
|
9
|
-
if (tag.children.length === 1) {
|
|
10
|
-
tag2 = tag.children[0];
|
|
11
|
-
href = tag2.getAttribute('href');
|
|
12
|
-
if (tag2.nodeName === 'A' && href === '#fn:-') {
|
|
13
|
-
tag2.setAttribute('href', href + n);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
} else if (tagName === 'li') {
|
|
17
|
-
if (tag.id !== 'fn:-') continue;
|
|
18
|
-
tag.id += n;
|
|
19
|
-
tag2 = tag.lastChild; href = tag2.getAttribute('href');
|
|
20
|
-
if (tag2.nodeName === 'A' && href === '#fnref:-') {
|
|
21
|
-
tag2.setAttribute('href', href + n);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
n++;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
fix_footnote('sup'); fix_footnote('li');
|
|
2
|
+
// add [] to footnote numbers
|
|
3
|
+
d.querySelectorAll('sup[id^="fnref:"] > a.footnote-ref, a.footnote-ref > sup').forEach(el => {
|
|
4
|
+
if (/^[0-9]+$/.test(el.innerText)) el.innerText = ' [' + el.innerText + ']';
|
|
5
|
+
});
|
|
28
6
|
// move the return symbol into the previous <p>
|
|
29
7
|
d.querySelectorAll('.footnotes > ol > li > p ~ .footnote-return').forEach(el => {
|
|
30
8
|
el.previousElementSibling.lastChild.after(el);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e){e.querySelectorAll('sup[id^="fnref:"] > a.footnote-ref, a.footnote-ref > sup').forEach((e=>{/^[0-9]+$/.test(e.innerText)&&(e.innerText=" ["+e.innerText+"]")})),e.querySelectorAll(".footnotes > ol > li > p ~ .footnote-return").forEach((e=>{e.previousElementSibling.lastChild.after(e)}))}(document);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(){const e=document.getElementById("TableOfContents");if(!e)return;e.querySelectorAll('a[href^="#"]').forEach((e=>{let t=e.getAttribute("href").replace(/^#/,"");const n=document.getElementById(t);if(t=t.replace(/-https?-.+$/,""),n&&(n.id=t),e.href="#"+t,""!==e.innerHTML)return;const r=e.nextElementSibling;r&&"A"===r.tagName&&(e.innerHTML=r.innerHTML,r.remove())}));let t,n=e.querySelector("ul");1===n.childElementCount&&(t=n.firstElementChild,"LI"===t.tagName&&(n.outerHTML=t.innerHTML))}();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e){!function n(t){t.childNodes.forEach((t=>{t.nodeType===Node.COMMENT_NODE?function(n){const t=n.textContent,a=/^#[\s\n]+([\s\S]+)[\s\n]+$/;if(!a.test(t))return;e.body.classList.add("has-notes","hide-notes");const o=e.createElement("P"===n.parentNode.nodeName?"span":"p");o.className="hash-note",o.innerText=t.replace(a,"$1"),o.innerHTML=o.innerHTML.replace(/\[([^\]]+)\]\(([^)]+)\)/g,'<a href="$2">$1</a>').replace(/(^|[^"])(https?:\/\/)([-a-zA-Z0-9%._=/\+]+)(#)?([-a-zA-Z0-9%._=\+]+)?/g,'$1<a href="$2$3$4$5">$3$4</a>'),n.before(o),n.remove()}(t):n(t)}))}(e.body)}(document);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(){for(var a,e=document.querySelectorAll("article h1, article h2, article h3"),r=0;r<e.length;r++)""!==(a=e[r]).id&&(a.innerHTML+=' <span class="anchor"><a href="#'+a.id+'">#</a></span>')}();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e){const r=["Enter","Up","Down","Left","Right"],t=["↵","↑","↓","←","→"];function n(e){return r.map(((r,n)=>e=e.replace(new RegExp(">"+r+"<","g"),' title="'+r+(n?" Arrow":"")+'">'+t[n]+"<"))),e}const o="Esc|Tab|PageUp|PageDown|Space|Delete|Home|End|PrtScr?|PrintScreen|"+Array(12).fill().map(((e,r)=>"F"+(r+1))).concat(r).join("|"),c="Ctrl|Control|Shift|Alt|Cmd|Command|fn",a=new RegExp("^("+o+"|"+c+")$"),l=new RegExp("^("+c+") [/+] "),i=new RegExp("^("+[o,c,"[a-zA-Z0-9]|Click"].join("|")+")( [/+] )(.*)");e.querySelectorAll(":not(pre) > code").forEach((e=>{if(e.childElementCount>0)return;let r=e.innerText;if(a.test(r))return void(e.outerHTML=n("<kbd>"+r+"</kbd>"));if(!l.test(r))return;let t="";for(r+=" + ";i.test(r);)t+=r.replace(i,"<kbd>$1</kbd>$2"),r=r.replace(i,"$3");""===r&&(e.outerHTML=n(t.replace(/ \+ $/,"")))}))}(document);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
hljs.configure({languages:[]}),hljs.highlightAll?hljs.highlightAll():hljs.initHighlightingOnLoad();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e){var t=e.createElement("canvas").getContext("2d"),a="abcdefghijklmnopqrstuvwxyz0123456789";t.font="72px monospace";for(var n=t.measureText(a).width,c=[" SC"," CN"," TC"," TW",""],o=0;o<c.length;o++)if(t.font="72px 'Source Han Serif"+c[o]+"', monospace",t.measureText(a).width!=n)return;var i,r={kitId:"kwz5xar",scriptTimeout:3e3,async:!0},s=e.documentElement,m=setTimeout((function(){s.className=s.className.replace(/\bwf-loading\b/g,"")+" wf-inactive"}),r.scriptTimeout),d=e.createElement("script"),l=!1,p=e.getElementsByTagName("script")[0];s.className+=" wf-loading",d.src="https://use.typekit.net/"+r.kitId+".js",d.async=!0,d.onload=d.onreadystatechange=function(){if(i=this.readyState,!(l||i&&"complete"!=i&&"loaded"!=i)){l=!0,clearTimeout(m);try{Typekit.load(r)}catch(e){}}},p.parentNode.insertBefore(d,p)}(document);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(){var e,t,n,$=document.getElementsByTagName("code");for(e=0;e<$.length;)"PRE"!==(n=$[e]).parentNode.tagName&&0===n.childElementCount&&(t=n.textContent,/^\$[^$]/.test(t)&&/[^$]\$$/.test(t)&&(t=t.replace(/^\$/,"\\(").replace(/\$$/,"\\)"),n.textContent=t),/^\\\((.|\s)+\\\)$/.test(t)||/^\\\[(.|\s)+\\\]$/.test(t)||/^\$(.|\s)+\$$/.test(t)||/^\\begin\{([^}]+)\}(.|\s)+\\end\{[^}]+\}$/.test(t))?n.outerHTML=n.innerHTML:e++}();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(){var e,a,l,s=document.getElementsByTagName("pre");for(e=0;e<s.length;e++)1===(l=s[e]).children.length&&"CODE"===(l=l.children[0]).tagName&&(""===(a=l.className)||"hljs"===a?l.className="nohighlight":/^language-/.test(a)&&!/hljs/.test(a)&&(l.className+=" hljs"))}();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e){const r=e.querySelector(".nav-prev > a"),t=e.querySelector(".nav-next > a");e.addEventListener("keyup",(function(e){if("BODY"!=e.target.nodeName.toUpperCase())return;let n;r&&37==e.which?n=r.href:t&&39==e.which&&(n=t.href),n&&(window.location=n)}));const n=e.querySelectorAll(".unlist");if(0===n.length)return;if(null!==sessionStorage.getItem("hide-notes"))return n.forEach((e=>e.classList.remove("unlist")));r&&t&&(window.location=e.referrer===t.href?r.href:t.href)}(document);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(){var e,t,n=document.getElementsByTagName("blockquote");for(e=0;e<n.length;e++){var l=(t=n[e]).children.length;if(0!==l){var o=t.children[l-1];o&&"P"===o.nodeName&&/^—/.test(o.textContent)&&(o.style.textAlign="right")}}}();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(t){if(!t.body.classList.contains("has-notes"))return;const e=t.querySelector(".title > hr");if(!e)return;let s=sessionStorage.getItem("hide-notes");e.classList.add("toggle-notes"),e.onclick=function(e){null===s&&!/^(localhost|[0-9.]+)$/.test(location.hostname)&&alert("你好像点了个神秘开关……请勿公开,自行阅读即可(再次点击可关闭),谢谢!"),s=t.body.classList.toggle("hide-notes");try{sessionStorage.setItem("hide-notes",s)}catch(e){}},null!==s&&t.body.classList.toggle("hide-notes","true"===s)}(document);
|