@@ -112,7 +112,6 @@ export abstract class AbstractRegion<T> implements Region<T> {
112112 constructor ( public document : A11yDocument ) {
113113 this . CLASS = this . constructor as typeof AbstractRegion ;
114114 this . AddStyles ( ) ;
115- this . AddElement ( ) ;
116115 }
117116
118117
@@ -136,9 +135,9 @@ export abstract class AbstractRegion<T> implements Region<T> {
136135 * @override
137136 */
138137 public AddElement ( ) {
138+ if ( this . div ) return ;
139139 let element = this . document . adaptor . node ( 'div' ) ;
140140 element . classList . add ( this . CLASS . className ) ;
141- element . style . backgroundColor = 'white' ;
142141 this . div = element ;
143142 this . inner = this . document . adaptor . node ( 'div' ) ;
144143 this . div . appendChild ( this . inner ) ;
@@ -153,6 +152,7 @@ export abstract class AbstractRegion<T> implements Region<T> {
153152 * @override
154153 */
155154 public Show ( node : HTMLElement , highlighter : Sre . highlighter ) {
155+ this . AddElement ( ) ;
156156 this . position ( node ) ;
157157 this . highlight ( highlighter ) ;
158158 this . div . classList . add ( this . CLASS . className + '_Show' ) ;
@@ -177,7 +177,10 @@ export abstract class AbstractRegion<T> implements Region<T> {
177177 * @override
178178 */
179179 public Hide ( ) {
180- this . div . classList . remove ( this . CLASS . className + '_Show' ) ;
180+ if ( ! this . div ) return ;
181+ this . div . parentNode . removeChild ( this . div ) ;
182+ this . div = null ;
183+ this . inner = null ;
181184 }
182185
183186
@@ -198,6 +201,7 @@ export abstract class AbstractRegion<T> implements Region<T> {
198201 * @param {HTMLElement } node The reference node.
199202 */
200203 protected stackRegions ( node : HTMLElement ) {
204+ this . AddElement ( ) ;
201205 // TODO: This could be made more efficient by caching regions of a class.
202206 const rect = node . getBoundingClientRect ( ) ;
203207 let baseBottom = 0 ;
@@ -270,6 +274,7 @@ export class StringRegion extends AbstractRegion<string> {
270274 * @override
271275 */
272276 public Clear ( ) : void {
277+ if ( ! this . div ) return ;
273278 this . Update ( '' ) ;
274279 this . inner . style . top = '' ;
275280 this . inner . style . backgroundColor = '' ;
@@ -280,8 +285,13 @@ export class StringRegion extends AbstractRegion<string> {
280285 * @override
281286 */
282287 public Update ( speech : string ) {
283- this . inner . textContent = '' ;
284- this . inner . textContent = speech ;
288+ if ( speech ) {
289+ this . AddElement ( ) ;
290+ }
291+ if ( this . inner ) {
292+ this . inner . textContent = '' ;
293+ this . inner . textContent = speech ;
294+ }
285295 }
286296
287297 /**
@@ -296,6 +306,7 @@ export class StringRegion extends AbstractRegion<string> {
296306 * @override
297307 */
298308 protected highlight ( highlighter : Sre . highlighter ) {
309+ if ( ! this . div ) return ;
299310 const color = highlighter . colorString ( ) ;
300311 this . inner . style . backgroundColor = color . background ;
301312 this . inner . style . color = color . foreground ;
@@ -317,13 +328,11 @@ export class ToolTip extends StringRegion {
317328 protected static style : CssStyles =
318329 new CssStyles ( {
319330 [ '.' + ToolTip . className ] : {
320- display : 'none' ,
321- } ,
322- [ '.' + ToolTip . className + '_Show' ] : {
323331 width : 'auto' , height : 'auto' , opacity : 1 , 'text-align' : 'center' ,
324332 'border-radius' : '6px' , padding : 0 ,
325333 'border-bottom' : '1px dotted black' ,
326334 position : 'absolute' , display : 'inline-block' ,
335+ 'background-color' : 'white' ,
327336 'z-index' : 202
328337 }
329338 } ) ;
@@ -344,14 +353,12 @@ export class LiveRegion extends StringRegion {
344353 protected static style : CssStyles =
345354 new CssStyles ( {
346355 [ '.' + LiveRegion . className ] : {
347- display : 'none'
348- } ,
349- [ '.' + LiveRegion . className + '_Show' ] : {
350356 position : 'absolute' , top : 0 ,
351357 display : 'block' , width : 'auto' , height : 'auto' ,
352358 padding : 0 , opacity : 1 , 'z-index' : '202' ,
353359 left : 0 , right : 0 , 'margin' : '0 auto' ,
354- 'background-color' : 'rgba(0, 0, 255, 0.2)' , 'box-shadow' : '0px 5px 20px #888' ,
360+ 'background-color' : 'white' ,
361+ 'box-shadow' : '0px 5px 20px #888' ,
355362 border : '2px solid #CCCCCC'
356363 }
357364 } ) ;
@@ -531,27 +538,17 @@ export class HoverRegion extends AbstractRegion<HTMLElement> {
531538 protected static style : CssStyles =
532539 new CssStyles ( {
533540 [ '.' + HoverRegion . className ] : {
534- display : 'none'
535- } ,
536- [ '.' + HoverRegion . className + '_Show' ] : {
537541 display : 'block' , position : 'absolute' ,
538542 width : 'max-content' , height : 'auto' ,
539543 padding : 0 , opacity : 1 , 'z-index' : '202' , 'margin' : '0 auto' ,
540- 'background-color' : 'rgba(0, 0, 255, 0.2)' ,
544+ 'background-color' : 'white' , 'line-height' : 0 ,
541545 'box-shadow' : '0px 10px 20px #888' , border : '2px solid #CCCCCC'
546+ } ,
547+ [ '.' + HoverRegion . className + ' > div' ] : {
548+ overflow : 'hidden'
542549 }
543550 } ) ;
544551
545-
546- /**
547- * @constructor
548- * @param {A11yDocument } document The document the live region is added to.
549- */
550- constructor ( public document : A11yDocument ) {
551- super ( document ) ;
552- this . inner . style . lineHeight = '0' ;
553- }
554-
555552 /**
556553 * Sets the position of the region with respect to align parameter. There are
557554 * three options: top, bottom and center. Center is the default.
@@ -568,7 +565,7 @@ export class HoverRegion extends AbstractRegion<HTMLElement> {
568565 let top ;
569566 switch ( this . document . options . a11y . align ) {
570567 case 'top' :
571- top = nodeRect . top - divRect . height - 10 ;
568+ top = nodeRect . top - divRect . height - 10 ;
572569 break ;
573570 case 'bottom' :
574571 top = nodeRect . bottom + 10 ;
@@ -588,6 +585,7 @@ export class HoverRegion extends AbstractRegion<HTMLElement> {
588585 * @override
589586 */
590587 protected highlight ( highlighter : Sre . highlighter ) {
588+ if ( ! this . div ) return ;
591589 // TODO Do this with styles to avoid the interaction of SVG/CHTML.
592590 if ( this . inner . firstChild &&
593591 ! ( this . inner . firstChild as HTMLElement ) . hasAttribute ( 'sre-highlight' ) ) {
@@ -602,6 +600,7 @@ export class HoverRegion extends AbstractRegion<HTMLElement> {
602600 * @override
603601 */
604602 public Show ( node : HTMLElement , highlighter : Sre . highlighter ) {
603+ this . AddElement ( ) ;
605604 this . div . style . fontSize = this . document . options . a11y . magnify ;
606605 this . Update ( node ) ;
607606 super . Show ( node , highlighter ) ;
@@ -611,6 +610,7 @@ export class HoverRegion extends AbstractRegion<HTMLElement> {
611610 * @override
612611 */
613612 public Clear ( ) {
613+ if ( ! this . div ) return ;
614614 this . inner . textContent = '' ;
615615 this . inner . style . top = '' ;
616616 this . inner . style . backgroundColor = '' ;
@@ -620,9 +620,11 @@ export class HoverRegion extends AbstractRegion<HTMLElement> {
620620 * @override
621621 */
622622 public Update ( node : HTMLElement ) {
623+ if ( ! this . div ) return ;
623624 this . Clear ( ) ;
624625 let mjx = this . cloneNode ( node ) ;
625626 this . inner . appendChild ( mjx ) ;
627+ this . position ( node ) ;
626628 }
627629
628630 /**
0 commit comments