import { Mark as l, mergeAttributes as n } from "@tiptap/core";
import o from "../utils/isValidColor.js";
const a = l.create({
  name: "textColor",
  /**
   * Declares the `color` attribute with HTML parse / render helpers.
   */
  addAttributes() {
    return {
      color: {
        default: null,
        // Read the color value from an existing inline style.
        // Only accept validated color formats to prevent injection attacks.
        parseHTML: (r) => {
          var t;
          const e = (t = r.style) == null ? void 0 : t.color;
          return e && o(e) ? e : null;
        },
        // Write the color value back as an inline style.
        // Validate before rendering as a safety net.
        renderHTML: (r) => r.color ? o(r.color) ? { style: `color: ${r.color}` } : {} : {}
      }
    };
  },
  /**
   * Matches `<span>` elements that carry an inline `color` style.
   * Nodes without a color style are skipped (return false).
   */
  parseHTML() {
    return [
      {
        tag: "span",
        getAttrs: (r) => {
          var e;
          return typeof r == "string" ? !1 : (e = r.style) != null && e.color ? null : !1;
        }
      }
    ];
  },
  /**
   * Renders the mark as a `<span>` with the color applied via renderHTML in addAttributes.
   */
  renderHTML({ HTMLAttributes: r }) {
    return ["span", n(r), 0];
  }
});
export {
  a as default
};
//# sourceMappingURL=textColorExtension.js.map
