import { Decoration_Type, Mark_Type } from "./../../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 === Mark_Type.COLOR_FOREGROUND);
    let textColorInDocumentStyle;
    if (textNode && styles && converters) {
      for (const node of content) {
        const decoration = styles.getDecoration(
          converters.fromPmNode(node.toJSON()),
          Decoration_Type.COLOR
        );
        if (decoration.colorData?.foreground) {
          textColorInDocumentStyle = decoration.colorData?.foreground;
          break;
        }
      }
    }
    const storedMark = editor?.state?.storedMarks?.find((mark) => {
      return mark.type.name === Mark_Type.COLOR_FOREGROUND && mark.attrs.color;
    });
    const markInSelection = editor?.state?.selection?.$from.marks().find((mark) => {
      return mark.type.name === 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;
};
export {
  getTextColorInSelection
};
//# sourceMappingURL=get-text-color-in-selection.js.map
