@@ -9,16 +9,13 @@ export interface Config {
99}
1010export class GlobalPosition extends Position {
1111 private size ;
12- placement : InsidePlacement ;
13- hostWidth : string | number ;
14- hostHeight : string | number ;
15- offset : number ;
16- constructor ( { placement = InsidePlacement . CENTER , hostWidth = 500 , hostHeight = 500 , offset = 0 } : Config ) {
12+ private _config : Config = { placement : InsidePlacement . CENTER , hostWidth : 500 , hostHeight : 500 , offset : 0 } ;
13+ constructor ( config : Config ) {
1714 super ( ) ;
18- this . placement = placement ;
19- this . hostWidth = hostWidth ;
20- this . hostHeight = hostHeight ;
21- this . offset = offset ;
15+ this . _config = { ... this . _config , ... config } ;
16+ }
17+ updateConfig ( newConfig ) {
18+ this . _config = { ... this . _config , ... newConfig } ;
2219 }
2320 getPositions ( hostElement ?: HTMLElement ) {
2421 const host = hostElement . getBoundingClientRect ( ) ;
@@ -27,7 +24,7 @@ export class GlobalPosition extends Position {
2724 width : ( window as any ) . innerWidth ,
2825 height : ( window as any ) . innerHeight
2926 } ;
30- switch ( this . placement ) {
27+ switch ( this . _config . placement ) {
3128 case InsidePlacement . TOP :
3229 props = this . calculateTop ( src , host ) ;
3330 break ;
@@ -58,27 +55,27 @@ export class GlobalPosition extends Position {
5855 default :
5956 break ;
6057 }
61- return { ...props , width : this . hostWidth , height : this . hostHeight , position : 'fixed' } ;
58+ return { ...props , width : this . _config . hostWidth , height : this . _config . hostHeight , position : 'fixed' } ;
6259 }
6360
6461 private calculateTop ( src , host ) {
65- const top = this . offset ;
62+ const top = this . _config . offset ;
6663 const left = ( src . width - host . width ) / 2 ;
6764 return { left, top } ;
6865 }
6966 private calculateBottom ( src , host ) {
70- const bottom = this . offset ;
67+ const bottom = this . _config . offset ;
7168 const left = ( src . width - host . width ) / 2 ;
7269 return { left, bottom } ;
7370 }
7471 private calculateLeft ( src , host ) {
7572 const top = ( src . height - host . height ) / 2 ;
76- const left = this . offset ;
73+ const left = this . _config . offset ;
7774 return { left, top } ;
7875 }
7976 private calculateRight ( src , host ) {
8077 const top = ( src . height - host . height ) / 2 ;
81- const right = this . offset ;
78+ const right = this . _config . offset ;
8279 return { right, top } ;
8380 }
8481 private calculateCenter ( src , host ) {
@@ -87,23 +84,23 @@ export class GlobalPosition extends Position {
8784 return { left, top } ;
8885 }
8986 private calculateTopLeft ( src , host ) {
90- const top = this . offset ;
91- const left = this . offset ;
87+ const top = this . _config . offset ;
88+ const left = this . _config . offset ;
9289 return { left, top } ;
9390 }
9491 private calculateTopRight ( src , host ) {
95- const top = this . offset ;
96- const right = this . offset ;
92+ const top = this . _config . offset ;
93+ const right = this . _config . offset ;
9794 return { right, top } ;
9895 }
9996 private calculateBottomLeft ( src , host ) {
100- const bottom = this . offset ;
101- const left = this . offset ;
97+ const bottom = this . _config . offset ;
98+ const left = this . _config . offset ;
10299 return { left, bottom } ;
103100 }
104101 private calculateBottomRight ( src , host ) {
105- const bottom = this . offset ;
106- const right = this . offset ;
102+ const bottom = this . _config . offset ;
103+ const right = this . _config . offset ;
107104 return { right, bottom } ;
108105 }
109106}
0 commit comments