<commit_before>define([
  'viewport/src/utils',
  'viewport/src/bindings'
], function(utils, bindings) {

  var conditions = {};

  var is = function is(element, name, data) {

    if (name[0] === '!') {
      return !is(element, name.slice(1), data);
    }

    if (conditions[name] === undefined) {
      throw new Error('Undefined condition: ' + name);
    }

    data = data || {};
    data.position = data.position || utils.offsetOf(element);
    data.viewport = data.viewport || utils.position();
    if (!data.state) {
      var binding = bindings.get(element);
      if (binding) {
        data.state = binding.state;
      } else {
        data.state = {};
      }
    }

    return conditions[name](element, data);
  };

  var defineCondition = function defineCondition(name, test) {
    if (!conditions[name]) {
      conditions[name] = test;
    } else {
      throw new Error('A condition has already been defined with the name "' + name + '"');
    }
  };

  defineCondition('above', function(element, data) {
    return data.position.bottom < data.viewport.top;
  });

  defineCondition('below', function(element, data) {
    return data.position.top > data.viewport.bottom;
  });

  defineCondition('inside', function(element, data) {
    return !(
      is(element, 'above', data) ||
      is(element, 'below', data)
    );
  });

  defineCondition('intersectingTop', function(element, data) {
    return (
      data.position.top <= data.viewport.top &&
      data.position.bottom >= data.viewport.top
    );
  });

  defineCondition('intersectingMiddle', function(element, data) {
    var viewportMiddle = data.viewport.height / 2;
    return (
      data.position.top <= viewportMiddle &&
      data.position.bottom >= viewportMiddle
    );
  });

  defineCondition('intersectingBottom', function(element, data) {
    return (
      data.position.top <= data.viewport.bottom &&
      data.position.bottom >= data.viewport.bottom
    );
  });

  defineCondition('contained', function(element, data) {
    return !is(element, 'notContained', data);
  });

  defineCondition('enter', function(element, data) {
    var state = data.state;
    if (is(element, 'inside', data)) {
      if (!state.inViewport) {
        state.inViewport = true;
        return true;
      }
    } else {
      state.inViewport = false;
    }
    return false;
  });

  defineCondition('exit', function(element, data) {
    var state = data.state;
    if (is(element, 'outside', data)) {
      if (
        state.inViewport === true ||
        state.inViewport === undefined
      ) {
        state.inViewport = false;
        return true;
      }
    } else {
      state.inViewport = true;
    }
    return false;
  });

  return {
    is: is,
    defineCondition: defineCondition,
    conditions: conditions
  };

});<commit_msg>Corrected the logic in `intersectingMiddle`<commit_after>define([
  'viewport/src/utils',
  'viewport/src/bindings'
], function(utils, bindings) {

  var conditions = {};

  var is = function is(element, name, data) {

    if (name[0] === '!') {
      return !is(element, name.slice(1), data);
    }

    if (conditions[name] === undefined) {
      throw new Error('Undefined condition: ' + name);
    }

    data = data || {};
    data.position = data.position || utils.offsetOf(element);
    data.viewport = data.viewport || utils.position();
    if (!data.state) {
      var binding = bindings.get(element);
      if (binding) {
        data.state = binding.state;
      } else {
        data.state = {};
      }
    }

    return conditions[name](element, data);
  };

  var defineCondition = function defineCondition(name, test) {
    if (!conditions[name]) {
      conditions[name] = test;
    } else {
      throw new Error('A condition has already been defined with the name "' + name + '"');
    }
  };

  defineCondition('above', function(element, data) {
    return data.position.bottom < data.viewport.top;
  });

  defineCondition('below', function(element, data) {
    return data.position.top > data.viewport.bottom;
  });

  defineCondition('inside', function(element, data) {
    return !(
      is(element, 'above', data) ||
      is(element, 'below', data)
    );
  });

  defineCondition('intersectingTop', function(element, data) {
    return (
      data.position.top <= data.viewport.top &&
      data.position.bottom >= data.viewport.top
    );
  });

  defineCondition('intersectingMiddle', function(element, data) {
    var viewportMiddle = data.viewport.top + (data.viewport.height / 2);
    return (
      data.position.top <= viewportMiddle &&
      data.position.bottom >= viewportMiddle
    );
  });

  defineCondition('intersectingBottom', function(element, data) {
    return (
      data.position.top <= data.viewport.bottom &&
      data.position.bottom >= data.viewport.bottom
    );
  });

  defineCondition('contained', function(element, data) {
    return !is(element, 'notContained', data);
  });

  defineCondition('enter', function(element, data) {
    var state = data.state;
    if (is(element, 'inside', data)) {
      if (!state.inViewport) {
        state.inViewport = true;
        return true;
      }
    } else {
      state.inViewport = false;
    }
    return false;
  });

  defineCondition('exit', function(element, data) {
    var state = data.state;
    if (is(element, 'outside', data)) {
      if (
        state.inViewport === true ||
        state.inViewport === undefined
      ) {
        state.inViewport = false;
        return true;
      }
    } else {
      state.inViewport = true;
    }
    return false;
  });

  return {
    is: is,
    defineCondition: defineCondition,
    conditions: conditions
  };

});
{'fraction_non_alphanumeric': 0.14914125481948826, 'fraction_numerical': 0.0010515247108307045, 'mean_word_length': 2.6748229233741148, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '1022410', 'n_tokens_mistral': 1781, 'n_tokens_neox': 1720, 'n_words': 365}