op;
          let newLeft;

          const popoverHeightForFitting = popoverRect.height;
          const spaceBelow = viewportHeight - triggerRect.bottom;
          const spaceAbove = triggerRect.top;

          if (popoverHeightForFitting + cssGap <= spaceBelow) {
            newTop = triggerRect.bottom + scrollY + cssGap;
          } else if (popoverHeightForFitting + cssGap <= spaceAbove) {
            newTop =
              triggerRect.top + scrollY - popoverHeightForFitting - cssGap;
          } else 