Debian Codegraph @

docs/src/js/extra-loader.js

raw
1 import uml from "./uml"
2 import arithmatex from "./arithmatex"
3 import "./material-extra-3rdparty"
4
5 // Main function
6 (() => {
7 let umlPromise = Promise.resolve()
8 let mathPromise = Promise.resolve()
9
10 const observer = new MutationObserver(mutations => {
11 mutations.forEach(mutation => {
12 if (mutation.type === "attributes") {
13 let scheme = mutation.target.getAttribute("data-md-color-scheme")
14 if (!scheme) {
15 scheme = "slate"
16 }
17 if (typeof mermaid !== "undefined") {
18 uml("diagram")
19 }
20 }
21 })
22 })
23
24 const main = () => {
25 observer.observe(document.querySelector("body"), {attributeFilter: ["data-md-color-scheme"]})
26
27 if (typeof mermaid !== "undefined") {
28 umlPromise = umlPromise.then(() => {
29 uml("diagram")
30 }).catch(err => {
31 console.log(`UML loading failed...${err}`) // eslint-disable-line no-console
32 })
33 }
34
35 if (typeof katex !== "undefined") {
36 mathPromise = mathPromise.then(() => {
37 arithmatex("arithmatex", "katex")
38 }).catch(err => {
39 console.log(`Math loading failed...${err}`) // eslint-disable-line no-console
40 })
41 } else if (typeof MathJax !== "undefined" && 'typesetPromise' in MathJax) {
42 mathPromise = mathPromise.then(() => {
43 arithmatex("arithmatex", "mathjax")
44 }).catch(err => {
45 console.log(`Math loading failed...${err}`) // eslint-disable-line no-console
46 })
47 }
48 }
49
50 window.document$.subscribe(main)
51 })()