All files / lib/event Event.ts

51.51% Statements 17/33
100% Branches 0/0
0% Functions 0/6
51.51% Lines 17/33

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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93                              1x 1x 1x                 1x 1x 1x   1x         1x 1x           1x               1x                         1x                     1x                     1x     1x 1x   1x  
/*
 * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
 * http://paperjs.org/
 *
 * Copyright (c) 2011 - 2020, Jürg Lehni & Jonathan Puckey
 * http://juerglehni.com/ & https://puckey.studio/
 *
 * Distributed under the MIT license. See LICENSE file for details.
 *
 * All rights reserved.
 */
 
// TODO: remove eslint-disable comment and deal with errors over time
/* eslint-disable */
 
import { ref } from '~/globals';
import { Base } from '~/straps';
import { Key } from './Key';
 
/**
 * @name Event
 *
 * @class The Event object is the base class for any of the other event types,
 * such as {@link MouseEvent}, {@link ToolEvent} and {@link KeyEvent}.
 */
/* global Event: true */
export const Event = Base.extend(
  /** @lends Event# */ {
    _class: 'Event',
 
    initialize: function Event(event) {
      this.event = event;
      this.type = event && event.type;
    },
 
    prevented: false,
    stopped: false,
 
    /**
     * Cancels the event if it is cancelable, without stopping further
     * propagation of the event.
     */
    preventDefault: function () {
      this.prevented = true;
      this.event.preventDefault();
    },
 
    /**
     * Prevents further propagation of the current event.
     */
    stopPropagation: function () {
      this.stopped = true;
      this.event.stopPropagation();
    },
 
    /**
     * Cancels the event if it is cancelable, and stops stopping further
     * propagation of the event. This is has the same effect as calling both
     * {@link #stopPropagation()} and {@link #preventDefault()}.
     *
     * Any handler can also return `false` to indicate that `stop()` should be
     * called right after.
     */
    stop: function () {
      this.stopPropagation();
      this.preventDefault();
    },
 
    /**
     * The time at which the event was created, in milliseconds since the epoch.
     *
     * @bean
     * @type Number
     */
    getTimeStamp: function () {
      return this.event.timeStamp;
    },
 
    /**
     * The current state of the keyboard modifiers.
     *
     * @bean
     * @type object
     * @see Key.modifiers
     */
    getModifiers: function () {
      return Key.modifiers;
    },
  }
);
 
ref.Event = Event;