var e = function (t, n) {
  return (e =
    Object.setPrototypeOf ||
    ({ __proto__: [] } instanceof Array &&
      function (e, t) {
        e.__proto__ = t;
      }) ||
    function (e, t) {
      for (var n in t) t.hasOwnProperty(n) && (e[n] = t[n]);
    })(t, n);
};
function t(t, n) {
  function i() {
    this.constructor = t;
  }
  e(t, n), (t.prototype = null === n ? Object.create(n) : ((i.prototype = n.prototype), new i()));
}
var n,
  i,
  r,
  s,
  o = function () {
    return (o =
      Object.assign ||
      function (e) {
        for (var t, n = 1, i = arguments.length; n < i; n++)
          for (var r in (t = arguments[n])) Object.prototype.hasOwnProperty.call(t, r) && (e[r] = t[r]);
        return e;
      }).apply(this, arguments);
  };
function a(e, t, n, i) {
  return new (n || (n = Promise))(function (r, s) {
    function o(e) {
      try {
        c(i.next(e));
      } catch (e) {
        s(e);
      }
    }
    function a(e) {
      try {
        c(i.throw(e));
      } catch (e) {
        s(e);
      }
    }
    function c(e) {
      var t;
      e.done
        ? r(e.value)
        : ((t = e.value),
          t instanceof n
            ? t
            : new n(function (e) {
                e(t);
              })).then(o, a);
    }
    c((i = i.apply(e, t || [])).next());
  });
}
function c(e, t) {
  var n,
    i,
    r,
    s,
    o = {
      label: 0,
      sent: function () {
        if (1 & r[0]) throw r[1];
        return r[1];
      },
      trys: [],
      ops: []
    };
  return (
    (s = { next: a(0), throw: a(1), return: a(2) }),
    'function' == typeof Symbol &&
      (s[Symbol.iterator] = function () {
        return this;
      }),
    s
  );
  function a(s) {
    return function (a) {
      return (function (s) {
        if (n) throw new TypeError('Generator is already executing.');
        for (; o; )
          try {
            if (
              ((n = 1), i && (r = 2 & s[0] ? i.return : s[0] ? i.throw || ((r = i.return) && r.call(i), 0) : i.next) && !(r = r.call(i, s[1])).done)
            )
              return r;
            switch (((i = 0), r && (s = [2 & s[0], r.value]), s[0])) {
              case 0:
              case 1:
                r = s;
                break;
              case 4:
                return o.label++, { value: s[1], done: !1 };
              case 5:
                o.label++, (i = s[1]), (s = [0]);
                continue;
              case 7:
                (s = o.ops.pop()), o.trys.pop();
                continue;
              default:
                if (!(r = (r = o.trys).length > 0 && r[r.length - 1]) && (6 === s[0] || 2 === s[0])) {
                  o = 0;
                  continue;
                }
                if (3 === s[0] && (!r || (s[1] > r[0] && s[1] < r[3]))) {
                  o.label = s[1];
                  break;
                }
                if (6 === s[0] && o.label < r[1]) {
                  (o.label = r[1]), (r = s);
                  break;
                }
                if (r && o.label < r[2]) {
                  (o.label = r[2]), o.ops.push(s);
                  break;
                }
                r[2] && o.ops.pop(), o.trys.pop();
                continue;
            }
            s = t.call(e, o);
          } catch (e) {
            (s = [6, e]), (i = 0);
          } finally {
            n = r = 0;
          }
        if (5 & s[0]) throw s[1];
        return { value: s[0] ? s[1] : void 0, done: !0 };
      })([s, a]);
    };
  }
}
!(function (e) {
  e.refreshToken = 'api.getToken';
})(n || (n = {})),
  (function (e) {
    (e.unknown = 'unknown'),
      (e.spreadsheet = 's'),
      (e.writer = 'w'),
      (e.presentation = 'p'),
      (e.pdf = 'f'),
      (e.otl = 'o'),
      (e.dbt = 'd'),
      (e.ksheet = 'k');
  })(i || (i = {})),
  (function (e) {
    (e.nomal = 'nomal'), (e.simple = 'simple'), (e.embed = 'embed');
  })(r || (r = {})),
  (function (e) {
    (e[(e.requestFullscreen = 1)] = 'requestFullscreen'), (e[(e.exitFullscreen = 0)] = 'exitFullscreen');
  })(s || (s = {}));
var l = window.navigator.userAgent.toLowerCase(),
  u = /iPhone|iPod|iPad/i.test(l);
