"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const index = require("../_vendor/xss/lib-index.cjs");
const ALLOWED_HTML_ATTRIBUTES = ["href", "name", "target", "title", "class", "id", "style"];
const ALLOWED_HTML_TAGS = [
  "p",
  "strong",
  "b",
  "code",
  "a",
  "br",
  "i",
  "ul",
  "li",
  "em",
  "small",
  "details",
  "summary",
  "mark"
];
function sanitizeHtml(dirtyHtml) {
  const sanitizedHtml = index.default(dirtyHtml, {
    onTagAttr: (tag, name, value) => {
      if (tag === "img" && name === "src") {
        const isImageFile = value.split("#")[0].match(/\.(jpeg|jpg|gif|png|webp)$/) !== null;
        const isStaticImageFile = isImageFile && value.startsWith("/static/");
        if (!value.startsWith("https://") && !isStaticImageFile) {
          return "";
        }
      }
      if (ALLOWED_HTML_ATTRIBUTES.includes(name) || name.startsWith("data-")) {
        if (name === "href" && !value.match(/^https?:\/\//gm) && !value.startsWith("/")) {
          return "";
        }
        return `${name}="${index.libExports.escapeAttrValue(value)}"`;
      }
      return;
    },
    onTag: (tag) => {
      if (!ALLOWED_HTML_TAGS.includes(tag)) return "";
      return;
    }
  });
  return sanitizedHtml;
}
const prefixMatch = (first, second) => first.toLocaleLowerCase().startsWith(second.toLocaleLowerCase());
function longestCommonPrefix(...strings) {
  if (strings.length < 2) return "";
  return strings.reduce((prefix, str) => {
    while (!str.startsWith(prefix)) {
      prefix = prefix.slice(0, -1);
      if (prefix === "") return "";
    }
    return prefix;
  }, strings[0]);
}
exports.ALLOWED_HTML_ATTRIBUTES = ALLOWED_HTML_ATTRIBUTES;
exports.ALLOWED_HTML_TAGS = ALLOWED_HTML_TAGS;
exports.longestCommonPrefix = longestCommonPrefix;
exports.prefixMatch = prefixMatch;
exports.sanitizeHtml = sanitizeHtml;
//# sourceMappingURL=index.cjs.map
