All files / packages/tools/src/eventDispatchers cameraResetEventDispatcher.ts

90% Statements 9/10
50% Branches 1/2
100% Functions 4/4
90% Lines 9/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42        1x                   1x   76x           76x 80x           1x 128x     1x 11x              
import { Enums, Types } from '@cornerstonejs/core';
import { ToolModes } from '../enums';
import getToolsWithModesForMouseEvent from './shared/getToolsWithModesForMouseEvent';
 
const { Active, Passive, Enabled } = ToolModes;
 
/**
 * When the camera is reset, check what tools need to react to this.
 *
 * - First we get all tools which are active, passive or enabled on the element.
 * - If any of these tools have a `onCameraReset` method, we call it.
 *
 * @param evt - The normalized camera reset event.
 */
const onCameraReset = function (evt: Types.EventTypes.CameraResetEvent) {
  // @ts-ignore
  const enabledTools = getToolsWithModesForMouseEvent(evt, [
    Active,
    Passive,
    Enabled,
  ]);
 
  enabledTools.forEach((tool) => {
    Iif (tool.onResetCamera) {
      tool.onResetCamera(evt);
    }
  });
};
 
const enable = function (element) {
  element.addEventListener(Enums.Events.CAMERA_RESET, onCameraReset);
};
 
const disable = function (element) {
  element.removeEventListener(Enums.Events.CAMERA_RESET, onCameraReset);
};
 
export default {
  enable,
  disable,
};