function d(e) {
  if (!e) return !1;
  for (var t = e; null !== Object.getPrototypeOf(t); ) t = Object.getPrototypeOf(t);
  return Object.getPrototypeOf(e) === t;
}
var h = (function () {
    function e(e, t, n, i, r, s, o) {
      var a = this;
      void 0 === r && (r = !0),
        void 0 === s && (s = !1),
        void 0 === o && (o = {}),
        (this.instance = e),
        (this.instanceId = t),
        (this.url = n),
        (this.mount = i),
        (this.isListenResize = r),
        (this.addedStyles = s),
        (this.customAttrs = o),
        (this.handleResize = function () {
          var e = a.mount,
            t = a.mountResizeObserver,
            n = e.clientHeight,
            i = e.clientWidth;
          0 !== n || 0 !== i || t
            ? (0 === n && 0 === i) || !t || (t.disconnect(), (t = null))
            : window.ResizeObserver &&
              (t = new ResizeObserver(function (e) {
                a.handleResize();
              })).observe(e),
            (a.iframe.style.cssText += 'height: ' + e.clientHeight + 'px; width: ' + e.clientWidth + 'px');
        }),
        (this.iframe = this.initIframe());
    }
    return (
      (e.prototype.initIframe = function () {
        var e = this,
          t = this.mount,
          n = document.createElement('iframe');
        n.classList.add('web-office-iframe');
        var i = this.mergeAttrs({
          id: 'office-iframe-' + this.instanceId,
          src: this.url,
          scrolling: 'no',
          frameborder: '0',
          allowfullscreen: 'allowfullscreen',
          webkitallowfullscreen: 'true',
          mozallowfullscreen: 'true',
          allow: 'clipboard-read; clipboard-write'
        });
        for (var r in (t
          ? ((i.style = 'width: ' + t.clientWidth + 'px; height: ' + t.clientHeight + 'px;'),
            this.isListenResize && window.addEventListener('resize', this.handleResize))
          : ((t = document.createElement('div')).classList.add('web-office-default-container'),
            this.addedStyles ||
              this.addStylesheetRules(
                '.web-office-default-container {position: absolute; padding: 0;  margin: 0; width: 100vw; height: 100vh; left: 0; top: 0;}'
              ),
            document.body.appendChild(t),
            (i.style = 'width: 100vw; height: 100vh;')),
        u &&
          window.visualViewport &&
          this.isListenResize &&
          window.visualViewport.addEventListener('resize', function () {
            var t = window.visualViewport,
              n = t.width,
              i = t.height,
              r = document.body.clientHeight - e.iframe.clientHeight;
            e.instance.sendMsgToWps({ eventName: 'visualViewportResize', data: { width: n, height: i - r } });
          }),
        i))
          n.setAttribute(r, i[r]);
        return (
          t.appendChild(n),
          (n.destroy = function () {
            window.removeEventListener('resize', e.handleResize),
              n.parentNode.removeChild(n),
              (n = null),
              e.mountResizeObserver && (e.mountResizeObserver.disconnect(), (e.mountResizeObserver = null));
          }),
          n
        );
      }),
      (e.prototype.destroy = function () {
        this.iframe.parentNode.removeChild(this.iframe), window.removeEventListener('resize', this.handleResize);
      }),
      (e.prototype.addStylesheetRules = function (e) {
        var t = document.createElement('style');
        document.head.appendChild(t);
        var n = t.sheet;
        n.insertRule(e, n.cssRules.length);
      }),
      (e.prototype.mergeAttrs = function (e) {
        var t = this.customAttrs;
        if (t && Object.keys(t).length && t.allow) {
          var n = t.allow instanceof Array ? t.allow : t.allow.split(';');
          n.unshift('clipboard-write'), n.unshift('clipboard-read'), (t.allow = n.join(';')), Object.assign(e, t);
        }
        return e;
      }),
      e
    );
  })(),
  f = (function () {
    function e() {
      this.HANDLE_LIST = [];
    }
    return (
      (e.prototype.add = function (e) {
        this.HANDLE_LIST.push(e), window.addEventListener('message', e, !1);
      }),
      (e.prototype.remove = function (e) {
        var t = this.HANDLE_LIST.indexOf(e);
        t >= 0 && this.HANDLE_LIST.splice(t, 1), window.removeEventListener('message', e, !1);
      }),
      (e.prototype.empty = function () {
        for (; this.HANDLE_LIST.length; ) {
          var e = this.HANDLE_LIST.shift();
          window.removeEventListener('message', e, !1);
        }
      }),
      (e.prototype.parse = function (e) {
        try {
          return 'object' == typeof e ? e : e ? JSON.parse(e) : e;
        } catch (t) {
          return e;
        }
      }),
      e
    );
  })(),
  p = (function () {
    function e(e, t) {
      var n = this;
      (this.collectObjIdHandlers = new Set()),
        (this.polyfillApi = [
          'ExportAsFixedFormat',
          'GetOperatorsInfo',
          'ImportDataIntoFields',
          'ReplaceText',
          'ReplaceBookmark',
          'GetBookmarkText',
          'GetComments'
        ]),
        (this.getId = function () {
          return '';
        }),
        (this.setterCallbacks = { idMap: {} }),
        (this.sendMsgToWps = function () {}),
        (this.objId = 0),
        (this.origin = ''),
        (this.apiChannel = function (e, t, i, r) {
          return a(n, void 0, void 0, function () {
            var n,
              s,
              o,
              l,
              u,
              d,
              h,
              f,
              p,
              m = this;
            return c(this, function (v) {
              switch (v.label) {
                case 0:
                  return (
                    (n = this.getId()),
                    (l = new Promise(function (e, t) {
                      (s = e), (o = t);
                    })),
                    (u = {}),
                    t.args ? [4, this.reduceArgs(t.args)] : [3, 2]
                  );
                case 1:
                  (d = v.sent()), (h = d[0]), (f = d[1]), (t.args = h), (u = f), (v.label = 2);
                case 2:
                  return e !== this.prefix + 'setter' ? [3, 4] : [4, this.handleApiSetter(t)];
                case 3:
                  v.sent(), (v.label = 4);
                case 4:
                  return (
                    (p = function () {
                      var t = function (l) {
                        return a(m, void 0, void 0, function () {
                          var a, d, h;
                          return c(this, function (c) {
                            switch (c.label) {
                              case 0:
                                return this.instance.originWhiteList.includes(l.origin) || this.origin === l.origin
                                  ? (a = this.message.parse(l.data)).eventName === this.prefix + 'callback' && a.callbackId && u[a.callbackId]
                                    ? [4, u[a.callbackId].apply(u, a.data.args)]
                                    : [3, 2]
                                  : [2];
                              case 1:
                                (d = c.sent()),
                                  this.sendMsgToWps({ result: d, eventName: this.prefix + 'callback.reply', callbackId: a.callbackId }),
                                  (c.label = 2);
                              case 2:
                                return (
                                  a.eventName === e + '.reply' &&
                                    a.msgId === n &&
                                    (a.error ? (((h = new Error('')).stack = a.error + '\n' + i), r && r(), o(h)) : s(a.result),
                                    this.message.remove(t)),
                                  [2]
                                );
                            }
                          });
                        });
                      };
                      return m.message.add(t), l;
                    }),
                    this.handleSendApiChannel([{ eventName: e, data: t, msgId: n }, p]),
                    [2, l]
                  );
              }
            });
          });
        }),
        (this.handleApiSetter = function (e) {
          return a(n, void 0, void 0, function () {
            var t,
              n,
              i,
              r,
              s,
              o,
              a,
              l,
              u,
              d,
              h = this;
            return c(this, function (c) {
              switch (c.label) {
                case 0:
                  return (
                    (t = function () {
                      return Object.keys(h.setterCallbacks.idMap).find(function (e) {
                        return h.setterCallbacks.idMap[e] === i + ':' + n;
                      });
                    }),
                    (n = e.prop),
                    (i = e.parentObjId),
                    (r = e.value),
                    [4, this.reduceArgs([r])]
                  );
                case 1:
                  return (
                    (s = c.sent()),
                    (o = s[0]),
                    (a = s[1]),
                    (e.value = o[0]),
                    (l = Object.keys(a)[0]),
                    (u = this.setterCallbacks[i]),
                    null === r &&
                      u &&
                      u[n] &&
                      ((d = t()) && delete this.setterCallbacks.idMap[d],
                      delete u[n],
                      Object.keys(u).length || delete this.setterCallbacks[i],
                      Object.keys(this.setterCallbacks.idMap).length || this.message.remove(this.setterCallbackSubscribe.bind(this))),
                    l &&
                      (Object.keys(this.setterCallbacks.idMap).length || this.message.add(this.setterCallbackSubscribe.bind(this)),
                      this.setterCallbacks[i] || (this.setterCallbacks[i] = {}),
                      (this.setterCallbacks[i][n] = { callbackId: l, callback: a[l] }),
                      (d = t()) && delete this.setterCallbacks.idMap[d],
                      (this.setterCallbacks.idMap[l] = i + ':' + n)),
                    [2]
                  );
              }
            });
          });
        }),
        (this.prefix = t),
        (this.origin = e.origin),
        (this.sendMsgToWps = e.sendMsgToWps.bind(e)),
        (this.getId = e.getId.bind(e)),
        (this.message = e.message),
        (this.sdkInstanceId = e.instanceId),
        (this.instance = e);
    }
    return (
      (e.prototype.destroyApplication = function () {
        (this.collectObjIdHandlers = new Set()), (this.objId = 0);
      }),
      (e.prototype.subEventHandle = function (e, t) {
        var n = this,
          i = {};
        this.message.add(function (e) {
          return a(n, void 0, void 0, function () {
            var t, n, r, s, o, a;
            return c(this, function (c) {
              switch (c.label) {
                case 0:
                  return this.instance.originWhiteList.includes(e.origin) || this.origin === e.origin
                    ? ((t = this.message.parse(e.data)),
                      (n = t.sdkInstanceId),
                      t.eventName === this.prefix + 'event' && Number(n) === this.sdkInstanceId && t.data
                        ? ((r = t.data), (s = r.eventName), (o = r.data), (a = i[s]) ? [4, a(o)] : [3, 2])
                        : [3, 2])
                    : [2];
                case 1:
                  c.sent(), (c.label = 2);
                case 2:
                  return [2];
              }
            });
          });
        });
        var r = function (r) {
          var s = t[r];
          Object.defineProperty(e, s, {
            set: function (e) {
              (i[s] = e),
                n.sendMsgToWps({
                  eventName: n.prefix + 'event.register',
                  data: { eventName: s, register: !!e, objId: (n.objId += 1) },
                  sdkInstanceId: n.sdkInstanceId
                });
            }
          });
        };
        for (var s in t) r(s);
      }),
      (e.prototype.mixinProto = function (e, t) {
        Object.assign(e, t);
      }),
      (e.prototype.makeCollectObjIdHandle = function (e) {
        var t = this;
        return function () {
          var n = [],
            i = function (e) {
              n.push(e);
            };
          return (
            t.collectObjIdHandlers.add(i),
            {
              End: function () {
                e(n), t.collectObjIdHandlers.delete(i);
              }
            }
          );
        };
      }),
      (e.prototype.assign = function (e, t, n) {
        for (
          var i = this,
            r = t.slice(0),
            s = function () {
              var t = r.shift();
              !t.alias && ~a.polyfillApi.indexOf(t.prop) && r.push(o(o({}, t), { alias: t.prop + 'Async' })),
                Object.defineProperty(e, t.alias || t.prop, {
                  get: function () {
                    var r = 1 === t.cache,
                      s = r && e['__' + t.prop + 'CacheValue'];
                    if (!s) {
                      var o = i.getError(),
                        a = i.createObjId(r),
                        c = function () {
                          for (var r, s = [], a = 0; a < arguments.length; a++) s[a] = arguments[a];
                          return (
                            void 0 !== t.caller ? ((r = { objId: i.createObjId() }), i.assign(r, n[t.caller], n)) : (r = {}),
                            i.wrapper(c, r, i.prefix + 'caller', { obj: c, args: s, parentObjId: e.objId, objId: r.objId, prop: t.prop }, o),
                            r
                          );
                        };
                      return (
                        (c.objId = -1),
                        void 0 !== t.getter && ((c.objId = a), i.assign(c, n[t.getter], n)),
                        i.wrapper(e, c, i.prefix + 'getter', { parentObjId: e.objId, objId: c.objId, prop: t.prop }, o, function () {
                          delete e['__' + t.prop + 'CacheValue'];
                        }),
                        r && (e['__' + t.prop + 'CacheValue'] = c),
                        c
                      );
                    }
                    return s;
                  },
                  set: function (n) {
                    var r = i.getError();
                    return i.wrapper(e, {}, i.prefix + 'setter', { value: n, parentObjId: e.objId, objId: -1, prop: t.prop }, r);
                  }
                });
            },
            a = this;
          r.length;

        )
          s();
      }),
      (e.prototype.wrapper = function (e, t, n, i, r, s) {
        var o,
          a = this,
          c = (e.done ? e.done() : Promise.resolve()).then(function () {
            return o || (o = a.apiChannel(n, i, r, s)), o;
          });
        (t.done = function () {
          return c;
        }),
          (t.then = function (e, n) {
            return i.objId >= 0
              ? ((t.then = null),
                (t.catch = null),
                c
                  .then(function () {
                    e(t);
                  })
                  .catch(function (e) {
                    return n(e);
                  }))
              : c.then(e, n);
          }),
          (t.catch = function (e) {
            return c.catch(e);
          }),
          (t.Destroy = function () {
            return this.apiChannel(this.prefix + 'free', { objId: t.objId }, '');
          });
      }),
      (e.prototype.handleSendApiChannel = function (e) {
        var t = e[0],
          n = e[1];
        'function' == typeof (t = o({}, t)).data && (t.data = t.data()), n(), this.sendMsgToWps(t);
      }),
      (e.prototype.setterCallbackSubscribe = function (e) {
        return a(this, void 0, void 0, function () {
          var t, n, i, r, s, o, a, l, u, d;
          return c(this, function (c) {
            switch (c.label) {
              case 0:
                return this.instance.originWhiteList.includes(e.origin) || this.origin === e.origin
                  ? ((t = this.message.parse(e.data)),
                    (n = t.eventName),
                    (i = t.callbackId),
                    (r = t.data),
                    i && (s = this.setterCallbacks.idMap[i])
                      ? ((o = s.split(':')),
                        (a = o[0]),
                        (l = o[1]),
                        n === this.prefix + 'callback' && this.setterCallbacks[a] && this.setterCallbacks[a][l]
                          ? [4, (d = this.setterCallbacks[a][l]).callback.apply(d, r.args)]
                          : [3, 2])
                      : [3, 2])
                  : [2];
              case 1:
                (u = c.sent()), this.sendMsgToWps({ result: u, callbackId: i, eventName: this.prefix + 'callback.reply' }), (c.label = 2);
              case 2:
                return [2];
            }
          });
        });
      }),
      (e.prototype.reduceArgs = function (e) {
        return a(this, void 0, void 0, function () {
          var t, n, i, r, s, o, a, l, u, h, f;
          return c(this, function (c) {
            switch (c.label) {
              case 0:
                (t = {}), (n = []), (i = e.slice(0)), (c.label = 1);
              case 1:
                return i.length ? ((r = void 0), [4, i.shift()]) : [3, 13];
              case 2:
                return (s = c.sent()) && s.done ? [4, s.done()] : [3, 4];
              case 3:
                c.sent(), (c.label = 4);
              case 4:
                if (!d(r)) return [3, 11];
                for (a in ((r = {}), (o = []), s)) o.push(a);
                (l = 0), (c.label = 5);
              case 5:
                return l < o.length ? ((u = o[l]), (h = s[u]), /^[A-Z]/.test(u) ? (h && h.done ? [4, h.done()] : [3, 7]) : [3, 8]) : [3, 10];
              case 6:
                c.sent(), (c.label = 7);
              case 7:
                h && h.objId ? (h = { objId: h.objId }) : 'function' == typeof h && ((f = this.getId()), (t[f] = h), (h = { callbackId: f })),
                  (c.label = 8);
              case 8:
                (r[u] = h), (c.label = 9);
              case 9:
                return l++, [3, 5];
              case 10:
                return [3, 12];
              case 11:
                s && s.objId
                  ? (r = { objId: s.objId })
                  : 'function' == typeof s && void 0 === s.objId
                    ? ((f = this.getId()), (t[f] = s), (r = { callbackId: f }))
                    : (r = s),
                  (c.label = 12);
              case 12:
                return n.push(r), [3, 1];
              case 13:
                return [2, [n, t]];
            }
          });
        });
      }),
      (e.prototype.createObjId = function (e) {
        return (this.objId += 1), !e && this.collectObjId(), this.objId;
      }),
      (e.prototype.collectObjId = function () {
        var e = this;
        this.collectObjIdHandlers.forEach(function (t) {
          return t(e.objId);
        });
      }),
      (e.prototype.getError = function () {
        var e = new Error('');
        return (e.stack || e.message || '').split('\n').slice(2).join('\n');
      }),
      e
    );
  })(),
  m = (function (e) {
    function n(t, n, r) {
      var s = e.call(this, t, r) || this,
        o = {},
        a = t.officeType,
        c = n.Events,
        l = n.Enum,
        u = n.Props,
        d = u[0],
        h = u[1],
        f = { objId: s.objId };
      switch ((s.assign(f, d, h), (f.Events = c), (f.Enum = l), (f.Sub = {}), (o.Enum = f.Enum), (o.Events = f.Events), (o.Props = u), a)) {
        case i.writer:
          o.WordApplication = t.WpsApplication = function () {
            return f;
          };
          break;
        case i.spreadsheet:
          o.ExcelApplication = t.EtApplication = function () {
            return f;
          };
          break;
        case i.presentation:
          o.PPTApplication = t.WppApplication = function () {
            return f;
          };
          break;
        case i.pdf:
          o.PDFApplication = function () {
            return f;
          };
      }
      return (
        (o.Application = f),
        (o.Free = function (e) {
          return s.apiChannel(s.prefix + 'free', { objId: e }, '');
        }),
        (o.Stack = f.Stack =
          s.makeCollectObjIdHandle(function (e) {
            s.apiChannel(s.prefix + 'free', { objId: e }, '');
          })),
        (o.destroyApplication = function () {
          s.destroyApplication();
        }),
        s.subEventHandle(f.Sub, c),
        s.mixinProto(t, o),
        s
      );
    }
    return t(n, e), n;
  })(p),
  v = (function (e) {
    function n(t, n, i) {
      var r = e.call(this, t, i) || this,
        s = {},
        o = n.Events,
        a = n.Enum,
        c = n.Props,
        l = c[0],
        u = c[1],
        d = { objId: r.objId };
      return (
        r.assign(d, l, u),
        (d.Events = o),
        (d.Enum = a),
        (d.Sub = {}),
        (s.CommonEnum = d.Enum),
        (s.CommonEvents = d.Events),
        (s.CommonProps = c),
        (s.CommonApi = d),
        (s.CommonFree = function (e) {
          return r.apiChannel(r.prefix + 'free', { objId: e }, '');
        }),
        (s.CommonStack = d.Stack =
          r.makeCollectObjIdHandle(function (e) {
            r.apiChannel(r.prefix + 'free', { objId: e }, '');
          })),
        (s.destroyCommonApp = function () {
          r.destroyApplication();
        }),
        r.subEventHandle(d.Sub, o),
        r.mixinProto(t, s),
        r
      );
    }
    return t(n, e), n;
  })(p);
