<commit_before>import mixins from '../mixins/index.js';

/**
 * The fundemental abstract class from which all other tools inherit.
 *
 * @typedef {Object} BaseTool
 * @property {String} activeStrategy Strategy name to use when a strategy needs to be applied
 * @property {String} defaultStrategy Strategy name to "reset" the activeStrategy to if default behavior is desired
 * @property {String} mode 1 of 4 modes that influence the tool's behavior
 * @property {String} name
 * @property {Object} strategies
 * @property {Array} supportedInteractionTypes
 */

/**
 * @export @interface @class
 * @name BaseTool
 * @type {BaseTool}
 * @classdesc The fundemental abstract class from which all other tools inherit.
 */
export default class BaseTool {
  constructor ({
    name,
    strategies,
    defaultStrategy,
    configuration,
    supportedInteractionTypes,
    mixins
  } = {}) {
    this.name = name;
    this.mode = 'disabled';
    this.element = undefined;
    this.supportedInteractionTypes = supportedInteractionTypes || [];

    // Todo: should this live in baseTool?
    this.strategies = strategies || {};
    this.defaultStrategy =
      defaultStrategy || Object.keys(this.strategies)[0] || undefined;
    this.activeStrategy = this.defaultStrategy;

    // Options are set when a tool is added, during a "mode" change,
    // Or via a tool's option's setter
    this._options = {};
    // Configuration is set at tool initalization
    this._configuration = Object.assign({}, configuration);

    // True if tool has a custom cursor, causes the frame to render on every mouse move when the tool is active.
    this.hasCursor = false;

    // Apply mixins if mixinsArray is not empty.
    if (mixins && mixins.length) {
      this._applyMixins(mixins);
    }
  }

  get configuration () {
    return this._configuration;
  }

  set configuration (configuration) {
    this._configuration = configuration;
  }

  // ToolOptions.js
  get options () {
    return this._options;
  }

  /**
   * Merges provided options with existing options
   *
   * @memberof BaseTool
   */
  mergeOptions (options) {
    this._options = Object.assign({}, this._options, options);
  }

  /**
   * Clears the tools options; preserves internal options, but
   * with `undefined` values.
   *
   * @memberof BaseTool
   */
  clearOptions () {
    this._options = {};
  }

  /**
   * Internal options that "MUST" be in the tool's options if
   * certain conditions are met. Method is also good for inspecting
   * options that can be used to change tool behavior.
   *
   * @readonly
   * @memberof BaseTool
   */


  /**
   *
   *
   * @param {*} evt
   * @returns {*}
   */
  applyActiveStrategy (evt) {
    return this.strategies[this.activeStrategy](evt, this.configuration);
  }

  /**
   * Applys the requested mixins to the class.
   *
   * @private
   * @method
   * @param {string[]} mixinsArray An array of mixin identifiers (strings).
   */
  _applyMixins (mixinsArray) {
    for (let i = 0; i < mixinsArray.length; i++) {
      const mixin = mixins[`${mixinsArray[i]}`];

      if (typeof mixin === 'object') {
        Object.assign(this, mixin);
      } else {
        console.warn(`${this.name}: mixin ${mixins[i]} does not exist.`);
      }
    }
  }

  // ===================================================================
  // Virtual Methods - Have default behavior but may be overriden.
  // ===================================================================

  /**
   * Callback that takes priority if the tool is active, before `MOUSE_DOWN`
   * events are processed. Does nothing by default.
   *
   * @virtual
   * @param  {type} evt
   * @returns {boolean} consumedEvent - True if function consumed the event.
   */
  /**
   * Example implementation:
   *
   * preMouseDownCallback(evt) {
   *    return false;
   * }
   */

  /**
   * Callback that is called if the tool is active, after `MOUSE_DOWN`
   * events are processed. Does nothing by default.
   *
   * @virtual
   * @param  {type} evt
   * @returns {boolean} consumedEvent - True if function consumed the event.
   */
  /**
   * Example implementation:
   *
   * postMouseDownCallback(evt) {
   *    return false;
   * }
   */

  /**
   * Callback that takes priority if the tool is active, before `TOUCH_START`
   * events are processed. Does nothing by default.
   *
   * @virtual
   * @param  {type} evt
   * @returns {boolean} consumedEvent - True if function consumed the event.
   */
  /**
   * Example implementation:
   *
   * preTouchStartCallback(evt) {
   *    return false;
   * }
   */

  /**
   * Callback that is called if the tool is active, after `TOUCH_START`
   * events are processed. Does nothing by default.
   *
   * @virtual
   * @param  {type} evt
   * @returns {boolean} consumedEvent - True if function consumed the event.
   */
  /**
   * Example implementation:
   *
   * postTouchStartCallback(evt) {
   *    return false;
   * }
   */
}
<commit_msg>First pass at cleaning up documentation for BaseTool<commit_after>import mixins from '../mixins/index.js';

/**
 *
 *
 * @export
 * @class BaseTool
 */

/**
 * @interface
 * @class BaseTool
 * @type {BaseTool}
 * @classdesc The fundemental abstract class from which all other tools inherit.
 * @property {String} activeStrategy The name of the strategy that should be used
 * @property {String} defaultStrategy The initial `activeStrategy` when the tool was initialized
 * @property {CornerstoneTools.ToolMode} mode 1 of 4 modes that influence the tool's behavior
 * @property {String} name A descriptive, unique tool name
 * @property {Object} strategies An object containing available tool strategies
 * @property {Array} supportedInteractionTypes
 */
