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