@nethesis/chat-island 0.1.5 → 0.1.6

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
@@ -2315,6 +2315,8 @@ var U = {
2315
2315
  mucsub: "urn:xmpp:mucsub:0",
2316
2316
  pubsubEvent: "http://jabber.org/protocol/pubsub#event",
2317
2317
  mucsubMessages: "urn:xmpp:mucsub:nodes:messages",
2318
+ mucsubConfig: "urn:xmpp:mucsub:nodes:config",
2319
+ mucUser: "http://jabber.org/protocol/muc#user",
2318
2320
  conference: "jabber:x:conference",
2319
2321
  vcard: "vcard-temp",
2320
2322
  ping: "urn:xmpp:ping",
@@ -2558,14 +2560,14 @@ var U = {
2558
2560
  xmlns: U.mucsub,
2559
2561
  jid: `${e}@${this.domain}`,
2560
2562
  nick: e
2561
- }, P("event", { node: U.mucsubMessages }))), 15e3).catch(() => {});
2563
+ }, P("event", { node: U.mucsubMessages }), P("event", { node: U.mucsubConfig }))), 15e3).catch(() => {});
2562
2564
  await this.xmpp.iqCaller.request(P("iq", {
2563
2565
  type: "set",
2564
2566
  to: r
2565
2567
  }, P("subscribe", {
2566
2568
  xmlns: U.mucsub,
2567
2569
  nick: i
2568
- }, P("event", { node: U.mucsubMessages }))), 15e3), await this.xmpp.send(P("presence", {
2570
+ }, P("event", { node: U.mucsubMessages }), P("event", { node: U.mucsubConfig }))), 15e3), await this.xmpp.send(P("presence", {
2569
2571
  to: `${r}/${i}`,
2570
2572
  type: "unavailable"
2571
2573
  }));
@@ -2730,9 +2732,15 @@ var U = {
2730
2732
  e && this.deliver(e);
2731
2733
  return;
2732
2734
  }
