wxParse.js
3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
"use strict";
var _showdown = _interopRequireDefault(require("./showdown.js")),
_html2json = _interopRequireDefault(require("./html2json.js"));
function _interopRequireDefault(e) {
return e && e.__esModule ? e : {
default: e
}
}
function _defineProperty(e, t, a) {
return t in e ? Object.defineProperty(e, t, {
value: a,
enumerable: !0,
configurable: !0,
writable: !0
}) : e[t] = a, e
}
var realWindowWidth = 0,
realWindowHeight = 0;
function wxParse() {
var e = 0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : "wxParseData",
t = 1 < arguments.length && void 0 !== arguments[1] ? arguments[1] : "html",
a = 2 < arguments.length && void 0 !== arguments[2] ? arguments[2] : '<div class="color:red;">数据不能为空</div>',
i = 3 < arguments.length ? arguments[3] : void 0,
r = 4 < arguments.length ? arguments[4] : void 0,
n = i,
o = {};
if ("html" == t) o = _html2json.default.html2json(a, e);
else if ("md" == t || "markdown" == t) {
var d = (new _showdown.default.Converter).makeHtml(a);
o = _html2json.default.html2json(d, e)
}
o.view = {}, void(o.view.imagePadding = 0) !== r && (o.view.imagePadding = r);
var l = {};
l[e] = o, n.setData(l), n.wxParseImgLoad = wxParseImgLoad, n.wxParseImgTap = wxParseImgTap
}
function wxParseImgTap(e) {
var t = e.target.dataset.src,
a = e.target.dataset.from;
void 0 !== a && 0 < a.length && tt.previewImage({
current: t,
urls: this.data[a].imageUrls
})
}
function wxParseImgLoad(e) {
var t = e.target.dataset.from,
a = e.target.dataset.idx;
void 0 !== t && 0 < t.length && calMoreImageInfo(e, a, this, t)
}
function calMoreImageInfo(e, t, a, i) {
var r, n = a.data[i];
if (n && 0 != n.images.length) {
var o = n.images,
d = wxAutoImageCal(e.detail.width, e.detail.height, a, i),
l = o[t].index,
s = "".concat(i),
g = !0,
m = !1,
h = void 0;
try {
for (var w, u = l.split(".")[Symbol.iterator](); !(g = (w = u.next()).done); g = !0) {
var v = w.value;
s += ".nodes[".concat(v, "]")
}
} catch (e) {
m = !0, h = e
} finally {
try {
g || null == u.return || u.return()
} finally {
if (m) throw h
}
}
var f = s + ".width",
c = s + ".height";
a.setData((_defineProperty(r = {}, f, d.imageWidth), _defineProperty(r, c, d.imageheight), r))
}
}
function wxAutoImageCal(e, t, a, i) {
var r, n = 0,
o = 0,
d = {},
l = a.data[i].view.imagePadding;
return r = realWindowWidth - 2 * l, realWindowHeight, d.imageheight = r < e ? (o = (n = r) * t / e, d.imageWidth = n, o) : (d.imageWidth = e, t), d
}
function wxParseTemArray(e, t, a, i) {
for (var r = [], n = i.data, o = null, d = 0; d < a; d++) {
var l = n[t + d].nodes;
r.push(l)
}
e = e || "wxParseTemArray", (o = JSON.parse('{"' + e + '":""}'))[e] = r, i.setData(o)
}
function emojisInit() {
var e = 0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : "",
t = 1 < arguments.length && void 0 !== arguments[1] ? arguments[1] : "/wxParse/emojis/",
a = 2 < arguments.length ? arguments[2] : void 0;
_html2json.default.emojisInit(e, t, a)
}
tt.getSystemInfo({
success: function(e) {
realWindowWidth = e.windowWidth, realWindowHeight = e.windowHeight
}
}), module.exports = {
wxParse: wxParse,
wxParseTemArray: wxParseTemArray,
emojisInit: emojisInit
};