# All files / src/utils getClientPosition.ts

100% Statements 47/47
83.33% Branches 5/6
100% Functions 1/1
100% Lines 47/47

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
    43
    44
    45
    46
    47
    481x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    56x
    56x
    56x
    56x
    54x
    54x
    2x
    2x
    56x
    56x
     /**
     * @internal
     * @remarks \@since 6.0.0
     */
    export interface ClientPositionMouseEvent {
      clientX: number;
      clientY: number;
    }

    /**
     * @internal
     * @remarks \@since 6.0.0
     */
    export interface ClientPositionTouchEvent {
      changedTouches: {
        [index: number]: ClientPositionMouseEvent;
      };
    }

    export type ClientPositionEvent =
      | ClientPositionMouseEvent
      | ClientPositionTouchEvent;

    /**
     * @internal
     * @remarks \@since 6.0.0
     */
    export interface ClientPositionOptions {
      event: ClientPositionEvent;
      vertical: boolean;
    }

    /**
     * @internal
     * @remarks \@since 6.0.0
     */
    export const getClientPosition = (options: ClientPositionOptions): number => {
      const { event, vertical } = options;

      const key = vertical ? "clientY" : "clientX";
      if ("clientX" in event) {
        return event[key];
      }

      // this should pretty much always be defined
      return event.changedTouches[0]?.[key] || 0;
    };