@@ -358,6 +358,9 @@ export class AnimateExecutor implements IAnimateExecutor {
358358 }
359359 from = parsedFromProps . from ;
360360 }
361+ if ( parsedFromProps . attrOutChannel ) {
362+ graphic . setAttributes ( parsedFromProps . attrOutChannel ) ;
363+ }
361364
362365 this . _handleRunAnimate (
363366 animate ,
@@ -559,6 +562,9 @@ export class AnimateExecutor implements IAnimateExecutor {
559562 }
560563 from = parsedFromProps . from ;
561564 }
565+ if ( parsedFromProps . attrOutChannel ) {
566+ graphic . setAttributes ( parsedFromProps . attrOutChannel ) ;
567+ }
562568 const custom = effect . custom ?? AnimateExecutor . builtInAnimateMap [ type ] ;
563569 const customType = effect . custom ? ( effect as any ) . customType : getCustomType ( custom ) ;
564570 this . _handleRunAnimate (
@@ -645,51 +651,73 @@ export class AnimateExecutor implements IAnimateExecutor {
645651 private createPropsFromChannel (
646652 channel : IAnimationChannelAttrs | IAnimationChannelAttributes | undefined ,
647653 graphic : IGraphic
648- ) : { from : Record < string , any > | null ; props : Record < string , any > } {
654+ ) : {
655+ from : Record < string , any > | null ;
656+ props : Record < string , any > ;
657+ attrOutChannel : Record < string , any > | null ;
658+ } {
649659 const props : Record < string , any > = { } ;
650660 let from : Record < string , any > | null = null ;
651-
652661 if ( ! channel ) {
653662 return {
654663 from,
655- props
664+ props,
665+ attrOutChannel : null
656666 } ;
657667 }
658668
659- if ( ! Array . isArray ( channel ) ) {
660- // 如果是对象,解析 from/to 配置
661- Object . keys ( channel ) . forEach ( key => {
662- const config = channel [ key ] ;
663- if ( config . to !== undefined ) {
664- if ( typeof config . to === 'function' ) {
665- props [ key ] = config . to ( ( graphic . context as any ) ?. data ?. [ 0 ] , graphic , { } ) ;
666- } else {
667- props [ key ] = config . to ;
668- }
669+ const attrOutChannel : Record < string , any > | null = { } ;
670+ let hasAttrs = false ;
671+ const diffAttrs = graphic . context ?. diffAttrs ;
672+ if ( Array . isArray ( channel ) ) {
673+ channel = channel . reduce ( ( res , key ) => {
674+ if ( diffAttrs [ key ] === undefined ) {
675+ return res ;
669676 }
670- if ( config . from !== undefined ) {
671- if ( ! from ) {
672- from = { } ;
673- }
674- if ( typeof config . from === 'function' ) {
675- from [ key ] = config . from ( ( graphic . context as any ) ?. data ?. [ 0 ] , graphic , { } ) ;
676- } else {
677- from [ key ] = config . from ;
678- }
677+ res [ key ] = { to : diffAttrs [ key ] } ;
678+ return res ;
679+ } , { } as Record < string , any > ) ;
680+ }
681+
682+ // 对象,解析 from/to 配置
683+ Object . keys ( channel ) . forEach ( key => {
684+ const config = channel [ key ] ;
685+ if ( config . to !== undefined ) {
686+ if ( typeof config . to === 'function' ) {
687+ props [ key ] = config . to ( ( graphic . context as any ) ?. data ?. [ 0 ] , graphic , { } ) ;
688+ } else {
689+ props [ key ] = config . to ;
679690 }
680- } ) ;
681- } else {
682- channel . forEach ( key => {
683- const value = graphic . context ?. diffAttrs ?. [ key ] ;
684- if ( value !== undefined ) {
685- props [ key ] = value ;
691+ }
692+ if ( config . from !== undefined ) {
693+ if ( ! from ) {
694+ from = { } ;
686695 }
687- } ) ;
696+ if ( typeof config . from === 'function' ) {
697+ from [ key ] = config . from ( ( graphic . context as any ) ?. data ?. [ 0 ] , graphic , { } ) ;
698+ } else {
699+ from [ key ] = config . from ;
700+ }
701+ }
702+ } ) ;
703+
704+ if ( diffAttrs ) {
705+ for ( const key in diffAttrs ) {
706+ const value = ( diffAttrs as any ) [ key ] ;
707+ if ( value === undefined ) {
708+ continue ;
709+ }
710+ if ( ! props . hasOwnProperty ( key ) ) {
711+ attrOutChannel [ key ] = value ;
712+ hasAttrs = true ;
713+ }
714+ }
688715 }
689716
690717 return {
691718 from,
692- props
719+ props,
720+ attrOutChannel : hasAttrs ? attrOutChannel : null
693721 } ;
694722 }
695723
0 commit comments