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

100% Statements 12/12
100% Branches 2/2
100% Functions 4/4
100% Lines 10/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   318x           318x 366x 4x         1x 96x     1x 4x              
import { Enums, Types } from '@cornerstonejs/core';
import { ToolModes } from '../enums';
import getToolsWithModesForMouseEvent from './shared/getToolsWithModesForMouseEvent';
 
const { Active, Passive, Enabled } = ToolModes;
 
/**
 * When the camera is modified, 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 `onCameraModified` method, we call it.
 *
 * @param evt - The normalized camera modified event.
 */
const onCameraModified = function (evt: Types.EventTypes.CameraModifiedEvent) {
  // @ts-ignore
  const enabledTools = getToolsWithModesForMouseEvent(evt, [
    Active,
    Passive,
    Enabled,
  ]);
 
  enabledTools.forEach((tool) => {
    if (tool.onCameraModified) {
      tool.onCameraModified(evt);
    }
  });
};
 
const enable = function (element) {
  element.addEventListener(Enums.Events.CAMERA_MODIFIED, onCameraModified);
};
 
const disable = function (element) {
  element.removeEventListener(Enums.Events.CAMERA_MODIFIED, onCameraModified);
};
 
export default {
  enable,
  disable,
};