"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var font_size_exports = {};
__export(font_size_exports, {
  DEFAULT_FONTSIZE_DROPDOWN_OPTIONS: () => DEFAULT_FONTSIZE_DROPDOWN_OPTIONS,
  pluginFontSize: () => pluginFontSize
});
module.exports = __toCommonJS(font_size_exports);
var import_react = __toESM(require("react"));
var import_ricos_content = require("./../../ricos-content/index.js");
var import_v1 = require("./../../ricos-schema/legacy/wix/rich_content/v1/index.js");
var import_ricos_types = require("./../../ricos-types/index.js");
var import_create_text_button = require("./../../_shared/create-text-button.js");
var import_get_font_size_in_selection = require("./../../_shared/resolvers/get-font-size-in-selection.js");
var import_is_always_visible = require("./../../_shared/resolvers/is-always-visible.js");
var import_is_node_selected = require("./../../_shared/resolvers/is-node-selected.js");
var import_font_size_button = require("./../../toolbars-v3/components/buttons/FontSizeButton/font-size-button.js");
var import_data_hooks = require("./data-hooks.js");
var import_extension = require("./extension.js");
var import_font_size_converter = require("./font-size-converter.js");
var import_font_size_panel_component = require("./font-size-panel-component.js");
const FONT_SIZE_MODAL_ID = `${import_v1.Decoration_Type.FONT_SIZE}.modal`;
const MAX_FONT_SIZE = 900;
const MIN_FONT_SIZE = 1;
const DEFAULT_FONTSIZE_DROPDOWN_OPTIONS = [
  "6",
  "8",
  "10",
  "12",
  "14",
  "16",
  "18",
  "20",
  "24",
  "30",
  "36",
  "48",
  "64",
  "72",
  "96"
];
const getFontSize = ({
  publicCommands
}) => {
  const currentFontSize = publicCommands.getFontSize() || "";
  return () => /* @__PURE__ */ import_react.default.createElement("div", null, currentFontSize);
};
const pluginFontSize = (config) => ({
  type: import_v1.Decoration_Type.FONT_SIZE,
  config: {},
  pmNodeConverters: [],
  pmMarkConverters: [import_font_size_converter.fontSizeConverter],
  tiptapExtensions: [(0, import_extension.fontSize)(config)],
  shortcuts: [
    (0, import_ricos_types.createShortcut)({
      name: `${import_v1.Decoration_Type.FONT_SIZE}.increase`,
      description: "ShortcutsSheet_Formatting_IncreaseFontSize",
      keys: { macOs: "Meta+Alt+.", windows: "Ctrl+Alt+." },
      command({ publicCommands }) {
        const currentFontSize = publicCommands.getFontSize();
        const newFontSize = currentFontSize && parseInt(currentFontSize, 10) + 1;
        if (newFontSize) {
          publicCommands.insertDecoration(import_ricos_content.RICOS_FONT_SIZE_TYPE, {
            fontSize: newFontSize.toString()
          });
        }
        return "continue";
      },
      group: "ShortcutsSheet_Section_Formatting",
      enabled: true,
      showInShortcutSheet: true
    }),
    (0, import_ricos_types.createShortcut)({
      name: `${import_v1.Decoration_Type.FONT_SIZE}.decrease`,
      description: "ShortcutsSheet_Formatting_DecreaseFontSize",
      keys: { macOs: "Meta+Alt+,", windows: "Ctrl+Alt+," },
      command({ publicCommands }) {
        const currentFontSize = publicCommands.getFontSize();
        const newFontSize = currentFontSize && parseInt(currentFontSize, 10) - 1;
        if (newFontSize) {
          publicCommands.insertDecoration(import_ricos_content.RICOS_FONT_SIZE_TYPE, {
            fontSize: newFontSize.toString()
          });
        }
        return "continue";
      },
      group: "ShortcutsSheet_Section_Formatting",
      enabled: true,
      showInShortcutSheet: true
    })
  ],
  textButtons: [
    (0, import_create_text_button.createTextButton)({
      id: import_v1.Decoration_Type.FONT_SIZE,
      type: "dropdown",
      presentation: {
        id: FONT_SIZE_MODAL_ID,
        dataHook: import_data_hooks.TEXT_BUTTON_FONT_SIZE,
        tooltip: "FormattingToolbar_CustomFontSizeButton_Tooltip",
        getIcon: getFontSize,
        renderer: (toolbarItem) => /* @__PURE__ */ import_react.default.createElement(import_font_size_button.FontSizeButton, { toolbarItem }),
        Component: import_font_size_panel_component.FontSizePanelComponent,
        getComponentProps: ({ publicCommands, modals }) => {
          const selectedFontSize = publicCommands?.getFontSize() ?? "";
          const dropdownOptions = insertSorted(
            [...DEFAULT_FONTSIZE_DROPDOWN_OPTIONS],
            selectedFontSize
          );
          return {
            dropdownOptions: dropdownOptions.map((fontSize2) => ({
              id: fontSize2,
              dataHook: `font-size-dropdown-option-${fontSize2}`,
              label: fontSize2
            })),
            onSelect: (fontSize2) => {
              const fontSizeValue = Math.min(
                Math.max(MIN_FONT_SIZE, parseInt(fontSize2)),
                MAX_FONT_SIZE
              );
              publicCommands.insertDecoration(import_ricos_content.RICOS_FONT_SIZE_TYPE, {
                fontSize: `${fontSizeValue}`
              });
            },
            selectedId: selectedFontSize,
            closeModal: () => modals.closeModal(FONT_SIZE_MODAL_ID)
          };
        }
      },
      command: ({ modalService: modals, referenceElement, isMobile, componentProps }) => () => {
        if (!componentProps) {
          return false;
        }
        modals.isModalOpen(FONT_SIZE_MODAL_ID) ? modals.closeModal(FONT_SIZE_MODAL_ID) : modals.openModal({
          id: FONT_SIZE_MODAL_ID,
          Component: import_font_size_panel_component.FontSizePanelComponent,
          componentProps,
          positioning: {
            placement: "bottom",
            referenceElement
          },
          layout: isMobile ? "drawer" : referenceElement ? "floating" : "dialog",
          returnFocusToEditor: true
        });
        return true;
      },
      attributes: {
        visible: import_is_always_visible.isAlwaysVisible,
        selectedFontSize: import_get_font_size_in_selection.getFontSizeInSelection,
        disabled: import_is_node_selected.isNodeSelected
      }
    })
  ]
});
const insertSorted = (array, value) => {
  if (!array.includes(value) && value !== "") {
    array.push(value);
    array.sort((a, b) => parseInt(a) - parseInt(b));
  }
  return array;
};
//# sourceMappingURL=font-size.js.map
