<commit_before>(function() {
  var tosser = window.tosser = {},
      unknownUnits = [
        'em', 'ex', 'ch', 'rem',
        'vh', 'vw', 'vmin', 'vmax'
      ],
      knownUnits = {
        'mm': 96 / 25.4,
        'cm': 96 / 2.54,
        'in': 96,
        'pt': 4 / 3
      },
      measurementHtml = buildMeasurementHtml(),
      replacementPattern = buildReplacementPattern();

  /**
   * options:
   *     container: Element
   *     containerUnits: Object<string, number>
   *     vertical: boolean (default: false)
   */
  tosser.evaluate = function(expression, options) {
    var units = options.containerUnits ||
                tosser.resolveContainerUnits(options.container);

    return eval(
      expression
        .trim()
        .replace(/^calc/, '')
        .replace(replacementPattern, function(m, v, _, unit) {
          var value = parseFloat(v);
          switch (unit) {
            case 'px':
              return value;
            case '%':
              return value * units[options.vertical ? 'v%' : 'h%'];
            default:
              return value * (units[unit] || knownUnits[unit]);
          }
        }));
  };

  /**
   *
   */
  tosser.resolveContainerUnits = function(container) {
    var el = document.createElement('div');
    el.id = 'text-resize-control';
    el.position = 'absolute';
    el.style.visibility = 'hidden';
    el.innerHTML = measurementHtml;
    container.insertBefore(el, container.firstChild);

    var units = unknownUnits.reduce(function(acc, unit) {
      acc[unit] = container.querySelector('.tosser--' + unit).clientWidth;
      return acc;
    }, {});

    var percentEl = container.querySelector('.tosser--percent');
    units['h%'] = percentEl.clientWidth / 100;
    units['v%'] = percentEl.clientHeight / 100;

    container.removeChild(el);

    return units;
  }

  /**
   *
   */
  function buildMeasurementHtml() {<commit_msg>Adds style object evaluation<commit_after>(function() {
  var tosser = window.tosser = {},
      unknownUnits = [
        'em', 'ex', 'ch', 'rem',
        'vh', 'vw', 'vmin', 'vmax'
      ],
      knownUnits = {
        'mm': 96 / 25.4,
        'cm': 96 / 2.54,
        'in': 96,
        'pt': 4 / 3
      },
      verticalStyles = {
        'top': true,
        'height': true
      },
      isCalcPattern = /^calc\(/,
      measurementHtml = buildMeasurementHtml(),
      replacementPattern = buildReplacementPattern();

  /**
   *
   */
  tosser.evaluateStyles = function(styles, options) {
    var units = options.containerUnits ||
                tosser.resolveContainerUnits(options.container);

    return Object.keys(styles).reduce(function(acc, name) {
      var val = styles[name];
      acc[name] = isCalcPattern.test(val) ?
          toss.evaluateCalc(styles[name], {
            containerUnits: units,
            vertical: !!verticalStyles[name]}) :
          val;
      return acc;
    }, {});
  };

  /**
   * Evaluates a calc expression in the context of a container.
   * options:
   *     container: Element
   *     containerUnits: Object<string, number>
   *     vertical: boolean (default: false)
   */
  tosser.evaluateCalc = function(expression, options) {
    var units = options.containerUnits ||
                tosser.resolveContainerUnits(options.container);

    return eval(
      expression
        .trim()
        .replace(/^calc/, '')
        .replace(replacementPattern, function(m, v, _, unit) {
          var value = parseFloat(v);
          switch (unit) {
            case 'px':
              return value;
            case '%':
              return value * units[options.vertical ? 'v%' : 'h%'];
            default:
              return value * (units[unit] || knownUnits[unit]);
          }
        }));
  };

  /**
   * Resolves and returns units that are relative to the container, or can only
   * be determined at a point in time.
   *
   * Useful when evaluating multiple calcs against a single container, and
   * can be supplied to `evaluateCalc` as options.containerUnits to avoid
   * unnecessary calculation.
   */
  tosser.resolveContainerUnits = function(container) {
    var el = document.createElement('div');
    el.id = 'text-resize-control';
    el.position = 'absolute';
    el.style.visibility = 'hidden';
    el.innerHTML = measurementHtml;
    container.insertBefore(el, container.firstChild);

    var units = unknownUnits.reduce(function(acc, unit) {
      acc[unit] = container.querySelector('.tosser--' + unit).clientWidth;
      return acc;
    }, {});

    var percentEl = container.querySelector('.tosser--percent');
    units['h%'] = percentEl.clientWidth / 100;
    units['v%'] = percentEl.clientHeight / 100;

    container.removeChild(el);

    return units;
  }

  /**
   *
   */
  function buildMeasurementHtml() {
{'fraction_non_alphanumeric': 0.14157631359466222, 'fraction_numerical': 0.008340283569641367, 'mean_word_length': 2.198, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7262357', 'n_tokens_mistral': 1449, 'n_tokens_neox': 1417, 'n_words': 310}