|
| 1 | +import { DevtoolsBackend } from '@vue-devtools/app-backend-api' |
| 2 | +import { ComponentInstance } from '@vue/devtools-api' |
| 3 | + |
| 4 | +export async function flashComponent (instance: ComponentInstance, backend: DevtoolsBackend) { |
| 5 | + const bounds = await backend.api.getComponentBounds(instance) |
| 6 | + if (bounds) { |
| 7 | + let overlay: HTMLDivElement = instance.__VUE_DEVTOOLS_FLASH |
| 8 | + if (!overlay) { |
| 9 | + overlay = document.createElement('div') |
| 10 | + instance.__VUE_DEVTOOLS_FLASH = overlay |
| 11 | + overlay.style.border = '2px rgba(65, 184, 131, 0.7) solid' |
| 12 | + overlay.style.position = 'fixed' |
| 13 | + overlay.style.zIndex = '99999999999998' |
| 14 | + overlay.style.pointerEvents = 'none' |
| 15 | + overlay.style.borderRadius = '3px' |
| 16 | + overlay.style.boxSizing = 'border-box' |
| 17 | + document.body.appendChild(overlay) |
| 18 | + } |
| 19 | + overlay.style.opacity = '1' |
| 20 | + overlay.style.transition = null |
| 21 | + overlay.style.width = Math.round(bounds.width) + 'px' |
| 22 | + overlay.style.height = Math.round(bounds.height) + 'px' |
| 23 | + overlay.style.left = Math.round(bounds.left) + 'px' |
| 24 | + overlay.style.top = Math.round(bounds.top) + 'px' |
| 25 | + requestAnimationFrame(() => { |
| 26 | + overlay.style.transition = 'opacity 1s' |
| 27 | + overlay.style.opacity = '0' |
| 28 | + }) |
| 29 | + clearTimeout((overlay as any)._timer) |
| 30 | + ;(overlay as any)._timer = setTimeout(() => { |
| 31 | + document.body.removeChild(overlay) |
| 32 | + instance.__VUE_DEVTOOLS_FLASH = null |
| 33 | + }, 1000) |
| 34 | + } |
| 35 | +} |
0 commit comments