-
Notifications
You must be signed in to change notification settings - Fork 320
Expand file tree
/
Copy pathoverlay.element.js
More file actions
45 lines (34 loc) · 1020 Bytes
/
overlay.element.js
File metadata and controls
45 lines (34 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { OverlayStyles } from '../styles.store'
export class Overlay extends HTMLElement {
constructor() {
super()
this.$shadow = this.attachShadow({mode: 'closed'})
}
connectedCallback() {
this.$shadow.adoptedStyleSheets = [OverlayStyles]
}
disconnectedCallback() {}
set position(boundingRect) {
this.$shadow.innerHTML = this.render(boundingRect)
}
set update({ top, left, width, height }) {
const [svg] = this.$shadow.children
this.$shadow.host.style.display = 'block'
svg.style.display = 'block'
this.style.setProperty('--top', `${top}px`)
this.style.setProperty('--left', `${left - 1}px`)
svg.setAttribute('width', width + 'px')
svg.setAttribute('height', height + 'px')
}
render({height, width}) {
return `
<svg class="visbug-overlay"
width="${width}px" height="${height}px"
viewBox="0 0 ${width} ${height}"
>
<rect></rect>
</svg>
`
}
}
customElements.define('visbug-overlay', Overlay)