"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var node_view_decorators_exports = {};
__export(node_view_decorators_exports, {
  Decorators: () => Decorators
});
module.exports = __toCommonJS(node_view_decorators_exports);
const _Decorators = class _Decorators {
  constructor(decorators, context) {
    this.decorators = [];
    this.textualDecorators = [];
    this.decorators = decorators.filter((decorator) => !decorator.isText).sort(_Decorators.sort).reverse();
    this.textualDecorators = decorators.filter((decorator) => decorator.isText);
    this.context = context;
  }
  // sort function must be aligned with Tiptap sort to ensure correct Editor and Viewer decorations order
  // https://github.com/ueberdosis/tiptap/blob/develop/packages/core/src/ExtensionManager.ts#L160
  static sort(a, b) {
    const priorityA = a.priority ?? _Decorators.defaultPriority;
    const priorityB = b.priority ?? _Decorators.defaultPriority;
    if (priorityA > priorityB) {
      return -1;
    }
    if (priorityA < priorityB) {
      return 1;
    }
    return 0;
  }
  static of(decorators, context) {
    return new _Decorators(decorators, context);
  }
  getDecorators() {
    return this.decorators;
  }
  merge(decorators) {
    return _Decorators.of([...this.decorators, ...decorators.getDecorators()], this.context);
  }
  apply(element, node, isRoot) {
    return this.decorators.reduce((decorated, decorator) => {
      if (decorator.rule(node)) {
        return decorator.decorate({ node, context: this.context, element: decorated, isRoot });
      }
      return decorated;
    }, element);
  }
  applyTextual(node) {
    const decorator = this.textualDecorators.find((decorator2) => decorator2.rule(node));
    return decorator?.decorate({ node, context: this.context, isRoot: false });
  }
};
_Decorators.defaultPriority = 100;
let Decorators = _Decorators;
//# sourceMappingURL=node-view-decorators.js.map
