@@ -3464,14 +3464,7 @@ function RemoteFunctions(config = {}) {
34643464 */
34653465 function RulerLines ( element ) {
34663466 this . element = element ;
3467-
3468- const editable = element . hasAttribute ( GLOBALS . DATA_BRACKETS_ID_ATTR ) ;
3469- this . color = editable
3470- ? "rgba(66, 133, 244, 0.4)"
3471- : "rgba(60, 63, 65, 0.8)" ;
3472- this . labelColor = editable
3473- ? "rgba(66, 133, 244, 1)"
3474- : "rgba(60, 63, 65, 1)" ;
3467+ this . editable = element . hasAttribute ( GLOBALS . DATA_BRACKETS_ID_ATTR ) ;
34753468
34763469 this . sides = [ "left" , "right" , "top" , "bottom" ] ;
34773470 this . lineElements = { } ;
@@ -3483,45 +3476,43 @@ function RemoteFunctions(config = {}) {
34833476
34843477 RulerLines . prototype = {
34853478 create : function ( ) {
3486- const body = document . body ;
3487-
3488- const makeDiv = ( ) => {
3489- const el = document . createElement ( "div" ) ;
3490- el . setAttribute ( GLOBALS . PHCODE_INTERNAL_ATTR , "true" ) ;
3491- return el ;
3492- } ;
3479+ this . container = window . document . createElement ( "div" ) ;
3480+ this . container . setAttribute ( GLOBALS . PHCODE_INTERNAL_ATTR , "true" ) ;
34933481
3494- const styleLine = ( el ) => {
3495- el . style . position = "absolute" ;
3496- el . style . backgroundColor = this . color ;
3497- el . style . pointerEvents = "none" ;
3498- el . style . zIndex = "2147483645" ;
3499- } ;
3482+ const shadow = this . container . attachShadow ( { mode : "open" } ) ;
3483+ this . _shadow = shadow ;
35003484
3501- const styleLabel = ( el ) => {
3502- el . style . position = "absolute" ;
3503- el . style . color = this . labelColor ;
3504- el . style . fontSize = "9px" ;
3505- el . style . fontFamily = "Arial, sans-serif" ;
3506- el . style . pointerEvents = "none" ;
3507- el . style . zIndex = "2147483646" ;
3508- el . style . whiteSpace = "nowrap" ;
3509- el . style . backgroundColor = "transparent" ;
3510- } ;
3485+ const lineClass = this . editable ? "phoenix-ruler-line-editable" : "phoenix-ruler-line-non-editable" ;
3486+ const labelClass = this . editable ? "phoenix-ruler-label-editable" : "phoenix-ruler-label-non-editable" ;
35113487
3488+ let html = "" ;
35123489 for ( const side of this . sides ) {
3513- const line = makeDiv ( ) ;
3514- const label = makeDiv ( ) ;
3515-
3516- styleLine ( line ) ;
3517- styleLabel ( label ) ;
3490+ html += `<div class="phoenix-ruler-line ${ lineClass } " data-side="${ side } "></div>` ;
3491+ html += `<div class="phoenix-ruler-label ${ labelClass } " data-side="${ side } "></div>` ;
3492+ }
35183493
3519- this . lineElements [ side ] = line ;
3520- this . labelElements [ side ] = label ;
3494+ shadow . innerHTML = `
3495+ <style>
3496+ ${ config . styles . ruler }
3497+ </style>
3498+ ${ html }
3499+ ` ;
3500+
3501+ window . document . body . appendChild ( this . container ) ;
3502+
3503+ this . lineElements = {
3504+ left : shadow . querySelector ( '.phoenix-ruler-line[data-side="left"]' ) ,
3505+ right : shadow . querySelector ( '.phoenix-ruler-line[data-side="right"]' ) ,
3506+ top : shadow . querySelector ( '.phoenix-ruler-line[data-side="top"]' ) ,
3507+ bottom : shadow . querySelector ( '.phoenix-ruler-line[data-side="bottom"]' )
3508+ } ;
35213509
3522- body . appendChild ( line ) ;
3523- body . appendChild ( label ) ;
3524- }
3510+ this . labelElements = {
3511+ left : shadow . querySelector ( '.phoenix-ruler-label[data-side="left"]' ) ,
3512+ right : shadow . querySelector ( '.phoenix-ruler-label[data-side="right"]' ) ,
3513+ top : shadow . querySelector ( '.phoenix-ruler-label[data-side="top"]' ) ,
3514+ bottom : shadow . querySelector ( '.phoenix-ruler-label[data-side="bottom"]' )
3515+ } ;
35253516 } ,
35263517
35273518 update : function ( ) {
@@ -3610,16 +3601,12 @@ function RemoteFunctions(config = {}) {
36103601 } ,
36113602
36123603 remove : function ( ) {
3613- const body = document . body ;
3614-
3615- for ( const side of this . sides ) {
3616- const line = this . lineElements [ side ] ;
3617- const label = this . labelElements [ side ] ;
3618-
3619- if ( line && line . parentNode ) { body . removeChild ( line ) ; }
3620- if ( label && label . parentNode ) { body . removeChild ( label ) ; }
3604+ if ( this . container && this . container . parentNode ) {
3605+ window . document . body . removeChild ( this . container ) ;
36213606 }
36223607
3608+ this . container = null ;
3609+ this . _shadow = null ;
36233610 this . lineElements = { } ;
36243611 this . labelElements = { } ;
36253612 }
@@ -3875,6 +3862,11 @@ function RemoteFunctions(config = {}) {
38753862 }
38763863 // Always show info box for inspectable elements
38773864 _nodeInfoBox = new NodeInfoBox ( element ) ;
3865+
3866+ // show ruler lines (only when enabled)
3867+ if ( config . showRulerLines ) {
3868+ _currentRulerLines = new RulerLines ( element ) ;
3869+ }
38783870 } else {
38793871 // Element is hidden, so don't show UI boxes but still apply visual styling
38803872 _nodeMoreOptionsBox = null ;
@@ -3897,11 +3889,6 @@ function RemoteFunctions(config = {}) {
38973889 _hoverHighlight . add ( element , true ) ;
38983890 }
38993891
3900- // to show ruler lines (only when its enabled)
3901- if ( config . showRulerLines ) {
3902- _currentRulerLines = new RulerLines ( element ) ;
3903- }
3904-
39053892 previouslyClickedElement = element ;
39063893 }
39073894
0 commit comments