Skip to content

Commit efa5f2b

Browse files
Merge pull request #27 from ThisIs-Developer/copilot/fix-copy-button-toolbar-order
Mermaid UI: fix Copy button visibility, toolbar order, modal size, and modal Copy action
2 parents 03b4b59 + 3abcdd7 commit efa5f2b

3 files changed

Lines changed: 44 additions & 4 deletions

File tree

index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ <h5>Menu</h5>
243243
<button class="mermaid-toolbar-btn" id="mermaid-modal-zoom-reset" title="Reset zoom">
244244
<i class="bi bi-arrows-angle-contract"></i> Reset
245245
</button>
246+
<button class="mermaid-toolbar-btn" id="mermaid-modal-copy" title="Copy image">
247+
<i class="bi bi-clipboard-image"></i> Copy
248+
</button>
246249
<button class="mermaid-toolbar-btn" id="mermaid-modal-download-png" title="Download PNG">
247250
<i class="bi bi-file-image"></i> PNG
248251
</button>

script.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,6 +1843,31 @@ This is a fully client-side application. Your content never leaves your browser
18431843
}
18441844
});
18451845

1846+
document.getElementById('mermaid-modal-copy').addEventListener('click', async function() {
1847+
if (!modalCurrentSvgEl) return;
1848+
const btn = this;
1849+
const original = btn.innerHTML;
1850+
btn.innerHTML = '<i class="bi bi-hourglass-split"></i>';
1851+
try {
1852+
const canvas = await svgToCanvas(modalCurrentSvgEl);
1853+
canvas.toBlob(async blob => {
1854+
try {
1855+
await navigator.clipboard.write([
1856+
new ClipboardItem({ 'image/png': blob })
1857+
]);
1858+
btn.innerHTML = '<i class="bi bi-check-lg"></i> Copied!';
1859+
} catch (clipErr) {
1860+
console.error('Clipboard write failed:', clipErr);
1861+
btn.innerHTML = '<i class="bi bi-x-lg"></i>';
1862+
}
1863+
setTimeout(() => { btn.innerHTML = original; }, 1800);
1864+
}, 'image/png');
1865+
} catch (e) {
1866+
console.error('Modal copy failed:', e);
1867+
btn.innerHTML = original;
1868+
}
1869+
});
1870+
18461871
document.getElementById('mermaid-modal-download-svg').addEventListener('click', function() {
18471872
if (!modalCurrentSvgEl) return;
18481873
const serialized = new XMLSerializer().serializeToString(modalCurrentSvgEl);
@@ -1885,7 +1910,7 @@ This is a fully client-side application. Your content never leaves your browser
18851910
btnCopy.className = 'mermaid-toolbar-btn';
18861911
btnCopy.title = 'Copy image to clipboard';
18871912
btnCopy.setAttribute('aria-label', 'Copy image to clipboard');
1888-
btnCopy.innerHTML = '<i class="bi bi-clipboard-image"></i>';
1913+
btnCopy.innerHTML = '<i class="bi bi-clipboard-image"></i> Copy';
18891914
btnCopy.addEventListener('click', () => copyMermaidImage(container, btnCopy));
18901915

18911916
const btnSvg = document.createElement('button');
@@ -1896,8 +1921,8 @@ This is a fully client-side application. Your content never leaves your browser
18961921
btnSvg.addEventListener('click', () => downloadMermaidSvg(container, btnSvg));
18971922

18981923
toolbar.appendChild(btnZoom);
1899-
toolbar.appendChild(btnPng);
19001924
toolbar.appendChild(btnCopy);
1925+
toolbar.appendChild(btnPng);
19011926
toolbar.appendChild(btnSvg);
19021927
container.appendChild(toolbar);
19031928
});

styles.css

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,13 +1027,25 @@ a:focus {
10271027
border: 1px solid var(--border-color);
10281028
border-radius: 8px;
10291029
padding: 16px;
1030-
max-width: 92vw;
1031-
max-height: 92vh;
1030+
width: 85vw;
1031+
height: 85vh;
1032+
max-width: 85vw;
1033+
max-height: 85vh;
10321034
display: flex;
10331035
flex-direction: column;
10341036
gap: 12px;
10351037
}
10361038

1039+
@media (max-width: 576px) {
1040+
.mermaid-modal-content {
1041+
width: 95vw;
1042+
height: 90vh;
1043+
max-width: 95vw;
1044+
max-height: 90vh;
1045+
padding: 10px;
1046+
}
1047+
}
1048+
10371049
.mermaid-modal-header {
10381050
display: flex;
10391051
justify-content: space-between;

0 commit comments

Comments
 (0)