Improve MDHelper themes and packaging
This commit is contained in:
@@ -10,8 +10,8 @@ body {
|
||||
margin: 0;
|
||||
background: #f6f7f9;
|
||||
color: #23272f;
|
||||
font-family: "Segoe UI", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;
|
||||
font-size: var(--reader-font-scale);
|
||||
font-family: var(--reader-font-family);
|
||||
font-size: var(--reader-font-size);
|
||||
line-height: 1.72;
|
||||
}
|
||||
|
||||
@@ -122,6 +122,12 @@ html[data-theme="dark"] blockquote {
|
||||
background: #f0fff6;
|
||||
}
|
||||
|
||||
.admonition-note {
|
||||
border-color: #cfe0f2;
|
||||
border-left-color: #3b82c4;
|
||||
background: #f0f7ff;
|
||||
}
|
||||
|
||||
.admonition-warning,
|
||||
.admonition-caution {
|
||||
border-color: #f1d7a8;
|
||||
@@ -152,6 +158,12 @@ html[data-theme="dark"] .admonition-tip {
|
||||
background: #1d3026;
|
||||
}
|
||||
|
||||
html[data-theme="dark"] .admonition-note {
|
||||
border-color: #344e68;
|
||||
border-left-color: #5aa5e8;
|
||||
background: #1e2b38;
|
||||
}
|
||||
|
||||
html[data-theme="dark"] .admonition-warning,
|
||||
html[data-theme="dark"] .admonition-caution {
|
||||
border-color: #584725;
|
||||
@@ -402,6 +414,62 @@ html[data-theme="dark"] .plain-file-view {
|
||||
background: #171b22;
|
||||
}
|
||||
|
||||
.diagram-block,
|
||||
.math-block {
|
||||
margin: 1.2em 0;
|
||||
border: 1px solid #d8dee8;
|
||||
border-radius: 8px;
|
||||
overflow: auto;
|
||||
background: #f7f9fc;
|
||||
}
|
||||
|
||||
html[data-theme="dark"] .diagram-block,
|
||||
html[data-theme="dark"] .math-block {
|
||||
border-color: #384252;
|
||||
background: #171b22;
|
||||
}
|
||||
|
||||
.diagram-title {
|
||||
padding: 0.42em 0.76em;
|
||||
border-bottom: 1px solid #d8dee8;
|
||||
background: #edf1f6;
|
||||
color: #53606f;
|
||||
font-size: 0.82em;
|
||||
font-weight: 650;
|
||||
}
|
||||
|
||||
html[data-theme="dark"] .diagram-title {
|
||||
border-bottom-color: #384252;
|
||||
background: #242b36;
|
||||
color: #b7c0cc;
|
||||
}
|
||||
|
||||
.mermaid,
|
||||
.math-block {
|
||||
padding: 1em;
|
||||
}
|
||||
|
||||
.diagram-missing-runtime::before {
|
||||
content: "Mermaid 本地资源未加载,下面显示原始图表代码。";
|
||||
display: block;
|
||||
margin-bottom: 0.75em;
|
||||
color: #9b2c2c;
|
||||
font-weight: 650;
|
||||
}
|
||||
|
||||
.diagram-render-error::before {
|
||||
content: "Mermaid 图表渲染失败,下面显示原始图表代码。";
|
||||
display: block;
|
||||
margin-bottom: 0.75em;
|
||||
color: #9b2c2c;
|
||||
font-weight: 650;
|
||||
}
|
||||
|
||||
html[data-theme="dark"] .diagram-missing-runtime::before,
|
||||
html[data-theme="dark"] .diagram-render-error::before {
|
||||
color: #f2b8b5;
|
||||
}
|
||||
|
||||
.copy-code-button {
|
||||
position: absolute;
|
||||
top: 6px;
|
||||
@@ -555,7 +623,10 @@ html[data-theme="dark"] hr {
|
||||
left: 50%;
|
||||
z-index: 1001;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
max-width: min(92vw, 760px);
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,60 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
});
|
||||
});
|
||||
|
||||
const renderMermaidDiagrams = async () => {
|
||||
const diagrams = [...document.querySelectorAll(".mermaid")];
|
||||
if (!diagrams.length) {
|
||||
return;
|
||||
}
|
||||
if (!window.mermaid) {
|
||||
diagrams.forEach((diagram) => {
|
||||
diagram.classList.add("diagram-missing-runtime");
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const theme = document.documentElement.dataset.theme === "dark" ? "dark" : "default";
|
||||
window.mermaid.initialize({
|
||||
startOnLoad: false,
|
||||
securityLevel: "loose",
|
||||
theme,
|
||||
});
|
||||
try {
|
||||
await window.mermaid.run({ nodes: diagrams });
|
||||
} catch (error) {
|
||||
diagrams.forEach((diagram) => {
|
||||
diagram.classList.add("diagram-render-error");
|
||||
diagram.title = String(error);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const renderMath = () => {
|
||||
const reader = document.querySelector(".reader");
|
||||
const engine = document.documentElement.dataset.mathEngine || "katex";
|
||||
if (!reader) {
|
||||
return;
|
||||
}
|
||||
if (engine === "mathjax" && window.MathJax && window.MathJax.typesetPromise) {
|
||||
window.MathJax.typesetPromise([reader]).catch(() => {});
|
||||
return;
|
||||
}
|
||||
if (engine === "katex" && window.renderMathInElement) {
|
||||
window.renderMathInElement(reader, {
|
||||
delimiters: [
|
||||
{ left: "$$", right: "$$", display: true },
|
||||
{ left: "\\[", right: "\\]", display: true },
|
||||
{ left: "\\(", right: "\\)", display: false },
|
||||
{ left: "$", right: "$", display: false },
|
||||
],
|
||||
throwOnError: false,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
renderMermaidDiagrams();
|
||||
renderMath();
|
||||
|
||||
document.querySelectorAll(".code-block").forEach((block) => {
|
||||
const code = block.querySelector("pre code");
|
||||
if (!code) {
|
||||
@@ -151,6 +205,10 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
<button type="button" data-action="zoom-in" title="放大">+</button>
|
||||
<button type="button" data-action="rotate-left" title="向左旋转">↺</button>
|
||||
<button type="button" data-action="rotate-right" title="向右旋转">↻</button>
|
||||
<button type="button" data-action="fit" title="适应窗口">适应</button>
|
||||
<button type="button" data-action="actual-size" title="原始大小">原始</button>
|
||||
<button type="button" data-action="save" title="保存图片">保存</button>
|
||||
<button type="button" data-action="reveal" title="在文件夹中显示">定位</button>
|
||||
<button type="button" data-action="reset" title="重置">1:1</button>
|
||||
<button type="button" data-action="close" title="关闭">×</button>
|
||||
</div>
|
||||
@@ -164,6 +222,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
const toolbar = lightbox.querySelector(".image-lightbox__toolbar");
|
||||
let scale = 1;
|
||||
let rotation = 0;
|
||||
let currentImageUrl = "";
|
||||
|
||||
const updatePreviewTransform = () => {
|
||||
preview.style.transform = `scale(${scale}) rotate(${rotation}deg)`;
|
||||
@@ -175,16 +234,30 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
updatePreviewTransform();
|
||||
};
|
||||
|
||||
const fitPreviewToWindow = () => {
|
||||
scale = 1;
|
||||
updatePreviewTransform();
|
||||
};
|
||||
|
||||
const showPreviewActualSize = () => {
|
||||
const renderedWidth = Math.max(1, preview.getBoundingClientRect().width);
|
||||
const naturalWidth = Math.max(1, preview.naturalWidth || renderedWidth);
|
||||
scale = Math.max(0.25, Math.min(5, naturalWidth / renderedWidth));
|
||||
updatePreviewTransform();
|
||||
};
|
||||
|
||||
const closeLightbox = () => {
|
||||
lightbox.classList.remove("is-open");
|
||||
preview.removeAttribute("src");
|
||||
currentImageUrl = "";
|
||||
caption.textContent = "";
|
||||
resetPreviewTransform();
|
||||
};
|
||||
|
||||
document.querySelectorAll(".reader img").forEach((image) => {
|
||||
image.addEventListener("click", () => {
|
||||
preview.src = image.currentSrc || image.src;
|
||||
currentImageUrl = image.currentSrc || image.src;
|
||||
preview.src = currentImageUrl;
|
||||
preview.alt = image.alt || "";
|
||||
caption.textContent = image.alt || image.title || "";
|
||||
resetPreviewTransform();
|
||||
@@ -213,6 +286,22 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
rotation -= 90;
|
||||
} else if (action === "rotate-right") {
|
||||
rotation += 90;
|
||||
} else if (action === "fit") {
|
||||
fitPreviewToWindow();
|
||||
return;
|
||||
} else if (action === "actual-size") {
|
||||
showPreviewActualSize();
|
||||
return;
|
||||
} else if (action === "save") {
|
||||
if (bridge && bridge.saveImage && currentImageUrl) {
|
||||
bridge.saveImage(currentImageUrl);
|
||||
}
|
||||
return;
|
||||
} else if (action === "reveal") {
|
||||
if (bridge && bridge.revealImage && currentImageUrl) {
|
||||
bridge.revealImage(currentImageUrl);
|
||||
}
|
||||
return;
|
||||
} else if (action === "reset") {
|
||||
resetPreviewTransform();
|
||||
return;
|
||||
@@ -258,7 +347,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
}
|
||||
|
||||
if (bridge && bridge.reportScroll) {
|
||||
bridge.reportScroll(progress, activeId);
|
||||
bridge.reportScroll(progress, activeId, Math.max(0, Math.round(window.scrollY || 0)));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
# Vendor Assets
|
||||
|
||||
These files are bundled so MDHelper can render diagrams and formulas without network access.
|
||||
|
||||
- Mermaid 10.9.1: `mermaid/mermaid.min.js`
|
||||
- KaTeX 0.16.9: `katex/katex.min.js`, `katex/auto-render.min.js`, `katex/katex.min.css`, `katex/fonts/*.woff2`
|
||||
- MathJax 3.2.2: `mathjax/tex-svg-full.js`
|
||||
@@ -0,0 +1 @@
|
||||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("katex")):"function"==typeof define&&define.amd?define(["katex"],t):"object"==typeof exports?exports.renderMathInElement=t(require("katex")):e.renderMathInElement=t(e.katex)}("undefined"!=typeof self?self:this,(function(e){return function(){"use strict";var t={771:function(t){t.exports=e}},r={};function n(e){var i=r[e];if(void 0!==i)return i.exports;var a=r[e]={exports:{}};return t[e](a,a.exports,n),a.exports}n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)};var i={};return function(){n.d(i,{default:function(){return s}});var e=n(771),t=n.n(e),r=function(e,t,r){for(var n=r,i=0,a=e.length;n<t.length;){var o=t[n];if(i<=0&&t.slice(n,n+a)===e)return n;"\\"===o?n++:"{"===o?i++:"}"===o&&i--,n++}return-1},a=/^\\begin{/,o=function(e,t){for(var n,i=[],o=new RegExp("("+t.map((function(e){return e.left.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&")})).join("|")+")");-1!==(n=e.search(o));){n>0&&(i.push({type:"text",data:e.slice(0,n)}),e=e.slice(n));var l=t.findIndex((function(t){return e.startsWith(t.left)}));if(-1===(n=r(t[l].right,e,t[l].left.length)))break;var d=e.slice(0,n+t[l].right.length),s=a.test(d)?d:e.slice(t[l].left.length,n);i.push({type:"math",data:s,rawData:d,display:t[l].display}),e=e.slice(n+t[l].right.length)}return""!==e&&i.push({type:"text",data:e}),i},l=function(e,r){var n=o(e,r.delimiters);if(1===n.length&&"text"===n[0].type)return null;for(var i=document.createDocumentFragment(),a=0;a<n.length;a++)if("text"===n[a].type)i.appendChild(document.createTextNode(n[a].data));else{var l=document.createElement("span"),d=n[a].data;r.displayMode=n[a].display;try{r.preProcess&&(d=r.preProcess(d)),t().render(d,l,r)}catch(e){if(!(e instanceof t().ParseError))throw e;r.errorCallback("KaTeX auto-render: Failed to parse `"+n[a].data+"` with ",e),i.appendChild(document.createTextNode(n[a].rawData));continue}i.appendChild(l)}return i},d=function e(t,r){for(var n=0;n<t.childNodes.length;n++){var i=t.childNodes[n];if(3===i.nodeType){for(var a=i.textContent,o=i.nextSibling,d=0;o&&o.nodeType===Node.TEXT_NODE;)a+=o.textContent,o=o.nextSibling,d++;var s=l(a,r);if(s){for(var f=0;f<d;f++)i.nextSibling.remove();n+=s.childNodes.length-1,t.replaceChild(s,i)}else n+=d}else 1===i.nodeType&&function(){var t=" "+i.className+" ";-1===r.ignoredTags.indexOf(i.nodeName.toLowerCase())&&r.ignoredClasses.every((function(e){return-1===t.indexOf(" "+e+" ")}))&&e(i,r)}()}},s=function(e,t){if(!e)throw new Error("No element provided to render");var r={};for(var n in t)t.hasOwnProperty(n)&&(r[n]=t[n]);r.delimiters=r.delimiters||[{left:"$$",right:"$$",display:!0},{left:"\\(",right:"\\)",display:!1},{left:"\\begin{equation}",right:"\\end{equation}",display:!0},{left:"\\begin{align}",right:"\\end{align}",display:!0},{left:"\\begin{alignat}",right:"\\end{alignat}",display:!0},{left:"\\begin{gather}",right:"\\end{gather}",display:!0},{left:"\\begin{CD}",right:"\\end{CD}",display:!0},{left:"\\[",right:"\\]",display:!0}],r.ignoredTags=r.ignoredTags||["script","noscript","style","textarea","pre","code","option"],r.ignoredClasses=r.ignoredClasses||[],r.errorCallback=r.errorCallback||console.error,r.macros=r.macros||{},d(e,r)}}(),i=i.default}()}));
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+2029
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user