@@ -7,7 +7,7 @@ let lastY = 40
77export const addNewStat = ( id : string , width = 80 , x = rightOffset , y = lastY ) => {
88 const pane = document . createElement ( 'div' )
99 pane . style . position = 'fixed'
10- pane . style . top = `${ y } px`
10+ pane . style . top = `${ y ?? lastY } px`
1111 pane . style . right = `${ x } px`
1212 // gray bg
1313 pane . style . backgroundColor = 'rgba(0, 0, 0, 0.7)'
@@ -19,7 +19,7 @@ export const addNewStat = (id: string, width = 80, x = rightOffset, y = lastY) =
1919 pane . style . pointerEvents = 'none'
2020 document . body . appendChild ( pane )
2121 stats [ id ] = pane
22- if ( y === 0 ) { // otherwise it's a custom position
22+ if ( y === undefined && x === rightOffset ) { // otherwise it's a custom position
2323 // rightOffset += width
2424 lastY += 20
2525 }
@@ -35,6 +35,50 @@ export const addNewStat = (id: string, width = 80, x = rightOffset, y = lastY) =
3535 }
3636}
3737
38+ export const addNewStat2 = ( id : string , { top, bottom, right, left, displayOnlyWhenWider } : { top ?: number , bottom ?: number , right ?: number , left ?: number , displayOnlyWhenWider ?: number } ) => {
39+ if ( top === undefined && bottom === undefined ) top = 0
40+ const pane = document . createElement ( 'div' )
41+ pane . style . position = 'fixed'
42+ if ( top !== undefined ) {
43+ pane . style . top = `${ top } px`
44+ }
45+ if ( bottom !== undefined ) {
46+ pane . style . bottom = `${ bottom } px`
47+ }
48+ if ( left !== undefined ) {
49+ pane . style . left = `${ left } px`
50+ }
51+ if ( right !== undefined ) {
52+ pane . style . right = `${ right } px`
53+ }
54+ // gray bg
55+ pane . style . backgroundColor = 'rgba(0, 0, 0, 0.7)'
56+ pane . style . color = 'white'
57+ pane . style . padding = '2px'
58+ pane . style . fontFamily = 'monospace'
59+ pane . style . fontSize = '12px'
60+ pane . style . zIndex = '10000'
61+ pane . style . pointerEvents = 'none'
62+ document . body . appendChild ( pane )
63+ stats [ id ] = pane
64+
65+ const resizeCheck = ( ) => {
66+ if ( ! displayOnlyWhenWider ) return
67+ pane . style . display = window . innerWidth > displayOnlyWhenWider ? 'block' : 'none'
68+ }
69+ window . addEventListener ( 'resize' , resizeCheck )
70+ resizeCheck ( )
71+
72+ return {
73+ updateText ( text : string ) {
74+ pane . innerText = text
75+ } ,
76+ setVisibility ( visible : boolean ) {
77+ pane . style . display = visible ? 'block' : 'none'
78+ }
79+ }
80+ }
81+
3882export const updateStatText = ( id , text ) => {
3983 if ( ! stats [ id ] ) return
4084 stats [ id ] . innerText = text
0 commit comments