// packages/block-editor/src/hooks/font-family.js
import { addFilter } from "@wordpress/hooks";
import { hasBlockSupport } from "@wordpress/blocks";
import TokenList from "@wordpress/token-list";
import { privateApis as componentsPrivateApis } from "@wordpress/components";
import { shouldSkipSerialization } from "./utils";
import { TYPOGRAPHY_SUPPORT_KEY } from "./typography";
import { unlock } from "../lock-unlock";
var FONT_FAMILY_SUPPORT_KEY = "typography.__experimentalFontFamily";
var { kebabCase } = unlock(componentsPrivateApis);
function addAttributes(settings) {
  if (!hasBlockSupport(settings, FONT_FAMILY_SUPPORT_KEY)) {
    return settings;
  }
  if (!settings.attributes.fontFamily) {
    Object.assign(settings.attributes, {
      fontFamily: {
        type: "string"
      }
    });
  }
  return settings;
}
function addSaveProps(props, blockType, attributes) {
  if (!hasBlockSupport(blockType, FONT_FAMILY_SUPPORT_KEY)) {
    return props;
  }
  if (shouldSkipSerialization(
    blockType,
    TYPOGRAPHY_SUPPORT_KEY,
    "fontFamily"
  )) {
    return props;
  }
  if (!attributes?.fontFamily) {
    return props;
  }
  const classes = new TokenList(props.className);
  classes.add(`has-${kebabCase(attributes?.fontFamily)}-font-family`);
  const newClassName = classes.value;
  props.className = newClassName ? newClassName : void 0;
  return props;
}
function useBlockProps({ name, fontFamily }) {
  return addSaveProps({}, name, { fontFamily });
}
var font_family_default = {
  useBlockProps,
  addSaveProps,
  attributeKeys: ["fontFamily"],
  hasSupport(name) {
    return hasBlockSupport(name, FONT_FAMILY_SUPPORT_KEY);
  }
};
function resetFontFamily({ setAttributes }) {
  setAttributes({ fontFamily: void 0 });
}
addFilter(
  "blocks.registerBlockType",
  "core/fontFamily/addAttribute",
  addAttributes
);
export {
  FONT_FAMILY_SUPPORT_KEY,
  font_family_default as default,
  resetFontFamily
};
//# sourceMappingURL=font-family.js.map
