1
1
/*! Granim v1.1.1 - https://sarcadass.github.io/granim.js */
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 ) {
2
+ ( function ( ) { function r ( e , n , t ) { function o ( i , f ) { if ( ! n [ i ] ) { if ( ! e [ i ] ) { var c = "function" == typeof require && require ; if ( ! f && c ) return c ( i , ! 0 ) ; if ( u ) return u ( i , ! 0 ) ; var a = new Error ( "Cannot find module '" + i + "'" ) ; throw a . code = "MODULE_NOT_FOUND" , a } var p = n [ i ] = { exports :{ } } ; e [ i ] [ 0 ] . call ( p . exports , function ( r ) { var n = e [ i ] [ 1 ] [ r ] ; return o ( n || r ) } , p , p . exports , r , e , n , t ) } return n [ i ] . exports } for ( var u = "function" == typeof require && require , i = 0 ; i < t . length ; i ++ ) o ( t [ i ] ) ; return o } return r } ) ( ) ( { 1 :[ function ( require , module , exports ) {
3
3
'use strict' ;
4
4
5
5
function Granim ( options ) {
@@ -10,6 +10,8 @@ function Granim(options) {
10
10
this . name = options . name || false ;
11
11
this . elToSetClassOn = options . elToSetClassOn || 'body' ;
12
12
this . direction = options . direction || 'diagonal' ;
13
+ this . customDirection = options . customDirection || { } ;
14
+ this . validateCustomDirection ( ) ;
13
15
this . isPausedWhenNotInView = options . isPausedWhenNotInView || false ;
14
16
this . opacity = options . opacity ;
15
17
this . states = options . states ;
@@ -44,13 +46,13 @@ function Granim(options) {
44
46
blendingMode : options . image . blendingMode || false
45
47
} ;
46
48
}
47
- doesGradientUseOpacity = this . opacity . map ( function ( el ) { return el !== 1 } )
49
+ doesGradientUseOpacity = this . opacity . map ( function ( el ) { return el !== 1 } )
48
50
. indexOf ( true ) !== - 1 ;
49
51
this . shouldClearCanvasOnEachFrame = ! ! this . image || doesGradientUseOpacity ;
50
52
this . events = {
51
53
start : new CustomEvent ( 'granim:start' ) ,
52
54
end : new CustomEvent ( 'granim:end' ) ,
53
- gradientChange : function ( details ) {
55
+ gradientChange : function ( details ) {
54
56
return new CustomEvent ( 'granim:gradientChange' , {
55
57
detail : {
56
58
isLooping : details . isLooping ,
@@ -105,6 +107,8 @@ Granim.prototype.onScroll = require('./onScroll.js');
105
107
106
108
Granim . prototype . validateInput = require ( './validateInput.js' ) ;
107
109
110
+ Granim . prototype . validateCustomDirection = require ( './validateCustomDirection.js' ) ;
111
+
108
112
Granim . prototype . triggerError = require ( './triggerError.js' ) ;
109
113
110
114
Granim . prototype . prepareImage = require ( './prepareImage.js' ) ;
@@ -153,7 +157,7 @@ Granim.prototype.changeState = require('./changeState.js');
153
157
154
158
module . exports = Granim ;
155
159
156
- } , { "./animateColors.js" :2 , "./changeBlendingMode.js" :3 , "./changeDirection.js" :4 , "./changeState.js" :5 , "./clear.js" :6 , "./colorDiff.js" :7 , "./destroy.js" :8 , "./eventPolyfill.js" :9 , "./getCurrentColors.js" :10 , "./getDimensions.js" :11 , "./getElement.js" :12 , "./getLightness.js" :13 , "./hexToRgb.js" :14 , "./makeGradient.js" :15 , "./onResize.js" :16 , "./onScroll.js" :17 , "./pause.js" :18 , "./pauseWhenNotInView.js" :19 , "./play.js" :20 , "./prepareImage.js" :21 , "./refreshColors.js" :22 , "./setColors.js" :23 , "./setDirection.js" :24 , "./setSizeAttributes.js" :25 , "./triggerError.js" :26 , "./validateInput .js" :27 } ] , 2 :[ function ( require , module , exports ) {
160
+ } , { "./animateColors.js" :2 , "./changeBlendingMode.js" :3 , "./changeDirection.js" :4 , "./changeState.js" :5 , "./clear.js" :6 , "./colorDiff.js" :7 , "./destroy.js" :8 , "./eventPolyfill.js" :9 , "./getCurrentColors.js" :10 , "./getDimensions.js" :11 , "./getElement.js" :12 , "./getLightness.js" :13 , "./hexToRgb.js" :14 , "./makeGradient.js" :15 , "./onResize.js" :16 , "./onScroll.js" :17 , "./pause.js" :18 , "./pauseWhenNotInView.js" :19 , "./play.js" :20 , "./prepareImage.js" :21 , "./refreshColors.js" :22 , "./setColors.js" :23 , "./setDirection.js" :24 , "./setSizeAttributes.js" :25 , "./triggerError.js" :26 , "./validateCustomDirection .js" :27 , "./validateInput.js" : 28 } ] , 2 :[ function ( require , module , exports ) {
157
161
'use strict' ;
158
162
159
163
module . exports = function ( timestamp ) {
@@ -252,10 +256,11 @@ module.exports = function(newBlendingMode) {
252
256
} , { } ] , 4 :[ function ( require , module , exports ) {
253
257
'use strict' ;
254
258
255
- module . exports = function ( newDirection ) {
259
+ module . exports = function ( newDirection ) {
256
260
this . context . clearRect ( 0 , 0 , this . x1 , this . y1 ) ;
257
261
this . direction = newDirection ;
258
262
this . validateInput ( 'direction' ) ;
263
+ this . validateCustomDirection ( ) ;
259
264
if ( this . isPaused ) this . refreshColors ( ) ;
260
265
} ;
261
266
@@ -764,14 +769,14 @@ module.exports = function() {
764
769
} , { } ] , 24 :[ function ( require , module , exports ) {
765
770
'use strict' ;
766
771
767
- module . exports = function ( ) {
772
+ module . exports = function ( ) {
768
773
var ctx = this . context ;
769
774
770
- switch ( this . direction ) {
775
+ switch ( this . direction ) {
771
776
default :
772
777
this . triggerError ( 'direction' ) ;
773
778
break ;
774
-
779
+
775
780
case 'diagonal' :
776
781
return ctx . createLinearGradient ( 0 , 0 , this . x1 , this . y1 ) ;
777
782
break ;
@@ -787,6 +792,10 @@ module.exports = function() {
787
792
case 'radial' :
788
793
return ctx . createRadialGradient ( this . x1 / 2 , this . y1 / 2 , this . x1 / 2 , this . x1 / 2 , this . y1 / 2 , 0 ) ;
789
794
break ;
795
+ case 'custom' :
796
+ return ctx . createLinearGradient ( this . customDirection . x0 , this . customDirection . y0 , this . customDirection . x1 , this . customDirection . y1 ) ;
797
+ break ;
798
+
790
799
}
791
800
} ;
792
801
@@ -810,6 +819,30 @@ module.exports = function(element) {
810
819
} ;
811
820
812
821
} , { } ] , 27 :[ function ( require , module , exports ) {
822
+ module . exports = function ( ) {
823
+ if ( this . direction === 'custom' ) {
824
+ if ( ! areDefinedAndNumbers ( [
825
+ this . customDirection . x0 ,
826
+ this . customDirection . x1 ,
827
+ this . customDirection . y0 ,
828
+ this . customDirection . y1
829
+ ] ) ) {
830
+ throw new Error ( 'When using a custom direction, the custom object is required with it\'s attributes: x0, x1, y0, y1 of type number' ) ;
831
+ }
832
+ }
833
+ }
834
+
835
+ function areDefinedAndNumbers ( array ) {
836
+ var definedAndNumber = true , i = 0 ;
837
+ while ( definedAndNumber && i < array . length ) {
838
+ if ( typeof array [ i ] !== 'number' ) {
839
+ definedAndNumber = false ;
840
+ }
841
+ i ++ ;
842
+ }
843
+ return definedAndNumber ;
844
+ }
845
+ } , { } ] , 28 :[ function ( require , module , exports ) {
813
846
'use strict' ;
814
847
815
848
module . exports = function ( inputType ) {
@@ -843,7 +876,7 @@ module.exports = function(inputType) {
843
876
}
844
877
} ;
845
878
846
- } , { } ] , 28 :[ function ( require , module , exports ) {
879
+ } , { } ] , 29 :[ function ( require , module , exports ) {
847
880
window . Granim = require ( './lib/Granim.js' ) ;
848
881
849
- } , { "./lib/Granim.js" :1 } ] } , { } , [ 28 ] ) ;
882
+ } , { "./lib/Granim.js" :1 } ] } , { } , [ 29 ] ) ;
0 commit comments