
export function pxToRem(pxVal) {
    // 基准是750，10px
    const baseWidth = 750
    const basePx = 100;
    const fontSize = Math.round((pxVal / baseWidth) * basePx)
    return fontSize
}

export function resizeWindow() {
  // 是否需要横屏展示
  let isLandSpace = false;
  // 处理横屏
  let clientWidth = 0;
  let clientHeight = 0;
  if (window.screen) {
    clientWidth = window.screen.width;
    clientHeight = window.screen.height;
  }
  if (!clientWidth || !clientHeight) {
    clientWidth = document.documentElement.clientWidth;
    clientHeight = document.documentElement.clientHeight;
  }
  let elWidth = 375;
  let elHeight = 667;
  // islandSpace 为 clientWidth > clientHeight
  if (clientWidth && clientHeight) {
    if(isLandSpace) {
      // 横屏模式下，宽度取大的值
      elWidth = Math.max(clientWidth, clientHeight);
      elHeight = Math.min(clientWidth, clientHeight);
    } else {
      // 竖屏模式下，宽度取小的值
      elWidth = Math.min(clientWidth, clientHeight);
      elHeight = Math.max(clientWidth, clientHeight);
    }
  } 
  let fontSize = pxToRem(elWidth);
  // 横屏展示时，rem 按 16:9 宽高比缩小
  if (isLandSpace) {
    fontSize = fontSize / (elWidth > elHeight ? elWidth / elHeight : elHeight / elWidth);
  }
  // 最后一层控制font-size
  fontSize = Math.min(55, Math.max(45, fontSize));
  document.documentElement.style.setProperty('font-size', `${fontSize}px`, 'important');
}