export default class BaseTool {

  /**
   *Creates an instance of BaseTool.
   * @param {*} [{
   *     name,
   *     strategies,
   *     defaultStrategy,
   *     configuration,
   *     supportedInteractionTypes,
   *     mixins
   *   }={}]
   * @memberof BaseTool
   */
  constructor ({
    name,
    strategies,
    defaultStrategy,
    configuration,
    supportedInteractionTypes,
    mixins
  } = {}) {
    this.name = name;
    this.mode = 'disabled';
    this.element = undefined;
    this.supportedInteractionTypes = supportedInteractionTypes || [];

    this.strategies = strategies || {};
    this.defaultStrategy =
      defaultStrategy || Object.keys(this.strategies)[0] || undefined;
    this.activeStrategy = this.defaultStrategy;

    // Options are set when a tool is added, during a "mode" change,
    // Or via a tool's option's setter
    this._options = {};
    // Configuration is set at tool initalization
    this._configuration = Object.assign({}, configuration);

    // True if tool has a custom cursor, causes the frame to render on every mouse move when the tool is active.
    this.hasCursor = false;

    // Apply mixins if mixinsArray is not empty.
    if (mixins && mixins.length) {
      this._applyMixins(mixins);
    }
  }

  //
  // CONFIGURATION
  //

  /**
   *
   *
   * @memberof BaseTool
   */
  get configuration () {
    return this._configuration;
  }

  /**
   *
   *
   * @memberof BaseTool
   */
  set configuration (configuration) {
    this._configuration = configuration;
  }

  //
  // OPTIONS
  //

  /**
   * @readonly
   * @memberof BaseTool
   */
  get options () {
    return this._options;
  }

  /**
   * Merges provided options with existing options.
   *
   * @public
   * @memberof BaseTool
   * @param {Object} options - options object to merge with existing options.
   * @returns {undefined}
   */
  mergeOptions (options) {
    this._options = Object.assign({}, this._options, options);
  }

  /**
   * Clears the tools options.
   *
   * @public
   * @memberof BaseTool
   * @returns {undefined}
   */
  clearOptions () {
    this._options = {};
  }

  /**
   * Apply the currently set/active strategy.
   *
   * @public
   * @memberof BaseTool
   * @method applyActiveStrategy
   * @param {*} evt The event that triggered the strategies application
   * @returns {*} strategies vary widely; check each specific strategy to find expected return value
   */
  applyActiveStrategy (evt) {
    return this.strategies[this.activeStrategy](evt, this.configuration);
  }

  /**
   * Iterates over registered mixins; any matching names in the provided `mixinsArray` will
   * be merged with this instance.
   *
   * @private
   * @memberof BaseTool
   * @method _applyMixins
   * @param {string[]} mixinsArray An array of mixin identifiers (strings).
   * @returns {undefined}
   */
  _applyMixins (mixinsArray) {
    for (let i = 0; i < mixinsArray.length; i++) {
      const mixin = mixins[`${mixinsArray[i]}`];

      if (typeof mixin === 'object') {
        Object.assign(this, mixin);
      } else {
        console.warn(`${this.name}: mixin ${mixins[i]} does not exist.`);
      }
    }
  }

  // ===================================================================
  // Virtual Methods - Have default behavior but may be overriden.
  // ===================================================================

  /**
   * Callback that takes priority if the tool is active, before `MOUSE_DOWN`
   * events are processed. Does nothing by default.
   *
   * @virtual
   * @param  {type} evt
   * @returns {boolean} consumedEvent - True if function consumed the event.
   */
  /**
   * Example implementation:
   *
   * preMouseDownCallback(evt) {
   *    return false;
   * }
   */

  /**
   * Callback that is called if the tool is active, after `MOUSE_DOWN`
   * events are processed. Does nothing by default.
   *
   * @virtual
   * @param  {type} evt
   * @returns {boolean} consumedEvent - True if function consumed the event.
   */
  /**
   * Example implementation:
   *
   * postMouseDownCallback(evt) {
   *    return false;
   * }
   */

  /**
   * Callback that takes priority if the tool is active, before `TOUCH_START`
   * events are processed. Does nothing by default.
   *
   * @virtual
   * @param  {type} evt
   * @returns {boolean} consumedEvent - True if function consumed the event.
   */
  /**
   * Example implementation:
   *
   * preTouchStartCallback(evt) {
   *    return false;
   * }
   */

  /**
   * Callback that is called if the tool is active, after `TOUCH_START`
   * events are processed. Does nothing by default.
   *
   * @virtual
   * @param  {type} evt
   * @returns {boolean} consumedEvent - True if function consumed the event.
   */
  /**
   * Example implementation:
   *
   * postTouchStartCallback(evt) {
   *    return false;
   * }
   */
}

{'fraction_non_alphanumeric': 0.1363808442173008, 'fraction_numerical': 0.0007571455612341472, 'mean_word_length': 2.7524857954545454, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '194614', 'n_tokens_mistral': 3106, 'n_tokens_neox': 3061, 'n_words': 955}