<commit_before>/// <reference path="../content/base.d.ts" />
var VDom = {
  UI: null as never as DomUI,
  // note: allowScripts is equal with allowTimers, vPort.ClearPort requires this assumption
  allowScripts: true,
  allowRAF: true,
  isHTML (this: void): boolean { return document.documentElement instanceof HTMLElement; },
  isStandard: true,
  createElement: function (this: any, tagName: string): HTMLElement {
    const node = document.createElement(tagName), valid = node instanceof HTMLElement;
    (this as typeof VDom).isStandard = valid;
    (this as typeof VDom).createElement = valid
      ? document.createElement.bind(document)
      : (document.createElementNS as (namespaceURI: "http://www.w3.org/1999/xhtml", qualifiedName: string) => HTMLElement
        ).bind(document, "http://www.w3.org/1999/xhtml");
    return valid ? node : (this as typeof VDom).createElement(tagName);
  } as Document["createElement"],
  /** Note: won't call functions if Vimium is destroyed */
  documentReady (callback: (this: void) => void): void {
    const f = function(callback: (this: void) => void): void { return callback(); };
    if (document.readyState !== "loading") {
      this.documentReady = f;
      return callback();
    }
    const listeners = [callback];
    function eventHandler(): void {
      // not need to check event.isTrusted
      removeEventListener("DOMContentLoaded", eventHandler, true);
      if (VDom) {
        VDom.documentReady = f;
        for (const i of listeners) { i(); }
      }
      listeners.length = 0; // in case VDom.documentReady is kept by other extensions
    }
    this.documentReady = function(callback): void {
      listeners.push(callback);
    };
    addEventListener("DOMContentLoaded", eventHandler, true);
  },
  parentFrame(): Element | null {
    try {
      return window.frameElement;
    } catch (e) {
      return null;
    }
  },
  getParent (el: Element): Element | null {
    const arr = el.getDestinationInsertionPoints ? el.getDestinationInsertionPoints() : null;
    arr && arr.length > 0 && (el = arr[arr.length - 1]);
    return el.parentElement || window.ShadowRoot && el.parentNode instanceof ShadowRoot && el.parentNode.host || null;
  },
  scrollingEl (): Element | null {
    return document.scrollingElement || (document.compatMode === "BackCompat" ? document.body : document.documentElement);
  },
  /**
   * other parts of code require that prepareCrop only depends on @dbZoom
   */
  prepareCrop (): number {
    let iw: number, ih: number, ihs: number;
    this.prepareCrop = function(): number {
      let fz = this.dbZoom, el = this.scrollingEl(), i: number, j: number;
      if (el) {
        i = el.clientWidth, j = el.clientHeight;
      } else {
        i = window.innerWidth, j = window.innerHeight;
        const doc = document.documentElement as Element | null, dz = fz / this.bZoom;
        if (!doc) { return ih = j, ihs = j - 8, iw = i; }
        // not reliable
        i = Math.min(Math.max(i - PixelConsts.MaxScrollbarWidth, (doc.clientWidth * dz) | 0), i);
        j = Math.min(Math.max(j - PixelConsts.MaxScrollbarWidth, (doc.clientHeight * dz) | 0), j);
      }
      if (this.paintBox) {
        const b = this.paintBox, dz = fz / this.bZoom;
        i = Math.min(i, b[0] * dz); j = Math.min(j, b[1] * dz);
      }
      iw = i / fz, ih = j / fz;
      ihs = ih - ((8 / fz) | 0);
      return iw;
    };
    this.cropRectToVisible = function(left, top, right, bottom): VRect | null {
      if (top > ihs || bottom < 3) {
        return null;
      }
      const cr: VRect = [ //
        left   >  0 ? (left   | 0) :  0, //
        top    >  0 ? (top    | 0) :  0, //
        right  < iw ? (right  | 0) : iw, //
        bottom < ih ? (bottom | 0) : ih  //
      ];
      return (cr[2] - cr[0] >= 3 && cr[3] - cr[1] >= 3) ? cr : null;
    };
    return this.prepareCrop();
  },
  getVisibleClientRect (element: Element, el_style?: CSSStyleDeclaration): VRect | null {
    const arr = element.getClientRects();
    let cr: VRect | null, style: CSSStyleDeclaration | null, _ref: HTMLCollection | undefined
      , isVisible: boolean | undefined, notInline: boolean | undefined, str: string;
    for (let _i = 0, _len = arr.length; _i < _len; _i++) {
      const rect = arr[_i];
      if (rect.height > 0 && rect.width > 0) {
        if (cr = this.cropRectToVisible(rect.left, rect.top, rect.right, rect.bottom)) {
          if (isVisible == null) {
            el_style || (el_style = window.getComputedStyle(element));
            isVisible = el_style.visibility === 'visible';
          }
          if (isVisible) { return cr; }
        }
        continue;
      }
      if (_ref) { continue; }
      _ref = element.children;
      for (let _j = 0, _len1 = _ref.length; _j < _len1; _j++) {
        style = window.getComputedStyle(_ref[_j]);
        if (style.float !== 'none' ||<commit_msg>prepareCrop: make cached values integer<commit_after>/// <reference path="../content/base.d.ts" />
var VDom = {
  UI: null as never as DomUI,
  // note: allowScripts is equal with allowTimers, vPort.ClearPort requires this assumption
  allowScripts: true,
  allowRAF: true,
  isHTML (this: void): boolean { return document.documentElement instanceof HTMLElement; },
  isStandard: true,
  createElement: function (this: any, tagName: string): HTMLElement {
    const node = document.createElement(tagName), valid = node instanceof HTMLElement;
    (this as typeof VDom).isStandard = valid;
    (this as typeof VDom).createElement = valid
      ? document.createElement.bind(document)
      : (document.createElementNS as (namespaceURI: "http://www.w3.org/1999/xhtml", qualifiedName: string) => HTMLElement
        ).bind(document, "http://www.w3.org/1999/xhtml");
    return valid ? node : (this as typeof VDom).createElement(tagName);
  } as Document["createElement"],
  /** Note: won't call functions if Vimium is destroyed */
  documentReady (callback: (this: void) => void): void {
    const f = function(callback: (this: void) => void): void { return callback(); };
    if (document.readyState !== "loading") {
      this.documentReady = f;
      return callback();
    }
    const listeners = [callback];
    function eventHandler(): void {
      // not need to check event.isTrusted
      removeEventListener("DOMContentLoaded", eventHandler, true);
      if (VDom) {
        VDom.documentReady = f;
        for (const i of listeners) { i(); }
      }
      listeners.length = 0; // in case VDom.documentReady is kept by other extensions
    }
    this.documentReady = function(callback): void {
      listeners.push(callback);
    };
    addEventListener("DOMContentLoaded", eventHandler, true);
  },
  parentFrame(): Element | null {
    try {
      return window.frameElement;
    } catch (e) {
      return null;
    }
  },
  getParent (el: Element): Element | null {
    const arr = el.getDestinationInsertionPoints ? el.getDestinationInsertionPoints() : null;
    arr && arr.length > 0 && (el = arr[arr.length - 1]);
    return el.parentElement || window.ShadowRoot && el.parentNode instanceof ShadowRoot && el.parentNode.host || null;
  },
  scrollingEl (): Element | null {
    return document.scrollingElement || (document.compatMode === "BackCompat" ? document.body : document.documentElement);
  },
  /**
   * other parts of code require that prepareCrop only depends on @dbZoom
   */
  prepareCrop (): number {
    let iw: number, ih: number, ihs: number;
    this.prepareCrop = function(): number {
      let fz = this.dbZoom, el = this.scrollingEl(), i: number, j: number;
      if (el) {
        i = el.clientWidth, j = el.clientHeight;
      } else {
        i = window.innerWidth, j = window.innerHeight;
        const doc = document.documentElement as Element | null, dz = fz / this.bZoom;
        if (!doc) { return ih = j, ihs = j - 8, iw = i; }
        // not reliable
        i = Math.min(Math.max(i - PixelConsts.MaxScrollbarWidth, (doc.clientWidth * dz) | 0), i);
        j = Math.min(Math.max(j - PixelConsts.MaxScrollbarWidth, (doc.clientHeight * dz) | 0), j);
      }
      if (this.paintBox) {
        const b = this.paintBox, dz = fz / this.bZoom;
        i = Math.min(i, b[0] * dz); j = Math.min(j, b[1] * dz);
      }
      iw = (i / fz) | 0, ih = (j / fz) | 0;
      ihs = ((j - 8) / fz) | 0;
      return iw;
    };
    this.cropRectToVisible = function(left, top, right, bottom): VRect | null {
      if (top > ihs || bottom < 3) {
        return null;
      }
      const cr: VRect = [ //
        left   >  0 ? (left   | 0) :  0, //
        top    >  0 ? (top    | 0) :  0, //
        right  < iw ? (right  | 0) : iw, //
        bottom < ih ? (bottom | 0) : ih  //
      ];
      return cr[2] - cr[0] >= 3 && cr[3] - cr[1] >= 3 ? cr : null;
    };
    return this.prepareCrop();
  },
  getVisibleClientRect (element: Element, el_style?: CSSStyleDeclaration): VRect | null {
    const arr = element.getClientRects();
    let cr: VRect | null, style: CSSStyleDeclaration | null, _ref: HTMLCollection | undefined
      , isVisible: boolean | undefined, notInline: boolean | undefined, str: string;
    for (let _i = 0, _len = arr.length; _i < _len; _i++) {
      const rect = arr[_i];
      if (rect.height > 0 && rect.width > 0) {
        if (cr = this.cropRectToVisible(rect.left, rect.top, rect.right, rect.bottom)) {
          if (isVisible == null) {
            el_style || (el_style = window.getComputedStyle(element));
            isVisible = el_style.visibility === 'visible';
          }
          if (isVisible) { return cr; }
        }
        continue;
      }
      if (_ref) { continue; }
      _ref = element.children;
      for (let _j = 0, _len1 = _ref.length; _j < _len1; _j++) {
        style = window.getComputedStyle(_ref[_j]);
        if (style.float !== 'none' ||
{'fraction_non_alphanumeric': 0.14212939378502293, 'fraction_numerical': 0.008558329088130413, 'mean_word_length': 2.5552336110105034, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '60779', 'n_tokens_mistral': 3136, 'n_tokens_neox': 3086, 'n_words': 868}