<commit_before>import Browser from '../interfaces/browser';
import PNGProcessor from '../interfaces/png-processor';
import Screenshotter, {
  ScreenshotOptions,
  TooManyElementsError
} from '../interfaces/screenshotter';
import JimpProcessor from './jimp-processor';
import { MugshotSelector } from './mugshot';

export interface BrowserScreenshotterOptions {
  pngProcessor?: PNGProcessor;

  /**
   * Disable any CSS animations that might cause test flakiness.
   */
  disableAnimations?: boolean;
}

/* istanbul ignore next because this will be stringified and executed in the browser */
function injectAnimationDisablingStylesheet() {
  const style = document.createElement('style');
  style.textContent = `
input {
  caret-color: transparent;
}

*, *::before, *::after {
  transition: none !important;
  animation: none !important;
}
        `;
  document.head.appendChild(style);
}

/**
 * Take screenshots from a Webdriver compatible browser.
 */
export default class BrowserScreenshotter implements Screenshotter {
  private readonly disableAnimations: boolean;

  private readonly pngProcessor: PNGProcessor;

  constructor(
    private readonly browser: Browser,
    {
      disableAnimations = false,
      pngProcessor = new JimpProcessor()
    }: BrowserScreenshotterOptions = {}
  ) {
    this.disableAnimations = disableAnimations;
    this.pngProcessor = pngProcessor;
  }

  /**
   * Take screenshots of selectors by first taking a viewport screenshot and
   * then cropping the element out.
   *
   * The element's bounding rectangle will be used to crop it out of the<commit_msg>Reorder params<commit_after>import Browser from '../interfaces/browser';
import PNGProcessor from '../interfaces/png-processor';
import Screenshotter, {
  ScreenshotOptions,
  TooManyElementsError
} from '../interfaces/screenshotter';
import JimpProcessor from './jimp-processor';
import { MugshotSelector } from './mugshot';

export interface BrowserScreenshotterOptions {
  pngProcessor?: PNGProcessor;

  /**
   * Disable any CSS animations that might cause test flakiness.
   */
  disableAnimations?: boolean;
}

/* istanbul ignore next because this will be stringified and executed in the browser */
function injectAnimationDisablingStylesheet() {
  const style = document.createElement('style');
  style.textContent = `
input {
  caret-color: transparent;
}

*, *::before, *::after {
  transition: none !important;
  animation: none !important;
}
        `;
  document.head.appendChild(style);
}

/**
 * Take screenshots from a Webdriver compatible browser.
 */
export default class BrowserScreenshotter implements Screenshotter {
  private readonly pngProcessor: PNGProcessor;

  private readonly disableAnimations: boolean;

  constructor(
    private readonly browser: Browser,
    {
      pngProcessor = new JimpProcessor(),
      disableAnimations = false
    }: BrowserScreenshotterOptions = {}
  ) {
    this.pngProcessor = pngProcessor;
    this.disableAnimations = disableAnimations;
  }

  /**
   * Take screenshots of selectors by first taking a viewport screenshot and
   * then cropping the element out.
   *
   * The element's bounding rectangle will be used to crop it out of the
{'fraction_non_alphanumeric': 0.09252891528602689, 'fraction_numerical': 0.0, 'mean_word_length': 4.111821086261981, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2552757', 'n_tokens_mistral': 900, 'n_tokens_neox': 847, 'n_words': 268}