@@ -8,7 +8,10 @@ import {
8
8
toFixed ,
9
9
stylesToCss ,
10
10
createMatrix ,
11
+ getGsapType ,
12
+ isTransform ,
11
13
checkStyleName ,
14
+ toCssLowerCase ,
12
15
} from 'style-utils' ;
13
16
14
17
import easingTypes from './easing' ;
@@ -88,7 +91,7 @@ p.setAttrIsStyle = function () {
88
91
}
89
92
} ) ;
90
93
data [ i ] . style = _d ;
91
- this . startDefaultData . style = this . target . getAttribute ( 'style' ) ;
94
+ this . startDefaultData . style = this . target . getAttribute ( 'style' ) || '' ;
92
95
} else if ( this . attr === 'attr' ) {
93
96
Object . keys ( _d ) . forEach ( key => {
94
97
if ( key === 'style' && Array . isArray ( d [ key ] ) ) {
@@ -97,7 +100,7 @@ p.setAttrIsStyle = function () {
97
100
if ( key === 'bezier' ) {
98
101
_d . style = { ..._d . style , bezier : _d [ key ] } ;
99
102
delete _d [ key ] ;
100
- this . startDefaultData . style = this . target . getAttribute ( 'style' ) ;
103
+ this . startDefaultData . style = this . target . getAttribute ( 'style' ) || '' ;
101
104
} else {
102
105
this . startDefaultData [ key ] = this . target . getAttribute ( key ) ;
103
106
}
@@ -389,15 +392,50 @@ p.resetAnimData = function () {
389
392
this . start = { } ;
390
393
} ;
391
394
395
+ p . getDefaultStyle = function ( domStyle ) {
396
+ const $data = defaultData ( { } , 0 ) ;
397
+ const getStyleToArray = ( styleString ) => (
398
+ styleString . split ( ';' ) . filter ( c => c ) . map ( str =>
399
+ str . split ( ':' ) . map ( s => s . trim ( ) )
400
+ )
401
+ ) ;
402
+ const styleToArray = getStyleToArray ( this . startDefaultData . style ) ;
403
+ let domStyleToArray = getStyleToArray ( domStyle ) ;
404
+ this . data . forEach ( value => {
405
+ Object . keys ( value ) . forEach ( name => {
406
+ if ( ! ( name in $data ) ) {
407
+ const styleName = toCssLowerCase ( isTransform ( getGsapType ( name ) ) ) ;
408
+ domStyleToArray = domStyleToArray . filter ( item => item [ 0 ] !== styleName ) ;
409
+ }
410
+ } )
411
+ } ) ;
412
+ styleToArray . forEach ( item => {
413
+ domStyleToArray = domStyleToArray . map ( $item => {
414
+ if ( $item [ 0 ] === item [ 0 ] ) {
415
+ return item ;
416
+ }
417
+ return $item ;
418
+ } ) ;
419
+ } )
420
+ return domStyleToArray . map ( item => item . join ( ':' ) ) . join ( ';' ) ;
421
+ }
422
+
392
423
p . resetDefaultStyle = function ( ) {
393
424
this . tween = { } ;
394
425
this . defaultData = this . defaultData . map ( item => {
395
426
item . reset = true ;
396
427
delete item . mode ;
397
428
return item ;
398
429
} ) ;
430
+ const data = defaultData ( { } , 0 ) ;
399
431
Object . keys ( this . startDefaultData ) . forEach ( key => {
400
- if ( ! ( key in defaultData ( { } , 0 ) ) ) {
432
+ if ( ! ( key in data ) ) {
433
+ if ( key === 'style' ) {
434
+ const value = this . getDefaultStyle ( this . target . style . cssText ) ;
435
+ this . target . setAttribute ( key , value ) ;
436
+ } else {
437
+ this . target . setAttribute ( key , this . startDefaultData [ key ] ) ;
438
+ }
401
439
this . target . setAttribute ( key , this . startDefaultData [ key ] ) ;
402
440
this . computedStyle = null ;
403
441
}
@@ -406,7 +444,7 @@ p.resetDefaultStyle = function () {
406
444
407
445
p . reStart = function ( style ) {
408
446
this . start = { } ;
409
- this . target . style . cssText = '' ;
447
+ this . target . style . cssText = this . getDefaultStyle ( this . target . style . cssText ) ;
410
448
Object . keys ( style || { } ) . forEach ( key => {
411
449
this . target . style [ key ] = stylesToCss ( key , style [ key ] ) ;
412
450
} ) ;
0 commit comments