var ue = Object.defineProperty;
var de = (e, n, t) => n in e ? ue(e, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[n] = t;
var h = (e, n, t) => de(e, typeof n != "symbol" ? n + "" : n, t);
import { primeOfficeSdkRuntimePreload as z, preloadOfficeSdkRuntime as Ee } from "./preload.js";
const T = {
  WORD: 1,
  EXCEL: 2,
  PPT: 3
}, me = "FILE_READ_ERROR", we = "FILE_TYPE_ERROR", Oe = "FILE_UNKNOWN_ERROR", he = "FILE_PASSWORD_ERROR", De = "FILE_PASSWORD_OK", v = "DOCUMENT_EXPORT_READY", X = "UNDO_REDO_STATE_CHANGE", B = "DOCUMENT_EDITING_ENABLED", M = "DOCUMENT_EDITING_DISABLED", k = "SEE", _e = "DOCX_PAGE_POSITION_CHANGE", ye = "DOCX_FIRST_PART_LOADING", pe = "DOCX_PART_LOADING", Se = "DOCX_END_LOADING", ge = "DOCX_ZOOM_CHANGE", Ce = "DOCX_OPEN_FIND_UI", Ae = "XLSX_WORKSHEET_LOADED", Ie = "XLSX_WORKSHEET_CHANGE", Re = "XLSX_END_LOADING", Le = "XLSX_EDITING_STATUS_CHANGE", Te = "XLSX_ZOOM_CHANGE", Ne = "XLSX_OPEN_FIND_UI", Pe = "XLSX_WORKSHEET_LOADING_RATIO", be = "XLSX_FIRST_PART_LOADING", G = "SELECTION_CHANGE", Fe = "DOCUMENT_READY", Ue = "PPTX_SLIDES_CHANGED", ve = "PPTX_ZOOM_CHANGE", Xe = "PPTX_START_LOADING", Be = "PPTX_FIRST_PAGE_LOADED";
function Me(e, n) {
  const t = [], r = (i, f, u) => {
    i.addEventListener(f, u), t.push(() => i.removeEventListener(f, u));
  };
  let o = e.Document;
  r(o, v, () => {
    a("ExportReady", void 0, n);
  }), r(o, _e, () => {
    a("PagePositionChange", void 0, n);
  }), r(o, ye, () => {
    a("DocumentReady", void 0, n);
  }), r(o, Se, (i) => {
    a("LoadAllPageEnd", { count: i }, n);
  }), r(o, ge, () => {
    a("ZoomChange", void 0, n);
  }), r(o, pe, (i, f) => {
    const u = Math.trunc(f * 100);
    a("DocumentLoading", { pageIndex: i, formatRatio: u }, n);
  }), r(o, B, () => {
    a("EditorEnable", void 0, n);
  }), r(o, M, () => {
    a("EditorDisable", void 0, n);
  }), r(o, k, (i) => {
    a("SecurityError", { action: i }, n);
  });
  let l = e.Finder;
  r(l, Ce, () => {
    a("OpenFindDialog", void 0, n);
  });
  let c = e.Selection;
  r(c, G, (i) => {
    a("SelectionChange", i, n);
  });
  let s = e.UndoRedo;
  return r(s, X, () => {
    a("UndoRedoChange", void 0, n);
  }), () => t.forEach((i) => i());
}
function ke(e, n) {
  const t = [], r = (s, i, f) => {
    s.addEventListener(i, f), t.push(() => s.removeEventListener(i, f));
  };
  let o = e.Document;
  r(o, Fe, () => {
    a("DocumentReady", void 0, n);
  }), r(o, v, () => {
    a("ExportReady", void 0, n);
  }), r(o, ve, (s) => {
    a("ZoomChange", void 0, n);
  }), r(o, Ue, (s, i) => {
    a("CurrentPage", { currentPage: s }, n), a("PageCount", { totalPages: i }, n);
  }), r(o, Xe, () => {
  }), r(o, Be, () => {
    a("FirstPageLoaded", void 0, n);
  }), r(o, B, () => {
    a("EditorEnable", void 0, n);
  }), r(o, M, () => {
    a("EditorDisable", void 0, n);
  }), r(o, k, (s) => {
    a("SecurityError", { action: s }, n);
  });
  let l = e.UndoRedo;
  r(l, X, () => {
    a("UndoRedoChange", void 0, n);
  });
  let c = e.Selection;
  return r(c, G, (s) => {
    a("SelectionChange", s, n);
  }), () => t.forEach((s) => s());
}
function Ge(e, n) {
  const t = [], r = (i, f, u) => {
    i.addEventListener(f, u), t.push(() => i.removeEventListener(f, u));
  };
  let o = e.Document;
  r(o, v, () => {
    a("ExportReady", void 0, n);
  }), r(o, Ae, () => {
    a("WorksheetLoaded", void 0, n);
  }), r(o, Re, () => {
    a("EndLoading", void 0, n);
  }), r(o, Le, (i) => {
    a("EditingStatusChange", { status: i }, n);
  }), r(o, Te, () => {
    a("ZoomChange", void 0, n);
  }), r(o, Pe, (i) => {
    const f = Math.trunc(i * 100);
    a("DocumentLoading", { formatRatio: f }, n);
  }), r(o, be, () => {
    a("DocumentReady", void 0, n);
  }), r(o, Ie, (i) => {
    a("SheetChange", i, n);
  }), r(o, B, () => {
    a("EditorEnable", void 0, n);
  }), r(o, M, () => {
    a("EditorDisable", void 0, n);
  }), r(o, k, (i) => {
    a("SecurityError", { action: i }, n);
  });
  let l = e.Selection;
  r(l, G, (i) => {
    a("SelectionChange", i, n);
  });
  let c = e.UndoRedo;
  r(c, X, () => {
    a("UndoRedoChange", void 0, n);
  });
  let s = e.Finder;
  return r(s, Ne, () => {
    a("OpenFindDialog", void 0, n);
  }), () => t.forEach((i) => i());
}
function $e(e) {
  return e ?? window;
}
function a(e, n, t) {
  let r = new CustomEvent(e, {
    detail: {
      ...n
    }
  });
  $e(t).dispatchEvent(r);
}
function Ke(e) {
}
function We(e, n, t) {
  switch (e) {
    case we:
    case me:
    case Oe:
      a("FileError", { callback: n, type: e }, t);
      break;
    case he:
      a("FilePassWordError", { callback: n, type: e }, t);
      break;
    case De:
      a("FilePassWordOK", void 0, t);
      break;
  }
}
const y = {
  addInitEvent: Ke,
  addXLSEvent: Ge,
  addDocEvent: Me,
  addPPTEvent: ke,
  beforeMiddleware: We
};
function $(e) {
  return new Promise((n, t) => {
    const r = {
      request: e,
      onSuccess(o) {
        try {
          const l = JSON.parse(o);
          n(l);
        } catch (l) {
          t({ error_code: -100, error_message: l.message });
        }
      },
      onFailure(o, l) {
        t({ error_code: o, error_message: l });
      }
    };
    window.CallBridge && window.CallBridge.CefViewQuery ? window.CallBridge.CefViewQuery(r) : window.CefViewQuery(r);
  });
}
const N = {
  openTabType: {
    OfficeFile: 1,
    PrintedPdf: 2
  },
  ReadFileMode: {
    Shared: 0,
    Exclusive: 1
  },
  isClient() {
    return !!window.CallBridge;
  },
  async getResFileInfo(e) {
    return await $("getResFileInfo:" + e);
  },
  readFile(e) {
    return new Promise((n, t) => {
      window.CallBridge.addEventListener("onReadFileComplete", (o, l) => {
        if (Array.isArray(l)) {
          const s = l.flatMap((f) => Object.values(f));
          l = Uint8Array.from(s).buffer;
        }
        o = o.substring(o.lastIndexOf("/") + 1);
        const c = o.substring(o.lastIndexOf(".") + 1).toUpperCase();
        n(l);
      });
      const r = {
        request: "readFile:" + JSON.stringify(e),
        onSuccess(o) {
          try {
            const l = JSON.parse(o);
            l.resultCode !== 0 && t(l);
          } catch (l) {
            t(l);
          }
        },
        onFailure(o, l) {
          t({ resultCode: o, result: l });
        }
      };
      window.CallBridge && window.CallBridge.CefViewQuery ? window.CallBridge.CefViewQuery(r) : window.CefViewQuery(r);
    });
  },
  setTabInfo(e) {
    this.isClient() && window.CallBridge.invokeMethod("setTabInfo", e);
  },
  closeTab() {
    this.isClient() && window.CallBridge.invokeMethod("closeTab");
  },
  closeTabCancel() {
    this.isClient();
  },
  async openFileDir(e) {
    if (this.isClient())
      return await $("showFile:" + e);
  },
  addEventListener(e, n) {
    this.isClient() && window.CallBridge.addEventListener(e, n);
  }
};
function xe(e) {
  return /.pdf$/.test(e) ? N.ReadFileMode.Shared : N.ReadFileMode.Exclusive;
}
async function He(e) {
  return e.startsWith("http://") || e.startsWith("https://") ? qe(e) : await N.readFile({
    filePath: e,
    mode: xe(e)
  });
}
function qe(e) {
  const { promise: n, resolve: t, reject: r } = Ve();
  return fetch(e).then(function(o) {
    return o.status === 200 || o.status === 0 ? o.arrayBuffer() : Promise.reject(new Error(o.statusText));
  }).then((o) => {
    t(o);
  }).catch((o) => {
    r(o);
  }), n;
}
function Ve() {
  let e = null, n = null;
  return { promise: new Promise((r, o) => {
    e = r, n = o;
  }), resolve: e, reject: n };
}
function K(e) {
  const n = import.meta.url;
  return new URL(`./${e}`, n).href;
}
const je = {
  loadBrowser: () => import(
    /* @vite-ignore */
    K("index_browser.js")
  ),
  loadLocale: () => import(
    /* @vite-ignore */
    K("office.locale.js")
  )
};
let R = { ...je };
function ze(e = {}) {
  R = {
    ...R,
    ...e
  };
}
function Ye() {
  return R.loadBrowser();
}
function Ze() {
  return R.loadLocale();
}
async function Y(e = {}) {
  const n = Je(e), [t, r] = await Promise.all([
    Ze(),
    Ye()
  ]), o = t.default, l = r.default, c = n ? await on(e.docId) : null, s = en(e.userData ?? e.user ?? (c == null ? void 0 : c.currentUser)), i = e.fileData ?? (c ? nn(c) : await tn(e)), { app: f, docType: u } = await l.openFile(i, s, o, (w, O) => {
    y.beforeMiddleware(w, O, e.eventTarget);
  });
  return (e.title ?? i.fileName) && (document.title = e.title ?? i.fileName), {
    app: f,
    docType: u,
    docId: i.docId,
    fileData: i,
    userData: s,
    isLocal: !n
  };
}
function Qe() {
  let e = null, n = null;
  return { promise: new Promise((r, o) => {
    e = r, n = o;
  }), resolve: e, reject: n };
}
function Je(e = {}) {
  return !e.fileData && !e.file && !e.fileUrl && !e.filePath;
}
function en(e) {
  return {
    ...e,
    nickName: (e == null ? void 0 : e.nickName) ?? "Local User",
    avatar: (e == null ? void 0 : e.avatar) ?? "",
    opts: (e == null ? void 0 : e.opts) ?? { color: "#2F80ED" }
  };
}
function nn(e) {
  return {
    docId: e.docId,
    fileName: e.title,
    file: e.files.main,
    opts: {
      isLocal: !1,
      draftIndex: e.draftIndex,
      lastIndex: e.lastIndex
    }
  };
}
async function tn(e = {}) {
  var o, l;
  const n = e.fileName ?? ((o = e.fileData) == null ? void 0 : o.fileName);
  if (!n)
    throw new Error("bootup requires fileName when opening local or widget files");
  const t = e.file ?? ((l = e.fileData) == null ? void 0 : l.file) ?? e.fileUrl ?? e.filePath;
  if (!t)
    throw new Error("bootup requires file/fileUrl/filePath when opening local or widget files");
  const r = await rn(t);
  return {
    docId: e.docId ?? ln(`${n}:${String(e.fileUrl ?? e.filePath ?? "local")}`),
    fileName: n,
    file: r,
    opts: {
      isLocal: !0
    }
  };
}
async function rn(e) {
  if (e instanceof ArrayBuffer)
    return e;
  if (ArrayBuffer.isView(e))
    return e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength);
  if (typeof Blob < "u" && e instanceof Blob)
    return await e.arrayBuffer();
  if (typeof e == "string") {
    if (/^(blob:|data:|https?:\/\/)/i.test(e)) {
      const n = await fetch(e);
      if (!n.ok)
        throw new Error(`failed to read file payload: ${n.status} ${n.statusText}`);
      return await n.arrayBuffer();
    }
    return await He(e);
  }
  throw new Error("unsupported file payload for bootup");
}
async function on(e = window.docId) {
  const n = `${window.apibase}/api/fetchDraft/${e}`, { promise: t, resolve: r, reject: o } = Qe();
  return fetch(n, {
    method: "POST",
    mode: "cors",
    cache: "no-cache",
    credentials: "include",
    headers: {
      "Content-Type": "application/json"
    },
    body: {}
  }).then((l) => l.json()).then((l) => {
    r(l);
  }).catch((l) => {
    console.error("Error:", l), o(l);
  }), t;
}
function ln(e) {
  let n = 0;
  for (let t = 0; t < e.length; t += 1)
    n = (n << 5) - n + e.charCodeAt(t), n |= 0;
  return `widget-${Math.abs(n)}`;
}
const Z = "__documentModeController";
function W(e) {
  return !!e && typeof e.then == "function";
}
function cn(e) {
  if (!e || typeof e != "object")
    return !1;
  const n = e;
  return typeof n.setReadOnly == "function" && typeof n.isReadOnly == "function" && typeof n.onChange == "function";
}
class sn {
  constructor(n) {
    h(this, "app");
    h(this, "readOnly", !1);
    h(this, "operationId", 0);
    h(this, "listeners", /* @__PURE__ */ new Set());
    h(this, "setReadOnlyAlias", (n) => this.setReadOnly(n));
    h(this, "isReadOnlyAlias", () => this.isReadOnly());
    this.app = n, this.installAliases(n), this.readOnly = this.readFromCore(!1);
  }
  onChange(n) {
    return this.listeners.add(n), () => {
      this.listeners.delete(n);
    };
  }
  isReadOnly() {
    return this.readOnly = this.readFromCore(this.readOnly), this.readOnly;
  }
  async setReadOnly(n) {
    const t = ++this.operationId, r = this.readOnly, o = !!n, l = this.getDocumentCallFun();
    if (!l)
      return this.readOnly;
    const c = l(o ? "startReadOnly" : "endReadOnly");
    return W(c) && await c, t !== this.operationId ? this.readOnly : (this.readOnly = this.readFromCore(o), this.readOnly !== r && this.emitChange(), this.readOnly);
  }
  installAliases(n) {
    try {
      Object.defineProperty(n, Z, {
        value: this,
        enumerable: !1,
        configurable: !0
      }), n.setReadOnly = this.setReadOnlyAlias, n.isReadOnly = this.isReadOnlyAlias;
    } catch {
    }
  }
  getDocumentCallFun() {
    var t, r, o;
    const n = (r = (t = this.app) == null ? void 0 : t.Document) == null ? void 0 : r.callFun;
    return typeof n == "function" ? n.bind((o = this.app) == null ? void 0 : o.Document) : null;
  }
  readFromCore(n = this.readOnly) {
    const t = this.getDocumentCallFun();
    if (!t)
      return n;
    const r = t("isReadOnly");
    return typeof r == "boolean" ? r : (W(r), n);
  }
  emitChange() {
    this.listeners.forEach((n) => {
      try {
        n(this.readOnly);
      } catch {
      }
    });
  }
}
function an(e) {
  if (!e || typeof e != "object")
    return null;
  const n = e, t = n[Z];
  return cn(t) ? t : new sn(n);
}
const fn = Symbol(), p = /* @__PURE__ */ new Map(), D = /* @__PURE__ */ new Map(), P = /* @__PURE__ */ new WeakMap();
function un(e) {
  return e ?? window;
}
function b(e) {
  const n = P.get(e);
  n && (n(), P.delete(e));
}
function dn(e) {
  if (!e || e.__officeSdkDocumentEventsDisposePatched)
    return;
  const n = e.dispose, t = e.destroy;
  typeof n == "function" && (e.dispose = function(...r) {
    return b(e), n.apply(this, r);
  }), typeof t == "function" && t !== n && (e.destroy = function(...r) {
    return b(e), t.apply(this, r);
  }), Object.defineProperty(e, "__officeSdkDocumentEventsDisposePatched", {
    value: !0,
    enumerable: !1,
    configurable: !1,
    writable: !1
  });
}
function C(e) {
  var n, t, r;
  return !!((n = e == null ? void 0 : e.isDisposed) != null && n.call(e) || (r = (t = e == null ? void 0 : e.__internalApp) == null ? void 0 : t.isDisposed) != null && r.call(t));
}
function En(e) {
  if (document.visibilityState === "hidden" || C(e))
    return;
  const n = e.Document || e.Viewer;
  typeof (n == null ? void 0 : n.updateVisibleArea) == "function" && requestAnimationFrame(() => {
    if (!(document.visibilityState === "hidden" || C(e)))
      try {
        Promise.resolve(n.updateVisibleArea()).catch((t) => {
          C(e);
        });
      } catch (t) {
        C(e);
      }
  });
}
function mn(e, n, t, r) {
  b(e);
  const o = [], l = (s) => {
    typeof s == "function" && o.push(s);
  };
  switch (y.addInitEvent(e, t), n) {
    case T.WORD: {
      l(y.addDocEvent(e, r));
      break;
    }
    case T.EXCEL: {
      l(y.addXLSEvent(e, r));
      break;
    }
    case T.PPT: {
      l(y.addPPTEvent(e, r));
      break;
    }
  }
  const c = () => {
    En(e);
  };
  document.addEventListener("visibilitychange", c), P.set(e, () => {
    document.removeEventListener("visibilitychange", c), o.forEach((s) => {
      try {
        s();
      } catch (i) {
      }
    });
  }), dn(e);
}
function wn(e = {}) {
  return {
    docId: e.docId ?? window.docId,
    mainDom: e.mainDom ?? document.getElementById("main"),
    eventTarget: un(e.eventTarget),
    title: e.title
  };
}
function On(e) {
  e != null && e.docId && p.set(e.docId, e);
}
function hn(e, n) {
  !e || !n || (D.set(e, n), n.finally(() => {
    D.get(e) === n && D.delete(e);
  }).catch(() => {
  }));
}
function Dn(e) {
  if (!e || !p.has(e))
    return null;
  const n = p.get(e);
  return p.delete(e), n;
}
async function _n(e) {
  if (!e || !D.has(e))
    return null;
  const n = D.get(e);
  try {
    const t = await n;
    return t != null && t.docId && p.delete(t.docId), t;
  } catch {
    return null;
  }
}
function Q(e = {}) {
  return {
    docId: e.docId,
    eventTarget: e.eventTarget,
    title: e.title,
    user: e.user,
    userData: e.userData,
    fileData: e.fileData,
    file: e.file,
    fileUrl: e.fileUrl,
    filePath: e.filePath,
    fileName: e.fileName
  };
}
async function yn(e, n) {
  !e || !n || !Object.prototype.hasOwnProperty.call(n, "readOnly") || await e.setReadOnly(!!n.readOnly);
}
function pn(e) {
  return e == null ? void 0 : e[fn];
}
async function Sn(e = {}) {
  const n = D.get(e.docId);
  if (n)
    return n;
  const t = Y(Q(e)).then((r) => (On(r), r));
  return hn(e.docId, t), t;
}
async function F(e = {}) {
  var f;
  const { docId: n, mainDom: t, eventTarget: r } = wn(e);
  if (e.probeOnly) {
    const u = await Sn({
      ...e,
      eventTarget: r
    });
    return {
      docId: u.docId,
      docType: u.docType
    };
  }
  if (!t)
    throw new Error("OpenDocument requires a mount element");
  let o = Dn(n);
  o || (o = await _n(n)), o || (o = await Y(Q({
    ...e,
    docId: n,
    eventTarget: r
  })));
  const { app: l, docType: c } = o, s = an(l);
  l.mount(t), mn(l, c, t, r);
  const i = pn(e);
  return typeof (i == null ? void 0 : i.beforeRender) == "function" && await i.beforeRender(l, {
    docId: o.docId ?? n,
    docType: c
  }), await yn(s, e.widgetMode), o.isLocal || await ((f = l.startCoEditing) == null ? void 0 : f.call(l)), await l.render(), {
    docId: o.docId ?? n,
    docType: c,
    app: l
  };
}
const d = {
  WORD: 1,
  EXCEL: 2,
  PPT: 3,
  PDF: 4,
  OFD: 5,
  TXT: 6
};
function gn() {
  return {
    docx: () => import("./mountDocxApp.js"),
    xlsx: () => import("./mountXlsxApp.js"),
    pptx: () => import("./mountPptxApp.js")
  };
}
function Cn(e) {
  return {
    ...gn(),
    ...e
  };
}
function An(e) {
  switch (e) {
    case d.WORD:
      return "docx";
    case d.EXCEL:
      return "xlsx";
    case d.PPT:
      return "pptx";
    default:
      throw new Error(`Fuxin Office SDK does not support docType ${e}`);
  }
}
async function In(e, n, t, r, o) {
  const l = An(e), c = r[l];
  if (typeof c != "function")
    throw new Error(`Fuxin Office SDK app loader is not configured for ${l}`);
  const s = await c();
  if (typeof s.mount != "function")
    throw new Error(`Fuxin Office SDK app module for ${l} does not export mount(...)`);
  return s.mount(n, t, o);
}
const Rn = "Local User", Ln = "#2F80ED";
function J(e) {
  return {
    ...e,
    nickName: (e == null ? void 0 : e.nickName) ?? Rn,
    avatar: (e == null ? void 0 : e.avatar) ?? "",
    opts: (e == null ? void 0 : e.opts) ?? { color: Ln }
  };
}
const Tn = ["Word", "PPT", "Excel"];
let S = null, m = null, I = null, L = 0, _ = null, x = "";
function Nn(e) {
  const n = typeof e == "string" && e.trim() ? e.trim() : new URL(
    /* @vite-ignore */
    "./license/gsdk/",
    import.meta.url
  ).href, t = typeof document < "u" && document.baseURI ? document.baseURI : typeof window < "u" ? window.location.href : import.meta.url, r = new URL(n, t).href;
  return r.endsWith("/") ? r : `${r}/`;
}
function Pn() {
  if (typeof window > "u" || !window.location)
    throw new Error("Fuxin Office SDK license requires a browser hostname");
  const e = String(window.location.hostname ?? "").trim();
  if (!e)
    throw new Error("Fuxin Office SDK license requires a browser hostname");
  return [e];
}
function bn(e) {
  return new URL("../OfficeSDK.js", e).href;
}
function Fn(e) {
  const n = /* @__PURE__ */ new Set();
  for (const t of e)
    (t === "Word" || t === "PPT" || t === "Excel") && n.add(t);
  return Tn.filter((t) => n.has(t));
}
function Un(e) {
  switch (e) {
    case d.WORD:
      return "Word";
    case d.EXCEL:
      return "Excel";
    case d.PPT:
      return "PPT";
    default:
      return null;
  }
}
function ee() {
  var e;
  try {
    (e = m == null ? void 0 : m.destroy) == null || e.call(m);
  } catch {
  } finally {
    m = null, I = null;
  }
}
function ne() {
  return typeof globalThis > "u" ? null : globalThis.FoxitOfficeSDK ?? null;
}
function vn() {
  const e = ne();
  if (!(e != null && e.OfficeSDK))
    throw new Error("Fuxin Office SDK license bridge did not expose the expected OfficeSDK constructor");
  return e;
}
async function Xn(e) {
  const n = ne();
  if (n != null && n.OfficeSDK)
    return n;
  if (typeof document > "u" || typeof window > "u")
    throw new Error("Fuxin Office SDK license requires a browser environment");
  const t = new URL(e, window.location.href).href;
  return _ && x === t || (x = t, _ = new Promise((r, o) => {
    const l = () => {
      try {
        r(vn());
      } catch (i) {
        o(i);
      }
    }, c = document.querySelector(
      `script[data-office-sdk-license-src="${t}"]`
    );
    if (c) {
      if (c.dataset.officeSdkLicenseLoaded === "true") {
        l();
        return;
      }
      c.addEventListener("load", l, { once: !0 }), c.addEventListener(
        "error",
        () => o(new Error(`failed to load Fuxin Office SDK license bridge: ${t}`)),
        { once: !0 }
      );
      return;
    }
    const s = document.createElement("script");
    s.src = t, s.async = !0, s.dataset.officeSdkLicenseSrc = t, s.addEventListener(
      "load",
      () => {
        s.dataset.officeSdkLicenseLoaded = "true", l();
      },
      { once: !0 }
    ), s.addEventListener(
      "error",
      () => o(new Error(`failed to load Fuxin Office SDK license bridge: ${t}`)),
      { once: !0 }
    ), document.head.appendChild(s);
  }).catch((r) => {
    throw _ = null, r;
  })), _;
}
async function Bn(e) {
  const n = e._loadPromise;
  n && typeof n.then == "function" && await n;
}
function Mn() {
  if (!S)
    throw new Error("Fuxin Office SDK license is not configured; call configureLicense(...) before opening a document");
  return S;
}
function H(e) {
  if (e !== L)
    throw new Error("Fuxin Office SDK license configuration changed while loading");
}
function kn(e) {
  const n = String(e.licenseKey ?? "").trim(), t = String(e.licenseSN ?? "").trim();
  if (!n)
    throw new Error("Fuxin Office SDK license requires licenseKey");
  if (!t)
    throw new Error("Fuxin Office SDK license requires licenseSN");
  L += 1, ee(), S = {
    licenseKey: n,
    licenseSN: t,
    enginePath: Nn(e.enginePath),
    bridgePath: ""
  }, S.bridgePath = bn(S.enginePath);
}
async function Gn() {
  const e = Mn();
  if (!I) {
    const n = L;
    I = (async () => {
      var c;
      const t = await Xn(e.bridgePath);
      H(n);
      const r = t.OfficeSDK;
      if (typeof r != "function")
        throw new Error("Fuxin Office SDK license bridge did not export a valid OfficeSDK constructor");
      const o = new r({
        enginePath: e.enginePath,
        licenseKey: e.licenseKey,
        licenseSN: e.licenseSN,
        domains: Pn()
      });
      m = o, await Bn(o), H(n);
      const l = Fn(((c = o.getTargetApplications) == null ? void 0 : c.call(o)) ?? []);
      if (l.length === 0)
        throw new Error("Fuxin Office SDK license did not grant any target applications");
      return l;
    })().catch((t) => {
      throw n === L && ee(), t;
    });
  }
  return [...await I];
}
async function te(e) {
  const n = Un(e);
  if (!n)
    return;
  const t = await Gn();
  if (!(typeof (m == null ? void 0 : m.allowsTargetApplication) == "function" ? m.allowsTargetApplication(n) : t.includes(n)))
    throw new Error(`Fuxin Office SDK license does not allow ${n}`);
}
let U = null, E = null;
function re(e) {
  return e.replace(/\/$/, "");
}
function $n(e) {
  const n = new URL(e, window.location.href), t = new URL("./sharedWorkerStorage.worker.js", n);
  return t.search = n.search, t.href;
}
function oe() {
  if (!U)
    throw new Error(
      "Fuxin Office SDK runtime is not ready. Please verify the SDK assets are deployed correctly and retry opening the document."
    );
  return U;
}
function Kn(e) {
  const n = oe();
  return {
    ...e,
    user: J(e.user),
    lang: e.lang ?? n.lang,
    assetBaseUrl: e.assetBaseUrl ?? n.assetBaseUrl,
    workerUrl: e.workerUrl ?? n.workerUrl,
    localeAssetRoot: e.localeAssetRoot ?? n.localeAssetRoot
  };
}
function Wn(e) {
  U = {
    ...e,
    appLoaders: Cn(e.appLoaders)
  }, ze({
    loadBrowser: async () => ({ default: e.core }),
    loadLocale: async () => ({ default: e.locale })
  });
}
function xn(e) {
  return {
    core: e.core,
    locale: e.locale,
    mount(n) {
      return Wn(e), at(n);
    }
  };
}
function Hn(e) {
  if (e.target instanceof HTMLElement)
    return e.target;
  if (typeof e.target == "string") {
    const n = document.querySelector(e.target);
    if (!n)
      throw new Error(`mount target "${e.target}" not found`);
    return n;
  }
  if (e.domId) {
    const n = document.getElementById(e.domId);
    if (!n)
      throw new Error(`mount target #${e.domId} not found`);
    return n;
  }
  throw new Error("mount target is required");
}
function qn(e) {
  e.replaceChildren();
  const n = document.createElement("div");
  return n.className = "office-sdk-root", e.appendChild(n), n;
}
function Vn(e) {
  const n = import.meta.url;
  return new URL(e, n).href;
}
function jn() {
  return re(Vn("./"));
}
function zn(e) {
  const n = re(e.assetBaseUrl ?? jn());
  return {
    apibase: e.apibase ?? window.location.origin,
    uriprefix: e.uriprefix ?? "",
    lang: e.lang ?? window.navigator.language,
    assetBaseUrl: n,
    localeAssetRoot: e.localeAssetRoot ?? `${n}/locale-assets`,
    workerUrl: e.workerUrl ?? `${n}/worker/index.js`
  };
}
function ie(e, n) {
  const t = window, r = $n(e.workerUrl);
  t.apibase = e.apibase, t.uriprefix = e.uriprefix, t.lang = e.lang, t.__OFFICE_SDK_RUNTIME__ = {
    assetBaseUrl: e.assetBaseUrl,
    localeAssetRoot: e.localeAssetRoot,
    workerUrl: e.workerUrl,
    storageWorkerUrl: r
  }, t.__OFFICE_SDK_MOUNT__ = !0, t.__OFFICE_SDK_MOUNT_COUNT__ = (E == null ? void 0 : E.mountCount) ?? 0, n && (document.title = n);
}
function Yn(e, n) {
  return e.apibase === n.apibase && e.uriprefix === n.uriprefix && e.lang === n.lang && e.assetBaseUrl === n.assetBaseUrl && e.localeAssetRoot === n.localeAssetRoot && e.workerUrl === n.workerUrl;
}
function Zn(e, n) {
  const t = zn(n);
  if (E) {
    if (E.core !== e.core || E.locale !== e.locale || !Yn(E.config, t))
      throw new Error(
        "Fuxin Office SDK can mount multiple active instances only when they share the same runtime and page-level config (apibase, uriprefix, lang, worker and asset roots)"
      );
  } else
    E = {
      config: t,
      core: e.core,
      locale: e.locale,
      mountCount: 0
    };
  E.mountCount += 1, ie(t, n.title);
}
function q() {
  if (!E)
    return;
  if (E.mountCount -= 1, E.mountCount > 0) {
    ie(E.config);
    return;
  }
  const e = window;
  delete e.__OFFICE_SDK_RUNTIME__, delete e.__OFFICE_SDK_MOUNT__, delete e.__OFFICE_SDK_MOUNT_COUNT__, E = null;
}
function le(e) {
  return e.mode ? e.mode : e.fileUrl || e.file ? "offline" : "online";
}
function Qn(e) {
  var t;
  const n = e.includes(".") ? ((t = e.split(".").pop()) == null ? void 0 : t.toLowerCase()) ?? "" : "";
  if (["xls", "xlsx"].includes(n))
    return "xlsx";
  if (["pptx"].includes(n))
    return "pptx";
  if (["doc", "docx"].includes(n))
    return "docx";
}
function Jn(e) {
  switch (e) {
    case "docx":
      return d.WORD;
    case "xlsx":
      return d.EXCEL;
    case "pptx":
      return d.PPT;
    default:
      return null;
  }
}
function et(e) {
  let n = 0;
  for (let t = 0; t < e.length; t += 1)
    n = (n << 5) - n + e.charCodeAt(t), n |= 0;
  return `widget-${Math.abs(n)}`;
}
function nt(e, n, t) {
  return typeof t == "string" && t ? `${e}:${t}` : typeof File < "u" && n instanceof File ? `${e}:${n.size}:${n.lastModified}:${n.type}` : typeof Blob < "u" && n instanceof Blob ? `${e}:${n.size}:${n.type}` : n instanceof ArrayBuffer ? `${e}:${n.byteLength}:arraybuffer` : ArrayBuffer.isView(n) ? `${e}:${n.byteLength}:view` : typeof n == "string" ? `${e}:${n}` : `${e}:local`;
}
function tt(e) {
  return e instanceof ArrayBuffer ? e.slice(0) : ArrayBuffer.isView(e) ? new Uint8Array(e.buffer, e.byteOffset, e.byteLength).slice().buffer : e;
}
function rt(e, n, t) {
  F({
    probeOnly: !0,
    mode: "offline",
    docId: t.docId,
    file: tt(t.file),
    fileUrl: t.fileUrl,
    fileName: t.fileName,
    user: e.user,
    eventTarget: n == null ? void 0 : n.eventTarget,
    title: e.title
  }).catch((r) => {
  });
}
async function ot(e, n) {
  var r;
  if (le(e) === "offline") {
    if (!e.fileUrl && !e.file)
      throw new Error('mount option "file" or "fileUrl" is required in offline mode');
    const o = e.fileUrl ? new URL(e.fileUrl, window.location.href).href : void 0, l = (r = e.fileName) == null ? void 0 : r.trim();
    if (!l)
      throw new Error('mount option "fileName" is required in offline mode');
    const c = Qn(l), s = Jn(c), i = e.docId ?? et(nt(l, e.file, o));
    return s ? (rt(e, n, {
      docId: i,
      file: e.file,
      fileUrl: o,
      fileName: l
    }), {
      docId: i,
      docType: s,
      file: e.file,
      fileUrl: o,
      fileName: l
    }) : F({
      probeOnly: !0,
      mode: "offline",
      docId: i,
      file: e.file,
      fileUrl: o,
      fileName: l,
      user: e.user,
      eventTarget: n == null ? void 0 : n.eventTarget,
      title: e.title
    });
  }
  if (!e.docId)
    throw new Error('mount option "docId" is required in online mode');
  return F({
    probeOnly: !0,
    mode: "online",
    eventTarget: n == null ? void 0 : n.eventTarget,
    docId: e.docId,
    title: e.title
  });
}
async function it(e, n, t, r, o) {
  if ([d.PDF, d.OFD, d.TXT].includes(e))
    throw new Error(`Fuxin Office SDK does not support docType ${e}`);
  return In(e, n, t, r, o);
}
function lt(e) {
  const n = Object.entries(d).find(([, t]) => t === e);
  return n ? n[0] : null;
}
function ct(e, n) {
  var t, r;
  return ((r = (t = e.store.state.file) == null ? void 0 : t.fileInfo) == null ? void 0 : r.docId) ?? n.docId ?? "";
}
function st(e) {
  var n;
  return ((n = e.api) == null ? void 0 : n.docApp) ?? null;
}
async function at(e) {
  const n = Kn(e), t = oe(), r = {
    eventTarget: new EventTarget(),
    uiOptions: n.uiOptions,
    widgetMode: n.widgetMode
  };
  Zn(t, n);
  const o = Hn(n), l = qn(o);
  try {
    const c = await ot(n, r), s = (c == null ? void 0 : c.docId) ?? n.docId;
    r.docId = s, r.mode = le(n), r.file = n.file, r.user = n.user, r.fileUrl = c && "fileUrl" in c ? c.fileUrl : n.fileUrl, r.fileName = c && "fileName" in c ? c.fileName : n.fileName, r.widgetMode = n.widgetMode;
    const { docType: i } = c;
    await te(i);
    const f = await it(
      i,
      l,
      n.lang,
      t.appLoaders,
      r
    );
    let u = !1;
    async function w() {
      if (!u) {
        u = !0;
        try {
          const O = f.destroy ?? f.close ?? f.unmount;
          await (O == null ? void 0 : O.call(f));
        } finally {
          l.replaceChildren(), q();
        }
      }
    }
    return {
      get docId() {
        return ct(f, {
          ...n,
          docId: s
        });
      },
      docType: i,
      docTypeName: lt(i),
      root: l,
      core: t.core,
      get app() {
        return st(f);
      },
      api: f.api,
      ready: f.ready,
      destroy: w,
      close: w,
      unmount: w
    };
  } catch (c) {
    throw l.replaceChildren(), q(), c;
  }
}
function ft(e) {
  var r;
  const n = e != null && e.mode ? { ...e.mode } : void 0, t = ((r = n == null ? void 0 : n.lang) == null ? void 0 : r.trim()) || void 0;
  return n && delete n.lang, {
    userData: J(e == null ? void 0 : e.userData),
    uiOptions: e == null ? void 0 : e.uiOptions,
    mode: n && Object.keys(n).length > 0 ? n : void 0,
    lang: t
  };
}
let A = null, V = 0;
z();
function ut(e) {
  var r;
  const n = (r = e.fileName) == null ? void 0 : r.trim();
  if (n)
    return n;
  const t = e.file;
  if (typeof File < "u" && t instanceof File && t.name)
    return t.name;
  if (typeof t == "string" && se(t))
    try {
      const l = new URL(t, window.location.href).pathname.split("/").pop() ?? "";
      if (l)
        return decodeURIComponent(l);
    } catch {
      const o = t.split("/").pop() ?? "";
      if (o)
        return o;
    }
  return "";
}
function ce(e) {
  const n = ut(e);
  if (n)
    return n;
  throw new Error("Fuxin Office SDK openfile requires fileData.fileName");
}
function dt(e) {
  let n = 0;
  for (let t = 0; t < e.length; t += 1)
    n = (n << 5) - n + e.charCodeAt(t), n |= 0;
  return `widget-${Math.abs(n)}`;
}
function Et(e, n) {
  return typeof File < "u" && n instanceof File ? `${e}:${n.size}:${n.lastModified}:${n.type}` : typeof Blob < "u" && n instanceof Blob ? `${e}:${n.size}:${n.type}` : n instanceof ArrayBuffer ? `${e}:${n.byteLength}:arraybuffer` : ArrayBuffer.isView(n) ? `${e}:${n.byteLength}:view` : typeof n == "string" ? `${e}:${n}` : `${e}:local`;
}
function mt(e, n) {
  var r;
  const t = (r = e.docId) == null ? void 0 : r.trim();
  return t || dt(Et(n, e.file));
}
function wt(e) {
  var t;
  switch (e.includes(".") ? ((t = e.split(".").pop()) == null ? void 0 : t.toLowerCase()) ?? "" : "") {
    case "doc":
    case "docx":
      return d.WORD;
    case "xls":
    case "xlsx":
      return d.EXCEL;
    case "pptx":
      return d.PPT;
    default:
      throw new Error(`Fuxin Office SDK openfile does not support file "${e || "(unknown)"}"`);
  }
}
function Ot(e) {
  switch (e) {
    case d.WORD:
      return "blank.docx";
    case d.EXCEL:
      return "blank.xlsx";
    case d.PPT:
      return "blank.pptx";
    default:
      throw new Error(`Fuxin Office SDK createfile does not support docType ${e}`);
  }
}
function ht(e) {
  return V += 1, `new-${e}-${Date.now()}-${V}`;
}
function Dt() {
  if (typeof window < "u" && typeof window.lang == "string" && window.lang)
    return window.lang;
  if (typeof document < "u" && document.documentElement.lang)
    return document.documentElement.lang;
}
function se(e) {
  return /^(blob:|data:|https?:\/\/|file:|\/|\.\/|\.\.\/)/i.test(e);
}
function _t(e) {
  return typeof Blob < "u" && e instanceof Blob ? e : e instanceof ArrayBuffer ? new Blob([e]) : ArrayBuffer.isView(e) ? new Blob([e]) : typeof e == "string" ? new Blob([e]) : null;
}
function yt(e) {
  if (typeof e == "string" && se(e))
    return {
      fileUrl: e,
      file: void 0,
      revoke: null
    };
  if (typeof Blob < "u" && e instanceof Blob || e instanceof ArrayBuffer || ArrayBuffer.isView(e))
    return {
      file: e,
      fileUrl: void 0,
      revoke: null
    };
  const n = typeof e == "string" ? new Blob([e]) : _t(e);
  if (!n)
    throw new Error("Fuxin Office SDK openfile requires fileData.file to be a URL, Blob, ArrayBuffer, or TypedArray");
  return {
    file: n,
    fileUrl: void 0,
    revoke: null
  };
}
function pt(e) {
  if (typeof HTMLElement < "u" && e instanceof HTMLElement)
    return { target: e };
  if (typeof e != "string" || !e.trim())
    throw new Error("Fuxin Office SDK widget.mount(...) requires a target dom id or HTMLElement");
  const n = e.trim();
  return n.startsWith("#") || n.startsWith(".") || n.startsWith("[") ? { target: n } : { domId: n };
}
function j(e) {
  const n = import.meta.url;
  return new URL(`./${e}`, n).href;
}
async function ae() {
  return A || (A = Promise.all([
    import(
      /* @vite-ignore */
      j("index_browser.js")
    ),
    import(
      /* @vite-ignore */
      j("office.locale.js")
    )
  ]).then(([e, n]) => ({
    core: e.default,
    locale: n.default
  })).catch((e) => {
    throw A = null, e;
  })), A;
}
function St(e, n, t, r, o, l) {
  const c = {
    handle: null,
    handlePromise: null,
    mountTarget: null,
    revokeFileUrl: null
  };
  async function s() {
    const i = c.handle ?? (c.handlePromise ? await c.handlePromise.catch(() => null) : null);
    c.handle = null, c.handlePromise = null;
    try {
      const f = (i == null ? void 0 : i.destroy) ?? (i == null ? void 0 : i.close) ?? (i == null ? void 0 : i.unmount);
      await (f == null ? void 0 : f.call(i));
    } finally {
      c.revokeFileUrl && (c.revokeFileUrl(), c.revokeFileUrl = null);
    }
  }
  return {
    mount(i) {
      return c.mountTarget = i, this;
    },
    async render() {
      if (!c.mountTarget)
        throw new Error("Fuxin Office SDK widget.render() requires widget.mount(...) to be called first");
      if (!c.handlePromise) {
        const f = ce(n), { file: u, fileUrl: w, revoke: O } = yt(n.file);
        c.revokeFileUrl = O, c.handlePromise = e.mount({
          ...pt(c.mountTarget),
          mode: "offline",
          docId: n.docId,
          file: u,
          fileUrl: w,
          fileName: f,
          user: t,
          uiOptions: o,
          widgetMode: l
        }).then((g) => (c.handle = g, g)).catch((g) => {
          throw c.handlePromise = null, c.revokeFileUrl && (c.revokeFileUrl(), c.revokeFileUrl = null), g;
        });
      }
      const i = await c.handlePromise;
      return await i.ready, i.app;
    },
    async destroy() {
      await s();
    },
    async close() {
      await s();
    },
    async unmount() {
      await s();
    },
    get docId() {
      var i;
      return ((i = c.handle) == null ? void 0 : i.docId) ?? n.docId ?? "";
    },
    get docType() {
      var i;
      return ((i = c.handle) == null ? void 0 : i.docType) ?? r;
    },
    get docTypeName() {
      var i;
      return ((i = c.handle) == null ? void 0 : i.docTypeName) ?? null;
    }
  };
}
async function fe(e, n) {
  z();
  const t = ce(e), r = mt(e, t), o = wt(t);
  await te(o);
  const { core: l, locale: c } = await ae(), {
    userData: s,
    uiOptions: i,
    mode: f,
    lang: u
  } = ft(n), w = xn({
    core: l,
    locale: c,
    lang: u ?? Dt()
  });
  return {
    docType: o,
    widget: St(
      w,
      { ...e, docId: r, fileName: t },
      s,
      o,
      i,
      f
    )
  };
}
async function gt(e, n) {
  const t = Ot(e), { locale: r } = await ae(), o = r == null ? void 0 : r.loadSample;
  if (typeof o != "function")
    throw new Error("Fuxin Office SDK createfile requires locale.loadSample(docType)");
  const l = await o.call(r, e);
  if (typeof l != "string" || !l.trim())
    throw new Error(`Fuxin Office SDK createfile did not receive a sample URL for docType ${e}`);
  return fe(
    {
      docId: ht(e),
      fileName: t,
      file: l.trim()
    },
    n
  );
}
function Ct(e) {
  return Ee(e ?? {});
}
function At(e) {
  kn(e);
}
const Lt = {
  configureLicense: At,
  openfile: fe,
  createfile: gt,
  preload: Ct
};
export {
  F as O,
  an as a,
  At as b,
  fn as c,
  a as d,
  gt as e,
  fe as f,
  Lt as o,
  Ct as p
};