2733
- let i = e.getChild("x", U.conference);
2734
- if (i) {
2735
- let e = W(i.attrs.jid);
2735
+ let i = e.getChild("event", U.pubsubEvent);
2736
+ if (i?.getChild("items")?.attrs.node === U.mucsubConfig) {
2737
+ let t = W(e.attrs.from);
2738
+ this.isGroup(t) && bn(i, "presence")?.getChild("x", U.mucUser)?.getChild("destroy") && this.h.groupDestroyed(t);
2739
+ return;
2740
+ }
2741
+ let a = e.getChild("x", U.conference);
2742
+ if (a) {
2743
+ let e = W(a.attrs.jid);
2736
2744
  this.isGroup(e) && this.h.groupInvite(e);
2737
2745
  return;
2738
2746
  }
@@ -2757,7 +2765,7 @@ var U = {
2757
2765
  let t = e.getChild("event", U.pubsubEvent), n = e, r;
2758
2766
  if (t && t.getChild("items")?.attrs.node === U.mucsubMessages) {
2759
2767
  r = W(e.attrs.from);
2760
- let i = bn(t);
2768
+ let i = xn(t);
2761
2769
  if (!this.isGroup(r) || !i || W(i.attrs.from) !== r) return;
2762
2770
  n = i;
2763
2771
  } else if (e.attrs.type === "groupchat" && (r = W(e.attrs.from), !this.isGroup(r))) return;
@@ -2787,7 +2795,7 @@ var U = {
2787
2795
  if (r && r.getChild("items")?.attrs.node === U.mucsubMessages) {
2788
2796
  let i = W(e.attrs.from);
2789
2797
  if (!this.isGroup(i)) return;
2790
- let a = bn(r);
2798
+ let a = xn(r);
2791
2799
  if (!a || W(a.attrs.from) !== i) return;
2792
2800
  let o = (a.attrs.from ?? "").split("/")[1] ?? "", s = a.getChildText("body");
2793
2801
  return s == null ? void 0 : {
@@ -2839,18 +2847,16 @@ var U = {
2839
2847
  let t = e?.getChild("delay", U.delay)?.attrs.stamp;
2840
2848
  return t ? Date.parse(t) : Date.now();
2841
2849
  };
2842
- function bn(e) {
2843
- for (let t of e.children) {
2844
- if (typeof t == "string") continue;
2845
- if (t.name === "message") return t;
2846
- let e = bn(t);
2850
+ function bn(e, t) {
2851
+ for (let n of e.children) {
2852
+ if (typeof n == "string") continue;
2853
+ if (n.name === t) return n;
2854
+ let e = bn(n, t);
2847
2855
  if (e) return e;
2848
2856
  }
2849
2857
  }
2850
- //#endregion
2851
- //#region src/sound.ts
2852
- var K;
2853
- function xn() {
2858
+ var xn = (e) => bn(e, "message"), K;
2859
+ function Sn() {
2854
2860
  try {
2855
2861
  K ??= new AudioContext(), K.state === "suspended" && K.resume();
2856
2862
  let e = K.currentTime;
@@ -2870,7 +2876,7 @@ function xn() {
2870
2876
  }
2871
2877
  //#endregion
2872
2878
  //#region node_modules/zustand/esm/vanilla.mjs
2873
- var Sn = (e) => {
2879
+ var Cn = (e) => {
2874
2880
  let t, n = /* @__PURE__ */ new Set(), r = (e, r) => {
2875
2881
  let i = typeof e == "function" ? e(t) : e;
2876
2882
  if (!Object.is(i, t)) {
@@ -2887,15 +2893,15 @@ var Sn = (e) => {
2887
2893
  }
2888
2894
  }, o = t = e(r, i, a);
2889
2895
  return a;
2890
- }, Cn = (e) => e ? Sn(e) : Sn, { useDebugValue: wn } = e, { useSyncExternalStoreWithSelector: Tn } = l, En = (e) => e;
2891
- function Dn(e, t = En, n) {
2892
- let r = Tn(e.subscribe, e.getState, e.getServerState || e.getInitialState, t, n);
2893
- return wn(r), r;
2896
+ }, wn = (e) => e ? Cn(e) : Cn, { useDebugValue: Tn } = e, { useSyncExternalStoreWithSelector: En } = l, Dn = (e) => e;
2897
+ function On(e, t = Dn, n) {
2898
+ let r = En(e.subscribe, e.getState, e.getServerState || e.getInitialState, t, n);
2899
+ return Tn(r), r;
2894
2900
  }
2895
- var On = (e) => {
2896
- let t = typeof e == "function" ? Cn(e) : e, n = (e, n) => Dn(t, e, n);
2901
+ var kn = (e) => {
2902
+ let t = typeof e == "function" ? wn(e) : e, n = (e, n) => On(t, e, n);
2897
2903
  return Object.assign(n, t), n;
2898
- }, kn = (e) => e ? On(e) : On, An = (e) => e.room ?? (e.mine ? e.to : e.from), q = (e, t) => ({
2904
+ }, An = (e) => e ? kn(e) : kn, jn = (e) => e.room ?? (e.mine ? e.to : e.from), q = (e, t) => ({
2899
2905
  peer: e,
2900
2906
  kind: t && e.endsWith("@" + t) ? "group" : "chat",
2901
2907
  messages: [],
@@ -2903,13 +2909,13 @@ var On = (e) => {
2903
2909
  typing: !1,
2904
2910
  loaded: !1,
2905
2911
  complete: !1
2906
- }), jn = (e, t, n, r) => {
2912
+ }), Mn = (e, t, n, r) => {
2907
2913
  if (e.includes(t)) return e;
2908
2914
  let i = [t, ...e];
2909
2915
  if (i.length <= n) return i;
2910
2916
  let a = [...i].reverse().find((e) => e !== r);
2911
2917
  return i.filter((e) => e !== a);
2912
- }, J = kn((e, t) => ({
2918
+ }, J = An((e, t) => ({
2913
2919
  me: "",
2914
2920
  mucHost: "",
2915
2921
  status: "connecting",
@@ -2974,7 +2980,7 @@ var On = (e) => {
2974
2980
  seed: (t, n) => e((e) => {
2975
2981
  let r = { ...e.conversations };
2976
2982
  for (let i of t) {
2977
- let t = An(i);
2983
+ let t = jn(i);
2978
2984
  if (!t || t === n) continue;
2979
2985
  let a = r[t] ?? q(t, e.mucHost);
2980
2986
  if (a.messages.some((e) => e.id === i.id)) continue;
@@ -2997,7 +3003,7 @@ var On = (e) => {
2997
3003
  let i = e.conversations[t] ?? q(t, e.mucHost), a = i.messages.filter((e) => e.id !== n.id && !(e.pending && n.mine && e.body === n.body && e.oob === n.oob)), o = a.length;
2998
3004
  for (; o > 0 && a[o - 1].ts > n.ts;) o--;
2999
3005
  a.splice(o, 0, n);
3000
- let s = e.open === t, c = r?.live && !n.mine && !s ? i.unread + 1 : i.unread, l = jn(e.order, t, e.maxHeads, e.open);
3006
+ let s = e.open === t, c = r?.live && !n.mine && !s ? i.unread + 1 : i.unread, l = Mn(e.order, t, e.maxHeads, e.open);
3001
3007
  return {
3002
3008
  conversations: {
3003
3009
  ...e.conversations,
@@ -3048,7 +3054,7 @@ var On = (e) => {
3048
3054
  ...e.conversations,
3049
3055
  [t]: q(t, e.mucHost)
3050
3056
  },
3051
- order: jn(e.order, t, e.maxHeads, e.open),
3057
+ order: Mn(e.order, t, e.maxHeads, e.open),
3052
3058
  open: t,
3053
3059
  picker: !1
3054
3060
  })),
@@ -3077,15 +3083,15 @@ var On = (e) => {
3077
3083
  }));
3078
3084
  //#endregion
3079
3085
  //#region src/api.ts
3080
- async function Mn(e, t, n) {
3086
+ async function Nn(e, t, n) {
3081
3087
  let r = await fetch(`https://${e}/api${n}`, { headers: { Authorization: `Bearer ${t}` } });
3082
3088
  if (!r.ok) throw Error(`${n}: HTTP ${r.status}`);
3083
3089
  return await r.json();
3084
3090
  }
3085
- async function Nn(e, t, n) {
3086
- let r = await Mn(e, t, "/user/endpoints/all"), i = {};
3091
+ async function Pn(e, t, n) {
3092
+ let r = await Nn(e, t, "/user/endpoints/all"), i = {};
3087
3093
  try {
3088
- i = await Mn(e, t, "/user/all_avatars");
3094
+ i = await Nn(e, t, "/user/all_avatars");
3089
3095
  } catch {}
3090
3096
  return Object.values(r).filter((e) => e.username && e.username !== n).map((e) => ({
3091
3097
  username: e.username,
@@ -3094,12 +3100,12 @@ async function Nn(e, t, n) {
3094
3100
  presence: e.mainPresence
3095
3101
  })).sort((e, t) => e.name.localeCompare(t.name));
3096
3102
  }
3097
- async function Pn(e, t) {
3103
+ async function Fn(e, t) {
3098
3104
  let n = await fetch(`https://${e}/chat-gw/push/mobile`, { headers: { Authorization: `Bearer ${t}` } });
3099
3105
  if (!n.ok) throw Error(`push/mobile: HTTP ${n.status}`);
3100
3106
  return (await n.json()).users;
3101
3107
  }
3102
- async function Fn(e, t, n) {
3108
+ async function In(e, t, n) {
3103
3109
  let r = await fetch(`https://${e}/chat-gw/conversations/${encodeURIComponent(n)}`, {
3104
3110
  method: "DELETE",
3105
3111
  headers: { Authorization: `Bearer ${t}` }
@@ -3108,16 +3114,16 @@ async function Fn(e, t, n) {
3108
3114
  }
3109
3115
  //#endregion
3110
3116
  //#region src/push.ts
3111
- var In = (e) => {
3117
+ var Ln = (e) => {
3112
3118
  let t = atob((e + "=".repeat((4 - e.length % 4) % 4)).replace(/-/g, "+").replace(/_/g, "/"));
3113
3119
  return Uint8Array.from(t, (e) => e.charCodeAt(0));
3114
- }, Ln = !1;
3115
- function Rn() {
3116
- Ln || (Ln = !0, navigator.serviceWorker.addEventListener("message", (e) => {
3120
+ }, Rn = !1;
3121
+ function zn() {
3122
+ Rn || (Rn = !0, navigator.serviceWorker.addEventListener("message", (e) => {
3117
3123
  e.data?.type === "chat-island-open" && typeof e.data.username == "string" && window.dispatchEvent(new CustomEvent("chat-island-open", { detail: { username: e.data.username } }));
3118
3124
  }));
3119
3125
  }
3120
- async function zn(e, t) {
3126
+ async function Bn(e, t) {
3121
3127
  if (!("serviceWorker" in navigator) || !("PushManager" in window)) throw Error("push not supported by this browser");
3122
3128
  if (Notification.permission === "denied" || Notification.permission !== "granted" && await Notification.requestPermission() !== "granted") return null;
3123
3129
  let n = `https://${e.host}/chat-gw`, r = await fetch(`${n}/push/vapid`);
@@ -3126,7 +3132,7 @@ async function zn(e, t) {
3126
3132
  await navigator.serviceWorker.ready;
3127
3133
  let o = await a.pushManager.getSubscription() ?? await a.pushManager.subscribe({
3128
3134
  userVisibleOnly: !0,
3129
- applicationServerKey: In(i.publicKey)
3135
+ applicationServerKey: Ln(i.publicKey)
3130
3136
  }), s = await fetch(`${n}/push/web`, {
3131
3137
  method: "POST",
3132
3138
  headers: {
@@ -3137,7 +3143,7 @@ async function zn(e, t) {
3137
3143
  });
3138
3144
  if (!s.ok) throw Error(`push/web: HTTP ${s.status} ${(await s.text()).slice(0, 120)}`);
3139
3145
  let c = await s.json();
3140
- return Rn(), {
3146
+ return zn(), {
3141
3147
  node: c.node,
3142
3148
  service: c.service
3143
3149
  };
@@ -3153,8 +3159,8 @@ function X(e, t) {
3153
3159
  }
3154
3160
  //#endregion
3155
3161
  //#region src/components/Avatar.tsx
3156
- var Bn = (e) => e.split(/\s+/).slice(0, 2).map((e) => e[0]?.toUpperCase() ?? "").join("");
3157
- function Vn({ contact: e, username: t, size: n = 40 }) {
3162
+ var Vn = (e) => e.split(/\s+/).slice(0, 2).map((e) => e[0]?.toUpperCase() ?? "").join("");
3163
+ function Hn({ contact: e, username: t, size: n = 40 }) {
3158
3164
  let r = e?.name || t, i = {
3159
3165
  width: n,
3160
3166
  height: n,
@@ -3169,13 +3175,13 @@ function Vn({ contact: e, username: t, size: n = 40 }) {
3169
3175
  }) : /* @__PURE__ */ d("div", {
3170
3176
  style: i,
3171
3177
  className: "ci-rounded-full ci-shrink-0 ci-flex ci-items-center ci-justify-center ci-font-medium ci-bg-gray-700 ci-text-gray-50 dark:ci-bg-gray-300 dark:ci-text-gray-900",
3172
- children: Bn(r)
3178
+ children: Vn(r)
3173
3179
  });
3174
3180
  }
3175
- function Hn({ online: e, presence: t, mobile: n }) {
3181
+ function Un({ online: e, presence: t, mobile: n }) {
3176
3182
  return /* @__PURE__ */ d("span", { className: `ci-absolute ci-bottom-0 ci-right-0 ci-w-3 ci-h-3 ci-rounded-full ci-ring-2 ci-ring-gray-50 dark:ci-ring-gray-950 ${t === "dnd" || t === "busy" ? "ci-bg-phoneIslandClose dark:ci-bg-phoneIslandCloseDark" : e || n ? "ci-bg-phoneIslandCall dark:ci-bg-phoneIslandCallDark" : "ci-bg-gray-400 dark:ci-bg-gray-600"}` });
3177
3183
  }
3178
- function Un({ name: e, size: t = 40, avatar: n }) {
3184
+ function Wn({ name: e, size: t = 40, avatar: n }) {
3179
3185
  let r = {
3180
3186
  width: t,
3181
3187
  height: t,
@@ -3190,12 +3196,12 @@ function Un({ name: e, size: t = 40, avatar: n }) {
3190
3196
  }) : /* @__PURE__ */ d("div", {
3191
3197
  style: r,
3192
3198
  className: "ci-rounded-full ci-shrink-0 ci-flex ci-items-center ci-justify-center ci-font-medium ci-bg-iconSecondary dark:ci-bg-iconSecondaryDark ci-text-white",
3193
- children: Bn(e || "G")
3199
+ children: Vn(e || "G")
3194
3200
  });
3195
3201
  }
3196
3202
  //#endregion
3197
3203
  //#region src/components/Button.tsx
3198
- var Wn = "ci-flex ci-content-center ci-items-center ci-justify-center ci-tracking-wide ci-duration-200 ci-transform ci-outline-none focus:ci-ring-2 focus:ci-z-20 focus:ci-ring-offset-2 disabled:ci-opacity-40 disabled:ci-cursor-not-allowed ci-border ci-border-transparent focus:ci-ring-offset-white dark:focus:ci-ring-offset-black ci-text-sm ci-leading-4 ci-transition-colors ci-shrink-0 ci-font-light", Gn = {
3204
+ var Gn = "ci-flex ci-content-center ci-items-center ci-justify-center ci-tracking-wide ci-duration-200 ci-transform ci-outline-none focus:ci-ring-2 focus:ci-z-20 focus:ci-ring-offset-2 disabled:ci-opacity-40 disabled:ci-cursor-not-allowed ci-border ci-border-transparent focus:ci-ring-offset-white dark:focus:ci-ring-offset-black ci-text-sm ci-leading-4 ci-transition-colors ci-shrink-0 ci-font-light", Kn = {
3199
3205
  default: "ci-bg-phoneIslandActive dark:ci-bg-phoneIslandActiveDark hover:ci-bg-gray-500 dark:hover:ci-bg-gray-50 focus:ci-ring-emerald-500 dark:focus:ci-ring-emerald-300 ci-text-primaryInvert dark:ci-text-primaryInvertDark ci-h-12 ci-w-12 ci-rounded-full",
3200
3206
  green: "ci-bg-phoneIslandCall dark:ci-bg-phoneIslandCallDark hover:ci-bg-phoneIslandCallHover dark:hover:ci-bg-phoneIslandCallHoverDark focus:ci-ring-green-500 ci-text-white dark:ci-text-gray-950 ci-h-12 ci-w-12 ci-rounded-full",
3201
3207
  red: "ci-bg-phoneIslandClose dark:ci-bg-phoneIslandCloseDark hover:ci-bg-phoneIslandCloseHover dark:hover:ci-bg-phoneIslandCloseHoverDark focus:ci-ring-emerald-500 ci-text-white dark:ci-text-gray-950 ci-h-12 ci-w-12 ci-rounded-full",
@@ -3208,7 +3214,7 @@ function Z({ variant: e, className: t = "", children: n, ...r }) {
3208
3214
  return /* @__PURE__ */ d("button", {
3209
3215
  type: "button",
3210
3216
  "aria-label": r["aria-label"] ?? r.title,
3211
- className: `${Wn} ${Gn[e]} ${t}`,
3217
+ className: `${Gn} ${Kn[e]} ${t}`,
3212
3218
  ...r,
3213
3219
  children: n
3214
3220
  });
@@ -3369,7 +3375,7 @@ var Q = {
3369
3375
  };
3370
3376
  //#endregion
3371
3377
  //#region src/components/Dock.tsx
3372
- function Kn({ onDragStart: e, pushButton: t = !0 }) {
3378
+ function qn({ onDragStart: e, pushButton: t = !0 }) {
3373
3379
  let { order: n, open: r, conversations: i, contacts: a, online: o, mobile: s, openChat: c, removeHead: l, picker: p, setPicker: m, status: h, push: g, enablePush: _, newChatButton: v } = J(w((e) => ({
3374
3380
  order: e.order,
3375
3381
  open: e.open,
@@ -3399,15 +3405,15 @@ function Kn({ onDragStart: e, pushButton: t = !0 }) {
3399
3405
  title: t?.kind === "group" ? t.name ?? e : a[e]?.name ?? e,
3400
3406
  onClick: () => n ? J.getState().closeChat() : c(e),
3401
3407
  className: `ci-relative ci-rounded-full ci-shadow-lg ci-transition-transform hover:ci-scale-105 ci-ring-2 ci-border-0 ci-p-0 ci-bg-transparent ${n ? "ci-ring-iconSecondary dark:ci-ring-iconSecondaryDark" : "ci-ring-gray-50 dark:ci-ring-gray-950"}`,
3402
- children: [t?.kind === "group" ? /* @__PURE__ */ d(Un, {
3408
+ children: [t?.kind === "group" ? /* @__PURE__ */ d(Wn, {
3403
3409
  name: t.name ?? e,
3404
3410
  size: 48,
3405
3411
  avatar: t.avatar
3406
- }) : /* @__PURE__ */ f(u, { children: [/* @__PURE__ */ d(Vn, {
3412
+ }) : /* @__PURE__ */ f(u, { children: [/* @__PURE__ */ d(Hn, {
3407
3413
  contact: a[e],
3408
3414
  username: e,
3409
3415
  size: 48
3410
- }), /* @__PURE__ */ d(Hn, {
3416
+ }), /* @__PURE__ */ d(Un, {
3411
3417
  online: o[e],
3412
3418
  presence: a[e]?.presence,
3413
3419
  mobile: s[e]
@@ -3443,7 +3449,7 @@ function Kn({ onDragStart: e, pushButton: t = !0 }) {
3443
3449
  }
3444
3450
  //#endregion
3445
3451
  //#region src/shortcodes.ts
3446
- var qn = {
3452
+ var Jn = {
3447
3453
  "+1": "👍",
3448
3454
  thumbsup: "👍",
3449
3455
  "-1": "👎",
@@ -3637,13 +3643,13 @@ var qn = {
3637
3643
  zzz: "💤",
3638
3644
  sweat_drops: "💦",
3639
3645
  dash: "💨"
3640
- }, Jn = /(```[\s\S]*?(?:```|$)|`[^`\n]*`?)/g, Yn = /:([a-z0-9_+-]+):/g, Xn = (e) => e.replace(Yn, (e, t) => qn[t] ?? e);
3646
+ }, Yn = /(```[\s\S]*?(?:```|$)|`[^`\n]*`?)/g, Xn = /:([a-z0-9_+-]+):/g, Zn = (e) => e.replace(Xn, (e, t) => Jn[t] ?? e);
3641
3647
  function $(e) {
3642
- return e.includes(":") ? e.split(Jn).map((e, t) => t % 2 ? e : Xn(e)).join("") : e;
3648
+ return e.includes(":") ? e.split(Yn).map((e, t) => t % 2 ? e : Zn(e)).join("") : e;
3643
3649
  }
3644
3650
  //#endregion
3645
3651
  //#region src/components/EmojiPicker.tsx
3646
- var Zn = [
3652
+ var Qn = [
3647
3653
  {
3648
3654
  label: "Smileys",
3649
3655
  icon: "😀",
@@ -3674,7 +3680,7 @@ var Zn = [
3674
3680
  icon: "☕",
3675
3681
  emojis: "☕ 🍵 🥤 🍕 🍔 🍟 🌭 🥪 🌮 🍝 🍣 🍩 🍪 🍫 🍎 🍌 🍓 🥐 🚗 🚕 🚌 🚆 ✈️ 🚀 🏠 🏢 🏖️ 🌍 ☀️ 🌤️ 🌧️ ⛈️ ❄️ ⚡ 🌈 🌙"
3676
3682
  }
3677
- ], Qn = [
3683
+ ], $n = [
3678
3684
  "👍",
3679
3685
  "❤️",
3680
3686
  "😂",
@@ -3682,7 +3688,7 @@ var Zn = [
3682
3688
  "😢",
3683
3689
  "🙏"
3684
3690
  ];
3685
- function $n({ onPick: e, onClose: t, className: n = "" }) {
3691
+ function er({ onPick: e, onClose: t, className: n = "" }) {
3686
3692
  let [r, a] = c(0), o = s(null);
3687
3693
  return i(() => {
3688
3694
  let e = (e) => o.current && !o.current.contains(e.target) && t(), n = (e) => {
@@ -3698,7 +3704,7 @@ function $n({ onPick: e, onClose: t, className: n = "" }) {
3698
3704
  className: `ci-z-30 ci-w-[21rem] ci-max-w-full ci-rounded-2xl ci-bg-gray-50 dark:ci-bg-gray-950 ci-shadow-2xl ci-ring-1 ci-ring-gray-300 dark:ci-ring-gray-700 ci-select-none ${n}`,
3699
3705
  children: [/* @__PURE__ */ d("div", {
3700
3706
  className: "ci-flex ci-gap-1 ci-px-2 ci-pt-2 ci-border-b ci-border-gray-300 dark:ci-border-gray-700",
3701
- children: Zn.map((e, t) => /* @__PURE__ */ d("button", {
3707
+ children: Qn.map((e, t) => /* @__PURE__ */ d("button", {
3702
3708
  type: "button",
3703
3709
  title: e.label,
3704
3710
  "aria-label": e.label,
@@ -3712,7 +3718,7 @@ function $n({ onPick: e, onClose: t, className: n = "" }) {
3712
3718
  }, e.label))
3713
3719
  }), /* @__PURE__ */ d("div", {
3714
3720
  className: "ci-grid ci-grid-cols-7 ci-gap-1 ci-p-2 ci-h-64 ci-overflow-y-auto",
3715
- children: Zn[r].emojis.split(" ").map((t) => /* @__PURE__ */ d("button", {
3721
+ children: Qn[r].emojis.split(" ").map((t) => /* @__PURE__ */ d("button", {
3716
3722
  type: "button",
3717
3723
  onClick: () => e(t),
3718
3724
  style: {
@@ -3727,27 +3733,27 @@ function $n({ onPick: e, onClose: t, className: n = "" }) {
3727
3733
  }
3728
3734
  //#endregion
3729
3735
  //#region src/components/MessageList.tsx
3730
- var er = (e) => /\.(png|jpe?g|gif|webp|avif|svg)(\?|$)/i.test(e), tr = (e) => /\.(webm|ogg|oga|opus|mp3|m4a|wav)(\?|$)/i.test(e), nr = (e) => {
3736
+ var tr = (e) => /\.(png|jpe?g|gif|webp|avif|svg)(\?|$)/i.test(e), nr = (e) => /\.(webm|ogg|oga|opus|mp3|m4a|wav)(\?|$)/i.test(e), rr = (e) => {
3731
3737
  let t = e.split("/").pop() || "file";
3732
3738
  try {
3733
3739
  return decodeURIComponent(t);
3734
3740
  } catch {
3735
3741
  return t;
3736
3742
  }
3737
- }, rr = (e) => {
3743
+ }, ir = (e) => {
3738
3744
  try {
3739
3745
  return new URL(e).protocol === "https:";
3740
3746
  } catch {
3741
3747
  return !1;
3742
3748
  }
3743
- }, ir = (e) => new Date(e).toLocaleTimeString([], {
3749
+ }, ar = (e) => new Date(e).toLocaleTimeString([], {
3744
3750
  hour: "2-digit",
3745
3751
  minute: "2-digit"
3746
- }), ar = (e) => new Date(e).toLocaleDateString([], {
3752
+ }), or = (e) => new Date(e).toLocaleDateString([], {
3747
3753
  weekday: "short",
3748
3754
  day: "numeric",
3749
3755
  month: "short"
3750
- }), or = (e, t) => new Date(e).toDateString() === new Date(t).toDateString(), sr = (e) => {
3756
+ }), sr = (e, t) => new Date(e).toDateString() === new Date(t).toDateString(), cr = (e) => {
3751
3757
  if (!e.startsWith("{\"")) return null;
3752
3758
  try {
3753
3759
  let t = JSON.parse(e);
@@ -3758,17 +3764,17 @@ var er = (e) => /\.(png|jpe?g|gif|webp|avif|svg)(\?|$)/i.test(e), tr = (e) => /\
3758
3764
  } catch {
3759
3765
  return null;
3760
3766
  }
3761
- }, cr = n(function({ url: e }) {
3762
- return rr(e) ? er(e) ? /* @__PURE__ */ d("a", {
3767
+ }, lr = n(function({ url: e }) {
3768
+ return ir(e) ? tr(e) ? /* @__PURE__ */ d("a", {
3763
3769
  href: e,
3764
3770
  target: "_blank",
3765
3771
  rel: "noreferrer",
3766
3772
  children: /* @__PURE__ */ d("img", {
3767
3773
  src: e,
3768
- alt: nr(e),
3774
+ alt: rr(e),
3769
3775
  className: "ci-max-w-full ci-max-h-60 ci-rounded-2xl ci-block"
3770
3776
  })
3771
- }) : tr(e) ? /* @__PURE__ */ d("audio", {
3777
+ }) : nr(e) ? /* @__PURE__ */ d("audio", {
3772
3778
  controls: !0,
3773
3779
  src: e,
3774
3780
  className: "ci-max-w-full"
@@ -3785,15 +3791,15 @@ var er = (e) => /\.(png|jpe?g|gif|webp|avif|svg)(\?|$)/i.test(e), tr = (e) => /\
3785
3791
  stroke: "currentColor",
3786
3792
  strokeWidth: "2",
3787
3793
  children: /* @__PURE__ */ d("path", { d: "M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48" })
3788
- }), nr(e)]
3794
+ }), rr(e)]
3789
3795
  }) : /* @__PURE__ */ d("span", {
3790
3796
  className: "ci-break-all",
3791
3797
  children: e
3792
3798
  });
3793
- }), lr = /(`[^`\n]+`)|(\*\*[^*\n]+\*\*|__[^_\n]+__)|(~~[^~\n]+~~)|(\*[^*\s][^*\n]*\*|_[^_\s][^_\n]*_)|\[([^\]\n]+)\]\((https?:\/\/[^\s)]+)\)|(https?:\/\/[^\s<]+)/g;
3794
- function ur({ text: e }) {
3799
+ }), ur = /(`[^`\n]+`)|(\*\*[^*\n]+\*\*|__[^_\n]+__)|(~~[^~\n]+~~)|(\*[^*\s][^*\n]*\*|_[^_\s][^_\n]*_)|\[([^\]\n]+)\]\((https?:\/\/[^\s)]+)\)|(https?:\/\/[^\s<]+)/g;
3800
+ function dr({ text: e }) {
3795
3801
  let t = [], n = 0;
3796
- for (let r of e.matchAll(lr)) {
3802
+ for (let r of e.matchAll(ur)) {
3797
3803
  let i = r[0], a = r.index ?? 0;
3798
3804
  a > n && t.push($(e.slice(n, a))), r[1] ? t.push(/* @__PURE__ */ d("code", {
3799
3805
  className: "ci-px-1 ci-py-0.5 ci-rounded ci-bg-black/10 dark:ci-bg-white/10 ci-font-mono ci-text-[0.85em]",
@@ -3814,17 +3820,17 @@ function ur({ text: e }) {
3814
3820
  }
3815
3821
  return n < e.length && t.push($(e.slice(n))), /* @__PURE__ */ d(u, { children: t });
3816
3822
  }
3817
- var dr = n(function({ text: e }) {
3823
+ var fr = n(function({ text: e }) {
3818
3824
  let t = e.split(/```[^\n]*\n?([\s\S]*?)```/g);
3819
3825
  return /* @__PURE__ */ d("span", {
3820
3826
  className: "ci-whitespace-pre-wrap ci-break-words",
3821
3827
  children: t.map((e, t) => t % 2 ? /* @__PURE__ */ d("pre", {
3822
3828
  className: "ci-my-1 ci-p-2 ci-rounded-xl ci-bg-black/10 dark:ci-bg-white/10 ci-font-mono ci-text-xs ci-overflow-x-auto ci-whitespace-pre",
3823
3829
  children: e.replace(/\n$/, "")
3824
- }, t) : /* @__PURE__ */ d(ur, { text: e.replace(/^(\s*)[-*] (?=\S)/gm, "$1• ") }, t))
3830
+ }, t) : /* @__PURE__ */ d(dr, { text: e.replace(/^(\s*)[-*] (?=\S)/gm, "$1• ") }, t))
3825
3831
  });
3826
3832
  });
3827
- function fr({ text: e, count: t }) {
3833
+ function pr({ text: e, count: t }) {
3828
3834
  return /* @__PURE__ */ f("span", {
3829
3835
  className: "ci-italic ci-opacity-80",
3830
3836
  children: [
@@ -3837,7 +3843,7 @@ function fr({ text: e, count: t }) {
3837
3843
  ]
3838
3844
  });
3839
3845
  }
3840
- function pr({ forMsg: e, me: t, onReact: n, nameOf: r, mine: i }) {
3846
+ function mr({ forMsg: e, me: t, onReact: n, nameOf: r, mine: i }) {
3841
3847
  if (!e) return null;
3842
3848
  let a = /* @__PURE__ */ new Map();
3843
3849
  for (let [t, n] of Object.entries(e)) for (let e of n) a.set(e, [...a.get(e) ?? [], t]);
@@ -3862,7 +3868,7 @@ function pr({ forMsg: e, me: t, onReact: n, nameOf: r, mine: i }) {
3862
3868
  })
3863
3869
  }) : null;
3864
3870
  }
3865
- function mr({ messages: e, typing: t, onLoadOlder: n, hasOlder: r, group: a, reactions: o, me: l = "", onReact: u }) {
3871
+ function hr({ messages: e, typing: t, onLoadOlder: n, hasOlder: r, group: a, reactions: o, me: l = "", onReact: u }) {
3866
3872
  let p = J((e) => e.contacts), m = s(null), h = s(!0), [g, _] = c(null), [v, y] = c(null), b = (e) => p[e]?.name ?? e;
3867
3873
  i(() => {
3868
3874
  let e = m.current;
@@ -3896,7 +3902,7 @@ function mr({ messages: e, typing: t, onLoadOlder: n, hasOlder: r, group: a, rea
3896
3902
  children: "Scroll up for older messages"
3897
3903
  }),
3898
3904
  e.map((t, n) => {
3899
- let r = e[n - 1], i = !r || !or(r.ts, t.ts), s = r && !i && r.mine === t.mine && r.nick === t.nick && t.ts - r.ts < 12e4, c = a && !t.mine && t.nick ? b(t.nick) : null, m = t.oid, h = !!u && !!m && !t.pending, v = h && /* @__PURE__ */ d("button", {
3905
+ let r = e[n - 1], i = !r || !sr(r.ts, t.ts), s = r && !i && r.mine === t.mine && r.nick === t.nick && t.ts - r.ts < 12e4, c = a && !t.mine && t.nick ? b(t.nick) : null, m = t.oid, h = !!u && !!m && !t.pending, v = h && /* @__PURE__ */ d("button", {
3900
3906
  type: "button",
3901
3907
  title: "React",
3902
3908
  "aria-label": "React to this message",
@@ -3908,14 +3914,14 @@ function mr({ messages: e, typing: t, onLoadOlder: n, hasOlder: r, group: a, rea
3908
3914
  });
3909
3915
  return /* @__PURE__ */ f("div", { children: [i && /* @__PURE__ */ d("div", {
3910
3916
  className: "ci-text-center ci-text-xs ci-text-gray-500 dark:ci-text-gray-400 ci-py-2",
3911
- children: ar(t.ts)
3917
+ children: or(t.ts)
3912
3918
  }), /* @__PURE__ */ f("div", {
3913
3919
  className: `ci-group ci-flex ci-items-start ci-gap-1.5 ${t.mine ? "ci-justify-end" : "ci-justify-start"} ${s ? "ci-mt-0.5" : "ci-mt-2"}`,
3914
3920
  children: [
3915
3921
  c && /* @__PURE__ */ d("span", {
3916
3922
  className: "ci-w-7 ci-shrink-0",
3917
3923
  title: c,
3918
- children: !s && /* @__PURE__ */ d(Vn, {
3924
+ children: !s && /* @__PURE__ */ d(Hn, {
3919
3925
  contact: p[t.nick],
3920
3926
  username: t.nick,
3921
3927
  size: 28
@@ -3929,7 +3935,7 @@ function mr({ messages: e, typing: t, onLoadOlder: n, hasOlder: r, group: a, rea
3929
3935
  role: "menu",
3930
3936
  onClick: (e) => e.stopPropagation(),
3931
3937
  className: `ci-absolute ci-bottom-full ci-mb-1 ci-z-20 ci-flex ci-items-center ci-gap-0.5 ci-p-1 ci-rounded-full ci-bg-gray-50 dark:ci-bg-gray-950 ci-shadow-xl ci-ring-1 ci-ring-gray-300 dark:ci-ring-gray-700 ${t.mine ? "ci-right-0" : "ci-left-0"}`,
3932
- children: [Qn.map((e) => /* @__PURE__ */ d("button", {
3938
+ children: [$n.map((e) => /* @__PURE__ */ d("button", {
3933
3939
  type: "button",
3934
3940
  role: "menuitem",
3935
3941
  "aria-label": e,
@@ -3953,22 +3959,22 @@ function mr({ messages: e, typing: t, onLoadOlder: n, hasOlder: r, group: a, rea
3953
3959
  })]
3954
3960
  }),
3955
3961
  /* @__PURE__ */ f("div", {
3956
- title: ir(t.ts),
3957
- onDoubleClick: () => h && S(m, Qn[0]),
3962
+ title: ar(t.ts),
3963
+ onDoubleClick: () => h && S(m, $n[0]),
3958
3964
  className: `ci-px-3.5 ci-py-2 ci-rounded-3xl ci-text-sm ci-select-text ci-cursor-text ${t.mine ? "ci-bg-gray-700 ci-text-gray-50 dark:ci-bg-gray-300 dark:ci-text-gray-900 ci-rounded-br-lg" : "ci-bg-elevationL2 ci-text-gray-900 dark:ci-bg-elevationL2Dark dark:ci-text-white ci-rounded-bl-lg"} ${t.pending ? "ci-opacity-60" : ""}`,
3959
3965
  children: [
3960
- t.oob ? /* @__PURE__ */ d(cr, { url: t.oob }) : sr(t.body) ? /* @__PURE__ */ d(fr, { ...sr(t.body) }) : /* @__PURE__ */ d(dr, { text: t.body }),
3961
- t.oob && t.body && t.body !== t.oob && t.body !== nr(t.oob) && /* @__PURE__ */ d("div", {
3966
+ t.oob ? /* @__PURE__ */ d(lr, { url: t.oob }) : cr(t.body) ? /* @__PURE__ */ d(pr, { ...cr(t.body) }) : /* @__PURE__ */ d(fr, { text: t.body }),
3967
+ t.oob && t.body && t.body !== t.oob && t.body !== rr(t.oob) && /* @__PURE__ */ d("div", {
3962
3968
  className: "ci-text-xs ci-opacity-80 ci-mt-1",
3963
3969
  children: t.body
3964
3970
  }),
3965
3971
  /* @__PURE__ */ d("span", {
3966
3972
  className: "ci-block ci-text-right ci-text-[10px] ci-leading-none ci-opacity-60 ci-mt-1",
3967
- children: ir(t.ts)
3973
+ children: ar(t.ts)
3968
3974
  })
3969
3975
  ]
3970
3976
  }),
3971
- m && /* @__PURE__ */ d(pr, {
3977
+ m && /* @__PURE__ */ d(mr, {
3972
3978
  forMsg: o?.[m],
3973
3979
  me: l,
3974
3980
  mine: t.mine,
@@ -3989,7 +3995,7 @@ function mr({ messages: e, typing: t, onLoadOlder: n, hasOlder: r, group: a, rea
3989
3995
  })
3990
3996
  })
3991
3997
  ]
3992
- }), v && /* @__PURE__ */ d($n, {
3998
+ }), v && /* @__PURE__ */ d(er, {
3993
3999
  className: "ci-absolute ci-bottom-2 ci-left-1/2 ci--translate-x-1/2",
3994
4000
  onPick: (e) => S(v, e),
3995
4001
  onClose: () => y(null)
@@ -3998,7 +4004,7 @@ function mr({ messages: e, typing: t, onLoadOlder: n, hasOlder: r, group: a, rea
3998
4004
  }
3999
4005
  //#endregion
4000
4006
  //#region src/ogg.ts
4001
- function hr(e, t, n) {
4007
+ function gr(e, t, n) {
4002
4008
  let r = e[t];
4003
4009
  if (r === void 0) return null;
4004
4010
  let i = 1;
@@ -4012,7 +4018,7 @@ function hr(e, t, n) {
4012
4018
  unknown: !n && o
4013
4019
  };
4014
4020
  }
4015
- var gr = /* @__PURE__ */ new Set([
4021
+ var _r = /* @__PURE__ */ new Set([
4016
4022
  408125543,
4017
4023
  524531317,
4018
4024
  374648427,
@@ -4020,18 +4026,18 @@ var gr = /* @__PURE__ */ new Set([
4020
4026
  225,
4021
4027
  160
4022
4028
  ]);
4023
- function _r(e) {
4029
+ function vr(e) {
4024
4030
  let t = {
4025
4031
  channels: 1,
4026
4032
  packets: []
4027
4033
  }, n = 0;
4028
4034
  for (; n < e.length;) {
4029
- let r = hr(e, n, !0);
4035
+ let r = gr(e, n, !0);
4030
4036
  if (!r) break;
4031
- let i = hr(e, n + r.len, !1);
4037
+ let i = gr(e, n + r.len, !1);
4032
4038
  if (!i) break;
4033
4039
  let a = n + r.len + i.len;
4034
- if (gr.has(r.value)) {
4040
+ if (_r.has(r.value)) {
4035
4041
  n = a;
4036
4042
  continue;
4037
4043
  }
@@ -4040,14 +4046,14 @@ function _r(e) {
4040
4046
  if (r.value === 25506) t.head = e.slice(a, o);
4041
4047
  else if (r.value === 159) t.channels = e[a] || 1;
4042
4048
  else if (r.value === 163 || r.value === 161) {
4043
- let n = hr(e, a, !1);
4049
+ let n = gr(e, a, !1);
4044
4050
  n && (e[a + n.len + 2] >> 1 & 3 || t.packets.push(e.slice(a + n.len + 3, o)));
4045
4051
  }
4046
4052
  n = o;
4047
4053
  }
4048
4054
  return t;
4049
4055
  }
4050
- function vr(e) {
4056
+ function yr(e) {
4051
4057
  if (!e.length) return 0;
4052
4058
  let t = e[0], n = t >> 3, r;
4053
4059
  r = n < 12 ? [
@@ -4064,7 +4070,7 @@ function vr(e) {
4064
4070
  let i = t & 3, a = i === 0 ? 1 : i === 3 ? (e[1] ?? 0) & 63 : 2;
4065
4071
  return Math.round(a * r * 48);
4066
4072
  }
4067
- var yr = (() => {
4073
+ var br = (() => {
4068
4074
  let e = /* @__PURE__ */ new Uint32Array(256);
4069
4075
  for (let t = 0; t < 256; t++) {
4070
4076
  let n = t << 24;
@@ -4073,12 +4079,12 @@ var yr = (() => {
4073
4079
  }
4074
4080
  return e;
4075
4081
  })();
4076
- function br(e) {
4082
+ function xr(e) {
4077
4083
  let t = 0;
4078
- for (let n = 0; n < e.length; n++) t = (t << 8 ^ yr[(t >>> 24 ^ e[n]) & 255]) >>> 0;
4084
+ for (let n = 0; n < e.length; n++) t = (t << 8 ^ br[(t >>> 24 ^ e[n]) & 255]) >>> 0;
4079
4085
  return t;
4080
4086
  }
4081
- function xr(e, t, n, r, i) {
4087
+ function Sr(e, t, n, r, i) {
4082
4088
  let a = [];
4083
4089
  for (let t of e) {
4084
4090
  let e = t.length;
@@ -4094,29 +4100,29 @@ function xr(e, t, n, r, i) {
4094
4100
  ], 0), s[5] = i, c.setUint32(6, t % 4294967296, !0), c.setUint32(10, Math.floor(t / 4294967296), !0), c.setUint32(14, n, !0), c.setUint32(18, r, !0), s[26] = a.length, s.set(a, 27);
4095
4101
  let l = 27 + a.length;
4096
4102
  for (let t of e) s.set(t, l), l += t.length;
4097
- return c.setUint32(22, br(s), !0), s;
4103
+ return c.setUint32(22, xr(s), !0), s;
4098
4104
  }
4099
- function Sr(e) {
4105
+ function Cr(e) {
4100
4106
  let t = /* @__PURE__ */ new Uint8Array(19), n = new DataView(t.buffer);
4101
4107
  return t.set(new TextEncoder().encode("OpusHead"), 0), t[8] = 1, t[9] = e, n.setUint16(10, 312, !0), n.setUint32(12, 48e3, !0), t;
4102
4108
  }
4103
- function Cr() {
4109
+ function wr() {
4104
4110
  let e = new TextEncoder().encode("chat-island"), t = new Uint8Array(12 + e.length + 4);
4105
4111
  return t.set(new TextEncoder().encode("OpusTags"), 0), new DataView(t.buffer).setUint32(8, e.length, !0), t.set(e, 12), t;
4106
4112
  }
4107
- function wr(e) {
4108
- let { head: t, channels: n, packets: r } = _r(e);
4113
+ function Tr(e) {
4114
+ let { head: t, channels: n, packets: r } = vr(e);
4109
4115
  if (!r.length) return null;
4110
- let i = t && t.length >= 19 && new TextDecoder().decode(t.slice(0, 8)) === "OpusHead", a = Math.random() * 4294967295 >>> 0, o = [xr([i ? t : Sr(n)], 0, a, 0, 2), xr([Cr()], 0, a, 1, 0)], s = 0, c = 2;
4116
+ let i = t && t.length >= 19 && new TextDecoder().decode(t.slice(0, 8)) === "OpusHead", a = Math.random() * 4294967295 >>> 0, o = [Sr([i ? t : Cr(n)], 0, a, 0, 2), Sr([wr()], 0, a, 1, 0)], s = 0, c = 2;
4111
4117
  for (let e = 0; e < r.length;) {
4112
4118
  let t = [], n = 0;
4113
4119
  for (; e < r.length && t.length < 50;) {
4114
4120
  let i = Math.floor(r[e].length / 255) + 1;
4115
4121
  if (n + i > 255) break;
4116
- t.push(r[e]), n += i, s += vr(r[e]), e++;
4122
+ t.push(r[e]), n += i, s += yr(r[e]), e++;
4117
4123
  }
4118
4124
  if (!t.length) return null;
4119
- o.push(xr(t, s, a, c++, e >= r.length ? 4 : 0));
4125
+ o.push(Sr(t, s, a, c++, e >= r.length ? 4 : 0));
4120
4126
  }
4121
4127
  let l = o.reduce((e, t) => e + t.length, 0), u = new Uint8Array(l), d = 0;
4122
4128
  for (let e of o) u.set(e, d), d += e.length;
@@ -4124,22 +4130,22 @@ function wr(e) {
4124
4130
  }
4125
4131
  //#endregion
4126
4132
  //#region src/components/Composer.tsx
4127
- var Tr = [
4133
+ var Er = [
4128
4134
  "audio/ogg;codecs=opus",
4129
4135
  "audio/webm;codecs=opus",
4130
4136
  "audio/mp4",
4131
4137
  "audio/webm"
4132
4138
  ];
4133
- async function Er(e, t) {
4139
+ async function Dr(e, t) {
4134
4140
  let n = Date.now();
4135
4141
  if (/webm/.test(t) && /opus/.test(t)) try {
4136
- let t = wr(new Uint8Array(await new Blob(e).arrayBuffer()));
4142
+ let t = Tr(new Uint8Array(await new Blob(e).arrayBuffer()));
4137
4143
  if (t) return new File([t], `voice-${n}.ogg`, { type: "audio/ogg" });
4138
4144
  } catch {}
4139
- return new File(e, `voice-${n}.${Dr(t)}`, { type: t.split(";")[0] });
4145
+ return new File(e, `voice-${n}.${Or(t)}`, { type: t.split(";")[0] });
4140
4146
  }
4141
- var Dr = (e) => /mp4/.test(e) ? "m4a" : /ogg/.test(e) ? "ogg" : "webm", Or = (e) => `${Math.floor(e / 6e4)}:${String(Math.floor(e % 6e4 / 1e3)).padStart(2, "0")}`;
4142
- function kr({ onSend: e, onTyping: t, onFile: n, disabled: r }) {
4147
+ var Or = (e) => /mp4/.test(e) ? "m4a" : /ogg/.test(e) ? "ogg" : "webm", kr = (e) => `${Math.floor(e / 6e4)}:${String(Math.floor(e % 6e4 / 1e3)).padStart(2, "0")}`;
4148
+ function Ar({ onSend: e, onTyping: t, onFile: n, disabled: r }) {
4143
4149
  let [o, l] = c(""), [u, p] = c(!1), m = s(null), h = s(null), g = s(null), _ = s(), v = s(!1), [y, b] = c(null), [x, S] = c(0), C = s(!1), w = s(!1), T = s(!1), E = s({});
4144
4150
  i(() => g.current?.focus(), []), i(() => () => {
4145
4151
  T.current = !0, C.current = !0, window.clearTimeout(_.current);
@@ -4178,9 +4184,9 @@ function kr({ onSend: e, onTyping: t, onFile: n, disabled: r }) {
4178
4184
  t.getTracks().forEach((e) => e.stop());
4179
4185
  return;
4180
4186
  }
4181
- let r = Tr.find((e) => MediaRecorder.isTypeSupported(e)), i = new MediaRecorder(e, r ? { mimeType: r } : void 0), a = [];
4187
+ let r = Er.find((e) => MediaRecorder.isTypeSupported(e)), i = new MediaRecorder(e, r ? { mimeType: r } : void 0), a = [];
4182
4188
  i.ondataavailable = (e) => e.data.size && a.push(e.data), i.onstop = () => {
4183
- t.getTracks().forEach((e) => e.stop()), E.current = {}, b(null), !C.current && a.length && Er(a, i.mimeType || r || "").then(n);
4189
+ t.getTracks().forEach((e) => e.stop()), E.current = {}, b(null), !C.current && a.length && Dr(a, i.mimeType || r || "").then(n);
4184
4190
  }, C.current = !1, i.start(), E.current = {
4185
4191
  r: i,
4186
4192
  stream: t
@@ -4209,7 +4215,7 @@ function kr({ onSend: e, onTyping: t, onFile: n, disabled: r }) {
4209
4215
  }),
4210
4216
  /* @__PURE__ */ f("div", {
4211
4217
  className: "ci-flex-1 ci-flex ci-items-center ci-gap-2 ci-px-4 ci-py-2.5 ci-rounded-3xl ci-bg-elevationL2 dark:ci-bg-elevationL2Dark ci-text-sm",
4212
- children: [/* @__PURE__ */ d("span", { className: "ci-w-2.5 ci-h-2.5 ci-rounded-full ci-bg-phoneIslandClose dark:ci-bg-phoneIslandCloseDark ci-animate-pulse" }), /* @__PURE__ */ f("span", { children: ["Recording ", Or(x)] })]
4218
+ children: [/* @__PURE__ */ d("span", { className: "ci-w-2.5 ci-h-2.5 ci-rounded-full ci-bg-phoneIslandClose dark:ci-bg-phoneIslandCloseDark ci-animate-pulse" }), /* @__PURE__ */ f("span", { children: ["Recording ", kr(x)] })]
4213
4219
  }),
4214
4220
  /* @__PURE__ */ d(Z, {
4215
4221
  variant: "green",
@@ -4223,7 +4229,7 @@ function kr({ onSend: e, onTyping: t, onFile: n, disabled: r }) {
4223
4229
  }) : /* @__PURE__ */ f("div", {
4224
4230
  className: "ci-relative ci-flex ci-items-center ci-gap-2 ci-px-3 ci-py-3",
4225
4231
  children: [
4226
- u && /* @__PURE__ */ d($n, {
4232
+ u && /* @__PURE__ */ d(er, {
4227
4233
  className: "ci-absolute ci-bottom-full ci-left-3 ci-mb-1",
4228
4234
  onPick: ee,
4229
4235
  onClose: () => p(!1)
@@ -4289,14 +4295,14 @@ function kr({ onSend: e, onTyping: t, onFile: n, disabled: r }) {
4289
4295
  }
4290
4296
  //#endregion
4291
4297
  //#region src/components/ChatWindow.tsx
4292
- var Ar = (e) => !!e && ![
4298
+ var jr = (e) => !!e && ![
4293
4299
  "offline",
4294
4300
  "dnd",
4295
4301
  "busy",
4296
4302
  "ringing",
4297
4303
  "onhold"
4298
4304
  ].includes(e);
4299
- function jr({ peer: e, actions: t, onDragStart: n }) {
4305
+ function Mr({ peer: e, actions: t, onDragStart: n }) {
4300
4306
  let { c: r, contacts: a, online: o, mobile: s, status: l, closeChat: p, openChat: m, markRead: h, order: g, me: _ } = J(w((t) => ({
4301
4307
  c: t.conversations[e],
4302
4308
  contacts: t.contacts,
@@ -4330,17 +4336,17 @@ function jr({ peer: e, actions: t, onDragStart: n }) {
4330
4336
  className: `ci-flex ci-items-center ci-gap-3 ci-px-4 ci-py-3 ci-rounded-t-3xl ${n ? "ci-cursor-grab active:ci-cursor-grabbing ci-touch-none" : ""}`,
4331
4337
  onPointerDown: n,
4332
4338
  children: [
4333
- r.kind === "group" ? /* @__PURE__ */ d(Un, {
4339
+ r.kind === "group" ? /* @__PURE__ */ d(Wn, {
4334
4340
  name: r.name ?? e,
4335
4341
  size: 36,
4336
4342
  avatar: r.avatar
4337
4343
  }) : /* @__PURE__ */ f("span", {
4338
4344
  className: "ci-relative",
4339
- children: [/* @__PURE__ */ d(Vn, {
4345
+ children: [/* @__PURE__ */ d(Hn, {
4340
4346
  contact: y,
4341
4347
  username: e,
4342
4348
  size: 36
4343
- }), /* @__PURE__ */ d(Hn, {
4349
+ }), /* @__PURE__ */ d(Un, {
4344
4350
  online: o[e],
4345
4351
  presence: y?.presence,
4346
4352
  mobile: s[e]
@@ -4363,7 +4369,7 @@ function jr({ peer: e, actions: t, onDragStart: n }) {
4363
4369
  children: l === "online" ? r.kind === "group" ? C.map(S).join(", ") : r.typing ? "typing…" : o[e] ? "online" : s[e] ? "Mobile" : "offline" : l
4364
4370
  })]
4365
4371
  }),
4366
- r.kind !== "group" && y?.number && Ar(y.presence) && /* @__PURE__ */ d(Z, {
4372
+ r.kind !== "group" && y?.number && jr(y.presence) && /* @__PURE__ */ d(Z, {
4367
4373
  variant: "call",
4368
4374
  title: `Call ${y.number}`,
4369
4375
  "aria-label": "Call",
@@ -4389,11 +4395,11 @@ function jr({ peer: e, actions: t, onDragStart: n }) {
4389
4395
  children: [
4390
4396
  /* @__PURE__ */ f("span", {
4391
4397
  className: "ci-relative",
4392
- children: [/* @__PURE__ */ d(Vn, {
4398
+ children: [/* @__PURE__ */ d(Hn, {
4393
4399
  contact: a[e],
4394
4400
  username: e,
4395
4401
  size: 28
4396
- }), e !== _ && /* @__PURE__ */ d(Hn, {
4402
+ }), e !== _ && /* @__PURE__ */ d(Un, {
4397
4403
  online: o[e],
4398
4404
  presence: a[e]?.presence,
4399
4405
  mobile: s[e]
@@ -4409,7 +4415,7 @@ function jr({ peer: e, actions: t, onDragStart: n }) {
4409
4415
  "aria-label": "Chat",
4410
4416
  onClick: () => m(e),
4411
4417
  children: Q.chat
4412
- }), a[e]?.number && Ar(a[e]?.presence) && /* @__PURE__ */ d(Z, {
4418
+ }), a[e]?.number && jr(a[e]?.presence) && /* @__PURE__ */ d(Z, {
4413
4419
  variant: "call",
4414
4420
  title: `Call ${a[e]?.number}`,
4415
4421
  "aria-label": "Call",
@@ -4424,7 +4430,7 @@ function jr({ peer: e, actions: t, onDragStart: n }) {
4424
4430
  }),
4425
4431
  /* @__PURE__ */ f("div", {
4426
4432
  className: "ci-flex-1 ci-min-h-0 ci-flex ci-flex-col ci-overflow-hidden ci-rounded-b-3xl",
4427
- children: [/* @__PURE__ */ d(mr, {
4433
+ children: [/* @__PURE__ */ d(hr, {
4428
4434
  messages: r.messages,
4429
4435
  typing: r.typing,
4430
4436
  group: r.kind === "group",
@@ -4433,7 +4439,7 @@ function jr({ peer: e, actions: t, onDragStart: n }) {
4433
4439
  reactions: r.reactions,
4434
4440
  me: _,
4435
4441
  onReact: (n, r) => t.react(e, n, r)
4436
- }), /* @__PURE__ */ d(kr, {
4442
+ }), /* @__PURE__ */ d(Ar, {
4437
4443
  disabled: l !== "online",
4438
4444
  onSend: (n) => t.send(e, n),
4439
4445
  onTyping: (n) => t.typing(e, n),
@@ -4445,11 +4451,11 @@ function jr({ peer: e, actions: t, onDragStart: n }) {
4445
4451
  }
4446
4452
  //#endregion
4447
4453
  //#region src/components/NewChat.tsx
4448
- async function Mr(e) {
4454
+ async function Nr(e) {
4449
4455
  let t = await createImageBitmap(e), n = Math.min(t.width, t.height), r = document.createElement("canvas");
4450
4456
  return r.width = r.height = 128, r.getContext("2d")?.drawImage(t, (t.width - n) / 2, (t.height - n) / 2, n, n, 0, 0, 128, 128), r.toDataURL("image/jpeg", .8);
4451
4457
  }
4452
- function Nr({ onOpen: e, onCreateGroup: t }) {
4458
+ function Pr({ onOpen: e, onCreateGroup: t }) {
4453
4459
  let { contacts: n, online: r, mobile: i, setPicker: a } = J(), [l, p] = c(""), [m, h] = c([]), [g, _] = c(""), [v, y] = c(!1), [b, x] = c(), S = s(null), C = o(() => {
4454
4460
  let e = Object.values(n), t = l.trim().toLowerCase();
4455
4461
  return t ? e.filter((e) => (e.name ?? "").toLowerCase().includes(t) || e.username.includes(t)) : e;
@@ -4506,11 +4512,11 @@ function Nr({ onOpen: e, onCreateGroup: t }) {
4506
4512
  children: [
4507
4513
  /* @__PURE__ */ f("span", {
4508
4514
  className: "ci-relative",
4509
- children: [/* @__PURE__ */ d(Vn, {
4515
+ children: [/* @__PURE__ */ d(Hn, {
4510
4516
  contact: e,
4511
4517
  username: e.username,
4512
4518
  size: 36
4513
- }), /* @__PURE__ */ d(Hn, {
4519
+ }), /* @__PURE__ */ d(Un, {
4514
4520
  online: r[e.username],
4515
4521
  presence: e.presence,
4516
4522
  mobile: i[e.username]
@@ -4557,7 +4563,7 @@ function Nr({ onOpen: e, onCreateGroup: t }) {
4557
4563
  type: "file",
4558
4564
  accept: "image/*",
4559
4565
  hidden: !0,
4560
- onChange: (e) => e.target.files?.[0] && Mr(e.target.files[0]).then(x).catch(() => {})
4566
+ onChange: (e) => e.target.files?.[0] && Nr(e.target.files[0]).then(x).catch(() => {})
4561
4567
  }),
4562
4568
  /* @__PURE__ */ d("button", {
4563
4569
  type: "button",
@@ -4592,22 +4598,22 @@ function Nr({ onOpen: e, onCreateGroup: t }) {
4592
4598
  }
4593
4599
  //#endregion
4594
4600
  //#region src/theme.ts
4595
- var Pr = "chat-island-theme", Fr = () => {
4601
+ var Fr = "chat-island-theme", Ir = () => {
4596
4602
  try {
4597
- let e = localStorage.getItem(Pr);
4603
+ let e = localStorage.getItem(Fr);
4598
4604
  return e === "light" || e === "dark" || e === "system" ? e : void 0;
4599
4605
  } catch {
4600
4606
  return;
4601
4607
  }
4602
4608
  };
4603
- function Ir(e) {
4604
- let [t, n] = c(() => e ?? Fr()), [r, a] = c(!1);
4605
- return i(() => n(e ?? Fr()), [e]), i(() => {
4609
+ function Lr(e) {
4610
+ let [t, n] = c(() => e ?? Ir()), [r, a] = c(!1);
4611
+ return i(() => n(e ?? Ir()), [e]), i(() => {
4606
4612
  let e = (e) => {
4607
4613
  let t = e.detail?.theme;
4608
4614
  if (t === "light" || t === "dark" || t === "system") {
4609
4615
  try {
4610
- localStorage.setItem(Pr, t);
4616
+ localStorage.setItem(Fr, t);
4611
4617
  } catch {}
4612
4618
  n(t);
4613
4619
  }
@@ -4633,7 +4639,7 @@ function Ir(e) {
4633
4639
  }
4634
4640
  //#endregion
4635
4641
  //#region src/ChatIsland.tsx
4636
- function Lr() {
4642
+ function Rr() {
4637
4643
  let e = J.getState();
4638
4644
  return Object.values(e.conversations).map((t) => {
4639
4645
  let n = t.messages[t.messages.length - 1], r = e.contacts[t.peer];
@@ -4648,7 +4654,7 @@ function Lr() {
4648
4654
  unread: t.unread,
4649
4655
  members: t.members,
4650
4656
  last: n ? {
4651
- body: Br(n.body),
4657
+ body: Vr(n.body),
4652
4658
  ts: n.ts,
4653
4659
  mine: n.mine,
4654
4660
  oob: n.oob,
@@ -4657,7 +4663,7 @@ function Lr() {
4657
4663
  };
4658
4664
  }).filter((e) => e.last || e.kind === "group").sort((e, t) => (t.last?.ts ?? 0) - (e.last?.ts ?? 0));
4659
4665
  }
4660
- var Rr = class extends t {
4666
+ var zr = class extends t {
4661
4667
  state = { failed: !1 };
4662
4668
  failures = [];
4663
4669
  static getDerivedStateFromError() {
@@ -4675,7 +4681,7 @@ var Rr = class extends t {
4675
4681
  return this.state.failed ? null : this.props.children;
4676
4682
  }
4677
4683
  };
4678
- function zr(e) {
4684
+ function Br(e) {
4679
4685
  try {
4680
4686
  let [t, n, r] = atob(e).split(":");
4681
4687
  return t && n && r ? {
@@ -4687,9 +4693,9 @@ function zr(e) {
4687
4693
  return null;
4688
4694
  }
4689
4695
  }
4690
- var Br = (e) => (sr(e) ? "Attachment" : $(e)).replace(/```[^\n]*\n?/g, "").replace(/(\*\*|__|~~|`)/g, "").replace(/(^|\s)[*_](\S[^*_]*)[*_]/g, "$1$2").replace(/\s+/g, " ").trim();
4691
- function Vr({ dataConfig: e, position: t = "bottom-right", theme: n, serviceWorker: r, maxHeads: a = 5, newChatButton: l = !0, notifications: u = "click", sound: p = !0, drag: m = !0, onDragStart: h }) {
4692
- let g = o(() => zr(e), [e]), _ = Ir(n), v = s(g), y = s(p), b = s(u);
4696
+ var Vr = (e) => (cr(e) ? "Attachment" : $(e)).replace(/```[^\n]*\n?/g, "").replace(/(\*\*|__|~~|`)/g, "").replace(/(^|\s)[*_](\S[^*_]*)[*_]/g, "$1$2").replace(/\s+/g, " ").trim();
4697
+ function Hr({ dataConfig: e, position: t = "bottom-right", theme: n, serviceWorker: r, maxHeads: a = 5, newChatButton: l = !0, notifications: u = "click", sound: p = !0, drag: m = !0, onDragStart: h }) {
4698
+ let g = o(() => Br(e), [e]), _ = Lr(n), v = s(g), y = s(p), b = s(u);
4693
4699
  i(() => {
4694
4700
  v.current = g, y.current = p, b.current = u;
4695
4701
  }, [
@@ -4752,7 +4758,7 @@ function Vr({ dataConfig: e, position: t = "bottom-right", theme: n, serviceWork
4752
4758
  if (!t || !n) return;
4753
4759
  let r = J.getState().conversations[e];
4754
4760
  try {
4755
- r?.kind === "group" && await t.leaveGroup(e, !!r.owner).catch(() => {}), await Fn(n.host, n.token, e), J.getState().removeConversation(e);
4761
+ r?.kind === "group" && await t.leaveGroup(e, !!r.owner).catch(() => {}), await In(n.host, n.token, e), J.getState().removeConversation(e);
4756
4762
  } catch (e) {
4757
4763
  Y("chat-island-error", {
4758
4764
  scope: "delete",
@@ -4821,6 +4827,7 @@ function Vr({ dataConfig: e, position: t = "bottom-right", theme: n, serviceWork
4821
4827
  typing: (t, n) => e.setTyping(t, n),
4822
4828
  reaction: (t) => e.applyReactions([t]),
4823
4829
  presence: (t, n) => e.setOnline(t, n),
4830
+ groupDestroyed: (t) => e.removeConversation(t),
4824
4831
  groupInvite: (n) => {
4825
4832
  t.subscribed(n).then(async (r) => {
4826
4833
  if (!r) return;
@@ -4829,7 +4836,7 @@ function Vr({ dataConfig: e, position: t = "bottom-right", theme: n, serviceWork
4829
4836
  }).catch(() => {});
4830
4837
  },
4831
4838
  message: (r) => {
4832
- let i = An(r);
4839
+ let i = jn(r);
4833
4840
  r.room && !J.getState().conversations[r.room]?.name && t.groupInfo(r.room).then((t) => e.setGroup(t.peer, t.name, t.members, t.avatar, t.owner)).catch(() => {}), e.addMessage(i, r, { live: !0 }), Y("chat-island-message", {
4834
4841
  ...r,
4835
4842
  peer: i
@@ -4839,7 +4846,7 @@ function Vr({ dataConfig: e, position: t = "bottom-right", theme: n, serviceWork
4839
4846
  let n = J.getState(), r = document.visibilityState === "visible";
4840
4847
  if (r && n.open === e) return;
4841
4848
  let i = n.conversations[e], a = i?.kind === "group" ? i.name ?? e : n.contacts[e]?.name ?? e, o = t.oob ? "Attachment" : $(t.body), s = i?.kind === "group", c = s && t.nick ? n.contacts[t.nick]?.name ?? t.nick : a, l = s && t.nick ? `${c}: ${o}` : o;
4842
- y.current && xn();
4849
+ y.current && Sn();
4843
4850
  let u = s ? i?.avatar : n.contacts[e]?.avatar;
4844
4851
  if (Y("chat-island-notify", {
4845
4852
  peer: e,
@@ -4863,7 +4870,7 @@ function Vr({ dataConfig: e, position: t = "bottom-right", theme: n, serviceWork
4863
4870
  };
4864
4871
  C.current = t;
4865
4872
  let i = () => {
4866
- r && !D.current && (D.current = !0, zn(g, r).then((e) => {
4873
+ r && !D.current && (D.current = !0, Bn(g, r).then((e) => {
4867
4874
  if (!e) {
4868
4875
  D.current = !1, J.setState({ push: Notification.permission === "denied" ? "denied" : "ask" });
4869
4876
  return;
@@ -4884,14 +4891,14 @@ function Vr({ dataConfig: e, position: t = "bottom-right", theme: n, serviceWork
4884
4891
  });
4885
4892
  let s = () => t.stop();
4886
4893
  window.addEventListener("pagehide", s), t.start();
4887
- let c = () => Pn(g.host, g.token).then(e.setMobile).catch(() => {});
4894
+ let c = () => Fn(g.host, g.token).then(e.setMobile).catch(() => {});
4888
4895
  c();
4889
4896
  let u = window.setInterval(c, 12e4);
4890
- Nn(g.host, g.token, g.username).then(e.setContacts).catch((e) => Y("chat-island-error", {
4897
+ Pn(g.host, g.token, g.username).then(e.setContacts).catch((e) => Y("chat-island-error", {
4891
4898
  scope: "contacts",
4892
4899
  message: e.message
4893
4900
  }));
4894
- let d = X("chat-island-open", ({ username: t }) => t && e.openChat(t)), f = X("chat-island-close", () => e.closeChat()), p = X("chat-island-new", () => e.setPicker(!0)), m = X("chat-island-delete", ({ username: e }) => e && ne.remove(e)), h = X("chat-island-contacts", ({ contacts: t }) => t && e.setContacts(t)), _ = X("chat-island-conversations-request", () => Y("chat-island-conversations", { conversations: Lr() }));
4901
+ let d = X("chat-island-open", ({ username: t }) => t && e.openChat(t)), f = X("chat-island-close", () => e.closeChat()), p = X("chat-island-new", () => e.setPicker(!0)), m = X("chat-island-delete", ({ username: e }) => e && ne.remove(e)), h = X("chat-island-contacts", ({ contacts: t }) => t && e.setContacts(t)), _ = X("chat-island-conversations-request", () => Y("chat-island-conversations", { conversations: Rr() }));
4895
4902
  return () => {
4896
4903
  window.removeEventListener("pagehide", s), window.clearInterval(u), _(), p(), m(), d(), f(), h(), O.current && t.disablePush(O.current.service, O.current.node).catch(() => {}), O.current = null, t.stop(), C.current = null, D.current = !1;
4897
4904
  };
@@ -4905,7 +4912,7 @@ function Vr({ dataConfig: e, position: t = "bottom-right", theme: n, serviceWork
4905
4912
  j === "online" && M && C.current?.announce(M.split(","));
4906
4913
  }, [j, M]);
4907
4914
  let re = J((e) => Object.values(e.conversations).map((e) => `${e.peer}:${e.kind}:${e.name ?? ""}:${(e.members ?? []).length}:${e.unread}:${e.messages[e.messages.length - 1]?.id ?? ""}`).join("|") + "#" + Object.keys(e.contacts).length + "#" + Object.values(e.online).filter(Boolean).length);
4908
- i(() => Y("chat-island-conversations", { conversations: Lr() }), [re]);
4915
+ i(() => Y("chat-island-conversations", { conversations: Rr() }), [re]);
4909
4916
  let ie = J((e) => Object.values(e.conversations).reduce((e, t) => e + t.unread, 0));
4910
4917
  if (i(() => Y("chat-island-unread", { total: ie }), [ie]), !g) return null;
4911
4918
  let ae = m && !h && k.anchor ? {
@@ -4918,17 +4925,17 @@ function Vr({ dataConfig: e, position: t = "bottom-right", theme: n, serviceWork
4918
4925
  onClickCapture: k.onClickCapture,
4919
4926
  className: `chat-island-root ${_ ? "ci-dark" : ""} ci-fixed ${oe} ci-z-[9999] ci-flex ci-items-end ci-gap-3 ci-font-sans ci-select-none`,
4920
4927
  "data-status": j,
4921
- children: /* @__PURE__ */ f(Rr, { children: [
4922
- te && /* @__PURE__ */ d(jr, {
4928
+ children: /* @__PURE__ */ f(zr, { children: [
4929
+ te && /* @__PURE__ */ d(Mr, {
4923
4930
  peer: te,
4924
4931
  actions: ne,
4925
4932
  onDragStart: h ?? (m ? k.start : void 0)
4926
4933
  }),
4927
- A && /* @__PURE__ */ d(Nr, {
4934
+ A && /* @__PURE__ */ d(Pr, {
4928
4935
  onOpen: (e) => J.getState().openChat(e),
4929
4936
  onCreateGroup: ne.createGroup
4930
4937
  }),
4931
- /* @__PURE__ */ d(Kn, {
4938
+ /* @__PURE__ */ d(qn, {
4932
4939
  onDragStart: h ?? (m ? k.start : void 0),
4933
4940
  pushButton: u !== "auto"
4934
4941
  })
@@ -4936,4 +4943,4 @@ function Vr({ dataConfig: e, position: t = "bottom-right", theme: n, serviceWork
4936
4943
  });
4937
4944
  }
4938
4945
  //#endregion
4939
- export { Vr as ChatIsland };
4946
+ export { Hr as ChatIsland };