export function copyToClipboard (text: string) { document.addEventListener('copy', handler) document.execCommand('copy') function handler (event: any) { event.clipboardData.setData('text/plain', text) event.preventDefault() document.removeEventListener('copy', handler) } } export function bubble (evt: any, text: string) { const left = evt.clientX + 20 const top = evt.clientY const $e = document.createElement('div') $e.textContent = text $e.style.top = top + 'px' $e.style.left = left + 'px' $e.classList.add('honjo-ui-bubble') document.body.appendChild($e) selectText(evt?.target || evt?.srcElement) setTimeout(() => { $e.style.top = (top - 20) + 'px' $e.style.opacity = '0' }, 100) setTimeout(() => { document.body.removeChild($e) }, 1500) function selectText (el: HTMLElement) { if (!el) return const range = document.createRange() range.selectNodeContents(el) const selection = window.getSelection() as any selection.removeAllRanges() selection.addRange(range) } }