UNPKG

@goodpie/html-typer

Version:

Types out HTML into a view, supporting vanilla JS

5 lines (4 loc) 25.5 kB
function e(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 t(e,t){var n,o,r,i={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=l(0),a.throw=l(1),a.return=l(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function l(l){return function(c){return function(l){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,l[0]&&(i=0)),i;)try{if(n=1,o&&(r=2&l[0]?o.return:l[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,l[1])).done)return r;switch(o=0,r&&(l=[2&l[0],r.value]),l[0]){case 0:case 1:r=l;break;case 4:return i.label++,{value:l[1],done:!1};case 5:i.label++,o=l[1],l=[0];continue;case 7:l=i.ops.pop(),i.trys.pop();continue;default:if(!(r=i.trys,(r=r.length>0&&r[r.length-1])||6!==l[0]&&2!==l[0])){i=0;continue}if(3===l[0]&&(!r||l[1]>r[0]&&l[1]<r[3])){i.label=l[1];break}if(6===l[0]&&i.label<r[1]){i.label=r[1],r=l;break}if(r&&i.label<r[2]){i.label=r[2],i.ops.push(l);break}r[2]&&i.ops.pop(),i.trys.pop();continue}l=t.call(e,i)}catch(e){l=[6,e],o=0}finally{n=r=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}([l,c])}}}"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:n,setPrototypeOf:o,isFrozen:r,getPrototypeOf:i,getOwnPropertyDescriptor:a}=Object;let{freeze:l,seal:c,create:s}=Object,{apply:u,construct:p}="undefined"!=typeof Reflect&&Reflect;l||(l=function(e){return e}),c||(c=function(e){return e}),u||(u=function(e,t,n){return e.apply(t,n)}),p||(p=function(e,t){return new e(...t)});const m=R(Array.prototype.forEach),f=R(Array.prototype.lastIndexOf),d=R(Array.prototype.pop),h=R(Array.prototype.push),g=R(Array.prototype.splice),T=R(String.prototype.toLowerCase),y=R(String.prototype.toString),E=R(String.prototype.match),b=R(String.prototype.replace),A=R(String.prototype.indexOf),N=R(String.prototype.trim),_=R(Object.prototype.hasOwnProperty),S=R(RegExp.prototype.test),v=(w=TypeError,function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return p(w,t)});var w;function R(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 u(e,t,o)}}function x(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:T;o&&o(e,null);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 O(e){for(let t=0;t<e.length;t++){_(e,t)||(e[t]=null)}return e}function C(e){const t=s(null);for(const[o,r]of n(e)){_(e,o)&&(Array.isArray(r)?t[o]=O(r):r&&"object"==typeof r&&r.constructor===Object?t[o]=C(r):t[o]=r)}return t}function L(e,t){for(;null!==e;){const n=a(e,t);if(n){if(n.get)return R(n.get);if("function"==typeof n.value)return R(n.value)}e=i(e)}return function(){return null}}const D=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","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=l(["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"]),I=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"]),M=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"]),P=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"]),U=l(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),z=l(["#text"]),H=l(["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"]),F=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","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"]),B=l(["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"]),W=l(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),G=c(/\{\{[\w\W]*|[\w\W]*\}\}/gm),Y=c(/<%[\w\W]*|[\w\W]*%>/gm),j=c(/\$\{[\w\W]*/gm),X=c(/^data-[\-\w.\u00B7-\uFFFF]+$/),q=c(/^aria-[\-\w]+$/),$=c(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),K=c(/^(?:\w+script|data):/i),V=c(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),Z=c(/^html$/i),J=c(/^[a-z][.\w]*(-[.\w]+)+$/i);var Q=Object.freeze({__proto__:null,ARIA_ATTR:q,ATTR_WHITESPACE:V,CUSTOM_ELEMENT:J,DATA_ATTR:X,DOCTYPE_NAME:Z,ERB_EXPR:Y,IS_ALLOWED_URI:$,IS_SCRIPT_OR_DATA:K,MUSTACHE_EXPR:G,TMPLIT_EXPR:j});const ee=1,te=3,ne=7,oe=8,re=9,ie=function(){return"undefined"==typeof window?null:window};var ae=function e(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:ie();const o=t=>e(t);if(o.version="3.2.4",o.removed=[],!t||!t.document||t.document.nodeType!==re||!t.Element)return o.isSupported=!1,o;let{document:r}=t;const i=r,a=i.currentScript,{DocumentFragment:c,HTMLTemplateElement:u,Node:p,Element:w,NodeFilter:R,NamedNodeMap:O=t.NamedNodeMap||t.MozNamedAttrMap,HTMLFormElement:G,DOMParser:Y,trustedTypes:j}=t,X=w.prototype,q=L(X,"cloneNode"),K=L(X,"remove"),V=L(X,"nextSibling"),J=L(X,"childNodes"),ae=L(X,"parentNode");if("function"==typeof u){const e=r.createElement("template");e.content&&e.content.ownerDocument&&(r=e.content.ownerDocument)}let le,ce="";const{implementation:se,createNodeIterator:ue,createDocumentFragment:pe,getElementsByTagName:me}=r,{importNode:fe}=i;let de={afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]};o.isSupported="function"==typeof n&&"function"==typeof ae&&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:be,ATTR_WHITESPACE:Ae,CUSTOM_ELEMENT:Ne}=Q;let{IS_ALLOWED_URI:_e}=Q,Se=null;const ve=x({},[...D,...k,...I,...P,...z]);let we=null;const Re=x({},[...H,...F,...B,...W]);let xe=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}})),Oe=null,Ce=null,Le=!0,De=!0,ke=!1,Ie=!0,Me=!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],y);let lt=x({},["mi","mo","mn","ms","mtext"]),ct=x({},["annotation-xml"]);const st=x({},["title","style","font","a","script"]);let ut=null;const pt=["application/xhtml+xml","text/html"];let mt=null,ft=null;const dt=r.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=C(e),ut=-1===pt.indexOf(e.PARSER_MEDIA_TYPE)?"text/html":e.PARSER_MEDIA_TYPE,mt="application/xhtml+xml"===ut?y:T,Se=_(e,"ALLOWED_TAGS")?x({},e.ALLOWED_TAGS,mt):ve,we=_(e,"ALLOWED_ATTR")?x({},e.ALLOWED_ATTR,mt):Re,it=_(e,"ALLOWED_NAMESPACES")?x({},e.ALLOWED_NAMESPACES,y):at,Je=_(e,"ADD_URI_SAFE_ATTR")?x(C(Qe),e.ADD_URI_SAFE_ATTR,mt):Qe,Ve=_(e,"ADD_DATA_URI_TAGS")?x(C(Ze),e.ADD_DATA_URI_TAGS,mt):Ze,$e=_(e,"FORBID_CONTENTS")?x({},e.FORBID_CONTENTS,mt):Ke,Oe=_(e,"FORBID_TAGS")?x({},e.FORBID_TAGS,mt):{},Ce=_(e,"FORBID_ATTR")?x({},e.FORBID_ATTR,mt):{},qe=!!_(e,"USE_PROFILES")&&e.USE_PROFILES,Le=!1!==e.ALLOW_ARIA_ATTR,De=!1!==e.ALLOW_DATA_ATTR,ke=e.ALLOW_UNKNOWN_PROTOCOLS||!1,Ie=!1!==e.ALLOW_SELF_CLOSE_IN_ATTR,Me=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,_e=e.ALLOWED_URI_REGEXP||$,ot=e.NAMESPACE||nt,lt=e.MATHML_TEXT_INTEGRATION_POINTS||lt,ct=e.HTML_INTEGRATION_POINTS||ct,xe=e.CUSTOM_ELEMENT_HANDLING||{},e.CUSTOM_ELEMENT_HANDLING&&ht(e.CUSTOM_ELEMENT_HANDLING.tagNameCheck)&&(xe.tagNameCheck=e.CUSTOM_ELEMENT_HANDLING.tagNameCheck),e.CUSTOM_ELEMENT_HANDLING&&ht(e.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)&&(xe.attributeNameCheck=e.CUSTOM_ELEMENT_HANDLING.attributeNameCheck),e.CUSTOM_ELEMENT_HANDLING&&"boolean"==typeof e.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements&&(xe.allowCustomizedBuiltInElements=e.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements),Me&&(De=!1),Be&&(Fe=!0),qe&&(Se=x({},z),we=[],!0===qe.html&&(x(Se,D),x(we,H)),!0===qe.svg&&(x(Se,k),x(we,F),x(we,W)),!0===qe.svgFilters&&(x(Se,I),x(we,F),x(we,W)),!0===qe.mathMl&&(x(Se,P),x(we,B),x(we,W))),e.ADD_TAGS&&(Se===ve&&(Se=C(Se)),x(Se,e.ADD_TAGS,mt)),e.ADD_ATTR&&(we===Re&&(we=C(we)),x(we,e.ADD_ATTR,mt)),e.ADD_URI_SAFE_ATTR&&x(Je,e.ADD_URI_SAFE_ATTR,mt),e.FORBID_CONTENTS&&($e===Ke&&($e=C($e)),x($e,e.FORBID_CONTENTS,mt)),je&&(Se["#text"]=!0),Ue&&x(Se,["html","head","body"]),Se.table&&(x(Se,["tbody"]),delete Oe.tbody),e.TRUSTED_TYPES_POLICY){if("function"!=typeof e.TRUSTED_TYPES_POLICY.createHTML)throw v('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if("function"!=typeof e.TRUSTED_TYPES_POLICY.createScriptURL)throw v('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');le=e.TRUSTED_TYPES_POLICY,ce=le.createHTML("")}else void 0===le&&(le=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!==le&&"string"==typeof ce&&(ce=le.createHTML(""));l&&l(e),ft=e}},Tt=x({},[...k,...I,...M]),yt=x({},[...P,...U]),Et=function(e){h(o.removed,{element:e});try{ae(e).removeChild(e)}catch(t){K(e)}},bt=function(e,t){try{h(o.removed,{attribute:t.getAttributeNode(e),from:t})}catch(e){h(o.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=E(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 o=le?le.createHTML(e):e;if(ot===nt)try{t=(new Y).parseFromString(o,ut)}catch(e){}if(!t||!t.documentElement){t=se.createDocument(ot,"template",null);try{t.documentElement.innerHTML=rt?ce:o}catch(e){}}const i=t.body||t.documentElement;return e&&n&&i.insertBefore(r.createTextNode(n),i.childNodes[0]||null),ot===nt?me.call(t,Ue?"html":"body")[0]:Ue?t.documentElement:i},Nt=function(e){return ue.call(e.ownerDocument||e,e,R.SHOW_ELEMENT|R.SHOW_COMMENT|R.SHOW_TEXT|R.SHOW_PROCESSING_INSTRUCTION|R.SHOW_CDATA_SECTION,null)},_t=function(e){return e instanceof G&&("string"!=typeof e.nodeName||"string"!=typeof e.textContent||"function"!=typeof e.removeChild||!(e.attributes instanceof O)||"function"!=typeof e.removeAttribute||"function"!=typeof e.setAttribute||"string"!=typeof e.namespaceURI||"function"!=typeof e.insertBefore||"function"!=typeof e.hasChildNodes)},St=function(e){return"function"==typeof p&&e instanceof p};function vt(e,t,n){m(e,(e=>{e.call(o,t,n,ft)}))}const wt=function(e){let t=null;if(vt(de.beforeSanitizeElements,e,null),_t(e))return Et(e),!0;const n=mt(e.nodeName);if(vt(de.uponSanitizeElement,e,{tagName:n,allowedTags:Se}),e.hasChildNodes()&&!St(e.firstElementChild)&&S(/<[/\w]/g,e.innerHTML)&&S(/<[/\w]/g,e.textContent))return Et(e),!0;if(e.nodeType===ne)return Et(e),!0;if(Pe&&e.nodeType===oe&&S(/<[/\w]/g,e.data))return Et(e),!0;if(!Se[n]||Oe[n]){if(!Oe[n]&&xt(n)){if(xe.tagNameCheck instanceof RegExp&&S(xe.tagNameCheck,n))return!1;if(xe.tagNameCheck instanceof Function&&xe.tagNameCheck(n))return!1}if(je&&!$e[n]){const t=ae(e)||e.parentNode,n=J(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,V(e))}}}return Et(e),!0}return e instanceof w&&!function(e){let t=ae(e);t&&t.tagName||(t={namespaceURI:ot,tagName:"template"});const n=T(e.tagName),o=T(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"!==n&&"noembed"!==n&&"noframes"!==n||!S(/<\/no(script|embed|frames)/i,e.innerHTML)?(Me&&e.nodeType===te&&(t=e.textContent,m([he,ge,Te],(e=>{t=b(t,e," ")})),e.textContent!==t&&(h(o.removed,{element:e.cloneNode()}),e.textContent=t)),vt(de.afterSanitizeElements,e,null),!1):(Et(e),!0)},Rt=function(e,t,n){if(Ge&&("id"===t||"name"===t)&&(n in r||n in dt))return!1;if(De&&!Ce[t]&&S(ye,t));else if(Le&&S(Ee,t));else if(!we[t]||Ce[t]){if(!(xt(e)&&(xe.tagNameCheck instanceof RegExp&&S(xe.tagNameCheck,e)||xe.tagNameCheck instanceof Function&&xe.tagNameCheck(e))&&(xe.attributeNameCheck instanceof RegExp&&S(xe.attributeNameCheck,t)||xe.attributeNameCheck instanceof Function&&xe.attributeNameCheck(t))||"is"===t&&xe.allowCustomizedBuiltInElements&&(xe.tagNameCheck instanceof RegExp&&S(xe.tagNameCheck,n)||xe.tagNameCheck instanceof Function&&xe.tagNameCheck(n))))return!1}else if(Je[t]);else if(S(_e,b(n,Ae,"")));else if("src"!==t&&"xlink:href"!==t&&"href"!==t||"script"===e||0!==A(n,"data:")||!Ve[e]){if(ke&&!S(be,b(n,Ae,"")));else if(n)return!1}else;return!0},xt=function(e){return"annotation-xml"!==e&&E(e,Ne)},Ot=function(e){vt(de.beforeSanitizeAttributes,e,null);const{attributes:t}=e;if(!t||_t(e))return;const n={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:we,forceKeepAttr:void 0};let r=t.length;for(;r--;){const i=t[r],{name:a,namespaceURI:l,value:c}=i,s=mt(a);let u="value"===a?c:N(c);if(n.attrName=s,n.attrValue=u,n.keepAttr=!0,n.forceKeepAttr=void 0,vt(de.uponSanitizeAttribute,e,n),u=n.attrValue,!Ye||"id"!==s&&"name"!==s||(bt(a,e),u="user-content-"+u),Pe&&S(/((--!?|])>)|<\/(style|title)/i,u)){bt(a,e);continue}if(n.forceKeepAttr)continue;if(bt(a,e),!n.keepAttr)continue;if(!Ie&&S(/\/>/i,u)){bt(a,e);continue}Me&&m([he,ge,Te],(e=>{u=b(u,e," ")}));const p=mt(e.nodeName);if(Rt(p,s,u)){if(le&&"object"==typeof j&&"function"==typeof j.getAttributeType)if(l);else switch(j.getAttributeType(p,s)){case"TrustedHTML":u=le.createHTML(u);break;case"TrustedScriptURL":u=le.createScriptURL(u)}try{l?e.setAttributeNS(l,a,u):e.setAttribute(a,u),_t(e)?Et(e):d(o.removed)}catch(e){}}}vt(de.afterSanitizeAttributes,e,null)},Ct=function e(t){let n=null;const o=Nt(t);for(vt(de.beforeSanitizeShadowDOM,t,null);n=o.nextNode();)vt(de.uponSanitizeShadowNode,n,null),wt(n),Ot(n),n.content instanceof c&&e(n.content);vt(de.afterSanitizeShadowDOM,t,null)};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(rt=!e,rt&&(e="\x3c!--\x3e"),"string"!=typeof e&&!St(e)){if("function"!=typeof e.toString)throw v("toString is not a function");if("string"!=typeof(e=e.toString()))throw v("dirty is not a string, aborting")}if(!o.isSupported)return e;if(ze||gt(t),o.removed=[],"string"==typeof e&&(Xe=!1),Xe){if(e.nodeName){const t=mt(e.nodeName);if(!Se[t]||Oe[t])throw v("root node is forbidden and cannot be sanitized in-place")}}else if(e instanceof p)n=At("\x3c!----\x3e"),r=n.ownerDocument.importNode(e,!0),r.nodeType===ee&&"BODY"===r.nodeName||"HTML"===r.nodeName?n=r:n.appendChild(r);else{if(!Fe&&!Me&&!Ue&&-1===e.indexOf("<"))return le&&We?le.createHTML(e):e;if(n=At(e),!n)return Fe?null:We?ce:""}n&&He&&Et(n.firstChild);const s=Nt(Xe?e:n);for(;a=s.nextNode();)wt(a),Ot(a),a.content instanceof c&&Ct(a.content);if(Xe)return e;if(Fe){if(Be)for(l=pe.call(n.ownerDocument);n.firstChild;)l.appendChild(n.firstChild);else l=n;return(we.shadowroot||we.shadowrootmode)&&(l=fe.call(i,l,!0)),l}let u=Ue?n.outerHTML:n.innerHTML;return Ue&&Se["!doctype"]&&n.ownerDocument&&n.ownerDocument.doctype&&n.ownerDocument.doctype.name&&S(Z,n.ownerDocument.doctype.name)&&(u="<!DOCTYPE "+n.ownerDocument.doctype.name+">\n"+u),Me&&m([he,ge,Te],(e=>{u=b(u,e," ")})),le&&We?le.createHTML(u):u},o.setConfig=function(){gt(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),ze=!0},o.clearConfig=function(){ft=null,ze=!1},o.isValidAttribute=function(e,t,n){ft||gt({});const o=mt(e),r=mt(t);return Rt(o,r,n)},o.addHook=function(e,t){"function"==typeof t&&h(de[e],t)},o.removeHook=function(e,t){if(void 0!==t){const n=f(de[e],t);return-1===n?void 0:g(de[e],n,1)[0]}return d(de[e])},o.removeHooks=function(e){de[e]=[]},o.removeAllHooks=function(){de={afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},o}(),le=function(n,o){for(var r=[],i=2;i<arguments.length;i++)r[i-2]=arguments[i];return e(void 0,function(e,t,n){if(n||2===arguments.length)for(var o,r=0,i=t.length;r<i;r++)!o&&r in t||(o||(o=Array.prototype.slice.call(t,0,r)),o[r]=t[r]);return e.concat(o||Array.prototype.slice.call(t))}([n,o],r,!0),void 0,(function(n,o,r){var i,a,l,c;return void 0===r&&(r=50),t(this,(function(s){switch(s.label){case 0:return r=Math.max(1,r),i=ae.sanitize(o),n.innerHTML="",a=ce(i),l=function(e,t,o){return new Promise((function(r){var i=0,a=setInterval((function(){i<t.length?e.textContent+=t[i++]:(clearInterval(a),r()),requestAnimationFrame((function(){n.parentElement&&(n.parentElement.scrollTop=n.parentElement.scrollHeight)}))}),o)}))},c=function(n,o,r){return e(void 0,void 0,void 0,(function(){var e,i,a,s,u,p;return t(this,(function(t){switch(t.label){case 0:e=0,i=n,t.label=1;case 1:return e<i.length?"#text"!==(a=i[e]).tagName?[3,3]:(s=document.createTextNode(""),o.appendChild(s),[4,l(s,a.content||"",r)]):[3,8];case 2:return t.sent(),[3,7];case 3:return u=document.createElement(a.tagName),a.classes&&a.classes.length>0&&(p=u.classList).add.apply(p,a.classes),o.appendChild(u),a.content?[4,l(u,a.content,r)]:[3,5];case 4:t.sent(),t.label=5;case 5:return a.children&&a.children.length>0?[4,c(a.children,u,r)]:[3,7];case 6:t.sent(),t.label=7;case 7:return e++,[3,1];case 8:return[2]}}))}))},[4,c(a,n,r)];case 1:return s.sent(),[2]}}))}))},ce=function(e){var t=(new DOMParser).parseFromString(e,"text/html"),n=[],o=function(e,t){if(void 0===t&&(t=null),e.nodeType===Node.ELEMENT_NODE){var r={tagName:e.tagName.toLowerCase(),classes:e.className?e.className.split(/\s+/).filter((function(e){return!!e})):[],children:[]};t?t.children.push(r):n.push(r),e.childNodes.forEach((function(e){return o(e,r)}))}else if(e.nodeType===Node.TEXT_NODE&&e.textContent&&e.textContent.trim()){var i={tagName:"#text",content:e.textContent.trim()};t?t.children.push(i):n.push(i)}};return t.body.childNodes.forEach((function(e){return o(e)})),n};export{le as animateHtmlRendering}; //# sourceMappingURL=index.esm.js.map