"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 reset_attributes_exports = {};
__export(reset_attributes_exports, {
  resetAttributes: () => resetAttributes
});
module.exports = __toCommonJS(reset_attributes_exports);
var import_get_mark_type = require("../helpers/get-mark-type.js");
var import_get_node_type = require("../helpers/get-node-type.js");
var import_get_schema_type_name_by_name = require("../helpers/get-schema-type-name-by-name.js");
var import_delete_props = require("../utilities/delete-props.js");
const resetAttributes = (typeOrName, attributes) => ({ tr, state, dispatch }) => {
  let nodeType = null;
  let markType = null;
  const schemaType = (0, import_get_schema_type_name_by_name.getSchemaTypeNameByName)(
    typeof typeOrName === "string" ? typeOrName : typeOrName.name,
    state.schema
  );
  if (!schemaType) {
    return false;
  }
  if (schemaType === "node") {
    nodeType = (0, import_get_node_type.getNodeType)(typeOrName, state.schema);
  }
  if (schemaType === "mark") {
    markType = (0, import_get_mark_type.getMarkType)(typeOrName, state.schema);
  }
  if (dispatch) {
    tr.selection.ranges.forEach((range) => {
      state.doc.nodesBetween(range.$from.pos, range.$to.pos, (node, pos) => {
        if (nodeType && nodeType === node.type) {
          tr.setNodeMarkup(pos, void 0, (0, import_delete_props.deleteProps)(node.attrs, attributes));
        }
        if (markType && node.marks.length) {
          node.marks.forEach((mark) => {
            if (markType === mark.type) {
              tr.addMark(
                pos,
                pos + node.nodeSize,
                markType.create((0, import_delete_props.deleteProps)(mark.attrs, attributes))
              );
            }
          });
        }
      });
    });
  }
  return true;
};
//# sourceMappingURL=reset-attributes.js.map
