<commit_before>import * as cornerstone from 'cornerstone-core';
import * as cornerstoneMath from 'cornerstone-math';
import copyPoints from '../util/copyPoints.js';
import pauseEvent from '../util/pauseEvent.js';

let isClickEvent = true;
let preventClickTimeout;
const clickDelay = 200;

function preventClickHandler () {
  isClickEvent = false;
}

function activateMouseDown (mouseEventDetail) {
  $(mouseEventDetail.element).trigger('CornerstoneToolsMouseDownActivate', mouseEventDetail);
}

function mouseDoubleClick (e) {
  const element = e.currentTarget;
  const eventType = 'CornerstoneToolsMouseDoubleClick';

  const startPoints = {
    page: cornerstoneMath.point.pageToPoint(e),
    image: cornerstone.pageToPixel(element, e.pageX, e.pageY),
    client: {
      x: e.clientX,
      y: e.clientY
    }
  };

  startPoints.canvas = cornerstone.pixelToCanvas(element, startPoints.image);

  const lastPoints = copyPoints(startPoints);
  const eventData = {
    event: e,
    which: e.which,
    viewport: cornerstone.getViewport(element),
    image: cornerstone.getEnabledElement(element).image,
    element,
    startPoints,
    lastPoints,
    currentPoints: startPoints,
    deltaPoints: {
      x: 0,
      y: 0
    },
    type: eventType
  };

  const event = $.Event(eventType, eventData);

  $(eventData.element).trigger(event, eventData);
}

