@@ -57,32 +57,54 @@ export function HowToSetupYourProject() {
57
57
if ( events !== null ) {
58
58
// This uses https://www.npmjs.com/package/canvas-confetti
59
59
if ( "confetti" in window && typeof window . confetti !== "undefined" ) {
60
- var duration = 2.5 * 1000 ;
61
- var end = Date . now ( ) + duration ;
60
+ const duration = 3.5 * 1000 ;
61
+ const animationEnd = Date . now ( ) + duration ;
62
+ const defaults = {
63
+ startVelocity : 30 ,
64
+ spread : 360 ,
65
+ ticks : 60 ,
66
+ zIndex : 0 ,
67
+ colors : [
68
+ "#E7FF52" ,
69
+ "#41FF54" ,
70
+ "rgb(245 158 11)" ,
71
+ "rgb(22 163 74)" ,
72
+ "rgb(37 99 235)" ,
73
+ "rgb(67 56 202)" ,
74
+ "rgb(219 39 119)" ,
75
+ "rgb(225 29 72)" ,
76
+ "rgb(217 70 239)" ,
77
+ ] ,
78
+ } ;
79
+ // @ts -ignore
80
+ function randomInRange ( min , max ) {
81
+ return Math . random ( ) * ( max - min ) + min ;
82
+ }
83
+ // @ts -ignore
84
+ const interval = setInterval ( function ( ) {
85
+ const timeLeft = animationEnd - Date . now ( ) ;
86
+
87
+ if ( timeLeft <= 0 ) {
88
+ return clearInterval ( interval ) ;
89
+ }
62
90
63
- ( function frame ( ) {
64
- // launch a few confetti from the left edge
91
+ const particleCount = 50 * ( timeLeft / duration ) ;
92
+ // since particles fall down, start a bit higher than random
65
93
// @ts -ignore
66
- window . confetti ( {
67
- particleCount : 7 ,
68
- angle : 60 ,
69
- spread : 55 ,
70
- origin : { x : 0 } ,
71
- } ) ;
72
- // and launch a few from the right edge
94
+ window . confetti (
95
+ Object . assign ( { } , defaults , {
96
+ particleCount,
97
+ origin : { x : randomInRange ( 0.1 , 0.4 ) , y : Math . random ( ) - 0.2 } ,
98
+ } )
99
+ ) ;
73
100
// @ts -ignore
74
- window . confetti ( {
75
- particleCount : 7 ,
76
- angle : 120 ,
77
- spread : 55 ,
78
- origin : { x : 1 } ,
79
- } ) ;
80
-
81
- // keep going until we are out of time
82
- if ( Date . now ( ) < end ) {
83
- requestAnimationFrame ( frame ) ;
84
- }
85
- } ) ( ) ;
101
+ window . confetti (
102
+ Object . assign ( { } , defaults , {
103
+ particleCount,
104
+ origin : { x : randomInRange ( 0.6 , 0.9 ) , y : Math . random ( ) - 0.2 } ,
105
+ } )
106
+ ) ;
107
+ } , 250 ) ;
86
108
}
87
109
88
110
revalidator . revalidate ( ) ;
0 commit comments