12345678 |
- "use strict";function e(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}/*!
- * mp-html v2.2.1
- * https://github.com/jin-yufeng/mp-html
- *
- * Released under the MIT license
- * Author: Jin Yufeng
- */
- var t=require("./parser"),n=[];Component({data:{nodes:[]},props:{containerStyle:"",content:"",copyLink:!0,domain:"",errorImg:"",lazyLoad:!1,loadingImg:"",pauseVideo:!0,previewImg:!0,scrollTable:!1,setTitle:!0,showImgMenu:!0,tagStyle:{}},didMount:function(){this.plugins=[];for(var e=n.length;e--;)this.plugins.push(new n[e](this));this.props.content&&this.setContent(this.props.content)},didUpdate:function(e){e.content!==this.props.content&&this.setContent(this.props.content)},didUnmount:function(){clearInterval(this._timer),this._hook("onDetached")},methods:{in:function(e,t,n){e&&t&&n&&(this._in={page:e,selector:t,scrollTop:n})},navigateTo:function(t,n){var o=this;return new Promise(function(r,i){if(!o.props.useAnchor)return void i(Error("Anchor is disabled"));var a=my.createSelectorQuery().select((o._in?o._in.selector:"._root")+(t?"".concat(" ","#").concat(t):"")).boundingClientRect();o._in?a.select(o._in.selector).scrollOffset().select(o._in.selector).boundingClientRect():a.selectViewport().scrollOffset(),a.exec(function(t){if(!t[0])return void i(Error("Label not found"));var a=t[1].scrollTop+t[0].top-(t[2]?t[2].top:0)+(n||parseInt(o.props.useAnchor)||0);o._in?o._in.page.setData(e({},o._in.scrollTop,a)):my.pageScrollTo({scrollTop:a,duration:300}),r()})})},getText:function(e){var t="";return function e(n){for(var o=0;o<n.length;o++){var r=n[o];if("text"===r.type)t+=r.text.replace(/&/g,"&");else if("br"===r.name)t+="\n";else{var i="p"===r.name||"div"===r.name||"tr"===r.name||"li"===r.name||"h"===r.name[0]&&r.name[1]>"0"&&r.name[1]<"7";i&&t&&"\n"!==t[t.length-1]&&(t+="\n"),r.children&&e(r.children),i&&"\n"!==t[t.length-1]?t+="\n":"td"!==r.name&&"th"!==r.name||(t+="\t")}}}(e||this.data.nodes),t},getRect:function(){return new Promise(function(e,t){my.createSelectorQuery().select("._root").boundingClientRect().exec(function(n){return n[0]?e(n[0]):t(Error("Root label not found"))})})},setContent:function(e,n){var o=this;this.imgList&&n||(this.imgList=[]),this._videos=[];var r={},i=new t(this).parse(e);if(n)for(var a=this.data.nodes.length,s=i.length;s--;)r["nodes[".concat(a+s,"]")]=i[s];else r.nodes=i;this.setData(r,function(){o._hook("onLoad"),o.props.onLoad&&o.props.onLoad()});var l;clearInterval(this._timer),this._timer=setInterval(function(){o.getRect().then(function(e){e.height===l&&(o.props.onReady&&o.props.onReady(e),clearInterval(o._timer)),l=e.height}).catch(function(){})},350)},_hook:function(e){for(var t=n.length;t--;)this.plugins[t][e]&&this.plugins[t][e]()},_add:function(e){e.root=this}}});
|