import { Mark_Type } from "./../../ricos-types/index.js";
import { Decoration, DecorationSet } from "./../../tiptap/pm/view.js";
import { hashtagRegex } from "../const.js";
import styles from "../statics/hashtag-scss.js";
const hasLink = (node) => {
  return node.marks.map((mark) => mark.type.name).includes("link");
};
function findHashTag(doc) {
  const decorations = [];
  doc.descendants((node, position) => {
    if (!node.text) {
      return;
    }
    Array.from(node.text.matchAll(hashtagRegex)).forEach((match) => {
      const hash = match[0];
      let hashLength = hash.length;
      let index = match.index || 0;
      if (!hash.startsWith("#")) {
        index++;
        hashLength--;
      }
      const from = position + index;
      const to = from + hashLength;
      if (hasLink(node)) {
        return false;
      }
      const foregroundMark = node.marks.find((mark) => mark.type.name === Mark_Type.COLOR_FOREGROUND);
      const decoration = Decoration.inline(
        from,
        to,
        {
          class: styles.hashtag,
          style: foregroundMark ? `color: ${foregroundMark?.attrs?.color};` : void 0
        },
        { name: "hashtag" }
      );
      decorations.push(decoration);
    });
  });
  return DecorationSet.create(doc, decorations);
}
export {
  findHashTag
};
//# sourceMappingURL=find-hash-tag.js.map
