@@ -47,6 +47,9 @@ const platformNames = {
4747// Z indexing
4848let currentZ = 500
4949
50+ // window cascade offset
51+ let windowCascadeIndex = 0 ;
52+
5053// setup the initial state
5154setupTable ( ) ;
5255setupFileInput ( ) ;
@@ -681,6 +684,23 @@ function createUsageWindow(methodName) {
681684 document . body . appendChild ( windowEl ) ;
682685 openWindows . add ( windowId ) ;
683686
687+ const cascadeStep = 30 ;
688+ const maxCascade = 10 ;
689+ const cascadeOffset = ( windowCascadeIndex % maxCascade ) * cascadeStep ;
690+ windowCascadeIndex ++ ;
691+
692+ const winW = windowEl . offsetWidth || 600 ;
693+ const winH = windowEl . offsetHeight || 400 ;
694+ const viewW = window . innerWidth ;
695+ const viewH = window . innerHeight ;
696+
697+ const spawnLeft = Math . min ( Math . max ( cascadeOffset + 60 , 0 ) , viewW - winW - 20 ) ;
698+ const spawnTop = Math . min ( Math . max ( cascadeOffset + 60 , 0 ) , viewH - 120 ) ;
699+
700+ windowEl . style . left = spawnLeft + 'px' ;
701+ windowEl . style . top = spawnTop + 'px' ;
702+ windowEl . style . transform = 'none' ;
703+
684704 setupWindowDrag ( windowEl ) ;
685705 setupWindowResize ( windowEl , resizeHandle ) ;
686706
@@ -708,6 +728,8 @@ function setupWindowDrag(windowEl) {
708728 return ;
709729 }
710730
731+ windowEl . style . transform = 'none' ;
732+
711733 isDragging = true ;
712734 offsetX = e . clientX - windowEl . getBoundingClientRect ( ) . left ;
713735 offsetY = e . clientY - windowEl . getBoundingClientRect ( ) . top ;
@@ -727,8 +749,11 @@ function setupWindowDrag(windowEl) {
727749
728750 if ( ! isDragging ) return ;
729751
730- windowEl . style . left = `${ e . clientX - offsetX } px` ;
731- windowEl . style . top = `${ e . clientY - offsetY } px` ;
752+ const newLeft = e . clientX - offsetX ;
753+ const newTop = Math . max ( 0 , e . clientY - offsetY ) ;
754+
755+ windowEl . style . left = `${ newLeft } px` ;
756+ windowEl . style . top = `${ newTop } px` ;
732757 windowEl . style . right = 'auto' ;
733758 } ) ;
734759
0 commit comments