var N = Object.defineProperty; var U = (e, r, t) => r in e ? N(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t; var d = (e, r, t) => U(e, typeof r != "symbol" ? r + "" : r, t); const I = "%[a-f0-9]{2}", b = new RegExp("(" + I + ")|([^%]+?)", "gi"), w = new RegExp("(" + I + ")+", "gi"); function h(e, r) { try { return [decodeURIComponent(e.join(""))]; } catch { } if (e.length === 1) return e; r = r || 1; const t = e.slice(0, r), n = e.slice(r); return Array.prototype.concat.call([], h(t), h(n)); } function q(e) { try { return decodeURIComponent(e); } catch { let r = e.match(b) || []; for (let t = 1; t < r.length; t++) e = h(r, t).join(""), r = e.match(b) || []; return e; } } function D(e) { const r = { "%FE%FF": "��", "%FF%FE": "��" }; let t = w.exec(e); for (; t; ) { try { r[t[0]] = decodeURIComponent(t[0]); } catch { const a = q(t[0]); a !== t[0] && (r[t[0]] = a); } t = w.exec(e); } r["%C2"] = "�"; const n = Object.keys(r); for (const a of n) e = e.replace(new RegExp(a, "g"), r[a]); return e; } function k(e) { if (typeof e != "string") throw new TypeError("Expected `encodedURI` to be of type `string`, got `" + typeof e + "`"); try { return decodeURIComponent(e); } catch { return D(e); } } function M(e, r) { if (!(typeof e == "string" && typeof r == "string")) throw new TypeError("Expected the arguments to be of type `string`"); if (e === "" || r === "") return []; const t = e.indexOf(r); return t === -1 ? [] : [ e.slice(0, t), e.slice(t + r.length) ]; } function R(e, r) { const t = {}; if (Array.isArray(r)) for (const n of r) { const a = Object.getOwnPropertyDescriptor(e, n); a != null && a.enumerable && Object.defineProperty(t, n, a); } else for (const n of Reflect.ownKeys(e)) { const a = Object.getOwnPropertyDescriptor(e, n); if (a.enumerable) { const s = e[n]; r(n, s, e) && Object.defineProperty(t, n, a); } } return t; } const P = (e) => e == null, H = (e) => encodeURIComponent(e).replaceAll(/[!'()*]/g, (r) => `%${r.charCodeAt(0).toString(16).toUpperCase()}`), g = Symbol("encodeFragmentIdentifier"); function L(e) { switch (e.arrayFormat) { case "index": return (r) => (t, n) => { const a = t.length; return n === void 0 || e.skipNull && n === null || e.skipEmptyString && n === "" ? t : n === null ? [ ...t, [c(r, e), "[", a, "]"].join("") ] : [ ...t, [c(r, e), "[", c(a, e), "]=", c(n, e)].join("") ]; }; case "bracket": return (r) => (t, n) => n === void 0 || e.skipNull && n === null || e.skipEmptyString && n === "" ? t : n === null ? [ ...t, [c(r, e), "[]"].join("") ] : [ ...t, [c(r, e), "[]=", c(n, e)].join("") ]; case "colon-list-separator": return (r) => (t, n) => n === void 0 || e.skipNull && n === null || e.skipEmptyString && n === "" ? t : n === null ? [ ...t, [c(r, e), ":list="].join("") ] : [ ...t, [c(r, e), ":list=", c(n, e)].join("") ]; case "comma": case "separator": case "bracket-separator": { const r = e.arrayFormat === "bracket-separator" ? "[]=" : "="; return (t) => (n, a) => a === void 0 || e.skipNull && a === null || e.skipEmptyString && a === "" ? n : (a = a === null ? "" : a, n.length === 0 ? [[c(t, e), r, c(a, e)].join("")] : [[n, c(a, e)].join(e.arrayFormatSeparator)]); } default: return (r) => (t, n) => n === void 0 || e.skipNull && n === null || e.skipEmptyString && n === "" ? t : n === null ? [ ...t, c(r, e) ] : [ ...t, [c(r, e), "=", c(n, e)].join("") ]; } } function T(e) { let r; switch (e.arrayFormat) { case "index": return (t, n, a) => { if (r = /\[(\d*)]$/.exec(t), t = t.replace(/\[\d*]$/, ""), !r) { a[t] = n; return; } a[t] === void 0 && (a[t] = {}), a[t][r[1]] = n; }; case "bracket": return (t, n, a) => { if (r = /(\[])$/.exec(t), t = t.replace(/\[]$/, ""), !r) { a[t] = n; return; } if (a[t] === void 0) { a[t] = [n]; return; } a[t] = [...a[t], n]; }; case "colon-list-separator": return (t, n, a) => { if (r = /(:list)$/.exec(t), t = t.replace(/:list$/, ""), !r) { a[t] = n; return; } if (a[t] === void 0) { a[t] = [n]; return; } a[t] = [...a[t], n]; }; case "comma": case "separator": return (t, n, a) => { const s = typeof n == "string" && n.includes(e.arrayFormatSeparator), i = typeof n == "string" && !s && o(n, e).includes(e.arrayFormatSeparator); n = i ? o(n, e) : n; const f = s || i ? n.split(e.arrayFormatSeparator).map((l) => o(l, e)) : n === null ? n : o(n, e); a[t] = f; }; case "bracket-separator": return (t, n, a) => { const s = /(\[])$/.test(t); if (t = t.replace(/\[]$/, ""), !s) { a[t] = n && o(n, e); return; } const i = n === null ? [] : n.split(e.arrayFormatSeparator).map((f) => o(f, e)); if (a[t] === void 0) { a[t] = i; return; } a[t] = [...a[t], ...i]; }; default: return (t, n, a) => { if (a[t] === void 0) { a[t] = n; return; } a[t] = [...[a[t]].flat(), n]; }; } } function E(e) { if (typeof e != "string" || e.length !== 1) throw new TypeError("arrayFormatSeparator must be single character string"); } function c(e, r) { return r.encode ? r.strict ? H(e) : encodeURIComponent(e) : e; } function o(e, r) { return r.decode ? k(e) : e; } function O(e) { return Array.isArray(e) ? e.sort() : typeof e == "object" ? O(Object.keys(e)).sort((r, t) => Number(r) - Number(t)).map((r) => e[r]) : e; } function x(e) { const r = e.indexOf("#"); return r !== -1 && (e = e.slice(0, r)), e; } function V(e) { let r = ""; const t = e.indexOf("#"); return t !== -1 && (r = e.slice(t)), r; } function S(e, r) { return r.parseNumbers && !Number.isNaN(Number(e)) && typeof e == "string" && e.trim() !== "" ? e = Number(e) : r.parseBooleans && e !== null && (e.toLowerCase() === "true" || e.toLowerCase() === "false") && (e = e.toLowerCase() === "true"), e; } function y(e) { e = x(e); const r = e.indexOf("?"); return r === -1 ? "" : e.slice(r + 1); } function F(e, r) { r = { decode: !0, sort: !0, arrayFormat: "none", arrayFormatSeparator: ",", parseNumbers: !1, parseBooleans: !1, ...r }, E(r.arrayFormatSeparator); const t = T(r), n = /* @__PURE__ */ Object.create(null); if (typeof e != "string" || (e = e.trim().replace(/^[?#&]/, ""), !e)) return n; for (const a of e.split("&")) { if (a === "") continue; const s = r.decode ? a.replaceAll("+", " ") : a; let [i, f] = M(s, "="); i === void 0 && (i = s), f = f === void 0 ? null : ["comma", "separator", "bracket-separator"].includes(r.arrayFormat) ? f : o(f, r), t(o(i, r), f, n); } for (const [a, s] of Object.entries(n)) if (typeof s == "object" && s !== null) for (const [i, f] of Object.entries(s)) s[i] = S(f, r); else n[a] = S(s, r); return r.sort === !1 ? n : (r.sort === !0 ? Object.keys(n).sort() : Object.keys(n).sort(r.sort)).reduce((a, s) => { const i = n[s]; return a[s] = i && typeof i == "object" && !Array.isArray(i) ? O(i) : i, a; }, /* @__PURE__ */ Object.create(null)); } function $(e, r) { if (!e) return ""; r = { encode: !0, strict: !0, arrayFormat: "none", arrayFormatSeparator: ",", ...r }, E(r.arrayFormatSeparator); const t = (i) => r.skipNull && P(e[i]) || r.skipEmptyString && e[i] === "", n = L(r), a = {}; for (const [i, f] of Object.entries(e)) t(i) || (a[i] = f); const s = Object.keys(a); return r.sort !== !1 && s.sort(r.sort), s.map((i) => { const f = e[i]; return f === void 0 ? "" : f === null ? c(i, r) : Array.isArray(f) ? f.length === 0 && r.arrayFormat === "bracket-separator" ? c(i, r) + "[]" : f.reduce(n(i), []).join("&") : c(i, r) + "=" + c(f, r); }).filter((i) => i.length > 0).join("&"); } function A(e, r) { var a; r = { decode: !0, ...r }; let [t, n] = M(e, "#"); return t === void 0 && (t = e), { url: ((a = t == null ? void 0 : t.split("?")) == null ? void 0 : a[0]) ?? "", query: F(y(e), r), ...r && r.parseFragmentIdentifier && n ? { fragmentIdentifier: o(n, r) } : {} }; } function j(e, r) { r = { encode: !0, strict: !0, [g]: !0, ...r }; const t = x(e.url).split("?")[0] || "", n = y(e.url), a = { ...F(n, { sort: !1 }), ...e.query }; let s = $(a, r); s && (s = `?${s}`); let i = V(e.url); if (typeof e.fragmentIdentifier == "string") { const f = new URL(t); f.hash = e.fragmentIdentifier, i = r[g] ? f.hash : `#${e.fragmentIdentifier}`; } return `${t}${s}${i}`; } function C(e, r, t) { t = { parseFragmentIdentifier: !0, [g]: !1, ...t }; const { url: n, query: a, fragmentIdentifier: s } = A(e, t); return j({ url: n, query: R(a, r), fragmentIdentifier: s }, t); } function W(e, r, t) { const n = Array.isArray(r) ? (a) => !r.includes(a) : (a, s) => !r(a, s); return C(e, n, t); } const K = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, exclude: W, extract: y, parse: F, parseUrl: A, pick: C, stringify: $, stringifyUrl: j }, Symbol.toStringTag, { value: "Module" })), u = "https://docmee.cn", m = { dashboard: `${u}/sdk-ui/dashboard`, editor: `${u}/sdk-ui/editor`, creator: `${u}/sdk-ui/creator/0`, customTemplate: `${u}/sdk-ui/custom-template`, templateCreator: `${u}/sdk-ui/custom-template-creator`, templateMarker: `${u}/sdk-ui/marker` }; class B { /** * * @param {DocmeeUIConstructorOptions} options */ constructor({ token: r, page: t = "dashboard", container: n, pptId: a, onMessage: s, ...i }) { d(this, "docmeeHref", m.dashboard); d(this, "query", { iframe: "1" }); d(this, "iframe", null); d(this, "onMessage", () => Promise.resolve(!0)); d(this, "iframeMounted", !1); d(this, "initInterval", null); this.onMessage = s, this.container = n, location.protocol.startsWith("file") && console.log( "%c %s", "color: red; background-color: #f7c600", "🔴 不能在file协议下运行,请启动一个http服务来运行! 🔴 " ), r || console.log( "%c 初始化时,token不能为空!", "color: #d7514f; background-color: #2e2e2e" ), this.init({ token: r, page: t, pptId: a, ...i }); } _postMessage(r) { var t, n; if (!this.iframe.contentWindow) throw new Error("iframe未挂载!"); (n = (t = this.iframe) == null ? void 0 : t.contentWindow) == null || n.postMessage(r, this.docmeeHref); } init({ token: r, page: t = "dashboard", ...n }) { if (t === "editor" && !n.pptId) throw new Error("初始化editor页面时,必须传入pptId"); this.query = Object.assign({}, this.query, n), this.docmeeHref = m[t], this.updateToken(r), this._initIframe(!0); } // 初始化iframe _initIframe(r) { const t = this.container, n = document.createElement("iframe"), a = location.href, s = K.stringifyUrl({ url: this.docmeeHref, query: r ? { iframe: 1, targetOrigin: a } : this.query }); n.src = s, n.style.width = "100%", n.style.height = "100%", n.style.border = "0", n.style.outline = "none", n.style.padding = "0px", n.setAttribute("allowfullscreen", "true"), this.iframe = n, this.iframeMounted = !1, t.innerHTML = "", t.appendChild(n), this.iframe.addEventListener("load", () => { setTimeout(() => { this.iframeMounted || (this.initInterval = setInterval(() => { if (this.iframeMounted) return clearInterval(this.initInterval); r && this._postMessage({ type: "transParams", data: this.query }); }, 200)); }, 300), window.addEventListener("message", async (i) => { var l, p; if (i.source !== this.iframe.contentWindow) return; const f = i.data; if (r && f.type === "mounted" && (this.iframeMounted = !0, this._postMessage({ type: "transParams", data: this.query })), f.type === "user-info" && (this.iframeMounted = !0), f.type.startsWith("before")) { const _ = await ((l = this.onMessage) == null ? void 0 : l.call(this, f)); this._postMessage({ data: _, type: `recover_${f.type}` }); } else (p = this.onMessage) == null || p.call(this, f); }); }); } /** * 更新用户token * @param {string} latestToken 新的token */ updateToken(r) { /(a|s)k_.+/.test(r) || console.error("token 错误!"), this.token = r, this.query.token = r, this.iframeMounted && this._postMessage({ type: "transParams", data: { token: r } }); } /** * 卸载iframe */ destroy() { this.container.innerHTML = ""; } /** * 发送消息 * @param {{type: 'warning' | 'success' | 'error' | 'info', content: string}} */ sendMessage(r) { this._postMessage({ type: "message", data: r }); } getInfo() { this._postMessage({ type: "getInfo" }); } navigate({ page: r, pptId: t, templateId: n }) { if (!m[r]) throw new Error(`页面${r} 不存在`); this._postMessage({ type: "nav", data: { page: r, token: this.token, pptId: t, templateId: n } }); } changeCreatorData(r, t = !1) { this._postMessage({ type: "transParams", data: { creatorData: { ...r, createNow: t } } }); } } window.DocmeeUI = B;