YingXingAI/node_modules/mp-html/dist/mp-alipay/index.js

8 lines
3.1 KiB
JavaScript

"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.5.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(){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 i=this;return new Promise(function(o,r){if(!i.props.useAnchor)return void r(Error("Anchor is disabled"));var s=my.createSelectorQuery().select((i._in?i._in.selector:"._root")+(t?"".concat(" ","#").concat(t):"")).boundingClientRect();i._in?s.select(i._in.selector).scrollOffset().select(i._in.selector).boundingClientRect():s.selectViewport().scrollOffset(),s.exec(function(t){if(!t[0])return void r(Error("Label not found"));var s=t[1].scrollTop+t[0].top-(t[2]?t[2].top:0)+(n||parseInt(i.props.useAnchor)||0);i._in?i._in.page.setData(e({},i._in.scrollTop,s)):my.pageScrollTo({scrollTop:s,duration:300}),o()})})},getText:function(e){var t="";return function e(n){for(var i=0;i<n.length;i++){var o=n[i];if("text"===o.type)t+=o.text.replace(/&amp;/g,"&");else if("br"===o.name)t+="\n";else{var r="p"===o.name||"div"===o.name||"tr"===o.name||"li"===o.name||"h"===o.name[0]&&o.name[1]>"0"&&o.name[1]<"7";r&&t&&"\n"!==t[t.length-1]&&(t+="\n"),o.children&&e(o.children),r&&"\n"!==t[t.length-1]?t+="\n":"td"!==o.name&&"th"!==o.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"))})})},pauseMedia:function(){for(var e=(this._videos||[]).length;e--;)this._videos[e].pause()},setPlaybackRate:function(e){this.playbackRate=e;for(var t=(this._videos||[]).length;t--;)this._videos[t].playbackRate(e)},setContent:function(e,n){var i=this;this.imgList&&n||(this.imgList=[]),this._videos=[];var o={},r=new t(this).parse(e);if(n)for(var s=this.data.nodes.length,a=r.length;a--;)o["nodes[".concat(s+a,"]")]=r[a];else o.nodes=r;if(this.setData(o,function(){i._hook("onLoad"),i.props.onLoad&&i.props.onLoad()}),this.props.lazyLoad||this.imgList._unloadimgs<this.imgList.length/2){var l=0,c=function e(t){t&&t.height||(t={}),t.height===l?i.props.onReady&&i.props.onReady(t):(l=t.height,setTimeout(function(){i.getRect().then(e).catch(e)},350))};this.getRect().then(c).catch(c)}else this.imgList._unloadimgs||this.getRect().then(function(e){i.props.onReady&&i.props.onReady(e)}).catch(function(){i.props.onReady&&i.props.onReady({})})},_hook:function(e){for(var t=n.length;t--;)this.plugins[t][e]&&this.plugins[t][e]()},_add:function(e){e.root=this}}});