import{parseFragment,serialize}from"parse5";import sanitizeHTML from"sanitize-html";import{ALLOWED_HTML_ATTRIBUTES,ALLOWED_HTML_TAGS,ALLOWED_URL_SCHEMES,ALLOWED_URL_SCHEMES_APPLIED_TO_ATTRIBUTES,TRUSTED_IFRAME_DOMAINS}from"../../common/constants.mjs";export function cleanHTML(t){const e=parseFragment(t);return sanitizeHTML(serialize(e),{allowedTags:ALLOWED_HTML_TAGS,allowedAttributes:ALLOWED_HTML_ATTRIBUTES,allowedSchemes:ALLOWED_URL_SCHEMES,allowedSchemesAppliedToAttributes:ALLOWED_URL_SCHEMES_APPLIED_TO_ATTRIBUTES,transformTags:{"*":sanitizeTooltip,iframe:sanitizeIframe}}).replace(/ \/>/g,">")}function sanitizeIframe(t,e){const a=URL.parse(e.src),o=a?.hostname;return!e.srcdoc&&TRUSTED_IFRAME_DOMAINS.some(t=>o===t||o?.endsWith(`.${t}`))?delete e.sandbox:e.sandbox="allow-scripts allow-forms",{tagName:"iframe",attribs:e}}function sanitizeTooltip(t,e){return e["data-tooltip"]&&(e["data-tooltip"]=cleanHTML(e["data-tooltip"])),{tagName:t,attribs:e}}