All files / packages/tools/src/cursors ImageMouseCursor.ts

92.85% Statements 13/14
58.33% Branches 7/12
66.66% Functions 2/3
91.66% Lines 11/12

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      1x                         40x 8x       8x 8x 8x       152x 152x 152x 152x   152x              
import { utilities } from '@cornerstonejs/core';
import MouseCursor from './MouseCursor';
 
const DEFAULT_NAME = 'image-cursor';
 
export default class ImageMouseCursor extends MouseCursor {
  private url: string;
  private x: number;
  private y: number;
 
  constructor(
    url: string,
    x?: number,
    y?: number,
    name?: string | undefined,
    fallback?: MouseCursor | undefined
  ) {
    super(
      name || ImageMouseCursor.getUniqueInstanceName(DEFAULT_NAME),
      fallback
    );
    this.url = url;
    this.x = Number(x) || 0;
    this.y = Number(y) || 0;
  }
 
  getStyleProperty(): string {
    const { url, x, y } = this;
    let style = `url('${url}')`;
    Eif (x >= 0 && y >= 0 && (x > 0 || y > 0)) {
      style += ` ${x} ${y}`;
    }
    return this.addFallbackStyleProperty(style);
  }
 
  static getUniqueInstanceName(prefix: string): string {
    return `${prefix}-${utilities.getRuntimeId(ImageMouseCursor)}`;
  }
}