<commit_before>// @ts-ignore
import { setModifierManager } from '@ember/modifier';

type State = {
  element: Element;
  handler: (...args: unknown[]) => unknown;
};

/**
 * Used to trigger an action a user reaches the bottom of the modified element.
 * This is useful especially for infinite scrolls.
 */
export default setModifierManager(
  () => ({
    createModifier() {
      return {
        element: null,
        handler: null
      };
    },

    installModifier(state: State, element: Element, { positional }: any) {
      const [callback] = positional;
      state.element = element;

      state.handler = (event: Event) => {
        if (state.element.scrollTop + state.element.clientHeight >= state.element.scrollHeight) {
          callback(state.element, event);
        }
      };

      state.element.addEventListener('scroll', state.handler, false);
    },

    destroyModifier(state: any) {
      state.element.removeEventListener('scroll', state.handler, false);
    }
  }),
  class OnClickOutsideModifierManager {}
);<commit_msg>add offset to on-bottom-reached modifier<commit_after>// @ts-ignore
import { setModifierManager } from '@ember/modifier';

type State = {
  element: Element;
  handler: (...args: unknown[]) => unknown;
  cachedScrollTop: number;
};

const TRIGGER_OFFSET = 20;

/**
 * Used to trigger an action a user reaches the bottom of the modified element.
 * This is useful especially for infinite scrolls.
 */
export default setModifierManager(
  () => ({
    createModifier() {
      return {
        element: null,
        handler: null
      };
    },

    installModifier(state: State, element: Element, { positional }: any) {
      const [callback] = positional;
      state.element = element;
      state.cachedScrollTop = 0;

      state.handler = (_: Event) => {
        if (
          state.element.scrollTop >= state.cachedScrollTop &&
          Math.ceil(state.element.scrollTop) + state.element.clientHeight >= state.element.scrollHeight - TRIGGER_OFFSET
        ) {
          state.cachedScrollTop = state.element.scrollTop + TRIGGER_OFFSET;
          callback(state.element, event);
        }
      };

      state.element.addEventListener('scroll', state.handler, false);
    },

    destroyModifier(state: any) {
      state.element.removeEventListener('scroll', state.handler, false);
    }
  }),
  class OnClickOutsideModifierManager {}
);
{'fraction_non_alphanumeric': 0.12599082186065916, 'fraction_numerical': 0.0012515644555694619, 'mean_word_length': 2.861513687600644, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '5508257', 'n_tokens_mistral': 669, 'n_tokens_neox': 662, 'n_words': 164}