This commit is contained in:
Yvan
2026-09-23 17:42:55 +08:00
parent 0a8ecbe09b
commit 435b601273
42 changed files with 2845 additions and 154 deletions
+24
View File
@@ -0,0 +1,24 @@
export async function copyLiveText(value, {
clipboard = navigator.clipboard,
documentRef = document,
} = {}) {
const text = String(value)
if (clipboard?.writeText) {
try { await clipboard.writeText(text); return }
catch { /* Older or restricted browsers can still support a selection copy. */ }
}
const previousFocus = documentRef.activeElement
const input = documentRef.createElement('textarea')
input.value = text
input.readOnly = true
input.style.position = 'fixed'
input.style.left = '-9999px'
documentRef.body.appendChild(input)
try {
input.select()
if (!documentRef.execCommand('copy')) throw new Error('Clipboard copy failed')
} finally {
input.remove()
previousFocus?.focus?.({ preventScroll: true })
}
}