@@ -466,6 +466,42 @@ const setSelectRect = (
466466 )
467467}
468468
469+ const getElementDurationTime = ( elementId ?: string ) => {
470+ const element = elementId ? querySelectById ( elementId ) : getDocument ( ) . body
471+
472+ const durationTime = window . getComputedStyle ( element ) . getPropertyValue ( 'transition-duration' )
473+ const delayTime = window . getComputedStyle ( element ) . getPropertyValue ( 'transition-delay' )
474+ const transition = window . getComputedStyle ( element ) . getPropertyValue ( 'transition' )
475+ let delayArray : string [ ] = [ ]
476+ if ( transition ) {
477+ const delayRegex = / ( [ 0 - 9 ] + ( \. [ 0 - 9 ] + ) ? ) ( s | m s | S | M S ) /
478+ const transitions = transition . split ( ',' )
479+ transitions . forEach ( ( item ) => {
480+ const parts = item . trim ( ) . split ( ' ' )
481+ delayArray = delayArray . concat ( parts )
482+ } )
483+ delayArray = delayArray . filter ( ( delay ) => delayRegex . test ( delay ) )
484+ }
485+
486+ if ( durationTime ) {
487+ delayArray . push ( durationTime )
488+ }
489+
490+ if ( delayTime ) {
491+ delayArray . push ( delayTime )
492+ }
493+ const delayTimes : any [ ] = delayArray . map ( ( item ) => {
494+ if ( item ) {
495+ if ( item . endsWith ( 'ms' ) ) {
496+ return parseFloat ( item )
497+ } else {
498+ return parseFloat ( item ) * 1000
499+ }
500+ }
501+ } )
502+ return delayTimes . length ? Math . max ( ...delayTimes ) : 0
503+ }
504+
469505export const updateRect = ( id ?: string ) => {
470506 id = ( typeof id === 'string' && id ) || getCurrent ( ) . schema ?. id
471507 clearHover ( )
@@ -482,16 +518,7 @@ export const updateRect = (id?: string) => {
482518
483519 if ( id || isBodySelected ) {
484520 // 获取元素动画持续时间
485- const element = querySelectById ( id ) || getDocument ( ) . body
486- const duration = window . getComputedStyle ( element ) . getPropertyValue ( 'transition-duration' )
487- let waitTime = 0
488- if ( duration ) {
489- if ( duration . endsWith ( 'ms' ) ) {
490- waitTime = parseFloat ( duration )
491- } else {
492- waitTime = parseFloat ( duration ) * 1000
493- }
494- }
521+ const waitTime = getElementDurationTime ( id )
495522 setTimeout ( ( ) => setSelectRect ( id ) , waitTime )
496523 } else {
497524 clearSelect ( )
0 commit comments