@@ -3525,7 +3525,9 @@ function RemoteFunctions(config = {}) {
35253525 } ,
35263526
35273527 update : function ( ) {
3528- if ( ! this . element ) { return ; }
3528+ if ( ! this . element ) {
3529+ return ;
3530+ }
35293531
35303532 const rect = this . element . getBoundingClientRect ( ) ;
35313533 const scrollTop = window . pageYOffset ;
@@ -3541,26 +3543,25 @@ function RemoteFunctions(config = {}) {
35413543 const docHeight = document . documentElement . scrollHeight ;
35423544 const docWidth = document . documentElement . scrollWidth ;
35433545
3544- // Position lines
3545- this . lineElements . left . style . width = '1px' ;
3546- this . lineElements . left . style . height = docHeight + 'px' ;
3547- this . lineElements . left . style . left = edges . left + 'px' ;
3548- this . lineElements . left . style . top = '0px' ;
3546+ this . lineElements . left . style . width = "1px" ;
3547+ this . lineElements . left . style . height = docHeight + "px" ;
3548+ this . lineElements . left . style . left = edges . left + "px" ;
3549+ this . lineElements . left . style . top = "0px" ;
35493550
3550- this . lineElements . right . style . width = ' 1px' ;
3551- this . lineElements . right . style . height = docHeight + 'px' ;
3552- this . lineElements . right . style . left = edges . right + 'px' ;
3553- this . lineElements . right . style . top = ' 0px' ;
3551+ this . lineElements . right . style . width = " 1px" ;
3552+ this . lineElements . right . style . height = docHeight + "px" ;
3553+ this . lineElements . right . style . left = edges . right + "px" ;
3554+ this . lineElements . right . style . top = " 0px" ;
35543555
3555- this . lineElements . top . style . height = ' 1px' ;
3556- this . lineElements . top . style . width = docWidth + 'px' ;
3557- this . lineElements . top . style . top = edges . top + 'px' ;
3558- this . lineElements . top . style . left = ' 0px' ;
3556+ this . lineElements . top . style . height = " 1px" ;
3557+ this . lineElements . top . style . width = docWidth + "px" ;
3558+ this . lineElements . top . style . top = edges . top + "px" ;
3559+ this . lineElements . top . style . left = " 0px" ;
35593560
3560- this . lineElements . bottom . style . height = ' 1px' ;
3561- this . lineElements . bottom . style . width = docWidth + 'px' ;
3562- this . lineElements . bottom . style . top = edges . bottom + 'px' ;
3563- this . lineElements . bottom . style . left = ' 0px' ;
3561+ this . lineElements . bottom . style . height = " 1px" ;
3562+ this . lineElements . bottom . style . width = docWidth + "px" ;
3563+ this . lineElements . bottom . style . top = edges . bottom + "px" ;
3564+ this . lineElements . bottom . style . left = " 0px" ;
35643565
35653566 const x1 = Math . floor ( edges . left + 1 ) ;
35663567 const x2 = x1 + rect . width ;
@@ -3572,16 +3573,40 @@ function RemoteFunctions(config = {}) {
35723573 this . labelElements . top . textContent = Math . round ( y1 ) + "px" ;
35733574 this . labelElements . bottom . textContent = Math . round ( y2 ) + "px" ;
35743575
3575- this . labelElements . left . style . left = ( edges . left - 30 ) + "px" ;
3576- this . labelElements . right . style . left = ( edges . right + 5 ) + "px" ;
3577- this . labelElements . top . style . left = ( scrollLeft + 10 ) + "px" ;
3578- this . labelElements . bottom . style . left = ( scrollLeft + 10 ) + "px" ;
3576+ const LABEL_MARGIN = 6 ;
35793577
3580- this . labelElements . left . style . top = ( scrollTop + 10 ) + "px" ;
3581- this . labelElements . right . style . top = ( scrollTop + 10 ) + "px" ;
3578+ const leftLabelWidth = this . labelElements . left . offsetWidth ;
3579+ const rightLabelWidth = this . labelElements . right . offsetWidth ;
3580+ const topLabelHeight = this . labelElements . top . offsetHeight ;
3581+ const bottomLabelHeight = this . labelElements . bottom . offsetHeight ;
35823582
3583- this . labelElements . top . style . top = ( edges . top - 15 ) + "px" ;
3584- this . labelElements . bottom . style . top = ( edges . bottom + 5 ) + "px" ;
3583+ let leftLabelLeft = edges . left - leftLabelWidth - LABEL_MARGIN ;
3584+ if ( rect . left - leftLabelWidth - LABEL_MARGIN < LABEL_MARGIN ) {
3585+ leftLabelLeft = edges . left + LABEL_MARGIN ;
3586+ }
3587+ this . labelElements . left . style . left = leftLabelLeft + "px" ;
3588+ this . labelElements . left . style . top = scrollTop + 10 + "px" ;
3589+
3590+ let rightLabelLeft = edges . right + LABEL_MARGIN ;
3591+ if ( rect . right + rightLabelWidth + LABEL_MARGIN > window . innerWidth - LABEL_MARGIN ) {
3592+ rightLabelLeft = edges . right - rightLabelWidth - LABEL_MARGIN ;
3593+ }
3594+ this . labelElements . right . style . left = rightLabelLeft + "px" ;
3595+ this . labelElements . right . style . top = scrollTop + 10 + "px" ;
3596+
3597+ let topLabelTop = edges . top - topLabelHeight - LABEL_MARGIN ;
3598+ if ( rect . top - topLabelHeight - LABEL_MARGIN < LABEL_MARGIN ) {
3599+ topLabelTop = edges . top + LABEL_MARGIN ;
3600+ }
3601+ this . labelElements . top . style . left = scrollLeft + 10 + "px" ;
3602+ this . labelElements . top . style . top = topLabelTop + "px" ;
3603+
3604+ let bottomLabelTop = edges . bottom + LABEL_MARGIN ;
3605+ if ( rect . bottom + bottomLabelHeight + LABEL_MARGIN > window . innerHeight - LABEL_MARGIN ) {
3606+ bottomLabelTop = edges . bottom - bottomLabelHeight - LABEL_MARGIN ;
3607+ }
3608+ this . labelElements . bottom . style . left = scrollLeft + 10 + "px" ;
3609+ this . labelElements . bottom . style . top = bottomLabelTop + "px" ;
35853610 } ,
35863611
35873612 remove : function ( ) {
0 commit comments