"use strict";function t(t){for(var i=Object.create(null),e=t.split(","),s=e.length;s--;)i[e[s]]=!0;return i}function i(t,i){for(var e=t.indexOf("&");-1!==e;){var s=t.indexOf(";",e+3),a=void 0;if(-1===s)break;"#"===t[e+1]?(a=parseInt(("x"===t[e+2]?"0":"")+t.substring(e+2,s)),isNaN(a)||(t=t.substr(0,e)+String.fromCharCode(a)+t.substr(s+1))):(a=t.substring(e+1,s),(n.entities[a]||"amp"===a&&i)&&(t=t.substr(0,e)+(n.entities[a]||"&")+t.substr(s+1))),e=t.indexOf("&",e+1)}return t}function e(t){for(var i=t.length-1,e=i;e>=-1;e--)(-1===e||t[e].c||!t[e].name||"div"!==t[e].name&&"p"!==t[e].name&&"h"!==t[e].name[0]||(t[e].attrs.style||"").includes("inline"))&&(i-e>=5&&t.splice(e+1,i-e,{name:"div",attrs:{},children:t.slice(e+1,i+1)}),i=e-1)}function s(t){this.options=t.data||{},this.tagStyle=Object.assign({},n.tagStyle,this.options.tagStyle),this.imgList=t.imgList||[],this.imgList._unloadimgs=0,this.plugins=t.plugins||[],this.attrs=Object.create(null),this.stack=[],this.nodes=[],this.pre=(this.options.containerStyle||"").includes("white-space")&&this.options.containerStyle.includes("pre")?2:0}function a(t){this.handler=t}var n={trustTags:t("a,abbr,ad,audio,b,blockquote,br,code,col,colgroup,dd,del,dl,dt,div,em,fieldset,h1,h2,h3,h4,h5,h6,hr,i,img,ins,label,legend,li,ol,p,q,ruby,rt,source,span,strong,sub,sup,table,tbody,td,tfoot,th,thead,tr,title,ul,video"),blockTags:t("address,article,aside,body,caption,center,cite,footer,header,html,nav,pre,section"),ignoreTags:t("area,base,canvas,embed,frame,head,iframe,input,link,map,meta,param,rp,script,source,style,textarea,title,track,wbr"),voidTags:t("area,base,br,col,circle,ellipse,embed,frame,hr,img,input,line,link,meta,param,path,polygon,rect,source,track,use,wbr"),entities:{lt:"<",gt:">",quot:'"',apos:"'",ensp:" ",emsp:" ",nbsp:" ",semi:";",ndash:"–",mdash:"—",middot:"·",lsquo:"‘",rsquo:"’",ldquo:"“",rdquo:"”",bull:"•",hellip:"…",larr:"←",uarr:"↑",rarr:"→",darr:"↓"},tagStyle:{address:"font-style:italic",big:"display:inline;font-size:1.2em",caption:"display:table-caption;text-align:center",center:"text-align:center",cite:"font-style:italic",dd:"margin-left:40px",mark:"background-color:yellow",pre:"font-family:monospace;white-space:pre",s:"text-decoration:line-through",small:"display:inline;font-size:0.8em",strike:"text-decoration:line-through",u:"text-decoration:underline"},svgDict:{animatetransform:"animateTransform",lineargradient:"linearGradient",viewbox:"viewBox",attributename:"attributeName",repeatcount:"repeatCount",repeatdur:"repeatDur"}},r={},o=wx.getSystemInfoSync(),h=o.windowWidth,l=o.system,c=t(" ,\r,\n,\t,\f"),d=0;s.prototype.parse=function(t){for(var i=this.plugins.length;i--;)this.plugins[i].onUpdate&&(t=this.plugins[i].onUpdate(t,n)||t);for(new a(this).parse(t);this.stack.length;)this.popNode();return this.nodes.length>50&&e(this.nodes),this.nodes},s.prototype.expose=function(){for(var t=this.stack.length;t--;){var i=this.stack[t];if(i.c||"a"===i.name||"video"===i.name||"audio"===i.name)return;i.c=1}},s.prototype.hook=function(t){for(var i=this.plugins.length;i--;)if(this.plugins[i].onParse&&!1===this.plugins[i].onParse(t,this))return!1;return!0},s.prototype.getUrl=function(t){var i=this.options.domain;return"/"===t[0]?"/"===t[1]?t=(i?i.split("://")[0]:"http")+":"+t:i&&(t=i+t):!i||t.includes("data:")||t.includes("://")||(t=i+"/"+t),t},s.prototype.parseStyle=function(t){var i=t.attrs,e=(this.tagStyle[t.name]||"").split(";").concat((i.style||"").split(";")),s={},a="";i.id&&!this.xml&&(this.options.useAnchor?this.expose():"img"!==t.name&&"a"!==t.name&&"video"!==t.name&&"audio"!==t.name&&(i.id=void 0)),i.width&&(s.width=parseFloat(i.width)+(i.width.includes("%")?"%":"px"),i.width=void 0),i.height&&(s.height=parseFloat(i.height)+(i.height.includes("%")?"%":"px"),i.height=void 0);for(var n=0,r=e.length;n0||d.includes("safe"))a+=";".concat(l,":").concat(d);else if(!s[l]||d.includes("import")||!s[l].includes("import")){if(d.includes("url")){var p=d.indexOf("(")+1;if(p){for(;'"'===d[p]||"'"===d[p]||c[d[p]];)p++;d=d.substr(0,p)+this.getUrl(d.substr(p))}}else d.includes("rpx")&&(d=d.replace(/[0-9.]+\s*rpx/g,function(t){return parseFloat(t)*h/750+"px"}));s[l]=d}}}return t.attrs.style=a,s},s.prototype.onTagName=function(t){this.tagName=this.xml?t:t.toLowerCase(),"svg"===this.tagName&&(this.xml=(this.xml||0)+1)},s.prototype.onAttrName=function(t){t=this.xml?t:t.toLowerCase(),"data-"===t.substr(0,5)?"data-src"!==t||this.attrs.src?"img"===this.tagName||"a"===this.tagName?this.attrName=t:this.attrName=void 0:this.attrName="src":(this.attrName=t,this.attrs[t]="T")},s.prototype.onAttrVal=function(t){var e=this.attrName||"";"style"===e||"href"===e?this.attrs[e]=i(t,!0):e.includes("src")?this.attrs[e]=this.getUrl(i(t,!0)):e&&(this.attrs[e]=t)},s.prototype.onOpenTag=function(t){var i=Object.create(null);i.name=this.tagName,i.attrs=this.attrs,this.attrs=Object.create(null);var e=i.attrs,s=this.stack[this.stack.length-1],a=s?s.children:this.nodes,o=this.xml?t:n.voidTags[i.name];if(r[i.name]&&(e.class=r[i.name]+(e.class?" "+e.class:"")),"embed"===i.name){var l=e.src||"";l.includes(".mp4")||l.includes(".3gp")||l.includes(".m3u8")||(e.type||"").includes("video")?i.name="video":(l.includes(".mp3")||l.includes(".wav")||l.includes(".aac")||l.includes(".m4a")||(e.type||"").includes("audio"))&&(i.name="audio"),e.autostart&&(e.autoplay="T"),e.controls="T"}if("video"!==i.name&&"audio"!==i.name||("video"!==i.name||e.id||(e.id="v"+d++),e.controls||e.autoplay||(e.controls="T"),i.src=[],e.src&&(i.src.push(e.src),e.src=void 0),this.expose()),o){if(!this.hook(i)||n.ignoreTags[i.name])return void("base"!==i.name||this.options.domain?"source"===i.name&&s&&("video"===s.name||"audio"===s.name)&&e.src&&s.src.push(e.src):this.options.domain=e.href);var c=this.parseStyle(i);if("img"===i.name){if(e.src&&(e.src.includes("webp")&&(i.webp="T"),e.src.includes("data:")&&!e["original-src"]&&(e.ignore="T"),!e.ignore||i.webp||e.src.includes("cloud://"))){for(var p=this.stack.length;p--;){var u=this.stack[p];"table"!==u.name||i.webp||e.src.includes("cloud://")||(!c.display||c.display.includes("inline")?i.t="inline-block":i.t=c.display,c.display=void 0);var g=u.attrs.style||"";if(!g.includes("flex:")||g.includes("flex:0")||g.includes("flex: 0")||c.width&&!(parseInt(c.width)>100))if(g.includes("flex")&&"100%"===c.width)for(var f=p+1;f.5?y[x].toUpperCase():y[x];b+=y.substr(x),y=b}}this.imgList.push(y),i.t||(this.imgList._unloadimgs+=1)}"inline"===c.display&&(c.display=""),e.ignore&&(c["max-width"]=c["max-width"]||"100%",e.style+=";-webkit-touch-callout:none"),parseInt(c.width)>h&&(c.height=void 0),isNaN(parseInt(c.width))||(i.w="T"),!isNaN(parseInt(c.height))&&(!c.height.includes("%")||s&&(s.attrs.style||"").includes("height"))&&(i.h="T")}else if("svg"===i.name)return a.push(i),this.stack.push(i),void this.popNode();for(var w in c)c[w]&&(e.style+=";".concat(w,":").concat(c[w].replace(" !important","")));e.style=e.style.substr(1)||void 0}else("pre"===i.name||(e.style||"").includes("white-space")&&e.style.includes("pre"))&&2!==this.pre&&(this.pre=i.pre=1),i.children=[],this.stack.push(i);a.push(i)},s.prototype.onCloseTag=function(t){t=this.xml?t:t.toLowerCase();var i;for(i=this.stack.length;i--&&this.stack[i].name!==t;);if(-1!==i)for(;this.stack.length>i;)this.popNode();else if("p"===t||"br"===t){var e=this.stack.length?this.stack[this.stack.length-1].children:this.nodes;e.push({name:t,attrs:{class:r[t],style:this.tagStyle[t]}})}},s.prototype.popNode=function(){var t=this.stack.pop(),i=t.attrs,s=t.children,a=this.stack[this.stack.length-1],r=a?a.children:this.nodes;if(!this.hook(t)||n.ignoreTags[t.name])return"title"===t.name&&s.length&&"text"===s[0].type&&this.options.setTitle&&wx.setNavigationBarTitle({title:s[0].text}),void r.pop();if(t.pre&&2!==this.pre){this.pre=t.pre=void 0;for(var o=this.stack.length;o--;)this.stack[o].pre&&(this.pre=1)}if("svg"===t.name){if(this.xml>1)return void this.xml--;var l="",c=i.style;return i.style="",i.xmlns="http://www.w3.org/2000/svg",function t(i){if("text"===i.type)return void(l+=i.text);var e=n.svgDict[i.name]||i.name;l+="<"+e;for(var s in i.attrs){var a=i.attrs[s];a&&(l+=" ".concat(n.svgDict[s]||s,'="').concat(a,'"'))}if(i.children){l+=">";for(var r=0;r"}else l+="/>"}(t),t.name="img",t.attrs={src:"data:image/svg+xml;utf8,"+l.replace(/#/g,"%23"),style:c,ignore:"T"},t.children=void 0,void(this.xml=!1)}var d={};if(i.align&&("table"===t.name?"center"===i.align?d["margin-inline-start"]=d["margin-inline-end"]="auto":d.float=i.align:d["text-align"]=i.align,i.align=void 0),i.dir&&(d.direction=i.dir,i.dir=void 0),"font"===t.name&&(i.color&&(d.color=i.color,i.color=void 0),i.face&&(d["font-family"]=i.face,i.face=void 0),i.size)){var p=parseInt(i.size);isNaN(p)||(p<1?p=1:p>7&&(p=7),d["font-size"]=["x-small","small","medium","large","x-large","xx-large","xxx-large"][p-1]),i.size=void 0}if((i.class||"").includes("align-center")&&(d["text-align"]="center"),Object.assign(d,this.parseStyle(t)),"table"!==t.name&&parseInt(d.width)>h&&(d["max-width"]="100%",d["box-sizing"]="border-box"),n.blockTags[t.name])t.name="div";else if(n.trustTags[t.name]||this.xml)if("a"===t.name||"ad"===t.name)this.expose();else if("video"===t.name||"audio"===t.name)(d.height||"").includes("auto")&&(d.height=void 0),t.children=void 0;else if("ul"!==t.name&&"ol"!==t.name||!t.c){if("table"===t.name){var u=parseFloat(i.cellpadding),g=parseFloat(i.cellspacing),f=parseFloat(i.border),m=d["border-color"],v=d["border-style"];if(t.c&&(isNaN(u)&&(u=2),isNaN(g)&&(g=2)),f&&(i.style+=";border:".concat(f,"px ").concat(v||"solid"," ").concat(m||"gray")),t.flag&&t.c){t.flag=void 0,d.display="grid",g?(d["grid-gap"]=g+"px",d.padding=g+"px"):f&&(i.style+=";border-left:0;border-top:0");var y=[],x=[],b=[],w={};!function t(i){for(var e=0;e=50&&t.c&&!(d.display||"").includes("flex")&&e(s);for(var M in d)if(d[M]){var W=";".concat(M,":").concat(d[M].replace(" !important",""));G&&(M.includes("flex")&&"flex-direction"!==M||"align-self"===M||M.includes("grid")||"-"===d[M][0]||M.includes("width")&&W.includes("%"))?(t.f+=W,"width"===M&&(i.style+=";width:100%")):i.style+=W}i.style=i.style.substr(1)||void 0},s.prototype.onText=function(t){if(!this.pre){for(var e,s="",a=0,n=t.length;a"===this.content[this.i]||i&&">"===this.content[this.i+1])&&(t&&this.handler[t](this.content.substring(this.start,this.i)),this.i+=i?2:1,this.start=this.i,this.handler.onOpenTag(i),"script"===this.handler.tagName?(this.i=this.content.indexOf("="a"&&t<="z"||t>="A"&&t<="Z")this.start!==this.i&&this.handler.onText(this.content.substring(this.start,this.i)),this.start=++this.i,this.state=this.tagName;else if("/"===t||"!"===t||"?"===t){this.start!==this.i&&this.handler.onText(this.content.substring(this.start,this.i));var i=this.content[this.i+2];if("/"===t&&(i>="a"&&i<="z"||i>="A"&&i<="Z"))return this.i+=2,this.start=this.i,void(this.state=this.endTag);var e="--\x3e";"!"===t&&"-"===this.content[this.i+2]&&"-"===this.content[this.i+3]||(e=">"),this.i=this.content.indexOf(e,this.i),-1!==this.i&&(this.i+=e.length,this.start=this.i)}else this.i++},a.prototype.tagName=function(){if(c[this.content[this.i]]){for(this.handler.onTagName(this.content.substring(this.start,this.i));c[this.content[++this.i]];);this.i"===t||"/"===t){if(this.handler.onCloseTag(this.content.substring(this.start,this.i)),">"!==t&&(this.i=this.content.indexOf(">",this.i),-1===this.i))return;this.start=++this.i,this.state=this.text}else this.i++},module.exports=s;