|
|
@ -2,13 +2,12 @@ import { inBrowser } from 'vitepress'
|
|
|
|
|
|
|
|
|
|
|
|
export function useCopyCode() {
|
|
|
|
export function useCopyCode() {
|
|
|
|
if (inBrowser) {
|
|
|
|
if (inBrowser) {
|
|
|
|
const timeoutIdMap: Map<HTMLElement, NodeJS.Timeout> = new Map()
|
|
|
|
const timeoutIdMap: WeakMap<HTMLElement, NodeJS.Timeout> = new WeakMap()
|
|
|
|
window.addEventListener('click', (e) => {
|
|
|
|
window.addEventListener('click', (e) => {
|
|
|
|
const el = e.target as HTMLElement
|
|
|
|
const el = e.target as HTMLElement
|
|
|
|
if (el.matches('div[class*="language-"] > button.copy')) {
|
|
|
|
if (el.matches('div[class*="language-"] > button.copy')) {
|
|
|
|
const parent = el.parentElement
|
|
|
|
const parent = el.parentElement
|
|
|
|
const sibling = el.nextElementSibling
|
|
|
|
const sibling = el.nextElementSibling?.nextElementSibling
|
|
|
|
?.nextElementSibling as HTMLPreElement | null
|
|
|
|
|
|
|
|
if (!parent || !sibling) {
|
|
|
|
if (!parent || !sibling) {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|