"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 get_text_color_in_selection_exports = {};
__export(get_text_color_in_selection_exports, {
  getTextColorInSelection: () => getTextColorInSelection
});
module.exports = __toCommonJS(get_text_color_in_selection_exports);
var import_ricos_types = require("./../../ricos-types/index.js");
const getTextColorInSelection = (content, { styles, converters }, editor) => {
  if (Array.isArray(content)) {
    const textNode = content.find((node) => node.type.name === "text");
    const colorMark = textNode?.marks.find((mark) => mark.type.name === import_ricos_types.Mark_Type.COLOR_FOREGROUND);
    let textColorInDocumentStyle;
    if (textNode && styles && converters) {
      for (const node of content) {
        const decoration = styles.getDecoration(
          converters.fromPmNode(node.toJSON()),
          import_ricos_types.Decoration_Type.COLOR
        );
        if (decoration.colorData?.foreground) {
          textColorInDocumentStyle = decoration.colorData?.foreground;
          break;
        }
      }
    }
    const storedMark = editor?.state?.storedMarks?.find((mark) => {
      return mark.type.name === import_ricos_types.Mark_Type.COLOR_FOREGROUND && mark.attrs.color;
    });
    const markInSelection = editor?.state?.selection?.$from.marks().find((mark) => {
      return mark.type.name === import_ricos_types.Mark_Type.COLOR_FOREGROUND && mark.attrs.color;
    });
    let colorInStoredMark;
    let colorInSelection;
    if (storedMark) {
      colorInStoredMark = storedMark.attrs.color;
    }
    if (markInSelection) {
      colorInSelection = markInSelection.attrs.color;
    }
    return colorMark?.attrs.color || textColorInDocumentStyle || colorInStoredMark || colorInSelection || styles.getTheme().getColors()?.textColor;
  }
  return void 0;
};
//# sourceMappingURL=get-text-color-in-selection.js.map
