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.SUPERSCRIPT;
const superscript = createRicosMarkExtension({
  type: "mark",
  groups: [],
  name: Decoration_Type.SUPERSCRIPT,
  reconfigure(config, _extensions, _ricosProps, _settings, services) {
    return {
      ...config,
      addCommands() {
        return {
          setSuperscript: () => ({ commands }) => {
            return commands.setMark(this.name);
          },
          toggleSuperscript: () => ({ commands, state }) => {
            const decoration = getStylesDecorationBySelectedNode(name, {
              state,
              styles: services.styles,
              pmConverters: services.converters
            });
            const hasSuperscriptInStyle = decoration && decoration.superscriptData === true;
            const hasSuperscriptInMark = isMarkActive(state, this.name, {
              superscriptData: true
            });
            return commands.toggleMark(this.name, {
              superscriptData: !!(hasSuperscriptInMark || !hasSuperscriptInStyle)
            });
          },
          unsetSuperscript: () => ({ commands }) => {
            return commands.unsetMark(this.name);
          }
        };
      }
    };
  },
  createExtensionConfig: () => ({
    name,
    parseHTML: () => [
      { tag: "sup" },
      {
        style: "vertical-align",
        consuming: false,
        getAttrs: (style) => style.includes("super") ? {} : false
      }
    ],
    renderHTML: () => ["sup", 0],
    addOptions() {
      return {
        HTMLAttributes: {}
      };
    },
    addAttributes() {
      return {
        superscriptData: {
          default: true
        }
      };
    },
    addKeyboardShortcuts() {
      return {
        "Mod-Shift-.": () => {
          return this.editor.commands.toggleSuperscript();
        }
      };
    }
  })
});
export {
  superscript
};
//# sourceMappingURL=extension.js.map
