"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 tiptap_font_family_exports = {};
__export(tiptap_font_family_exports, {
  tiptapFontFamilyExtension: () => tiptapFontFamilyExtension
});
module.exports = __toCommonJS(tiptap_font_family_exports);
var import_v1 = require("./../ricos-schema/legacy/wix/rich_content/v1/index.js");
var import_plugin_commons = require("./../plugin-commons/index.js");
var import_data_hooks = require("./data-hooks.js");
var import_with_fallback_font_family = require("./with-fallback-font-family.js");
const tiptapFontFamilyExtension = (fallbackFontFamily) => (0, import_plugin_commons.createRicosMarkExtension)({
  type: "mark",
  groups: [],
  name: import_v1.Decoration_Type.FONT_FAMILY,
  createExtensionConfig({ mergeAttributes }) {
    return {
      name: this.name,
      addAttributes() {
        return { value: null };
      },
      renderHTML({ HTMLAttributes }) {
        const htmlAttrs = {
          style: `font-family: ${(0, import_with_fallback_font_family.withFallbackFontFamily)(HTMLAttributes.value, fallbackFontFamily)}`,
          "data-hook": import_data_hooks.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)
        };
      }
    };
  }
});
//# sourceMappingURL=tiptap-font-family.js.map
