import { Mark as i, mergeAttributes as s } from "@tiptap/core";
import n from "../utils/isValidFontSize.js";
const o = i.create({
  name: "fontSize",
  /**
   * Defines the mark's attributes.
   * The `size` attribute stores the font size value (e.g. "14", "14px", "1.5rem", "var(--variable)").
   */
  addAttributes() {
    return {
      size: {
        default: null,
        // Parse the font-size from the inline style when reading HTML.
        // Only accept validated formats to prevent injection attacks.
        parseHTML: (e) => {
          var t;
          const r = (t = e.style) == null ? void 0 : t.fontSize;
          return !r || !n(r) ? null : r;
        },
        // Render the font-size as an inline style when writing HTML.
        // Validate before rendering as a safety net.
        renderHTML: (e) => e.size ? n(e.size) ? {
          style: `font-size: ${/^\d+(\.\d+)?$/.test(e.size) ? `${e.size}px` : e.size}`
        } : {} : {}
      }
    };
  },
  /**
   * Parses an existing <span style="font-size: ..."> back into this mark.
   * Only matches spans that have an inline font-size style.
   */
  parseHTML() {
    return [
      {
        tag: "span",
        getAttrs: (e) => {
          var t;
          return typeof e == "string" || !((t = e.style) == null ? void 0 : t.fontSize) ? !1 : null;
        }
      }
    ];
  },
  /**
   * Renders the mark as a <span> with merged HTML attributes.
   * The font-size style is applied via the renderHTML function in addAttributes.
   */
  renderHTML({ HTMLAttributes: e }) {
    return ["span", s(e), 0];
  }
});
export {
  o as default
};
//# sourceMappingURL=fontSizeExtension.js.map
