@@ -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 } ) ;
0 commit comments