Skip to content
26 changes: 11 additions & 15 deletions src/_support/html/Broadcast Registry Mermaid.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CSM Mermaid Diagram</title>
<style>
.mermaid-container {
overflow: visible;
Expand Down Expand Up @@ -29,6 +31,8 @@
font-size: 14px;
margin-bottom: 10px;
width: fit-content;
max-width: calc(100vw - 30px);
box-sizing: border-box;
position: fixed;
top: 10px;
left: 10px;
Expand All @@ -51,7 +55,7 @@
// 根据浏览器语言设置提示文本
function setTipsByBrowserLanguage() {
const tipsElement = document.getElementById('operation-tips');
const browserLanguage = navigator.language || navigator.userLanguage;
const browserLanguage = navigator.language || 'en';

// 检测是否为中文
if (browserLanguage.includes('zh')) {
Expand All @@ -67,6 +71,8 @@
// 初始化缩放因子
let scale = 1;
const scaleStep = 0.1;
const scaleMax = 5;
const scaleMin = 0.1;
const container = document.querySelector('.mermaid-container');
const mermaidElement = document.querySelector('.mermaid');

Expand All @@ -83,31 +89,21 @@
// 计算新的缩放因子
if (e.deltaY < 0) {
// 向上滚动,放大
scale += scaleStep;
scale = Math.round(Math.min(scaleMax, scale + scaleStep) * 10) / 10; // 最大缩放到 scaleMax
} else {
// 向下滚动,缩小
scale = Math.max(0.1, scale - scaleStep); // 最小缩放到 0.1
scale = Math.round(Math.max(scaleMin, scale - scaleStep) * 10) / 10; // 最小缩放到 scaleMin
}

// 应用缩放
mermaidElement.style.transform = `scale(${scale})`;
});
}, { passive: false });

// 双击重置缩放
container.addEventListener('dblclick', function() {
scale = 1;
mermaidElement.style.transform = 'scale(1)';
});

// 等待 mermaid 渲染完成后再应用缩放
document.addEventListener('DOMContentLoaded', function() {
setTimeout(function() {
// 确保 mermaid 已经渲染完成
if (mermaidElement) {
mermaidElement.style.transform = `scale(${scale})`;
}
}, 100);
});
</script>

</body>
Expand Down
Loading