import xss, { l as libExports } from "../_vendor/xss/lib-index.js";
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 = xss(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}="${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]);
}
export {
  ALLOWED_HTML_ATTRIBUTES,
  ALLOWED_HTML_TAGS,
  longestCommonPrefix,
  prefixMatch,
  sanitizeHtml
};
//# sourceMappingURL=index.js.map
