"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 mark_exports = {};
__export(mark_exports, {
  Mark: () => Mark
});
module.exports = __toCommonJS(mark_exports);
var import_get_extension_field = require("./helpers/get-extension-field.js");
var import_call_or_return = require("./utilities/call-or-return.js");
var import_merge_deep = require("./utilities/merge-deep.js");
class Mark {
  // Accept any config shape for compatibility with @tiptap/core's MarkConfig
  constructor(config = {}) {
    this.type = "mark";
    this.name = "mark";
    this.parent = null;
    this.child = null;
    this.config = {
      name: this.name,
      defaultOptions: {}
    };
    this.config = {
      ...this.config,
      ...config
    };
    this.name = this.config.name;
    if (config.defaultOptions && Object.keys(config.defaultOptions).length > 0) {
      console.warn(
        `[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`
      );
    }
    this.options = this.config.defaultOptions;
    if (this.config.addOptions) {
      this.options = (0, import_call_or_return.callOrReturn)(
        (0, import_get_extension_field.getExtensionField)(this, "addOptions", {
          name: this.name
        })
      );
    }
    this.storage = (0, import_call_or_return.callOrReturn)(
      (0, import_get_extension_field.getExtensionField)(this, "addStorage", {
        name: this.name,
        options: this.options
      })
    ) || {};
  }
  static create(config = {}) {
    return new Mark(config);
  }
  configure(options = {}) {
    const extension = this.extend({
      ...this.config,
      addOptions: () => {
        return (0, import_merge_deep.mergeDeep)(
          this.options,
          options
        );
      }
    });
    extension.name = this.name;
    extension.parent = this.parent;
    return extension;
  }
  extend(extendedConfig = {}) {
    const extension = new Mark(extendedConfig);
    extension.parent = this;
    this.child = extension;
    extension.name = extendedConfig.name ? extendedConfig.name : this.name;
    if (extendedConfig.defaultOptions && Object.keys(extendedConfig.defaultOptions).length > 0) {
      console.warn(
        `[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${extension.name}".`
      );
    }
    extension.options = (0, import_call_or_return.callOrReturn)(
      (0, import_get_extension_field.getExtensionField)(extension, "addOptions", {
        name: extension.name
      })
    );
    extension.storage = (0, import_call_or_return.callOrReturn)(
      (0, import_get_extension_field.getExtensionField)(extension, "addStorage", {
        name: extension.name,
        options: extension.options
      })
    );
    return extension;
  }
  static handleExit({ editor, mark }) {
    const { tr } = editor.state;
    const currentPos = editor.state.selection.$from;
    const isAtEnd = currentPos.pos === currentPos.end();
    if (isAtEnd) {
      const currentMarks = currentPos.marks();
      const isInMark = !!currentMarks.find((m) => m?.type.name === mark.name);
      if (!isInMark) {
        return false;
      }
      const removeMark = currentMarks.find((m) => m?.type.name === mark.name);
      if (removeMark) {
        tr.removeStoredMark(removeMark);
      }
      tr.insertText(" ", currentPos.pos);
      editor.view.dispatch(tr);
      return true;
    }
    return false;
  }
}
//# sourceMappingURL=mark.js.map
