import { Decoration_Type } from "./../ricos-schema/legacy/wix/rich_content/v1/index.js";
import { createRicosMarkExtension } from "./../plugin-commons/index.js";
import { FONT_FAMILY_MARK } from "./data-hooks.js";
import { withFallbackFontFamily } from "./with-fallback-font-family.js";
const tiptapFontFamilyExtension = (fallbackFontFamily) => createRicosMarkExtension({
  type: "mark",
  groups: [],
  name: Decoration_Type.FONT_FAMILY,
  createExtensionConfig({ mergeAttributes }) {
    return {
      name: this.name,
      addAttributes() {
        return { value: null };
      },
      renderHTML({ HTMLAttributes }) {
        const htmlAttrs = {
          style: `font-family: ${withFallbackFontFamily(HTMLAttributes.value, fallbackFontFamily)}`,
          "data-hook": FONT_FAMILY_MARK,
          "data-font-family": HTMLAttributes.value
        };
        return ["span", mergeAttributes(htmlAttrs), 0];
      },
      parseHTML() {
        return [
          {
            tag: "span",
            getAttrs: (element) => {
              const attribute = element.attributes.getNamedItem("data-font-family");
              if (!attribute?.value) {
                return false;
              }
              return {
                value: attribute.value
              };
            }
          }
        ];
      },
      addCommands() {
        return {
          setFontFamily: (fontFamily) => ({ commands }) => {
            if (!fontFamily) {
              return false;
            }
            return commands.setMark(this.name, {
              value: fontFamily
            });
          },
          unsetFontFamily: () => ({ commands }) => commands.unsetMark(this.name)
        };
      }
    };
  }
});
export {
  tiptapFontFamilyExtension
};
//# sourceMappingURL=tiptap-font-family.js.map
