import { Decoration_Type } from "./../../ricos-schema/legacy/wix/rich_content/v1/index.js";
import { isMarkActive } from "./../../tiptap/index.js";
import { createRicosMarkExtension } from "./../../plugin-commons/index.js";
import { getStylesDecorationBySelectedNode } from "./../../tiptap-extensions/index.js";
const name = Decoration_Type.SUBSCRIPT;
const subscript = createRicosMarkExtension({
  type: "mark",
  groups: [],
  name: 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 = getStylesDecorationBySelectedNode(name, {
              state,
              styles: services.styles,
              pmConverters: services.converters
            });
            const hasSubscriptInStyle = decoration && decoration.subscriptData === true;
            const hasSubscriptInMark = 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();
        }
      };
    }
  })
});
export {
  subscript
};
//# sourceMappingURL=extension.js.map
