@goodpie/html-typer
Version:
Types out HTML into a view, supporting vanilla JS
5 lines (4 loc) • 23.8 kB
JavaScript
import e,{useRef as t,useEffect as n}from"react";function o(e,t,n,o){return new(n||(n=Promise))((function(r,i){function a(e){try{c(o.next(e))}catch(e){i(e)}}function l(e){try{c(o.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,l)}c((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;
/*! @license DOMPurify 3.2.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.2.4/LICENSE */
const{entries:r,setPrototypeOf:i,isFrozen:a,getPrototypeOf:l,getOwnPropertyDescriptor:c}=Object;let{freeze:s,seal:u,create:m}=Object,{apply:p,construct:f}="undefined"!=typeof Reflect&&Reflect;s||(s=function(e){return e}),u||(u=function(e){return e}),p||(p=function(e,t,n){return e.apply(t,n)}),f||(f=function(e,t){return new e(...t)});const d=O(Array.prototype.forEach),h=O(Array.prototype.lastIndexOf),g=O(Array.prototype.pop),T=O(Array.prototype.push),y=O(Array.prototype.splice),E=O(String.prototype.toLowerCase),N=O(String.prototype.toString),A=O(String.prototype.match),_=O(String.prototype.replace),S=O(String.prototype.indexOf),b=O(String.prototype.trim),w=O(Object.prototype.hasOwnProperty),v=O(RegExp.prototype.test),R=(C=TypeError,function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return f(C,t)});var C;function O(e){return function(t){for(var n=arguments.length,o=new Array(n>1?n-1:0),r=1;r<n;r++)o[r-1]=arguments[r];return p(e,t,o)}}function x(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:E;i&&i(e,null);let o=t.length;for(;o--;){let r=t[o];if("string"==typeof r){const e=n(r);e!==r&&(a(t)||(t[o]=e),r=e)}e[r]=!0}return e}function L(e){for(let t=0;t<e.length;t++){w(e,t)||(e[t]=null)}return e}function D(e){const t=m(null);for(const[n,o]of r(e)){w(e,n)&&(Array.isArray(o)?t[n]=L(o):o&&"object"==typeof o&&o.constructor===Object?t[n]=D(o):t[n]=o)}return t}function M(e,t){for(;null!==e;){const n=c(e,t);if(n){if(n.get)return O(n.get);if("function"==typeof n.value)return O(n.value)}e=l(e)}return function(){return null}}const I=s(["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","section","select","shadow","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"]),k=s(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","filter","font","g","glyph","glyphref","hkern","image","line","lineargradient","marker","mask","metadata","mpath","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),P=s(["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"]),U=s(["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"]),z=s(["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"]),H=s(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),F=s(["#text"]),B=s(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","face","for","headers","height","hidden","high","href","hreflang","id","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","pattern","placeholder","playsinline","popover","popovertarget","popovertargetaction","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","span","srclang","start","src","srcset","step","style","summary","tabindex","title","translate","type","usemap","valign","value","width","wrap","xmlns","slot"]),W=s(["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","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"]),G=s(["accent","accentunder","align","bevelled","close","columnsalign","columnlines","columnspan","denomalign","depth","dir","display","displaystyle","encoding","fence","frame","height","href","id","largeop","length","linethickness","lspace","lquote","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"]),Y=s(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),j=u(/\{\{[\w\W]*|[\w\W]*\}\}/gm),X=u(/<%[\w\W]*|[\w\W]*%>/gm),q=u(/\$\{[\w\W]*/gm),$=u(/^data-[\-\w.\u00B7-\uFFFF]+$/),K=u(/^aria-[\-\w]+$/),V=u(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),Z=u(/^(?:\w+script|data):/i),J=u(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),Q=u(/^html$/i),ee=u(/^[a-z][.\w]*(-[.\w]+)+$/i);var te=Object.freeze({__proto__:null,ARIA_ATTR:K,ATTR_WHITESPACE:J,CUSTOM_ELEMENT:ee,DATA_ATTR:$,DOCTYPE_NAME:Q,ERB_EXPR:X,IS_ALLOWED_URI:V,IS_SCRIPT_OR_DATA:Z,MUSTACHE_EXPR:j,TMPLIT_EXPR:q});const ne=1,oe=3,re=7,ie=8,ae=9,le=function(){return"undefined"==typeof window?null:window};var ce=function e(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:le();const n=t=>e(t);if(n.version="3.2.4",n.removed=[],!t||!t.document||t.document.nodeType!==ae||!t.Element)return n.isSupported=!1,n;let{document:o}=t;const i=o,a=i.currentScript,{DocumentFragment:l,HTMLTemplateElement:c,Node:u,Element:p,NodeFilter:f,NamedNodeMap:C=t.NamedNodeMap||t.MozNamedAttrMap,HTMLFormElement:O,DOMParser:L,trustedTypes:j}=t,X=p.prototype,q=M(X,"cloneNode"),$=M(X,"remove"),K=M(X,"nextSibling"),Z=M(X,"childNodes"),J=M(X,"parentNode");if("function"==typeof c){const e=o.createElement("template");e.content&&e.content.ownerDocument&&(o=e.content.ownerDocument)}let ee,ce="";const{implementation:se,createNodeIterator:ue,createDocumentFragment:me,getElementsByTagName:pe}=o,{importNode:fe}=i;let de={afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]};n.isSupported="function"==typeof r&&"function"==typeof J&&se&&void 0!==se.createHTMLDocument;const{MUSTACHE_EXPR:he,ERB_EXPR:ge,TMPLIT_EXPR:Te,DATA_ATTR:ye,ARIA_ATTR:Ee,IS_SCRIPT_OR_DATA:Ne,ATTR_WHITESPACE:Ae,CUSTOM_ELEMENT:_e}=te;let{IS_ALLOWED_URI:Se}=te,be=null;const we=x({},[...I,...k,...P,...z,...F]);let ve=null;const Re=x({},[...B,...W,...G,...Y]);let Ce=Object.seal(m(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}})),Oe=null,xe=null,Le=!0,De=!0,Me=!1,Ie=!0,ke=!1,Pe=!0,Ue=!1,ze=!1,He=!1,Fe=!1,Be=!1,We=!1,Ge=!0,Ye=!1,je=!0,Xe=!1,qe={},$e=null;const Ke=x({},["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 Ve=null;const Ze=x({},["audio","video","img","source","image","track"]);let Je=null;const Qe=x({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),et="http://www.w3.org/1998/Math/MathML",tt="http://www.w3.org/2000/svg",nt="http://www.w3.org/1999/xhtml";let ot=nt,rt=!1,it=null;const at=x({},[et,tt,nt],N);let lt=x({},["mi","mo","mn","ms","mtext"]),ct=x({},["annotation-xml"]);const st=x({},["title","style","font","a","script"]);let ut=null;const mt=["application/xhtml+xml","text/html"];let pt=null,ft=null;const dt=o.createElement("form"),ht=function(e){return e instanceof RegExp||e instanceof Function},gt=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!ft||ft!==e){if(e&&"object"==typeof e||(e={}),e=D(e),ut=-1===mt.indexOf(e.PARSER_MEDIA_TYPE)?"text/html":e.PARSER_MEDIA_TYPE,pt="application/xhtml+xml"===ut?N:E,be=w(e,"ALLOWED_TAGS")?x({},e.ALLOWED_TAGS,pt):we,ve=w(e,"ALLOWED_ATTR")?x({},e.ALLOWED_ATTR,pt):Re,it=w(e,"ALLOWED_NAMESPACES")?x({},e.ALLOWED_NAMESPACES,N):at,Je=w(e,"ADD_URI_SAFE_ATTR")?x(D(Qe),e.ADD_URI_SAFE_ATTR,pt):Qe,Ve=w(e,"ADD_DATA_URI_TAGS")?x(D(Ze),e.ADD_DATA_URI_TAGS,pt):Ze,$e=w(e,"FORBID_CONTENTS")?x({},e.FORBID_CONTENTS,pt):Ke,Oe=w(e,"FORBID_TAGS")?x({},e.FORBID_TAGS,pt):{},xe=w(e,"FORBID_ATTR")?x({},e.FORBID_ATTR,pt):{},qe=!!w(e,"USE_PROFILES")&&e.USE_PROFILES,Le=!1!==e.ALLOW_ARIA_ATTR,De=!1!==e.ALLOW_DATA_ATTR,Me=e.ALLOW_UNKNOWN_PROTOCOLS||!1,Ie=!1!==e.ALLOW_SELF_CLOSE_IN_ATTR,ke=e.SAFE_FOR_TEMPLATES||!1,Pe=!1!==e.SAFE_FOR_XML,Ue=e.WHOLE_DOCUMENT||!1,Fe=e.RETURN_DOM||!1,Be=e.RETURN_DOM_FRAGMENT||!1,We=e.RETURN_TRUSTED_TYPE||!1,He=e.FORCE_BODY||!1,Ge=!1!==e.SANITIZE_DOM,Ye=e.SANITIZE_NAMED_PROPS||!1,je=!1!==e.KEEP_CONTENT,Xe=e.IN_PLACE||!1,Se=e.ALLOWED_URI_REGEXP||V,ot=e.NAMESPACE||nt,lt=e.MATHML_TEXT_INTEGRATION_POINTS||lt,ct=e.HTML_INTEGRATION_POINTS||ct,Ce=e.CUSTOM_ELEMENT_HANDLING||{},e.CUSTOM_ELEMENT_HANDLING&&ht(e.CUSTOM_ELEMENT_HANDLING.tagNameCheck)&&(Ce.tagNameCheck=e.CUSTOM_ELEMENT_HANDLING.tagNameCheck),e.CUSTOM_ELEMENT_HANDLING&&ht(e.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)&&(Ce.attributeNameCheck=e.CUSTOM_ELEMENT_HANDLING.attributeNameCheck),e.CUSTOM_ELEMENT_HANDLING&&"boolean"==typeof e.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements&&(Ce.allowCustomizedBuiltInElements=e.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements),ke&&(De=!1),Be&&(Fe=!0),qe&&(be=x({},F),ve=[],!0===qe.html&&(x(be,I),x(ve,B)),!0===qe.svg&&(x(be,k),x(ve,W),x(ve,Y)),!0===qe.svgFilters&&(x(be,P),x(ve,W),x(ve,Y)),!0===qe.mathMl&&(x(be,z),x(ve,G),x(ve,Y))),e.ADD_TAGS&&(be===we&&(be=D(be)),x(be,e.ADD_TAGS,pt)),e.ADD_ATTR&&(ve===Re&&(ve=D(ve)),x(ve,e.ADD_ATTR,pt)),e.ADD_URI_SAFE_ATTR&&x(Je,e.ADD_URI_SAFE_ATTR,pt),e.FORBID_CONTENTS&&($e===Ke&&($e=D($e)),x($e,e.FORBID_CONTENTS,pt)),je&&(be["#text"]=!0),Ue&&x(be,["html","head","body"]),be.table&&(x(be,["tbody"]),delete Oe.tbody),e.TRUSTED_TYPES_POLICY){if("function"!=typeof e.TRUSTED_TYPES_POLICY.createHTML)throw R('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if("function"!=typeof e.TRUSTED_TYPES_POLICY.createScriptURL)throw R('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');ee=e.TRUSTED_TYPES_POLICY,ce=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}}(j,a)),null!==ee&&"string"==typeof ce&&(ce=ee.createHTML(""));s&&s(e),ft=e}},Tt=x({},[...k,...P,...U]),yt=x({},[...z,...H]),Et=function(e){T(n.removed,{element:e});try{J(e).removeChild(e)}catch(t){$(e)}},Nt=function(e,t){try{T(n.removed,{attribute:t.getAttributeNode(e),from:t})}catch(e){T(n.removed,{attribute:null,from:t})}if(t.removeAttribute(e),"is"===e)if(Fe||Be)try{Et(t)}catch(e){}else try{t.setAttribute(e,"")}catch(e){}},At=function(e){let t=null,n=null;if(He)e="<remove></remove>"+e;else{const t=A(e,/^[\r\n\t ]+/);n=t&&t[0]}"application/xhtml+xml"===ut&&ot===nt&&(e='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+e+"</body></html>");const r=ee?ee.createHTML(e):e;if(ot===nt)try{t=(new L).parseFromString(r,ut)}catch(e){}if(!t||!t.documentElement){t=se.createDocument(ot,"template",null);try{t.documentElement.innerHTML=rt?ce:r}catch(e){}}const i=t.body||t.documentElement;return e&&n&&i.insertBefore(o.createTextNode(n),i.childNodes[0]||null),ot===nt?pe.call(t,Ue?"html":"body")[0]:Ue?t.documentElement:i},_t=function(e){return ue.call(e.ownerDocument||e,e,f.SHOW_ELEMENT|f.SHOW_COMMENT|f.SHOW_TEXT|f.SHOW_PROCESSING_INSTRUCTION|f.SHOW_CDATA_SECTION,null)},St=function(e){return e instanceof O&&("string"!=typeof e.nodeName||"string"!=typeof e.textContent||"function"!=typeof e.removeChild||!(e.attributes instanceof C)||"function"!=typeof e.removeAttribute||"function"!=typeof e.setAttribute||"string"!=typeof e.namespaceURI||"function"!=typeof e.insertBefore||"function"!=typeof e.hasChildNodes)},bt=function(e){return"function"==typeof u&&e instanceof u};function wt(e,t,o){d(e,(e=>{e.call(n,t,o,ft)}))}const vt=function(e){let t=null;if(wt(de.beforeSanitizeElements,e,null),St(e))return Et(e),!0;const o=pt(e.nodeName);if(wt(de.uponSanitizeElement,e,{tagName:o,allowedTags:be}),e.hasChildNodes()&&!bt(e.firstElementChild)&&v(/<[/\w]/g,e.innerHTML)&&v(/<[/\w]/g,e.textContent))return Et(e),!0;if(e.nodeType===re)return Et(e),!0;if(Pe&&e.nodeType===ie&&v(/<[/\w]/g,e.data))return Et(e),!0;if(!be[o]||Oe[o]){if(!Oe[o]&&Ct(o)){if(Ce.tagNameCheck instanceof RegExp&&v(Ce.tagNameCheck,o))return!1;if(Ce.tagNameCheck instanceof Function&&Ce.tagNameCheck(o))return!1}if(je&&!$e[o]){const t=J(e)||e.parentNode,n=Z(e)||e.childNodes;if(n&&t){for(let o=n.length-1;o>=0;--o){const r=q(n[o],!0);r.__removalCount=(e.__removalCount||0)+1,t.insertBefore(r,K(e))}}}return Et(e),!0}return e instanceof p&&!function(e){let t=J(e);t&&t.tagName||(t={namespaceURI:ot,tagName:"template"});const n=E(e.tagName),o=E(t.tagName);return!!it[e.namespaceURI]&&(e.namespaceURI===tt?t.namespaceURI===nt?"svg"===n:t.namespaceURI===et?"svg"===n&&("annotation-xml"===o||lt[o]):Boolean(Tt[n]):e.namespaceURI===et?t.namespaceURI===nt?"math"===n:t.namespaceURI===tt?"math"===n&&ct[o]:Boolean(yt[n]):e.namespaceURI===nt?!(t.namespaceURI===tt&&!ct[o])&&!(t.namespaceURI===et&&!lt[o])&&!yt[n]&&(st[n]||!Tt[n]):!("application/xhtml+xml"!==ut||!it[e.namespaceURI]))}(e)?(Et(e),!0):"noscript"!==o&&"noembed"!==o&&"noframes"!==o||!v(/<\/no(script|embed|frames)/i,e.innerHTML)?(ke&&e.nodeType===oe&&(t=e.textContent,d([he,ge,Te],(e=>{t=_(t,e," ")})),e.textContent!==t&&(T(n.removed,{element:e.cloneNode()}),e.textContent=t)),wt(de.afterSanitizeElements,e,null),!1):(Et(e),!0)},Rt=function(e,t,n){if(Ge&&("id"===t||"name"===t)&&(n in o||n in dt))return!1;if(De&&!xe[t]&&v(ye,t));else if(Le&&v(Ee,t));else if(!ve[t]||xe[t]){if(!(Ct(e)&&(Ce.tagNameCheck instanceof RegExp&&v(Ce.tagNameCheck,e)||Ce.tagNameCheck instanceof Function&&Ce.tagNameCheck(e))&&(Ce.attributeNameCheck instanceof RegExp&&v(Ce.attributeNameCheck,t)||Ce.attributeNameCheck instanceof Function&&Ce.attributeNameCheck(t))||"is"===t&&Ce.allowCustomizedBuiltInElements&&(Ce.tagNameCheck instanceof RegExp&&v(Ce.tagNameCheck,n)||Ce.tagNameCheck instanceof Function&&Ce.tagNameCheck(n))))return!1}else if(Je[t]);else if(v(Se,_(n,Ae,"")));else if("src"!==t&&"xlink:href"!==t&&"href"!==t||"script"===e||0!==S(n,"data:")||!Ve[e]){if(Me&&!v(Ne,_(n,Ae,"")));else if(n)return!1}else;return!0},Ct=function(e){return"annotation-xml"!==e&&A(e,_e)},Ot=function(e){wt(de.beforeSanitizeAttributes,e,null);const{attributes:t}=e;if(!t||St(e))return;const o={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:ve,forceKeepAttr:void 0};let r=t.length;for(;r--;){const i=t[r],{name:a,namespaceURI:l,value:c}=i,s=pt(a);let u="value"===a?c:b(c);if(o.attrName=s,o.attrValue=u,o.keepAttr=!0,o.forceKeepAttr=void 0,wt(de.uponSanitizeAttribute,e,o),u=o.attrValue,!Ye||"id"!==s&&"name"!==s||(Nt(a,e),u="user-content-"+u),Pe&&v(/((--!?|])>)|<\/(style|title)/i,u)){Nt(a,e);continue}if(o.forceKeepAttr)continue;if(Nt(a,e),!o.keepAttr)continue;if(!Ie&&v(/\/>/i,u)){Nt(a,e);continue}ke&&d([he,ge,Te],(e=>{u=_(u,e," ")}));const m=pt(e.nodeName);if(Rt(m,s,u)){if(ee&&"object"==typeof j&&"function"==typeof j.getAttributeType)if(l);else switch(j.getAttributeType(m,s)){case"TrustedHTML":u=ee.createHTML(u);break;case"TrustedScriptURL":u=ee.createScriptURL(u)}try{l?e.setAttributeNS(l,a,u):e.setAttribute(a,u),St(e)?Et(e):g(n.removed)}catch(e){}}}wt(de.afterSanitizeAttributes,e,null)},xt=function e(t){let n=null;const o=_t(t);for(wt(de.beforeSanitizeShadowDOM,t,null);n=o.nextNode();)wt(de.uponSanitizeShadowNode,n,null),vt(n),Ot(n),n.content instanceof l&&e(n.content);wt(de.afterSanitizeShadowDOM,t,null)};return n.sanitize=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=null,r=null,a=null,c=null;if(rt=!e,rt&&(e="\x3c!--\x3e"),"string"!=typeof e&&!bt(e)){if("function"!=typeof e.toString)throw R("toString is not a function");if("string"!=typeof(e=e.toString()))throw R("dirty is not a string, aborting")}if(!n.isSupported)return e;if(ze||gt(t),n.removed=[],"string"==typeof e&&(Xe=!1),Xe){if(e.nodeName){const t=pt(e.nodeName);if(!be[t]||Oe[t])throw R("root node is forbidden and cannot be sanitized in-place")}}else if(e instanceof u)o=At("\x3c!----\x3e"),r=o.ownerDocument.importNode(e,!0),r.nodeType===ne&&"BODY"===r.nodeName||"HTML"===r.nodeName?o=r:o.appendChild(r);else{if(!Fe&&!ke&&!Ue&&-1===e.indexOf("<"))return ee&&We?ee.createHTML(e):e;if(o=At(e),!o)return Fe?null:We?ce:""}o&&He&&Et(o.firstChild);const s=_t(Xe?e:o);for(;a=s.nextNode();)vt(a),Ot(a),a.content instanceof l&&xt(a.content);if(Xe)return e;if(Fe){if(Be)for(c=me.call(o.ownerDocument);o.firstChild;)c.appendChild(o.firstChild);else c=o;return(ve.shadowroot||ve.shadowrootmode)&&(c=fe.call(i,c,!0)),c}let m=Ue?o.outerHTML:o.innerHTML;return Ue&&be["!doctype"]&&o.ownerDocument&&o.ownerDocument.doctype&&o.ownerDocument.doctype.name&&v(Q,o.ownerDocument.doctype.name)&&(m="<!DOCTYPE "+o.ownerDocument.doctype.name+">\n"+m),ke&&d([he,ge,Te],(e=>{m=_(m,e," ")})),ee&&We?ee.createHTML(m):m},n.setConfig=function(){gt(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),ze=!0},n.clearConfig=function(){ft=null,ze=!1},n.isValidAttribute=function(e,t,n){ft||gt({});const o=pt(e),r=pt(t);return Rt(o,r,n)},n.addHook=function(e,t){"function"==typeof t&&T(de[e],t)},n.removeHook=function(e,t){if(void 0!==t){const n=h(de[e],t);return-1===n?void 0:y(de[e],n,1)[0]}return g(de[e])},n.removeHooks=function(e){de[e]=[]},n.removeAllHooks=function(){de={afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},n}();const se=e=>{const t=(new DOMParser).parseFromString(e,"text/html"),n=[],o=(e,t=null)=>{if(e.nodeType===Node.ELEMENT_NODE){const r={tagName:e.tagName.toLowerCase(),classes:e.className?e.className.split(/\s+/).filter((e=>!!e)):[],children:[]};t?t.children.push(r):n.push(r),e.childNodes.forEach((e=>o(e,r)))}else if(e.nodeType===Node.TEXT_NODE&&e.textContent&&e.textContent.trim()){const o={tagName:"#text",content:e.textContent.trim()};t?t.children.push(o):n.push(o)}};return t.body.childNodes.forEach((e=>o(e))),n},ue=({html:r,speed:i=50,className:a,style:l})=>{const c=t(null);return n((()=>{c.current&&((e,t,...n)=>{o(void 0,[e,t,...n],void 0,(function*(e,t,n=50){n=Math.max(1,n);const r=ce.sanitize(t);e.innerHTML="";const i=se(r),a=(t,n,o)=>new Promise((r=>{let i=0;const a=setInterval((()=>{i<n.length?t.textContent+=n[i++]:(clearInterval(a),r()),requestAnimationFrame((()=>{e.parentElement&&(e.parentElement.scrollTop=e.parentElement.scrollHeight)}))}),o)})),l=(e,t,n)=>o(void 0,void 0,void 0,(function*(){for(const o of e)if("#text"===o.tagName){const e=document.createTextNode("");t.appendChild(e),yield a(e,o.content||"",n)}else{const e=document.createElement(o.tagName);o.classes&&o.classes.length>0&&e.classList.add(...o.classes),t.appendChild(e),o.content&&(yield a(e,o.content,n)),o.children&&o.children.length>0&&(yield l(o.children,e,n))}}));yield l(i,e,n)}))})(c.current,r,i)}),[r,i]),e.createElement("div",{ref:c,className:a,style:l})};export{ue as HtmlTyper};
//# sourceMappingURL=react.esm.js.map