import showdown from"./showdown.js";import HtmlToJson from"./html2json.js";var realWindowWidth=0,realWindowHeight=0;function wxParse(a="wxParseData",e="html",t='<div class="color:red;">数据不能为空</div>',i,r){var o=i,s={};if("html"==e)s=HtmlToJson.html2json(t,a);else if("md"==e||"markdown"==e){var n=(new showdown.Converter).makeHtml(t);s=HtmlToJson.html2json(n,a)}s.view={},s.view.imagePadding=0,void 0!==r&&(s.view.imagePadding=r);var m={};m[a]=s,o.setData(m),o.wxParseImgLoad=wxParseImgLoad,o.wxParseImgTap=wxParseImgTap}function wxParseImgTap(a){var e=a.target.dataset.src,t=a.target.dataset.from;void 0!==t&&t.length>0&&wx.previewImage({current:e,urls:this.data[t].imageUrls})}function wxParseImgLoad(a){var e=a.target.dataset.from,t=a.target.dataset.idx;void 0!==e&&e.length>0&&calMoreImageInfo(a,t,this,e)}function calMoreImageInfo(a,e,t,i){var r=t.data[i];if(r&&0!=r.images.length){var o=r.images,s=wxAutoImageCal(a.detail.width,a.detail.height,t,i),n=o[e].index,m=`${i}`;for(var d of n.split("."))m+=`.nodes[${d}]`;var w=m+".width",g=m+".height";t.setData({[w]:s.imageWidth,[g]:s.imageheight})}}function wxAutoImageCal(a,e,t,i){var r,o=0,s=0,n={},m=t.data[i].view.imagePadding;return realWindowHeight,a>(r=realWindowWidth-2*m)?(s=(o=r)*e/a,n.imageWidth=o,n.imageheight=s):(n.imageWidth=a,n.imageheight=e),n}function wxParseTemArray(a,e,t,i){for(var r=[],o=i.data,s=null,n=0;n<t;n++){var m=o[e+n].nodes;r.push(m)}a=a||"wxParseTemArray",(s=JSON.parse('{"'+a+'":""}'))[a]=r,i.setData(s)}function emojisInit(a="",e="/wxParse/emojis/",t){HtmlToJson.emojisInit(a,e,t)}wx.getSystemInfo({success:function(a){realWindowWidth=a.windowWidth,realWindowHeight=a.windowHeight}}),module.exports={wxParse:wxParse,wxParseTemArray:wxParseTemArray,emojisInit:emojisInit};