1
- /*! Granim v1.0.5 - https://sarcadass.github.io/granim.js */
1
+ /*! Granim v1.0.6 - https://sarcadass.github.io/granim.js */
2
2
( function e ( t , n , r ) { function s ( o , u ) { if ( ! n [ o ] ) { if ( ! t [ o ] ) { var a = typeof require == "function" && require ; if ( ! u && a ) return a ( o , ! 0 ) ; if ( i ) return i ( o , ! 0 ) ; var f = new Error ( "Cannot find module '" + o + "'" ) ; throw f . code = "MODULE_NOT_FOUND" , f } var l = n [ o ] = { exports :{ } } ; t [ o ] [ 0 ] . call ( l . exports , function ( e ) { var n = t [ o ] [ 1 ] [ e ] ; return s ( n ?n :e ) } , l , l . exports , e , t , n , r ) } return n [ o ] . exports } var i = typeof require == "function" && require ; for ( var o = 0 ; o < r . length ; o ++ ) s ( r [ o ] ) ; return s } ) ( { 1 :[ function ( require , module , exports ) {
3
3
'use strict' ;
4
4
5
5
function Granim ( options ) {
6
- if ( options . element instanceof HTMLCanvasElement )
7
- this . canvas = options . element
8
- else if ( typeof options . element === "string" )
9
- this . canvas = document . querySelector ( options . element )
10
- else
11
- throw new Error ( 'The element you used is neither a String, nor a HTMLCanvasElement' ) ;
12
- if ( ! this . canvas ) {
13
- throw new Error ( '`' + options . element + '` could not be found in the DOM' ) ;
14
- }
6
+ this . getElement ( options . element ) ;
15
7
this . x1 = 0 ;
16
8
this . y1 = 0 ;
17
9
this . name = options . name || false ;
@@ -24,6 +16,7 @@ function Granim(options) {
24
16
this . previousTimeStamp = null ;
25
17
this . progress = 0 ;
26
18
this . isPaused = false ;
19
+ this . isCleared = false ;
27
20
this . isPausedBecauseNotInView = false ;
28
21
this . iscurrentColorsSet = false ;
29
22
this . context = this . canvas . getContext ( '2d' ) ;
@@ -91,6 +84,8 @@ Granim.prototype.makeGradient = require('./makeGradient.js');
91
84
92
85
Granim . prototype . getDimensions = require ( './getDimensions.js' ) ;
93
86
87
+ Granim . prototype . getElement = require ( './getElement.js' ) ;
88
+
94
89
Granim . prototype . animateColors = require ( './animateColors.js' ) ;
95
90
96
91
Granim . prototype . getLightness = require ( './getLightness.js' ) ;
@@ -113,7 +108,7 @@ Granim.prototype.onResize = require('./onResize.js');
113
108
114
109
module . exports = Granim ;
115
110
116
- } , { "./animateColors.js" :2 , "./changeState.js" :3 , "./clear.js" :4 , "./colorDiff.js" :5 , "./eventPolyfill.js" :6 , "./getCurrentColors.js" :7 , "./getDimensions.js" :8 , "./getLightness .js" :9 , "./hexToRgb .js" :10 , "./makeGradient .js" :11 , "./onResize .js" :12 , "./pause .js" :13 , "./pauseWhenNotInView .js" :14 , "./play .js" :15 , "./refreshColors .js" :16 , "./setColors .js" :17 , "./setDirection .js" :18 } ] , 2 :[ function ( require , module , exports ) {
111
+ } , { "./animateColors.js" :2 , "./changeState.js" :3 , "./clear.js" :4 , "./colorDiff.js" :5 , "./eventPolyfill.js" :6 , "./getCurrentColors.js" :7 , "./getDimensions.js" :8 , "./getElement .js" :9 , "./getLightness .js" :10 , "./hexToRgb .js" :11 , "./makeGradient .js" :12 , "./onResize .js" :13 , "./pause .js" :14 , "./pauseWhenNotInView .js" :15 , "./play .js" :16 , "./refreshColors .js" :17 , "./setColors .js" :18 , "./setDirection.js" : 19 } ] , 2 :[ function ( require , module , exports ) {
117
112
'use strict' ;
118
113
119
114
module . exports = function ( timestamp ) {
@@ -241,9 +236,16 @@ module.exports = function(state) {
241
236
'use strict' ;
242
237
243
238
module . exports = function ( ) {
244
- cancelAnimationFrame ( this . animation ) ;
239
+ if ( ! this . isPaused ) {
240
+ cancelAnimationFrame ( this . animation ) ;
241
+
242
+ } else {
243
+ this . isPaused = false ;
244
+ }
245
+ this . isCleared = true ;
245
246
this . context . clearRect ( 0 , 0 , this . x1 , this . y1 ) ;
246
247
} ;
248
+
247
249
} , { } ] , 5 :[ function ( require , module , exports ) {
248
250
'use strict' ;
249
251
@@ -306,6 +308,25 @@ module.exports = function() {
306
308
} , { } ] , 9 :[ function ( require , module , exports ) {
307
309
'use strict' ;
308
310
311
+ module . exports = function ( element ) {
312
+ if ( element instanceof HTMLCanvasElement ) {
313
+ this . canvas = element ;
314
+
315
+ } else if ( typeof element === "string" ) {
316
+ this . canvas = document . querySelector ( element ) ;
317
+
318
+ } else {
319
+ throw new Error ( 'The element you used is neither a String, nor a HTMLCanvasElement' ) ;
320
+ }
321
+
322
+ if ( ! this . canvas ) {
323
+ throw new Error ( '`' + element + '` could not be found in the DOM' ) ;
324
+ }
325
+ } ;
326
+
327
+ } , { } ] , 10 :[ function ( require , module , exports ) {
328
+ 'use strict' ;
329
+
309
330
module . exports = function ( ) {
310
331
var currentColors = this . getCurrentColors ( ) ;
311
332
var colorsAverage = [ ] ;
@@ -337,7 +358,7 @@ module.exports = function() {
337
358
return lightnessAverage >= 128 ? 'light' : 'dark' ;
338
359
} ;
339
360
340
- } , { } ] , 10 :[ function ( require , module , exports ) {
361
+ } , { } ] , 11 :[ function ( require , module , exports ) {
341
362
'use strict' ;
342
363
343
364
module . exports = function ( hex ) {
@@ -355,7 +376,7 @@ module.exports = function(hex) {
355
376
] : null ;
356
377
} ;
357
378
358
- } , { } ] , 11 :[ function ( require , module , exports ) {
379
+ } , { } ] , 12 :[ function ( require , module , exports ) {
359
380
'use strict' ;
360
381
361
382
module . exports = function ( ) {
@@ -392,7 +413,7 @@ module.exports = function() {
392
413
this . context . fillRect ( 0 , 0 , this . x1 , this . y1 ) ;
393
414
} ;
394
415
395
- } , { } ] , 12 :[ function ( require , module , exports ) {
416
+ } , { } ] , 13 :[ function ( require , module , exports ) {
396
417
'use strict' ;
397
418
398
419
module . exports = function ( ) {
@@ -402,16 +423,17 @@ module.exports = function() {
402
423
this . refreshColors ( ) ;
403
424
} ;
404
425
405
- } , { } ] , 13 :[ function ( require , module , exports ) {
426
+ } , { } ] , 14 :[ function ( require , module , exports ) {
406
427
'use strict' ;
407
428
408
429
module . exports = function ( state ) {
409
430
var isPausedBecauseNotInView = state === 'isPausedBecauseNotInView' ;
431
+ if ( this . isCleared ) { return ; }
410
432
if ( ! isPausedBecauseNotInView ) this . isPaused = true ;
411
433
cancelAnimationFrame ( this . animation ) ;
412
434
} ;
413
435
414
- } , { } ] , 14 :[ function ( require , module , exports ) {
436
+ } , { } ] , 15 :[ function ( require , module , exports ) {
415
437
'use strict' ;
416
438
417
439
module . exports = function ( ) {
@@ -447,16 +469,19 @@ module.exports = function() {
447
469
}
448
470
} ;
449
471
450
- } , { } ] , 15 :[ function ( require , module , exports ) {
472
+ } , { } ] , 16 :[ function ( require , module , exports ) {
451
473
'use strict' ;
452
474
453
475
module . exports = function ( state ) {
454
476
var isPausedBecauseNotInView = state === 'isPausedBecauseNotInView' ;
455
- if ( ! isPausedBecauseNotInView ) this . isPaused = false ;
477
+ if ( ! isPausedBecauseNotInView ) {
478
+ this . isPaused = false ;
479
+ }
480
+ this . isCleared = false ;
456
481
this . animation = requestAnimationFrame ( this . animateColors . bind ( this ) ) ;
457
482
} ;
458
483
459
- } , { } ] , 16 :[ function ( require , module , exports ) {
484
+ } , { } ] , 17 :[ function ( require , module , exports ) {
460
485
'use strict' ;
461
486
462
487
module . exports = function ( progressPercent ) {
@@ -478,7 +503,7 @@ module.exports = function(progressPercent) {
478
503
this . makeGradient ( ) ;
479
504
} ;
480
505
481
- } , { } ] , 17 :[ function ( require , module , exports ) {
506
+ } , { } ] , 18 :[ function ( require , module , exports ) {
482
507
'use strict' ;
483
508
484
509
module . exports = function ( ) {
@@ -540,7 +565,7 @@ module.exports = function() {
540
565
this . iscurrentColorsSet = true ;
541
566
} ;
542
567
543
- } , { } ] , 18 :[ function ( require , module , exports ) {
568
+ } , { } ] , 19 :[ function ( require , module , exports ) {
544
569
'use strict' ;
545
570
546
571
module . exports = function ( ) {
@@ -566,7 +591,7 @@ module.exports = function() {
566
591
}
567
592
} ;
568
593
569
- } , { } ] , 19 :[ function ( require , module , exports ) {
594
+ } , { } ] , 20 :[ function ( require , module , exports ) {
570
595
window . Granim = require ( './lib/Granim.js' ) ;
571
596
572
- } , { "./lib/Granim.js" :1 } ] } , { } , [ 19 ] ) ;
597
+ } , { "./lib/Granim.js" :1 } ] } , { } , [ 20 ] ) ;
0 commit comments