src/plugins/popper/index.js
function toValue(str, measurement, popperOffsets, referenceOffsets) {
  // separate value from unit
  var split = str.match(/((?:\-|\+)?\d*\.?\d*)(.*)/);
  var value = +split[1];
  var unit = split[2];

  // If it's not a number it's an operator, I guess
  if (!value) {
    return str;
  }

  if (unit.indexOf('%') === 0) {
    var element = void 0;
    switch (unit) {
      case '%p':
        element = popperOffsets;
        break;
      case '%':
      case '%r':
      default:
        element = referenceOffsets;
    }

    var rect = getClientRect(element);
    return rect[measurement] / 100 * value;
  } else if (unit === 'vh' || unit === 'vw') {
    // if is a vh or vw, we calculate the size based on the viewport
    var size = void 0;
    if (unit === 'vh') {
      size = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
    } else {
      size = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
    }
    return size / 100 * value;
  } else {
    // if is an explicit pixel unit, we get rid of the unit and keep the value
    // if is an implicit unit, it's px, and we return just the value
    return value;
  }
}
function toValue(str, measurement, popperOffsets, referenceOffsets) {
  // separate value from unit
  var split = str.match(/((?:\-|\+)?\d*\.?\d*)(.*)/);
  var value = +split[1];
  var unit = split[2];

  // If it's not a number it's an operator, I guess
  if (!value) {
    return str;
  }

  if (unit.indexOf('%') === 0) {
    var element = void 0;
    switch (unit) {
      case '%p':
        element = popperOffsets;
        break;
      case '%':
      case '%r':
      default:
        element = referenceOffsets;
    }

    var rect = getClientRect(element);
    return rect[measurement] / 100 * value;
  } else if (unit === 'vh' || unit === 'vw') {
    // if is a vh or vw, we calculate the size based on the viewport
    var size = void 0;
    if (unit === 'vh') {
      size = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
    } else {
      size = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
    }
    return size / 100 * value;
  } else {
    // if is an explicit pixel unit, we get rid of the unit and keep the value
    // if is an implicit unit, it's px, and we return just the value
    return value;
  }
}
function toValue ( str , measurement , popperOffsets , referenceOffsets ) { // separate value from unit var split = str . match ( / ((?:\-|\+)?\d*\.?\d*)(.*) / ) ; var value = + split [ 1 ] ; var unit = split [ 2 ] ; // If it's not a number it's an operator, I guess if ( ! value ) { return str ; } if ( unit . indexOf ( '%' ) === 0 ) { var element = void 0 ; switch ( unit ) { case '%p' : element = popperOffsets ; break ; case '%' : case '%r' : default : element = referenceOffsets ; } var rect = getClientRect ( element ) ; return rect [ measurement ] / 100 * value ; } else if ( unit === 'vh' || unit === 'vw' ) { // if is a vh or vw, we calculate the size based on the viewport var size = void 0 ; if ( unit === 'vh' ) { size = Math . max ( document . documentElement . clientHeight , window . innerHeight || 0 ) ; } else { size = Math . max ( document . documentElement . clientWidth , window . innerWidth || 0 ) ; } return size / 100 * value ; } else { // if is an explicit pixel unit, we get rid of the unit and keep the value // if is an implicit unit, it's px, and we return just the value return value ; } }
Converts a string containing value + unit into a px value number
@function
@memberof {modifiers~offset}
@private
@argument {String} str - Value + unit string
@argument {String} measurement - `height` or `width`
@argument {Object} popperOffsets
@argument {Object} referenceOffsets
@returns {Number|String}
Value in pixels, or original string if no values were extracted
Converts a string containing value + unit into a px value number