parser.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. "use strict";
  2. function t(t, e) {
  3. var s = "undefined" != typeof Symbol && t[Symbol.iterator] || t["@@iterator"];
  4. if (!s) {
  5. if (Array.isArray(t) || (s = i(t)) || e && t && "number" == typeof t.length) {
  6. s && (t = s);
  7. var n = 0,
  8. a = function () {};
  9. return {
  10. s: a,
  11. n: function () {
  12. return n >= t.length ? {
  13. done: !0
  14. } : {
  15. done: !1,
  16. value: t[n++]
  17. };
  18. },
  19. e: function (t) {
  20. throw t;
  21. },
  22. f: a
  23. };
  24. }
  25. throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  26. }
  27. var r,
  28. o = !0,
  29. l = !1;
  30. return {
  31. s: function () {
  32. s = s.call(t);
  33. },
  34. n: function () {
  35. var t = s.next();
  36. return o = t.done, t;
  37. },
  38. e: function (t) {
  39. l = !0, r = t;
  40. },
  41. f: function () {
  42. try {
  43. o || null == s.return || s.return();
  44. } finally {
  45. if (l) throw r;
  46. }
  47. }
  48. };
  49. }
  50. function i(t, i) {
  51. if (t) {
  52. if ("string" == typeof t) return e(t, i);
  53. var s = {}.toString.call(t).slice(8, -1);
  54. return "Object" === s && t.constructor && (s = t.constructor.name), "Map" === s || "Set" === s ? Array.from(t) : "Arguments" === s || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(s) ? e(t, i) : void 0;
  55. }
  56. }
  57. function e(t, i) {
  58. (null == i || i > t.length) && (i = t.length);
  59. for (var e = 0, s = Array(i); e < i; e++) s[e] = t[e];
  60. return s;
  61. }
  62. function s(t) {
  63. for (var i = Object.create(null), e = t.split(","), s = e.length; s--;) i[e[s]] = !0;
  64. return i;
  65. }
  66. function n(t, i) {
  67. for (var e = t.indexOf("&"); -1 !== e;) {
  68. var s = t.indexOf(";", e + 3),
  69. n = void 0;
  70. if (-1 === s) break;
  71. "#" === t[e + 1] ? (n = parseInt(("x" === t[e + 2] ? "0" : "") + t.substring(e + 2, s)), isNaN(n) || (t = t.substr(0, e) + String.fromCharCode(n) + t.substr(s + 1))) : (n = t.substring(e + 1, s), (l.entities[n] || "amp" === n && i) && (t = t.substr(0, e) + (l.entities[n] || "&") + t.substr(s + 1))), e = t.indexOf("&", e + 1);
  72. }
  73. return t;
  74. }
  75. function a(t) {
  76. 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, {
  77. name: "div",
  78. attrs: {},
  79. children: t.slice(e + 1, i + 1)
  80. }), i = e - 1);
  81. }
  82. function r(t) {
  83. this.options = t.data || {}, this.tagStyle = Object.assign({}, l.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;
  84. }
  85. function o(t) {
  86. this.handler = t;
  87. }
  88. var l = {
  89. trustTags: s("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"),
  90. blockTags: s("address,article,aside,body,caption,center,cite,footer,header,html,nav,pre,section"),
  91. ignoreTags: s("area,base,canvas,embed,frame,head,iframe,input,link,map,meta,param,rp,script,source,style,textarea,title,track,wbr"),
  92. voidTags: s("area,base,br,col,circle,ellipse,embed,frame,hr,img,input,line,link,meta,param,path,polygon,rect,source,track,use,wbr"),
  93. entities: {
  94. lt: "<",
  95. gt: ">",
  96. quot: '"',
  97. apos: "'",
  98. ensp: " ",
  99. emsp: " ",
  100. nbsp: " ",
  101. semi: ";",
  102. ndash: "–",
  103. mdash: "—",
  104. middot: "·",
  105. lsquo: "‘",
  106. rsquo: "’",
  107. ldquo: "“",
  108. rdquo: "”",
  109. bull: "•",
  110. hellip: "…",
  111. larr: "←",
  112. uarr: "↑",
  113. rarr: "→",
  114. darr: "↓"
  115. },
  116. tagStyle: {
  117. address: "font-style:italic",
  118. big: "display:inline;font-size:1.2em",
  119. caption: "display:table-caption;text-align:center",
  120. center: "text-align:center",
  121. cite: "font-style:italic",
  122. dd: "margin-left:40px",
  123. mark: "background-color:yellow",
  124. pre: "font-family:monospace;white-space:pre",
  125. s: "text-decoration:line-through",
  126. small: "display:inline;font-size:0.8em",
  127. strike: "text-decoration:line-through",
  128. u: "text-decoration:underline"
  129. },
  130. svgDict: {
  131. animatetransform: "animateTransform",
  132. lineargradient: "linearGradient",
  133. viewbox: "viewBox",
  134. attributename: "attributeName",
  135. repeatcount: "repeatCount",
  136. repeatdur: "repeatDur",
  137. foreignobject: "foreignObject"
  138. }
  139. },
  140. h = {},
  141. c = uni.getSystemInfoSync(),
  142. d = c.windowWidth,
  143. p = c.system,
  144. u = s(" ,\r,\n,\t,\f"),
  145. f = 0;
  146. r.prototype.parse = function (t) {
  147. for (var i = this.plugins.length; i--;) this.plugins[i].onUpdate && (t = this.plugins[i].onUpdate(t, l) || t);
  148. for (new o(this).parse(t); this.stack.length;) this.popNode();
  149. return this.nodes.length > 50 && a(this.nodes), this.nodes;
  150. }, r.prototype.expose = function () {
  151. for (var t = this.stack.length; t--;) {
  152. var i = this.stack[t];
  153. if (i.c || "a" === i.name || "video" === i.name || "audio" === i.name) return;
  154. i.c = 1;
  155. }
  156. }, r.prototype.hook = function (t) {
  157. for (var i = this.plugins.length; i--;) if (this.plugins[i].onParse && !1 === this.plugins[i].onParse(t, this)) return !1;
  158. return !0;
  159. }, r.prototype.getUrl = function (t) {
  160. var i = this.options.domain;
  161. 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;
  162. }, r.prototype.parseStyle = function (t) {
  163. var i = t.attrs,
  164. e = (this.tagStyle[t.name] || "").split(";").concat((i.style || "").split(";")),
  165. s = {},
  166. n = "";
  167. 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);
  168. for (var a = 0, r = e.length; a < r; a++) {
  169. var o = e[a].split(":");
  170. if (!(o.length < 2)) {
  171. var l = o.shift().trim().toLowerCase(),
  172. h = o.join(":").trim();
  173. if ("-" === h[0] && h.lastIndexOf("-") > 0 || h.includes("safe")) n += ";".concat(l, ":").concat(h);else if (!s[l] || h.includes("import") || !s[l].includes("import")) {
  174. if (h.includes("url")) {
  175. var c = h.indexOf("(") + 1;
  176. if (c) {
  177. for (; '"' === h[c] || "'" === h[c] || u[h[c]];) c++;
  178. h = h.substr(0, c) + this.getUrl(h.substr(c));
  179. }
  180. } else h.includes("rpx") && (h = h.replace(/[0-9.]+\s*rpx/g, function (t) {
  181. return parseFloat(t) * d / 750 + "px";
  182. }));
  183. s[l] = h;
  184. }
  185. }
  186. }
  187. return t.attrs.style = n, s;
  188. }, r.prototype.onTagName = function (t) {
  189. this.tagName = this.xml ? t : t.toLowerCase(), "svg" === this.tagName && (this.xml = (this.xml || 0) + 1, l.ignoreTags.style = void 0);
  190. }, r.prototype.onAttrName = function (t) {
  191. 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");
  192. }, r.prototype.onAttrVal = function (t) {
  193. var i = this.attrName || "";
  194. "style" === i || "href" === i ? this.attrs[i] = n(t, !0) : i.includes("src") ? this.attrs[i] = this.getUrl(n(t, !0)) : i && (this.attrs[i] = t);
  195. }, r.prototype.onOpenTag = function (t) {
  196. var i = Object.create(null);
  197. i.name = this.tagName, i.attrs = this.attrs, this.attrs = Object.create(null);
  198. var e = i.attrs,
  199. s = this.stack[this.stack.length - 1],
  200. n = s ? s.children : this.nodes,
  201. a = this.xml ? t : l.voidTags[i.name];
  202. if (h[i.name] && (e.class = h[i.name] + (e.class ? " " + e.class : "")), "embed" === i.name) {
  203. var r = e.src || "";
  204. r.includes(".mp4") || r.includes(".3gp") || r.includes(".m3u8") || (e.type || "").includes("video") ? i.name = "video" : (r.includes(".mp3") || r.includes(".wav") || r.includes(".aac") || r.includes(".m4a") || (e.type || "").includes("audio")) && (i.name = "audio"), e.autostart && (e.autoplay = "T"), e.controls = "T";
  205. }
  206. if ("video" !== i.name && "audio" !== i.name || ("video" !== i.name || e.id || (e.id = "v" + f++), e.controls || e.autoplay || (e.controls = "T"), i.src = [], e.src && (i.src.push(e.src), e.src = void 0), this.expose()), a) {
  207. if (!this.hook(i) || l.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);
  208. var o = this.parseStyle(i);
  209. if ("img" === i.name) {
  210. if (e.src && (e.src.includes("webp") && (i.webp = "T"), e.src.includes("data:") && "all" !== this.options.previewImg && !e["original-src"] && (e.ignore = "T"), !e.ignore || i.webp || e.src.includes("cloud://"))) {
  211. for (var c = this.stack.length; c--;) {
  212. var p = this.stack[c];
  213. "table" !== p.name || i.webp || e.src.includes("cloud://") || (!o.display || o.display.includes("inline") ? i.t = "inline-block" : i.t = o.display, o.display = void 0);
  214. var u = p.attrs.style || "";
  215. if (!u.includes("flex:") || u.includes("flex:0") || u.includes("flex: 0") || o.width && !(parseInt(o.width) > 100)) {
  216. if (u.includes("flex") && "100%" === o.width) for (var g = c + 1; g < this.stack.length; g++) {
  217. var m = this.stack[g].attrs.style || "";
  218. if (!m.includes(";width") && !m.includes(" width") && 0 !== m.indexOf("width")) {
  219. o.width = "";
  220. break;
  221. }
  222. } else u.includes("inline-block") && (o.width && "%" === o.width[o.width.length - 1] ? (p.attrs.style += ";max-width:" + o.width, o.width = "") : p.attrs.style += ";max-width:100%");
  223. } else {
  224. o.width = "100% !important", o.height = "";
  225. for (var v = c + 1; v < this.stack.length; v++) this.stack[v].attrs.style = (this.stack[v].attrs.style || "").replace("inline-", "");
  226. }
  227. "a" === p.name ? i.a = p.attrs : p.c = 1;
  228. }
  229. i.i = this.imgList.length;
  230. var y = e["original-src"] || e.src;
  231. if (this.imgList.includes(y)) {
  232. var b = y.indexOf("://");
  233. if (-1 !== b) {
  234. b += 3;
  235. for (var x = y.substr(0, b); b < y.length && "/" !== y[b]; b++) x += Math.random() > .5 ? y[b].toUpperCase() : y[b];
  236. x += y.substr(b), y = x;
  237. }
  238. }
  239. this.imgList.push(y), i.t || (this.imgList._unloadimgs += 1);
  240. }
  241. "inline" === o.display && (o.display = ""), e.ignore && (o["max-width"] = o["max-width"] || "100%", e.style += ";-webkit-touch-callout:none"), parseInt(o.width) > d && (o.height = void 0), isNaN(parseInt(o.width)) || (i.w = "T"), !isNaN(parseInt(o.height)) && (!o.height.includes("%") || s && (s.attrs.style || "").includes("height")) && (i.h = "T"), i.w && i.h && o["object-fit"] && ("contain" === o["object-fit"] ? i.m = "aspectFit" : "cover" === o["object-fit"] && (i.m = "aspectFill"));
  242. } else if ("svg" === i.name) return n.push(i), this.stack.push(i), void this.popNode();
  243. for (var w in o) o[w] && (e.style += ";".concat(w, ":").concat(o[w].replace(" !important", "")));
  244. e.style = e.style.substr(1) || void 0;
  245. } 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);
  246. n.push(i);
  247. }, r.prototype.onCloseTag = function (t) {
  248. t = this.xml ? t : t.toLowerCase();
  249. var i;
  250. for (i = this.stack.length; i-- && this.stack[i].name !== t;);
  251. if (-1 !== i) for (; this.stack.length > i;) this.popNode();else if ("p" === t || "br" === t) {
  252. var e = this.stack.length ? this.stack[this.stack.length - 1].children : this.nodes;
  253. e.push({
  254. name: t,
  255. attrs: {
  256. class: h[t],
  257. style: this.tagStyle[t]
  258. }
  259. });
  260. }
  261. }, r.prototype.popNode = function () {
  262. var i = this.stack.pop(),
  263. e = i.attrs,
  264. s = i.children,
  265. n = this.stack[this.stack.length - 1],
  266. r = n ? n.children : this.nodes;
  267. if (!this.hook(i) || l.ignoreTags[i.name]) return "title" === i.name && s.length && "text" === s[0].type && this.options.setTitle && uni.setNavigationBarTitle({
  268. title: s[0].text
  269. }), void r.pop();
  270. if (i.pre && 2 !== this.pre) {
  271. this.pre = i.pre = void 0;
  272. for (var o = this.stack.length; o--;) this.stack[o].pre && (this.pre = 1);
  273. }
  274. if ("svg" === i.name) {
  275. if (this.xml > 1) return void this.xml--;
  276. var h = "",
  277. c = e.style;
  278. return e.style = "", e.xmlns = "http://www.w3.org/2000/svg", function i(e) {
  279. if ("text" === e.type) return void (h += e.text);
  280. var s = l.svgDict[e.name] || e.name;
  281. if ("foreignObject" === s) {
  282. var n,
  283. a = t(e.children || []);
  284. try {
  285. for (a.s(); !(n = a.n()).done;) {
  286. var r = n.value;
  287. if (r.attrs && !r.attrs.xmlns) {
  288. r.attrs.xmlns = "http://www.w3.org/1999/xhtml";
  289. break;
  290. }
  291. }
  292. } catch (t) {
  293. a.e(t);
  294. } finally {
  295. a.f();
  296. }
  297. }
  298. h += "<" + s;
  299. for (var o in e.attrs) {
  300. var c = e.attrs[o];
  301. c && (h += " ".concat(l.svgDict[o] || o, '="').concat(c.replace(/"/g, ""), '"'));
  302. }
  303. if (e.children) {
  304. h += ">";
  305. for (var d = 0; d < e.children.length; d++) i(e.children[d]);
  306. h += "</" + s + ">";
  307. } else h += "/>";
  308. }(i), i.name = "img", i.attrs = {
  309. src: "data:image/svg+xml;utf8," + h.replace(/#/g, "%23"),
  310. style: c,
  311. ignore: "T"
  312. }, i.children = void 0, this.xml = !1, void (l.ignoreTags.style = !0);
  313. }
  314. var p = {};
  315. if (e.align && ("table" === i.name ? "center" === e.align ? p["margin-inline-start"] = p["margin-inline-end"] = "auto" : p.float = e.align : p["text-align"] = e.align, e.align = void 0), e.dir && (p.direction = e.dir, e.dir = void 0), "font" === i.name && (e.color && (p.color = e.color, e.color = void 0), e.face && (p["font-family"] = e.face, e.face = void 0), e.size)) {
  316. var u = parseInt(e.size);
  317. isNaN(u) || (u < 1 ? u = 1 : u > 7 && (u = 7), p["font-size"] = ["x-small", "small", "medium", "large", "x-large", "xx-large", "xxx-large"][u - 1]), e.size = void 0;
  318. }
  319. if ((e.class || "").includes("align-center") && (p["text-align"] = "center"), Object.assign(p, this.parseStyle(i)), "table" !== i.name && parseInt(p.width) > d && (p["max-width"] = "100%", p["box-sizing"] = "border-box"), l.blockTags[i.name]) i.name = "div";else if (l.trustTags[i.name] || this.xml) {
  320. if ("a" === i.name || "ad" === i.name) this.expose();else if ("video" === i.name || "audio" === i.name) (p.height || "").includes("auto") && (p.height = void 0), i.children = void 0;else if ("ul" !== i.name && "ol" !== i.name || !i.c) {
  321. if ("table" === i.name) {
  322. var f = parseFloat(e.cellpadding),
  323. g = parseFloat(e.cellspacing),
  324. m = parseFloat(e.border),
  325. v = p["border-color"],
  326. y = p["border-style"];
  327. if (i.c && (isNaN(f) && (f = 2), isNaN(g) && (g = 2)), m && (e.style += ";border:".concat(m, "px ").concat(y || "solid", " ").concat(v || "gray")), i.flag && i.c) {
  328. i.flag = void 0, p.display = "grid", "collapse" === p["border-collapse"] && (p["border-collapse"] = void 0, g = 0), g ? (p["grid-gap"] = g + "px", p.padding = g + "px") : m && (e.style += ";border-left:0;border-top:0");
  329. var b = [],
  330. x = [],
  331. w = [],
  332. k = {};
  333. !function i(e) {
  334. for (var s = 0; s < e.length; s++) if ("tr" === e[s].name) x.push(e[s]);else if ("colgroup" === e[s].name) {
  335. var n,
  336. a = 1,
  337. r = t(e[s].children || []);
  338. try {
  339. for (r.s(); !(n = r.n()).done;) {
  340. var o = n.value;
  341. if ("col" === o.name) {
  342. var l = o.attrs.style || "",
  343. h = l.indexOf("width") ? l.indexOf(";width") : 0;
  344. if (-1 !== h) {
  345. var c = l.indexOf(";", h + 6);
  346. -1 === c && (c = l.length), b[a] = l.substring(h ? h + 7 : 6, c);
  347. }
  348. a += 1;
  349. }
  350. }
  351. } catch (t) {
  352. r.e(t);
  353. } finally {
  354. r.f();
  355. }
  356. } else i(e[s].children || []);
  357. }(s);
  358. for (var N = 1; N <= x.length; N++) {
  359. for (var T = 1, O = 0; O < x[N - 1].children.length; O++) {
  360. var j = x[N - 1].children[O];
  361. if ("td" === j.name || "th" === j.name) {
  362. for (; k[N + "." + T];) T++;
  363. j.c = 1;
  364. var S = j.attrs.style || "",
  365. C = S.indexOf("width") ? S.indexOf(";width") : 0;
  366. if (-1 !== C) {
  367. var I = S.indexOf(";", C + 6);
  368. -1 === I && (I = S.length), j.attrs.colspan || (b[T] = S.substring(C ? C + 7 : 6, I)), S = S.substr(0, C) + S.substr(I);
  369. }
  370. if (S += ";display:flex;flex-direction:column", -1 !== (C = S.indexOf("vertical-align"))) {
  371. var A = S.substr(C + 15, 10);
  372. A.includes("middle") ? S += ";justify-content:center" : A.includes("bottom") && (S += ";justify-content:flex-end");
  373. } else S += ";justify-content:center";
  374. if (-1 !== (C = S.indexOf("text-align"))) {
  375. var L = S.substr(C + 11, 10);
  376. L.includes("center") ? S += ";justify-content: center" : L.includes("right") && (S += ";justify-content: right");
  377. }
  378. if (S = (m ? ";border:".concat(m, "px ").concat(y || "solid", " ").concat(v || "gray") + (g ? "" : ";border-right:0;border-bottom:0") : "") + (f ? ";padding:".concat(f, "px") : "") + ";" + S, j.attrs.colspan && (S += ";grid-column-start:".concat(T, ";grid-column-end:").concat(T + parseInt(j.attrs.colspan)), j.attrs.rowspan || (S += ";grid-row-start:".concat(N, ";grid-row-end:").concat(N + 1)), T += parseInt(j.attrs.colspan) - 1), j.attrs.rowspan) {
  379. S += ";grid-row-start:".concat(N, ";grid-row-end:").concat(N + parseInt(j.attrs.rowspan)), j.attrs.colspan || (S += ";grid-column-start:".concat(T, ";grid-column-end:").concat(T + 1));
  380. for (var z = 1; z < j.attrs.rowspan; z++) for (var F = 0; F < (j.attrs.colspan || 1); F++) k[N + z + "." + (T - F)] = 1;
  381. }
  382. S && (j.attrs.style = S), w.push(j), T++;
  383. }
  384. }
  385. if (1 === N) {
  386. for (var U = "", q = 1; q < T; q++) U += (b[q] ? b[q] : "auto") + " ";
  387. p["grid-template-columns"] = U;
  388. }
  389. }
  390. i.children = w;
  391. } else i.c && (p.display = "table"), isNaN(g) || (p["border-spacing"] = g + "px"), (m || f || i.c) && function t(e) {
  392. for (var s = 0; s < e.length; s++) {
  393. var n = e[s];
  394. i.c && (n.c = 1), "th" === n.name || "td" === n.name ? (m && (n.attrs.style = "border:".concat(m, "px ").concat(y || "solid", " ").concat(v || "gray", ";").concat(n.attrs.style || "")), f && (n.attrs.style = "padding:".concat(f, "px;").concat(n.attrs.style || ""))) : n.children && t(n.children);
  395. }
  396. }(s);
  397. if (this.options.scrollTable && !(e.style || "").includes("inline")) {
  398. var V = Object.assign({}, i);
  399. i.name = "div", i.attrs = {
  400. style: "overflow-x:auto;padding:1px"
  401. }, i.children = [V], e = V.attrs;
  402. }
  403. } else if (("tbody" === i.name || "tr" === i.name) && i.flag && i.c) i.flag = void 0, function t(i) {
  404. for (var e = 0; e < i.length; e++) if ("td" === i[e].name) for (var s = 0, n = ["color", "background", "background-color"]; s < n.length; s++) {
  405. var a = n[s];
  406. p[a] && (i[e].attrs.style = a + ":" + p[a] + ";" + (i[e].attrs.style || ""));
  407. } else t(i[e].children || []);
  408. }(s);else if ("td" !== i.name && "th" !== i.name || !e.colspan && !e.rowspan) {
  409. if ("ruby" === i.name) {
  410. i.name = "span";
  411. for (var D = 0; D < s.length - 1; D++) "text" === s[D].type && "rt" === s[D + 1].name && (s[D] = {
  412. name: "span",
  413. attrs: {
  414. style: "display:inline-block;text-align:center"
  415. },
  416. children: [{
  417. name: "div",
  418. attrs: {
  419. style: "font-size:50%;" + (s[D + 1].attrs.style || "")
  420. },
  421. children: s[D + 1].children
  422. }, s[D]]
  423. }, s.splice(D + 1, 1));
  424. }
  425. } else for (var B = this.stack.length; B--;) "table" !== this.stack[B].name && "tbody" !== this.stack[B].name && "tr" !== this.stack[B].name || (this.stack[B].flag = 1);
  426. } else {
  427. var M = {
  428. a: "lower-alpha",
  429. A: "upper-alpha",
  430. i: "lower-roman",
  431. I: "upper-roman"
  432. };
  433. M[e.type] && (e.style += ";list-style-type:" + M[e.type], e.type = void 0), i.c = 1;
  434. for (var P = s.length; P--;) "li" === s[P].name && (s[P].c = 1);
  435. }
  436. } else i.name = "span";
  437. if ((p.display || "").includes("flex") && !i.c) for (var Z = s.length; Z--;) {
  438. var _ = s[Z];
  439. _.f && (_.attrs.style = (_.attrs.style || "") + _.f, _.f = void 0);
  440. }
  441. var E = n && ((n.attrs.style || "").includes("flex") || (n.attrs.style || "").includes("grid")) && !i.c && !(p.display || "").includes("inline");
  442. E && (i.f = ";max-width:100%"), s.length >= 50 && i.c && !(p.display || "").includes("flex") && a(s);
  443. for (var G in p) if (p[G]) {
  444. var W = ";".concat(G, ":").concat(p[G].replace(" !important", ""));
  445. E && (G.includes("flex") && "flex-direction" !== G || "align-self" === G || G.includes("grid") || "-" === p[G][0] || G.includes("width") && W.includes("%")) ? (i.f += W, "width" === G && (e.style += ";width:100%")) : e.style += W;
  446. }
  447. e.style = e.style.substr(1) || void 0;
  448. }, r.prototype.onText = function (t) {
  449. if (!this.pre) {
  450. for (var i, e = "", s = 0, a = t.length; s < a; s++) u[t[s]] ? (" " !== e[e.length - 1] && (e += " "), "\n" !== t[s] || i || (i = !0)) : e += t[s];
  451. if (" " === e && i) return;
  452. t = e;
  453. }
  454. var r = Object.create(null);
  455. if (r.type = "text", r.text = n(t), this.hook(r)) {
  456. "force" === this.options.selectable && p.includes("iOS") && !uni.canIUse("rich-text.user-select") && this.expose();
  457. (this.stack.length ? this.stack[this.stack.length - 1].children : this.nodes).push(r);
  458. }
  459. }, o.prototype.parse = function (t) {
  460. this.content = t || "", this.i = 0, this.start = 0, this.state = this.text;
  461. for (var i = this.content.length; -1 !== this.i && this.i < i;) this.state();
  462. }, o.prototype.checkClose = function (t) {
  463. var i = "/" === this.content[this.i];
  464. return !!(">" === 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("</", this.i), -1 !== this.i && (this.i += 2, this.start = this.i), this.state = this.endTag) : this.state = this.text, !0);
  465. }, o.prototype.text = function () {
  466. if (this.i = this.content.indexOf("<", this.i), -1 === this.i) return void (this.start < this.content.length && this.handler.onText(this.content.substring(this.start, this.content.length)));
  467. var t = this.content[this.i + 1];
  468. if (t >= "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) {
  469. this.start !== this.i && this.handler.onText(this.content.substring(this.start, this.i));
  470. var i = this.content[this.i + 2];
  471. if ("/" === t && (i >= "a" && i <= "z" || i >= "A" && i <= "Z")) return this.i += 2, this.start = this.i, void (this.state = this.endTag);
  472. var e = "--\x3e";
  473. "!" === 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);
  474. } else this.i++;
  475. }, o.prototype.tagName = function () {
  476. if (u[this.content[this.i]]) {
  477. for (this.handler.onTagName(this.content.substring(this.start, this.i)); u[this.content[++this.i]];);
  478. this.i < this.content.length && !this.checkClose() && (this.start = this.i, this.state = this.attrName);
  479. } else this.checkClose("onTagName") || this.i++;
  480. }, o.prototype.attrName = function () {
  481. var t = this.content[this.i];
  482. if (u[t] || "=" === t) {
  483. this.handler.onAttrName(this.content.substring(this.start, this.i));
  484. for (var i = "=" === t, e = this.content.length; ++this.i < e;) if (t = this.content[this.i], !u[t]) {
  485. if (this.checkClose()) return;
  486. if (i) return this.start = this.i, void (this.state = this.attrVal);
  487. if ("=" !== this.content[this.i]) return this.start = this.i, void (this.state = this.attrName);
  488. i = !0;
  489. }
  490. } else this.checkClose("onAttrName") || this.i++;
  491. }, o.prototype.attrVal = function () {
  492. var t = this.content[this.i],
  493. i = this.content.length;
  494. if ('"' === t || "'" === t) {
  495. if (this.start = ++this.i, this.i = this.content.indexOf(t, this.i), -1 === this.i) return;
  496. this.handler.onAttrVal(this.content.substring(this.start, this.i));
  497. } else for (; this.i < i; this.i++) {
  498. if (u[this.content[this.i]]) {
  499. this.handler.onAttrVal(this.content.substring(this.start, this.i));
  500. break;
  501. }
  502. if (this.checkClose("onAttrVal")) return;
  503. }
  504. for (; u[this.content[++this.i]];);
  505. this.i < i && !this.checkClose() && (this.start = this.i, this.state = this.attrName);
  506. }, o.prototype.endTag = function () {
  507. var t = this.content[this.i];
  508. if (u[t] || ">" === t || "/" === t) {
  509. if (this.handler.onCloseTag(this.content.substring(this.start, this.i)), ">" !== t && (this.i = this.content.indexOf(">", this.i), -1 === this.i)) return;
  510. this.start = ++this.i, this.state = this.text;
  511. } else this.i++;
  512. }, module.exports = r;