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 a=parseFragment(t);return sanitizeHTML(serialize(a),{allowedTags:ALLOWED_HTML_TAGS,allowedAttributes:ALLOWED_HTML_ATTRIBUTES,allowedSchemes:ALLOWED_URL_SCHEMES,allowedSchemesAppliedToAttributes:ALLOWED_URL_SCHEMES_APPLIED_TO_ATTRIBUTES,transformTags:{"*":sanitizeTooltip,iframe:sanitizeIframe}})}function sanitizeIframe(t,a){const e=URL.parseSafe(a.src),o=e?.hostname;return!a.srcdoc&&TRUSTED_IFRAME_DOMAINS.some((t=>o===t||o?.endsWith(`.${t}`)))?delete a.sandbox:a.sandbox="allow-scripts allow-forms",{tagName:"iframe",attribs:a}}function sanitizeTooltip(t,a){return a["data-tooltip"]&&(a["data-tooltip"]=cleanHTML(a["data-tooltip"])),{tagName:t,attribs:a}}