fix: copy svg (#491)
All checks were successful
Build and Deploy / build-and-deploy (push) Has been skipped

close #490
This commit is contained in:
Libin YANG 2024-12-23 11:34:33 +08:00 committed by GitHub
parent 8d620bc693
commit 1ab6cbfeb2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -64,6 +64,15 @@ const copyMode = useStorage(addPrefix(`copyMode`), `txt`)
const source = ref(``)
const { copy: copyContent } = useClipboard({ source })
const creatEmptyNode = () => {
const node = document.createElement(`p`)
node.style.fontSize = `0`
node.style.lineHeight = `0`
node.style.margin = `0`
node.innerHTML = ` `
return node
}
//
function copy() {
emit(`startCopy`)
@ -107,13 +116,11 @@ function copy() {
clipboardDiv.focus()
// edge case: svg
const p = document.createElement(`p`)
p.style.fontSize = `0` // 0
p.style.lineHeight = `0` // 0
p.style.margin = `0` //
p.innerHTML = ` `
clipboardDiv.insertBefore(p, clipboardDiv.firstChild)
// svg
const beforeNode = creatEmptyNode()
const afterNode = creatEmptyNode()
clipboardDiv.insertBefore(beforeNode, clipboardDiv.firstChild)
clipboardDiv.appendChild(afterNode)
// Mermaid
const nodes = clipboardDiv.querySelectorAll(`.nodeLabel`)