@paramms/chat-widget 1.6.3 → 1.9.0

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/chatlist2.js CHANGED
@@ -1,42 +1,42 @@
1
- var Ue = Object.defineProperty;
2
- var ve = (n, e, t) => e in n ? Ue(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
- var a = (n, e, t) => ve(n, typeof e != "symbol" ? e + "" : e, t);
4
- function de(n, e) {
1
+ var ve = Object.defineProperty;
2
+ var Ue = (s, e, t) => e in s ? ve(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
+ var a = (s, e, t) => Ue(s, typeof e != "symbol" ? e + "" : e, t);
4
+ function de(s, e) {
5
5
  var d;
6
- const t = n.trim().replace(/\/+$/, ""), i = (d = t.match(/^(https|http|wss|ws):\/\//)) == null ? void 0 : d[1], s = i ? i === "https" || i === "wss" : !0, r = (i ? t.slice(i.length + 3) : t).replace(/\/ws$/, ""), o = e ? e.trim().replace(/\/+$/, "") : `${s ? "https" : "http"}://${r}`;
7
- return { wsUrl: `${s ? "wss" : "ws"}://${r}/ws`, httpBase: o };
6
+ const t = s.trim().replace(/\/+$/, ""), i = (d = t.match(/^(https|http|wss|ws):\/\//)) == null ? void 0 : d[1], n = i ? i === "https" || i === "wss" : !0, r = (i ? t.slice(i.length + 3) : t).replace(/\/ws$/, ""), o = e ? e.trim().replace(/\/+$/, "") : `${n ? "https" : "http"}://${r}`;
7
+ return { wsUrl: `${n ? "wss" : "ws"}://${r}/ws`, httpBase: o };
8
8
  }
9
- function Se(n) {
10
- return de(n).httpBase;
9
+ function Se(s) {
10
+ return de(s).httpBase;
11
11
  }
12
- function be(n, e, t, i) {
13
- const s = `beforeSeq=${t}&limit=${i}`;
12
+ function be(s, e, t, i) {
13
+ const n = `beforeSeq=${t}&limit=${i}`;
14
14
  return [
15
- `${n}/conversations/${e}/messages?${s}`,
16
- `${n}/conversations/${e}/history?${s}`
15
+ `${s}/conversations/${e}/messages?${n}`,
16
+ `${s}/conversations/${e}/history?${n}`
17
17
  ];
18
18
  }
19
- async function ae(n, e, t, i, s = 20) {
19
+ async function ae(s, e, t, i, n = 20) {
20
20
  let r, o = !1;
21
- for (const h of be(n, e, i, s))
21
+ for (const l of be(s, e, i, n))
22
22
  try {
23
- const d = await fetch(h, { headers: { authorization: `Bearer ${t}` } });
23
+ const d = await fetch(l, { headers: { authorization: `Bearer ${t}` } });
24
24
  if (o = !0, !d.ok) continue;
25
- const U = await d.json();
26
- return { messages: U.messages ?? [], hasMore: U.hasMore ?? !1 };
25
+ const v = await d.json();
26
+ return { messages: v.messages ?? [], hasMore: v.hasMore ?? !1 };
27
27
  } catch (d) {
28
28
  r = d;
29
29
  }
30
- return o ? console.error(`[chat-widget] history request to ${n} was rejected for conversation ${e}.`) : console.error(
31
- `[chat-widget] could not load history from ${n} — the request never reached the server. This is almost always CORS: add this site's origin to the chatroom's allowed origins (dashboard → chatroom → allowed origins) or to the server's CORS_ORIGINS.`,
30
+ return o ? console.error(`[chat-widget] history request to ${s} was rejected for conversation ${e}.`) : console.error(
31
+ `[chat-widget] could not load history from ${s} — the request never reached the server. This is almost always CORS: add this site's origin to the chatroom's allowed origins (dashboard → chatroom → allowed origins) or to the server's CORS_ORIGINS.`,
32
32
  r
33
33
  ), null;
34
34
  }
35
- async function yt(n, e, t, i, s, r) {
36
- const o = r ? r.replace(/\/+$/, "") : Se(n), h = await ae(o, t, e, Number.MAX_SAFE_INTEGER);
37
- if (!h || (h.messages.length ? (i.apply({ type: "sync", conversationId: t, messages: h.messages }), i.apply({ type: "history", conversationId: t, messages: [], hasMore: h.hasMore }), s.render(i)) : i.apply({ type: "history", conversationId: t, messages: [], hasMore: !1 }), !h.hasMore)) return;
35
+ async function bt(s, e, t, i, n, r) {
36
+ const o = r ? r.replace(/\/+$/, "") : Se(s), l = await ae(o, t, e, Number.MAX_SAFE_INTEGER);
37
+ if (!l || (l.messages.length ? (i.apply({ type: "sync", conversationId: t, messages: l.messages }), i.apply({ type: "history", conversationId: t, messages: [], hasMore: l.hasMore }), n.render(i)) : i.apply({ type: "history", conversationId: t, messages: [], hasMore: !1 }), !l.hasMore)) return;
38
38
  let d = !1;
39
- const U = async () => {
39
+ const v = async () => {
40
40
  if (d || !i.hasMoreHistory) return;
41
41
  d = !0;
42
42
  const I = i.messages()[0];
@@ -44,18 +44,18 @@ async function yt(n, e, t, i, s, r) {
44
44
  d = !1;
45
45
  return;
46
46
  }
47
- const v = await ae(o, t, e, I.seq);
48
- v && (i.apply({ type: "history", conversationId: t, messages: v.messages, hasMore: v.hasMore }), s.render(i)), d = !1;
49
- }, b = s.getScrollEl();
47
+ const U = await ae(o, t, e, I.seq);
48
+ U && (i.apply({ type: "history", conversationId: t, messages: U.messages, hasMore: U.hasMore }), n.render(i)), d = !1;
49
+ }, b = n.getScrollEl();
50
50
  if (!b) return;
51
51
  let x = !1;
52
52
  setTimeout(() => {
53
53
  x = !0;
54
54
  }, 300);
55
55
  const g = () => {
56
- x && b.scrollTop < 80 && i.hasMoreHistory && !d && U();
56
+ x && b.scrollTop < 80 && i.hasMoreHistory && !d && v();
57
57
  };
58
- b.addEventListener("scroll", g, { passive: !0 }), s.setScrollCleanup(() => b.removeEventListener("scroll", g));
58
+ b.addEventListener("scroll", g, { passive: !0 }), n.setScrollCleanup(() => b.removeEventListener("scroll", g));
59
59
  }
60
60
  const Ee = {
61
61
  accent: "#6c5ce7",
@@ -82,16 +82,16 @@ const Ee = {
82
82
  rowhover: "#39325e",
83
83
  shadow: "0 12px 32px rgba(0,0,0,.4)"
84
84
  }, Ie = "'Nunito',-apple-system,BlinkMacSystemFont,'Segoe UI',system-ui,sans-serif";
85
- function fe(n, e) {
86
- return Object.entries(e).map(([t, i]) => `--${n}-${t}:${i};`).join(" ");
85
+ function fe(s, e) {
86
+ return Object.entries(e).map(([t, i]) => `--${s}-${t}:${i};`).join(" ");
87
87
  }
88
- function ke(n) {
89
- return `${fe(n, Ee)} --${n}-fb:${Ie}; --${n}-fh:'Baloo 2',var(--${n}-fb);`;
88
+ function ke(s) {
89
+ return `${fe(s, Ee)} --${s}-fb:${Ie}; --${s}-fh:'Baloo 2',var(--${s}-fb);`;
90
90
  }
91
- function ce(n) {
92
- return fe(n, Be);
91
+ function ce(s) {
92
+ return fe(s, Be);
93
93
  }
94
- const Te = `
94
+ const Ae = `
95
95
  .ocl { ${ke("ocl")}
96
96
  display:flex; flex-direction:column; height:100%; background:var(--ocl-bg);
97
97
  font-family:var(--ocl-fb); color:var(--ocl-ink); overflow:hidden; }
@@ -139,53 +139,105 @@ const Te = `
139
139
  .ocl-compact .ocl-search { font-size:16px; }
140
140
  .ocl-compact .ocl-compose { width:36px; height:36px; }
141
141
  .ocl-row:focus-visible, .ocl button:focus-visible, .ocl input:focus-visible { outline:2px solid var(--ocl-accent); outline-offset:2px; border-radius:12px; }
142
- `, _ = "oc_uid";
143
- function Ae(n) {
142
+ `, Te = {
143
+ placeholder: "Message…",
144
+ offline: "We're offline right now",
145
+ online: "Online",
146
+ away: "Away",
147
+ aiAssistant: "AI Assistant",
148
+ resolved: "Marked as resolved",
149
+ reopen: "Reopen conversation",
150
+ sources: "Sources",
151
+ helpful: "Helpful",
152
+ notHelpful: "Not helpful",
153
+ title: "Your conversations",
154
+ newChat: "New conversation",
155
+ startChat: "Start a conversation",
156
+ all: "All conversations",
157
+ empty: "No conversations yet.",
158
+ error: "Could not load conversations.",
159
+ retry: "Retry",
160
+ search: "🔍 Search",
161
+ unread: "Unread",
162
+ close: "Close"
163
+ }, Ce = {
164
+ placeholder: "메시지…",
165
+ offline: "지금은 오프라인입니다",
166
+ online: "온라인",
167
+ away: "자리 비움",
168
+ aiAssistant: "AI 어시스턴트",
169
+ resolved: "해결됨으로 표시됨",
170
+ reopen: "대화 다시 열기",
171
+ sources: "출처",
172
+ helpful: "도움돼요",
173
+ notHelpful: "도움 안돼요",
174
+ title: "내 대화",
175
+ newChat: "새 대화",
176
+ startChat: "대화 시작하기",
177
+ all: "전체 대화",
178
+ empty: "아직 대화가 없습니다.",
179
+ error: "대화를 불러오지 못했습니다.",
180
+ retry: "다시 시도",
181
+ search: "🔍 검색",
182
+ unread: "읽지 않음",
183
+ close: "닫기"
184
+ }, $e = { en: Te, ko: Ce };
185
+ function ze(s) {
186
+ const e = (s ?? (typeof navigator < "u" ? navigator.language : "") ?? "").toLowerCase();
187
+ return e.startsWith("ko") || e.includes("korean") || e.includes("한국") ? "ko" : "en";
188
+ }
189
+ function Le(s, e) {
190
+ const t = $e[ze(s)], i = {};
191
+ for (const [n, r] of Object.entries(e ?? {})) typeof r == "string" && r !== "" && (i[n] = r);
192
+ return { ...t, ...i };
193
+ }
194
+ const R = "oc_uid";
195
+ function Me(s) {
144
196
  try {
145
- const e = document.cookie.match(new RegExp(`(?:^|; )${n}=([^;]*)`));
197
+ const e = document.cookie.match(new RegExp(`(?:^|; )${s}=([^;]*)`));
146
198
  return e ? decodeURIComponent(e[1]) : null;
147
199
  } catch {
148
200
  return null;
149
201
  }
150
202
  }
151
- function $e(n, e) {
203
+ function De(s, e) {
152
204
  try {
153
205
  const i = location.protocol === "https:" ? "; Secure" : "";
154
- document.cookie = `${n}=${encodeURIComponent(e)}; Max-Age=31536000; Path=/; SameSite=Lax${i}`;
206
+ document.cookie = `${s}=${encodeURIComponent(e)}; Max-Age=31536000; Path=/; SameSite=Lax${i}`;
155
207
  } catch {
156
208
  }
157
209
  }
158
- function ze() {
210
+ function Re() {
159
211
  return `g_${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`;
160
212
  }
161
- function Ce() {
162
- let n = null;
213
+ function _e() {
214
+ let s = null;
163
215
  try {
164
- n = localStorage.getItem(_);
216
+ s = localStorage.getItem(R);
165
217
  } catch {
166
218
  }
167
- n || (n = Ae(_));
168
- const e = n ?? ze();
219
+ s || (s = Me(R));
220
+ const e = s ?? Re();
169
221
  try {
170
- localStorage.setItem(_, e);
222
+ localStorage.setItem(R, e);
171
223
  } catch {
172
224
  }
173
- return $e(_, e), e;
225
+ return De(R, e), e;
174
226
  }
175
- function Le(n) {
176
- const e = n.length;
227
+ function Fe(s) {
228
+ const e = s.length;
177
229
  let t = 0, i = 0;
178
230
  for (; i < e; ) {
179
- let s = n.charCodeAt(i++);
180
- if (s & 4294967168)
181
- if (!(s & 4294965248))
231
+ let n = s.charCodeAt(i++);
232
+ if (n & 4294967168)
233
+ if (!(n & 4294965248))
182
234
  t += 2;
183
235
  else {
184
- if (s >= 55296 && s <= 56319 && i < e) {
185
- const r = n.charCodeAt(i);
186
- (r & 64512) === 56320 && (++i, s = ((s & 1023) << 10) + (r & 1023) + 65536);
236
+ if (n >= 55296 && n <= 56319 && i < e) {
237
+ const r = s.charCodeAt(i);
238
+ (r & 64512) === 56320 && (++i, n = ((n & 1023) << 10) + (r & 1023) + 65536);
187
239
  }
188
- s & 4294901760 ? t += 4 : t += 3;
240
+ n & 4294901760 ? t += 4 : t += 3;
189
241
  }
190
242
  else {
191
243
  t++;
@@ -194,69 +246,69 @@ function Le(n) {
194
246
  }
195
247
  return t;
196
248
  }
197
- function Me(n, e, t) {
198
- const i = n.length;
199
- let s = t, r = 0;
249
+ function Pe(s, e, t) {
250
+ const i = s.length;
251
+ let n = t, r = 0;
200
252
  for (; r < i; ) {
201
- let o = n.charCodeAt(r++);
253
+ let o = s.charCodeAt(r++);
202
254
  if (o & 4294967168)
203
255
  if (!(o & 4294965248))
204
- e[s++] = o >> 6 & 31 | 192;
256
+ e[n++] = o >> 6 & 31 | 192;
205
257
  else {
206
258
  if (o >= 55296 && o <= 56319 && r < i) {
207
- const h = n.charCodeAt(r);
208
- (h & 64512) === 56320 && (++r, o = ((o & 1023) << 10) + (h & 1023) + 65536);
259
+ const l = s.charCodeAt(r);
260
+ (l & 64512) === 56320 && (++r, o = ((o & 1023) << 10) + (l & 1023) + 65536);
209
261
  }
210
- o & 4294901760 ? (e[s++] = o >> 18 & 7 | 240, e[s++] = o >> 12 & 63 | 128, e[s++] = o >> 6 & 63 | 128) : (e[s++] = o >> 12 & 15 | 224, e[s++] = o >> 6 & 63 | 128);
262
+ o & 4294901760 ? (e[n++] = o >> 18 & 7 | 240, e[n++] = o >> 12 & 63 | 128, e[n++] = o >> 6 & 63 | 128) : (e[n++] = o >> 12 & 15 | 224, e[n++] = o >> 6 & 63 | 128);
211
263
  }
212
264
  else {
213
- e[s++] = o;
265
+ e[n++] = o;
214
266
  continue;
215
267
  }
216
- e[s++] = o & 63 | 128;
268
+ e[n++] = o & 63 | 128;
217
269
  }
218
270
  }
219
- const De = new TextEncoder(), _e = 50;
220
- function Re(n, e, t) {
221
- De.encodeInto(n, e.subarray(t));
271
+ const Ne = new TextEncoder(), He = 50;
272
+ function Ke(s, e, t) {
273
+ Ne.encodeInto(s, e.subarray(t));
222
274
  }
223
- function Fe(n, e, t) {
224
- n.length > _e ? Re(n, e, t) : Me(n, e, t);
275
+ function We(s, e, t) {
276
+ s.length > He ? Ke(s, e, t) : Pe(s, e, t);
225
277
  }
226
- const Pe = 4096;
227
- function ue(n, e, t) {
278
+ const Oe = 4096;
279
+ function ue(s, e, t) {
228
280
  let i = e;
229
- const s = i + t, r = [];
281
+ const n = i + t, r = [];
230
282
  let o = "";
231
- for (; i < s; ) {
232
- const h = n[i++];
233
- if (!(h & 128))
234
- r.push(h);
235
- else if ((h & 224) === 192) {
236
- const d = n[i++] & 63;
237
- r.push((h & 31) << 6 | d);
238
- } else if ((h & 240) === 224) {
239
- const d = n[i++] & 63, U = n[i++] & 63;
240
- r.push((h & 31) << 12 | d << 6 | U);
241
- } else if ((h & 248) === 240) {
242
- const d = n[i++] & 63, U = n[i++] & 63, b = n[i++] & 63;
243
- let x = (h & 7) << 18 | d << 12 | U << 6 | b;
283
+ for (; i < n; ) {
284
+ const l = s[i++];
285
+ if (!(l & 128))
286
+ r.push(l);
287
+ else if ((l & 224) === 192) {
288
+ const d = s[i++] & 63;
289
+ r.push((l & 31) << 6 | d);
290
+ } else if ((l & 240) === 224) {
291
+ const d = s[i++] & 63, v = s[i++] & 63;
292
+ r.push((l & 31) << 12 | d << 6 | v);
293
+ } else if ((l & 248) === 240) {
294
+ const d = s[i++] & 63, v = s[i++] & 63, b = s[i++] & 63;
295
+ let x = (l & 7) << 18 | d << 12 | v << 6 | b;
244
296
  x > 65535 && (x -= 65536, r.push(x >>> 10 & 1023 | 55296), x = 56320 | x & 1023), r.push(x);
245
297
  } else
246
- r.push(h);
247
- r.length >= Pe && (o += String.fromCharCode(...r), r.length = 0);
298
+ r.push(l);
299
+ r.length >= Oe && (o += String.fromCharCode(...r), r.length = 0);
248
300
  }
249
301
  return r.length > 0 && (o += String.fromCharCode(...r)), o;
250
302
  }
251
- const Ne = new TextDecoder(), He = 200;
252
- function Ke(n, e, t) {
253
- const i = n.subarray(e, e + t);
254
- return Ne.decode(i);
303
+ const Ve = new TextDecoder(), Ye = 200;
304
+ function qe(s, e, t) {
305
+ const i = s.subarray(e, e + t);
306
+ return Ve.decode(i);
255
307
  }
256
- function We(n, e, t) {
257
- return t > He ? Ke(n, e, t) : ue(n, e, t);
308
+ function Xe(s, e, t) {
309
+ return t > Ye ? qe(s, e, t) : ue(s, e, t);
258
310
  }
259
- class R {
311
+ class _ {
260
312
  constructor(e, t) {
261
313
  a(this, "type");
262
314
  a(this, "data");
@@ -274,77 +326,77 @@ class y extends Error {
274
326
  });
275
327
  }
276
328
  }
277
- const z = 4294967295;
278
- function Oe(n, e, t) {
279
- const i = t / 4294967296, s = t;
280
- n.setUint32(e, i), n.setUint32(e + 4, s);
329
+ const $ = 4294967295;
330
+ function Ge(s, e, t) {
331
+ const i = t / 4294967296, n = t;
332
+ s.setUint32(e, i), s.setUint32(e + 4, n);
281
333
  }
282
- function xe(n, e, t) {
283
- const i = Math.floor(t / 4294967296), s = t;
284
- n.setUint32(e, i), n.setUint32(e + 4, s);
334
+ function xe(s, e, t) {
335
+ const i = Math.floor(t / 4294967296), n = t;
336
+ s.setUint32(e, i), s.setUint32(e + 4, n);
285
337
  }
286
- function pe(n, e) {
287
- const t = n.getInt32(e), i = n.getUint32(e + 4);
338
+ function pe(s, e) {
339
+ const t = s.getInt32(e), i = s.getUint32(e + 4);
288
340
  return t * 4294967296 + i;
289
341
  }
290
- function Ve(n, e) {
291
- const t = n.getUint32(e), i = n.getUint32(e + 4);
342
+ function Je(s, e) {
343
+ const t = s.getUint32(e), i = s.getUint32(e + 4);
292
344
  return t * 4294967296 + i;
293
345
  }
294
- const Ye = -1, qe = 4294967296 - 1, Xe = 17179869184 - 1;
295
- function Ge({ sec: n, nsec: e }) {
296
- if (n >= 0 && e >= 0 && n <= Xe)
297
- if (e === 0 && n <= qe) {
346
+ const Ze = -1, Qe = 4294967296 - 1, je = 17179869184 - 1;
347
+ function et({ sec: s, nsec: e }) {
348
+ if (s >= 0 && e >= 0 && s <= je)
349
+ if (e === 0 && s <= Qe) {
298
350
  const t = new Uint8Array(4);
299
- return new DataView(t.buffer).setUint32(0, n), t;
351
+ return new DataView(t.buffer).setUint32(0, s), t;
300
352
  } else {
301
- const t = n / 4294967296, i = n & 4294967295, s = new Uint8Array(8), r = new DataView(s.buffer);
302
- return r.setUint32(0, e << 2 | t & 3), r.setUint32(4, i), s;
353
+ const t = s / 4294967296, i = s & 4294967295, n = new Uint8Array(8), r = new DataView(n.buffer);
354
+ return r.setUint32(0, e << 2 | t & 3), r.setUint32(4, i), n;
303
355
  }
304
356
  else {
305
357
  const t = new Uint8Array(12), i = new DataView(t.buffer);
306
- return i.setUint32(0, e), xe(i, 4, n), t;
358
+ return i.setUint32(0, e), xe(i, 4, s), t;
307
359
  }
308
360
  }
309
- function Je(n) {
310
- const e = n.getTime(), t = Math.floor(e / 1e3), i = (e - t * 1e3) * 1e6, s = Math.floor(i / 1e9);
361
+ function tt(s) {
362
+ const e = s.getTime(), t = Math.floor(e / 1e3), i = (e - t * 1e3) * 1e6, n = Math.floor(i / 1e9);
311
363
  return {
312
- sec: t + s,
313
- nsec: i - s * 1e9
364
+ sec: t + n,
365
+ nsec: i - n * 1e9
314
366
  };
315
367
  }
316
- function Ze(n) {
317
- if (n instanceof Date) {
318
- const e = Je(n);
319
- return Ge(e);
368
+ function st(s) {
369
+ if (s instanceof Date) {
370
+ const e = tt(s);
371
+ return et(e);
320
372
  } else
321
373
  return null;
322
374
  }
323
- function Qe(n) {
324
- const e = new DataView(n.buffer, n.byteOffset, n.byteLength);
325
- switch (n.byteLength) {
375
+ function it(s) {
376
+ const e = new DataView(s.buffer, s.byteOffset, s.byteLength);
377
+ switch (s.byteLength) {
326
378
  case 4:
327
379
  return { sec: e.getUint32(0), nsec: 0 };
328
380
  case 8: {
329
- const t = e.getUint32(0), i = e.getUint32(4), s = (t & 3) * 4294967296 + i, r = t >>> 2;
330
- return { sec: s, nsec: r };
381
+ const t = e.getUint32(0), i = e.getUint32(4), n = (t & 3) * 4294967296 + i, r = t >>> 2;
382
+ return { sec: n, nsec: r };
331
383
  }
332
384
  case 12: {
333
385
  const t = pe(e, 4), i = e.getUint32(0);
334
386
  return { sec: t, nsec: i };
335
387
  }
336
388
  default:
337
- throw new y(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${n.length}`);
389
+ throw new y(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${s.length}`);
338
390
  }
339
391
  }
340
- function je(n) {
341
- const e = Qe(n);
392
+ function nt(s) {
393
+ const e = it(s);
342
394
  return new Date(e.sec * 1e3 + e.nsec / 1e6);
343
395
  }
344
- const et = {
345
- type: Ye,
346
- encode: Ze,
347
- decode: je
396
+ const rt = {
397
+ type: Ze,
398
+ encode: st,
399
+ decode: nt
348
400
  }, P = class P {
349
401
  constructor() {
350
402
  // ensures ExtensionCodecType<X> matches ExtensionCodec<X>
@@ -357,53 +409,53 @@ const et = {
357
409
  // custom extensions
358
410
  a(this, "encoders", []);
359
411
  a(this, "decoders", []);
360
- this.register(et);
412
+ this.register(rt);
361
413
  }
362
414
  register({ type: e, encode: t, decode: i }) {
363
415
  if (e >= 0)
364
416
  this.encoders[e] = t, this.decoders[e] = i;
365
417
  else {
366
- const s = -1 - e;
367
- this.builtInEncoders[s] = t, this.builtInDecoders[s] = i;
418
+ const n = -1 - e;
419
+ this.builtInEncoders[n] = t, this.builtInDecoders[n] = i;
368
420
  }
369
421
  }
370
422
  tryToEncode(e, t) {
371
423
  for (let i = 0; i < this.builtInEncoders.length; i++) {
372
- const s = this.builtInEncoders[i];
373
- if (s != null) {
374
- const r = s(e, t);
424
+ const n = this.builtInEncoders[i];
425
+ if (n != null) {
426
+ const r = n(e, t);
375
427
  if (r != null) {
376
428
  const o = -1 - i;
377
- return new R(o, r);
429
+ return new _(o, r);
378
430
  }
379
431
  }
380
432
  }
381
433
  for (let i = 0; i < this.encoders.length; i++) {
382
- const s = this.encoders[i];
383
- if (s != null) {
384
- const r = s(e, t);
434
+ const n = this.encoders[i];
435
+ if (n != null) {
436
+ const r = n(e, t);
385
437
  if (r != null) {
386
438
  const o = i;
387
- return new R(o, r);
439
+ return new _(o, r);
388
440
  }
389
441
  }
390
442
  }
391
- return e instanceof R ? e : null;
443
+ return e instanceof _ ? e : null;
392
444
  }
393
445
  decode(e, t, i) {
394
- const s = t < 0 ? this.builtInDecoders[-1 - t] : this.decoders[t];
395
- return s ? s(e, t, i) : new R(t, e);
446
+ const n = t < 0 ? this.builtInDecoders[-1 - t] : this.decoders[t];
447
+ return n ? n(e, t, i) : new _(t, e);
396
448
  }
397
449
  };
398
450
  a(P, "defaultCodec", new P());
399
451
  let F = P;
400
- function tt(n) {
401
- return n instanceof ArrayBuffer || typeof SharedArrayBuffer < "u" && n instanceof SharedArrayBuffer;
452
+ function ot(s) {
453
+ return s instanceof ArrayBuffer || typeof SharedArrayBuffer < "u" && s instanceof SharedArrayBuffer;
402
454
  }
403
- function W(n) {
404
- return n instanceof Uint8Array ? n : ArrayBuffer.isView(n) ? new Uint8Array(n.buffer, n.byteOffset, n.byteLength) : tt(n) ? new Uint8Array(n) : Uint8Array.from(n);
455
+ function W(s) {
456
+ return s instanceof Uint8Array ? s : ArrayBuffer.isView(s) ? new Uint8Array(s.buffer, s.byteOffset, s.byteLength) : ot(s) ? new Uint8Array(s) : Uint8Array.from(s);
405
457
  }
406
- const it = 100, st = 2048;
458
+ const at = 100, ct = 2048;
407
459
  class V {
408
460
  constructor(e) {
409
461
  a(this, "extensionCodec");
@@ -419,7 +471,7 @@ class V {
419
471
  a(this, "view");
420
472
  a(this, "bytes");
421
473
  a(this, "entered", !1);
422
- this.extensionCodec = (e == null ? void 0 : e.extensionCodec) ?? F.defaultCodec, this.context = e == null ? void 0 : e.context, this.useBigInt64 = (e == null ? void 0 : e.useBigInt64) ?? !1, this.maxDepth = (e == null ? void 0 : e.maxDepth) ?? it, this.initialBufferSize = (e == null ? void 0 : e.initialBufferSize) ?? st, this.sortKeys = (e == null ? void 0 : e.sortKeys) ?? !1, this.forceFloat32 = (e == null ? void 0 : e.forceFloat32) ?? !1, this.ignoreUndefined = (e == null ? void 0 : e.ignoreUndefined) ?? !1, this.forceIntegerToFloat = (e == null ? void 0 : e.forceIntegerToFloat) ?? !1, this.pos = 0, this.view = new DataView(new ArrayBuffer(this.initialBufferSize)), this.bytes = new Uint8Array(this.view.buffer);
474
+ this.extensionCodec = (e == null ? void 0 : e.extensionCodec) ?? F.defaultCodec, this.context = e == null ? void 0 : e.context, this.useBigInt64 = (e == null ? void 0 : e.useBigInt64) ?? !1, this.maxDepth = (e == null ? void 0 : e.maxDepth) ?? at, this.initialBufferSize = (e == null ? void 0 : e.initialBufferSize) ?? ct, this.sortKeys = (e == null ? void 0 : e.sortKeys) ?? !1, this.forceFloat32 = (e == null ? void 0 : e.forceFloat32) ?? !1, this.ignoreUndefined = (e == null ? void 0 : e.ignoreUndefined) ?? !1, this.forceIntegerToFloat = (e == null ? void 0 : e.forceIntegerToFloat) ?? !1, this.pos = 0, this.view = new DataView(new ArrayBuffer(this.initialBufferSize)), this.bytes = new Uint8Array(this.view.buffer);
423
475
  }
424
476
  clone() {
425
477
  return new V({
@@ -473,8 +525,8 @@ class V {
473
525
  this.view.byteLength < t && this.resizeBuffer(t * 2);
474
526
  }
475
527
  resizeBuffer(e) {
476
- const t = new ArrayBuffer(e), i = new Uint8Array(t), s = new DataView(t);
477
- i.set(this.bytes), this.view = s, this.bytes = i;
528
+ const t = new ArrayBuffer(e), i = new Uint8Array(t), n = new DataView(t);
529
+ i.set(this.bytes), this.view = n, this.bytes = i;
478
530
  }
479
531
  encodeNil() {
480
532
  this.writeU8(192);
@@ -504,8 +556,8 @@ class V {
504
556
  throw new Error(`Too long string: ${e} bytes in UTF-8`);
505
557
  }
506
558
  encodeString(e) {
507
- const i = Le(e);
508
- this.ensureBufferSizeToWrite(5 + i), this.writeStringHeader(i), Fe(e, this.bytes, this.pos), this.pos += i;
559
+ const i = Fe(e);
560
+ this.ensureBufferSizeToWrite(5 + i), this.writeStringHeader(i), We(e, this.bytes, this.pos), this.pos += i;
509
561
  }
510
562
  encodeObject(e, t) {
511
563
  const i = this.extensionCodec.tryToEncode(e, this.context);
@@ -543,27 +595,27 @@ class V {
543
595
  this.writeU8(221), this.writeU32(i);
544
596
  else
545
597
  throw new Error(`Too large array: ${i}`);
546
- for (const s of e)
547
- this.doEncode(s, t + 1);
598
+ for (const n of e)
599
+ this.doEncode(n, t + 1);
548
600
  }
549
601
  countWithoutUndefined(e, t) {
550
602
  let i = 0;
551
- for (const s of t)
552
- e[s] !== void 0 && i++;
603
+ for (const n of t)
604
+ e[n] !== void 0 && i++;
553
605
  return i;
554
606
  }
555
607
  encodeMap(e, t) {
556
608
  const i = Object.keys(e);
557
609
  this.sortKeys && i.sort();
558
- const s = this.ignoreUndefined ? this.countWithoutUndefined(e, i) : i.length;
559
- if (s < 16)
560
- this.writeU8(128 + s);
561
- else if (s < 65536)
562
- this.writeU8(222), this.writeU16(s);
563
- else if (s < 4294967296)
564
- this.writeU8(223), this.writeU32(s);
610
+ const n = this.ignoreUndefined ? this.countWithoutUndefined(e, i) : i.length;
611
+ if (n < 16)
612
+ this.writeU8(128 + n);
613
+ else if (n < 65536)
614
+ this.writeU8(222), this.writeU16(n);
615
+ else if (n < 4294967296)
616
+ this.writeU8(223), this.writeU32(n);
565
617
  else
566
- throw new Error(`Too large map object: ${s}`);
618
+ throw new Error(`Too large map object: ${n}`);
567
619
  for (const r of i) {
568
620
  const o = e[r];
569
621
  this.ignoreUndefined && o === void 0 || (this.encodeString(r), this.doEncode(o, t + 1));
@@ -571,10 +623,10 @@ class V {
571
623
  }
572
624
  encodeExtension(e) {
573
625
  if (typeof e.data == "function") {
574
- const i = e.data(this.pos + 6), s = i.length;
575
- if (s >= 4294967296)
576
- throw new Error(`Too large extension object: ${s}`);
577
- this.writeU8(201), this.writeU32(s), this.writeI8(e.type), this.writeU8a(i);
626
+ const i = e.data(this.pos + 6), n = i.length;
627
+ if (n >= 4294967296)
628
+ throw new Error(`Too large extension object: ${n}`);
629
+ this.writeU8(201), this.writeU32(n), this.writeI8(e.type), this.writeU8a(i);
578
630
  return;
579
631
  }
580
632
  const t = e.data.length;
@@ -627,7 +679,7 @@ class V {
627
679
  this.ensureBufferSizeToWrite(8), this.view.setFloat64(this.pos, e), this.pos += 8;
628
680
  }
629
681
  writeU64(e) {
630
- this.ensureBufferSizeToWrite(8), Oe(this.view, this.pos, e), this.pos += 8;
682
+ this.ensureBufferSizeToWrite(8), Ge(this.view, this.pos, e), this.pos += 8;
631
683
  }
632
684
  writeI64(e) {
633
685
  this.ensureBufferSizeToWrite(8), xe(this.view, this.pos, e), this.pos += 8;
@@ -639,15 +691,15 @@ class V {
639
691
  this.ensureBufferSizeToWrite(8), this.view.setBigInt64(this.pos, e), this.pos += 8;
640
692
  }
641
693
  }
642
- function nt(n, e) {
643
- return new V(e).encodeSharedRef(n);
694
+ function lt(s, e) {
695
+ return new V(e).encodeSharedRef(s);
644
696
  }
645
- function K(n) {
646
- return `${n < 0 ? "-" : ""}0x${Math.abs(n).toString(16).padStart(2, "0")}`;
697
+ function K(s) {
698
+ return `${s < 0 ? "-" : ""}0x${Math.abs(s).toString(16).padStart(2, "0")}`;
647
699
  }
648
- const rt = 16, ot = 16;
649
- class at {
650
- constructor(e = rt, t = ot) {
700
+ const ht = 16, dt = 16;
701
+ class ft {
702
+ constructor(e = ht, t = dt) {
651
703
  a(this, "hit", 0);
652
704
  a(this, "miss", 0);
653
705
  a(this, "caches");
@@ -661,35 +713,35 @@ class at {
661
713
  return e > 0 && e <= this.maxKeyLength;
662
714
  }
663
715
  find(e, t, i) {
664
- const s = this.caches[i - 1];
665
- e: for (const r of s) {
716
+ const n = this.caches[i - 1];
717
+ e: for (const r of n) {
666
718
  const o = r.bytes;
667
- for (let h = 0; h < i; h++)
668
- if (o[h] !== e[t + h])
719
+ for (let l = 0; l < i; l++)
720
+ if (o[l] !== e[t + l])
669
721
  continue e;
670
722
  return r.str;
671
723
  }
672
724
  return null;
673
725
  }
674
726
  store(e, t) {
675
- const i = this.caches[e.length - 1], s = { bytes: e, str: t };
676
- i.length >= this.maxLengthPerKey ? i[Math.random() * i.length | 0] = s : i.push(s);
727
+ const i = this.caches[e.length - 1], n = { bytes: e, str: t };
728
+ i.length >= this.maxLengthPerKey ? i[Math.random() * i.length | 0] = n : i.push(n);
677
729
  }
678
730
  decode(e, t, i) {
679
- const s = this.find(e, t, i);
680
- if (s != null)
681
- return this.hit++, s;
731
+ const n = this.find(e, t, i);
732
+ if (n != null)
733
+ return this.hit++, n;
682
734
  this.miss++;
683
735
  const r = ue(e, t, i), o = Uint8Array.prototype.slice.call(e, t, t + i);
684
736
  return this.store(o, r), r;
685
737
  }
686
738
  }
687
- const O = "array", L = "map_key", ge = "map_value", ct = (n) => {
688
- if (typeof n == "string" || typeof n == "number")
689
- return n;
690
- throw new y("The type of key must be string or number but " + typeof n);
739
+ const O = "array", L = "map_key", ge = "map_value", ut = (s) => {
740
+ if (typeof s == "string" || typeof s == "number")
741
+ return s;
742
+ throw new y("The type of key must be string or number but " + typeof s);
691
743
  };
692
- class ht {
744
+ class xt {
693
745
  constructor() {
694
746
  a(this, "stack", []);
695
747
  a(this, "stackHeadPosition", -1);
@@ -740,14 +792,14 @@ class ht {
740
792
  this.stack.length = 0, this.stackHeadPosition = -1;
741
793
  }
742
794
  }
743
- const C = -1, Y = new DataView(new ArrayBuffer(0)), lt = new Uint8Array(Y.buffer);
795
+ const z = -1, Y = new DataView(new ArrayBuffer(0)), pt = new Uint8Array(Y.buffer);
744
796
  try {
745
797
  Y.getInt8(0);
746
- } catch (n) {
747
- if (!(n instanceof RangeError))
798
+ } catch (s) {
799
+ if (!(s instanceof RangeError))
748
800
  throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access");
749
801
  }
750
- const he = new RangeError("Insufficient data"), dt = new at();
802
+ const le = new RangeError("Insufficient data"), gt = new ft();
751
803
  class q {
752
804
  constructor(e) {
753
805
  a(this, "extensionCodec");
@@ -764,11 +816,11 @@ class q {
764
816
  a(this, "totalPos", 0);
765
817
  a(this, "pos", 0);
766
818
  a(this, "view", Y);
767
- a(this, "bytes", lt);
768
- a(this, "headByte", C);
769
- a(this, "stack", new ht());
819
+ a(this, "bytes", pt);
820
+ a(this, "headByte", z);
821
+ a(this, "stack", new xt());
770
822
  a(this, "entered", !1);
771
- this.extensionCodec = (e == null ? void 0 : e.extensionCodec) ?? F.defaultCodec, this.context = e == null ? void 0 : e.context, this.useBigInt64 = (e == null ? void 0 : e.useBigInt64) ?? !1, this.rawStrings = (e == null ? void 0 : e.rawStrings) ?? !1, this.maxStrLength = (e == null ? void 0 : e.maxStrLength) ?? z, this.maxBinLength = (e == null ? void 0 : e.maxBinLength) ?? z, this.maxArrayLength = (e == null ? void 0 : e.maxArrayLength) ?? z, this.maxMapLength = (e == null ? void 0 : e.maxMapLength) ?? z, this.maxExtLength = (e == null ? void 0 : e.maxExtLength) ?? z, this.keyDecoder = (e == null ? void 0 : e.keyDecoder) !== void 0 ? e.keyDecoder : dt, this.mapKeyConverter = (e == null ? void 0 : e.mapKeyConverter) ?? ct;
823
+ this.extensionCodec = (e == null ? void 0 : e.extensionCodec) ?? F.defaultCodec, this.context = e == null ? void 0 : e.context, this.useBigInt64 = (e == null ? void 0 : e.useBigInt64) ?? !1, this.rawStrings = (e == null ? void 0 : e.rawStrings) ?? !1, this.maxStrLength = (e == null ? void 0 : e.maxStrLength) ?? $, this.maxBinLength = (e == null ? void 0 : e.maxBinLength) ?? $, this.maxArrayLength = (e == null ? void 0 : e.maxArrayLength) ?? $, this.maxMapLength = (e == null ? void 0 : e.maxMapLength) ?? $, this.maxExtLength = (e == null ? void 0 : e.maxExtLength) ?? $, this.keyDecoder = (e == null ? void 0 : e.keyDecoder) !== void 0 ? e.keyDecoder : gt, this.mapKeyConverter = (e == null ? void 0 : e.mapKeyConverter) ?? ut;
772
824
  }
773
825
  clone() {
774
826
  return new q({
@@ -785,18 +837,18 @@ class q {
785
837
  });
786
838
  }
787
839
  reinitializeState() {
788
- this.totalPos = 0, this.headByte = C, this.stack.reset();
840
+ this.totalPos = 0, this.headByte = z, this.stack.reset();
789
841
  }
790
842
  setBuffer(e) {
791
843
  const t = W(e);
792
844
  this.bytes = t, this.view = new DataView(t.buffer, t.byteOffset, t.byteLength), this.pos = 0;
793
845
  }
794
846
  appendBuffer(e) {
795
- if (this.headByte === C && !this.hasRemaining(1))
847
+ if (this.headByte === z && !this.hasRemaining(1))
796
848
  this.setBuffer(e);
797
849
  else {
798
- const t = this.bytes.subarray(this.pos), i = W(e), s = new Uint8Array(t.length + i.length);
799
- s.set(t), s.set(i, t.length), this.setBuffer(s);
850
+ const t = this.bytes.subarray(this.pos), i = W(e), n = new Uint8Array(t.length + i.length);
851
+ n.set(t), n.set(i, t.length), this.setBuffer(n);
800
852
  }
801
853
  }
802
854
  hasRemaining(e) {
@@ -841,10 +893,10 @@ class q {
841
893
  try {
842
894
  this.entered = !0;
843
895
  let t = !1, i;
844
- for await (const h of e) {
896
+ for await (const l of e) {
845
897
  if (t)
846
898
  throw this.entered = !1, this.createExtraByteError(this.totalPos);
847
- this.appendBuffer(h);
899
+ this.appendBuffer(l);
848
900
  try {
849
901
  i = this.doDecodeSync(), t = !0;
850
902
  } catch (d) {
@@ -858,8 +910,8 @@ class q {
858
910
  throw this.createExtraByteError(this.totalPos);
859
911
  return i;
860
912
  }
861
- const { headByte: s, pos: r, totalPos: o } = this;
862
- throw new RangeError(`Insufficient data in parsing ${K(s)} at ${o} (${r} in the current buffer)`);
913
+ const { headByte: n, pos: r, totalPos: o } = this;
914
+ throw new RangeError(`Insufficient data in parsing ${K(n)} at ${o} (${r} in the current buffer)`);
863
915
  } finally {
864
916
  this.entered = !1;
865
917
  }
@@ -877,13 +929,13 @@ class q {
877
929
  }
878
930
  try {
879
931
  this.entered = !0;
880
- let i = t, s = -1;
932
+ let i = t, n = -1;
881
933
  for await (const r of e) {
882
- if (t && s === 0)
934
+ if (t && n === 0)
883
935
  throw this.createExtraByteError(this.totalPos);
884
- this.appendBuffer(r), i && (s = this.readArraySize(), i = !1, this.complete());
936
+ this.appendBuffer(r), i && (n = this.readArraySize(), i = !1, this.complete());
885
937
  try {
886
- for (; yield this.doDecodeSync(), --s !== 0; )
938
+ for (; yield this.doDecodeSync(), --n !== 0; )
887
939
  ;
888
940
  } catch (o) {
889
941
  if (!(o instanceof RangeError))
@@ -905,22 +957,22 @@ class q {
905
957
  if (e < 128)
906
958
  t = e;
907
959
  else if (e < 144) {
908
- const s = e - 128;
909
- if (s !== 0) {
910
- this.pushMapState(s), this.complete();
960
+ const n = e - 128;
961
+ if (n !== 0) {
962
+ this.pushMapState(n), this.complete();
911
963
  continue e;
912
964
  } else
913
965
  t = {};
914
966
  } else if (e < 160) {
915
- const s = e - 144;
916
- if (s !== 0) {
917
- this.pushArrayState(s), this.complete();
967
+ const n = e - 144;
968
+ if (n !== 0) {
969
+ this.pushArrayState(n), this.complete();
918
970
  continue e;
919
971
  } else
920
972
  t = [];
921
973
  } else {
922
- const s = e - 160;
923
- t = this.decodeString(s, 0);
974
+ const n = e - 160;
975
+ t = this.decodeString(n, 0);
924
976
  }
925
977
  else if (e === 192)
926
978
  t = null;
@@ -949,51 +1001,51 @@ class q {
949
1001
  else if (e === 211)
950
1002
  this.useBigInt64 ? t = this.readI64AsBigInt() : t = this.readI64();
951
1003
  else if (e === 217) {
952
- const s = this.lookU8();
953
- t = this.decodeString(s, 1);
1004
+ const n = this.lookU8();
1005
+ t = this.decodeString(n, 1);
954
1006
  } else if (e === 218) {
955
- const s = this.lookU16();
956
- t = this.decodeString(s, 2);
1007
+ const n = this.lookU16();
1008
+ t = this.decodeString(n, 2);
957
1009
  } else if (e === 219) {
958
- const s = this.lookU32();
959
- t = this.decodeString(s, 4);
1010
+ const n = this.lookU32();
1011
+ t = this.decodeString(n, 4);
960
1012
  } else if (e === 220) {
961
- const s = this.readU16();
962
- if (s !== 0) {
963
- this.pushArrayState(s), this.complete();
1013
+ const n = this.readU16();
1014
+ if (n !== 0) {
1015
+ this.pushArrayState(n), this.complete();
964
1016
  continue e;
965
1017
  } else
966
1018
  t = [];
967
1019
  } else if (e === 221) {
968
- const s = this.readU32();
969
- if (s !== 0) {
970
- this.pushArrayState(s), this.complete();
1020
+ const n = this.readU32();
1021
+ if (n !== 0) {
1022
+ this.pushArrayState(n), this.complete();
971
1023
  continue e;
972
1024
  } else
973
1025
  t = [];
974
1026
  } else if (e === 222) {
975
- const s = this.readU16();
976
- if (s !== 0) {
977
- this.pushMapState(s), this.complete();
1027
+ const n = this.readU16();
1028
+ if (n !== 0) {
1029
+ this.pushMapState(n), this.complete();
978
1030
  continue e;
979
1031
  } else
980
1032
  t = {};
981
1033
  } else if (e === 223) {
982
- const s = this.readU32();
983
- if (s !== 0) {
984
- this.pushMapState(s), this.complete();
1034
+ const n = this.readU32();
1035
+ if (n !== 0) {
1036
+ this.pushMapState(n), this.complete();
985
1037
  continue e;
986
1038
  } else
987
1039
  t = {};
988
1040
  } else if (e === 196) {
989
- const s = this.lookU8();
990
- t = this.decodeBinary(s, 1);
1041
+ const n = this.lookU8();
1042
+ t = this.decodeBinary(n, 1);
991
1043
  } else if (e === 197) {
992
- const s = this.lookU16();
993
- t = this.decodeBinary(s, 2);
1044
+ const n = this.lookU16();
1045
+ t = this.decodeBinary(n, 2);
994
1046
  } else if (e === 198) {
995
- const s = this.lookU32();
996
- t = this.decodeBinary(s, 4);
1047
+ const n = this.lookU32();
1048
+ t = this.decodeBinary(n, 4);
997
1049
  } else if (e === 212)
998
1050
  t = this.decodeExtension(1, 0);
999
1051
  else if (e === 213)
@@ -1005,34 +1057,34 @@ class q {
1005
1057
  else if (e === 216)
1006
1058
  t = this.decodeExtension(16, 0);
1007
1059
  else if (e === 199) {
1008
- const s = this.lookU8();
1009
- t = this.decodeExtension(s, 1);
1060
+ const n = this.lookU8();
1061
+ t = this.decodeExtension(n, 1);
1010
1062
  } else if (e === 200) {
1011
- const s = this.lookU16();
1012
- t = this.decodeExtension(s, 2);
1063
+ const n = this.lookU16();
1064
+ t = this.decodeExtension(n, 2);
1013
1065
  } else if (e === 201) {
1014
- const s = this.lookU32();
1015
- t = this.decodeExtension(s, 4);
1066
+ const n = this.lookU32();
1067
+ t = this.decodeExtension(n, 4);
1016
1068
  } else
1017
1069
  throw new y(`Unrecognized type byte: ${K(e)}`);
1018
1070
  this.complete();
1019
1071
  const i = this.stack;
1020
1072
  for (; i.length > 0; ) {
1021
- const s = i.top();
1022
- if (s.type === O)
1023
- if (s.array[s.position] = t, s.position++, s.position === s.size)
1024
- t = s.array, i.release(s);
1073
+ const n = i.top();
1074
+ if (n.type === O)
1075
+ if (n.array[n.position] = t, n.position++, n.position === n.size)
1076
+ t = n.array, i.release(n);
1025
1077
  else
1026
1078
  continue e;
1027
- else if (s.type === L) {
1079
+ else if (n.type === L) {
1028
1080
  if (t === "__proto__")
1029
1081
  throw new y("The key __proto__ is not allowed");
1030
- s.key = this.mapKeyConverter(t), s.type = ge;
1082
+ n.key = this.mapKeyConverter(t), n.type = ge;
1031
1083
  continue e;
1032
- } else if (s.map[s.key] = t, s.readCount++, s.readCount === s.size)
1033
- t = s.map, i.release(s);
1084
+ } else if (n.map[n.key] = t, n.readCount++, n.readCount === n.size)
1085
+ t = n.map, i.release(n);
1034
1086
  else {
1035
- s.key = null, s.type = L;
1087
+ n.key = null, n.type = L;
1036
1088
  continue e;
1037
1089
  }
1038
1090
  }
@@ -1040,10 +1092,10 @@ class q {
1040
1092
  }
1041
1093
  }
1042
1094
  readHeadByte() {
1043
- return this.headByte === C && (this.headByte = this.readU8()), this.headByte;
1095
+ return this.headByte === z && (this.headByte = this.readU8()), this.headByte;
1044
1096
  }
1045
1097
  complete() {
1046
- this.headByte = C;
1098
+ this.headByte = z;
1047
1099
  }
1048
1100
  readArraySize() {
1049
1101
  const e = this.readHeadByte();
@@ -1080,10 +1132,10 @@ class q {
1080
1132
  if (e > this.maxStrLength)
1081
1133
  throw new y(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);
1082
1134
  if (this.bytes.byteLength < this.pos + t + e)
1083
- throw he;
1135
+ throw le;
1084
1136
  const i = this.pos + t;
1085
- let s;
1086
- return this.stateIsMapKey() && ((r = this.keyDecoder) != null && r.canBeCached(e)) ? s = this.keyDecoder.decode(this.bytes, i, e) : s = We(this.bytes, i, e), this.pos += t + e, s;
1137
+ let n;
1138
+ return this.stateIsMapKey() && ((r = this.keyDecoder) != null && r.canBeCached(e)) ? n = this.keyDecoder.decode(this.bytes, i, e) : n = Xe(this.bytes, i, e), this.pos += t + e, n;
1087
1139
  }
1088
1140
  stateIsMapKey() {
1089
1141
  return this.stack.length > 0 ? this.stack.top().type === L : !1;
@@ -1095,19 +1147,19 @@ class q {
1095
1147
  if (e > this.maxBinLength)
1096
1148
  throw new y(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);
1097
1149
  if (!this.hasRemaining(e + t))
1098
- throw he;
1099
- const i = this.pos + t, s = this.bytes.subarray(i, i + e);
1100
- return this.pos += t + e, s;
1150
+ throw le;
1151
+ const i = this.pos + t, n = this.bytes.subarray(i, i + e);
1152
+ return this.pos += t + e, n;
1101
1153
  }
1102
1154
  decodeExtension(e, t) {
1103
1155
  if (e > this.maxExtLength)
1104
1156
  throw new y(`Max length exceeded: ext length (${e}) > maxExtLength (${this.maxExtLength})`);
1105
- const i = this.view.getInt8(this.pos + t), s = this.decodeBinary(
1157
+ const i = this.view.getInt8(this.pos + t), n = this.decodeBinary(
1106
1158
  e,
1107
1159
  t + 1
1108
1160
  /* extType */
1109
1161
  );
1110
- return this.extensionCodec.decode(s, i, this.context);
1162
+ return this.extensionCodec.decode(n, i, this.context);
1111
1163
  }
1112
1164
  lookU8() {
1113
1165
  return this.view.getUint8(this.pos);
@@ -1143,7 +1195,7 @@ class q {
1143
1195
  return this.pos += 4, e;
1144
1196
  }
1145
1197
  readU64() {
1146
- const e = Ve(this.view, this.pos);
1198
+ const e = Je(this.view, this.pos);
1147
1199
  return this.pos += 8, e;
1148
1200
  }
1149
1201
  readI64() {
@@ -1167,10 +1219,10 @@ class q {
1167
1219
  return this.pos += 8, e;
1168
1220
  }
1169
1221
  }
1170
- function ft(n, e) {
1171
- return new q(e).decode(n);
1222
+ function wt(s, e) {
1223
+ return new q(e).decode(s);
1172
1224
  }
1173
- const ut = /* @__PURE__ */ new Set([
1225
+ const yt = /* @__PURE__ */ new Set([
1174
1226
  "auth",
1175
1227
  "open",
1176
1228
  "send",
@@ -1193,23 +1245,23 @@ const ut = /* @__PURE__ */ new Set([
1193
1245
  "subscribe_inbox",
1194
1246
  "unsubscribe_inbox"
1195
1247
  ]);
1196
- function mt(n) {
1197
- return ut.has(n.type);
1248
+ function Et(s) {
1249
+ return yt.has(s.type);
1198
1250
  }
1199
- function le(n) {
1200
- return nt(n);
1251
+ function he(s) {
1252
+ return lt(s);
1201
1253
  }
1202
- function xt(n) {
1254
+ function mt(s) {
1203
1255
  let e;
1204
1256
  try {
1205
- e = ft(n);
1257
+ e = wt(s);
1206
1258
  } catch {
1207
1259
  return null;
1208
1260
  }
1209
1261
  return typeof e != "object" || e === null || typeof e.type != "string" ? null : e;
1210
1262
  }
1211
- function pt(n) {
1212
- switch (n) {
1263
+ function vt(s) {
1264
+ switch (s) {
1213
1265
  case "open":
1214
1266
  return { label: "Open", cls: "open" };
1215
1267
  case "awaiting_staff":
@@ -1222,55 +1274,55 @@ function pt(n) {
1222
1274
  return null;
1223
1275
  }
1224
1276
  }
1225
- function gt(n) {
1226
- const e = Math.floor((Date.now() - n) / 1e3);
1277
+ function Ut(s) {
1278
+ const e = Math.floor((Date.now() - s) / 1e3);
1227
1279
  if (e < 60) return "just now";
1228
1280
  if (e < 3600) return `${Math.floor(e / 60)}m`;
1229
1281
  if (e < 86400) return `${Math.floor(e / 3600)}h`;
1230
1282
  const t = Math.floor(e / 86400);
1231
1283
  if (t <= 7) return `${t}d`;
1232
1284
  try {
1233
- return new Date(n).toLocaleDateString(void 0, { month: "short", day: "numeric" });
1285
+ return new Date(s).toLocaleDateString(void 0, { month: "short", day: "numeric" });
1234
1286
  } catch {
1235
1287
  return `${t}d`;
1236
1288
  }
1237
1289
  }
1238
- function l(n, e, t) {
1239
- const i = document.createElement(n);
1290
+ function h(s, e, t) {
1291
+ const i = document.createElement(s);
1240
1292
  return e && (i.className = e), t !== void 0 && (i.textContent = t), i;
1241
1293
  }
1242
- function Ut(n) {
1243
- const e = n.token ?? n.userId ?? Ce(), { httpBase: t, wsUrl: i } = de(n.url, n.apiUrl), s = n.i18n ?? {}, r = n.accent ?? "#6c5ce7";
1294
+ function Bt(s) {
1295
+ const e = s.token ?? s.userId ?? _e(), { httpBase: t, wsUrl: i } = de(s.url, s.apiUrl), n = Le(s.locale, s.i18n), r = s.accent ?? "#6c5ce7";
1244
1296
  if (!document.getElementById("ocl-styles")) {
1245
1297
  const c = document.createElement("style");
1246
- c.id = "ocl-styles", c.textContent = Te, document.head.append(c);
1298
+ c.id = "ocl-styles", c.textContent = Ae, document.head.append(c);
1247
1299
  }
1248
- if (n.webfont !== !1 && typeof document < "u" && !document.getElementById("ocw-webfont")) {
1300
+ if (s.webfont !== !1 && typeof document < "u" && !document.getElementById("ocw-webfont")) {
1249
1301
  const c = document.createElement("link");
1250
1302
  c.id = "ocw-webfont", c.rel = "stylesheet", c.href = "https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;600;700&family=Nunito:wght@400;500;600;700&display=swap", document.head.append(c);
1251
1303
  }
1252
- const o = l("div", "ocl");
1253
- o.style.setProperty("--ocl-accent", r), o.dataset.theme = n.theme ?? "light", n.reserveCloseSpace && o.classList.add("ocl-has-close");
1254
- const h = l("div", "ocl-head"), d = s.title ?? "Your conversations", U = l("span", "ocl-title", d);
1255
- if (U.setAttribute("aria-label", d), h.append(U), n.onNewChat) {
1256
- const c = l("button", "ocl-compose", "✎");
1257
- c.title = s.newChat ?? "New conversation", c.addEventListener("click", () => n.onNewChat()), h.append(c);
1258
- }
1259
- const b = l("div", "ocl-search-wrap"), x = l("input", "ocl-search");
1260
- x.placeholder = s.search ?? "🔍 Search", x.type = "search", b.append(x);
1261
- const g = l("div", "ocl-body");
1262
- g.append(l("div", "ocl-spinner", "Loading…")), o.append(h, b, g), n.el.replaceChildren(o);
1304
+ const o = h("div", "ocl");
1305
+ o.style.setProperty("--ocl-accent", r), o.dataset.theme = s.theme ?? "light", s.reserveCloseSpace && o.classList.add("ocl-has-close");
1306
+ const l = h("div", "ocl-head"), d = n.title ?? "Your conversations", v = h("span", "ocl-title", d);
1307
+ if (v.setAttribute("aria-label", d), l.append(v), s.onNewChat) {
1308
+ const c = h("button", "ocl-compose", "✎");
1309
+ c.title = n.newChat ?? "New conversation", c.addEventListener("click", () => s.onNewChat()), l.append(c);
1310
+ }
1311
+ const b = h("div", "ocl-search-wrap"), x = h("input", "ocl-search");
1312
+ x.placeholder = n.search ?? "🔍 Search", x.type = "search", b.append(x);
1313
+ const g = h("div", "ocl-body");
1314
+ g.append(h("div", "ocl-spinner", "Loading…")), o.append(l, b, g), s.el.replaceChildren(o);
1263
1315
  const I = (c) => {
1264
1316
  o.classList.toggle("ocl-compact", c > 0 && c < 400);
1265
1317
  };
1266
1318
  I(o.clientWidth);
1267
- let v = null;
1268
- if (typeof ResizeObserver < "u" && (v = new ResizeObserver((c) => {
1319
+ let U = null;
1320
+ if (typeof ResizeObserver < "u" && (U = new ResizeObserver((c) => {
1269
1321
  var u;
1270
1322
  return I(((u = c[0]) == null ? void 0 : u.contentRect.width) ?? o.clientWidth);
1271
- }), v.observe(o)), !n.profileId && !n.tenantId) throw new Error("[relay chatlist] provide profileId or tenantId");
1323
+ }), U.observe(o)), !s.profileId && !s.tenantId) throw new Error("[relay chatlist] provide profileId or tenantId");
1272
1324
  let X;
1273
- const G = `ocl_seen_${n.profileId ?? `t_${n.tenantId}`}_${(n.userId ?? e).slice(-8)}`;
1325
+ const G = `ocl_seen_${s.profileId ?? `t_${s.tenantId}`}_${(s.userId ?? e).slice(-8)}`;
1274
1326
  let k = {};
1275
1327
  try {
1276
1328
  k = JSON.parse(localStorage.getItem(G) ?? "{}");
@@ -1284,7 +1336,7 @@ function Ut(n) {
1284
1336
  };
1285
1337
  let J = [], B = !1;
1286
1338
  const ye = async () => {
1287
- const c = n.profileId ? `profileId=${encodeURIComponent(n.profileId)}${n.scope === "tenant" ? "&scope=tenant" : ""}` : `tenantId=${encodeURIComponent(n.tenantId)}`, u = `${t}/conversations/mine?${c}`, w = { authorization: `Bearer ${e}` };
1339
+ const c = s.profileId ? `profileId=${encodeURIComponent(s.profileId)}${s.scope === "tenant" ? "&scope=tenant" : ""}` : `tenantId=${encodeURIComponent(s.tenantId)}`, u = `${t}/conversations/mine?${c}`, w = { authorization: `Bearer ${e}` };
1288
1340
  let S;
1289
1341
  try {
1290
1342
  S = await fetch(u, { headers: w });
@@ -1300,43 +1352,43 @@ function Ut(n) {
1300
1352
  (f) => Q(f).toLowerCase().includes(u) || (f.lastMessage ?? "").toLowerCase().includes(u)
1301
1353
  ) : c;
1302
1354
  if (g.replaceChildren(), !w.length) {
1303
- const f = l("div", "ocl-empty", u ? "No results." : s.empty ?? "No conversations yet.");
1304
- if (!u && n.onNewChat) {
1305
- f.append(l("br"));
1306
- const D = l("button", "ocl-start", s.newChat ?? "Start a conversation");
1307
- D.addEventListener("click", () => n.onNewChat()), f.append(D);
1355
+ const f = h("div", "ocl-empty", u ? "No results." : n.empty ?? "No conversations yet.");
1356
+ if (!u && s.onNewChat) {
1357
+ f.append(h("br"));
1358
+ const D = h("button", "ocl-start", n.startChat ?? "Start a conversation");
1359
+ D.addEventListener("click", () => s.onNewChat()), f.append(D);
1308
1360
  }
1309
1361
  g.append(f);
1310
1362
  return;
1311
1363
  }
1312
1364
  const S = (f) => (f.lastSeq ?? 0) > (k[f.id] ?? 0), m = w.filter(S), E = w.filter((f) => !S(f));
1313
1365
  if (m.length) {
1314
- g.append(l("div", "ocl-section", `${s.unread ?? "Unread"} (${m.length})`));
1366
+ g.append(h("div", "ocl-section", `${n.unread ?? "Unread"} (${m.length})`));
1315
1367
  for (const f of m) g.append(j(f, S(f)));
1316
1368
  }
1317
1369
  if (E.length) {
1318
- g.append(l("div", "ocl-section", m.length ? s.all ?? "All conversations" : ""));
1370
+ g.append(h("div", "ocl-section", m.length ? n.all ?? "All conversations" : ""));
1319
1371
  for (const f of E) g.append(j(f, !1));
1320
1372
  }
1321
1373
  }, Q = (c) => c.subjectTitle ?? (c.kind === "direct" ? c.peerId ?? "Direct message" : "General enquiry"), j = (c, u) => {
1322
1374
  var re;
1323
- const w = Q(c), S = (((re = w.match(new RegExp("\\p{L}", "u"))) == null ? void 0 : re[0]) ?? w.trim()[0] ?? "?").toUpperCase(), m = c.lastSeq ?? 0, E = u ? Math.max(1, m - (k[c.id] ?? 0)) : 0, f = l("button", `ocl-row${u ? " unread" : ""}`), D = l("div", "ocl-av", S);
1375
+ const w = Q(c), S = (((re = w.match(new RegExp("\\p{L}", "u"))) == null ? void 0 : re[0]) ?? w.trim()[0] ?? "?").toUpperCase(), m = c.lastSeq ?? 0, E = u ? Math.max(1, m - (k[c.id] ?? 0)) : 0, f = h("button", `ocl-row${u ? " unread" : ""}`), D = h("div", "ocl-av", S);
1324
1376
  f.append(D);
1325
- const N = l("div", "ocl-info");
1326
- N.append(l("div", "ocl-name", w));
1377
+ const N = h("div", "ocl-info");
1378
+ N.append(h("div", "ocl-name", w));
1327
1379
  const me = {
1328
1380
  open: "Open",
1329
1381
  awaiting_staff: "Waiting for reply…",
1330
1382
  resolved: "Resolved ✓",
1331
1383
  closed: "Closed"
1332
1384
  };
1333
- N.append(l("div", "ocl-preview", c.lastMessage ?? me[c.state] ?? c.state)), f.append(N);
1334
- const $ = l("div", "ocl-right");
1335
- $.append(l("div", "ocl-time", gt(c.updatedAt)));
1336
- const H = pt(c.state);
1337
- return H && $.append(l("div", `ocl-status ${H.cls}`, H.label)), E > 0 && $.append(l("div", "ocl-badge", String(E > 99 ? "99+" : E))), f.append($), f.addEventListener("click", () => {
1385
+ N.append(h("div", "ocl-preview", c.lastMessage ?? me[c.state] ?? c.state)), f.append(N);
1386
+ const C = h("div", "ocl-right");
1387
+ C.append(h("div", "ocl-time", Ut(c.updatedAt)));
1388
+ const H = vt(c.state);
1389
+ return H && C.append(h("div", `ocl-status ${H.cls}`, H.label)), E > 0 && C.append(h("div", "ocl-badge", String(E > 99 ? "99+" : E))), f.append(C), f.addEventListener("click", () => {
1338
1390
  var oe;
1339
- m > 0 && (k[c.id] = m, we()), f.classList.remove("unread"), (oe = $.querySelector(".ocl-badge")) == null || oe.remove(), n.onSelect(c);
1391
+ m > 0 && (k[c.id] = m, we()), f.classList.remove("unread"), (oe = C.querySelector(".ocl-badge")) == null || oe.remove(), s.onSelect(c);
1340
1392
  }), f;
1341
1393
  }, M = () => {
1342
1394
  B || ye().then((c) => {
@@ -1344,21 +1396,21 @@ function Ut(n) {
1344
1396
  }).catch((c) => {
1345
1397
  if (B) return;
1346
1398
  console.error(`[chat-widget] failed to load conversations from ${t}/conversations/mine — check the apiUrl/CORS config.`, c);
1347
- const u = l("div", "ocl-empty", s.error ?? "Could not load conversations.");
1348
- u.append(l("br"));
1349
- const w = l("button", "ocl-retry", s.retry ?? "Retry");
1399
+ const u = h("div", "ocl-empty", n.error ?? "Could not load conversations.");
1400
+ u.append(h("br"));
1401
+ const w = h("button", "ocl-retry", n.retry ?? "Retry");
1350
1402
  w.addEventListener("click", () => {
1351
- g.replaceChildren(l("div", "ocl-spinner", "Loading…")), M();
1403
+ g.replaceChildren(h("div", "ocl-spinner", "Loading…")), M();
1352
1404
  }), u.append(w), g.replaceChildren(u);
1353
1405
  });
1354
1406
  };
1355
1407
  x.addEventListener("input", () => Z(J, x.value.trim().toLowerCase())), M();
1356
- let p = null, T, A, ee = 0, te = !1;
1357
- const ie = () => {
1358
- A || (A = setTimeout(() => {
1359
- A = void 0, M();
1408
+ let p = null, A, T, ee = 0, te = !1;
1409
+ const se = () => {
1410
+ T || (T = setTimeout(() => {
1411
+ T = void 0, M();
1360
1412
  }, 300));
1361
- }, se = () => {
1413
+ }, ie = () => {
1362
1414
  if (!B) {
1363
1415
  try {
1364
1416
  p = new WebSocket(i);
@@ -1367,10 +1419,10 @@ function Ut(n) {
1367
1419
  return;
1368
1420
  }
1369
1421
  p.binaryType = "arraybuffer", p.onopen = () => {
1370
- ee = 0, p.send(le({ type: "auth", token: e })), p.send(le({ type: "subscribe_inbox" })), te && ie(), te = !0;
1422
+ ee = 0, p.send(he({ type: "auth", token: e })), p.send(he({ type: "subscribe_inbox" })), te && se(), te = !0;
1371
1423
  }, p.onmessage = (c) => {
1372
- const u = xt(new Uint8Array(c.data));
1373
- u && u.type === "inbox_event" && ie();
1424
+ const u = mt(new Uint8Array(c.data));
1425
+ u && u.type === "inbox_event" && se();
1374
1426
  }, p.onclose = () => {
1375
1427
  p = null, ne();
1376
1428
  }, p.onerror = () => {
@@ -1381,37 +1433,39 @@ function Ut(n) {
1381
1433
  };
1382
1434
  }
1383
1435
  }, ne = () => {
1384
- if (B || T) return;
1436
+ if (B || A) return;
1385
1437
  const c = Math.min(15e3, 500 * 2 ** ee++) + Math.random() * 250;
1386
- T = setTimeout(() => {
1387
- T = void 0, se();
1438
+ A = setTimeout(() => {
1439
+ A = void 0, ie();
1388
1440
  }, c);
1389
1441
  };
1390
- return se(), {
1442
+ return ie(), {
1391
1443
  refresh: M,
1392
1444
  close() {
1393
- B = !0, T && clearTimeout(T), A && clearTimeout(A), v == null || v.disconnect(), v = null;
1445
+ B = !0, A && clearTimeout(A), T && clearTimeout(T), U == null || U.disconnect(), U = null;
1394
1446
  try {
1395
1447
  p == null || p.close();
1396
1448
  } catch {
1397
1449
  }
1398
- p = null, n.el.replaceChildren();
1450
+ p = null, s.el.replaceChildren();
1399
1451
  },
1400
1452
  defaultProfileId() {
1401
- return n.profileId ?? X;
1453
+ return s.profileId ?? X;
1402
1454
  }
1403
1455
  };
1404
1456
  }
1405
1457
  export {
1406
- yt as a,
1458
+ bt as a,
1407
1459
  ce as b,
1408
- xt as d,
1409
- le as e,
1460
+ Le as c,
1461
+ mt as d,
1462
+ he as e,
1463
+ ze as f,
1410
1464
  Se as h,
1411
- mt as i,
1465
+ Et as i,
1412
1466
  ke as l,
1413
- Ut as m,
1414
- Ce as p,
1467
+ Bt as m,
1468
+ _e as p,
1415
1469
  de as r
1416
1470
  };
1417
1471
  //# sourceMappingURL=chatlist2.js.map