Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions website/src/theme/Mermaid/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,29 @@ function MermaidRenderResult({ renderResult }) {

const instance = panzoom(svgEl, {
maxScale: 10,
minScale: 0.1,
minScale: 0.05,
step: 0.15,
contain: 'outside',
contain: false,
pinchAndPan: true,
});
instanceRef.current = instance;

// Wheel zoom: forward wheel events from modal body to panzoom
const handleWheel = (e) => {
e.preventDefault();
const delta = e.deltaY > 0 ? -0.3 : 0.3;
// Calculate zoom around cursor position
const rect = svgEl.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
instance.zoomWithWheel(e, {
step: 0.3,
minScale: 0.05,
maxScale: 10,
});
};
modalEl.addEventListener('wheel', handleWheel, { passive: false });

// Auto-fit: scale the SVG to fill the modal while keeping aspect ratio
const fitToScreen = () => {
const parent = modalRef.current;
Expand Down Expand Up @@ -105,6 +121,7 @@ function MermaidRenderResult({ renderResult }) {

return () => {
clearTimeout(fitTimer);
modalEl.removeEventListener('wheel', handleWheel);
window.removeEventListener('resize', fitToScreen);
window.removeEventListener('keydown', handleKeyDown);
if (instanceRef.current) {
Expand Down
Loading