"use strict";

exports.__esModule = true;
exports.default = void 0;
var rpxRegex = /"[^"]+"|'[^']+'|url\([^)]+\)|(\d*\.?\d+)rpx/g;
var defaults = {
  viewportWidth: 750,
  viewportUnit: 'vw',
  fontViewportUnit: 'vw',
  unitPrecision: 5
};
function toFixed(number, precision) {
  var multiplier = Math.pow(10, precision + 1);
  var wholeNumber = Math.floor(number * multiplier);
  return Math.round(wholeNumber / 10) * 10 / multiplier;
}

// transform rpx to vw
function createRpxReplace(opts, viewportUnit, viewportSize) {
  return function (m, $1) {
    if (!$1) {
      return m;
    }
    var pixels = parseFloat($1);
    var parsedVal = toFixed(pixels / viewportSize * 100, opts.unitPrecision);
    return parsedVal + viewportUnit;
  };
}
function rpx2vw(str, options) {
  var opts = Object.assign({}, defaults, options);
  if (str.indexOf('rpx') === -1) {
    return;
  }
  return str.replace(rpxRegex, createRpxReplace(opts, opts.viewportUnit, opts.viewportWidth));
}
var _default = rpx2vw;
exports.default = _default;