Skip to content

Commit

Permalink
Fix: limit resize observer to width
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed Jan 4, 2024
1 parent 9829f93 commit 1383759
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Renderer extends EventEmitter<RendererEvents> {
private isScrollable = false
private audioData: AudioBuffer | null = null
private resizeObserver: ResizeObserver | null = null
private lastContainerWidth: number = 0

Check failure on line 27 in src/renderer.ts

View workflow job for this annotation

GitHub Actions / ESLint Results

@typescript-eslint/no-inferrable-types

Type number trivially inferred from a number literal, remove type annotation.
private isDragging = false

constructor(options: WaveSurferOptions, audioElement?: HTMLElement) {
Expand Down Expand Up @@ -103,11 +104,18 @@ class Renderer extends EventEmitter<RendererEvents> {
// Re-render the waveform on container resize
const delay = this.createDelay(100)
this.resizeObserver = new ResizeObserver(() => {
delay(() => this.reRender())
delay(() => this.onContainerResize())
})
this.resizeObserver.observe(this.scrollContainer)
}

private onContainerResize() {
const width = this.parent.clientWidth
if (width === this.lastContainerWidth && this.options.height !== 'auto') return
this.lastContainerWidth = width
this.reRender()
}

private initDrag() {
makeDraggable(
this.wrapper,
Expand Down

0 comments on commit 1383759

Please sign in to comment.