var b = (function () {
    function e(t) {
      var n,
        i = this;
      (this.id = 0),
        (this.origin = ''),
        (this.originWhiteList = []),
        (this.realOrigin = ''),
        (this.iframeWH = null),
        (this.cbConfigsSub = {}),
        (this.readyEventNames = [
          {
            event: 'ready',
            callback: function () {
              i.handleBaseReady();
            },
            after: !0
          },
          { event: 'open.result' },
          {
            event: 'api.ready',
            callback: function () {
              for (var e = [], t = 0; t < arguments.length; t++) e[t] = arguments[t];
              var n = e[0];
              return new m(i, n, 'api.'), i.Application;
            }
          },
          {
            event: 'commonApi.ready',
            callback: function () {
              for (var e = [], t = 0; t < arguments.length; t++) e[t] = arguments[t];
              var n = e[0];
              return new v(i, n, 'commonApi.'), i.CommonApi;
            }
          }
        ]),
        (this.cbConfigs = ['refreshToken']),
        (this.onEventNames = { 'open.result': 'fileOpen', 'tab.switch': 'tabSwitch', 'file.saved': 'fileStatus', error: 'error', stage: 'stage' }),
        (this.polyfillConfigName = [
          ['wpsOptions', 'wordOptions'],
          ['etOptions', 'excelOptions'],
          ['wppOptions', 'pptOptions']
        ]),
        (this.flag = { advancedApiReadySended: !1, advancedApiReadySendedJust: !1, commonApiReadySended: !1, commonApiReadySendedJust: !1 }),
        (this.baseReadyPromise = Promise.resolve()),
        (this.fileOpenPromise = Promise.resolve()),
        (this.advancedReadyPromise = Promise.resolve()),
        (this.commonApiPromise = Promise.resolve()),
        (this.iframeInstance = null),
        (this.officeType = ''),
        (this.url = ''),
        (this.version = '2.0.7'),
        (this.iframeReady = !1),
        (this.forceIframeResize = function () {
          i.iframeInstance && i.iframeInstance.handleResize();
        }),
        (this.isOtherEvent = function (e) {
          return void 0 !== e && e !== i.instanceId;
        }),
        (this.handleBaseReady = function () {
          i.sendMsgToWps({ eventName: 'setConfig', data: o(o({}, i.sdkConfig), { version: i.version }) }),
            i.tokenData && i.setToken(o(o({}, i.tokenData), { hasRefreshTokenConfig: !!i.sdkConfig.refreshToken })),
            i.flag.advancedApiReadySended && i.sendMsgToWps({ eventName: 'api.ready' }),
            i.flag.commonApiReadySended && i.sendMsgToWps({ eventName: 'commonApi.ready' }),
            (i.iframeReady = !0);
        }),
        (this.handleFullscreenChange = function () {
          var e = { status: s.requestFullscreen };
          document.fullscreenElement ? (e.status = s.requestFullscreen) : (e.status = s.exitFullscreen),
            i.sendMsgToWps({ data: e, eventName: 'fullscreenchange' });
        }),
        (this.instanceId = e.instanceId),
        (e.instanceId += 1),
        (this.message = new f()),
        (this.mittInstance =
          ((n = n || Object.create(null)),
          {
            on: function (e, t) {
              (n[e] || (n[e] = [])).push(t);
            },
            off: function (e, t) {
              n[e] && n[e].splice(n[e].indexOf(t) >>> 0, 1);
            },
            emit: function (e, t) {
              (n[e] || []).slice().map(function (e) {
                e(t);
              }),
                (n['*'] || []).slice().map(function (n) {
                  n(e, t);
                });
            }
          })),
        this.handleConfig(t);
    }
    return (
      (e.config = function (t) {
        return void 0 === t && (t = {}), e.singleInstance || (e.singleInstance = new e(t)), e.singleInstance;
      }),
      (e.prototype.setToken = function (e) {
        return a(this, void 0, void 0, function () {
          return c(this, function (t) {
            switch (t.label) {
              case 0:
                return [4, this.basicReady()];
              case 1:
                return t.sent(), (this.tokenData = e), this.sendMsgToWps({ eventName: 'setToken', data: e }), [2];
            }
          });
        });
      }),
      (e.prototype.advancedApiReady = function () {
        return a(this, void 0, void 0, function () {
          return c(this, function (e) {
            switch (e.label) {
              case 0:
                return this.flag.advancedApiReadySendedJust ? [3, 2] : ((this.flag.advancedApiReadySendedJust = !0), [4, this.fileOpenPromise]);
              case 1:
                e.sent(),
                  this.flag.advancedApiReadySended || ((this.flag.advancedApiReadySended = !0), this.sendMsgToWps({ eventName: 'api.ready' })),
                  (e.label = 2);
              case 2:
                return [4, this.advancedReadyPromise];
              case 3:
                return [2, e.sent()];
            }
          });
        });
      }),
      (e.prototype.commonApiReady = function () {
        return a(this, void 0, void 0, function () {
          return c(this, function (e) {
            switch (e.label) {
              case 0:
                return this.flag.commonApiReadySendedJust ? [3, 2] : ((this.flag.commonApiReadySendedJust = !0), [4, this.basicReady()]);
              case 1:
                e.sent(),
                  this.flag.commonApiReadySended || ((this.flag.commonApiReadySended = !0), this.sendMsgToWps({ eventName: 'commonApi.ready' })),
                  (e.label = 2);
              case 2:
                return [4, this.commonApiPromise];
              case 3:
                return [2, e.sent()];
            }
          });
        });
      }),
      (e.prototype.destroy = function () {
        this.iframeInstance.destroy(),
          this.message.empty(),
          this.destroyApplication && this.destroyApplication(),
          this.destroyCommonApp && this.destroyCommonApp(),
          this.removeFullscreenEventListener();
      }),
      (e.prototype.on = function (e, t) {
        return a(this, void 0, void 0, function () {
          var n;
          return c(this, function (i) {
            switch (i.label) {
              case 0:
                return [4, this.basicReady()];
              case 1:
                return (
                  i.sent(),
                  (n = e),
                  'fullscreenChange' === e && (n = 'fullscreenchange'),
                  this.handleBasicEvent(n, 'on'),
                  this.mittInstance.on(e, t),
                  [2]
                );
            }
          });
        });
      }),
      (e.prototype.off = function (e, t) {
        return a(this, void 0, void 0, function () {
          return c(this, function (n) {
            switch (n.label) {
              case 0:
                return [4, this.basicReady()];
              case 1:
                return n.sent(), this.handleBasicEvent(e, 'off'), this.mittInstance.off(e, t), [2];
            }
          });
        });
      }),
      (e.prototype.handleConfig = function (e) {
        var t,
          n = this;
        void 0 === e && (e = {});
        try {
          var i = this.userConfHandler(e),
            r = i.subscriptions,
            s = void 0 === r ? {} : r,
            o = i.mount,
            a = void 0 === o ? null : o,
            c = i.url,
            l = i.originWhiteList;
          (this.origin = (c.match(/https*:\/\/[^\/]+/g) || [])[0]), (this.originWhiteList = l || []);
          var u = this.readyEventNames.map(function (e) {
              return n.makeReady(e);
            }),
            d = u[0],
            f = u[1],
            p = u[2],
            m = u[3];
          (this.baseReadyPromise = d),
            (this.fileOpenPromise = f),
            (this.advancedReadyPromise = p),
            (this.commonApiPromise = m),
            (this.iframeWH = a ? { width: a.clientWidth + 'px', height: a.clientHeight + 'px' } : { width: '100vw', height: '100vh' }),
            delete i.mount,
            c && delete i.url,
            (this.url = c),
            delete i.subscriptions,
            (this.sdkConfig = i),
            (this.iframeInstance = new h(this, this.instanceId, c, a, null === (t = i.isListenResize) || void 0 === t || t, !1, {
              allow: i.attrAllow
            })),
            (this.iframe = this.iframeInstance.iframe),
            this.listener(s);
        } catch (e) {
          return console.error(e), null;
        }
      }),
      (e.prototype.listener = function (e) {
        var t = this;
        this.message.add(function (n) {
          return a(t, void 0, void 0, function () {
            var t, i, r, s, o, a, l, u, d;
            return c(this, function (c) {
              return (
                (t = this.message.parse(n.data)),
                (i = t.eventName),
                (r = void 0 === i ? '' : i),
                (s = t.data),
                (o = void 0 === s ? null : s),
                (a = t.url),
                (l = void 0 === a ? null : a),
                (u = t.sdkInstanceId),
                this.isOtherEvent(u)
                  ? [2]
                  : -1 !== ['wps.jssdk.api'].indexOf(r)
                    ? [2]
                    : ((d = this.handleListenEvent(r, o))
                        ? d()
                        : Object.keys(this.onEventNames).includes(r) &&
                          ('open.result' === r && (this.officeType = o.fileInfo.officeType), this.mittInstance.emit(this.onEventNames[r], o)),
                      'function' == typeof e[r] && e[r](this, l || o),
                      [2])
              );
            });
          });
        });
      }),
      (e.prototype.handleListenEvent = function (e, t) {
        var i,
          r = this;
        return (((i = {
          'api.scroll': function () {
            return window.scrollTo(t.x, t.y);
          },
          'event.callback': function () {
            return a(r, void 0, void 0, function () {
              var e, n, i, r, s, o, a;
              return c(this, function (c) {
                return (
                  (e = t.eventName),
                  (n = t.data),
                  (i = e),
                  'fullScreenChange' === e && (i = 'fullscreenChange'),
                  ((null === (o = this.sdkConfig.commonOptions) || void 0 === o ? void 0 : o.isBrowserViewFullscreen) ||
                    (null === (a = this.sdkConfig.commonOptions) || void 0 === a ? void 0 : a.isParentFullscreen)) &&
                    'fullscreenchange' === i &&
                    ((r = n.status),
                    (s = n.isDispatchEvent),
                    this.sdkConfig.commonOptions.isBrowserViewFullscreen
                      ? this.iframeWH &&
                        (function (e, t, n, i) {
                          0 === e
                            ? (t.style = 'position: static; width: ' + n.width + '; height: ' + n.height)
                            : 1 === e && (t.style = 'position: absolute; width: 100%; height: 100%'),
                            i &&
                              (function (e) {
                                ['fullscreen', 'fullscreenElement'].forEach(function (t) {
                                  Object.defineProperty(document, t, {
                                    get: function () {
                                      return !!e.status;
                                    },
                                    configurable: !0
                                  });
                                });
                                var t = new CustomEvent('fullscreenchange');
                                document.dispatchEvent(t);
                              })({ status: e });
                        })(r, this.iframe, this.iframeWH, s)
                      : this.sdkConfig.commonOptions.isParentFullscreen &&
                        (function (e, t) {
                          if (0 === e) {
                            var n = document,
                              i =
                                n.exitFullscreen || n.mozCancelFullScreen || n.msExitFullscreen || n.webkitCancelFullScreen || n.webkitExitFullscreen;
                            i.call(document);
                          } else if (1 === e) {
                            var r = t.requestFullscreen || t.mozRequestFullScreen || t.msRequestFullscreen || t.webkitRequestFullscreen;
                            r.call(t);
                          }
                        })(r, this.iframe)),
                  this.mittInstance.emit(i, n),
                  [2]
                );
              });
            });
          }
        })[n.refreshToken] = function () {
          return a(r, void 0, void 0, function () {
            var t, n;
            return c(this, function (i) {
              switch (i.label) {
                case 0:
                  (t = { token: !1 }), (i.label = 1);
                case 1:
                  return i.trys.push([1, 3, , 4]), [4, this.cbConfigsSub.refreshToken()];
                case 2:
                  return (t = i.sent()), [3, 4];
                case 3:
                  return (n = i.sent()), console.error('refreshToken: ' + (n || 'fail to get')), [3, 4];
                case 4:
                  return this.sendMsgToWps({ eventName: e + '.reply', data: t }), [2];
              }
            });
          });
        }),
        i)[e];
      }),
      (e.prototype.basicReady = function () {
        return this.baseReadyPromise;
      }),
      (e.prototype.userConfHandler = function (e, t) {
        var i = this;
        void 0 === t && (t = !0);
        var s = o({}, e),
          a = s.headers,
          c = void 0 === a ? {} : a,
          l = s.subscriptions,
          u = void 0 === l ? {} : l,
          d = s.commonOptions,
          h = s.url,
          f = void 0 === h ? '' : h,
          p = s.wpsUrl,
          m = void 0 === p ? '' : p,
          v = s.mode,
          b = void 0 === v ? r.nomal : v,
          g = s.debug,
          y = s.disablePlugins,
          w = s.hideGuide,
          k = s.readOnly;
        return (
          Object.assign(s, this.handleHeadersAndSubscriptionsConfig(c, u, t)),
          (s.url = this.handleUrlConfig(d, b, g, f, m, y, w, k)),
          d && (d.isParentFullscreen || d.isBrowserViewFullscreen) && document.addEventListener('fullscreenchange', this.handleFullscreenChange),
          this.polyfillConfigName.map(function (e) {
            var t = e[0],
              n = e[1];
            s[n] && (s[t] = s[n]);
          }),
          this.cbConfigs.map(function (e) {
            var t,
              r,
              o = s[e];
            o && ((t = o), (r = 'Function'), {}.toString.call(t) === '[object ' + r + ']') && ((i.cbConfigsSub[e] = o), (s[e] = { eventName: n[e] }));
          }),
          s.commandBars && this.handleCommandBarsConfig(s.commandBars, !1),
          o({}, s)
        );
      }),
      (e.prototype.handleBasicEvent = function (e, t) {
        if (!['error', 'fileOpen'].includes(e)) {
          var n = { eventName: 'basic.event', data: { eventName: e, action: t } };
          this.sendMsgToWps(n);
        }
      }),
      (e.prototype.removeFullscreenEventListener = function () {
        document.removeEventListener('fullscreenchange', this.handleFullscreenChange);
      }),
      (e.prototype.handleHeadersAndSubscriptionsConfig = function (e, t, n) {
        var i = e.backBtn,
          r = void 0 === i ? {} : i,
          s = e.shareBtn,
          o = void 0 === s ? {} : s,
          a = e.otherMenuBtn,
          c = void 0 === a ? {} : a,
          l = [
            ['wpsconfig_back_btn', r],
            ['wpsconfig_share_btn', o],
            ['wpsconfig_other_menu_btn', c]
          ],
          u = [];
        return (
          c.items &&
            Array.isArray(c.items) &&
            c.items.forEach(function (e, t) {
              void 0 === e && (e = {}), 'custom' === e.type && u.push(['wpsconfig_other_menu_btn_' + t, e]);
            }),
          l.concat(u).forEach(function (e) {
            var i, r;
            (i = e[1]),
              (r = e[0]),
              i.subscribe && 'function' == typeof i.subscribe && ((i.callback = r), (t[r] = i.subscribe), n && delete i.subscribe);
          }),
          {}
        );
      }),
      (e.prototype.handleUrlConfig = function (e, t, n, i, s, o, a, c) {
        var l = [];
        l.push('sdkId=' + this.instanceId),
          t === r.simple || (e && !1 === e.isShowTopArea) ? l.push('simple', 'hidecmb') : t === r.embed && l.push('simple=1', 'hidecmb=1', 'embed=1'),
          o && l.push('disablePlugins'),
          a && l.push('hideguide'),
          c && l.push('readonly'),
          n && l.push('debugger');
        var u = i || s;
        return u && l.length && (u = u + (u.indexOf('?') >= 0 ? '&' : '?') + l.join('&')), u;
      }),
      (e.prototype.handleCommandBarsConfig = function (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 i in t)
              if (t.hasOwnProperty(i)) {
                var r = { name: i, value: t[i] };
                n.push(r);
              }
            e.attributes = n;
          }
          return e;
        });
        return t && this.sendMsgToWps({ data: n, eventName: 'setCommandBars' }), n;
      }),
      (e.prototype.sendMsgToWps = function (e) {
        var t,
          n,
          i = o(o({}, e), { sdkInstanceId: this.instanceId });
        null === (n = null === (t = this.iframe) || void 0 === t ? void 0 : t.contentWindow) ||
          void 0 === n ||
          n.postMessage(JSON.stringify(i), this.realOrigin);
      }),
      (e.prototype.makeReady = function (e) {
        var t = this,
          n = e.event,
          i = e.callback,
          r = e.after;
        return new Promise(function (e) {
          var s = function (o) {
            if (((t.realOrigin = o.origin), t.originWhiteList.includes(o.origin) || t.origin === o.origin)) {
              var a = t.message.parse(o.data),
                c = a.eventName,
                l = a.data,
                u = a.sdkInstanceId;
              if (!t.isOtherEvent(u) && c === n) {
                var d = void 0;
                !r && i && (d = i(l)), e(d), r && i && i(l), 'ready' !== n && t.message.remove(s);
              }
            }
          };
          t.message.add(s);
        });
      }),
      (e.prototype.getId = function () {
        return (this.id += 1), this.instanceId + '-' + this.id;
      }),
      (e.instanceId = 1),
      e
    );
  })(),
  g = {
    executeCommandBar: 'ExecuteCommandBar',
    off: 'Off',
    save: 'Save',
    setCommandBars: 'SetCommandBars',
    setCooperUserColor: 'SetCooperUserColor',
    tabs: 'Tabs',
    Stack: 'Stack',
    WhenStacksEmpty: 'WhenStacksEmpty'
  };
