import { useEffect } from 'react';
export var useWindowSize = function useWindowSize() {
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  var _options$debounceMs = options.debounceMs,
    debounceMs = _options$debounceMs === void 0 ? 100 : _options$debounceMs;
  useEffect(function () {
    var timeoutId;
    var setRealVH = function setRealVH() {
      // window.innerHeight 会返回视口真实的高度（不包括工具栏）
      var vh = window.innerHeight * 0.01;
      document.documentElement.style.setProperty('--vh', "".concat(vh, "px"));
    };
    var debouncedHandleResize = function debouncedHandleResize() {
      clearTimeout(timeoutId);
      timeoutId = setTimeout(setRealVH, debounceMs);
    };

    // 页面加载和窗口大小变化时都重新计算
    debouncedHandleResize();
    window.addEventListener('resize', debouncedHandleResize);
    return function () {
      window.removeEventListener('resize', debouncedHandleResize);
      clearTimeout(timeoutId);
    };
  }, [debounceMs]);
};