"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 name2 in all)
    __defProp(target, name2, { get: all[name2], 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 extension_exports = {};
__export(extension_exports, {
  subscript: () => subscript
});
module.exports = __toCommonJS(extension_exports);
var import_v1 = require("./../../ricos-schema/legacy/wix/rich_content/v1/index.js");
var import_tiptap = require("./../../tiptap/index.js");
var import_plugin_commons = require("./../../plugin-commons/index.js");
var import_tiptap_extensions = require("./../../tiptap-extensions/index.js");
const name = import_v1.Decoration_Type.SUBSCRIPT;
const subscript = (0, import_plugin_commons.createRicosMarkExtension)({
  type: "mark",
  groups: [],
  name: import_v1.Decoration_Type.SUBSCRIPT,
  reconfigure(config, _extensions, _ricosProps, _settings, services) {
    return {
      ...config,
      addCommands() {
        return {
          setSubscript: () => ({ commands }) => {
            return commands.setMark(this.name);
          },
          toggleSubscript: () => ({ commands, state }) => {
            const decoration = (0, import_tiptap_extensions.getStylesDecorationBySelectedNode)(name, {
              state,
              styles: services.styles,
              pmConverters: services.converters
            });
            const hasSubscriptInStyle = decoration && decoration.subscriptData === true;
            const hasSubscriptInMark = (0, import_tiptap.isMarkActive)(state, this.name, {
              subscriptData: true
            });
            return commands.toggleMark(this.name, {
              subscriptData: !!(hasSubscriptInMark || !hasSubscriptInStyle)
            });
          },
          unsetSubscript: () => ({ commands }) => {
            return commands.unsetMark(this.name);
          }
        };
      }
    };
  },
  createExtensionConfig: () => ({
    name,
    parseHTML: () => [
      { tag: "sub" },
      {
        style: "vertical-align",
        consuming: false,
        getAttrs: (style) => style.includes("sub") ? {} : false
      }
    ],
    renderHTML: () => ["sub", 0],
    addOptions() {
      return {
        HTMLAttributes: {}
      };
    },
    addAttributes() {
      return {
        subscriptData: {
          default: true
        }
      };
    },
    addKeyboardShortcuts() {
      return {
        "Mod-Shift-,": () => {
          return this.editor.commands.toggleSubscript();
        }
      };
    }
  })
});
//# sourceMappingURL=extension.js.map