function mouseDown (e) {
  preventClickTimeout = setTimeout(preventClickHandler, clickDelay);

  const element = e.currentTarget;
  const eventType = 'CornerstoneToolsMouseDown';

    // Prevent CornerstoneToolsMouseMove while mouse is down
  $(element).off('mousemove', mouseMove);

  const startPoints = {
    page: cornerstoneMath.point.pageToPoint(e),
    image: cornerstone.pageToPixel(element, e.pageX, e.pageY),
    client: {
      x: e.clientX,
      y: e.clientY
    }
  };

  startPoints.canvas = cornerstone.pixelToCanvas(element, startPoints.image);

  let lastPoints = copyPoints(startPoints);
  const eventData = {
    event: e,
    which: e.which,
    viewport: cornerstone.getViewport(element),
    image: cornerstone.getEnabledElement(element).image,
    element,
    startPoints,
    lastPoints,
    currentPoints: startPoints,
    deltaPoints: {
      x: 0,
      y: 0
    },
    type: eventType
  };

  const onMouseDown = $(element).data('onMouseDown');
  if (onMouseDown) {
    onMouseDown(eventData);
  }

  const event = $.Event(eventType, eventData);

  $(eventData.element).trigger(event, eventData);

  if (event.isImmediatePropagationStopped() === false) {
        // No tools responded to this event, give the active tool a chance
    if (activateMouseDown(eventData) === true) {
      return pauseEvent(e);
    }
  }

  const whichMouseButton = e.which;

  function onMouseMove (e) {
        // Calculate our current points in page and image coordinates
    const eventType = 'CornerstoneToolsMouseDrag';
    const currentPoints = {
      page: cornerstoneMath.point.pageToPoint(e),
      image: cornerstone.pageToPixel(element, e.pageX, e.pageY),
      client: {
        x: e.clientX,
        y: e.clientY
      }
    };

    currentPoints.canvas = cornerstone.pixelToCanvas(element, currentPoints.image);

        // Calculate delta values in page and image coordinates
    const deltaPoints = {
      page: cornerstoneMath.point.subtract(currentPoints.page, lastPoints.page),
      image: cornerstoneMath.point.subtract(currentPoints.image, lastPoints.image),
      client: cornerstoneMath.point.subtract(currentPoints.client, lastPoints.client),
      canvas: cornerstoneMath.point.subtract(currentPoints.canvas, lastPoints.canvas)
    };

    const eventData = {
      which: whichMouseButton,
      viewport: cornerstone.getViewport(element),
      image: cornerstone.getEnabledElement(element).image,
      element,
      startPoints,
      lastPoints,
      currentPoints,
      deltaPoints,
      type: eventType,
      ctrlKey : e.ctrlKey,
      metaKey : e.metaKey,
      shiftKey : e.shiftKey
    };

    $(eventData.element).trigger(eventType, eventData);

        // Update the last points<commit_msg>typos to validate eslint<commit_after>import * as cornerstone from 'cornerstone-core';
import * as cornerstoneMath from 'cornerstone-math';
import copyPoints from '../util/copyPoints.js';
import pauseEvent from '../util/pauseEvent.js';

let isClickEvent = true;
let preventClickTimeout;
const clickDelay = 200;

function preventClickHandler () {
  isClickEvent = false;
}

function activateMouseDown (mouseEventDetail) {
  $(mouseEventDetail.element).trigger('CornerstoneToolsMouseDownActivate', mouseEventDetail);
}

function mouseDoubleClick (e) {
  const element = e.currentTarget;
  const eventType = 'CornerstoneToolsMouseDoubleClick';

  const startPoints = {
    page: cornerstoneMath.point.pageToPoint(e),
    image: cornerstone.pageToPixel(element, e.pageX, e.pageY),
    client: {
      x: e.clientX,
      y: e.clientY
    }
  };

  startPoints.canvas = cornerstone.pixelToCanvas(element, startPoints.image);

  const lastPoints = copyPoints(startPoints);
  const eventData = {
    event: e,
    which: e.which,
    viewport: cornerstone.getViewport(element),
    image: cornerstone.getEnabledElement(element).image,
    element,
    startPoints,
    lastPoints,
    currentPoints: startPoints,
    deltaPoints: {
      x: 0,
      y: 0
    },
    type: eventType
  };

  const event = $.Event(eventType, eventData);

  $(eventData.element).trigger(event, eventData);
}

function mouseDown (e) {
  preventClickTimeout = setTimeout(preventClickHandler, clickDelay);

  const element = e.currentTarget;
  const eventType = 'CornerstoneToolsMouseDown';

    // Prevent CornerstoneToolsMouseMove while mouse is down
  $(element).off('mousemove', mouseMove);

  const startPoints = {
    page: cornerstoneMath.point.pageToPoint(e),
    image: cornerstone.pageToPixel(element, e.pageX, e.pageY),
    client: {
      x: e.clientX,
      y: e.clientY
    }
  };

  startPoints.canvas = cornerstone.pixelToCanvas(element, startPoints.image);

  let lastPoints = copyPoints(startPoints);
  const eventData = {
    event: e,
    which: e.which,
    viewport: cornerstone.getViewport(element),
    image: cornerstone.getEnabledElement(element).image,
    element,
    startPoints,
    lastPoints,
    currentPoints: startPoints,
    deltaPoints: {
      x: 0,
      y: 0
    },
    type: eventType
  };

  const onMouseDown = $(element).data('onMouseDown');

  if (onMouseDown) {
    onMouseDown(eventData);
  }

  const event = $.Event(eventType, eventData);

  $(eventData.element).trigger(event, eventData);

  if (event.isImmediatePropagationStopped() === false) {
        // No tools responded to this event, give the active tool a chance
    if (activateMouseDown(eventData) === true) {
      return pauseEvent(e);
    }
  }

  const whichMouseButton = e.which;

  function onMouseMove (e) {
        // Calculate our current points in page and image coordinates
    const eventType = 'CornerstoneToolsMouseDrag';
    const currentPoints = {
      page: cornerstoneMath.point.pageToPoint(e),
      image: cornerstone.pageToPixel(element, e.pageX, e.pageY),
      client: {
        x: e.clientX,
        y: e.clientY
      }
    };

    currentPoints.canvas = cornerstone.pixelToCanvas(element, currentPoints.image);

        // Calculate delta values in page and image coordinates
    const deltaPoints = {
      page: cornerstoneMath.point.subtract(currentPoints.page, lastPoints.page),
      image: cornerstoneMath.point.subtract(currentPoints.image, lastPoints.image),
      client: cornerstoneMath.point.subtract(currentPoints.client, lastPoints.client),
      canvas: cornerstoneMath.point.subtract(currentPoints.canvas, lastPoints.canvas)
    };

    const eventData = {
      which: whichMouseButton,
      viewport: cornerstone.getViewport(element),
      image: cornerstone.getEnabledElement(element).image,
      element,
      startPoints,
      lastPoints,
      currentPoints,
      deltaPoints,
      type: eventType,
      ctrlKey: e.ctrlKey,
      metaKey: e.metaKey,
      shiftKey: e.shiftKey
    };

    $(eventData.element).trigger(eventType, eventData);

        // Update the last points
{'fraction_non_alphanumeric': 0.10758184252160156, 'fraction_numerical': 0.0017037848363149568, 'mean_word_length': 3.4517876489707477, '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': '4529546', 'n_tokens_mistral': 2491, 'n_tokens_neox': 2425, 'n_words': 536}