Repository: mozilla/pdf.js
File: src/display/editor/draw.js (JavaScript)

Code before:
  }

  /**
   * Create a new drawer instance.
   * @param {number} x - The x coordinate of the event.
   * @param {number} y - The y coordinate of the event.
   * @param {number} parentWidth - The parent width.
   * @param {number} parentHeight - The parent height.
   * @param {number} rotation - The parent rotation.
   */
  static createDrawerInstance(_x, _y, _parentWidth, _parentHeight, _rotation) {
    unreachable("Not implemented");
  }

  static startDrawing(parent, uiManager, _isLTR, event) {
    // The _currentPointerType is set when the user starts an empty drawing
    // session. If, in the same drawing session, the user starts using a
    // different type of pointer (e.g. a pen and then a finger), we just return.
    //
    // The _currentPointerId  and _currentPointerIds are used to keep track of
    // the pointers with a same type (e.g. two fingers). If the user starts to
    // draw with a finger and then uses a second finger, we just stop the
    // current drawing and let the user zoom the document.

    const { target, offsetX: x, offsetY: y, pointerId, pointerType } = event;
    if (CurrentPointer.isInitializedAndDifferentPointerType(pointerType)) {
      return;
    }

    const {
      viewport: { rotation },
    } = parent;
    const { width: parentWidth, height: parentHeight } =
      target.getBoundingClientRect();

    const ac = (DrawingEditor.#currentDrawingAC = new AbortController());
    const signal = parent.combinedSignal(ac);

    CurrentPointer.setPointer(pointerType, pointerId);

    window.addEventListener(
      "pointerup",
      e => {
        if (CurrentPointer.isSamePointerId(e.pointerId)) {
          this._endDraw(e);
        }
      },
      { signal }
    );
    window.addEventListener(
      "pointercancel",

Review comment (suggestion):
The comment above should be updated: the variable `currentPointerType` isn't defined in this file.
Probably a part of it should be moved in the new class you created.

Code after:
      this._moveAfterPaste(baseX, baseY);
    }

    return div;
  }

  /**
   * Create a new drawer instance.
   * @param {number} x - The x coordinate of the event.
   * @param {number} y - The y coordinate of the event.
   * @param {number} parentWidth - The parent width.
   * @param {number} parentHeight - The parent height.
   * @param {number} rotation - The parent rotation.
   */
  static createDrawerInstance(_x, _y, _parentWidth, _parentHeight, _rotation) {
    unreachable("Not implemented");
  }

  static startDrawing(parent, uiManager, _isLTR, event) {
    // The pointerType of CurrentPointer is set when the user starts an empty
    // drawing session. If, in the same drawing session, the user starts using a
    // different type of pointer (e.g. a pen and then a finger), we just return.
    //
    // If the user starts to draw with a finger and then uses a second finger,
    // we just stop the current drawing and let the user zoom the document.

    const { target, offsetX: x, offsetY: y, pointerId, pointerType } = event;
    if (CurrentPointers.isInitializedAndDifferentPointerType(pointerType)) {
      return;
    }

    const {
      viewport: { rotation },
    } = parent;
    const { width: parentWidth, height: parentHeight } =
      target.getBoundingClientRect();

    const ac = (DrawingEditor.#currentDrawingAC = new AbortController());
    const signal = parent.combinedSignal(ac);

    CurrentPointers.setPointer(pointerType, pointerId);

    window.addEventListener(
      "pointerup",
      e => {
        if (CurrentPointers.isSamePointerIdOrRemove(e.pointerId)) {
          this._endDraw(e);
        }
      },
      { signal }
    );