jwps.es6.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. var e, t, n = function () {
  2. return (n = Object.assign || function (e) {
  3. for (var t, n = 1, o = arguments.length; n < o; n++) for (var r in t = arguments[n]) Object.prototype.hasOwnProperty.call(t, r) && (e[r] = t[r]);
  4. return e
  5. }).apply(this, arguments)
  6. }, o = function () {
  7. function e() {
  8. }
  9. return e.add = function (t) {
  10. e._handleList.push(t), window.addEventListener("message", t, !1)
  11. }, e.remove = function (t) {
  12. var n = e._handleList.indexOf(t);
  13. n >= 0 && e._handleList.splice(n, 1), window.removeEventListener("message", t, !1)
  14. }, e.empty = function () {
  15. for (; e._handleList.length;) window.removeEventListener("message", e._handleList.shift(), !1)
  16. }, e.parse = function (e) {
  17. return "object" == typeof e ? e : JSON.parse(e)
  18. }, e._handleList = [], e
  19. }();
  20. !function (e) {
  21. e.unknown = "unknown", e.spreadsheet = "s", e.writer = "w", e.presentation = "p", e.pdf = "f"
  22. }(e || (e = {})), function (e) {
  23. e.wps = "w", e.et = "s", e.presentation = "p", e.pdf = "f"
  24. }(t || (t = {}));
  25. var r, i, a, p, c, s, u, d = (r = 0, function () {
  26. return ++r
  27. }), f = (i = null, function (e, t) {
  28. if (!i) {
  29. i = document.createElement("iframe");
  30. var n = {
  31. id: "wps-iframe",
  32. src: e,
  33. scrolling: "no",
  34. frameborder: "0",
  35. allowfullscreen: "allowfullscreen",
  36. webkitallowfullscreen: "true",
  37. mozallowfullscreen: "true",
  38. height: 'auto',
  39. width: '100%'
  40. };
  41. for (var o in n) i.setAttribute(o, n[o]);
  42. t ? t.appendChild(i) : document.body.appendChild(i), i.destroy = function () {
  43. i.parentNode.removeChild(i), i = null
  44. }
  45. }
  46. return i
  47. }), l = function (e) {
  48. f().contentWindow.postMessage(JSON.stringify(e), "*")
  49. }, m = function (e) {
  50. return new Promise(function (t) {
  51. var n = d();
  52. e.type = y();
  53. var r = function (e) {
  54. var i = o.parse(e.data);
  55. "wps.api.reply" === i.eventName && i.msgId === n && (t(i.data), o.remove(r))
  56. };
  57. o.add(r), l({eventName: "wps.jssdk.api", data: e, msgId: n})
  58. })
  59. }, v = function (e) {
  60. var t = n({}, e), o = t.headers, r = void 0 === o ? {} : o, i = t.subscriptions, a = void 0 === i ? {} : i,
  61. p = (t.wpsUrl, r.backBtn), c = void 0 === p ? {} : p, s = r.shareBtn, u = void 0 === s ? {} : s,
  62. d = r.otherMenuBtn, f = void 0 === d ? {} : d, l = function (e, t) {
  63. e.subscribe && "function" == typeof e.subscribe && (e.callback = t, a[t] = e.subscribe, delete e.subscribe)
  64. };
  65. if (l(c, "wpsconfig_back_btn"), l(u, "wpsconfig_share_btn"), l(f, "wpsconfig_other_menu_btn"), f.items && Array.isArray(f.items)) {
  66. var m = [];
  67. f.items.forEach(function (e, t) {
  68. switch (void 0 === e && (e = {}), e.type) {
  69. case"export_img":
  70. e.type = 1, e.callback = "export_img";
  71. break;
  72. case"export_pdf":
  73. e.type = 1, e.callback = "export_pdf";
  74. break;
  75. case"save_version":
  76. e.type = 1, e.callback = "save_version";
  77. break;
  78. case"about_wps":
  79. e.type = 1, e.callback = "about_wps";
  80. break;
  81. case"split_line":
  82. e.type = 2;
  83. break;
  84. case"custom":
  85. e.type = 3, l(e, "wpsconfig_other_menu_btn_" + t), m.push(e)
  86. }
  87. }), m.length && (x || b) && (f.items = m)
  88. }
  89. if ("object" == typeof a.print) {
  90. var v = "wpsconfig_print";
  91. "function" == typeof a.print.subscribe && (a[v] = a.print.subscribe, t.print = {callback: v}, void 0 !== a.print.custom && (t.print.custom = a.print.custom)), delete a.print
  92. }
  93. "function" == typeof a.exportPdf && (a[v = "wpsconfig_export_pdf"] = a.exportPdf, t.exportPdf = {callback: v}, delete a.exportPdf);
  94. return n({}, t, {subscriptions: a})
  95. }, y = (a = "", function (n) {
  96. if (void 0 === n && (n = ""), !a && n) {
  97. var o = n.toLowerCase();
  98. -1 !== o.indexOf("/office/s/") && (a = e.spreadsheet), -1 !== o.indexOf("/office/w/") && (a = e.writer), -1 !== o.indexOf("/office/p/") && (a = e.presentation), -1 !== o.indexOf("/office/f/") && (a = e.pdf)
  99. }
  100. if (!a) {
  101. var r = n.match(/[\\?&]type=([a-z]+)/) || [];
  102. a = t[r[1]] || ""
  103. }
  104. return a
  105. }), w = window.navigator.userAgent.toLowerCase(), x = /Android|webOS|iPhone|iPod|BlackBerry|iPad/i.test(w),
  106. b = function () {
  107. try {
  108. return -1 !== window._parent.location.search.indexOf("from=wxminiprogram")
  109. } catch (e) {
  110. return !1
  111. }
  112. }();
  113. !function (e) {
  114. e[e.wdExportFormatPDF = 17] = "wdExportFormatPDF", e[e.wdExportFormatXPS = 18] = "wdExportFormatXPS"
  115. }(p || (p = {})), function (e) {
  116. e[e.wdExportAllDocument = 0] = "wdExportAllDocument", e[e.wdExportSelection = 1] = "wdExportSelection", e[e.wdExportCurrentPage = 2] = "wdExportCurrentPage", e[e.wdExportFromTo = 3] = "wdExportFromTo"
  117. }(c || (c = {})), function (e) {
  118. e[e.wdExportDocumentContent = 0] = "wdExportDocumentContent", e[e.wdExportDocumentWithMarkup = 7] = "wdExportDocumentWithMarkup"
  119. }(s || (s = {})), function (e) {
  120. e[e.title = 1] = "title", e[e.tag = 2] = "tag"
  121. }(u || (u = {}));
  122. var F;
  123. !function (e) {
  124. e[e.xlTypePDF = 0] = "xlTypePDF", e[e.xlTypeXPS = 1] = "xlTypeXPS"
  125. }(F || (F = {}));
  126. var A, g, E;
  127. !function (e) {
  128. e[e.ppFixedFormatTypePDF = 2] = "ppFixedFormatTypePDF", e[e.ppFixedFormatTypeXPS = 1] = "ppFixedFormatTypeXPS"
  129. }(A || (A = {})), function (e) {
  130. e[e.ppPrintAll = 1] = "ppPrintAll", e[e.ppPrintCurrent = 3] = "ppPrintCurrent"
  131. }(g || (g = {})), function (e) {
  132. e[e.msoFalse = 0] = "msoFalse", e[e.msoTrue = -1] = "msoTrue"
  133. }(E || (E = {}));
  134. var h;
  135. function P(e) {
  136. return e = e || Object.create(null), {
  137. on: function (t, n) {
  138. (e[t] || (e[t] = [])).push(n)
  139. }, off: function (t, n) {
  140. e[t] && e[t].splice(e[t].indexOf(n) >>> 0, 1)
  141. }, emit: function (t, n) {
  142. (e[t] || []).slice().map(function (e) {
  143. e(n)
  144. }), (e["*"] || []).slice().map(function (e) {
  145. e(t, n)
  146. })
  147. }
  148. }
  149. }
  150. var k = "fileOpen", D = function (e) {
  151. return "wps.advanced.api.ready" === e || "web_loaded" === e
  152. }, _ = function (e, t) {
  153. void 0 === e && (e = {});
  154. o.add(function (n) {
  155. var r = o.parse(n.data), i = r.eventName, a = void 0 === i ? "" : i, p = r.data, c = void 0 === p ? null : p,
  156. s = r.url, u = void 0 === s ? null : s;
  157. -1 === ["wps.jssdk.api"].indexOf(a) && ("ready" === a ? (l({
  158. eventName: "setConfig",
  159. data: e
  160. }), h.tokenData && l({
  161. eventName: "setToken",
  162. data: h.tokenData
  163. }), h.iframeReady = !0) : "open.result" === a && h.emit(k, c), D(a) && T(), "function" == typeof t[a] && t[a](h, u || c))
  164. })
  165. }, T = function () {
  166. var t = y(h.url);
  167. t === e.writer && function (e) {
  168. e.WpsApplication = function () {
  169. return {
  170. ActiveDocument: {
  171. ExportAsFixedFormatAsync: function (e) {
  172. var t = {
  173. api: "WpsApplication().ActiveDocument.ExportAsFixedFormatAsync",
  174. args: n({
  175. ExportFormat: p.wdExportFormatPDF,
  176. Range: c.wdExportAllDocument,
  177. From: 1,
  178. To: 1,
  179. Item: s.wdExportDocumentWithMarkup,
  180. IncludeDocProps: !0
  181. }, "object" == typeof e ? e : {})
  182. };
  183. return m(t)
  184. }, ImportDataIntoFieldsAsync: function (e) {
  185. var t = {
  186. api: "WpsApplication().ActiveDocument.ImportDataIntoFieldsAsync",
  187. args: {Data: e.Data, Options: e.Options}
  188. };
  189. return m(t)
  190. }, ReplaceTextAsync: function (e) {
  191. var t = {api: "WpsApplication().ActiveDocument.ReplaceTextAsync", args: {Data: e.Data}};
  192. return m(t)
  193. }
  194. }, Enum: n({}, p, c, s)
  195. }
  196. }
  197. }(h), t === e.spreadsheet && function (e) {
  198. e.EtApplication = function () {
  199. return {
  200. ActiveWorkbook: {
  201. ExportAsFixedFormatAsync: function (e) {
  202. var t = {
  203. api: "EtApplication().ActiveWorkbook.ExportAsFixedFormatAsync",
  204. args: n({Type: F.xlTypePDF, IncludeDocProps: !0}, "object" == typeof e ? e : {})
  205. };
  206. return m(t)
  207. }, ActiveSheet: {
  208. ExportAsFixedFormatAsync: function (e) {
  209. var t = {
  210. api: "EtApplication().ActiveWorkbook.ActiveSheet.ExportAsFixedFormatAsync",
  211. args: n({Type: F.xlTypePDF, IncludeDocProps: !0}, "object" == typeof e ? e : {})
  212. };
  213. return m(t)
  214. }
  215. }
  216. }, Enum: n({}, F)
  217. }
  218. }
  219. }(h), t === e.presentation && function (e) {
  220. e.WppApplication = function () {
  221. return {
  222. ActivePresentation: {
  223. ExportAsFixedFormatAsync: function (e) {
  224. var t = {
  225. api: "WppApplication().ActivePresentation.ExportAsFixedFormatAsync",
  226. args: n({
  227. FixedFormatType: A.ppFixedFormatTypePDF,
  228. RangeType: g.ppPrintAll,
  229. FrameSlides: E.msoTrue
  230. }, "object" == typeof e ? e : {})
  231. };
  232. return m(t)
  233. }
  234. }, Enum: n({}, A, g)
  235. }
  236. }
  237. }(h)
  238. };
  239. // console.log("WPS WebOffice JS-SDK V1.0.11");
  240. var O = function (e) {
  241. void 0 === e && (e = {}), h && h.destroy();
  242. try {
  243. var t, r = v(e), i = r.wpsUrl, a = r.subscriptions, p = void 0 === a ? {} : a, c = r.mount,
  244. s = f(i, void 0 === c ? null : c);
  245. return delete r.mount, delete r.wpsUrl, delete r.subscriptions, h = {
  246. url: i,
  247. version: "1.0.11",
  248. iframe: s,
  249. Enum: n({}, E),
  250. iframeReady: !1,
  251. tokenData: null,
  252. setToken: function (e) {
  253. h.tokenData = e, h.iframeReady && l({eventName: "setToken", data: e})
  254. },
  255. ready: function () {
  256. return t || (t = new Promise(function (e) {
  257. var t = function (n) {
  258. var r = o.parse(n.data).eventName;
  259. D(r) && (e(), o.remove(t))
  260. };
  261. o.add(t)
  262. }))
  263. },
  264. destroy: function () {
  265. s.destroy(), o.empty(), h = null
  266. },
  267. save: function () {
  268. return m({api: "save"})
  269. }
  270. }, Object.assign(h, new P.prototype.constructor), _(r, p), h.ready(), h
  271. } catch (e) {
  272. // console.error(e)
  273. }
  274. };
  275. export default {config: O};
  276. export {O as config};
  277. //# sourceMappingURL=jwps.es6.js.map