var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var stdin_exports = {};
__export(stdin_exports, {
  addUnit: () => addUnit,
  getSizeStyle: () => getSizeStyle,
  getZIndexStyle: () => getZIndexStyle,
  unitToPx: () => unitToPx
});
module.exports = __toCommonJS(stdin_exports);
var import__ = require("..");
var import_number = require("../validate/number");
function addUnit(value) {
  if (!(0, import__.isDef)(value)) {
    return void 0;
  }
  return (0, import_number.isNumeric)(value) ? `${value}px` : String(value);
}
function getSizeStyle(originSize) {
  if ((0, import__.isDef)(originSize)) {
    const size = addUnit(originSize);
    return {
      width: size,
      height: size
    };
  }
  return {};
}
function getZIndexStyle(zIndex) {
  const style = {};
  if (zIndex !== void 0) {
    style.zIndex = +zIndex;
  }
  return style;
}
let rootFontSize;
function getRootFontSize() {
  if (!rootFontSize) {
    const doc = document.documentElement;
    const fontSize = doc.style.fontSize || window.getComputedStyle(doc).fontSize;
    rootFontSize = parseFloat(fontSize);
  }
  return rootFontSize;
}
function convertRem(value) {
  value = value.replace(/rem/g, "");
  return +value * getRootFontSize();
}
function convertVw(value) {
  value = value.replace(/vw/g, "");
  return +value * window.innerWidth / 100;
}
function convertVh(value) {
  value = value.replace(/vh/g, "");
  return +value * window.innerHeight / 100;
}
function unitToPx(value) {
  if (typeof value === "number") {
    return value;
  }
  if (import__.inBrowser) {
    if (value.indexOf("rem") !== -1) {
      return convertRem(value);
    }
    if (value.indexOf("vw") !== -1) {
      return convertVw(value);
    }
    if (value.indexOf("vh") !== -1) {
      return convertVh(value);
    }
  }
  return parseFloat(value);
}
