!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).DOMPurify=t()}(this,function(){"use strict";var r,o=Object.hasOwnProperty,i=Object.setPrototypeOf,a=Object.isFrozen,l=Object.getPrototypeOf,c=Object.getOwnPropertyDescriptor,Re=Object.freeze,e=Object.seal,s=Object.create,t="undefined"!=typeof Reflect&&Reflect,u=(u=t.apply)||function(e,t,n){return e.apply(t,n)},Re=Re||function(e){return e},e=e||function(e){return e},m=(m=t.construct)||function(e,t){return new(Function.prototype.bind.apply(e,[null].concat(function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t/gm),rt=e(/^data-[\-\w.\u00B7-\uFFFF]/),ot=e(/^aria-[\-\w]+$/),it=e(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),at=e(/^(?:\w+script|data):/i),lt=e(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),$e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};function Ze(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t"+e:n=(r=Le(e,/^[\r\n\t ]+/))&&r[0],p?p.createHTML(e):e);if(ge===N)try{t=(new B).parseFromString(r,"text/html")}catch(e){}if(!t||!t.documentElement){t=i.createDocument(ge,"template",null);try{t.documentElement.innerHTML=$?"":r}catch(e){}}return r=t.body||t.documentElement,e&&n&&r.insertBefore(o.createTextNode(n),r.childNodes[0]||null),T?t.documentElement:r},xe=function(e){return V.call(e.ownerDocument||e,e,t.SHOW_ELEMENT|t.SHOW_COMMENT|t.SHOW_TEXT,null,!1)},F=function(e){return"object"===(void 0===u?"undefined":$e(u))?e instanceof u:e&&"object"===(void 0===e?"undefined":$e(e))&&"number"==typeof e.nodeType&&"string"==typeof e.nodeName},I=function(e,t,n){a[e]&&_e(a[e],function(e){e.call(s,t,n,O)})},Se=function(e){if(I("beforeSanitizeElements",e,null),((i=e)instanceof j||i instanceof P||"string"==typeof i.nodeName&&"string"==typeof i.textContent&&"function"==typeof i.removeChild&&i.attributes instanceof H&&"function"==typeof i.removeAttribute&&"function"==typeof i.setAttribute&&"string"==typeof i.namespaceURI&&"function"==typeof i.insertBefore)&&!Le(e.nodeName,/[\u0080-\uFFFF]/)){var t,n,r,o,i=Me(e.nodeName);if(I("uponSanitizeElement",e,{tagName:i,allowedTags:h}),F(e.firstElementChild)||F(e.content)&&F(e.content.firstElementChild)||!Ce(/<[/\w]/g,e.innerHTML)||!Ce(/<[/\w]/g,e.textContent)){if(h[i]&&!v[i])return e instanceof U&&((n=m(t=e))&&n.tagName||(n={namespaceURI:N,tagName:"template"}),r=Me(t.tagName),o=Me(n.tagName),t.namespaceURI===de?n.namespaceURI===N?"svg"!==r:n.namespaceURI===fe?"svg"!==r||"annotation-xml"!==o&&!ve[o]:!Boolean(M[r]):t.namespaceURI===fe?n.namespaceURI===N?"math"!==r:n.namespaceURI===de?"math"!==r||!be[o]:!Boolean(Ae[r]):t.namespaceURI!==N||n.namespaceURI===de&&!be[o]||n.namespaceURI===fe&&!ve[o]||(n=Ue({},["title","style","font","a","script"]),Ae[r])||!n[r]&&M[r])||("noscript"===i||"noembed"===i)&&Ce(/<\/no(script|embed)/i,e.innerHTML)?(L(e),!0):(A&&3===e.nodeType&&(t=e.textContent,t=Fe(t,f," "),t=Fe(t,d," "),e.textContent!==t)&&(Oe(s.removed,{element:e.cloneNode()}),e.textContent=t),I("afterSanitizeElements",e,null),!1);if(E&&!ce[i]){var a=m(e)||e.parentNode,l=q(e)||e.childNodes;if(l&&a)for(var c=l.length-1;0<=c;--c)a.insertBefore(W(l[c],!0),G(e))}}}return L(e),!0},ke=function(e,t,n){if(le&&("id"===t||"name"===t)&&(n in o||n in he))return!1;if(!(b&&Ce(Z,t)||oe&&Ce(J,t))){if(!y[t]||re[t])return!1;if(!me[t]&&!Ce(g,Fe(n,ee,""))&&("src"!==t&&"xlink:href"!==t&&"href"!==t||"script"===e||0!==Ie(n,"data:")||!se[e])&&(!ie||Ce(Q,Fe(n,ee,"")))&&n)return!1}return!0},De=function(e){var t=void 0,n=void 0,r=(I("beforeSanitizeAttributes",e,null),e.attributes);if(r){for(var o={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:y},n=r.length;n--;){var i=(l=r[n]).name,a=l.namespaceURI,t=Je(l.value),l=Me(i);if(o.attrName=l,o.attrValue=t,o.keepAttr=!0,o.forceKeepAttr=void 0,I("uponSanitizeAttribute",e,o),t=o.attrValue,!o.forceKeepAttr&&(Te(i,e),o.keepAttr))if(Ce(/\/>/i,t))Te(i,e);else{A&&(t=Fe(t,f," "),t=Fe(t,d," "));var c=e.nodeName.toLowerCase();if(ke(c,l,t))try{a?e.setAttributeNS(a,i,t):e.setAttribute(i,t),Ne(s.removed)}catch(e){}}}I("afterSanitizeAttributes",e,null)}},Ee=function e(t){var n,r=xe(t);for(I("beforeSanitizeShadowDOM",t,null);n=r.nextNode();)I("uponSanitizeShadowNode",n,null),Se(n)||(n.content instanceof z&&e(n.content),De(n));I("afterSanitizeShadowDOM",t,null)};s.sanitize=function(e,t){var n,r=void 0,o=void 0,i=void 0;if("string"!=typeof(e=($=!e)?"\x3c!--\x3e":e)&&!F(e)){if("function"!=typeof e.toString)throw ze("toString is not a function");if("string"!=typeof(e=e.toString()))throw ze("dirty is not a string, aborting")}if(!s.isSupported){if("object"===$e(l.toStaticHTML)||"function"==typeof l.toStaticHTML){if("string"==typeof e)return l.toStaticHTML(e);if(F(e))return l.toStaticHTML(e.outerHTML)}return e}if(w||ye(t),s.removed=[],!(R="string"!=typeof e&&R))if(e instanceof u)1===(t=(r=we("\x3c!----\x3e")).ownerDocument.importNode(e,!0)).nodeType&&"BODY"===t.nodeName||"HTML"===t.nodeName?r=t:r.appendChild(t);else{if(!S&&!A&&!T&&-1===e.indexOf("<"))return p&&D?p.createHTML(e):e;if(!(r=we(e)))return S?null:K}r&&x&&L(r.firstChild);for(var a=xe(R?e:r);n=a.nextNode();)3===n.nodeType&&n===o||Se(n)||(n.content instanceof z&&Ee(n.content),De(n),o=n);if(o=null,R)return e;if(S){if(k)for(i=Y.call(r.ownerDocument);r.firstChild;)i.appendChild(r.firstChild);else i=r;return i=ae?X.call(c,i,!0):i}return t=T?r.outerHTML:r.innerHTML,A&&(t=Fe(t,f," "),t=Fe(t,d," ")),p&&D?p.createHTML(t):t},s.setConfig=function(e){ye(e),w=!0},s.clearConfig=function(){O=null,w=!1},s.isValidAttribute=function(e,t,n){return O||ye({}),e=Me(e),t=Me(t),ke(e,t,n)},s.addHook=function(e,t){"function"==typeof t&&(a[e]=a[e]||[],Oe(a[e],t))},s.removeHook=function(e){a[e]&&Ne(a[e])},s.removeHooks=function(e){a[e]&&(a[e]=[])},s.removeAllHooks=function(){a={}}}else s.isSupported=!1;return s}()});