'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var INHERITED_PROPERTIES = ['font', 'letterSpacing', 'textTransform', 'fontKerning', 'fontOpticalSizing', 'fontSizeAdjust', 'fontStretch', 'fontVariant', 'fontWeight', 'fontVariationSettings', 'fontSynthesis', 'textIndent'];
var measureStyles = {
  position: 'absolute',
  top: '0px',
  left: '0px',
  width: '0px',
  height: '0px',
  visibility: 'hidden',
  overflow: 'scroll',
  whiteSpace: 'pre'
};
function getInputWidth(element, container) {
  if (!element || !container) {
    return 0;
  }
  var measure = document.createElement('span');
  measure.innerText = element.value || element.placeholder || ' ';
  Object.assign(measure.style, measureStyles);
  var styles = window.getComputedStyle(element);
  INHERITED_PROPERTIES.forEach(function (property) {
    measure.style.setProperty(property, String(styles[property]));
  });
  container.appendChild(measure);
  var width = measure.scrollWidth;
  container.removeChild(measure);
  return width;
}

exports.getInputWidth = getInputWidth;
