第一版绿谷官网
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

1012 lines
30 KiB

/* eslint-disable */
var e = function() {
return (e =
Object.assign ||
function(e) {
for (var t, n = 1, r = arguments.length; n < r; n++)
for (var o in (t = arguments[n]))
Object.prototype.hasOwnProperty.call(t, o) && (e[o] = t[o]);
return e;
}).apply(this, arguments);
};
function t(e, t, n, r) {
return new (n || (n = Promise))(function(o, i) {
function a(e) {
try {
s(r.next(e));
} catch (e) {
i(e);
}
}
function c(e) {
try {
s(r.throw(e));
} catch (e) {
i(e);
}
}
function s(e) {
e.done
? o(e.value)
: new n(function(t) {
t(e.value);
}).then(a, c);
}
s((r = r.apply(e, t || [])).next());
});
}
function n(e, t) {
var n,
r,
o,
i,
a = {
label: 0,
sent: function() {
if (1 & o[0]) throw o[1];
return o[1];
},
trys: [],
ops: [],
};
return (
(i = { next: c(0), throw: c(1), return: c(2) }),
'function' == typeof Symbol &&
(i[Symbol.iterator] = function() {
return this;
}),
i
);
function c(i) {
return function(c) {
return (function(i) {
if (n) throw new TypeError('Generator is already executing.');
for (; a; )
try {
if (
((n = 1),
r &&
(o =
2 & i[0]
? r.return
: i[0]
? r.throw || ((o = r.return) && o.call(r), 0)
: r.next) &&
!(o = o.call(r, i[1])).done)
)
return o;
switch (((r = 0), o && (i = [2 & i[0], o.value]), i[0])) {
case 0:
case 1:
o = i;
break;
case 4:
return a.label++, { value: i[1], done: !1 };
case 5:
a.label++, (r = i[1]), (i = [0]);
continue;
case 7:
(i = a.ops.pop()), a.trys.pop();
continue;
default:
if (
!(o = (o = a.trys).length > 0 && o[o.length - 1]) &&
(6 === i[0] || 2 === i[0])
) {
a = 0;
continue;
}
if (3 === i[0] && (!o || (i[1] > o[0] && i[1] < o[3]))) {
a.label = i[1];
break;
}
if (6 === i[0] && a.label < o[1]) {
(a.label = o[1]), (o = i);
break;
}
if (o && a.label < o[2]) {
(a.label = o[2]), a.ops.push(i);
break;
}
o[2] && a.ops.pop(), a.trys.pop();
continue;
}
i = t.call(e, a);
} catch (e) {
(i = [6, e]), (r = 0);
} finally {
n = o = 0;
}
if (5 & i[0]) throw i[1];
return { value: i[0] ? i[1] : void 0, done: !0 };
})([i, c]);
};
}
}
var r = (function() {
function e() {}
return (
(e.add = function(t) {
e._handleList.push(t), window.addEventListener('message', t, !1);
}),
(e.remove = function(t) {
var n = e._handleList.indexOf(t);
n >= 0 && e._handleList.splice(n, 1), window.removeEventListener('message', t, !1);
}),
(e.empty = function() {
for (; e._handleList.length; )
window.removeEventListener('message', e._handleList.shift(), !1);
}),
(e.parse = function(e) {
return 'object' == typeof e ? e : e ? JSON.parse(e) : e;
}),
(e._handleList = []),
e
);
})();
var o,
i,
a,
c = this;
!(function(e) {
(e.unknown = 'unknown'),
(e.spreadsheet = 's'),
(e.writer = 'w'),
(e.presentation = 'p'),
(e.pdf = 'f');
})(o || (o = {})),
(function(e) {
(e.wps = 'w'), (e.et = 's'), (e.presentation = 'p'), (e.pdf = 'f');
})(i || (i = {})),
(function(e) {
(e.nomal = 'nomal'), (e.simple = 'simple');
})(a || (a = {}));
var s,
u,
p =
((s = 0),
function() {
return ++s;
}),
l = function(e, t, n) {
if ((void 0 === n && (n = !0), !u)) {
var r = function(e) {
u.style.cssText += 'height: ' + e.clientHeight + 'px; width: ' + e.clientWidth + 'px';
}.bind(null, t);
(u = document.createElement('iframe')).classList.add('web-office-iframe');
var o = {
id: 'office-iframe',
src: e,
scrolling: 'no',
frameborder: '0',
allowfullscreen: 'allowfullscreen',
webkitallowfullscreen: 'true',
mozallowfullscreen: 'true',
};
for (var i in (t
? ((o.style = 'width: ' + t.clientWidth + 'px; height: ' + t.clientHeight + 'px;'),
n && window.addEventListener('resize', r))
: ((t = document.createElement('div')).classList.add('web-office-default-container'),
(function(e) {
var t = document.createElement('style');
document.head.appendChild(t);
var n = t.sheet;
n.insertRule(e, n.cssRules.length);
})(
'.web-office-default-container {position: absolute; padding: 0; margin: 0; width: 100vw; height: 100vh; left: 0; top: 0;}',
),
document.body.appendChild(t),
(o.style = 'width: 100vw; height: 100vh;')),
o))
u.setAttribute(i, o[i]);
t.appendChild(u),
(u.destroy = function() {
u.parentNode.removeChild(u), (u = null), window.removeEventListener('resize', r);
});
}
return u;
};
var d = function(e) {
l().contentWindow.postMessage(JSON.stringify(e), '*');
};
function f(e, t, n) {
return new Promise(function(o) {
var i = p(),
a = function(e) {
var t = r.parse(e.data);
t.eventName === n && t.msgId === i && (o(t.data), r.remove(a));
};
r.add(a), d({ eventName: t, data: e, msgId: i });
});
}
var v = function(e) {
return f(e, 'wps.jssdk.api', 'wps.api.reply');
},
b = function(e) {
return f(e, 'api.basic', 'api.basic.reply');
},
h = function(o, i, a, s) {
return t(c, void 0, void 0, function() {
var c, u, l, f, v, b, h, w;
return n(this, function(g) {
switch (g.label) {
case 0:
return (
(c = p()),
(f = new Promise(function(e, t) {
(u = e), (l = t);
})),
(v = {}),
i.args ? [4, m(i.args)] : [3, 2]
);
case 1:
(b = g.sent()), (h = b[0]), (w = b[1]), (i.args = h), (v = w), (g.label = 2);
case 2:
return (
(function(t) {
var n = t[0],
r = t[1];
'function' == typeof (n = e({}, n)).data && (n.data = n.data());
r(), d(n);
})([
{ eventName: o, data: i, msgId: c },
function() {
var e = this,
i = function(p) {
return t(e, void 0, void 0, function() {
var e, t, f;
return n(this, function(n) {
switch (n.label) {
case 0:
return 'api.callback' === (e = r.parse(p.data)).eventName &&
e.callbackId &&
v[e.callbackId]
? [4, v[e.callbackId].apply(v, e.data.args)]
: [3, 2];
case 1:
(t = n.sent()),
d({
eventName: 'api.callback.reply',
result: t,
callbackId: e.callbackId,
}),
(n.label = 2);
case 2:
return (
e.eventName === o + '.reply' &&
e.msgId === c &&
(e.error
? (((f = new Error('')).stack = e.error + '\n' + a),
s && s(),
l(f))
: u(e.result),
r.remove(i)),
[2]
);
}
});
});
};
return r.add(i), f;
},
]),
[2, f]
);
}
});
});
};
function m(e) {
return t(this, void 0, void 0, function() {
var t, r, o, i, a, c, s;
return n(this, function(n) {
switch (n.label) {
case 0:
(t = {}), (r = []), (e = e.slice(0)), (n.label = 1);
case 1:
return e.length ? ((o = void 0), [4, e.shift()]) : [3, 3];
case 2:
if (
((i = n.sent()),
(function(e) {
if (!e) return !1;
for (var t = e; null !== Object.getPrototypeOf(t); ) t = Object.getPrototypeOf(t);
return Object.getPrototypeOf(e) === t;
})(o))
)
for (a in ((o = {}), i))
'function' == typeof (c = i[a]) && ((s = p()), (t[s] = c), (c = { callbackId: s })),
(o[a] = c);
else 'function' == typeof i ? ((s = p()), (t[s] = i), (o = { callbackId: s })) : (o = i);
return r.push(o), [3, 1];
case 3:
return [2, [r, t]];
}
});
});
}
var w = function(t, n) {
void 0 === n && (n = !0);
var r = e({}, t),
o = r.headers,
i = void 0 === o ? {} : o,
c = r.subscriptions,
s = void 0 === c ? {} : c,
u = r.mode,
p = void 0 === u ? a.nomal : u,
l = i.backBtn,
d = void 0 === l ? {} : l,
f = i.shareBtn,
v = void 0 === f ? {} : f,
b = i.otherMenuBtn,
h = void 0 === b ? {} : b,
m = function(e, t) {
e.subscribe &&
'function' == typeof e.subscribe &&
((e.callback = t), (s[t] = e.subscribe), n && delete e.subscribe);
};
if (
(m(d, 'wpsconfig_back_btn'),
m(v, 'wpsconfig_share_btn'),
m(h, 'wpsconfig_other_menu_btn'),
h.items && Array.isArray(h.items))
) {
var w = [];
h.items.forEach(function(e, t) {
switch ((void 0 === e && (e = {}), e.type)) {
case 'export_img':
(e.type = 1), (e.callback = 'export_img');
break;
case 'export_pdf':
(e.type = 1), (e.callback = 'export_pdf');
break;
case 'save_version':
(e.type = 1), (e.callback = 'save_version');
break;
case 'about_wps':
(e.type = 1), (e.callback = 'about_wps');
break;
case 'split_line':
e.type = 2;
break;
case 'custom':
(e.type = 3), m(e, 'wpsconfig_other_menu_btn_' + t), w.push(e);
}
}),
w.length && (I || k) && (h.items = w);
}
if (
((r.url = r.url || r.wpsUrl),
(p === a.simple || (r.commonOptions && !1 === r.commonOptions.isShowTopArea)) &&
r.url &&
(r.url += '&simple&hidecmb'),
r.debug && r.url && (r.url += '&debugger'),
r.wordOptions && (r.wpsOptions = r.wordOptions),
r.excelOptions && (r.etOptions = r.excelOptions),
r.pptOptions && (r.wppOptions = r.pptOptions),
'object' == typeof s.print)
) {
var g = 'wpsconfig_print';
'function' == typeof s.print.subscribe &&
((s[g] = s.print.subscribe),
(r.print = { callback: g }),
void 0 !== s.print.custom && (r.print.custom = s.print.custom)),
delete s.print;
}
'function' == typeof s.exportPdf &&
((s[(g = 'wpsconfig_export_pdf')] = s.exportPdf),
(r.exportPdf = { callback: g }),
delete s.exportPdf);
return r.commandBars && y(r.commandBars, !1), e({}, r, { subscriptions: s });
},
g = function(e) {
void 0 === e && (e = '');
var t = '';
if (!t && e) {
var n = e.toLowerCase();
-1 !== n.indexOf('/office/s/') && (t = o.spreadsheet),
-1 !== n.indexOf('/office/w/') && (t = o.writer),
-1 !== n.indexOf('/office/p/') && (t = o.presentation),
-1 !== n.indexOf('/office/f/') && (t = o.pdf);
}
if (!t) {
var r = e.match(/[\?&]type=([a-z]+)/) || [];
t = i[r[1]] || '';
}
return t;
};
function y(e, t) {
void 0 === t && (t = !0);
var n = e.map(function(e) {
var t = e.attributes;
if (!Array.isArray(t)) {
var n = [];
for (var r in t)
if (t.hasOwnProperty(r)) {
var o = { name: r, value: t[r] };
n.push(o);
}
e.attributes = n;
}
return e;
});
return t && d({ eventName: 'setCommandBars', data: n }), n;
}
var j = window.navigator.userAgent.toLowerCase(),
I = /Android|webOS|iPhone|iPod|BlackBerry|iPad/i.test(j),
k = (function() {
try {
return -1 !== window._parent.location.search.indexOf('from=wxminiprogram');
} catch (e) {
return !1;
}
})();
function O(e) {
return (
(e = e || Object.create(null)),
{
on: function(t, n) {
(e[t] || (e[t] = [])).push(n);
},
off: function(t, n) {
e[t] && e[t].splice(e[t].indexOf(n) >>> 0, 1);
},
emit: function(t, n) {
(e[t] || []).slice().map(function(e) {
e(n);
}),
(e['*'] || []).slice().map(function(e) {
e(t, n);
});
},
}
);
}
var _ = 0,
x = new Set();
function E(e) {
return (
++_,
!e &&
(function(e) {
x.forEach(function(t) {
return t(e);
});
})(_),
_
);
}
function C(i, a) {
var c,
s = this,
u = a.Events,
p = a.Enum,
l = a.Props,
f = l[0],
v = l[1],
b = { objId: _ };
switch (
((function t(n, r, o) {
r = r.slice(0);
var i = function() {
var i = r.shift();
!i.alias && ~A.indexOf(i.prop) && r.push(e({}, i, { alias: i.prop + 'Async' })),
Object.defineProperty(n, i.alias || i.prop, {
get: function() {
var r = this,
a = 1 === i.cache,
c = a && this['__' + i.prop + 'CacheValue'];
if (c) return c;
var s = new Error(''),
u = s.stack
.split('\n')
.slice(2)
.join('\n'),
p = E(a),
l = function() {
for (var t, r = [], a = 0; a < arguments.length; a++) r[a] = arguments[a];
void 0 !== i.caller
? (function t(n, r, o) {
r = r.slice(0);
var i = function() {
var i = r.shift();
!i.alias &&
~A.indexOf(i.prop) &&
r.push(e({}, i, { alias: i.prop + 'Async' })),
Object.defineProperty(n, i.alias || i.prop, {
get: function() {
var e = this,
r = 1 === i.cache,
a = r && this['__' + i.prop + 'CacheValue'];
if (a) return a;
var c = new Error(''),
s = c.stack
.split('\n')
.slice(2)
.join('\n'),
u = E(r),
p = function() {
for (var e, r = [], a = 0; a < arguments.length; a++)
r[a] = arguments[a];
void 0 !== i.caller
? t((e = { objId: E() }), o[i.caller], o)
: (e = {});
return (
S(
p,
e,
'api.caller',
{
obj: p,
parentObjId: n.objId,
objId: e.objId,
args: r,
prop: i.prop,
},
s,
),
e
);
};
return (
(p.objId = -1),
void 0 !== i.getter && ((p.objId = u), t(p, o[i.getter], o)),
S(
n,
p,
'api.getter',
{ parentObjId: n.objId, objId: p.objId, prop: i.prop },
s,
function() {
delete e['__' + i.prop + 'CacheValue'];
},
),
r && (this['__' + i.prop + 'CacheValue'] = p),
p
);
},
set: function(e) {
var t = new Error(''),
r = t.stack
.split('\n')
.slice(2)
.join('\n');
return S(
n,
{},
'api.setter',
{ parentObjId: n.objId, objId: -1, prop: i.prop, value: e },
r,
);
},
});
};
for (; r.length; ) i();
})((t = { objId: E() }), o[i.caller], o)
: (t = {});
return (
S(
l,
t,
'api.caller',
{ obj: l, parentObjId: n.objId, objId: t.objId, args: r, prop: i.prop },
u,
),
t
);
};
return (
(l.objId = -1),
void 0 !== i.getter && ((l.objId = p), t(l, o[i.getter], o)),
S(
n,
l,
'api.getter',
{ parentObjId: n.objId, objId: l.objId, prop: i.prop },
u,
function() {
delete r['__' + i.prop + 'CacheValue'];
},
),
a && (this['__' + i.prop + 'CacheValue'] = l),
l
);
},
set: function(e) {
var t = new Error(''),
r = t.stack
.split('\n')
.slice(2)
.join('\n');
return S(
n,
{},
'api.setter',
{ parentObjId: n.objId, objId: -1, prop: i.prop, value: e },
r,
);
},
});
};
for (; r.length; ) i();
})(b, f, v),
(b.Events = u),
(b.Enum = p),
(i.Enum = b.Enum),
(i.Events = b.Events),
g(i.url))
) {
case o.writer:
i.WordApplication = i.WpsApplication = function() {
return b;
};
break;
case o.spreadsheet:
i.ExcelApplication = i.EtApplication = function() {
return b;
};
break;
case o.presentation:
i.PPTApplication = i.WppApplication = function() {
return b;
};
break;
case o.pdf:
i.PDFApplication = function() {
return b;
};
}
(i.Application = b),
(i.Free = function(e) {
return h('api.free', { objId: e }, '');
}),
(i.Stack = b.Stack =
((c = function(e) {
return i.Free(e);
}),
function() {
var e = [],
t = function(t) {
e.push(t);
};
return (
x.add(t),
{
End: function() {
c(e), x.delete(t);
},
}
);
}));
var m = {};
r.add(function(e) {
return t(s, void 0, void 0, function() {
var t, o, i, a, c;
return n(this, function(n) {
switch (n.label) {
case 0:
return 'api.event' === (t = r.parse(e.data)).eventName && t.data
? ((o = t.data),
(i = o.eventName),
(a = o.data),
o.objIds,
(c = m[i]) ? [4, c(a)] : [3, 2])
: [3, 2];
case 1:
n.sent(), (n.label = 2);
case 2:
return [2];
}
});
});
}),
(b.Sub = {}),
Object.values(u).forEach(function(e) {
Object.defineProperty(b.Sub, e, {
set: function(t) {
(m[e] = t),
d({
eventName: 'api.event.register',
data: { eventName: e, register: !!t, objId: ++_ },
});
},
});
});
}
var P,
A = [
'ExportAsFixedFormat',
'GetOperatorsInfo',
'ImportDataIntoFields',
'ReplaceText',
'ReplaceBookmark',
'GetBookmarkText',
'GetComments',
];
function N(t, n, r) {
n = n.slice(0);
var o = function() {
var o = n.shift();
if (!o.alias && ~A.indexOf(o.prop)) {
n.push(e({}, o, { alias: o.prop + 'Async' }));
}
Object.defineProperty(t, o.alias || o.prop, {
get: function() {
var e = this;
var n = o.cache === 1;
var i = n && this['__' + o.prop + 'CacheValue'];
if (!i) {
var a = new Error('');
var c = a.stack
.split('\n')
.slice(2)
.join('\n');
var s = E(n);
var u = function() {
for (var e = [], n = 0, i; n < arguments.length; n++) {
e[n] = arguments[n];
}
if (o.caller !== undefined) {
i = { objId: E() };
N(i, r[o.caller], r);
} else {
i = {};
}
return (
S(
p,
i,
'api.caller',
{ obj: p, parentObjId: t.objId, objId: i.objId, args: e, prop: o.prop },
c,
),
i
);
};
var p = u;
p.objId = -1;
if (o.getter !== undefined) {
p.objId = s;
N(p, r[o.getter], r);
}
S(
t,
p,
'api.getter',
{ parentObjId: t.objId, objId: p.objId, prop: o.prop },
c,
function() {
delete e['__' + o.prop + 'CacheValue'];
},
);
if (n) {
this['__' + o.prop + 'CacheValue'] = p;
}
return p;
} else {
return i;
}
},
set: function(e) {
var n = new Error('');
var r = n.stack
.split('\n')
.slice(2)
.join('\n');
return S(
t,
{},
'api.setter',
{ parentObjId: t.objId, objId: -1, prop: o.prop, value: e },
r,
);
},
});
};
while (n.length) {
o();
}
}
function S(e, t, n, r, o, i) {
var a = Promise.resolve(e)
.catch(function() {})
.then(function() {
return h(n, r, o, i);
});
(t.then = function(e, t) {
return a.then(e, t);
}),
(t.catch = function(e) {
return a.catch(e);
}),
(t.Destroy = function() {
return h('api.free', { objId: t.objId }, '');
});
}
var B = 'fileOpen',
L = 'tabSwitch',
T = 'fileSaved',
D = 'error',
V = function(e, t) {
void 0 === e && (e = {});
r.add(function(n) {
var o = r.parse(n.data),
i = o.eventName,
a = void 0 === i ? '' : i,
c = o.data,
s = void 0 === c ? null : c,
u = o.url,
p = void 0 === u ? null : u;
-1 === ['wps.jssdk.api'].indexOf(a) &&
('ready' === a
? (d({ eventName: 'setConfig', data: e }),
P.tokenData && P.setToken(P.tokenData),
(P.iframeReady = !0))
: 'error' === a
? P.emit(D, s)
: 'open.result' === a
? P.emit(B, s)
: 'file.saved' === a
? P.emit(T, s)
: 'tab.switch' === a
? P.emit(L, s)
: 'api.scroll' === a && window.scrollTo(s.x, s.y),
'function' == typeof t[a] && t[a](P, p || s));
});
};
function W(e) {
return new Promise(function(t) {
var n = function(o) {
var i = r.parse(o.data),
a = i.eventName,
c = i.data;
a === e && ('api.ready' === a && C(P, c), t(), r.remove(n));
};
r.add(n);
});
}
function F(o) {
void 0 === o && (o = {}), P && P.destroy();
try {
var i = w(o),
a = i.subscriptions,
c = void 0 === a ? {} : a,
s = i.mount,
u = void 0 === s ? null : s,
p = i.url,
f = l(p, u),
h = W('ready'),
m = W('api.ready');
return (
delete i.mount,
p && delete i.url,
delete i.subscriptions,
(P = e(
{},
(P = {
url: p,
version: '1.1.2',
iframe: f,
iframeReady: !1,
tokenData: null,
commandBars: null,
tabs: {
getTabs: function() {
return t(this, void 0, void 0, function() {
return n(this, function(e) {
switch (e.label) {
case 0:
return [4, h];
case 1:
return e.sent(), [2, b({ api: 'tab.getTabs' })];
}
});
});
},
switchTab: function(e) {
return t(this, void 0, void 0, function() {
return n(this, function(t) {
switch (t.label) {
case 0:
return [4, h];
case 1:
return t.sent(), [2, b({ api: 'tab.switchTab', args: { tabKey: e } })];
}
});
});
},
},
setCooperUserColor: function(e) {
return t(this, void 0, void 0, function() {
return n(this, function(t) {
switch (t.label) {
case 0:
return [4, h];
case 1:
return t.sent(), [2, b({ api: 'setCooperUserColor', args: e })];
}
});
});
},
setToken: function(e) {
return t(this, void 0, void 0, function() {
return n(this, function(t) {
switch (t.label) {
case 0:
return [4, h];
case 1:
return t.sent(), (P.tokenData = e), d({ eventName: 'setToken', data: e }), [2];
}
});
});
},
ready: function() {
return m;
},
destroy: function() {
f.destroy(), r.empty(), (P = null), (x = new Set()), (_ = 0);
},
save: function() {
return t(this, void 0, void 0, function() {
return n(this, function(e) {
switch (e.label) {
case 0:
return [4, h];
case 1:
return e.sent(), [2, v({ api: 'save' })];
}
});
});
},
setCommandBars: function(e) {
return t(this, void 0, void 0, function() {
return n(this, function(t) {
switch (t.label) {
case 0:
return [4, h];
case 1:
return t.sent(), y(e), [2];
}
});
});
},
updateConfig: function(e) {
return (
void 0 === e && (e = {}),
t(this, void 0, void 0, function() {
return n(this, function(t) {
switch (t.label) {
case 0:
return [4, h];
case 1:
return (
t.sent(),
e.commandBars
? (console.warn(
'Deprecated: `updateConfig()` 方法即将废弃,请使用`setCommandBars()`代替`updateConfig()`更新`commandBars`配置。',
),
[2, y(e.commandBars)])
: [2]
);
}
});
})
);
},
}),
new O.prototype.constructor(),
)),
V(i, c),
P.ready(),
P
);
} catch (e) {
console.error(e);
}
}
console.log('WebOfficeSDK JS-SDK V1.1.2');
var R = Object.freeze({ Listener: V, config: F });
window.WPS = R;
var z = F;
export default { config: F };
export { z as config };