UNPKG

dompurify

Version:

DOMPurify is a DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML and SVG. It's written in JavaScript and works in all modern browsers (Safari, Opera (15+), Internet Explorer (10+), Firefox and Chrome - as well as almost anything else usin

4 lines (3 loc) 26.2 kB
/*! @license DOMPurify 3.4.4 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.4.4/LICENSE */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).DOMPurify=t()}(this,function(){"use strict";function e(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=Array(t);n<t;n++)o[n]=e[n];return o}function t(t,n){return function(e){if(Array.isArray(e))return e}(t)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var o,r,i,a,l=[],c=!0,s=!1;try{if(i=(n=n.call(e)).next,0===t);else for(;!(c=(o=i.call(n)).done)&&(l.push(o.value),l.length!==t);c=!0);}catch(e){s=!0,r=e}finally{try{if(!c&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(s)throw r}}return l}}(t,n)||function(t,n){if(t){if("string"==typeof t)return e(t,n);var o={}.toString.call(t).slice(8,-1);return"Object"===o&&t.constructor&&(o=t.constructor.name),"Map"===o||"Set"===o?Array.from(t):"Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?e(t,n):void 0}}(t,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}const n=Object.entries,o=Object.setPrototypeOf,r=Object.isFrozen,i=Object.getPrototypeOf,a=Object.getOwnPropertyDescriptor;let l=Object.freeze,c=Object.seal,s=Object.create,u="undefined"!=typeof Reflect&&Reflect,f=u.apply,m=u.construct;l||(l=function(e){return e}),c||(c=function(e){return e}),f||(f=function(e,t){for(var n=arguments.length,o=new Array(n>2?n-2:0),r=2;r<n;r++)o[r-2]=arguments[r];return e.apply(t,o)}),m||(m=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];return new e(...n)});const p=L(Array.prototype.forEach),d=L(Array.prototype.lastIndexOf),h=L(Array.prototype.pop),g=L(Array.prototype.push),y=L(Array.prototype.splice),T=Array.isArray,b=L(String.prototype.toLowerCase),A=L(String.prototype.toString),S=L(String.prototype.match),E=L(String.prototype.replace),N=L(String.prototype.indexOf),_=L(String.prototype.trim),O=L(Number.prototype.toString),D=L(Boolean.prototype.toString),R="undefined"==typeof BigInt?null:L(BigInt.prototype.toString),w="undefined"==typeof Symbol?null:L(Symbol.prototype.toString),I=L(Object.prototype.hasOwnProperty),v=L(Object.prototype.toString),C=L(RegExp.prototype.test),x=(k=TypeError,function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return m(k,t)});var k;function L(e){return function(t){t instanceof RegExp&&(t.lastIndex=0);for(var n=arguments.length,o=new Array(n>1?n-1:0),r=1;r<n;r++)o[r-1]=arguments[r];return f(e,t,o)}}function M(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:b;if(o&&o(e,null),!T(t))return e;let i=t.length;for(;i--;){let o=t[i];if("string"==typeof o){const e=n(o);e!==o&&(r(t)||(t[i]=e),o=e)}e[o]=!0}return e}function F(e){for(let t=0;t<e.length;t++){I(e,t)||(e[t]=null)}return e}function z(e){const o=s(null);for(const i of n(e)){var r=t(i,2);const n=r[0],a=r[1];I(e,n)&&(T(a)?o[n]=F(a):a&&"object"==typeof a&&a.constructor===Object?o[n]=z(a):o[n]=a)}return o}function P(e,t){for(;null!==e;){const n=a(e,t);if(n){if(n.get)return L(n.get);if("function"==typeof n.value)return L(n.value)}e=i(e)}return function(){return null}}const U=l(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dialog","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","search","section","select","selectedcontent","shadow","slot","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]),H=l(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","enterkeyhint","exportparts","filter","font","g","glyph","glyphref","hkern","image","inputmode","line","lineargradient","marker","mask","metadata","mpath","part","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),B=l(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),G=l(["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"]),j=l(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover","mprescripts"]),W=l(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),Y=l(["#text"]),X=l(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","command","commandfor","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","exportparts","face","for","headers","height","hidden","high","href","hreflang","id","inert","inputmode","integrity","ismap","kind","label","lang","list","loading","loop","low","max","maxlength","media","method","min","minlength","multiple","muted","name","nonce","noshade","novalidate","nowrap","open","optimum","part","pattern","placeholder","playsinline","popover","popovertarget","popovertargetaction","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","slot","span","srclang","start","src","srcset","step","style","summary","tabindex","title","translate","type","usemap","valign","value","width","wrap","xmlns"]),q=l(["accent-height","accumulate","additive","alignment-baseline","amplitude","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clippathunits","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dur","edgemode","elevation","end","exponent","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","intercept","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","mask-type","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","slope","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","systemlanguage","tabindex","tablevalues","targetx","targety","transform","transform-origin","text-anchor","text-decoration","text-rendering","textlength","type","u1","u2","unicode","values","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]),$=l(["accent","accentunder","align","bevelled","close","columnalign","columnlines","columnspacing","columnspan","denomalign","depth","dir","display","displaystyle","encoding","fence","frame","height","href","id","largeop","length","linethickness","lquote","lspace","mathbackground","mathcolor","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","numalign","open","rowalign","rowlines","rowspacing","rowspan","rspace","rquote","scriptlevel","scriptminsize","scriptsizemultiplier","selection","separator","separators","stretchy","subscriptshift","supscriptshift","symmetric","voffset","width","xmlns"]),K=l(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),V=c(/{{[\w\W]*|^[\w\W]*}}/g),Z=c(/<%[\w\W]*|^[\w\W]*%>/g),J=c(/\${[\w\W]*/g),Q=c(/^data-[\-\w.\u00B7-\uFFFF]+$/),ee=c(/^aria-[\-\w]+$/),te=c(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),ne=c(/^(?:\w+script|data):/i),oe=c(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),re=c(/^html$/i),ie=c(/^[a-z][.\w]*(-[.\w]+)+$/i),ae=1,le=3,ce=7,se=8,ue=9,fe=function(){return"undefined"==typeof window?null:window};var me=function e(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:fe();const o=t=>e(t);if(o.version="3.4.4",o.removed=[],!t||!t.document||t.document.nodeType!==ue||!t.Element)return o.isSupported=!1,o;let r=t.document;const i=r,a=i.currentScript,c=t.DocumentFragment,u=t.HTMLTemplateElement,f=t.Node,m=t.Element,k=t.NodeFilter,L=t.NamedNodeMap,F=void 0===L?t.NamedNodeMap||t.MozNamedAttrMap:L,me=t.HTMLFormElement,pe=t.DOMParser,de=t.trustedTypes,he=m.prototype,ge=P(he,"cloneNode"),ye=P(he,"remove"),Te=P(he,"nextSibling"),be=P(he,"childNodes"),Ae=P(he,"parentNode"),Se=f&&f.prototype?P(f.prototype,"nodeType"):null;if("function"==typeof u){const e=r.createElement("template");e.content&&e.content.ownerDocument&&(r=e.content.ownerDocument)}let Ee,Ne="";const _e=r,Oe=_e.implementation,De=_e.createNodeIterator,Re=_e.createDocumentFragment,we=_e.getElementsByTagName,Ie=i.importNode;let ve={afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]};o.isSupported="function"==typeof n&&"function"==typeof Ae&&Oe&&void 0!==Oe.createHTMLDocument;const Ce=V,xe=Z,ke=J,Le=Q,Me=ee,Fe=ne,ze=oe,Pe=ie;let Ue=te,He=null;const Be=M({},[...U,...H,...B,...j,...Y]);let Ge=null;const je=M({},[...X,...q,...$,...K]);let We=Object.seal(s(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),Ye=null,Xe=null;const qe=Object.seal(s(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}}));let $e=!0,Ke=!0,Ve=!1,Ze=!0,Je=!1,Qe=!0,et=!1,tt=!1,nt=!1,ot=!1,rt=!1,it=!1,at=!0,lt=!1;const ct="user-content-";let st=!0,ut=!1,ft={},mt=null;const pt=M({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]);let dt=null;const ht=M({},["audio","video","img","source","image","track"]);let gt=null;const yt=M({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),Tt="http://www.w3.org/1998/Math/MathML",bt="http://www.w3.org/2000/svg",At="http://www.w3.org/1999/xhtml";let St=At,Et=!1,Nt=null;const _t=M({},[Tt,bt,At],A);let Ot=M({},["mi","mo","mn","ms","mtext"]),Dt=M({},["annotation-xml"]);const Rt=M({},["title","style","font","a","script"]);let wt=null;const It=["application/xhtml+xml","text/html"];let vt=null,Ct=null;const xt=r.createElement("form"),kt=function(e){return e instanceof RegExp||e instanceof Function},Lt=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(Ct&&Ct===e)return;e&&"object"==typeof e||(e={}),e=z(e),wt=-1===It.indexOf(e.PARSER_MEDIA_TYPE)?"text/html":e.PARSER_MEDIA_TYPE,vt="application/xhtml+xml"===wt?A:b,He=I(e,"ALLOWED_TAGS")&&T(e.ALLOWED_TAGS)?M({},e.ALLOWED_TAGS,vt):Be,Ge=I(e,"ALLOWED_ATTR")&&T(e.ALLOWED_ATTR)?M({},e.ALLOWED_ATTR,vt):je,Nt=I(e,"ALLOWED_NAMESPACES")&&T(e.ALLOWED_NAMESPACES)?M({},e.ALLOWED_NAMESPACES,A):_t,gt=I(e,"ADD_URI_SAFE_ATTR")&&T(e.ADD_URI_SAFE_ATTR)?M(z(yt),e.ADD_URI_SAFE_ATTR,vt):yt,dt=I(e,"ADD_DATA_URI_TAGS")&&T(e.ADD_DATA_URI_TAGS)?M(z(ht),e.ADD_DATA_URI_TAGS,vt):ht,mt=I(e,"FORBID_CONTENTS")&&T(e.FORBID_CONTENTS)?M({},e.FORBID_CONTENTS,vt):pt,Ye=I(e,"FORBID_TAGS")&&T(e.FORBID_TAGS)?M({},e.FORBID_TAGS,vt):z({}),Xe=I(e,"FORBID_ATTR")&&T(e.FORBID_ATTR)?M({},e.FORBID_ATTR,vt):z({}),ft=!!I(e,"USE_PROFILES")&&(e.USE_PROFILES&&"object"==typeof e.USE_PROFILES?z(e.USE_PROFILES):e.USE_PROFILES),$e=!1!==e.ALLOW_ARIA_ATTR,Ke=!1!==e.ALLOW_DATA_ATTR,Ve=e.ALLOW_UNKNOWN_PROTOCOLS||!1,Ze=!1!==e.ALLOW_SELF_CLOSE_IN_ATTR,Je=e.SAFE_FOR_TEMPLATES||!1,Qe=!1!==e.SAFE_FOR_XML,et=e.WHOLE_DOCUMENT||!1,ot=e.RETURN_DOM||!1,rt=e.RETURN_DOM_FRAGMENT||!1,it=e.RETURN_TRUSTED_TYPE||!1,nt=e.FORCE_BODY||!1,at=!1!==e.SANITIZE_DOM,lt=e.SANITIZE_NAMED_PROPS||!1,st=!1!==e.KEEP_CONTENT,ut=e.IN_PLACE||!1,Ue=function(e){try{return C(e,""),!0}catch(e){return!1}}(e.ALLOWED_URI_REGEXP)?e.ALLOWED_URI_REGEXP:te,St="string"==typeof e.NAMESPACE?e.NAMESPACE:At,Ot=I(e,"MATHML_TEXT_INTEGRATION_POINTS")&&e.MATHML_TEXT_INTEGRATION_POINTS&&"object"==typeof e.MATHML_TEXT_INTEGRATION_POINTS?z(e.MATHML_TEXT_INTEGRATION_POINTS):M({},["mi","mo","mn","ms","mtext"]),Dt=I(e,"HTML_INTEGRATION_POINTS")&&e.HTML_INTEGRATION_POINTS&&"object"==typeof e.HTML_INTEGRATION_POINTS?z(e.HTML_INTEGRATION_POINTS):M({},["annotation-xml"]);const t=I(e,"CUSTOM_ELEMENT_HANDLING")&&e.CUSTOM_ELEMENT_HANDLING&&"object"==typeof e.CUSTOM_ELEMENT_HANDLING?z(e.CUSTOM_ELEMENT_HANDLING):s(null);if(We=s(null),I(t,"tagNameCheck")&&kt(t.tagNameCheck)&&(We.tagNameCheck=t.tagNameCheck),I(t,"attributeNameCheck")&&kt(t.attributeNameCheck)&&(We.attributeNameCheck=t.attributeNameCheck),I(t,"allowCustomizedBuiltInElements")&&"boolean"==typeof t.allowCustomizedBuiltInElements&&(We.allowCustomizedBuiltInElements=t.allowCustomizedBuiltInElements),Je&&(Ke=!1),rt&&(ot=!0),ft&&(He=M({},Y),Ge=s(null),!0===ft.html&&(M(He,U),M(Ge,X)),!0===ft.svg&&(M(He,H),M(Ge,q),M(Ge,K)),!0===ft.svgFilters&&(M(He,B),M(Ge,q),M(Ge,K)),!0===ft.mathMl&&(M(He,j),M(Ge,$),M(Ge,K))),qe.tagCheck=null,qe.attributeCheck=null,I(e,"ADD_TAGS")&&("function"==typeof e.ADD_TAGS?qe.tagCheck=e.ADD_TAGS:T(e.ADD_TAGS)&&(He===Be&&(He=z(He)),M(He,e.ADD_TAGS,vt))),I(e,"ADD_ATTR")&&("function"==typeof e.ADD_ATTR?qe.attributeCheck=e.ADD_ATTR:T(e.ADD_ATTR)&&(Ge===je&&(Ge=z(Ge)),M(Ge,e.ADD_ATTR,vt))),I(e,"ADD_URI_SAFE_ATTR")&&T(e.ADD_URI_SAFE_ATTR)&&M(gt,e.ADD_URI_SAFE_ATTR,vt),I(e,"FORBID_CONTENTS")&&T(e.FORBID_CONTENTS)&&(mt===pt&&(mt=z(mt)),M(mt,e.FORBID_CONTENTS,vt)),I(e,"ADD_FORBID_CONTENTS")&&T(e.ADD_FORBID_CONTENTS)&&(mt===pt&&(mt=z(mt)),M(mt,e.ADD_FORBID_CONTENTS,vt)),st&&(He["#text"]=!0),et&&M(He,["html","head","body"]),He.table&&(M(He,["tbody"]),delete Ye.tbody),e.TRUSTED_TYPES_POLICY){if("function"!=typeof e.TRUSTED_TYPES_POLICY.createHTML)throw x('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if("function"!=typeof e.TRUSTED_TYPES_POLICY.createScriptURL)throw x('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');Ee=e.TRUSTED_TYPES_POLICY,Ne=Ee.createHTML("")}else void 0===Ee&&(Ee=function(e,t){if("object"!=typeof e||"function"!=typeof e.createPolicy)return null;let n=null;const o="data-tt-policy-suffix";t&&t.hasAttribute(o)&&(n=t.getAttribute(o));const r="dompurify"+(n?"#"+n:"");try{return e.createPolicy(r,{createHTML:e=>e,createScriptURL:e=>e})}catch(e){return console.warn("TrustedTypes policy "+r+" could not be created."),null}}(de,a)),null!==Ee&&"string"==typeof Ne&&(Ne=Ee.createHTML(""));l&&l(e),Ct=e},Mt=M({},[...H,...B,...G]),Ft=M({},[...j,...W]),zt=function(e){g(o.removed,{element:e});try{Ae(e).removeChild(e)}catch(t){ye(e)}},Pt=function(e,t){try{g(o.removed,{attribute:t.getAttributeNode(e),from:t})}catch(e){g(o.removed,{attribute:null,from:t})}if(t.removeAttribute(e),"is"===e)if(ot||rt)try{zt(t)}catch(e){}else try{t.setAttribute(e,"")}catch(e){}},Ut=function(e){let t=null,n=null;if(nt)e="<remove></remove>"+e;else{const t=S(e,/^[\r\n\t ]+/);n=t&&t[0]}"application/xhtml+xml"===wt&&St===At&&(e='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+e+"</body></html>");const o=Ee?Ee.createHTML(e):e;if(St===At)try{t=(new pe).parseFromString(o,wt)}catch(e){}if(!t||!t.documentElement){t=Oe.createDocument(St,"template",null);try{t.documentElement.innerHTML=Et?Ne:o}catch(e){}}const i=t.body||t.documentElement;return e&&n&&i.insertBefore(r.createTextNode(n),i.childNodes[0]||null),St===At?we.call(t,et?"html":"body")[0]:et?t.documentElement:i},Ht=function(e){return De.call(e.ownerDocument||e,e,k.SHOW_ELEMENT|k.SHOW_COMMENT|k.SHOW_TEXT|k.SHOW_PROCESSING_INSTRUCTION|k.SHOW_CDATA_SECTION,null)},Bt=function(e){e.normalize();const t=De.call(e.ownerDocument||e,e,k.SHOW_TEXT|k.SHOW_COMMENT|k.SHOW_CDATA_SECTION|k.SHOW_PROCESSING_INSTRUCTION,null);let n=t.nextNode();for(;n;){let e=n.data;p([Ce,xe,ke],t=>{e=E(e,t," ")}),n.data=e,n=t.nextNode()}},Gt=function(e){return e instanceof me&&("string"!=typeof e.nodeName||"string"!=typeof e.textContent||"function"!=typeof e.removeChild||!(e.attributes instanceof F)||"function"!=typeof e.removeAttribute||"function"!=typeof e.setAttribute||"string"!=typeof e.namespaceURI||"function"!=typeof e.insertBefore||"function"!=typeof e.hasChildNodes)},jt=function(e){if(!Se||"object"!=typeof e||null===e)return!1;try{return"number"==typeof Se(e)}catch(e){return!1}};function Wt(e,t,n){p(e,e=>{e.call(o,t,n,Ct)})}const Yt=function(e){let t=null;if(Wt(ve.beforeSanitizeElements,e,null),Gt(e))return zt(e),!0;const n=vt(e.nodeName);if(Wt(ve.uponSanitizeElement,e,{tagName:n,allowedTags:He}),Qe&&e.hasChildNodes()&&!jt(e.firstElementChild)&&C(/<[/\w!]/g,e.innerHTML)&&C(/<[/\w!]/g,e.textContent))return zt(e),!0;if(Qe&&e.namespaceURI===At&&"style"===n&&jt(e.firstElementChild))return zt(e),!0;if(e.nodeType===ce)return zt(e),!0;if(Qe&&e.nodeType===se&&C(/<[/\w]/g,e.data))return zt(e),!0;if(Ye[n]||!(qe.tagCheck instanceof Function&&qe.tagCheck(n))&&!He[n]){if(!Ye[n]&&$t(n)){if(We.tagNameCheck instanceof RegExp&&C(We.tagNameCheck,n))return!1;if(We.tagNameCheck instanceof Function&&We.tagNameCheck(n))return!1}if(st&&!mt[n]){const t=Ae(e)||e.parentNode,n=be(e)||e.childNodes;if(n&&t){for(let o=n.length-1;o>=0;--o){const r=ge(n[o],!0);t.insertBefore(r,Te(e))}}}return zt(e),!0}return e instanceof m&&!function(e){let t=Ae(e);t&&t.tagName||(t={namespaceURI:St,tagName:"template"});const n=b(e.tagName),o=b(t.tagName);return!!Nt[e.namespaceURI]&&(e.namespaceURI===bt?t.namespaceURI===At?"svg"===n:t.namespaceURI===Tt?"svg"===n&&("annotation-xml"===o||Ot[o]):Boolean(Mt[n]):e.namespaceURI===Tt?t.namespaceURI===At?"math"===n:t.namespaceURI===bt?"math"===n&&Dt[o]:Boolean(Ft[n]):e.namespaceURI===At?!(t.namespaceURI===bt&&!Dt[o])&&!(t.namespaceURI===Tt&&!Ot[o])&&!Ft[n]&&(Rt[n]||!Mt[n]):!("application/xhtml+xml"!==wt||!Nt[e.namespaceURI]))}(e)?(zt(e),!0):"noscript"!==n&&"noembed"!==n&&"noframes"!==n||!C(/<\/no(script|embed|frames)/i,e.innerHTML)?(Je&&e.nodeType===le&&(t=e.textContent,p([Ce,xe,ke],e=>{t=E(t,e," ")}),e.textContent!==t&&(g(o.removed,{element:e.cloneNode()}),e.textContent=t)),Wt(ve.afterSanitizeElements,e,null),!1):(zt(e),!0)},Xt=function(e,t,n){if(Xe[t])return!1;if(at&&("id"===t||"name"===t)&&(n in r||n in xt))return!1;const o=Ge[t]||qe.attributeCheck instanceof Function&&qe.attributeCheck(t,e);if(Ke&&!Xe[t]&&C(Le,t));else if($e&&C(Me,t));else if(!o||Xe[t]){if(!($t(e)&&(We.tagNameCheck instanceof RegExp&&C(We.tagNameCheck,e)||We.tagNameCheck instanceof Function&&We.tagNameCheck(e))&&(We.attributeNameCheck instanceof RegExp&&C(We.attributeNameCheck,t)||We.attributeNameCheck instanceof Function&&We.attributeNameCheck(t,e))||"is"===t&&We.allowCustomizedBuiltInElements&&(We.tagNameCheck instanceof RegExp&&C(We.tagNameCheck,n)||We.tagNameCheck instanceof Function&&We.tagNameCheck(n))))return!1}else if(gt[t]);else if(C(Ue,E(n,ze,"")));else if("src"!==t&&"xlink:href"!==t&&"href"!==t||"script"===e||0!==N(n,"data:")||!dt[e]){if(Ve&&!C(Fe,E(n,ze,"")));else if(n)return!1}else;return!0},qt=M({},["annotation-xml","color-profile","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","missing-glyph"]),$t=function(e){return!qt[b(e)]&&C(Pe,e)},Kt=function(e){Wt(ve.beforeSanitizeAttributes,e,null);const t=e.attributes;if(!t||Gt(e))return;const n={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:Ge,forceKeepAttr:void 0};let r=t.length;for(;r--;){const i=t[r],a=i.name,l=i.namespaceURI,c=i.value,s=vt(a),u=c;let f="value"===a?u:_(u);if(n.attrName=s,n.attrValue=f,n.keepAttr=!0,n.forceKeepAttr=void 0,Wt(ve.uponSanitizeAttribute,e,n),f=n.attrValue,!lt||"id"!==s&&"name"!==s||0===N(f,ct)||(Pt(a,e),f=ct+f),Qe&&C(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,f)){Pt(a,e);continue}if("attributename"===s&&S(f,"href")){Pt(a,e);continue}if(n.forceKeepAttr)continue;if(!n.keepAttr){Pt(a,e);continue}if(!Ze&&C(/\/>/i,f)){Pt(a,e);continue}Je&&p([Ce,xe,ke],e=>{f=E(f,e," ")});const m=vt(e.nodeName);if(Xt(m,s,f)){if(Ee&&"object"==typeof de&&"function"==typeof de.getAttributeType)if(l);else switch(de.getAttributeType(m,s)){case"TrustedHTML":f=Ee.createHTML(f);break;case"TrustedScriptURL":f=Ee.createScriptURL(f)}if(f!==u)try{l?e.setAttributeNS(l,a,f):e.setAttribute(a,f),Gt(e)?zt(e):h(o.removed)}catch(t){Pt(a,e)}}else Pt(a,e)}Wt(ve.afterSanitizeAttributes,e,null)},Vt=function(e){let t=null;const n=Ht(e);for(Wt(ve.beforeSanitizeShadowDOM,e,null);t=n.nextNode();)Wt(ve.uponSanitizeShadowNode,t,null),Yt(t),Kt(t),t.content instanceof c&&Vt(t.content);Wt(ve.afterSanitizeShadowDOM,e,null)},Zt=function(e){if(e.nodeType===ae&&e.shadowRoot instanceof c){const t=e.shadowRoot;Zt(t),Vt(t)}const t=e.childNodes;if(!t)return;const n=[];p(t,e=>{g(n,e)});for(const e of n)Zt(e)};return o.sanitize=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=null,r=null,a=null,l=null;if(Et=!e,Et&&(e="\x3c!--\x3e"),"string"!=typeof e&&!jt(e)&&"string"!=typeof(e=function(e){switch(typeof e){case"string":return e;case"number":return O(e);case"boolean":return D(e);case"bigint":return R?R(e):"0";case"symbol":return w?w(e):"Symbol()";case"undefined":default:return v(e);case"function":case"object":{if(null===e)return v(e);const t=e,n=P(t,"toString");if("function"==typeof n){const e=n(t);return"string"==typeof e?e:v(e)}return v(e)}}}(e)))throw x("dirty is not a string, aborting");if(!o.isSupported)return e;if(tt||Lt(t),o.removed=[],"string"==typeof e&&(ut=!1),ut){const t=e.nodeName;if("string"==typeof t){const e=vt(t);if(!He[e]||Ye[e])throw x("root node is forbidden and cannot be sanitized in-place")}Zt(e)}else if(jt(e))n=Ut("\x3c!----\x3e"),r=n.ownerDocument.importNode(e,!0),r.nodeType===ae&&"BODY"===r.nodeName||"HTML"===r.nodeName?n=r:n.appendChild(r),Zt(r);else{if(!ot&&!Je&&!et&&-1===e.indexOf("<"))return Ee&&it?Ee.createHTML(e):e;if(n=Ut(e),!n)return ot?null:it?Ne:""}n&&nt&&zt(n.firstChild);const s=Ht(ut?e:n);for(;a=s.nextNode();)Yt(a),Kt(a),a.content instanceof c&&Vt(a.content);if(ut)return Je&&Bt(e),e;if(ot){if(Je&&Bt(n),rt)for(l=Re.call(n.ownerDocument);n.firstChild;)l.appendChild(n.firstChild);else l=n;return(Ge.shadowroot||Ge.shadowrootmode)&&(l=Ie.call(i,l,!0)),l}let u=et?n.outerHTML:n.innerHTML;return et&&He["!doctype"]&&n.ownerDocument&&n.ownerDocument.doctype&&n.ownerDocument.doctype.name&&C(re,n.ownerDocument.doctype.name)&&(u="<!DOCTYPE "+n.ownerDocument.doctype.name+">\n"+u),Je&&p([Ce,xe,ke],e=>{u=E(u,e," ")}),Ee&&it?Ee.createHTML(u):u},o.setConfig=function(){Lt(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),tt=!0},o.clearConfig=function(){Ct=null,tt=!1},o.isValidAttribute=function(e,t,n){Ct||Lt({});const o=vt(e),r=vt(t);return Xt(o,r,n)},o.addHook=function(e,t){"function"==typeof t&&g(ve[e],t)},o.removeHook=function(e,t){if(void 0!==t){const n=d(ve[e],t);return-1===n?void 0:y(ve[e],n,1)[0]}return h(ve[e])},o.removeHooks=function(e){ve[e]=[]},o.removeAllHooks=function(){ve={afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},o}();return me}); //# sourceMappingURL=purify.min.js.map