'use strict';

require('../../../utils/index.cjs');
var ResizeObserver = require('resize-observer-polyfill');
var contains = require('../../../utils/dom/contains.cjs');

function isSamePoint(prev, next) {
  if (prev === next)
    return true;
  if (!prev || !next)
    return false;
  if ("pageX" in next && "pageY" in next)
    return prev.pageX === next.pageX && prev.pageY === next.pageY;
  if ("clientX" in next && "clientY" in next)
    return prev.clientX === next.clientX && prev.clientY === next.clientY;
  return false;
}
function restoreFocus(activeElement, container) {
  if (activeElement !== document.activeElement && contains.contains(container, activeElement) && typeof activeElement.focus === "function")
    activeElement.focus();
}
function monitorResize(element, callback) {
  let prevWidth = null;
  let prevHeight = null;
  function onResize([{ target }]) {
    if (!document.documentElement.contains(target))
      return;
    const { width, height } = target.getBoundingClientRect();
    const fixedWidth = Math.floor(width);
    const fixedHeight = Math.floor(height);
    if (prevWidth !== fixedWidth || prevHeight !== fixedHeight) {
      Promise.resolve().then(() => {
        callback({ width: fixedWidth, height: fixedHeight });
      });
    }
    prevWidth = fixedWidth;
    prevHeight = fixedHeight;
  }
  const resizeObserver = new ResizeObserver(onResize);
  if (element)
    resizeObserver.observe(element);
  return () => {
    resizeObserver.disconnect();
  };
}

exports.isSamePoint = isSamePoint;
exports.monitorResize = monitorResize;
exports.restoreFocus = restoreFocus;
//# sourceMappingURL=util.cjs.map
