chore: replace Map by WeakMap (#2499)

pull/2515/head
丶远方 1 year ago committed by GitHub
parent a5475304fa
commit 656df5c761
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

Loading…
Cancel
Save