function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
var _Symbol$iterator;
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
import "core-js/modules/es.array.iterator.js";
import "core-js/modules/es.map.js";
import "core-js/modules/es.object.to-string.js";
import "core-js/modules/es.string.iterator.js";
import "core-js/modules/web.dom-collections.iterator.js";
import "core-js/modules/es.array.fill.js";
import "core-js/modules/es.array.includes.js";
import "core-js/modules/es.string.includes.js";
import "core-js/modules/es.array.concat.js";
import "core-js/modules/es.symbol.iterator.js";
import "core-js/modules/es.symbol.js";
import "core-js/modules/es.symbol.description.js";
import "core-js/modules/es.weak-set.js";
import "core-js/modules/es.symbol.to-primitive.js";
import "core-js/modules/es.date.to-primitive.js";
import "core-js/modules/es.number.constructor.js";
import "core-js/modules/es.array.from.js";
import "core-js/modules/es.array.slice.js";
import "core-js/modules/es.regexp.to-string.js";
import "core-js/modules/es.function.name.js";
import "core-js/modules/es.regexp.exec.js";
import "core-js/modules/es.object.keys.js";
import "core-js/modules/es.array.filter.js";
import "core-js/modules/es.object.get-own-property-descriptor.js";
import "core-js/modules/web.dom-collections.for-each.js";
import "core-js/modules/es.object.get-own-property-descriptors.js";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
import { createHighlight as createActiveHighlight } from "./types/activeHeader.mjs";
import { createHighlight as createAreaLayeredHighlight } from "./types/areaLayered.mjs";
import { createHighlight as createAreaHighlight } from "./types/area.mjs";
import { createHighlight as _createColumnHighlight } from "./types/column.mjs";
import { createHighlight as createFocusHighlight } from "./types/focus.mjs";
import { createHighlight as createCustomHighlight } from "./types/customSelection.mjs";
import { createHighlight as createFillHighlight } from "./types/fill.mjs";
import { createHighlight as createHeaderHighlight } from "./types/header.mjs";
import { createHighlight as _createRowHighlight } from "./types/row.mjs";
import { HIGHLIGHT_ACTIVE_HEADER_TYPE, HIGHLIGHT_AREA_TYPE, HIGHLIGHT_FOCUS_TYPE, HIGHLIGHT_CUSTOM_SELECTION_TYPE, HIGHLIGHT_FILL_TYPE, HIGHLIGHT_HEADER_TYPE, HIGHLIGHT_ROW_TYPE, HIGHLIGHT_COLUMN_TYPE } from "../../3rdparty/walkontable/src/index.mjs";
import { arrayEach } from "./../../helpers/array.mjs";
export { HIGHLIGHT_ACTIVE_HEADER_TYPE as ACTIVE_HEADER_TYPE, HIGHLIGHT_AREA_TYPE as AREA_TYPE, HIGHLIGHT_FOCUS_TYPE as FOCUS_TYPE, HIGHLIGHT_CUSTOM_SELECTION_TYPE as CUSTOM_SELECTION_TYPE, HIGHLIGHT_FILL_TYPE as FILL_TYPE, HIGHLIGHT_HEADER_TYPE as HEADER_TYPE, HIGHLIGHT_ROW_TYPE as ROW_TYPE, HIGHLIGHT_COLUMN_TYPE as COLUMN_TYPE };

/**
 * Highlight class responsible for managing Walkontable Selection classes.
 *
 * With Highlight object you can manipulate four different highlight types:
 *  - `cell` can be added only to a single cell at a time and it defines currently selected cell;
 *  - `fill` can occur only once and its highlight defines selection of autofill functionality (managed by the plugin with the same name);
 *  - `areas` can be added to multiple cells at a time. This type highlights selected cell or multiple cells.
 *    The multiple cells have to be defined as an uninterrupted order (regular shape). Otherwise, the new layer of
 *    that type should be created to manage not-consecutive selection;
 *  - `header` can occur multiple times. This type is designed to highlight only headers. Like `area` type it
 *    can appear with multiple highlights (accessed under different level layers).
 *
 * @class Highlight
 * @util
 */
