-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
(function () { | ||
'use strict'; | ||
|
||
var katexMath = (function () { | ||
var maths = document.querySelectorAll('.arithmatex'), | ||
tex; | ||
|
||
for (var i = 0; i < maths.length; i++) { | ||
tex = maths[i].textContent || maths[i].innerText; | ||
if (tex.startsWith('\\(') && tex.endsWith('\\)')) { | ||
katex.render(tex.slice(2, -2), maths[i], {'displayMode': false}); | ||
} else if (tex.startsWith('\\[') && tex.endsWith('\\]')) { | ||
katex.render(tex.slice(2, -2), maths[i], {'displayMode': true}); | ||
} | ||
} | ||
}); | ||
|
||
(function () { | ||
var onReady = function onReady(fn) { | ||
if (document.addEventListener) { | ||
document.addEventListener("DOMContentLoaded", fn); | ||
} else { | ||
document.attachEvent("onreadystatechange", function () { | ||
if (document.readyState === "interactive") { | ||
fn(); | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
onReady(function () { | ||
if (typeof katex !== "undefined") { | ||
katexMath(); | ||
} | ||
}); | ||
})(); | ||
|
||
}()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
window.MathJax = { | ||
tex: { | ||
inlineMath: [["\\(", "\\)"]], | ||
displayMath: [["\\[", "\\]"]], | ||
processEscapes: true, | ||
processEnvironments: true, | ||
}, | ||
options: { | ||
ignoreHtmlClass: ".*|", | ||
processHtmlClass: "arithmatex", | ||
}, | ||
}; | ||
|
||
document$.subscribe(() => { | ||
MathJax.startup.output.clearCache(); | ||
MathJax.typesetClear(); | ||
MathJax.texReset(); | ||
MathJax.typesetPromise(); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
(() => { | ||
|
||
const preferToggle = e => { | ||
if (localStorage.getItem("data-md-prefers-color-scheme") === "true") { | ||
document.querySelector("body").setAttribute("data-md-color-scheme", (e.matches) ? "slate" : "default") | ||
} | ||
var frame = document.querySelector(".giscus-frame") | ||
var theme = document.querySelector("body").getAttribute("data-md-color-scheme") === "slate" ? "https://gcore.jsdelivr.net/gh/TonyCrane/note/docs/css/giscus.css" : "light" | ||
frame.contentWindow.postMessage( | ||
{ giscus: { setConfig: { theme } } }, | ||
"https://giscus.app" | ||
) | ||
} | ||
|
||
const setupTheme = body => { | ||
const preferSupported = window.matchMedia("(prefers-color-scheme)").media !== "not all" | ||
let scheme = localStorage.getItem("data-md-color-scheme") | ||
let prefers = localStorage.getItem("data-md-prefers-color-scheme") | ||
let oldversion = localStorage.getItem("/.__palette") | ||
|
||
if (oldversion) { | ||
localStorage.removeItem("/.__palette") | ||
} | ||
|
||
if (!scheme) { | ||
scheme = "slate" | ||
} | ||
if (!prefers) { | ||
prefers = "false" | ||
} | ||
|
||
if (prefers === "true" && preferSupported) { | ||
scheme = (window.matchMedia("(prefers-color-scheme: dark)").matches) ? "slate" : "default" | ||
} else { | ||
prefers = "false" | ||
} | ||
|
||
body.setAttribute("data-md-prefers-color-scheme", prefers) | ||
body.setAttribute("data-md-color-scheme", scheme) | ||
|
||
if (preferSupported) { | ||
const matchListener = window.matchMedia("(prefers-color-scheme: dark)") | ||
matchListener.addListener(preferToggle) | ||
} | ||
} | ||
|
||
const observer = new MutationObserver(mutations => { | ||
mutations.forEach(mutation => { | ||
if (mutation.type === "childList") { | ||
if (mutation.addedNodes.length) { | ||
for (let i = 0; i < mutation.addedNodes.length; i++) { | ||
const el = mutation.addedNodes[i] | ||
|
||
if (el.nodeType === 1 && el.tagName.toLowerCase() === "body") { | ||
setupTheme(el) | ||
break | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
}) | ||
|
||
observer.observe(document.querySelector("html"), {childList: true}) | ||
setupTheme(document.querySelector("body")) | ||
})() | ||
|
||
window.toggleScheme = () => { | ||
const body = document.querySelector("body") | ||
const preferSupported = window.matchMedia("(prefers-color-scheme)").media !== "not all" | ||
let scheme = body.getAttribute("data-md-color-scheme") | ||
let prefer = body.getAttribute("data-md-prefers-color-scheme") | ||
|
||
if (preferSupported && scheme === "default" && prefer !== "true") { | ||
prefer = "true" | ||
scheme = (window.matchMedia("(prefers-color-scheme: dark)").matches) ? "slate" : "default" | ||
} else if (preferSupported && prefer === "true") { | ||
prefer = "false" | ||
scheme = "slate" | ||
} else if (scheme === "slate") { | ||
prefer = "false" | ||
scheme = "default" | ||
} else { | ||
prefer = "false" | ||
scheme = "slate" | ||
} | ||
localStorage.setItem("data-md-prefers-color-scheme", prefer) | ||
localStorage.setItem("data-md-color-scheme", scheme) | ||
body.setAttribute("data-md-prefers-color-scheme", prefer) | ||
body.setAttribute("data-md-color-scheme", scheme) | ||
|
||
var frame = document.querySelector(".giscus-frame") | ||
var theme = scheme === "slate" ? "https://gcore.jsdelivr.net/gh/TonyCrane/note/docs/css/giscus.css" : "light" | ||
frame.contentWindow.postMessage( | ||
{ giscus: { setConfig: { theme } } }, | ||
"https://giscus.app" | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
document$.subscribe(function () { | ||
var tables = document.querySelectorAll("article table:not([class])"); | ||
tables.forEach(function (table) { | ||
new Tablesort(table); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
(function (window, document) { | ||
function register($toc) { | ||
const currentInView = new Set(); | ||
const headingToMenu = new Map(); | ||
const $menus = Array.from($toc.querySelectorAll('.md-nav__list > li > a')); | ||
|
||
for (const $menu of $menus) { | ||
const elementId = $menu.getAttribute('href').trim().slice(1); | ||
const $heading = document.getElementById(elementId); | ||
if ($heading) { | ||
headingToMenu.set($heading, $menu); | ||
} | ||
} | ||
|
||
const $headings = Array.from(headingToMenu.keys()); | ||
|
||
const callback = (entries) => { | ||
for (const entry of entries) { | ||
if (entry.isIntersecting) { | ||
currentInView.add(entry.target); | ||
} else { | ||
currentInView.delete(entry.target); | ||
} | ||
} | ||
let $heading; | ||
if (currentInView.size) { | ||
// heading is the first in-view heading | ||
$heading = [...currentInView].sort(($el1, $el2) => $el1.offsetTop - $el2.offsetTop)[0]; | ||
} else if ($headings.length) { | ||
// heading is the closest heading above the viewport top | ||
$heading = $headings | ||
.filter(($heading) => $heading.offsetTop < window.scrollY) | ||
.sort(($el1, $el2) => $el2.offsetTop - $el1.offsetTop)[0]; | ||
} | ||
if ($heading && headingToMenu.has($heading)) { | ||
$menus.forEach(($menu) => $menu.classList.remove('is-active')); | ||
|
||
const $menu = headingToMenu.get($heading); | ||
$menu.classList.add('is-active'); | ||
let $menuList = $menu.parentElement.parentElement.parentElement; | ||
while ( | ||
$menuList.classList.contains('md-nav') && | ||
$menuList.parentElement.tagName.toLowerCase() === 'li' | ||
) { | ||
$menuList.parentElement.children[0].classList.add('is-active'); | ||
$menuList = $menuList.parentElement.parentElement.parentElement; | ||
} | ||
} | ||
}; | ||
const observer = new IntersectionObserver(callback, { threshold: 0 }); | ||
|
||
for (const $heading of $headings) { | ||
observer.observe($heading); | ||
// smooth scroll to the heading | ||
if (headingToMenu.has($heading)) { | ||
const $menu = headingToMenu.get($heading); | ||
$menu.setAttribute('data-href', $menu.getAttribute('href')); | ||
$menu.setAttribute('href', 'javascript:;'); | ||
$menu.addEventListener('click', () => { | ||
if (typeof $heading.scrollIntoView === 'function') { | ||
$heading.scrollIntoView({ behavior: 'smooth' }); | ||
} | ||
const anchor = $menu.getAttribute('data-href'); | ||
if (history.pushState) { | ||
history.pushState(null, null, anchor); | ||
} else { | ||
location.hash = anchor; | ||
} | ||
}); | ||
$heading.style.scrollMargin = '4em'; | ||
} | ||
} | ||
} | ||
|
||
if (typeof window.IntersectionObserver === 'undefined') { | ||
return; | ||
} | ||
|
||
document.querySelectorAll('.md-sidebar--secondary').forEach(register); | ||
})(window, document); |