@paramms/chat-widget 1.0.32 → 1.0.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,46 +1,47 @@
1
- var ce = Object.defineProperty;
2
- var de = (t, e, n) => e in t ? ce(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
- var m = (t, e, n) => de(t, typeof e != "symbol" ? e + "" : e, n);
4
- import { p as le, r as pe, a as ue } from "./uid.js";
5
- import { h as $e } from "./uid.js";
6
- import { P as fe, C as he, E as we, b as be, m as xe } from "./e2e.js";
7
- import { e as Me } from "./e2e.js";
8
- const Q = "http://www.w3.org/2000/svg", ge = 8e3;
9
- class me {
1
+ var pe = Object.defineProperty;
2
+ var he = (o, e, i) => e in o ? pe(o, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : o[e] = i;
3
+ var y = (o, e, i) => he(o, typeof e != "symbol" ? e + "" : e, i);
4
+ import { p as fe, r as ue, a as we } from "./uid.js";
5
+ import { h as Me } from "./uid.js";
6
+ import { P as be, C as xe, b as ge } from "./outbox.js";
7
+ import { e as He } from "./outbox.js";
8
+ import { E2ESession as me, extractX3DHInit as ye } from "./e2e.js";
9
+ const te = "http://www.w3.org/2000/svg", ve = 8e3;
10
+ class ke {
10
11
  constructor() {
11
- m(this, "svg", null);
12
- m(this, "timers", /* @__PURE__ */ new Set());
12
+ y(this, "svg", null);
13
+ y(this, "timers", /* @__PURE__ */ new Set());
13
14
  }
14
15
  /** Feed every server frame; the overlay reacts to annotation frames only. */
15
16
  apply(e) {
16
- var n;
17
+ var i;
17
18
  if (e.type === "annotation") this.draw(e.stroke);
18
19
  else if (e.type === "annotation_clear") this.clear();
19
- else if (e.type === "opened" && ((n = e.annotations) != null && n.length))
20
+ else if (e.type === "opened" && ((i = e.annotations) != null && i.length))
20
21
  for (const s of e.annotations) this.draw(s);
21
22
  }
22
23
  ensureSvg() {
23
- var n;
24
- if ((n = this.svg) != null && n.isConnected) return this.svg;
25
- const e = document.createElementNS(Q, "svg");
24
+ var i;
25
+ if ((i = this.svg) != null && i.isConnected) return this.svg;
26
+ const e = document.createElementNS(te, "svg");
26
27
  return e.setAttribute("data-relay-annotations", ""), e.setAttribute("aria-hidden", "true"), e.setAttribute(
27
28
  "style",
28
29
  "position:fixed;inset:0;width:100vw;height:100vh;pointer-events:none;z-index:2147483000;"
29
30
  ), document.body.append(e), this.svg = e, e;
30
31
  }
31
32
  draw(e) {
32
- var f;
33
- if (typeof document > "u" || !((f = e.points) != null && f.length)) return;
34
- const n = this.ensureSvg(), s = window.innerWidth, p = window.innerHeight, d = document.createElementNS(Q, "polyline");
35
- d.setAttribute("points", e.points.map((h) => `${(h.x * s).toFixed(1)},${(h.y * p).toFixed(1)}`).join(" ")), d.setAttribute("fill", "none"), d.setAttribute("stroke", e.color || "#ff3b30"), d.setAttribute("stroke-width", String(e.width || 3)), d.setAttribute("stroke-linecap", "round"), d.setAttribute("stroke-linejoin", "round"), d.setAttribute("data-stroke-id", e.id), n.append(d);
36
- const a = setTimeout(() => {
37
- d.style.transition = "opacity 600ms", d.style.opacity = "0";
38
- const h = setTimeout(() => {
39
- d.remove(), this.timers.delete(h);
33
+ var b;
34
+ if (typeof document > "u" || !((b = e.points) != null && b.length)) return;
35
+ const i = this.ensureSvg(), s = window.innerWidth, a = window.innerHeight, c = document.createElementNS(te, "polyline");
36
+ c.setAttribute("points", e.points.map((d) => `${(d.x * s).toFixed(1)},${(d.y * a).toFixed(1)}`).join(" ")), c.setAttribute("fill", "none"), c.setAttribute("stroke", e.color || "#ff3b30"), c.setAttribute("stroke-width", String(e.width || 3)), c.setAttribute("stroke-linecap", "round"), c.setAttribute("stroke-linejoin", "round"), c.setAttribute("data-stroke-id", e.id), i.append(c);
37
+ const f = setTimeout(() => {
38
+ c.style.transition = "opacity 600ms", c.style.opacity = "0";
39
+ const d = setTimeout(() => {
40
+ c.remove(), this.timers.delete(d);
40
41
  }, 650);
41
- this.timers.add(h), this.timers.delete(a);
42
- }, ge);
43
- this.timers.add(a);
42
+ this.timers.add(d), this.timers.delete(f);
43
+ }, ve);
44
+ this.timers.add(f);
44
45
  }
45
46
  clear() {
46
47
  var e;
@@ -48,11 +49,11 @@ class me {
48
49
  }
49
50
  destroy() {
50
51
  var e;
51
- for (const n of this.timers) clearTimeout(n);
52
+ for (const i of this.timers) clearTimeout(i);
52
53
  this.timers.clear(), (e = this.svg) == null || e.remove(), this.svg = null;
53
54
  }
54
55
  }
55
- const Z = "objectchat-widget-styles", ve = ["👍", "❤️", "😂", "😮", "😢", "🙏"], ye = `
56
+ const oe = "objectchat-widget-styles", Ce = ["👍", "❤️", "😂", "😮", "😢", "🙏"], Te = `
56
57
  .ocw { --ocw-accent:#4F63F5; --ocw-bg:#f3efe9; --ocw-card:#fff; --ocw-line:#ececec; --ocw-ink:#1c1b1a; --ocw-mut:#9b9690;
57
58
  position:relative;
58
59
  display:flex; flex-direction:column; height:100%; min-height:320px; background:var(--ocw-bg);
@@ -149,6 +150,17 @@ const Z = "objectchat-widget-styles", ve = ["👍", "❤️", "😂", "😮", "
149
150
  .ocw-offline-input:focus { outline:none; border-color:var(--ocw-accent); }
150
151
  .ocw-offline-submit { background:var(--ocw-accent); color:#fff; border:none; border-radius:10px; padding:11px; font-size:14px; font-weight:600; cursor:pointer; }
151
152
  .ocw-offline-thanks { font-size:14px; color:#15803d; font-weight:600; }
153
+ .ocw-prechat { margin:20px 14px; padding:20px; background:#fff; border:1px solid #e3ded7; border-radius:16px; }
154
+ .ocw-prechat-title { font-weight:700; font-size:15px; margin-bottom:12px; }
155
+ .ocw-prechat select { border:1px solid #e3ded7; border-radius:10px; padding:10px 12px; font:inherit; font-size:13px; background:#fff; }
156
+ .ocw-prechat-cb { display:flex; align-items:center; gap:8px; font-size:13px; color:var(--ocw-ink); }
157
+ .ocw-deflect { margin:0 14px 8px; display:flex; flex-direction:column; gap:6px; }
158
+ .ocw-deflect-card { text-align:left; background:#fff; border:1px solid #e3ded7; border-radius:12px; padding:10px 12px; font:inherit; font-size:13px; cursor:pointer; }
159
+ .ocw-deflect-card:hover { border-color:var(--ocw-accent); }
160
+ .ocw-deflect-q { font-weight:600; margin-bottom:2px; }
161
+ .ocw-deflect-a { color:var(--ocw-mut); font-size:12.5px; display:none; white-space:pre-wrap; }
162
+ .ocw-deflect-card.open .ocw-deflect-a { display:block; }
163
+ .ocw-deflect-hint { font-size:11.5px; color:var(--ocw-mut); text-align:center; }
152
164
  .ocw-csat-title { font-size:13px; font-weight:600; margin-bottom:8px; }
153
165
  .ocw-csat-stars { display:flex; gap:6px; }
154
166
  .ocw-csat-star { background:none; border:none; font-size:22px; cursor:pointer; padding:2px; opacity:.4; transition:opacity .15s; }
@@ -212,122 +224,129 @@ const Z = "objectchat-widget-styles", ve = ["👍", "❤️", "😂", "😮", "
212
224
  .ocw-bubble-wrap:hover .ocw-translate-btn { opacity:1; }
213
225
  .ocw-translated-tag { font-size:10px; color:var(--ocw-mut); margin-top:2px; }
214
226
  `;
215
- function ke() {
216
- if (typeof document > "u" || document.getElementById(Z)) return;
217
- const t = document.createElement("style");
218
- t.id = Z, t.textContent = ye, document.head.appendChild(t);
227
+ function Ie() {
228
+ if (typeof document > "u" || document.getElementById(oe)) return;
229
+ const o = document.createElement("style");
230
+ o.id = oe, o.textContent = Te, document.head.appendChild(o);
219
231
  }
220
- function o(t, e, n) {
221
- const s = document.createElement(t);
222
- return e && (s.className = e), n !== void 0 && (s.textContent = n), s;
232
+ function t(o, e, i) {
233
+ const s = document.createElement(o);
234
+ return e && (s.className = e), i !== void 0 && (s.textContent = i), s;
223
235
  }
224
- function Ce(t) {
236
+ function Se(o) {
225
237
  try {
226
- return new Date(t).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
238
+ return new Date(o).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
227
239
  } catch {
228
240
  return "";
229
241
  }
230
242
  }
231
- function _(t) {
243
+ function W(o) {
232
244
  var e;
233
- switch (t.kind) {
245
+ switch (o.kind) {
234
246
  case "text":
235
- return t.text;
247
+ return o.text;
236
248
  case "system":
237
- return typeof ((e = t.data) == null ? void 0 : e.message) == "string" ? String(t.data.message) : t.event;
249
+ return typeof ((e = o.data) == null ? void 0 : e.message) == "string" ? String(o.data.message) : o.event;
238
250
  case "card":
239
- return [t.title, t.body].filter(Boolean).join(" — ");
251
+ return [o.title, o.body].filter(Boolean).join(" — ");
240
252
  case "attachment":
241
- return t.name ?? t.url;
253
+ return o.name ?? o.url;
242
254
  case "form":
243
- return t.prompt;
255
+ return o.prompt;
244
256
  case "appointment":
245
- return `📅 ${t.title} — ${new Date(t.startIso).toLocaleString()}`;
257
+ return `📅 ${o.title} — ${new Date(o.startIso).toLocaleString()}`;
246
258
  }
247
259
  }
248
- class Te {
260
+ class Ee {
249
261
  /** Last seq the guest has seen per conversationId — used to compute unread badges. */
250
- constructor(e, n, s, p = {}) {
251
- m(this, "scroll");
252
- m(this, "chips");
253
- m(this, "typing");
254
- m(this, "quick");
255
- m(this, "formHost");
256
- m(this, "csatPanel");
257
- m(this, "offlinePanel");
258
- m(this, "footer");
259
- m(this, "input");
260
- m(this, "subjectCard");
261
- m(this, "e2eBadge");
262
- m(this, "statusBadge");
263
- m(this, "headerName");
264
- m(this, "connStatus");
265
- m(this, "typingTimer", null);
266
- m(this, "csatSubmitted", !1);
262
+ constructor(e, i, s, a = {}) {
263
+ y(this, "scroll");
264
+ y(this, "chips");
265
+ y(this, "typing");
266
+ y(this, "quick");
267
+ y(this, "formHost");
268
+ y(this, "csatPanel");
269
+ y(this, "offlinePanel");
270
+ y(this, "preChatPanel");
271
+ y(this, "deflectPanel");
272
+ y(this, "preChatBuilt", !1);
273
+ y(this, "preChatDone", !1);
274
+ y(this, "footer");
275
+ y(this, "input");
276
+ y(this, "subjectCard");
277
+ y(this, "e2eBadge");
278
+ y(this, "statusBadge");
279
+ y(this, "headerName");
280
+ y(this, "connStatus");
281
+ y(this, "typingTimer", null);
282
+ y(this, "csatSubmitted", !1);
267
283
  // ── Co-browsing (shared whiteboard) ─────────────────────────────────────
268
- m(this, "cobrowseBtn");
269
- m(this, "cobrowseCanvas");
270
- m(this, "cobrowseToolbar");
271
- m(this, "cobrowseHint");
272
- m(this, "cobrowseActive", !1);
273
- m(this, "cobrowseColor", "#f5713c");
274
- m(this, "lastAnnotationVersion", -1);
275
- m(this, "storeRef", null);
276
- m(this, "scrollCleanup", null);
284
+ y(this, "cobrowseBtn");
285
+ y(this, "cobrowseCanvas");
286
+ y(this, "cobrowseToolbar");
287
+ y(this, "cobrowseHint");
288
+ y(this, "cobrowseActive", !1);
289
+ y(this, "cobrowseColor", "#f5713c");
290
+ y(this, "lastAnnotationVersion", -1);
291
+ y(this, "storeRef", null);
292
+ y(this, "scrollCleanup", null);
277
293
  // ── Live translation ──────────────────────────────────────────────────-
278
- m(this, "translationCache", /* @__PURE__ */ new Map());
279
- m(this, "showingTranslation", /* @__PURE__ */ new Set());
280
- m(this, "subjectBuilt", !1);
281
- var v, w, z, L, I, A, g, k, $;
282
- this.root = e, this.me = n, this.h = s, this.cfg = p, ke(), e.replaceChildren(), e.classList.add("ocw"), p.accent && e.style.setProperty("--ocw-accent", p.accent);
283
- const d = o("div", "ocw-head"), a = o("div", "ocw-avatar");
284
- if ((v = p.userInfo) != null && v.avatar) {
285
- const y = document.createElement("img");
286
- y.src = p.userInfo.avatar, y.alt = p.userInfo.name ?? "You", y.style.cssText = "width:100%;height:100%;border-radius:50%;object-fit:cover", a.append(y);
294
+ y(this, "translationCache", /* @__PURE__ */ new Map());
295
+ y(this, "showingTranslation", /* @__PURE__ */ new Set());
296
+ y(this, "subjectBuilt", !1);
297
+ var g, h, I, T, $, A, z, P, k;
298
+ this.root = e, this.me = i, this.h = s, this.cfg = a, Ie(), e.replaceChildren(), e.classList.add("ocw"), a.accent && e.style.setProperty("--ocw-accent", a.accent);
299
+ const c = t("div", "ocw-head"), f = t("div", "ocw-avatar");
300
+ if ((g = a.userInfo) != null && g.avatar) {
301
+ const m = document.createElement("img");
302
+ m.src = a.userInfo.avatar, m.alt = a.userInfo.name ?? "You", m.style.cssText = "width:100%;height:100%;border-radius:50%;object-fit:cover", f.append(m);
287
303
  } else
288
- a.textContent = (w = p.userInfo) != null && w.name ? p.userInfo.name[0].toUpperCase() : "🧑";
289
- d.append(a);
290
- const f = o("div", "ocw-head-main");
291
- this.headerName = o("div", "ocw-head-name", ((z = p.subject) == null ? void 0 : z.ownerLabel) ?? ((L = p.subject) == null ? void 0 : L.title) ?? ""), f.append(this.headerName), (I = p.subject) != null && I.subtitle && f.append(o("div", "ocw-head-meta", p.subject.subtitle)), d.append(f), this.statusBadge = o("span", "ocw-badge", ((A = p.subject) == null ? void 0 : A.status) ?? ""), (g = p.subject) != null && g.status || (this.statusBadge.style.display = "none"), d.append(this.statusBadge), this.e2eBadge = o("span", "ocw-e2e", "🔒 E2E"), this.e2eBadge.style.display = "none", d.append(this.e2eBadge), this.connStatus = o("span", "ocw-conn-status"), this.connStatus.style.display = "none", d.append(this.connStatus), this.cobrowseBtn = o("button", "ocw-menu ocw-cobrowse-btn", "🖍"), this.cobrowseBtn.title = "Shared whiteboard — draw to point things out together", this.cobrowseBtn.addEventListener("click", () => {
304
+ f.textContent = (h = a.userInfo) != null && h.name ? a.userInfo.name[0].toUpperCase() : "🧑";
305
+ c.append(f);
306
+ const b = t("div", "ocw-head-main");
307
+ this.headerName = t("div", "ocw-head-name", ((I = a.subject) == null ? void 0 : I.ownerLabel) ?? ((T = a.subject) == null ? void 0 : T.title) ?? ""), b.append(this.headerName), ($ = a.subject) != null && $.subtitle && b.append(t("div", "ocw-head-meta", a.subject.subtitle)), c.append(b), this.statusBadge = t("span", "ocw-badge", ((A = a.subject) == null ? void 0 : A.status) ?? ""), (z = a.subject) != null && z.status || (this.statusBadge.style.display = "none"), c.append(this.statusBadge), this.e2eBadge = t("span", "ocw-e2e", "🔒 E2E"), this.e2eBadge.style.display = "none", c.append(this.e2eBadge), this.connStatus = t("span", "ocw-conn-status"), this.connStatus.style.display = "none", c.append(this.connStatus), this.cobrowseBtn = t("button", "ocw-menu ocw-cobrowse-btn", "🖍"), this.cobrowseBtn.title = "Shared whiteboard — draw to point things out together", this.cobrowseBtn.addEventListener("click", () => {
292
308
  this.cobrowseActive = !this.cobrowseActive, this.updateCobrowseUI();
293
- }), d.append(this.cobrowseBtn), d.append(o("button", "ocw-menu", "⋯")), this.chips = o("div", "ocw-chiprow"), this.scroll = o("div", "ocw-scroll"), this.subjectCard = o("div", "ocw-subject"), this.typing = o("div", "ocw-typing");
294
- const h = o("div", "ocw-typing-bubble");
295
- h.append(o("div", "ocw-typing-dot"), o("div", "ocw-typing-dot"), o("div", "ocw-typing-dot")), this.typing.append(o("div", "ocw-dot", "🧑"), h), this.quick = o("div", "ocw-quick");
296
- for (const y of p.quickReplies ?? []) {
297
- const E = o("button", void 0, y);
298
- E.addEventListener("click", () => {
299
- this.h.onSend(y), this.quick.style.display = "none";
300
- }), this.quick.append(E);
309
+ }), c.append(this.cobrowseBtn), c.append(t("button", "ocw-menu", "⋯")), this.chips = t("div", "ocw-chiprow"), this.scroll = t("div", "ocw-scroll"), this.subjectCard = t("div", "ocw-subject"), this.typing = t("div", "ocw-typing");
310
+ const d = t("div", "ocw-typing-bubble");
311
+ d.append(t("div", "ocw-typing-dot"), t("div", "ocw-typing-dot"), t("div", "ocw-typing-dot")), this.typing.append(t("div", "ocw-dot", "🧑"), d), this.quick = t("div", "ocw-quick");
312
+ for (const m of a.quickReplies ?? []) {
313
+ const S = t("button", void 0, m);
314
+ S.addEventListener("click", () => {
315
+ this.h.onSend(m), this.quick.style.display = "none";
316
+ }), this.quick.append(S);
301
317
  }
302
- this.formHost = o("div", "ocw-form-host"), this.csatPanel = o("div", "ocw-csat"), this.csatPanel.style.display = "none", this.offlinePanel = o("div", "ocw-offline"), this.offlinePanel.style.display = "none", this.input = o("textarea", void 0), this.input.rows = 1, this.input.placeholder = "Message…";
303
- const r = o("button", "ocw-sendbtn", ((k = p.i18n) == null ? void 0 : k.send) ?? "➤");
304
- r.addEventListener("click", () => this.flushSend()), this.input.addEventListener("keydown", (y) => {
305
- y.isComposing || y.keyCode === 229 || (y.key === "Enter" && !y.shiftKey ? (y.preventDefault(), this.flushSend()) : this.signalTyping());
318
+ this.formHost = t("div", "ocw-form-host"), this.csatPanel = t("div", "ocw-csat"), this.csatPanel.style.display = "none", this.offlinePanel = t("div", "ocw-offline"), this.offlinePanel.style.display = "none", this.preChatPanel = t("div", "ocw-prechat"), this.preChatPanel.style.display = "none", this.deflectPanel = t("div", "ocw-deflect"), this.deflectPanel.style.display = "none", this.input = t("textarea", void 0), this.input.rows = 1, this.input.placeholder = "Message…";
319
+ const w = t("button", "ocw-sendbtn", ((P = a.i18n) == null ? void 0 : P.send) ?? "➤");
320
+ w.addEventListener("click", () => this.flushSend()), this.input.addEventListener("input", () => {
321
+ var m, S;
322
+ this.storeRef && !this.storeRef.messages().some((B) => B.senderRole === "guest") ? (S = (m = this.h).onDeflectQuery) == null || S.call(m, this.input.value) : this.hideDeflection();
323
+ }), this.input.addEventListener("keydown", (m) => {
324
+ m.isComposing || m.keyCode === 229 || (m.key === "Enter" && !m.shiftKey ? (m.preventDefault(), this.flushSend()) : this.signalTyping());
306
325
  });
307
- const T = o("button", "ocw-attach", "📎");
308
- T.title = "Attach image or file";
309
- const b = document.createElement("input");
310
- b.type = "file", b.accept = "image/*,.pdf,.txt,.doc,.docx", b.style.display = "none", T.addEventListener("click", () => b.click()), b.addEventListener("change", () => {
311
- var y;
312
- (y = b.files) != null && y[0] && this.h.onAttach && this.h.onAttach(b.files[0]), b.value = "";
326
+ const v = t("button", "ocw-attach", "📎");
327
+ v.title = "Attach image or file";
328
+ const r = document.createElement("input");
329
+ r.type = "file", r.accept = "image/*,.pdf,.txt,.doc,.docx", r.style.display = "none", v.addEventListener("click", () => r.click()), r.addEventListener("change", () => {
330
+ var m;
331
+ (m = r.files) != null && m[0] && this.h.onAttach && this.h.onAttach(r.files[0]), r.value = "";
313
332
  });
314
- const l = o("div", "ocw-input");
315
- l.append(T, b, this.input, r);
316
- const c = o("div", "ocw-footer");
317
- (($ = p.i18n) == null ? void 0 : $.poweredBy) !== void 0 ? c.textContent = p.i18n.poweredBy : c.innerHTML = 'Powered by <a href="https://relay.paramms.com" target="_blank" rel="noopener">Relay</a>', this.footer = c, e.append(d, this.chips, this.scroll, this.typing, this.quick, this.formHost, this.csatPanel, this.offlinePanel, l, this.footer), this.cobrowseCanvas = o("canvas", "ocw-cobrowse-canvas"), this.cobrowseToolbar = o("div", "ocw-cobrowse-toolbar");
318
- for (const y of ["#f5713c", "#1c1b1a", "#2563eb", "#16a34a", "#dc2626"]) {
319
- const E = o("button", "ocw-cobrowse-swatch");
320
- E.style.background = y, E.type = "button", y === this.cobrowseColor && E.classList.add("sel"), E.addEventListener("click", () => {
321
- this.cobrowseColor = y;
322
- for (const R of this.cobrowseToolbar.querySelectorAll(".ocw-cobrowse-swatch")) R.classList.remove("sel");
323
- E.classList.add("sel");
324
- }), this.cobrowseToolbar.append(E);
333
+ const u = t("div", "ocw-input");
334
+ u.append(v, r, this.input, w);
335
+ const l = t("div", "ocw-footer");
336
+ ((k = a.i18n) == null ? void 0 : k.poweredBy) !== void 0 ? l.textContent = a.i18n.poweredBy : l.innerHTML = 'Powered by <a href="https://relay.paramms.com" target="_blank" rel="noopener">Relay</a>', this.footer = l, e.append(c, this.chips, this.scroll, this.typing, this.quick, this.formHost, this.csatPanel, this.offlinePanel, this.preChatPanel, this.deflectPanel, u, this.footer), this.cobrowseCanvas = t("canvas", "ocw-cobrowse-canvas"), this.cobrowseToolbar = t("div", "ocw-cobrowse-toolbar");
337
+ for (const m of ["#f5713c", "#1c1b1a", "#2563eb", "#16a34a", "#dc2626"]) {
338
+ const S = t("button", "ocw-cobrowse-swatch");
339
+ S.style.background = m, S.type = "button", m === this.cobrowseColor && S.classList.add("sel"), S.addEventListener("click", () => {
340
+ this.cobrowseColor = m;
341
+ for (const B of this.cobrowseToolbar.querySelectorAll(".ocw-cobrowse-swatch")) B.classList.remove("sel");
342
+ S.classList.add("sel");
343
+ }), this.cobrowseToolbar.append(S);
325
344
  }
326
- const C = o("button", "ocw-cobrowse-clear", "Clear");
345
+ const C = t("button", "ocw-cobrowse-clear", "Clear");
327
346
  C.addEventListener("click", () => {
328
- var y, E;
329
- return (E = (y = this.h).onAnnotateClear) == null ? void 0 : E.call(y);
330
- }), this.cobrowseToolbar.append(C), this.cobrowseHint = o("div", "ocw-cobrowse-hint", "🖍 Draw to point things out — visible to both sides"), e.append(this.cobrowseCanvas, this.cobrowseToolbar, this.cobrowseHint), this.bindCobrowsePointerEvents();
347
+ var m, S;
348
+ return (S = (m = this.h).onAnnotateClear) == null ? void 0 : S.call(m);
349
+ }), this.cobrowseToolbar.append(C), this.cobrowseHint = t("div", "ocw-cobrowse-hint", "🖍 Draw to point things out — visible to both sides"), e.append(this.cobrowseCanvas, this.cobrowseToolbar, this.cobrowseHint), this.bindCobrowsePointerEvents();
331
350
  }
332
351
  /** Returns the scroll container so history.ts can attach scroll listeners. */
333
352
  getScrollEl() {
@@ -335,8 +354,8 @@ class Te {
335
354
  }
336
355
  /** Registers a cleanup fn removed on destroy() to prevent listener leaks. */
337
356
  setScrollCleanup(e) {
338
- var n;
339
- (n = this.scrollCleanup) == null || n.call(this), this.scrollCleanup = e;
357
+ var i;
358
+ (i = this.scrollCleanup) == null || i.call(this), this.scrollCleanup = e;
340
359
  }
341
360
  /** Call when the widget is unmounted. Disconnects scroll listeners and clears timers. */
342
361
  destroy() {
@@ -349,6 +368,7 @@ class Te {
349
368
  /** Navigate to the chat screen (slide list left, slide chat in from right). */
350
369
  /** Navigate back to the list screen. */
351
370
  flushSend() {
371
+ this.hideDeflection();
352
372
  const e = this.input.value.trim();
353
373
  e && (this.input.value = "", this.h.onTyping(!1), this.h.onSend(e));
354
374
  }
@@ -357,66 +377,135 @@ class Te {
357
377
  this.h.onTyping(!0, e), this.typingTimer && clearTimeout(this.typingTimer), this.typingTimer = setTimeout(() => this.h.onTyping(!1), 2e3);
358
378
  }
359
379
  render(e) {
360
- var r, T, b;
380
+ var r, u, l, C, g;
361
381
  if (this.storeRef = e, this.cobrowseBtn.classList.toggle("show", !!e.subject), !e.subject && this.cobrowseActive && (this.cobrowseActive = !1, this.updateCobrowseUI()), this.cobrowseActive && e.annotationVersion !== this.lastAnnotationVersion && (this.lastAnnotationVersion = e.annotationVersion, this.resizeCobrowseCanvas(), this.redrawCobrowse()), e.accent && this.root.style.setProperty("--ocw-accent", e.accent), this.e2eBadge.style.display = e.e2e ? "inline-flex" : "none", this.buildSubjectCard(e), e.subject) {
362
- const l = (r = this.cfg.subject) == null ? void 0 : r.ownerLabel;
363
- l && (this.headerName.textContent = l);
382
+ const h = (r = this.cfg.subject) == null ? void 0 : r.ownerLabel;
383
+ h && (this.headerName.textContent = h);
364
384
  }
365
385
  this.quick.style.display = e.messages().length === 0 ? "flex" : "none", this.chips.replaceChildren();
366
- const n = e.visibleActions();
367
- this.chips.style.display = n.length ? "flex" : "none";
368
- for (const l of n) this.chips.append(this.chipEl(l));
369
- const s = this.scroll.scrollHeight, p = this.scroll.scrollTop;
386
+ const i = e.visibleActions();
387
+ this.chips.style.display = i.length ? "flex" : "none";
388
+ for (const h of i) this.chips.append(this.chipEl(h));
389
+ const s = this.scroll.scrollHeight, a = this.scroll.scrollTop;
370
390
  if (this.scroll.replaceChildren(), this.subjectCard.childNodes.length && this.scroll.append(this.subjectCard), e.hasMoreHistory) {
371
- const l = o("div", "ocw-load-more");
372
- l.textContent = "↑ Loading earlier messages…", l.style.pointerEvents = "none", this.scroll.append(l);
391
+ const h = t("div", "ocw-load-more");
392
+ h.textContent = "↑ Loading earlier messages…", h.style.pointerEvents = "none", this.scroll.append(h);
373
393
  }
374
- let d = 0;
375
- for (const l of e.messages())
376
- this.scroll.append(this.messageEl(l, e)), l.senderId !== this.me && l.seq > d && (d = l.seq);
377
- p > 20 ? this.scroll.scrollTop = this.scroll.scrollHeight - s + p : this.scroll.scrollTop = this.scroll.scrollHeight, d > 0 && this.h.onReadUpTo(d);
378
- const a = [...e.typing];
379
- this.typing.classList.toggle("active", a.length > 0);
380
- const f = this.typing.querySelector(".ocw-typing-bubble");
381
- f && f.setAttribute("aria-label", a.length ? "typing" : ""), this.footer.style.display = e.whiteLabel ? "none" : "block", e.offline ? (this.offlinePanel.style.display === "none" && this.buildOfflinePanel(e.offlineMessage), this.offlinePanel.style.display = "block", (T = this.root.querySelector(".ocw-input")) == null || T.style.setProperty("display", "none")) : (this.offlinePanel.style.display = "none", (b = this.root.querySelector(".ocw-input")) == null || b.style.removeProperty("display"));
382
- const h = ["resolved", "closed", "sold", "issued", "checked_out"];
383
- this.h.onCsat && !this.csatSubmitted && h.includes(e.state) && e.messages().length > 0 && (this.csatPanel.style.display === "none" && this.buildCsatPanel(), this.csatPanel.style.display = "block");
384
- }
385
- setConnStatus(e, n) {
394
+ let c = 0;
395
+ for (const h of e.messages())
396
+ this.scroll.append(this.messageEl(h, e)), h.senderId !== this.me && h.seq > c && (c = h.seq);
397
+ a > 20 ? this.scroll.scrollTop = this.scroll.scrollHeight - s + a : this.scroll.scrollTop = this.scroll.scrollHeight, c > 0 && this.h.onReadUpTo(c);
398
+ const f = [...e.typing];
399
+ this.typing.classList.toggle("active", f.length > 0);
400
+ const b = this.typing.querySelector(".ocw-typing-bubble");
401
+ b && b.setAttribute("aria-label", f.length ? "typing" : ""), this.footer.style.display = e.whiteLabel ? "none" : "block";
402
+ const d = e.messages().some((h) => h.senderRole === "guest");
403
+ !!((u = e.preChat) != null && u.enabled) && !this.preChatDone && !d && (e.preChat.showWhen !== "offline" || e.offline) ? (this.preChatBuilt || this.buildPreChatPanel(e.preChat), this.preChatPanel.style.display = "block", this.offlinePanel.style.display = "none", (l = this.root.querySelector(".ocw-input")) == null || l.style.setProperty("display", "none")) : (this.preChatPanel.style.display = "none", e.offline ? (this.offlinePanel.style.display === "none" && this.buildOfflinePanel(e.offlineMessage), this.offlinePanel.style.display = "block", (C = this.root.querySelector(".ocw-input")) == null || C.style.setProperty("display", "none")) : (this.offlinePanel.style.display = "none", (g = this.root.querySelector(".ocw-input")) == null || g.style.removeProperty("display")));
404
+ const v = ["resolved", "closed", "sold", "issued", "checked_out"];
405
+ this.h.onCsat && !this.csatSubmitted && v.includes(e.state) && e.messages().length > 0 && (this.csatPanel.style.display === "none" && this.buildCsatPanel(), this.csatPanel.style.display = "block");
406
+ }
407
+ setConnStatus(e, i) {
386
408
  if (e === "open") {
387
409
  this.connStatus.style.display = "none";
388
410
  return;
389
411
  }
390
412
  this.connStatus.style.display = "";
391
413
  const s = e === "error";
392
- this.connStatus.className = `ocw-conn-status${s ? " err" : e === "reconnecting" ? " warn" : ""}`, this.connStatus.textContent = s ? `⚠ ${n ?? "Chat unavailable"}` : e === "reconnecting" ? n ?? "↻ reconnecting…" : "● connecting…";
414
+ this.connStatus.className = `ocw-conn-status${s ? " err" : e === "reconnecting" ? " warn" : ""}`, this.connStatus.textContent = s ? `⚠ ${i ?? "Chat unavailable"}` : e === "reconnecting" ? i ?? "↻ reconnecting…" : "● connecting…";
393
415
  }
394
416
  buildOfflinePanel(e) {
395
- var f;
396
- this.offlinePanel.replaceChildren(), this.offlinePanel.append(o("div", "ocw-offline-icon", "🌙")), this.offlinePanel.append(o("div", "ocw-offline-title", ((f = this.cfg.i18n) == null ? void 0 : f.offline) ?? "We're offline right now")), this.offlinePanel.append(o("div", "ocw-offline-msg", e || "Leave your details and we'll get back to you soon."));
397
- const n = o("div", "ocw-offline-form"), s = o("input", "ocw-offline-input");
417
+ var b;
418
+ this.offlinePanel.replaceChildren(), this.offlinePanel.append(t("div", "ocw-offline-icon", "🌙")), this.offlinePanel.append(t("div", "ocw-offline-title", ((b = this.cfg.i18n) == null ? void 0 : b.offline) ?? "We're offline right now")), this.offlinePanel.append(t("div", "ocw-offline-msg", e || "Leave your details and we'll get back to you soon."));
419
+ const i = t("div", "ocw-offline-form"), s = t("input", "ocw-offline-input");
398
420
  s.placeholder = "Your name", s.type = "text";
399
- const p = o("input", "ocw-offline-input");
400
- p.placeholder = "Your email", p.type = "email";
401
- const d = o("textarea", "ocw-offline-input");
402
- d.placeholder = "Your message", d.rows = 3;
403
- const a = o("button", "ocw-offline-submit", "Send message");
404
- a.addEventListener("click", () => {
405
- !p.value.trim() || !d.value.trim() || (this.h.onSend(`[Offline form]
421
+ const a = t("input", "ocw-offline-input");
422
+ a.placeholder = "Your email", a.type = "email";
423
+ const c = t("textarea", "ocw-offline-input");
424
+ c.placeholder = "Your message", c.rows = 3;
425
+ const f = t("button", "ocw-offline-submit", "Send message");
426
+ f.addEventListener("click", () => {
427
+ !a.value.trim() || !c.value.trim() || (this.h.onSend(`[Offline form]
406
428
  Name: ${s.value || "Anonymous"}
407
- Email: ${p.value}
408
- Message: ${d.value}`), this.offlinePanel.replaceChildren(o("div", "ocw-offline-thanks", "✓ Message sent! We'll reply to your email.")));
409
- }), n.append(s, p, d, a), this.offlinePanel.append(n);
429
+ Email: ${a.value}
430
+ Message: ${c.value}`), this.offlinePanel.replaceChildren(t("div", "ocw-offline-thanks", "✓ Message sent! We'll reply to your email.")));
431
+ }), i.append(s, a, c, f), this.offlinePanel.append(i);
432
+ }
433
+ buildPreChatPanel(e) {
434
+ var d;
435
+ this.preChatBuilt = !0, this.preChatPanel.replaceChildren(), this.preChatPanel.append(t("div", "ocw-prechat-title", e.title ?? "Before we start…"));
436
+ const i = t("div", "ocw-offline-form"), s = {};
437
+ for (const w of e.fields ?? ["name", "email"]) {
438
+ const v = t("input", "ocw-offline-input");
439
+ v.type = w === "email" ? "email" : w === "phone" ? "tel" : "text", v.placeholder = w === "name" ? "Your name" : w === "email" ? "Your email" : "Your phone number", s[w] = v, i.append(v);
440
+ }
441
+ let a = null;
442
+ if ((d = e.topics) != null && d.length) {
443
+ a = t("select", void 0);
444
+ const w = document.createElement("option");
445
+ w.value = "", w.textContent = "What is this about?", a.append(w);
446
+ for (const v of e.topics) {
447
+ const r = document.createElement("option");
448
+ r.value = v, r.textContent = v, a.append(r);
449
+ }
450
+ i.append(a);
451
+ }
452
+ let c = null, f = null;
453
+ if (e.callbackOption) {
454
+ const w = t("label", "ocw-prechat-cb");
455
+ c = document.createElement("input"), c.type = "checkbox", w.append(c, document.createTextNode("📞 Request a call back")), i.append(w), s.phone || (f = t("input", "ocw-offline-input"), f.type = "tel", f.placeholder = "Phone number for the call", f.style.display = "none", c.addEventListener("change", () => f.style.setProperty("display", c.checked ? "block" : "none")), i.append(f));
456
+ }
457
+ const b = t("button", "ocw-offline-submit", "Start chat");
458
+ b.addEventListener("click", () => {
459
+ var u, l, C, g, h, I, T;
460
+ const w = (u = s.email) == null ? void 0 : u.value.trim();
461
+ if (s.email && (!w || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(w))) {
462
+ s.email.focus();
463
+ return;
464
+ }
465
+ const v = !!(c != null && c.checked), r = (((l = s.phone) == null ? void 0 : l.value) ?? (f == null ? void 0 : f.value) ?? "").trim();
466
+ if (v && !r) {
467
+ (C = s.phone ?? f) == null || C.focus();
468
+ return;
469
+ }
470
+ if (a && ((g = e.topics) != null && g.length) && !a.value) {
471
+ a.focus();
472
+ return;
473
+ }
474
+ this.completePreChat(), (T = (I = this.h).onPreChat) == null || T.call(I, {
475
+ ...(h = s.name) != null && h.value.trim() ? { name: s.name.value.trim() } : {},
476
+ ...w ? { email: w } : {},
477
+ ...r ? { phone: r } : {},
478
+ ...a != null && a.value ? { topic: a.value } : {},
479
+ ...v ? { callback: !0 } : {}
480
+ });
481
+ }), i.append(b), this.preChatPanel.append(i);
482
+ }
483
+ /** Mark pre-chat complete (submitted now or in a previous session). */
484
+ completePreChat() {
485
+ this.preChatDone = !0, this.preChatPanel.style.display = "none", this.storeRef && this.render(this.storeRef);
486
+ }
487
+ /** KB deflection results ("was this your question?") above the composer. */
488
+ showDeflection(e) {
489
+ if (!e.length) return this.hideDeflection();
490
+ this.deflectPanel.replaceChildren(), this.deflectPanel.append(t("div", "ocw-deflect-hint", "Instant answers — tap to expand"));
491
+ for (const i of e.slice(0, 3)) {
492
+ const s = t("button", "ocw-deflect-card");
493
+ s.append(t("div", "ocw-deflect-q", i.title), t("div", "ocw-deflect-a", i.answer)), s.addEventListener("click", () => s.classList.toggle("open")), this.deflectPanel.append(s);
494
+ }
495
+ this.deflectPanel.style.display = "flex";
496
+ }
497
+ hideDeflection() {
498
+ this.deflectPanel.style.display = "none", this.deflectPanel.replaceChildren();
410
499
  }
411
500
  buildCsatPanel() {
412
- this.csatPanel.replaceChildren(), this.csatPanel.append(o("div", "ocw-csat-title", "How did we do?"));
413
- const e = o("div", "ocw-csat-stars"), n = [];
501
+ this.csatPanel.replaceChildren(), this.csatPanel.append(t("div", "ocw-csat-title", "How did we do?"));
502
+ const e = t("div", "ocw-csat-stars"), i = [];
414
503
  for (let s = 1; s <= 5; s++) {
415
- const p = o("button", "ocw-csat-star", "★");
416
- p.dataset.score = String(s), p.addEventListener("mouseenter", () => n.forEach((d, a) => d.classList.toggle("lit", a < s))), p.addEventListener("mouseleave", () => n.forEach((d) => d.classList.remove("lit"))), p.addEventListener("click", () => {
417
- var d, a;
418
- this.csatSubmitted = !0, this.csatPanel.replaceChildren(o("div", "ocw-csat-done", `Thanks for your ${s}★ rating!`)), (a = (d = this.h).onCsat) == null || a.call(d, s);
419
- }), n.push(p), e.append(p);
504
+ const a = t("button", "ocw-csat-star", "★");
505
+ a.dataset.score = String(s), a.addEventListener("mouseenter", () => i.forEach((c, f) => c.classList.toggle("lit", f < s))), a.addEventListener("mouseleave", () => i.forEach((c) => c.classList.remove("lit"))), a.addEventListener("click", () => {
506
+ var c, f;
507
+ this.csatSubmitted = !0, this.csatPanel.replaceChildren(t("div", "ocw-csat-done", `Thanks for your ${s}★ rating!`)), (f = (c = this.h).onCsat) == null || f.call(c, s);
508
+ }), i.push(a), e.append(a);
420
509
  }
421
510
  this.csatPanel.append(e);
422
511
  }
@@ -432,242 +521,242 @@ Message: ${d.value}`), this.offlinePanel.replaceChildren(o("div", "ocw-offline-t
432
521
  /** Draw a stroke whose points are normalized to 0..1, scaled to the current
433
522
  * canvas size — so strokes line up across different viewport sizes. */
434
523
  drawStroke(e) {
435
- const n = this.cobrowseCanvas.getContext("2d");
436
- if (!n || e.points.length < 2) return;
437
- const s = this.cobrowseCanvas.width, p = this.cobrowseCanvas.height;
438
- n.strokeStyle = e.color, n.lineWidth = Math.max(1, e.width * Math.min(s, p)), n.lineJoin = "round", n.lineCap = "round", n.beginPath(), n.moveTo(e.points[0].x * s, e.points[0].y * p);
439
- for (const d of e.points.slice(1)) n.lineTo(d.x * s, d.y * p);
440
- n.stroke();
524
+ const i = this.cobrowseCanvas.getContext("2d");
525
+ if (!i || e.points.length < 2) return;
526
+ const s = this.cobrowseCanvas.width, a = this.cobrowseCanvas.height;
527
+ i.strokeStyle = e.color, i.lineWidth = Math.max(1, e.width * Math.min(s, a)), i.lineJoin = "round", i.lineCap = "round", i.beginPath(), i.moveTo(e.points[0].x * s, e.points[0].y * a);
528
+ for (const c of e.points.slice(1)) i.lineTo(c.x * s, c.y * a);
529
+ i.stroke();
441
530
  }
442
531
  redrawCobrowse() {
443
- var n;
532
+ var i;
444
533
  const e = this.cobrowseCanvas.getContext("2d");
445
534
  if (e) {
446
535
  e.clearRect(0, 0, this.cobrowseCanvas.width, this.cobrowseCanvas.height);
447
- for (const s of ((n = this.storeRef) == null ? void 0 : n.annotations) ?? []) this.drawStroke(s);
536
+ for (const s of ((i = this.storeRef) == null ? void 0 : i.annotations) ?? []) this.drawStroke(s);
448
537
  }
449
538
  }
450
539
  bindCobrowsePointerEvents() {
451
- let e = !1, n = [];
452
- const s = (a) => {
453
- const f = this.cobrowseCanvas.getBoundingClientRect(), h = f.width > 0 ? (a.clientX - f.left) / f.width : 0, r = f.height > 0 ? (a.clientY - f.top) / f.height : 0;
454
- return { x: Math.min(1, Math.max(0, h)), y: Math.min(1, Math.max(0, r)) };
455
- }, p = 6e-3;
456
- this.cobrowseCanvas.addEventListener("pointerdown", (a) => {
457
- this.cobrowseActive && (e = !0, n = [s(a)], this.cobrowseCanvas.setPointerCapture(a.pointerId));
458
- }), this.cobrowseCanvas.addEventListener("pointermove", (a) => {
459
- e && (n.push(s(a)), this.redrawCobrowse(), this.drawStroke({ points: n, color: this.cobrowseColor, width: p }));
540
+ let e = !1, i = [];
541
+ const s = (f) => {
542
+ const b = this.cobrowseCanvas.getBoundingClientRect(), d = b.width > 0 ? (f.clientX - b.left) / b.width : 0, w = b.height > 0 ? (f.clientY - b.top) / b.height : 0;
543
+ return { x: Math.min(1, Math.max(0, d)), y: Math.min(1, Math.max(0, w)) };
544
+ }, a = 6e-3;
545
+ this.cobrowseCanvas.addEventListener("pointerdown", (f) => {
546
+ this.cobrowseActive && (e = !0, i = [s(f)], this.cobrowseCanvas.setPointerCapture(f.pointerId));
547
+ }), this.cobrowseCanvas.addEventListener("pointermove", (f) => {
548
+ e && (i.push(s(f)), this.redrawCobrowse(), this.drawStroke({ points: i, color: this.cobrowseColor, width: a }));
460
549
  });
461
- const d = (a) => {
462
- var f, h;
550
+ const c = (f) => {
551
+ var b, d;
463
552
  if (e) {
464
- e = !1, n.length > 1 && ((h = (f = this.h).onAnnotate) == null || h.call(f, { id: `an_${Date.now()}_${Math.random().toString(36).slice(2)}`, points: n, color: this.cobrowseColor, width: p })), n = [];
553
+ e = !1, i.length > 1 && ((d = (b = this.h).onAnnotate) == null || d.call(b, { id: `an_${Date.now()}_${Math.random().toString(36).slice(2)}`, points: i, color: this.cobrowseColor, width: a })), i = [];
465
554
  try {
466
- this.cobrowseCanvas.releasePointerCapture(a.pointerId);
555
+ this.cobrowseCanvas.releasePointerCapture(f.pointerId);
467
556
  } catch {
468
557
  }
469
558
  }
470
559
  };
471
- this.cobrowseCanvas.addEventListener("pointerup", d), this.cobrowseCanvas.addEventListener("pointercancel", d);
560
+ this.cobrowseCanvas.addEventListener("pointerup", c), this.cobrowseCanvas.addEventListener("pointercancel", c);
472
561
  }
473
562
  buildSubjectCard(e) {
474
563
  if (this.subjectBuilt) return;
475
- const n = e.subject, s = this.cfg.subject, p = (n == null ? void 0 : n.title) ?? (s == null ? void 0 : s.title);
476
- if (!p) return;
477
- this.subjectBuilt = !0, this.subjectCard.replaceChildren(), this.subjectCard.append(o("div", "ocw-subject-title", p)), s != null && s.subtitle && this.subjectCard.append(o("div", "ocw-subject-sub", s.subtitle));
478
- const d = o("div", "ocw-tags");
479
- if (n) for (const [f, h] of Object.entries(n.fields)) d.append(o("span", "ocw-tag", `${f}: ${h}`));
480
- else for (const f of (s == null ? void 0 : s.tags) ?? []) d.append(o("span", "ocw-tag", f));
481
- d.childNodes.length && this.subjectCard.append(d);
482
- const a = (n == null ? void 0 : n.state) ?? (s == null ? void 0 : s.status);
483
- a && (this.statusBadge.textContent = a, this.statusBadge.style.display = "inline-flex");
564
+ const i = e.subject, s = this.cfg.subject, a = (i == null ? void 0 : i.title) ?? (s == null ? void 0 : s.title);
565
+ if (!a) return;
566
+ this.subjectBuilt = !0, this.subjectCard.replaceChildren(), this.subjectCard.append(t("div", "ocw-subject-title", a)), s != null && s.subtitle && this.subjectCard.append(t("div", "ocw-subject-sub", s.subtitle));
567
+ const c = t("div", "ocw-tags");
568
+ if (i) for (const [b, d] of Object.entries(i.fields)) c.append(t("span", "ocw-tag", `${b}: ${d}`));
569
+ else for (const b of (s == null ? void 0 : s.tags) ?? []) c.append(t("span", "ocw-tag", b));
570
+ c.childNodes.length && this.subjectCard.append(c);
571
+ const f = (i == null ? void 0 : i.state) ?? (s == null ? void 0 : s.status);
572
+ f && (this.statusBadge.textContent = f, this.statusBadge.style.display = "inline-flex");
484
573
  }
485
574
  chipEl(e) {
486
- const n = o("button", "ocw-chip", e.icon ? `${e.icon} ${e.label}` : e.label);
487
- return n.dataset.actionId = e.id, n.addEventListener("click", async () => {
575
+ const i = t("button", "ocw-chip", e.icon ? `${e.icon} ${e.label}` : e.label);
576
+ return i.dataset.actionId = e.id, i.addEventListener("click", async () => {
488
577
  var s;
489
578
  e.confirm && !await this.confirm(e.label) || ((s = e.input) != null && s.length ? this.openForm(e) : this.h.onInvoke(e.id));
490
- }), n;
579
+ }), i;
491
580
  }
492
581
  /** In-widget confirmation modal (replaces window.confirm). */
493
582
  confirm(e) {
494
- return new Promise((n) => {
495
- const s = o("div", "ocw-modal"), p = o("div", "ocw-modal-card");
496
- p.append(o("div", "ocw-modal-title", e)), p.append(o("div", "ocw-modal-body", `Confirm “${e}”?`));
497
- const d = o("div", "ocw-modal-actions"), a = o("button", "ocw-modal-cancel", "Cancel"), f = o("button", "ocw-modal-ok", "Confirm"), h = (r) => {
498
- s.remove(), n(r);
583
+ return new Promise((i) => {
584
+ const s = t("div", "ocw-modal"), a = t("div", "ocw-modal-card");
585
+ a.append(t("div", "ocw-modal-title", e)), a.append(t("div", "ocw-modal-body", `Confirm “${e}”?`));
586
+ const c = t("div", "ocw-modal-actions"), f = t("button", "ocw-modal-cancel", "Cancel"), b = t("button", "ocw-modal-ok", "Confirm"), d = (w) => {
587
+ s.remove(), i(w);
499
588
  };
500
- a.addEventListener("click", () => h(!1)), f.addEventListener("click", () => h(!0)), s.addEventListener("click", (r) => {
501
- r.target === s && h(!1);
502
- }), d.append(a, f), p.append(d), s.append(p), this.root.append(s), f.focus();
589
+ f.addEventListener("click", () => d(!1)), b.addEventListener("click", () => d(!0)), s.addEventListener("click", (w) => {
590
+ w.target === s && d(!1);
591
+ }), c.append(f, b), a.append(c), s.append(a), this.root.append(s), b.focus();
503
592
  });
504
593
  }
505
594
  /** Inline form for a form-effect action: typed inputs (date picker, number,
506
595
  * text) rendered above the composer — no browser prompts. */
507
596
  openForm(e) {
508
- var f, h;
597
+ var b, d;
509
598
  this.formHost.replaceChildren();
510
- const n = o("div", "ocw-form");
511
- n.append(o("div", "ocw-form-title", e.icon ? `${e.icon} ${e.label}` : e.label));
599
+ const i = t("div", "ocw-form");
600
+ i.append(t("div", "ocw-form-title", e.icon ? `${e.icon} ${e.label}` : e.label));
512
601
  const s = /* @__PURE__ */ new Map();
513
- for (const r of e.input ?? []) {
514
- const T = o("label", "ocw-form-row");
515
- if (T.append(o("span", "ocw-form-lbl", r.label)), r.type === "select" && ((f = r.options) != null && f.length)) {
516
- const b = o("select", "ocw-form-input");
517
- r.required || b.append(o("option", void 0, "— select —"));
518
- for (const l of r.options) {
519
- const c = o("option");
520
- c.value = l, c.textContent = l, b.append(c);
602
+ for (const w of e.input ?? []) {
603
+ const v = t("label", "ocw-form-row");
604
+ if (v.append(t("span", "ocw-form-lbl", w.label)), w.type === "select" && ((b = w.options) != null && b.length)) {
605
+ const r = t("select", "ocw-form-input");
606
+ w.required || r.append(t("option", void 0, "— select —"));
607
+ for (const u of w.options) {
608
+ const l = t("option");
609
+ l.value = u, l.textContent = u, r.append(l);
521
610
  }
522
- r.required && (b.required = !0), T.append(b), s.set(r.name, b);
611
+ w.required && (r.required = !0), v.append(r), s.set(w.name, r);
523
612
  } else {
524
- const b = o("input", "ocw-form-input");
525
- b.type = r.type === "number" ? "number" : r.type === "date" ? "datetime-local" : "text", r.required && (b.required = !0), T.append(b), s.set(r.name, b);
613
+ const r = t("input", "ocw-form-input");
614
+ r.type = w.type === "number" ? "number" : w.type === "date" ? "datetime-local" : "text", w.required && (r.required = !0), v.append(r), s.set(w.name, r);
526
615
  }
527
- n.append(T);
616
+ i.append(v);
528
617
  }
529
- const p = o("div", "ocw-form-actions"), d = o("button", "ocw-form-cancel", "Cancel"), a = o("button", "ocw-form-submit", "Send");
530
- d.addEventListener("click", () => this.formHost.replaceChildren()), a.addEventListener("click", () => {
531
- const r = {};
532
- for (const [T, b] of s) {
533
- if (b.required && !b.value) {
534
- b.style.borderColor = "#e5484d";
618
+ const a = t("div", "ocw-form-actions"), c = t("button", "ocw-form-cancel", "Cancel"), f = t("button", "ocw-form-submit", "Send");
619
+ c.addEventListener("click", () => this.formHost.replaceChildren()), f.addEventListener("click", () => {
620
+ const w = {};
621
+ for (const [v, r] of s) {
622
+ if (r.required && !r.value) {
623
+ r.style.borderColor = "#e5484d";
535
624
  return;
536
625
  }
537
- r[T] = b.type === "number" ? Number(b.value) : b.value;
626
+ w[v] = r.type === "number" ? Number(r.value) : r.value;
538
627
  }
539
- this.formHost.replaceChildren(), this.h.onInvoke(e.id, r);
540
- }), p.append(d, a), n.append(p), this.formHost.append(n), (h = s.values().next().value) == null || h.focus();
628
+ this.formHost.replaceChildren(), this.h.onInvoke(e.id, w);
629
+ }), a.append(c, f), i.append(a), this.formHost.append(i), (d = s.values().next().value) == null || d.focus();
541
630
  }
542
- messageEl(e, n) {
543
- var b;
631
+ messageEl(e, i) {
632
+ var r;
544
633
  if (e.senderRole === "system") {
545
- const l = o("div", "ocw-sys");
546
- return l.textContent = e.deletedAt ? "message deleted" : _(e.content), l;
634
+ const u = t("div", "ocw-sys");
635
+ return u.textContent = e.deletedAt ? "message deleted" : W(e.content), u;
547
636
  }
548
- const s = e.senderId === this.me, p = !!e.internal, d = o("div", `ocw-row ${p ? "ocw-note mine" : s ? "mine" : "theirs"} ${e.senderRole === "bot" ? "ocw-bot" : ""}`);
549
- !s && !p && d.append(o("div", "ocw-dot", e.senderRole === "bot" ? "🤖" : "🧑"));
550
- const a = o("div"), f = o("div", "ocw-bubble-wrap");
637
+ const s = e.senderId === this.me, a = !!e.internal, c = t("div", `ocw-row ${a ? "ocw-note mine" : s ? "mine" : "theirs"} ${e.senderRole === "bot" ? "ocw-bot" : ""}`);
638
+ !s && !a && c.append(t("div", "ocw-dot", e.senderRole === "bot" ? "🤖" : "🧑"));
639
+ const f = t("div"), b = t("div", "ocw-bubble-wrap");
551
640
  if (e.replyToId) {
552
- const l = o("div", "ocw-reply-to", "↩ replying to a message");
553
- l.style.cssText = "font-size:11px;color:var(--ocw-mut);margin-bottom:2px;font-style:italic", a.append(l);
641
+ const u = t("div", "ocw-reply-to", "↩ replying to a message");
642
+ u.style.cssText = "font-size:11px;color:var(--ocw-mut);margin-bottom:2px;font-style:italic", f.append(u);
554
643
  }
555
- const h = o("div", "ocw-bubble");
556
- let r = null;
557
- if (e.deletedAt) h.append(o("span", "ocw-deleted", "message deleted"));
644
+ const d = t("div", "ocw-bubble");
645
+ let w = null;
646
+ if (e.deletedAt) d.append(t("span", "ocw-deleted", "message deleted"));
558
647
  else if (e.content.kind === "attachment") {
559
- const l = e.content;
560
- if ((b = l.mime) != null && b.startsWith("image/")) {
561
- const c = document.createElement("img");
562
- c.src = l.url, c.alt = l.name ?? "image", c.style.cssText = "max-width:220px;max-height:160px;border-radius:10px;display:block;cursor:pointer", c.addEventListener("click", () => window.open(l.url, "_blank")), h.append(c);
648
+ const u = e.content;
649
+ if ((r = u.mime) != null && r.startsWith("image/")) {
650
+ const l = document.createElement("img");
651
+ l.src = u.url, l.alt = u.name ?? "image", l.style.cssText = "max-width:220px;max-height:160px;border-radius:10px;display:block;cursor:pointer", l.addEventListener("click", () => window.open(u.url, "_blank")), d.append(l);
563
652
  } else {
564
- const c = document.createElement("a");
565
- c.href = l.url, c.target = "_blank", c.rel = "noopener", c.style.cssText = "display:flex;align-items:center;gap:8px;color:inherit;text-decoration:none", c.append(o("span", void 0, "📄"), o("span", void 0, l.name ?? "file")), h.append(c);
653
+ const l = document.createElement("a");
654
+ l.href = u.url, l.target = "_blank", l.rel = "noopener", l.style.cssText = "display:flex;align-items:center;gap:8px;color:inherit;text-decoration:none", l.append(t("span", void 0, "📄"), t("span", void 0, u.name ?? "file")), d.append(l);
566
655
  }
567
656
  } else if (e.content.kind === "appointment") {
568
- const l = e.content, c = o("div", "ocw-appt");
569
- c.append(o("div", "ocw-appt-title", `📅 ${l.title}`)), c.append(o("div", "ocw-appt-time", new Date(l.startIso).toLocaleString() + " – " + new Date(l.endIso).toLocaleTimeString())), l.location && c.append(o("div", "ocw-appt-loc", `📍 ${l.location}`)), l.description && c.append(o("div", "ocw-appt-desc", l.description));
570
- const C = o("div", "ocw-appt-links"), v = document.createElement("a");
571
- v.href = l.googleUrl, v.target = "_blank", v.rel = "noopener", v.className = "ocw-appt-btn", v.textContent = "📅 Add to Google Calendar";
572
- const w = document.createElement("a");
573
- w.href = l.icalUrl, w.download = `${l.title}.ics`, w.className = "ocw-appt-btn ocw-appt-btn-sec", w.textContent = "🍎 Apple / iCal", C.append(v, w), c.append(C), h.append(c);
657
+ const u = e.content, l = t("div", "ocw-appt");
658
+ l.append(t("div", "ocw-appt-title", `📅 ${u.title}`)), l.append(t("div", "ocw-appt-time", new Date(u.startIso).toLocaleString() + " – " + new Date(u.endIso).toLocaleTimeString())), u.location && l.append(t("div", "ocw-appt-loc", `📍 ${u.location}`)), u.description && l.append(t("div", "ocw-appt-desc", u.description));
659
+ const C = t("div", "ocw-appt-links"), g = document.createElement("a");
660
+ g.href = u.googleUrl, g.target = "_blank", g.rel = "noopener", g.className = "ocw-appt-btn", g.textContent = "📅 Add to Google Calendar";
661
+ const h = document.createElement("a");
662
+ h.href = u.icalUrl, h.download = `${u.title}.ics`, h.className = "ocw-appt-btn ocw-appt-btn-sec", h.textContent = "🍎 Apple / iCal", C.append(g, h), l.append(C), d.append(l);
574
663
  } else
575
- r = document.createTextNode(_(e.content)), h.append(r), e.editedAt && h.append(o("span", "ocw-edited", "(edited)"));
576
- if (f.append(h), !s && !p && this.h.onTranslate && e.content.kind === "text" && !e.deletedAt && e.seq > 0 && r) {
577
- const l = e.content.text;
578
- if (l.trim()) {
579
- const c = o("button", "ocw-translate-btn", "🌐");
580
- c.type = "button", c.title = "Translate", c.addEventListener("click", (C) => {
664
+ w = document.createTextNode(W(e.content)), d.append(w), e.editedAt && d.append(t("span", "ocw-edited", "(edited)"));
665
+ if (b.append(d), !s && !a && this.h.onTranslate && e.content.kind === "text" && !e.deletedAt && e.seq > 0 && w) {
666
+ const u = e.content.text;
667
+ if (u.trim()) {
668
+ const l = t("button", "ocw-translate-btn", "🌐");
669
+ l.type = "button", l.title = "Translate", l.addEventListener("click", (C) => {
581
670
  if (C.stopPropagation(), this.showingTranslation.has(e.id)) {
582
- this.showingTranslation.delete(e.id), r.textContent = l, c.textContent = "🌐", c.title = "Translate";
671
+ this.showingTranslation.delete(e.id), w.textContent = u, l.textContent = "🌐", l.title = "Translate";
583
672
  return;
584
673
  }
585
- const v = this.translationCache.get(e.id);
586
- if (v !== void 0) {
587
- this.showingTranslation.add(e.id), r.textContent = v, c.textContent = "↩", c.title = "Show original";
674
+ const g = this.translationCache.get(e.id);
675
+ if (g !== void 0) {
676
+ this.showingTranslation.add(e.id), w.textContent = g, l.textContent = "↩", l.title = "Show original";
588
677
  return;
589
678
  }
590
- c.textContent = "⏳", this.h.onTranslate(l).then((w) => {
591
- if (w === null) {
592
- c.textContent = "⚠️", c.title = "Translation unavailable", setTimeout(() => {
593
- c.textContent = "🌐", c.title = "Translate";
679
+ l.textContent = "⏳", this.h.onTranslate(u).then((h) => {
680
+ if (h === null) {
681
+ l.textContent = "⚠️", l.title = "Translation unavailable", setTimeout(() => {
682
+ l.textContent = "🌐", l.title = "Translate";
594
683
  }, 1500);
595
684
  return;
596
685
  }
597
- this.translationCache.set(e.id, w), this.showingTranslation.add(e.id), r.textContent = w, c.textContent = "↩", c.title = "Show original";
686
+ this.translationCache.set(e.id, h), this.showingTranslation.add(e.id), w.textContent = h, l.textContent = "↩", l.title = "Show original";
598
687
  });
599
- }), f.append(c);
688
+ }), b.append(l);
600
689
  }
601
690
  }
602
691
  if (s && !e.deletedAt && e.seq > 0 && (this.h.onEdit ?? this.h.onDelete)) {
603
- const l = o("div", "ocw-msg-menu");
692
+ const u = t("div", "ocw-msg-menu");
604
693
  if (this.h.onEdit) {
605
- const c = o("button", void 0, "✏️");
606
- c.title = "Edit", c.addEventListener("click", (C) => {
694
+ const l = t("button", void 0, "✏️");
695
+ l.title = "Edit", l.addEventListener("click", (C) => {
607
696
  C.stopPropagation();
608
- const v = _(e.content), w = document.createElement("textarea");
609
- w.value = v, w.rows = Math.min(4, Math.ceil(v.length / 40) + 1), w.style.cssText = "width:100%;resize:vertical;border:1px solid var(--ocw-accent);border-radius:8px;padding:6px 10px;font:inherit;font-size:14px;background:#fff;color:#1c1b1a;box-sizing:border-box";
610
- const z = o("button", "ocw-form-submit", "Save");
611
- z.style.cssText = "margin-top:6px;padding:5px 14px;font-size:13px";
612
- const L = o("button", "ocw-form-cancel", "Cancel");
613
- L.style.cssText = "margin-top:6px;padding:5px 10px;font-size:13px";
614
- const I = o("div");
615
- I.style.cssText = "display:flex;gap:6px;justify-content:flex-end", I.append(L, z);
616
- const A = o("div");
617
- A.append(w, I), h.replaceChildren(A), w.focus(), w.select();
618
- const g = () => h.replaceChildren(r ?? document.createTextNode(v));
619
- L.addEventListener("click", g), z.addEventListener("click", () => {
620
- const k = w.value.trim();
621
- k && k !== v && this.h.onEdit(e.id, k), g();
622
- }), w.addEventListener("keydown", (k) => {
623
- k.key === "Enter" && !k.shiftKey && (k.preventDefault(), z.click()), k.key === "Escape" && g();
697
+ const g = W(e.content), h = document.createElement("textarea");
698
+ h.value = g, h.rows = Math.min(4, Math.ceil(g.length / 40) + 1), h.style.cssText = "width:100%;resize:vertical;border:1px solid var(--ocw-accent);border-radius:8px;padding:6px 10px;font:inherit;font-size:14px;background:#fff;color:#1c1b1a;box-sizing:border-box";
699
+ const I = t("button", "ocw-form-submit", "Save");
700
+ I.style.cssText = "margin-top:6px;padding:5px 14px;font-size:13px";
701
+ const T = t("button", "ocw-form-cancel", "Cancel");
702
+ T.style.cssText = "margin-top:6px;padding:5px 10px;font-size:13px";
703
+ const $ = t("div");
704
+ $.style.cssText = "display:flex;gap:6px;justify-content:flex-end", $.append(T, I);
705
+ const A = t("div");
706
+ A.append(h, $), d.replaceChildren(A), h.focus(), h.select();
707
+ const z = () => d.replaceChildren(w ?? document.createTextNode(g));
708
+ T.addEventListener("click", z), I.addEventListener("click", () => {
709
+ const P = h.value.trim();
710
+ P && P !== g && this.h.onEdit(e.id, P), z();
711
+ }), h.addEventListener("keydown", (P) => {
712
+ P.key === "Enter" && !P.shiftKey && (P.preventDefault(), I.click()), P.key === "Escape" && z();
624
713
  });
625
- }), l.append(c);
714
+ }), u.append(l);
626
715
  }
627
716
  if (this.h.onDelete) {
628
- const c = o("button", "del", "🗑");
629
- c.title = "Delete", c.addEventListener("click", (C) => {
717
+ const l = t("button", "del", "🗑");
718
+ l.title = "Delete", l.addEventListener("click", (C) => {
630
719
  C.stopPropagation(), this.h.onDelete(e.id);
631
- }), l.append(c);
720
+ }), u.append(l);
632
721
  }
633
- f.append(l);
722
+ b.append(u);
634
723
  }
635
- if (a.append(f), this.h.onReact && !e.deletedAt && e.seq > 0) {
636
- const l = o("div", "ocw-react-wrap"), c = o("div", "ocw-react");
724
+ if (f.append(b), this.h.onReact && !e.deletedAt && e.seq > 0) {
725
+ const u = t("div", "ocw-react-wrap"), l = t("div", "ocw-react");
637
726
  if (e.reactions && Object.keys(e.reactions).length)
638
- for (const [w, z] of Object.entries(e.reactions)) {
639
- const L = o("button", `ocw-react-pill${z.includes(this.me) ? " mine" : ""}`, `${w} ${z.length}`);
640
- L.addEventListener("click", () => {
641
- var I, A;
642
- return (A = (I = this.h).onReact) == null ? void 0 : A.call(I, e.id, w, z.includes(this.me));
643
- }), c.append(L);
727
+ for (const [h, I] of Object.entries(e.reactions)) {
728
+ const T = t("button", `ocw-react-pill${I.includes(this.me) ? " mine" : ""}`, `${h} ${I.length}`);
729
+ T.addEventListener("click", () => {
730
+ var $, A;
731
+ return (A = ($ = this.h).onReact) == null ? void 0 : A.call($, e.id, h, I.includes(this.me));
732
+ }), l.append(T);
644
733
  }
645
- const C = o("button", "ocw-react-btn", "+"), v = o("div", "ocw-react-picker");
646
- for (const w of ve) {
647
- const z = o("button", void 0, w);
648
- z.addEventListener("click", (L) => {
649
- var A, g, k, $;
650
- L.stopPropagation();
651
- const I = (g = (A = e.reactions) == null ? void 0 : A[w]) == null ? void 0 : g.includes(this.me);
652
- ($ = (k = this.h).onReact) == null || $.call(k, e.id, w, !!I), v.style.display = "none";
653
- }), v.append(z);
734
+ const C = t("button", "ocw-react-btn", "+"), g = t("div", "ocw-react-picker");
735
+ for (const h of Ce) {
736
+ const I = t("button", void 0, h);
737
+ I.addEventListener("click", (T) => {
738
+ var A, z, P, k;
739
+ T.stopPropagation();
740
+ const $ = (z = (A = e.reactions) == null ? void 0 : A[h]) == null ? void 0 : z.includes(this.me);
741
+ (k = (P = this.h).onReact) == null || k.call(P, e.id, h, !!$), g.style.display = "none";
742
+ }), g.append(I);
654
743
  }
655
- v.style.display = "none", C.addEventListener("click", (w) => {
656
- w.stopPropagation(), v.style.display = v.style.display === "none" ? "flex" : "none";
744
+ g.style.display = "none", C.addEventListener("click", (h) => {
745
+ h.stopPropagation(), g.style.display = g.style.display === "none" ? "flex" : "none";
657
746
  }), document.addEventListener("click", () => {
658
- v.style.display = "none";
659
- }, { once: !0 }), c.append(C), l.append(c, v), a.append(l);
660
- } else e.reactions && Object.keys(e.reactions).length && a.append(o("div", "ocw-react", Object.entries(e.reactions).map(([l, c]) => `${l}${c.length}`).join(" ")));
661
- const T = o("div", "ocw-time ocw-meta", Ce(e.ts));
747
+ g.style.display = "none";
748
+ }, { once: !0 }), l.append(C), u.append(l, g), f.append(u);
749
+ } else e.reactions && Object.keys(e.reactions).length && f.append(t("div", "ocw-react", Object.entries(e.reactions).map(([u, l]) => `${u}${l.length}`).join(" ")));
750
+ const v = t("div", "ocw-time ocw-meta", Se(e.ts));
662
751
  if (s && e.status) {
663
- const l = o("span", `ocw-tick${e.status === "read" ? " read" : e.status === "delivered" ? " delivered" : ""}`, Se(e.status));
664
- T.append(l);
752
+ const u = t("span", `ocw-tick${e.status === "read" ? " read" : e.status === "delivered" ? " delivered" : ""}`, Pe(e.status));
753
+ v.append(u);
665
754
  }
666
- return s && e.seq > 0 && n.lastReadByOthers >= e.seq && T.append(o("span", "ocw-seen", " · Seen")), a.append(T), d.append(a), d;
755
+ return s && e.seq > 0 && i.lastReadByOthers >= e.seq && v.append(t("span", "ocw-seen", " · Seen")), f.append(v), c.append(f), c;
667
756
  }
668
757
  }
669
- function Se(t) {
670
- switch (t) {
758
+ function Pe(o) {
759
+ switch (o) {
671
760
  case "read":
672
761
  return "✓✓";
673
762
  case "delivered":
@@ -678,29 +767,31 @@ function Se(t) {
678
767
  return "🕓";
679
768
  }
680
769
  }
681
- const M = /* @__PURE__ */ new WeakMap(), F = /* @__PURE__ */ new Map();
682
- function ee(t) {
683
- return `relay-launcher::${t.profileId}::${t.subjectId ?? ""}`;
770
+ const R = /* @__PURE__ */ new WeakMap(), U = /* @__PURE__ */ new Map();
771
+ function ne(o) {
772
+ return `relay-launcher::${o.profileId}::${o.subjectId ?? ""}`;
684
773
  }
685
- function je(t) {
774
+ function Ae(o) {
686
775
  var e;
687
- (e = M.get(t)) == null || e.close(), M.delete(t);
776
+ (e = R.get(o)) == null || e.close(), R.delete(o);
688
777
  }
689
- function Le(t) {
690
- var V, Y, X, J, G;
691
- M.has(t.el) && (M.get(t.el).close(), M.delete(t.el)), t.launcher && ((V = F.get(ee(t))) == null || V.close());
692
- const e = le(), n = t.token ?? t.userId ?? e, s = n !== e ? e : void 0, { wsUrl: p, httpBase: d } = pe(t.url, t.apiUrl);
693
- let a = new he(n);
694
- const f = t.subjectId ? `${n}::${t.subjectId}` : n, h = new fe(f);
695
- let r, T = !1, b = null, l = null;
696
- !t.launcher && !t.el.style.height && t.el.clientHeight === 0 && (t.el.style.width = t.el.style.width || "100%", t.el.style.height = "600px");
697
- for (const i of h.load()) a.addOptimistic(i.clientMsgId, i.content);
698
- let c = null, C = null, v = 0, w = !t.launcher;
699
- if (t.launcher) {
700
- const u = (t.position ?? "bottom-right").includes("right");
701
- c = document.createElement("div"), c.style.cssText = `position:fixed;${u ? "right:20px" : "left:20px"};bottom:20px;z-index:9999;display:flex;flex-direction:column;align-items:${u ? "flex-end" : "flex-start"};gap:12px`;
702
- const x = document.createElement("div"), S = typeof window < "u" ? window.matchMedia("(max-width: 479px)") : null, O = (B) => {
703
- x.style.cssText = B ? [
778
+ function Be(o) {
779
+ var J, Q, G, Z, ee;
780
+ R.has(o.el) && (R.get(o.el).close(), R.delete(o.el)), o.launcher && ((J = U.get(ne(o))) == null || J.close());
781
+ const e = fe();
782
+ let i, s = !1;
783
+ const a = o.token ?? o.userId ?? e, c = a !== e ? e : void 0, { wsUrl: f, httpBase: b } = ue(o.url, o.apiUrl);
784
+ let d = new xe(a);
785
+ const w = o.subjectId ? `${a}::${o.subjectId}` : a, v = new be(w);
786
+ let r, u = !1, l = null, C = null;
787
+ !o.launcher && !o.el.style.height && o.el.clientHeight === 0 && (o.el.style.width = o.el.style.width || "100%", o.el.style.height = "600px");
788
+ for (const n of v.load()) d.addOptimistic(n.clientMsgId, n.content);
789
+ let g = null, h = null, I = 0, T = !o.launcher;
790
+ if (o.launcher) {
791
+ const p = (o.position ?? "bottom-right").includes("right");
792
+ g = document.createElement("div"), g.style.cssText = `position:fixed;${p ? "right:20px" : "left:20px"};bottom:20px;z-index:9999;display:flex;flex-direction:column;align-items:${p ? "flex-end" : "flex-start"};gap:12px`;
793
+ const x = document.createElement("div"), E = typeof window < "u" ? window.matchMedia("(max-width: 479px)") : null, O = (q) => {
794
+ x.style.cssText = q ? [
704
795
  "position:fixed",
705
796
  "inset:0",
706
797
  "width:100%",
@@ -723,150 +814,183 @@ function Le(t) {
723
814
  "display:none",
724
815
  "flex-direction:column",
725
816
  "background:#fff",
726
- "transform-origin:bottom " + (u ? "right" : "left"),
817
+ "transform-origin:bottom " + (p ? "right" : "left"),
727
818
  "transition:opacity .18s,transform .18s",
728
819
  "opacity:0",
729
820
  "transform:scale(.95)"
730
821
  ].join(";");
731
822
  };
732
- O((S == null ? void 0 : S.matches) ?? !1);
733
- const N = (B) => O(B.matches);
734
- S == null || S.addEventListener("change", N), b = S, l = N, t.el.style.cssText = "width:100%;height:100%;overflow:hidden", x.append(t.el);
735
- const j = document.createElement("button");
736
- j.style.cssText = [
823
+ O((E == null ? void 0 : E.matches) ?? !1);
824
+ const N = (q) => O(q.matches);
825
+ E == null || E.addEventListener("change", N), l = E, C = N, o.el.style.cssText = "width:100%;height:100%;overflow:hidden", x.append(o.el);
826
+ const L = document.createElement("button");
827
+ L.style.cssText = [
737
828
  "width:56px;height:56px;border-radius:50%",
738
- `background:${t.accent ?? "#4F63F5"}`,
829
+ `background:${o.accent ?? "#4F63F5"}`,
739
830
  "color:#fff;border:none;font-size:24px;cursor:pointer",
740
831
  "box-shadow:0 4px 16px rgba(0,0,0,.25)",
741
832
  "position:relative;flex:none",
742
833
  "transition:transform .15s"
743
- ].join(";"), j.textContent = "💬", j.onmouseenter = () => {
744
- j.style.transform = "scale(1.08)";
745
- }, j.onmouseleave = () => {
746
- j.style.transform = "scale(1)";
747
- }, C = document.createElement("span"), C.style.cssText = "position:absolute;top:-4px;right:-4px;background:#ef4444;color:#fff;border-radius:50%;width:20px;height:20px;font-size:11px;font-weight:700;display:none;align-items:center;justify-content:center", j.append(C), c.append(x, j), document.body.append(c);
748
- const D = (B) => {
749
- B ? (x.style.display = "flex", requestAnimationFrame(() => {
834
+ ].join(";"), L.textContent = "💬", L.onmouseenter = () => {
835
+ L.style.transform = "scale(1.08)";
836
+ }, L.onmouseleave = () => {
837
+ L.style.transform = "scale(1)";
838
+ }, h = document.createElement("span"), h.style.cssText = "position:absolute;top:-4px;right:-4px;background:#ef4444;color:#fff;border-radius:50%;width:20px;height:20px;font-size:11px;font-weight:700;display:none;align-items:center;justify-content:center", L.append(h), g.append(x, L), document.body.append(g);
839
+ const _ = (q) => {
840
+ q ? (x.style.display = "flex", requestAnimationFrame(() => {
750
841
  x.style.opacity = "1", x.style.transform = "scale(1)";
751
842
  })) : (x.style.opacity = "0", x.style.transform = "scale(.95)", setTimeout(() => {
752
- w || (x.style.display = "none");
843
+ T || (x.style.display = "none");
753
844
  }, 180));
754
845
  };
755
- j.addEventListener("click", () => {
756
- w = !w, D(w), j.textContent = w ? "✕" : "💬", j.append(C), w && (v = 0, C && (C.style.display = "none"));
757
- }), document.addEventListener("keydown", (B) => {
758
- B.key === "Escape" && w && (w = !1, D(!1), j.textContent = "💬", j.append(C));
846
+ L.addEventListener("click", () => {
847
+ T = !T, _(T), L.textContent = T ? "✕" : "💬", L.append(h), T && (I = 0, h && (h.style.display = "none"));
848
+ }), document.addEventListener("keydown", (q) => {
849
+ q.key === "Escape" && T && (T = !1, _(!1), L.textContent = "💬", L.append(h));
759
850
  });
760
851
  }
761
- const z = () => {
762
- w || (v++, C && (C.textContent = String(v), C.style.display = "flex"));
763
- }, L = () => {
852
+ const $ = () => {
853
+ T || (I++, h && (h.textContent = String(I), h.style.display = "flex"));
854
+ }, A = () => {
764
855
  try {
765
- const i = new AudioContext(), u = i.createOscillator(), x = i.createGain();
766
- u.connect(x), x.connect(i.destination), u.frequency.setValueAtTime(880, i.currentTime), u.frequency.exponentialRampToValueAtTime(440, i.currentTime + 0.15), x.gain.setValueAtTime(0.3, i.currentTime), x.gain.exponentialRampToValueAtTime(1e-3, i.currentTime + 0.3), u.start(), u.stop(i.currentTime + 0.3);
856
+ const n = new AudioContext(), p = n.createOscillator(), x = n.createGain();
857
+ p.connect(x), x.connect(n.destination), p.frequency.setValueAtTime(880, n.currentTime), p.frequency.exponentialRampToValueAtTime(440, n.currentTime + 0.15), x.gain.setValueAtTime(0.3, n.currentTime), x.gain.exponentialRampToValueAtTime(1e-3, n.currentTime + 0.3), p.start(), p.stop(n.currentTime + 0.3);
767
858
  } catch {
768
859
  }
769
- }, I = [], A = (i) => {
770
- for (; I.length; ) {
771
- const u = I.shift();
772
- h.add({ clientMsgId: u.clientMsgId, content: u.content, ts: Date.now() }), g.send({ type: "send", conversationId: i, clientMsgId: u.clientMsgId, content: u.content });
860
+ }, z = [], P = (n) => {
861
+ for (; z.length; ) {
862
+ const p = z.shift();
863
+ v.add({ clientMsgId: p.clientMsgId, content: p.content, ts: Date.now() }), k.send({ type: "send", conversationId: n, clientMsgId: p.clientMsgId, content: p.content });
773
864
  }
774
865
  };
775
- let g;
776
- const k = new we(`ocw-e2e-${t.profileId}`);
777
- let $ = !1;
778
- const y = [], E = [];
779
- let R = !1;
780
- const U = (i, u) => {
781
- k.sealText(u).then((x) => {
782
- r && g.send({ type: "send", conversationId: r, clientMsgId: i, content: x });
866
+ let k;
867
+ const m = new me(`ocw-e2e-${o.profileId}`);
868
+ let S = !1;
869
+ const B = [], D = [];
870
+ let Y = !1;
871
+ const F = (n, p) => {
872
+ m.sealText(p).then((x) => {
873
+ r && k.send({ type: "send", conversationId: r, clientMsgId: n, content: x });
783
874
  });
784
- }, te = (i, u, x) => {
785
- k.sealText(u, x).then((S) => {
786
- r && g.send({ type: "send", conversationId: r, clientMsgId: i, content: S });
875
+ }, ie = (n, p, x) => {
876
+ m.sealText(p, x).then((E) => {
877
+ r && k.send({ type: "send", conversationId: r, clientMsgId: n, content: E });
787
878
  });
788
- }, oe = () => {
789
- for (; y.length; ) {
790
- const i = y.shift();
791
- U(i.clientMsgId, i.text);
879
+ }, se = () => {
880
+ for (; B.length; ) {
881
+ const n = B.shift();
882
+ F(n.clientMsgId, n.text);
792
883
  }
793
- for (; E.length; ) {
794
- const i = E.shift();
795
- U(i.clientMsgId, i.text);
884
+ for (; D.length; ) {
885
+ const n = D.shift();
886
+ F(n.clientMsgId, n.text);
796
887
  }
797
- }, ne = (i) => {
798
- g.send({ type: "fetchPrekey", targetUserId: i });
799
- }, ie = t.i18n ?? {}, se = ["ar", "he", "fa", "ur"], re = typeof navigator < "u" ? (navigator.language ?? "").slice(0, 2).toLowerCase() : "";
800
- se.includes(re) && !t.el.dir && (t.el.dir = "rtl", t.el.style.fontFamily = t.el.style.fontFamily || "Tahoma,Arial,system-ui,sans-serif");
801
- const W = new me(), P = new Te(t.el, n, {
802
- onSend(i) {
803
- const u = `cm_${Math.random().toString(36).slice(2)}`, x = { kind: "text", text: i };
804
- a.addOptimistic(u, x), P.render(a), a.e2e ? k.ready ? U(u, i) : R ? E.push({ clientMsgId: u, text: i }) : (y.push({ clientMsgId: u, text: i }), a.assignedAgentId && ne(a.assignedAgentId)) : r ? (h.add({ clientMsgId: u, content: x, ts: Date.now() }), g.send({ type: "send", conversationId: r, clientMsgId: u, content: x })) : I.push({ clientMsgId: u, content: x });
888
+ }, ae = (n) => {
889
+ k.send({ type: "fetchPrekey", targetUserId: n });
890
+ }, re = o.i18n ?? {}, ce = ["ar", "he", "fa", "ur"], le = typeof navigator < "u" ? (navigator.language ?? "").slice(0, 2).toLowerCase() : "";
891
+ ce.includes(le) && !o.el.dir && (o.el.dir = "rtl", o.el.style.fontFamily = o.el.style.fontFamily || "Tahoma,Arial,system-ui,sans-serif");
892
+ const K = new ke(), V = `oc_prechat_${o.profileId}_${a.slice(-8)}`, j = new Ee(o.el, a, {
893
+ onSend(n) {
894
+ const p = `cm_${Math.random().toString(36).slice(2)}`, x = { kind: "text", text: n };
895
+ d.addOptimistic(p, x), j.render(d), d.e2e ? m.ready ? F(p, n) : Y ? D.push({ clientMsgId: p, text: n }) : (B.push({ clientMsgId: p, text: n }), d.assignedAgentId && ae(d.assignedAgentId)) : r ? (v.add({ clientMsgId: p, content: x, ts: Date.now() }), k.send({ type: "send", conversationId: r, clientMsgId: p, content: x })) : z.push({ clientMsgId: p, content: x });
805
896
  },
806
- async onAttach(i) {
897
+ async onAttach(n) {
807
898
  if (!r) return;
808
- const u = `${d}/upload?name=${encodeURIComponent(i.name)}`, x = `cm_${Math.random().toString(36).slice(2)}`;
809
- a.addOptimistic(x, { kind: "text", text: `📎 Uploading ${i.name}…` }), P.render(a);
899
+ const p = `${b}/upload?name=${encodeURIComponent(n.name)}`, x = `cm_${Math.random().toString(36).slice(2)}`;
900
+ d.addOptimistic(x, { kind: "text", text: `📎 Uploading ${n.name}…` }), j.render(d);
810
901
  try {
811
- const S = await fetch(u, {
902
+ const E = await fetch(p, {
812
903
  method: "POST",
813
- headers: { "content-type": i.type, ...t.token ? { authorization: `Bearer ${t.token}` } : {} },
814
- body: i
904
+ headers: { "content-type": n.type, ...o.token ? { authorization: `Bearer ${o.token}` } : {} },
905
+ body: n
815
906
  });
816
- if (!S.ok) throw new Error(`Upload failed: ${S.status}`);
817
- const { url: O, name: N, mime: j, size: D } = await S.json();
818
- g.send({ type: "send", conversationId: r, clientMsgId: x, content: { kind: "attachment", url: O, name: N, mime: j, size: D } });
819
- } catch (S) {
820
- a.addOptimistic(x, { kind: "text", text: `⚠️ Upload failed: ${S.message}` }), P.render(a);
907
+ if (!E.ok) throw new Error(`Upload failed: ${E.status}`);
908
+ const { url: O, name: N, mime: L, size: _ } = await E.json();
909
+ k.send({ type: "send", conversationId: r, clientMsgId: x, content: { kind: "attachment", url: O, name: N, mime: L, size: _ } });
910
+ } catch (E) {
911
+ d.addOptimistic(x, { kind: "text", text: `⚠️ Upload failed: ${E.message}` }), j.render(d);
821
912
  }
822
913
  },
823
- onInvoke(i, u) {
824
- r && g.send({ type: "invoke", conversationId: r, actionId: i, clientInvokeId: `iv_${Math.random().toString(36).slice(2)}`, ...u ? { inputs: u } : {} });
914
+ onInvoke(n, p) {
915
+ r && k.send({ type: "invoke", conversationId: r, actionId: n, clientInvokeId: `iv_${Math.random().toString(36).slice(2)}`, ...p ? { inputs: p } : {} });
825
916
  },
826
- onTyping(i, u) {
827
- r && g.send({ type: "typing", conversationId: r, isTyping: i, ...u ? { preview: u } : {} });
917
+ onTyping(n, p) {
918
+ r && k.send({ type: "typing", conversationId: r, isTyping: n, ...p ? { preview: p } : {} });
828
919
  },
829
- onReadUpTo(i) {
830
- r && g.send({ type: "read", conversationId: r, seq: i });
920
+ onPreChat(n) {
921
+ try {
922
+ localStorage.setItem(V, "1");
923
+ } catch {
924
+ }
925
+ k.send({
926
+ type: "open",
927
+ profileId: o.profileId,
928
+ ...o.subjectId ? { subjectId: o.subjectId } : {},
929
+ userInfo: {
930
+ ...n.name ? { name: n.name } : {},
931
+ ...n.email ? { email: n.email } : {},
932
+ ...n.phone || n.topic ? { meta: {
933
+ ...n.phone ? { phone: n.phone } : {},
934
+ ...n.topic ? { topic: n.topic } : {}
935
+ } } : {}
936
+ }
937
+ });
938
+ const p = n.callback ? `📞 Call-back requested${n.phone ? `: ${n.phone}` : ""}${n.topic ? ` — ${n.topic}` : ""}` : n.topic ? `Topic: ${n.topic}` : "";
939
+ p && r && !d.e2e && k.send({ type: "send", conversationId: r, clientMsgId: `pc_${Math.random().toString(36).slice(2, 12)}`, content: { kind: "text", text: p } });
940
+ },
941
+ onDeflectQuery(n) {
942
+ if (s) return;
943
+ clearTimeout(i);
944
+ const p = n.trim();
945
+ if (p.length < 3) {
946
+ j.hideDeflection();
947
+ return;
948
+ }
949
+ i = setTimeout(() => {
950
+ fetch(`${b}/kb/search?profileId=${encodeURIComponent(o.profileId)}&q=${encodeURIComponent(p.slice(0, 200))}`).then((x) => x.ok ? x.json() : { articles: [] }).then((x) => j.showDeflection(x.articles ?? [])).catch(() => j.hideDeflection());
951
+ }, 350);
952
+ },
953
+ onReadUpTo(n) {
954
+ r && k.send({ type: "read", conversationId: r, seq: n });
831
955
  },
832
956
  onLoadMore() {
833
- if (!r || !a.e2e) return;
834
- const i = a.messages()[0];
835
- i && g.send({ type: "history", conversationId: r, beforeSeq: i.seq, limit: 20 });
957
+ if (!r || !d.e2e) return;
958
+ const n = d.messages()[0];
959
+ n && k.send({ type: "history", conversationId: r, beforeSeq: n.seq, limit: 20 });
836
960
  },
837
- onEdit(i, u) {
838
- r && g.send({ type: "edit", conversationId: r, messageId: i, content: { kind: "text", text: u } });
961
+ onEdit(n, p) {
962
+ r && k.send({ type: "edit", conversationId: r, messageId: n, content: { kind: "text", text: p } });
839
963
  },
840
- onDelete(i) {
841
- r && g.send({ type: "delete", conversationId: r, messageId: i });
964
+ onDelete(n) {
965
+ r && k.send({ type: "delete", conversationId: r, messageId: n });
842
966
  },
843
- onReact(i, u, x) {
844
- r && g.send({ type: "react", conversationId: r, messageId: i, emoji: u, remove: x });
967
+ onReact(n, p, x) {
968
+ r && k.send({ type: "react", conversationId: r, messageId: n, emoji: p, remove: x });
845
969
  },
846
- onCsat(i) {
847
- r && fetch(`${d}/conversations/${r}/csat`, {
970
+ onCsat(n) {
971
+ r && fetch(`${b}/conversations/${r}/csat`, {
848
972
  method: "POST",
849
- headers: { "Content-Type": "application/json", Authorization: `Bearer ${n}` },
850
- body: JSON.stringify({ score: i })
973
+ headers: { "Content-Type": "application/json", Authorization: `Bearer ${a}` },
974
+ body: JSON.stringify({ score: n })
851
975
  }).catch(() => {
852
976
  });
853
977
  },
854
- onAnnotate(i) {
855
- r && g.send({ type: "annotate", conversationId: r, stroke: i });
978
+ onAnnotate(n) {
979
+ r && k.send({ type: "annotate", conversationId: r, stroke: n });
856
980
  },
857
981
  onAnnotateClear() {
858
- r && g.send({ type: "annotate_clear", conversationId: r });
982
+ r && k.send({ type: "annotate_clear", conversationId: r });
859
983
  },
860
- ...t.translateLang ? {
861
- async onTranslate(i) {
984
+ ...o.translateLang ? {
985
+ async onTranslate(n) {
862
986
  try {
863
- const u = await fetch(`${d}/translate`, {
987
+ const p = await fetch(`${b}/translate`, {
864
988
  method: "POST",
865
- headers: { "content-type": "application/json", authorization: `Bearer ${n}` },
866
- body: JSON.stringify({ text: i, targetLang: t.translateLang })
989
+ headers: { "content-type": "application/json", authorization: `Bearer ${a}` },
990
+ body: JSON.stringify({ text: n, targetLang: o.translateLang })
867
991
  });
868
- if (!u.ok) return null;
869
- const { translated: x } = await u.json();
992
+ if (!p.ok) return null;
993
+ const { translated: x } = await p.json();
870
994
  return x;
871
995
  } catch {
872
996
  return null;
@@ -874,97 +998,105 @@ function Le(t) {
874
998
  }
875
999
  } : {}
876
1000
  }, {
877
- ...t.subject ? { subject: t.subject } : {},
878
- ...t.quickReplies ? { quickReplies: t.quickReplies } : {},
879
- ...t.accent ? { accent: t.accent } : {},
880
- ...(Y = t.user) != null && Y.name || (X = t.user) != null && X.avatar ? { userInfo: { ...t.user.name ? { name: t.user.name } : {}, ...t.user.avatar ? { avatar: t.user.avatar } : {} } } : {},
881
- i18n: ie
882
- }), K = t.user && (t.user.name || t.user.email || t.user.avatar || t.user.meta) ? {
883
- ...t.user.name ? { name: t.user.name } : {},
884
- ...t.user.email ? { email: t.user.email } : {},
885
- ...t.user.avatar ? { avatar: t.user.avatar } : {},
886
- ...t.user.meta ? { meta: t.user.meta } : {}
887
- } : void 0, ae = {
1001
+ ...o.subject ? { subject: o.subject } : {},
1002
+ ...o.quickReplies ? { quickReplies: o.quickReplies } : {},
1003
+ ...o.accent ? { accent: o.accent } : {},
1004
+ ...(Q = o.user) != null && Q.name || (G = o.user) != null && G.avatar ? { userInfo: { ...o.user.name ? { name: o.user.name } : {}, ...o.user.avatar ? { avatar: o.user.avatar } : {} } } : {},
1005
+ i18n: re
1006
+ });
1007
+ try {
1008
+ localStorage.getItem(V) && j.completePreChat();
1009
+ } catch {
1010
+ }
1011
+ const X = o.user && (o.user.name || o.user.email || o.user.avatar || o.user.meta) ? {
1012
+ ...o.user.name ? { name: o.user.name } : {},
1013
+ ...o.user.email ? { email: o.user.email } : {},
1014
+ ...o.user.avatar ? { avatar: o.user.avatar } : {},
1015
+ ...o.user.meta ? { meta: o.user.meta } : {}
1016
+ } : void 0, de = {
888
1017
  type: "open",
889
- profileId: t.profileId,
890
- ...t.subjectId ? { subjectId: t.subjectId } : {},
891
- ...s ? { linkFrom: s } : {},
892
- ...K ? { userInfo: K } : {},
1018
+ profileId: o.profileId,
1019
+ // Direct conversations use the kind/peerId pair; the dm:… subject key is
1020
+ // server-derived and owner-keyed, so passing it as subjectId from the
1021
+ // NON-owner side would find-or-create a junk duplicate thread.
1022
+ ...o.kind === "direct" && o.peerId ? { kind: "direct", peerId: o.peerId } : o.subjectId ? { subjectId: o.subjectId } : {},
1023
+ ...c ? { linkFrom: c } : {},
1024
+ ...X ? { userInfo: X } : {},
893
1025
  ...typeof location < "u" ? { pageUrl: location.href } : {},
894
1026
  ...typeof document < "u" && document.title ? { pageTitle: document.title } : {},
895
1027
  // Pass subject display info so the server can persist it to the Subject record.
896
1028
  // This is how listingTitle and listingMeta get saved without a separate API call.
897
- ...(J = t.subject) != null && J.title ? { subjectTitle: t.subject.title } : {},
898
- ...(G = t.subject) != null && G.subtitle ? { subjectMeta: t.subject.subtitle } : {}
1029
+ ...(Z = o.subject) != null && Z.title ? { subjectTitle: o.subject.title } : {},
1030
+ ...(ee = o.subject) != null && ee.subtitle ? { subjectMeta: o.subject.subtitle } : {}
899
1031
  };
900
- g = new be({
901
- ...t.refreshToken ? { refreshToken: t.refreshToken } : {},
902
- url: p,
903
- token: n,
904
- open: ae,
905
- getCursor: () => a.highestSeq(),
906
- onStatusChange: (i, u) => P.setConnStatus(i, u),
907
- onFrame(i) {
908
- if (W.apply(i), i.type === "opened") {
909
- if (r = i.conversation.id, !T) {
910
- T = !0;
911
- for (const u of h.load())
912
- g.send({ type: "send", conversationId: r, clientMsgId: u.clientMsgId, content: u.content });
1032
+ k = new ge({
1033
+ ...o.refreshToken ? { refreshToken: o.refreshToken } : {},
1034
+ url: f,
1035
+ token: a,
1036
+ open: de,
1037
+ getCursor: () => d.highestSeq(),
1038
+ onStatusChange: (n, p) => j.setConnStatus(n, p),
1039
+ onFrame(n) {
1040
+ if (K.apply(n), n.type === "opened") {
1041
+ if (r = n.conversation.id, !u) {
1042
+ u = !0;
1043
+ for (const p of v.load())
1044
+ k.send({ type: "send", conversationId: r, clientMsgId: p.clientMsgId, content: p.content });
913
1045
  }
914
- ue(p, n, r, a, P, d), I.length && A(r);
1046
+ we(f, a, r, d, j, b), z.length && P(r);
915
1047
  }
916
- if (i.type === "ack" && h.remove(i.clientMsgId), i.type === "prekeyBundle") {
917
- i.bundle && (R = !0, k.x3dhSendTo(i.bundle).then((u) => {
918
- const x = [...y.splice(0), ...E.splice(0)];
919
- for (const S of x) te(S.clientMsgId, S.text, u);
920
- P.render(a);
1048
+ if (n.type === "ack" && v.remove(n.clientMsgId), n.type === "prekeyBundle") {
1049
+ n.bundle && (Y = !0, m.x3dhSendTo(n.bundle).then((p) => {
1050
+ const x = [...B.splice(0), ...D.splice(0)];
1051
+ for (const E of x) ie(E.clientMsgId, E.text, p);
1052
+ j.render(d);
921
1053
  }));
922
1054
  return;
923
1055
  }
924
- if (i.type === "message" && a.e2e) {
925
- const u = xe(i.message.content);
926
- if (u && !k.ready) {
927
- k.x3dhReceiveFrom(u.x3dhIK, u.x3dhEK, u.x3dhSPK).then(async () => {
928
- await k.openFrame(i), a.apply(i), P.render(a);
1056
+ if (n.type === "message" && d.e2e) {
1057
+ const p = ye(n.message.content);
1058
+ if (p && !m.ready) {
1059
+ m.x3dhReceiveFrom(p.x3dhIK, p.x3dhEK, p.x3dhSPK).then(async () => {
1060
+ await m.openFrame(n), d.apply(n), j.render(d);
929
1061
  });
930
1062
  return;
931
1063
  }
932
1064
  }
933
- if (i.type === "peerkey") {
934
- k.onPeerKey(i.key).then(() => {
935
- oe(), P.render(a);
1065
+ if (n.type === "peerkey") {
1066
+ m.onPeerKey(n.key).then(() => {
1067
+ se(), j.render(d);
936
1068
  });
937
1069
  return;
938
1070
  }
939
1071
  (async () => {
940
- if (a.e2e && await k.openFrame(i), a.apply(i), i.type === "message" && i.message.senderId !== n && !i.message.internal && (z(), L()), a.e2e && r && !$) {
941
- $ = !0;
942
- const u = await k.initX3DH();
943
- g.send({ type: "uploadPrekeys", ...u });
944
- const x = await k.begin();
945
- g.send({ type: "pubkey", conversationId: r, key: x });
1072
+ if (d.e2e && await m.openFrame(n), d.apply(n), n.type === "message" && n.message.senderId !== a && !n.message.internal && ($(), A()), d.e2e && r && !S) {
1073
+ S = !0;
1074
+ const p = await m.initX3DH();
1075
+ k.send({ type: "uploadPrekeys", ...p });
1076
+ const x = await m.begin();
1077
+ k.send({ type: "pubkey", conversationId: r, key: x });
946
1078
  }
947
- P.render(a);
1079
+ j.render(d);
948
1080
  })();
949
1081
  }
950
- }), g.connect(), P.render(a);
951
- const q = t.launcher ? ee(t) : null, H = { close: () => {
952
- g.close(), c == null || c.remove(), P.destroy(), W.destroy(), b && l && b.removeEventListener("change", l), M.delete(t.el), q && F.get(q) === H && F.delete(q);
1082
+ }), k.connect(), j.render(d);
1083
+ const M = o.launcher ? ne(o) : null, H = { close: () => {
1084
+ s = !0, clearTimeout(i), k.close(), g == null || g.remove(), j.destroy(), K.destroy(), l && C && l.removeEventListener("change", C), R.delete(o.el), M && U.get(M) === H && U.delete(M);
953
1085
  } };
954
- return M.set(t.el, H), q && F.set(q, H), H;
1086
+ return R.set(o.el, H), M && U.set(M, H), H;
955
1087
  }
956
1088
  export {
957
- he as ChatStore,
958
- be as ConnectionManager,
959
- we as E2ESession,
960
- fe as PersistentOutbox,
961
- Te as Renderer,
962
- Me as asConversationId,
963
- xe as extractX3DHInit,
964
- $e as httpBaseFromWsUrl,
965
- Le as mount,
966
- pe as resolveRelayUrls,
967
- ue as restoreHistory,
968
- je as unmount
1089
+ xe as ChatStore,
1090
+ ge as ConnectionManager,
1091
+ me as E2ESession,
1092
+ be as PersistentOutbox,
1093
+ Ee as Renderer,
1094
+ He as asConversationId,
1095
+ ye as extractX3DHInit,
1096
+ Me as httpBaseFromWsUrl,
1097
+ Be as mount,
1098
+ ue as resolveRelayUrls,
1099
+ we as restoreHistory,
1100
+ Ae as unmount
969
1101
  };
970
1102
  //# sourceMappingURL=index.js.map