1
+ "use strict" ;
2
+
3
+ Object . defineProperty ( exports , "__esModule" , {
4
+ value : true
5
+ } ) ;
6
+ exports . Element = void 0 ;
7
+
8
+ var _index = require ( "../utils/index" ) ;
9
+
10
+ var _index2 = require ( "../helpers/index" ) ;
11
+
12
+ var _constants = require ( "../constants" ) ;
13
+
14
+ var _Bounds = _interopRequireDefault ( require ( "./Bounds" ) ) ;
15
+
16
+ var _Rect = _interopRequireDefault ( require ( "./Rect" ) ) ;
17
+
18
+ function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
19
+
20
+ function ownKeys ( object , enumerableOnly ) { var keys = Object . keys ( object ) ; if ( Object . getOwnPropertySymbols ) { var symbols = Object . getOwnPropertySymbols ( object ) ; if ( enumerableOnly ) symbols = symbols . filter ( function ( sym ) { return Object . getOwnPropertyDescriptor ( object , sym ) . enumerable ; } ) ; keys . push . apply ( keys , symbols ) ; } return keys ; }
21
+
22
+ function _objectSpread ( target ) { for ( var i = 1 ; i < arguments . length ; i ++ ) { var source = arguments [ i ] != null ? arguments [ i ] : { } ; if ( i % 2 ) { ownKeys ( Object ( source ) , true ) . forEach ( function ( key ) { _defineProperty ( target , key , source [ key ] ) ; } ) ; } else if ( Object . getOwnPropertyDescriptors ) { Object . defineProperties ( target , Object . getOwnPropertyDescriptors ( source ) ) ; } else { ownKeys ( Object ( source ) ) . forEach ( function ( key ) { Object . defineProperty ( target , key , Object . getOwnPropertyDescriptor ( source , key ) ) ; } ) ; } } return target ; }
23
+
24
+ function _defineProperty ( obj , key , value ) { if ( key in obj ) { Object . defineProperty ( obj , key , { value : value , enumerable : true , configurable : true , writable : true } ) ; } else { obj [ key ] = value ; } return obj ; }
25
+
26
+ function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
27
+
28
+ function _defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } }
29
+
30
+ function _createClass ( Constructor , protoProps , staticProps ) { if ( protoProps ) _defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) _defineProperties ( Constructor , staticProps ) ; return Constructor ; }
31
+
32
+ var Element = /*#__PURE__*/ function ( ) {
33
+ function Element ( options ) {
34
+ _classCallCheck ( this , Element ) ;
35
+
36
+ this . elInner = options . elInner ;
37
+ this . elOuter = options . elOuter ;
38
+ this . props = options . props ;
39
+ this . scrollAxis = options . scrollAxis ;
40
+ this . id = ( 0 , _index . createId ) ( ) ;
41
+ this . offsets = ( 0 , _index2 . getOffsets ) ( this . props ) ;
42
+ this . isInView = null ;
43
+ this . percent = 0 ;
44
+ this . updatePosition = options . scrollAxis === _constants . VERTICAL ? this . _updatePositionVertical : this . _updatePositionHorizontal ;
45
+ }
46
+
47
+ _createClass ( Element , [ {
48
+ key : "updateProps" ,
49
+ value : function updateProps ( nextProps ) {
50
+ this . props = _objectSpread ( _objectSpread ( { } , this . props ) , nextProps ) ;
51
+ this . offsets = ( 0 , _index2 . getOffsets ) ( nextProps ) ;
52
+ return this ;
53
+ }
54
+ } , {
55
+ key : "setCachedAttributes" ,
56
+ value : function setCachedAttributes ( view , scroll ) {
57
+ this . rect = new _Rect . default ( this . elOuter , view , scroll ) ;
58
+ this . bounds = new _Bounds . default ( this . rect , this . offsets , view ) ;
59
+ return this ;
60
+ }
61
+ } , {
62
+ key : "_updatePositionHorizontal" ,
63
+ value : function _updatePositionHorizontal ( view , scroll ) {
64
+ this . isInView = ( 0 , _index2 . isElementInView ) ( this . bounds . left , this . bounds . right , view . width , scroll . x ) ;
65
+ if ( ! this . isInView ) return this ;
66
+ this . percent = ( 0 , _index2 . percentMoved ) ( this . rect . left , this . rect . originTotalDistX , view . width , scroll . x ) ;
67
+ ( 0 , _index2 . setParallaxStyles ) ( this . elInner , this . offsets , this . percent ) ;
68
+ return this ;
69
+ }
70
+ } , {
71
+ key : "_updatePositionVertical" ,
72
+ value : function _updatePositionVertical ( view , scroll ) {
73
+ this . isInView = ( 0 , _index2 . isElementInView ) ( this . bounds . top , this . bounds . bottom , view . height , scroll . y ) ;
74
+ if ( ! this . isInView ) return this ;
75
+ this . percent = ( 0 , _index2 . percentMoved ) ( this . rect . top , this . rect . originTotalDistY , view . height , scroll . y ) ;
76
+ ( 0 , _index2 . setParallaxStyles ) ( this . elInner , this . offsets , this . percent ) ;
77
+ return this ;
78
+ }
79
+ } ] ) ;
80
+
81
+ return Element ;
82
+ } ( ) ;
83
+
84
+ exports . Element = Element ;
0 commit comments