function y(e, t) {
  var n = this;
  return (
    void 0 === t && (t = {}),
    new Proxy(
      e,
      o(
        o(
          {},
          {
            get: function (e, t) {
              if (Object.keys(g).includes(t)) {
                var i = g[t];
                return 'Tabs' === i
                  ? (function (e) {
                      var t = this;
                      return {
                        switchTab: function (n) {
                          return a(t, void 0, void 0, function () {
                            return c(this, function (t) {
                              switch (t.label) {
                                case 0:
                                  return [4, e.commonApiReady()];
                                case 1:
                                  return t.sent(), [4, e.CommonApi.Tabs.SwitchTab(n.tabKey)];
                                case 2:
                                  return [2, t.sent()];
                              }
                            });
                          });
                        },
                        getTabs: function () {
                          return a(t, void 0, void 0, function () {
                            return c(this, function (t) {
                              switch (t.label) {
                                case 0:
                                  return [4, e.commonApiReady()];
                                case 1:
                                  return t.sent(), [4, e.CommonApi.Tabs.GetTabs()];
                                case 2:
                                  return [2, t.sent()];
                              }
                            });
                          });
                        }
                      };
                    })(e)
                  : e.CommonApi
                    ? Reflect.get(e.CommonApi, i)
                    : function () {
                        return a(n, void 0, void 0, function () {
                          var t;
                          return c(this, function (n) {
                            switch (n.label) {
                              case 0:
                                return [4, e.commonApiReady()];
                              case 1:
                                return n.sent(), [4, e.commonApiPromise];
                              case 2:
                                return n.sent(), 'function' != typeof e.CommonApi[i] ? [3, 4] : [4, e.CommonApi[i]()];
                              case 3:
                                return (t = n.sent()), [3, 5];
                              case 4:
                                (t = e.CommonApi[i]), (n.label = 5);
                              case 5:
                                return [2, t];
                            }
                          });
                        });
                      };
              }
              return Reflect.get(e, t);
            },
            set: function (e, t, n) {
              return !!Reflect.has(e, t) && Reflect.set(e, t, n);
            }
          }
        ),
        t
      )
    )
  );
}
var w;
!(function (e) {
  (e.Spreadsheet = 's'), (e.Writer = 'w'), (e.Presentation = 'p'), (e.Pdf = 'f'), (e.Otl = 'o'), (e.Dbt = 'd'), (e.KSheet = 'k');
})(w || (w = {}));
var k = (function (e) {
  function n(t) {
    var n = e.call(this, t) || this;
    return (
      t.token && (d(t.token) ? n.setToken(o({}, t.token)) : n.setToken({ token: t.token })),
      (n.ApiEvent = {
        AddApiEventListener: function (e, t) {
          n.on(e, t);
        },
        RemoveApiEventListener: function (e, t) {
          n.off(e, t);
        }
      }),
      n
    );
  }
  return (
    t(n, e),
    (n.init = function (e) {
      var t = o({}, e);
      if (((t.endpoint = t.endpoint || 'https://o.wpsgo.com'), 'string' == typeof t.mount)) {
        var i = document.querySelector(t.mount);
        i ? (t.mount = i) : (console.warn('[WebOfficeSDK.init] mount挂载节点未找到'), delete t.mount);
      }
      if (t.url) throw Error('[WebOfficeSDK.init] 不支持传递url，请使用appId、fileId、officeType、token等参数初始化！');
      if (!t.appId || !t.fileId || !t.officeType) throw Error('[WebOfficeSDK.init] appId、fileId、officeType为必选项！');
      if ('string' != typeof t.endpoint) throw Error('[WebOfficeSDK.init] endpoint期望为字符串');
      if (t.endpoint && !t.endpoint.startsWith('http')) throw Error('[WebOfficeSDK.init] endpoint仅支持http、https的地址');
      var r = new n(
        (function (e) {
          var t = o({}, e);
          t.token = t.token || t.fileToken;
          var n = t.appId,
            i = t.fileId,
            r = t.officeType,
            s = t.token,
            a = t.endpoint,
            c = t.customArgs,
            l = void 0 === c ? '' : c;
          if (!Object.values(w).includes(r))
            throw Error('[WebOfficeSDK.init] officeType属性值错误，可选值参考WebOfficeSDK.OfficeType: ' + JSON.stringify(w));
          var u = s ? 1 : 0,
            h = { token: '' };
          if (('string' == typeof s ? (h.token = s) : d(s) && (h = o({ tokenData: h }, s)), u && !h.token))
            return console.error('[WebOfficeSDK.init] token设置无效'), t;
          if (((t.url = a + '/office/' + r + '/' + i + '?_w_appid=' + n + '&_w_tokentype=' + u), d(l))) {
            var f = Object.entries(l)
              .map(function (e) {
                var t = e[0],
                  n = e[1];
                return t + '=' + encodeURIComponent(n);
              })
              .join('&');
            t.url = t.url + '&' + f;
          }
          return o({}, t);
        })(t)
      );
      return (
        (function (e, t) {
          a(this, void 0, void 0, function () {
            var n, i, r, s;
            return c(this, function (o) {
              switch (o.label) {
                case 0:
                  return [4, e.commonApiReady()];
                case 1:
                  for (i in (o.sent(), (n = []), t)) n.push(i);
                  (r = 0), (o.label = 2);
                case 2:
                  if (!(r < n.length)) return [3, 11];
                  switch ((s = n[r])) {
                    case 'onHyperLinkOpen':
                      return [3, 3];
                    case 'onToast':
                      return [3, 5];
                    case 'getClipboardData':
                      return [3, 7];
                  }
                  return [3, 9];
                case 3:
                  return [4, e.CommonApi.Hooks.Add('hyperLink')];
                case 4:
                  return (o.sent().OnAction = t[s]), [3, 10];
                case 5:
                  return [4, e.CommonApi.Hooks.Add('toast')];
                case 6:
                  return (o.sent().OnAction = t[s]), [3, 10];
                case 7:
                  return [4, e.CommonApi.Hooks.Add('getClipboardData')];
                case 8:
                  return (o.sent().OnAction = t[s]), [3, 10];
                case 9:
                  return [3, 10];
                case 10:
                  return r++, [3, 2];
                case 11:
                  return [2];
              }
            });
          });
        })(r, e),
        y(r)
      );
    }),
    Object.defineProperty(n, 'version', {
      get: function () {
        return '2.0.7';
      },
      enumerable: !1,
      configurable: !0
    }),
    (n.prototype.ready = function () {
      return a(this, void 0, void 0, function () {
        return c(this, function (e) {
          switch (e.label) {
            case 0:
              return [4, this.advancedApiReady()];
            case 1:
              return [2, e.sent()];
          }
        });
      });
    }),
    (n.OfficeType = Object.freeze({ Spreadsheet: 's', Writer: 'w', Presentation: 'p', Pdf: 'f', Otl: 'o', KSheet: 'k', Dbt: 'd' })),
    n
  );
})(b);
window.WPS = k;
export default k;
