| | |
| | | this.container = viewer?.container || null |
| | | this.tooltipEl = null |
| | | this.isVisible = false |
| | | this.handleMouseLeave = this.handleMouseLeave.bind(this) |
| | | this.init() |
| | | } |
| | | |
| | |
| | | el.style.display = 'none' |
| | | this.container.appendChild(el) |
| | | this.tooltipEl = el |
| | | this.container.addEventListener('mouseleave', this.handleMouseLeave) |
| | | this.container.addEventListener('pointerleave', this.handleMouseLeave) |
| | | } |
| | | |
| | | show(text, position) { |
| | |
| | | |
| | | move(position) { |
| | | if (!this.tooltipEl || !position) return |
| | | const width = this.container?.clientWidth ?? 0 |
| | | const height = this.container?.clientHeight ?? 0 |
| | | if ( |
| | | !width || |
| | | !height || |
| | | position.x < 0 || |
| | | position.y < 0 || |
| | | position.x > width || |
| | | position.y > height |
| | | ) { |
| | | this.hide() |
| | | return |
| | | } |
| | | const offset = this.options.offset || { x: 12, y: 12 } |
| | | this.tooltipEl.style.left = `${position.x + offset.x}px` |
| | | this.tooltipEl.style.top = `${position.y + offset.y}px` |
| | |
| | | this.isVisible = false |
| | | } |
| | | |
| | | handleMouseLeave() { |
| | | this.hide() |
| | | } |
| | | |
| | | destroy() { |
| | | this.hide() |
| | | if (this.container) { |
| | | this.container.removeEventListener('mouseleave', this.handleMouseLeave) |
| | | this.container.removeEventListener('pointerleave', this.handleMouseLeave) |
| | | } |
| | | if (this.tooltipEl && this.container) { |
| | | this.container.removeChild(this.tooltipEl) |
| | | } |