11import { Explosion } from './explosion.js'
22import { floor , randomFloat , randomInt } from './helpers.js'
33import { Mouse } from './mouse.js'
4- import { opts } from './options.js'
4+ import { Options } from './options.js'
55import { RequestAnimationFrame } from './raf.js'
66import { Resize } from './resize.js'
77import { Sound } from './sound.js'
@@ -15,6 +15,7 @@ export class Fireworks {
1515 private ctx : CanvasRenderingContext2D
1616 private width : number
1717 private height : number
18+ private opts : Options
1819 private sound : Sound
1920 private resize : Resize
2021 private mouse : Mouse
@@ -31,13 +32,15 @@ export class Fireworks {
3132 this . target = container
3233 this . container = container
3334
34- this . createCanvas ( this . target )
35+ this . opts = new Options ( )
36+
3537 this . updateOptions ( options )
38+ this . createCanvas ( this . target )
3639
37- this . sound = new Sound ( )
40+ this . sound = new Sound ( this )
3841 this . resize = new Resize ( this )
39- this . mouse = new Mouse ( this . canvas )
40- this . raf = new RequestAnimationFrame ( this . render . bind ( this ) )
42+ this . mouse = new Mouse ( this , this . canvas )
43+ this . raf = new RequestAnimationFrame ( this , this . render . bind ( this ) )
4144 }
4245
4346 get isRunning ( ) : boolean {
@@ -48,6 +51,10 @@ export class Fireworks {
4851 return __VERSION__
4952 }
5053
54+ get options ( ) : Options {
55+ return this . opts
56+ }
57+
5158 start ( ) : void {
5259 if ( this . running ) return
5360
@@ -122,7 +129,7 @@ export class Fireworks {
122129 }
123130
124131 updateOptions ( options : FireworksOptions ) : void {
125- opts . updateOptions ( options )
132+ this . opts . update ( options )
126133 }
127134
128135 updateSize ( {
@@ -136,7 +143,7 @@ export class Fireworks {
136143 this . canvas . height = height
137144
138145 this . updateBoundaries ( {
139- ...opts . boundaries ,
146+ ...this . opts . boundaries ,
140147 width,
141148 height
142149 } )
@@ -165,7 +172,7 @@ export class Fireworks {
165172 private render ( ) : void {
166173 if ( ! this . ctx || ! this . running ) return
167174
168- const { opacity, lineStyle, lineWidth } = opts
175+ const { opacity, lineStyle, lineWidth } = this . opts
169176 this . ctx . globalCompositeOperation = 'destination-out'
170177 this . ctx . fillStyle = `rgba(0, 0, 0, ${ opacity } )`
171178 this . ctx . fillRect ( 0 , 0 , this . width , this . height )
@@ -188,7 +195,7 @@ export class Fireworks {
188195 traceSpeed,
189196 acceleration,
190197 mouse
191- } = opts
198+ } = this . opts
192199
193200 this . traces . push (
194201 new Trace ( {
@@ -214,9 +221,10 @@ export class Fireworks {
214221 private initTrace ( ) : void {
215222 if ( this . waitStopRaf ) return
216223
224+ const { delay, mouse } = this . opts
217225 if (
218- this . raf . tick > randomInt ( opts . delay . min , opts . delay . max ) ||
219- ( this . mouse . active && opts . mouse . max > this . traces . length )
226+ this . raf . tick > randomInt ( delay . min , delay . max ) ||
227+ ( this . mouse . active && mouse . max > this . traces . length )
220228 ) {
221229 this . createTrace ( )
222230 this . raf . tick = 0
@@ -245,7 +253,7 @@ export class Fireworks {
245253 friction,
246254 gravity,
247255 decay
248- } = opts
256+ } = this . opts
249257
250258 let particlesLength = floor ( particles )
251259 while ( particlesLength -- ) {
0 commit comments