11import type { IllestWaveformProps } from '../types/waveform'
22
33export default class Wave {
4- protected canvasCtx ! : CanvasRenderingContext2D
4+ private canvasCtx ! : CanvasRenderingContext2D
55
66 constructor (
7- protected canvas : HTMLCanvasElement ,
8- protected props : IllestWaveformProps ,
9- protected filteredData : number [ ] [ ]
7+ private canvas : HTMLCanvasElement ,
8+ private props : IllestWaveformProps ,
9+ private filteredData : number [ ] [ ]
1010 ) {
1111 this . canvas = canvas
1212 this . canvasCtx = this . canvas ?. getContext ( '2d' ) as CanvasRenderingContext2D
@@ -32,7 +32,7 @@ export default class Wave {
3232 this . drawCanvasLines ( )
3333 }
3434
35- protected setCanvasBase ( ) : void {
35+ private setCanvasBase ( ) : void {
3636 this . canvas . width = this . canvas . offsetWidth
3737 this . canvas . height = this . canvas . offsetHeight
3838 this . canvas . style . opacity = '1'
@@ -64,17 +64,24 @@ export default class Wave {
6464 }
6565
6666 private drawMask ( maskWidth : number ) : void {
67- this . canvasCtx . globalCompositeOperation = 'destination-atop'
68- this . canvasCtx . fillStyle = this . props . maskColor as string
69- this . canvasCtx . fillRect ( 0 , 0 , maskWidth , this . canvas . height )
67+ const { canvas, canvasCtx, props } = this
68+ canvasCtx . globalCompositeOperation = 'destination-atop'
69+ canvasCtx . fillStyle = props . maskColor as string
70+ canvasCtx . fillRect ( 0 , 0 , maskWidth , canvas . height )
7071 }
7172
72- public setCanvasStyle ( maskWidth : number ) : void {
73- this . canvasCtx . clearRect ( 0 , 0 , this . canvas . width , this . canvas . height )
73+ private drawWave ( ) : void {
74+ const { canvasCtx, props } = this
75+ canvasCtx . lineWidth = props . lineWidth as number
76+ canvasCtx . lineCap = props . lineCap as CanvasLineCap
77+ canvasCtx . strokeStyle = props . lineColor as string
78+ canvasCtx . stroke ( )
79+ }
80+
81+ public setWaveStyle ( maskWidth : number ) : void {
82+ const { canvas, canvasCtx } = this
83+ canvasCtx . clearRect ( 0 , 0 , canvas . width , canvas . height )
7484 this . drawMask ( maskWidth )
75- this . canvasCtx . lineWidth = this . props . lineWidth as number
76- this . canvasCtx . lineCap = this . props . lineCap as CanvasLineCap
77- this . canvasCtx . strokeStyle = this . props . lineColor as string
78- this . canvasCtx . stroke ( )
85+ this . drawWave ( )
7986 }
8087}
0 commit comments