| 47 | } |
| 48 | |
| 49 | private setupClickHandler() { |
| 50 | this.canvas.addEventListener('click', (e) => { |
| 51 | if (this.duration === 0) return; |
| 52 | |
| 53 | const rect = this.canvas.getBoundingClientRect(); |
| 54 | const clickX = e.clientX - rect.left + this.canvas.parentElement!.scrollLeft; |
| 55 | |
| 56 | const padding = this.options.compact ? 10 : 40; |
| 57 | const leftPadding = this.options.showLabels ? padding : 10; |
| 58 | const timelineWidth = this.canvas.width - leftPadding - padding; |
| 59 | const relativeX = clickX - leftPadding; |
| 60 | |
| 61 | if (relativeX >= 0 && relativeX <= timelineWidth) { |
| 62 | const clickedTime = (relativeX / timelineWidth) * this.duration; |
| 63 | this.currentTime = clickedTime; |
| 64 | this.draw(); |
| 65 | |
| 66 | if (this.onSeek) { |
| 67 | this.onSeek(clickedTime); |
| 68 | } |
| 69 | } |
| 70 | }); |
| 71 | } |
| 72 | |
| 73 | resize() { |
| 74 | const parent = this.canvas.parentElement; |