var _createHighlight = /*#__PURE__*/new WeakSet();
_Symbol$iterator = Symbol.iterator;
var Highlight = /*#__PURE__*/function () {
  function Highlight(options) {
    _classCallCheck(this, Highlight);
    /**
     * Creates (if not exist in the cache) Walkontable Selection instance.
     *
     * @param {Map} cacheMap The map where the instance will be cached.
     * @param {Function} highlightFactory The function factory.
     * @returns {VisualSelection}
     */
    _classPrivateMethodInitSpec(this, _createHighlight);
    /**
     * Options consumed by Highlight class and Walkontable Selection classes.
     *
     * @type {object}
     */
    _defineProperty(this, "options", void 0);
    /**
     * The property which describes which layer level of the visual selection will be modified.
     * This option is valid only for `area` and `header` highlight types which occurs multiple times on
     * the table (as a non-consecutive selection).
     *
     * An order of the layers is the same as the order of added new non-consecutive selections.
     *
     * @type {number}
     * @default 0
     */
    _defineProperty(this, "layerLevel", 0);
    /**
     * `cell` highlight object which describes attributes for the currently selected cell.
     * It can only occur only once on the table.
     *
     * @type {Selection}
     */
    _defineProperty(this, "focus", void 0);
    /**
     * `fill` highlight object which describes attributes for the borders for autofill functionality.
     * It can only occur only once on the table.
     *
     * @type {Selection}
     */
    _defineProperty(this, "fill", void 0);
    /**
     * Collection of the `area` highlights. That objects describes attributes for the borders and selection of
     * the multiple selected cells. It can occur multiple times on the table.
     *
     * @type {Map.<number, Selection>}
     */
    _defineProperty(this, "layeredAreas", new Map());
    /**
     * Collection of the `highlight` highlights. That objects describes attributes for the borders and selection of
     * the multiple selected cells. It can occur multiple times on the table.
     *
     * @type {Map.<number, Selection>}
     */
    _defineProperty(this, "areas", new Map());
    /**
     * Collection of the `header` highlights. That objects describes attributes for the selection of
     * the multiple selected rows in the table header. It can occur multiple times on the table.
     *
     * @type {Map.<number, Selection>}
     */
    _defineProperty(this, "rowHeaders", new Map());
    /**
     * Collection of the `header` highlights. That objects describes attributes for the selection of
     * the multiple selected columns in the table header. It can occur multiple times on the table.
     *
     * @type {Map.<number, Selection>}
     */
    _defineProperty(this, "columnHeaders", new Map());
    /**
     * Collection of the `active-header` highlights. That objects describes attributes for the selection of
     * the multiple selected rows in the table header. The table headers which have selected all items in
     * a row will be marked as `active-header`.
     *
     * @type {Map.<number, Selection>}
     */
    _defineProperty(this, "activeRowHeaders", new Map());
    /**
     * Collection of the `active-header` highlights. That objects describes attributes for the selection of
     * the multiple selected columns in the table header. The table headers which have selected all items in
     * a row will be marked as `active-header`.
     *
     * @type {Map.<number, Selection>}
     */
    _defineProperty(this, "activeColumnHeaders", new Map());
    /**
     * Collection of the `active-header` highlights. That objects describes attributes for the selection of
     * the selected corner in the table header. The table headers which have selected all items in
     * a row will be marked as `active-header`.
     *
     * @type {Map.<number, Selection>}
     */
    _defineProperty(this, "activeCornerHeaders", new Map());
    /**
     * Collection of the `rows` highlights. That objects describes attributes for the selection of
     * the multiple selected cells in a row. It can occur multiple times on the table.
     *
     * @type {Map.<number, Selection>}
     */
    _defineProperty(this, "rowHighlights", new Map());
    /**
     * Collection of the `columns` highlights. That objects describes attributes for the selection of
     * the multiple selected cells in a column. It can occur multiple times on the table.
     *
     * @type {Map.<number, Selection>}
     */
    _defineProperty(this, "columnHighlights", new Map());
    /**
     * Collection of the `custom-selection`, holder for example borders added through CustomBorders plugin.
     *
     * @type {Selection[]}
     */
    _defineProperty(this, "customSelections", []);
    this.options = options;
    this.focus = createFocusHighlight(options);
    this.fill = createFillHighlight(options);
  }

  /**
   * Check if highlight cell rendering is disabled for specified highlight type.
   *
   * @param {string} highlightType Highlight type. Possible values are: `cell`, `area`, `fill` or `header`.
   * @param {CellCoords} coords The CellCoords instance with defined visual coordinates.
   * @returns {boolean}
   */
  _createClass(Highlight, [{
    key: "isEnabledFor",
    value: function isEnabledFor(highlightType, coords) {
      var type = highlightType;

      // Legacy compatibility.
      if (highlightType === HIGHLIGHT_FOCUS_TYPE) {
        type = 'current'; // One from settings for `disableVisualSelection` up to Handsontable 0.36/Handsontable Pro 1.16.0.
      }

      var disableHighlight = false;
      if (coords.isCell()) {
        disableHighlight = this.options.disabledCellSelection(coords.row, coords.col);
      }
      if (typeof disableHighlight === 'string') {
        disableHighlight = [disableHighlight];
      }
      return disableHighlight === false || Array.isArray(disableHighlight) && !disableHighlight.includes(type);
    }

    /**
     * Set a new layer level to make access to the desire `area` and `header` highlights.
     *
     * @param {number} [level=0] Layer level to use.
     * @returns {Highlight}
     */
  }, {
    key: "useLayerLevel",
    value: function useLayerLevel() {
      var level = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
      this.layerLevel = level;
      return this;
    }

    /**
     * Get Walkontable Selection instance created for controlling highlight of the currently
     * focused cell (or header).
     *
     * @returns {Selection}
     */
  }, {
    key: "getFocus",
    value: function getFocus() {
      return this.focus;
    }

    /**
     * Get Walkontable Selection instance created for controlling highlight of the autofill functionality.
     *
     * @returns {Selection}
     */
  }, {
    key: "getFill",
    value: function getFill() {
      return this.fill;
    }

    /**
     * Creates (if not exist in the cache) Walkontable Selection instance created for controlling
     * `area` highlights.
     *
     * @returns {Selection}
     */
  }, {
    key: "createLayeredArea",
    value: function createLayeredArea() {
      return _classPrivateMethodGet(this, _createHighlight, _createHighlight2).call(this, this.layeredAreas, createAreaLayeredHighlight);
    }

    /**
     * Get all Walkontable Selection instances which describes the state of the visual highlight of the cells.
     *
     * @returns {Selection[]}
     */
  }, {
    key: "getLayeredAreas",
    value: function getLayeredAreas() {
      return _toConsumableArray(this.layeredAreas.values());
    }

    /**
     * Creates (if not exist in the cache) Walkontable Selection instance created for controlling
     * `highlight` highlights.
     *
     * @returns {Selection}
     */
  }, {
    key: "createArea",
    value: function createArea() {
      return _classPrivateMethodGet(this, _createHighlight, _createHighlight2).call(this, this.areas, createAreaHighlight);
    }

    /**
     * Get all Walkontable Selection instances which describes the state of the visual highlight of the cells.
     *
     * @returns {Selection[]}
     */
  }, {
    key: "getAreas",
    value: function getAreas() {
      return _toConsumableArray(this.areas.values());
    }

    /**
     * Creates (if not exist in the cache) Walkontable Selection instance created for controlling
     * header highlight for rows.
     *
     * @returns {Selection}
     */
  }, {
    key: "createRowHeader",
    value: function createRowHeader() {
      return _classPrivateMethodGet(this, _createHighlight, _createHighlight2).call(this, this.rowHeaders, createHeaderHighlight);
    }

    /**
     * Get all Walkontable Selection instances which describes the state of the visual highlight of the headers.
     *
     * @returns {Selection[]}
     */
  }, {
    key: "getRowHeaders",
    value: function getRowHeaders() {
      return _toConsumableArray(this.rowHeaders.values());
    }

    /**
     * Creates (if not exist in the cache) Walkontable Selection instance created for controlling
     * header highlight for columns.
     *
     * @returns {Selection}
     */
  }, {
    key: "createColumnHeader",
    value: function createColumnHeader() {
      return _classPrivateMethodGet(this, _createHighlight, _createHighlight2).call(this, this.columnHeaders, createHeaderHighlight);
    }

    /**
     * Get all Walkontable Selection instances which describes the state of the visual highlight of the headers.
     *
     * @returns {Selection[]}
     */
  }, {
    key: "getColumnHeaders",
    value: function getColumnHeaders() {
      return _toConsumableArray(this.columnHeaders.values());
    }

    /**
     * Creates (if not exist in the cache) Walkontable Selection instance created for controlling
     * highlight for active row headers.
     *
     * @returns {Selection}
     */
  }, {
    key: "createActiveRowHeader",
    value: function createActiveRowHeader() {
      return _classPrivateMethodGet(this, _createHighlight, _createHighlight2).call(this, this.activeRowHeaders, createActiveHighlight);
    }

    /**
     * Get all Walkontable Selection instances which describes the state of the visual highlight of the active headers.
     *
     * @returns {Selection[]}
     */
  }, {
    key: "getActiveRowHeaders",
    value: function getActiveRowHeaders() {
      return _toConsumableArray(this.activeRowHeaders.values());
    }

    /**
     * Creates (if not exist in the cache) Walkontable Selection instance created for controlling
     * highlight for active column headers.
     *
     * @returns {Selection}
     */
  }, {
    key: "createActiveColumnHeader",
    value: function createActiveColumnHeader() {
      return _classPrivateMethodGet(this, _createHighlight, _createHighlight2).call(this, this.activeColumnHeaders, createActiveHighlight);
    }

    /**
     * Get all Walkontable Selection instances which describes the state of the visual highlight of the active headers.
     *
     * @returns {Selection[]}
     */
  }, {
    key: "getActiveColumnHeaders",
    value: function getActiveColumnHeaders() {
      return _toConsumableArray(this.activeColumnHeaders.values());
    }

    /**
     * Creates (if not exist in the cache) Walkontable Selection instance created for controlling
     * highlight for the headers corner.
     *
     * @returns {Selection}
     */
  }, {
    key: "createActiveCornerHeader",
    value: function createActiveCornerHeader() {
      return _classPrivateMethodGet(this, _createHighlight, _createHighlight2).call(this, this.activeCornerHeaders, createActiveHighlight);
    }

    /**
     * Get all Walkontable Selection instances which describes the state of the visual highlight of the headers corner.
     *
     * @returns {Selection[]}
     */
  }, {
    key: "getActiveCornerHeaders",
    value: function getActiveCornerHeaders() {
      return _toConsumableArray(this.activeCornerHeaders.values());
    }

    /**
     * Creates (if not exist in the cache) Walkontable Selection instance created for controlling
     * highlight cells in a row.
     *
     * @returns {Selection}
     */
  }, {
    key: "createRowHighlight",
    value: function createRowHighlight() {
      return _classPrivateMethodGet(this, _createHighlight, _createHighlight2).call(this, this.rowHighlights, _createRowHighlight);
    }

    /**
     * Get all Walkontable Selection instances which describes the state of the rows highlighting.
     *
     * @returns {Selection[]}
     */
  }, {
    key: "getRowHighlights",
    value: function getRowHighlights() {
      return _toConsumableArray(this.rowHighlights.values());
    }

    /**
     * Creates (if not exist in the cache) Walkontable Selection instance created for controlling
     * highlight cells in a column.
     *
     * @returns {Selection}
     */
  }, {
    key: "createColumnHighlight",
    value: function createColumnHighlight() {
      return _classPrivateMethodGet(this, _createHighlight, _createHighlight2).call(this, this.columnHighlights, _createColumnHighlight);
    }

    /**
     * Get all Walkontable Selection instances which describes the state of the columns highlighting.
     *
     * @returns {Selection[]}
     */
  }, {
    key: "getColumnHighlights",
    value: function getColumnHighlights() {
      return _toConsumableArray(this.columnHighlights.values());
    }

    /**
     * Get Walkontable Selection instance created for controlling highlight of the custom selection functionality.
     *
     * @returns {Selection}
     */
  }, {
    key: "getCustomSelections",
    value: function getCustomSelections() {
      return _toConsumableArray(this.customSelections.values());
    }

    /**
     * Add selection to the custom selection instance. The new selection are added to the end of the selection collection.
     *
     * @param {object} selectionInstance The selection instance.
     */
  }, {
    key: "addCustomSelection",
    value: function addCustomSelection(selectionInstance) {
      this.customSelections.push(createCustomHighlight(_objectSpread(_objectSpread({}, this.options), selectionInstance)));
    }

    /**
     * Perform cleaning visual highlights for the whole table.
     */
  }, {
    key: "clear",
    value: function clear() {
      this.focus.clear();
      this.fill.clear();
      arrayEach(this.areas.values(), function (highlight) {
        return void highlight.clear();
      });
      arrayEach(this.layeredAreas.values(), function (highlight) {
        return void highlight.clear();
      });
      arrayEach(this.rowHeaders.values(), function (highlight) {
        return void highlight.clear();
      });
      arrayEach(this.columnHeaders.values(), function (highlight) {
        return void highlight.clear();
      });
      arrayEach(this.activeRowHeaders.values(), function (highlight) {
        return void highlight.clear();
      });
      arrayEach(this.activeColumnHeaders.values(), function (highlight) {
        return void highlight.clear();
      });
      arrayEach(this.activeCornerHeaders.values(), function (highlight) {
        return void highlight.clear();
      });
      arrayEach(this.rowHighlights.values(), function (highlight) {
        return void highlight.clear();
      });
      arrayEach(this.columnHighlights.values(), function (highlight) {
        return void highlight.clear();
      });
    }
  }, {
    key: _Symbol$iterator,
    value:
    /**
     * This object can be iterate over using `for of` syntax or using internal `arrayEach` helper.
     *
     * @returns {Selection[]}
     */
    function value() {
      return [this.focus, this.fill].concat(_toConsumableArray(this.areas.values()), _toConsumableArray(this.layeredAreas.values()), _toConsumableArray(this.rowHeaders.values()), _toConsumableArray(this.columnHeaders.values()), _toConsumableArray(this.activeRowHeaders.values()), _toConsumableArray(this.activeColumnHeaders.values()), _toConsumableArray(this.activeCornerHeaders.values()), _toConsumableArray(this.rowHighlights.values()), _toConsumableArray(this.columnHighlights.values()), _toConsumableArray(this.customSelections))[Symbol.iterator]();
    }
  }]);
  return Highlight;
}();
function _createHighlight2(cacheMap, highlightFactory) {
  var layerLevel = this.layerLevel;
  if (cacheMap.has(layerLevel)) {
    return cacheMap.get(layerLevel);
  }
  var highlight = highlightFactory(_objectSpread({
    layerLevel: layerLevel
  }, this.options));
  cacheMap.set(layerLevel, highlight);
  return highlight;
}
export default Highlight;