@nethesis/chat-island 0.1.11 → 0.1.12

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
@@ -2956,7 +2956,7 @@ var An = (e) => {
2956
2956
  if (i.length <= n) return i;
2957
2957
  let a = [...i].reverse().find((e) => e !== r);
2958
2958
  return i.filter((e) => e !== a);
2959
- }, J = jn((e, t) => ({
2959
+ }, Pn = (e, t) => e.id === t.id || !!e.oid && e.oid === t.oid, J = jn((e, t) => ({
2960
2960
  me: "",
2961
2961
  myName: "",
2962
2962
  mucHost: "",
@@ -3028,7 +3028,7 @@ var An = (e) => {
3028
3028
  let t = Mn(i);
3029
3029
  if (!t || t === n) continue;
3030
3030
  let a = r[t] ?? q(t, e.mucHost);
3031
- if (a.messages.some((e) => e.id === i.id)) continue;
3031
+ if (a.messages.some((e) => Pn(e, i))) continue;
3032
3032
  if (a.loaded) {
3033
3033
  r[t] = {
3034
3034
  ...a,
@@ -3045,7 +3045,7 @@ var An = (e) => {
3045
3045
  return { conversations: r };
3046
3046
  }),
3047
3047
  addMessage: (t, n, r) => e((e) => {
3048
- 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;
3048
+ let i = e.conversations[t] ?? q(t, e.mucHost), a = i.messages.filter((e) => !Pn(e, n) && !(e.pending && n.mine && e.body === n.body && e.oob === n.oob)), o = a.length;
3049
3049
  for (; o > 0 && a[o - 1].ts > n.ts;) o--;
3050
3050
  a.splice(o, 0, n);
3051
3051
  let s = e.open === t, c = r?.live && !n.mine && !s ? i.unread + 1 : i.unread, l = Nn(e.order, t, e.maxHeads, e.open);
@@ -3063,12 +3063,12 @@ var An = (e) => {
3063
3063
  };
3064
3064
  }),
3065
3065
  prependHistory: (t, n, r, i) => e((e) => {
3066
- let a = e.conversations[t] ?? q(t, e.mucHost), o = new Set(a.messages.map((e) => e.id)), s = [...n.filter((e) => !o.has(e.id)), ...a.messages].sort((e, t) => e.ts - t.ts);
3066
+ let a = e.conversations[t] ?? q(t, e.mucHost), o = [...n.filter((e) => !a.messages.some((t) => Pn(t, e))), ...a.messages].sort((e, t) => e.ts - t.ts);
3067
3067
  return { conversations: {
3068
3068
  ...e.conversations,
3069
3069
  [t]: {
3070
3070
  ...a,
3071
- messages: s,
3071
+ messages: o,
3072
3072
  loaded: !0,
3073
3073
  complete: r,
3074
3074
  oldest: i ?? a.oldest
@@ -3128,7 +3128,7 @@ var An = (e) => {
3128
3128
  }));
3129
3129
  //#endregion
3130
3130
  //#region src/contacts.ts
3131
- function Pn(e, t, n) {
3131
+ function Fn(e, t, n) {
3132
3132
  return Object.values(e ?? {}).filter((e) => e?.username && e.username !== n).map((e) => ({
3133
3133
  username: e.username,
3134
3134
  name: e.name || e.username,
@@ -3139,31 +3139,31 @@ function Pn(e, t, n) {
3139
3139
  }
3140
3140
  //#endregion
3141
3141
  //#region src/api.ts
3142
- async function Fn(e, t, n) {
3142
+ async function In(e, t, n) {
3143
3143
  let r = await fetch(`https://${e}/api${n}`, { headers: { Authorization: `Bearer ${t}` } });
3144
3144
  if (!r.ok) throw Error(`${n}: HTTP ${r.status}`);
3145
3145
  return await r.json();
3146
3146
  }
3147
- async function In(e, t, n, r) {
3148
- let i = await Fn(e, t, "/user/endpoints/all"), a = {};
3147
+ async function Ln(e, t, n, r) {
3148
+ let i = await In(e, t, "/user/endpoints/all"), a = {};
3149
3149
  try {
3150
- a = await Fn(e, t, "/user/all_avatars");
3150
+ a = await In(e, t, "/user/all_avatars");
3151
3151
  } catch {}
3152
3152
  let o = Object.values(i).find((e) => e.username === n)?.name;
3153
- return o && r?.(o), Pn(i, a, n).sort((e, t) => e.name.localeCompare(t.name));
3153
+ return o && r?.(o), Fn(i, a, n).sort((e, t) => e.name.localeCompare(t.name));
3154
3154
  }
3155
- async function Ln(e, t) {
3155
+ async function Rn(e, t) {
3156
3156
  let n = await fetch(`https://${e}/chat-gw/push/mobile`, { headers: { Authorization: `Bearer ${t}` } });
3157
3157
  if (!n.ok) throw Error(`push/mobile: HTTP ${n.status}`);
3158
3158
  return (await n.json()).users;
3159
3159
  }
3160
- async function Rn(e, t) {
3160
+ async function zn(e, t) {
3161
3161
  let n = await fetch(`https://${e}/chat-gw/users/inactive`, { headers: { Authorization: `Bearer ${t}` } });
3162
3162
  if (!n.ok) throw Error(`users/inactive: HTTP ${n.status}`);
3163
3163
  let { users: r } = await n.json();
3164
3164
  return Object.fromEntries(r.map((e) => [e.username, e.name || e.username]));
3165
3165
  }
3166
- async function zn(e, t, n) {
3166
+ async function Bn(e, t, n) {
3167
3167
  let r = await fetch(`https://${e}/chat-gw/conversations/${encodeURIComponent(n)}`, {
3168
3168
  method: "DELETE",
3169
3169
  headers: { Authorization: `Bearer ${t}` }
@@ -3172,16 +3172,16 @@ async function zn(e, t, n) {
3172
3172
  }
3173
3173
  //#endregion
3174
3174
  //#region src/push.ts
3175
- var Bn = (e) => {
3175
+ var Vn = (e) => {
3176
3176
  let t = atob((e + "=".repeat((4 - e.length % 4) % 4)).replace(/-/g, "+").replace(/_/g, "/"));
3177
3177
  return Uint8Array.from(t, (e) => e.charCodeAt(0));
3178
- }, Vn = !1;
3179
- function Hn() {
3180
- Vn || (Vn = !0, navigator.serviceWorker.addEventListener("message", (e) => {
3178
+ }, Hn = !1;
3179
+ function Un() {
3180
+ Hn || (Hn = !0, navigator.serviceWorker.addEventListener("message", (e) => {
3181
3181
  e.data?.type === "chat-island-open" && typeof e.data.username == "string" && window.dispatchEvent(new CustomEvent("chat-island-open", { detail: { username: e.data.username } }));
3182
3182
  }));
3183
3183
  }
3184
- async function Un(e, t) {
3184
+ async function Wn(e, t) {
3185
3185
  if (!("serviceWorker" in navigator) || !("PushManager" in window)) throw Error("push not supported by this browser");
3186
3186
  if (Notification.permission === "denied" || Notification.permission !== "granted" && await Notification.requestPermission() !== "granted") return null;
3187
3187
  let n = `https://${e.host}/chat-gw`, r = await fetch(`${n}/push/vapid`);
@@ -3190,7 +3190,7 @@ async function Un(e, t) {
3190
3190
  await navigator.serviceWorker.ready;
3191
3191
  let o = await a.pushManager.getSubscription() ?? await a.pushManager.subscribe({
3192
3192
  userVisibleOnly: !0,
3193
- applicationServerKey: Bn(i.publicKey)
3193
+ applicationServerKey: Vn(i.publicKey)
3194
3194
  }), s = await fetch(`${n}/push/web`, {
3195
3195
  method: "POST",
3196
3196
  headers: {
@@ -3201,7 +3201,7 @@ async function Un(e, t) {
3201
3201
  });
3202
3202
  if (!s.ok) throw Error(`push/web: HTTP ${s.status} ${(await s.text()).slice(0, 120)}`);
3203
3203
  let c = await s.json();
3204
- return Hn(), {
3204
+ return Un(), {
3205
3205
  node: c.node,
3206
3206
  service: c.service
3207
3207
  };
@@ -3217,8 +3217,8 @@ function X(e, t) {
3217
3217
  }
3218
3218
  //#endregion
3219
3219
  //#region src/components/Avatar.tsx
3220
- var Wn = (e) => e.split(/\s+/).slice(0, 2).map((e) => e[0]?.toUpperCase() ?? "").join("");
3221
- function Gn({ contact: e, username: t, size: n = 40 }) {
3220
+ var Gn = (e) => e.split(/\s+/).slice(0, 2).map((e) => e[0]?.toUpperCase() ?? "").join("");
3221
+ function Kn({ contact: e, username: t, size: n = 40 }) {
3222
3222
  let r = e?.name || t, i = {
3223
3223
  width: n,
3224
3224
  height: n,
@@ -3233,13 +3233,13 @@ function Gn({ contact: e, username: t, size: n = 40 }) {
3233
3233
  }) : /* @__PURE__ */ d("div", {
3234
3234
  style: i,
3235
3235
  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",
3236
- children: Wn(r)
3236
+ children: Gn(r)
3237
3237
  });
3238
3238
  }
3239
- function Kn({ online: e, presence: t, mobile: n }) {
3239
+ function qn({ online: e, presence: t, mobile: n }) {
3240
3240
  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"}` });
3241
3241
  }
3242
- function qn({ name: e, size: t = 40, avatar: n }) {
3242
+ function Jn({ name: e, size: t = 40, avatar: n }) {
3243
3243
  let r = {
3244
3244
  width: t,
3245
3245
  height: t,
@@ -3254,12 +3254,12 @@ function qn({ name: e, size: t = 40, avatar: n }) {
3254
3254
  }) : /* @__PURE__ */ d("div", {
3255
3255
  style: r,
3256
3256
  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",
3257
- children: Wn(e || "G")
3257
+ children: Gn(e || "G")
3258
3258
  });
3259
3259
  }
3260
3260
  //#endregion
3261
3261
  //#region src/components/Button.tsx
3262
- var Jn = "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", Yn = {
3262
+ var Yn = "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", Xn = {
3263
3263
  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",
3264
3264
  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",
3265
3265
  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",
@@ -3272,7 +3272,7 @@ function Z({ variant: e, className: t = "", children: n, ...r }) {
3272
3272
  return /* @__PURE__ */ d("button", {
3273
3273
  type: "button",
3274
3274
  "aria-label": r["aria-label"] ?? r.title,
3275
- className: `${Jn} ${Yn[e]} ${t}`,
3275
+ className: `${Yn} ${Xn[e]} ${t}`,
3276
3276
  ...r,
3277
3277
  children: n
3278
3278
  });
@@ -3440,7 +3440,7 @@ var Q = {
3440
3440
  };
3441
3441
  //#endregion
3442
3442
  //#region src/components/Dock.tsx
3443
- function Xn({ onDragStart: e, pushButton: t = !0 }) {
3443
+ function Zn({ onDragStart: e, pushButton: t = !0 }) {
3444
3444
  let { order: n, open: r, conversations: i, contacts: a, inactive: o, online: s, mobile: c, openChat: l, removeHead: p, picker: m, setPicker: h, status: g, push: _, enablePush: v, newChatButton: y } = J(w((e) => ({
3445
3445
  order: e.order,
3446
3446
  open: e.open,
@@ -3471,15 +3471,15 @@ function Xn({ onDragStart: e, pushButton: t = !0 }) {
3471
3471
  title: t?.kind === "group" ? t.name ?? e : a[e]?.name ?? o[e] ?? e,
3472
3472
  onClick: () => n ? J.getState().closeChat() : l(e),
3473
3473
  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"}`,
3474
- children: [t?.kind === "group" ? /* @__PURE__ */ d(qn, {
3474
+ children: [t?.kind === "group" ? /* @__PURE__ */ d(Jn, {
3475
3475
  name: t.name ?? e,
3476
3476
  size: 48,
3477
3477
  avatar: t.avatar
3478
- }) : /* @__PURE__ */ f(u, { children: [/* @__PURE__ */ d(Gn, {
3478
+ }) : /* @__PURE__ */ f(u, { children: [/* @__PURE__ */ d(Kn, {
3479
3479
  contact: a[e],
3480
3480
  username: e,
3481
3481
  size: 48
3482
- }), /* @__PURE__ */ d(Kn, {
3482
+ }), /* @__PURE__ */ d(qn, {
3483
3483
  online: s[e],
3484
3484
  presence: a[e]?.presence,
3485
3485
  mobile: c[e]
@@ -3515,7 +3515,7 @@ function Xn({ onDragStart: e, pushButton: t = !0 }) {
3515
3515
  }
3516
3516
  //#endregion
3517
3517
  //#region src/shortcodes.ts
3518
- var Zn = {
3518
+ var Qn = {
3519
3519
  "+1": "👍",
3520
3520
  thumbsup: "👍",
3521
3521
  "-1": "👎",
@@ -3709,13 +3709,13 @@ var Zn = {
3709
3709
  zzz: "💤",
3710
3710
  sweat_drops: "💦",
3711
3711
  dash: "💨"
3712
- }, Qn = /(```[\s\S]*?(?:```|$)|`[^`\n]*`?)/g, $n = /:([a-z0-9_+-]+):/g, er = (e) => e.replace($n, (e, t) => Zn[t] ?? e);
3712
+ }, $n = /(```[\s\S]*?(?:```|$)|`[^`\n]*`?)/g, er = /:([a-z0-9_+-]+):/g, tr = (e) => e.replace(er, (e, t) => Qn[t] ?? e);
3713
3713
  function $(e) {
3714
- return e.includes(":") ? e.split(Qn).map((e, t) => t % 2 ? e : er(e)).join("") : e;
3714
+ return e.includes(":") ? e.split($n).map((e, t) => t % 2 ? e : tr(e)).join("") : e;
3715
3715
  }
3716
3716
  //#endregion
3717
3717
  //#region src/components/EmojiPicker.tsx
3718
- var tr = [
3718
+ var nr = [
3719
3719
  {
3720
3720
  label: "Smileys",
3721
3721
  icon: "😀",
@@ -3746,7 +3746,7 @@ var tr = [
3746
3746
  icon: "☕",
3747
3747
  emojis: "☕ 🍵 🥤 🍕 🍔 🍟 🌭 🥪 🌮 🍝 🍣 🍩 🍪 🍫 🍎 🍌 🍓 🥐 🚗 🚕 🚌 🚆 ✈️ 🚀 🏠 🏢 🏖️ 🌍 ☀️ 🌤️ 🌧️ ⛈️ ❄️ ⚡ 🌈 🌙"
3748
3748
  }
3749
- ], nr = [
3749
+ ], rr = [
3750
3750
  "👍",
3751
3751
  "❤️",
3752
3752
  "😂",
@@ -3754,7 +3754,7 @@ var tr = [
3754
3754
  "😢",
3755
3755
  "🙏"
3756
3756
  ];
3757
- function rr({ onPick: e, onClose: t, className: n = "" }) {
3757
+ function ir({ onPick: e, onClose: t, className: n = "" }) {
3758
3758
  let [r, a] = c(0), o = s(null);
3759
3759
  return i(() => {
3760
3760
  let e = (e) => o.current && !o.current.contains(e.target) && t(), n = (e) => {
@@ -3770,7 +3770,7 @@ function rr({ onPick: e, onClose: t, className: n = "" }) {
3770
3770
  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}`,
3771
3771
  children: [/* @__PURE__ */ d("div", {
3772
3772
  className: "ci-flex ci-gap-1 ci-px-2 ci-pt-2 ci-border-b ci-border-gray-300 dark:ci-border-gray-700",
3773
- children: tr.map((e, t) => /* @__PURE__ */ d("button", {
3773
+ children: nr.map((e, t) => /* @__PURE__ */ d("button", {
3774
3774
  type: "button",
3775
3775
  title: e.label,
3776
3776
  "aria-label": e.label,
@@ -3784,7 +3784,7 @@ function rr({ onPick: e, onClose: t, className: n = "" }) {
3784
3784
  }, e.label))
3785
3785
  }), /* @__PURE__ */ d("div", {
3786
3786
  className: "ci-grid ci-grid-cols-7 ci-gap-1 ci-p-2 ci-h-64 ci-overflow-y-auto",
3787
- children: tr[r].emojis.split(" ").map((t) => /* @__PURE__ */ d("button", {
3787
+ children: nr[r].emojis.split(" ").map((t) => /* @__PURE__ */ d("button", {
3788
3788
  type: "button",
3789
3789
  onClick: () => e(t),
3790
3790
  style: {
@@ -3799,27 +3799,27 @@ function rr({ onPick: e, onClose: t, className: n = "" }) {
3799
3799
  }
3800
3800
  //#endregion
3801
3801
  //#region src/components/MessageList.tsx
3802
- var ir = (e) => /\.(png|jpe?g|gif|webp|avif|svg)(\?|$)/i.test(e), ar = (e) => /\.(webm|ogg|oga|opus|mp3|m4a|wav)(\?|$)/i.test(e), or = (e) => {
3802
+ var ar = (e) => /\.(png|jpe?g|gif|webp|avif|svg)(\?|$)/i.test(e), or = (e) => /\.(webm|ogg|oga|opus|mp3|m4a|wav)(\?|$)/i.test(e), sr = (e) => {
3803
3803
  let t = e.split("/").pop() || "file";
3804
3804
  try {
3805
3805
  return decodeURIComponent(t);
3806
3806
  } catch {
3807
3807
  return t;
3808
3808
  }
3809
- }, sr = (e) => {
3809
+ }, cr = (e) => {
3810
3810
  try {
3811
3811
  return new URL(e).protocol === "https:";
3812
3812
  } catch {
3813
3813
  return !1;
3814
3814
  }
3815
- }, cr = (e) => new Date(e).toLocaleTimeString([], {
3815
+ }, lr = (e) => new Date(e).toLocaleTimeString([], {
3816
3816
  hour: "2-digit",
3817
3817
  minute: "2-digit"
3818
- }), lr = (e) => new Date(e).toLocaleDateString([], {
3818
+ }), ur = (e) => new Date(e).toLocaleDateString([], {
3819
3819
  weekday: "short",
3820
3820
  day: "numeric",
3821
3821
  month: "short"
3822
- }), ur = (e, t) => new Date(e).toDateString() === new Date(t).toDateString(), dr = (e) => {
3822
+ }), dr = (e, t) => new Date(e).toDateString() === new Date(t).toDateString(), fr = (e) => {
3823
3823
  if (!e.startsWith("{\"")) return null;
3824
3824
  try {
3825
3825
  let t = JSON.parse(e);
@@ -3830,17 +3830,17 @@ var ir = (e) => /\.(png|jpe?g|gif|webp|avif|svg)(\?|$)/i.test(e), ar = (e) => /\
3830
3830
  } catch {
3831
3831
  return null;
3832
3832
  }
3833
- }, fr = n(function({ url: e }) {
3834
- return sr(e) ? ir(e) ? /* @__PURE__ */ d("a", {
3833
+ }, pr = n(function({ url: e }) {
3834
+ return cr(e) ? ar(e) ? /* @__PURE__ */ d("a", {
3835
3835
  href: e,
3836
3836
  target: "_blank",
3837
3837
  rel: "noreferrer",
3838
3838
  children: /* @__PURE__ */ d("img", {
3839
3839
  src: e,
3840
- alt: or(e),
3840
+ alt: sr(e),
3841
3841
  className: "ci-max-w-full ci-max-h-60 ci-rounded-2xl ci-block"
3842
3842
  })
3843
- }) : ar(e) ? /* @__PURE__ */ d("audio", {
3843
+ }) : or(e) ? /* @__PURE__ */ d("audio", {
3844
3844
  controls: !0,
3845
3845
  src: e,
3846
3846
  className: "ci-max-w-full"
@@ -3857,15 +3857,15 @@ var ir = (e) => /\.(png|jpe?g|gif|webp|avif|svg)(\?|$)/i.test(e), ar = (e) => /\
3857
3857
  stroke: "currentColor",
3858
3858
  strokeWidth: "2",
3859
3859
  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" })
3860
- }), or(e)]
3860
+ }), sr(e)]
3861
3861
  }) : /* @__PURE__ */ d("span", {
3862
3862
  className: "ci-break-all",
3863
3863
  children: e
3864
3864
  });
3865
- }), pr = /(`[^`\n]+`)|(\*\*[^*\n]+\*\*|__[^_\n]+__)|(~~[^~\n]+~~)|(\*[^*\s][^*\n]*\*|_[^_\s][^_\n]*_)|\[([^\]\n]+)\]\((https?:\/\/[^\s)]+)\)|(https?:\/\/[^\s<]+)/g;
3866
- function mr({ text: e }) {
3865
+ }), mr = /(`[^`\n]+`)|(\*\*[^*\n]+\*\*|__[^_\n]+__)|(~~[^~\n]+~~)|(\*[^*\s][^*\n]*\*|_[^_\s][^_\n]*_)|\[([^\]\n]+)\]\((https?:\/\/[^\s)]+)\)|(https?:\/\/[^\s<]+)/g;
3866
+ function hr({ text: e }) {
3867
3867
  let t = [], n = 0;
3868
- for (let r of e.matchAll(pr)) {
3868
+ for (let r of e.matchAll(mr)) {
3869
3869
  let i = r[0], a = r.index ?? 0;
3870
3870
  a > n && t.push($(e.slice(n, a))), r[1] ? t.push(/* @__PURE__ */ d("code", {
3871
3871
  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]",
@@ -3886,17 +3886,17 @@ function mr({ text: e }) {
3886
3886
  }
3887
3887
  return n < e.length && t.push($(e.slice(n))), /* @__PURE__ */ d(u, { children: t });
3888
3888
  }
3889
- var hr = n(function({ text: e }) {
3889
+ var gr = n(function({ text: e }) {
3890
3890
  let t = e.split(/```[^\n]*\n?([\s\S]*?)```/g);
3891
3891
  return /* @__PURE__ */ d("span", {
3892
3892
  className: "ci-whitespace-pre-wrap ci-break-words",
3893
3893
  children: t.map((e, t) => t % 2 ? /* @__PURE__ */ d("pre", {
3894
3894
  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",
3895
3895
  children: e.replace(/\n$/, "")
3896
- }, t) : /* @__PURE__ */ d(mr, { text: e.replace(/^(\s*)[-*] (?=\S)/gm, "$1• ") }, t))
3896
+ }, t) : /* @__PURE__ */ d(hr, { text: e.replace(/^(\s*)[-*] (?=\S)/gm, "$1• ") }, t))
3897
3897
  });
3898
3898
  });
3899
- function gr({ text: e, count: t }) {
3899
+ function _r({ text: e, count: t }) {
3900
3900
  return /* @__PURE__ */ f("span", {
3901
3901
  className: "ci-italic ci-opacity-80",
3902
3902
  children: [
@@ -3909,7 +3909,7 @@ function gr({ text: e, count: t }) {
3909
3909
  ]
3910
3910
  });
3911
3911
  }
3912
- function _r({ forMsg: e, me: t, onReact: n, nameOf: r, mine: i }) {
3912
+ function vr({ forMsg: e, me: t, onReact: n, nameOf: r, mine: i }) {
3913
3913
  if (!e) return null;
3914
3914
  let a = /* @__PURE__ */ new Map();
3915
3915
  for (let [t, n] of Object.entries(e)) for (let e of n) a.set(e, [...a.get(e) ?? [], t]);
@@ -3934,7 +3934,7 @@ function _r({ forMsg: e, me: t, onReact: n, nameOf: r, mine: i }) {
3934
3934
  })
3935
3935
  }) : null;
3936
3936
  }
3937
- function vr({ reply: e, messages: t, mine: n, name: r }) {
3937
+ function yr({ reply: e, messages: t, mine: n, name: r }) {
3938
3938
  let i = t.find((t) => t.oid === e.id), a = i ? i.oob ? "Attachment" : i.body : e.quote?.replace(/^[^:]*: /, "") ?? "", o = (t) => {
3939
3939
  t.stopPropagation();
3940
3940
  let n = document.querySelector(`.chat-island-root [data-oid="${CSS.escape(e.id)}"]`);
@@ -3958,7 +3958,7 @@ function vr({ reply: e, messages: t, mine: n, name: r }) {
3958
3958
  })]
3959
3959
  });
3960
3960
  }
3961
- function yr({ messages: e, typing: t, onLoadOlder: n, hasOlder: r, group: a, reactions: o, me: l = "", onReact: u, onReply: p }) {
3961
+ function br({ messages: e, typing: t, onLoadOlder: n, hasOlder: r, group: a, reactions: o, me: l = "", onReact: u, onReply: p }) {
3962
3962
  let m = J((e) => e.contacts), h = s(null), g = s(!0), [_, v] = c(null), [y, b] = c(null), x = (e) => m[e]?.name ?? e;
3963
3963
  i(() => {
3964
3964
  let e = h.current;
@@ -3992,7 +3992,7 @@ function yr({ messages: e, typing: t, onLoadOlder: n, hasOlder: r, group: a, rea
3992
3992
  children: "Scroll up for older messages"
3993
3993
  }),
3994
3994
  e.map((t, n) => {
3995
- let r = e[n - 1], i = !r || !ur(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 ? x(t.nick) : null, h = t.oid, g = !!u && !!h && !t.pending, y = g && /* @__PURE__ */ d("button", {
3995
+ let r = e[n - 1], i = !r || !dr(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 ? x(t.nick) : null, h = t.oid, g = !!u && !!h && !t.pending, y = g && /* @__PURE__ */ d("button", {
3996
3996
  type: "button",
3997
3997
  title: "React",
3998
3998
  "aria-label": "React to this message",
@@ -4015,14 +4015,14 @@ function yr({ messages: e, typing: t, onLoadOlder: n, hasOlder: r, group: a, rea
4015
4015
  "data-oid": t.oid,
4016
4016
  children: [i && /* @__PURE__ */ d("div", {
4017
4017
  className: "ci-text-center ci-text-xs ci-text-gray-500 dark:ci-text-gray-400 ci-py-2",
4018
- children: lr(t.ts)
4018
+ children: ur(t.ts)
4019
4019
  }), /* @__PURE__ */ f("div", {
4020
4020
  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"}`,
4021
4021
  children: [
4022
4022
  c && /* @__PURE__ */ d("span", {
4023
4023
  className: "ci-w-7 ci-shrink-0",
4024
4024
  title: c,
4025
- children: !s && /* @__PURE__ */ d(Gn, {
4025
+ children: !s && /* @__PURE__ */ d(Kn, {
4026
4026
  contact: m[t.nick],
4027
4027
  username: t.nick,
4028
4028
  size: 28
@@ -4037,7 +4037,7 @@ function yr({ messages: e, typing: t, onLoadOlder: n, hasOlder: r, group: a, rea
4037
4037
  role: "menu",
4038
4038
  onClick: (e) => e.stopPropagation(),
4039
4039
  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"}`,
4040
- children: [nr.map((e) => /* @__PURE__ */ d("button", {
4040
+ children: [rr.map((e) => /* @__PURE__ */ d("button", {
4041
4041
  type: "button",
4042
4042
  role: "menuitem",
4043
4043
  "aria-label": e,
@@ -4061,28 +4061,28 @@ function yr({ messages: e, typing: t, onLoadOlder: n, hasOlder: r, group: a, rea
4061
4061
  })]
4062
4062
  }),
4063
4063
  /* @__PURE__ */ f("div", {
4064
- title: cr(t.ts),
4065
- onDoubleClick: () => g && C(h, nr[0]),
4064
+ title: lr(t.ts),
4065
+ onDoubleClick: () => g && C(h, rr[0]),
4066
4066
  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" : ""}`,
4067
4067
  children: [
4068
- t.reply && /* @__PURE__ */ d(vr, {
4068
+ t.reply && /* @__PURE__ */ d(yr, {
4069
4069
  reply: t.reply,
4070
4070
  messages: e,
4071
4071
  mine: t.mine,
4072
4072
  name: (e) => e === l ? "You" : x(e)
4073
4073
  }),
4074
- t.oob ? /* @__PURE__ */ d(fr, { url: t.oob }) : dr(t.body) ? /* @__PURE__ */ d(gr, { ...dr(t.body) }) : /* @__PURE__ */ d(hr, { text: t.body }),
4075
- t.oob && t.body && t.body !== t.oob && t.body !== or(t.oob) && /* @__PURE__ */ d("div", {
4074
+ t.oob ? /* @__PURE__ */ d(pr, { url: t.oob }) : fr(t.body) ? /* @__PURE__ */ d(_r, { ...fr(t.body) }) : /* @__PURE__ */ d(gr, { text: t.body }),
4075
+ t.oob && t.body && t.body !== t.oob && t.body !== sr(t.oob) && /* @__PURE__ */ d("div", {
4076
4076
  className: "ci-text-xs ci-opacity-80 ci-mt-1",
4077
4077
  children: t.body
4078
4078
  }),
4079
4079
  /* @__PURE__ */ d("span", {
4080
4080
  className: "ci-block ci-text-right ci-text-[10px] ci-leading-none ci-opacity-60 ci-mt-1",
4081
- children: cr(t.ts)
4081
+ children: lr(t.ts)
4082
4082
  })
4083
4083
  ]
4084
4084
  }),
4085
- h && /* @__PURE__ */ d(_r, {
4085
+ h && /* @__PURE__ */ d(vr, {
4086
4086
  forMsg: o?.[h],
4087
4087
  me: l,
4088
4088
  mine: t.mine,
@@ -4105,7 +4105,7 @@ function yr({ messages: e, typing: t, onLoadOlder: n, hasOlder: r, group: a, rea
4105
4105
  })
4106
4106
  })
4107
4107
  ]
4108
- }), y && /* @__PURE__ */ d(rr, {
4108
+ }), y && /* @__PURE__ */ d(ir, {
4109
4109
  className: "ci-absolute ci-bottom-2 ci-left-1/2 ci--translate-x-1/2",
4110
4110
  onPick: (e) => C(y, e),
4111
4111
  onClose: () => b(null)
@@ -4114,7 +4114,7 @@ function yr({ messages: e, typing: t, onLoadOlder: n, hasOlder: r, group: a, rea
4114
4114
  }
4115
4115
  //#endregion
4116
4116
  //#region src/ogg.ts
4117
- function br(e, t, n) {
4117
+ function xr(e, t, n) {
4118
4118
  let r = e[t];
4119
4119
  if (r === void 0) return null;
4120
4120
  let i = 1;
@@ -4128,7 +4128,7 @@ function br(e, t, n) {
4128
4128
  unknown: !n && o
4129
4129
  };
4130
4130
  }
4131
- var xr = /* @__PURE__ */ new Set([
4131
+ var Sr = /* @__PURE__ */ new Set([
4132
4132
  408125543,
4133
4133
  524531317,
4134
4134
  374648427,
@@ -4136,18 +4136,18 @@ var xr = /* @__PURE__ */ new Set([
4136
4136
  225,
4137
4137
  160
4138
4138
  ]);
4139
- function Sr(e) {
4139
+ function Cr(e) {
4140
4140
  let t = {
4141
4141
  channels: 1,
4142
4142
  packets: []
4143
4143
  }, n = 0;
4144
4144
  for (; n < e.length;) {
4145
- let r = br(e, n, !0);
4145
+ let r = xr(e, n, !0);
4146
4146
  if (!r) break;
4147
- let i = br(e, n + r.len, !1);
4147
+ let i = xr(e, n + r.len, !1);
4148
4148
  if (!i) break;
4149
4149
  let a = n + r.len + i.len;
4150
- if (xr.has(r.value)) {
4150
+ if (Sr.has(r.value)) {
4151
4151
  n = a;
4152
4152
  continue;
4153
4153
  }
@@ -4156,14 +4156,14 @@ function Sr(e) {
4156
4156
  if (r.value === 25506) t.head = e.slice(a, o);
4157
4157
  else if (r.value === 159) t.channels = e[a] || 1;
4158
4158
  else if (r.value === 163 || r.value === 161) {
4159
- let n = br(e, a, !1);
4159
+ let n = xr(e, a, !1);
4160
4160
  n && (e[a + n.len + 2] >> 1 & 3 || t.packets.push(e.slice(a + n.len + 3, o)));
4161
4161
  }
4162
4162
  n = o;
4163
4163
  }
4164
4164
  return t;
4165
4165
  }
4166
- function Cr(e) {
4166
+ function wr(e) {
4167
4167
  if (!e.length) return 0;
4168
4168
  let t = e[0], n = t >> 3, r;
4169
4169
  r = n < 12 ? [
@@ -4180,7 +4180,7 @@ function Cr(e) {
4180
4180
  let i = t & 3, a = i === 0 ? 1 : i === 3 ? (e[1] ?? 0) & 63 : 2;
4181
4181
  return Math.round(a * r * 48);
4182
4182
  }
4183
- var wr = (() => {
4183
+ var Tr = (() => {
4184
4184
  let e = /* @__PURE__ */ new Uint32Array(256);
4185
4185
  for (let t = 0; t < 256; t++) {
4186
4186
  let n = t << 24;
@@ -4189,12 +4189,12 @@ var wr = (() => {
4189
4189
  }
4190
4190
  return e;
4191
4191
  })();
4192
- function Tr(e) {
4192
+ function Er(e) {
4193
4193
  let t = 0;
4194
- for (let n = 0; n < e.length; n++) t = (t << 8 ^ wr[(t >>> 24 ^ e[n]) & 255]) >>> 0;
4194
+ for (let n = 0; n < e.length; n++) t = (t << 8 ^ Tr[(t >>> 24 ^ e[n]) & 255]) >>> 0;
4195
4195
  return t;
4196
4196
  }
4197
- function Er(e, t, n, r, i) {
4197
+ function Dr(e, t, n, r, i) {
4198
4198
  let a = [];
4199
4199
  for (let t of e) {
4200
4200
  let e = t.length;
@@ -4210,29 +4210,29 @@ function Er(e, t, n, r, i) {
4210
4210
  ], 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);
4211
4211
  let l = 27 + a.length;
4212
4212
  for (let t of e) s.set(t, l), l += t.length;
4213
- return c.setUint32(22, Tr(s), !0), s;
4213
+ return c.setUint32(22, Er(s), !0), s;
4214
4214
  }
4215
- function Dr(e) {
4215
+ function Or(e) {
4216
4216
  let t = /* @__PURE__ */ new Uint8Array(19), n = new DataView(t.buffer);
4217
4217
  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;
4218
4218
  }
4219
- function Or() {
4219
+ function kr() {
4220
4220
  let e = new TextEncoder().encode("chat-island"), t = new Uint8Array(12 + e.length + 4);
4221
4221
  return t.set(new TextEncoder().encode("OpusTags"), 0), new DataView(t.buffer).setUint32(8, e.length, !0), t.set(e, 12), t;
4222
4222
  }
4223
- function kr(e) {
4224
- let { head: t, channels: n, packets: r } = Sr(e);
4223
+ function Ar(e) {
4224
+ let { head: t, channels: n, packets: r } = Cr(e);
4225
4225
  if (!r.length) return null;
4226
- let i = t && t.length >= 19 && new TextDecoder().decode(t.slice(0, 8)) === "OpusHead", a = Math.random() * 4294967295 >>> 0, o = [Er([i ? t : Dr(n)], 0, a, 0, 2), Er([Or()], 0, a, 1, 0)], s = 0, c = 2;
4226
+ let i = t && t.length >= 19 && new TextDecoder().decode(t.slice(0, 8)) === "OpusHead", a = Math.random() * 4294967295 >>> 0, o = [Dr([i ? t : Or(n)], 0, a, 0, 2), Dr([kr()], 0, a, 1, 0)], s = 0, c = 2;
4227
4227
  for (let e = 0; e < r.length;) {
4228
4228
  let t = [], n = 0;
4229
4229
  for (; e < r.length && t.length < 50;) {
4230
4230
  let i = Math.floor(r[e].length / 255) + 1;
4231
4231
  if (n + i > 255) break;
4232
- t.push(r[e]), n += i, s += Cr(r[e]), e++;
4232
+ t.push(r[e]), n += i, s += wr(r[e]), e++;
4233
4233
  }
4234
4234
  if (!t.length) return null;
4235
- o.push(Er(t, s, a, c++, e >= r.length ? 4 : 0));
4235
+ o.push(Dr(t, s, a, c++, e >= r.length ? 4 : 0));
4236
4236
  }
4237
4237
  let l = o.reduce((e, t) => e + t.length, 0), u = new Uint8Array(l), d = 0;
4238
4238
  for (let e of o) u.set(e, d), d += e.length;
@@ -4240,22 +4240,22 @@ function kr(e) {
4240
4240
  }
4241
4241
  //#endregion
4242
4242
  //#region src/components/Composer.tsx
4243
- var Ar = [
4243
+ var jr = [
4244
4244
  "audio/ogg;codecs=opus",
4245
4245
  "audio/webm;codecs=opus",
4246
4246
  "audio/mp4",
4247
4247
  "audio/webm"
4248
4248
  ];
4249
- async function jr(e, t) {
4249
+ async function Mr(e, t) {
4250
4250
  let n = Date.now();
4251
4251
  if (/webm/.test(t) && /opus/.test(t)) try {
4252
- let t = kr(new Uint8Array(await new Blob(e).arrayBuffer()));
4252
+ let t = Ar(new Uint8Array(await new Blob(e).arrayBuffer()));
4253
4253
  if (t) return new File([t], `voice-${n}.ogg`, { type: "audio/ogg" });
4254
4254
  } catch {}
4255
- return new File(e, `voice-${n}.${Mr(t)}`, { type: t.split(";")[0] });
4255
+ return new File(e, `voice-${n}.${Nr(t)}`, { type: t.split(";")[0] });
4256
4256
  }
4257
- var Mr = (e) => /mp4/.test(e) ? "m4a" : /ogg/.test(e) ? "ogg" : "webm", Nr = (e) => `${Math.floor(e / 6e4)}:${String(Math.floor(e % 6e4 / 1e3)).padStart(2, "0")}`;
4258
- function Pr({ onSend: e, onTyping: t, onFile: n, disabled: r, disabledText: o, focusKey: l }) {
4257
+ var Nr = (e) => /mp4/.test(e) ? "m4a" : /ogg/.test(e) ? "ogg" : "webm", Pr = (e) => `${Math.floor(e / 6e4)}:${String(Math.floor(e % 6e4 / 1e3)).padStart(2, "0")}`;
4258
+ function Fr({ onSend: e, onTyping: t, onFile: n, disabled: r, disabledText: o, focusKey: l }) {
4259
4259
  let [u, p] = c(""), [m, h] = c(!1), g = s(null), _ = s(null), v = s(null), y = s(), b = s(!1), [x, S] = c(null), [C, w] = c(0), T = s(!1), E = s(!1), D = s(!1), O = s({});
4260
4260
  i(() => v.current?.focus(), []), i(() => () => {
4261
4261
  D.current = !0, T.current = !0, window.clearTimeout(y.current);
@@ -4296,9 +4296,9 @@ function Pr({ onSend: e, onTyping: t, onFile: n, disabled: r, disabledText: o, f
4296
4296
  t.getTracks().forEach((e) => e.stop());
4297
4297
  return;
4298
4298
  }
4299
- let r = Ar.find((e) => MediaRecorder.isTypeSupported(e)), i = new MediaRecorder(e, r ? { mimeType: r } : void 0), a = [];
4299
+ let r = jr.find((e) => MediaRecorder.isTypeSupported(e)), i = new MediaRecorder(e, r ? { mimeType: r } : void 0), a = [];
4300
4300
  i.ondataavailable = (e) => e.data.size && a.push(e.data), i.onstop = () => {
4301
- t.getTracks().forEach((e) => e.stop()), O.current = {}, S(null), !T.current && a.length && jr(a, i.mimeType || r || "").then(n);
4301
+ t.getTracks().forEach((e) => e.stop()), O.current = {}, S(null), !T.current && a.length && Mr(a, i.mimeType || r || "").then(n);
4302
4302
  }, T.current = !1, i.start(), O.current = {
4303
4303
  r: i,
4304
4304
  stream: t
@@ -4327,7 +4327,7 @@ function Pr({ onSend: e, onTyping: t, onFile: n, disabled: r, disabledText: o, f
4327
4327
  }),
4328
4328
  /* @__PURE__ */ f("div", {
4329
4329
  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",
4330
- 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 ", Nr(C)] })]
4330
+ 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 ", Pr(C)] })]
4331
4331
  }),
4332
4332
  /* @__PURE__ */ d(Z, {
4333
4333
  variant: "green",
@@ -4341,7 +4341,7 @@ function Pr({ onSend: e, onTyping: t, onFile: n, disabled: r, disabledText: o, f
4341
4341
  }) : /* @__PURE__ */ f("div", {
4342
4342
  className: "ci-relative ci-flex ci-items-center ci-gap-2 ci-px-3 ci-py-3",
4343
4343
  children: [
4344
- m && /* @__PURE__ */ d(rr, {
4344
+ m && /* @__PURE__ */ d(ir, {
4345
4345
  className: "ci-absolute ci-bottom-full ci-left-3 ci-mb-1",
4346
4346
  onPick: ee,
4347
4347
  onClose: () => h(!1)
@@ -4382,7 +4382,7 @@ function Pr({ onSend: e, onTyping: t, onFile: n, disabled: r, disabledText: o, f
4382
4382
  let t = (u.match(/```/g) ?? []).length % 2 == 1;
4383
4383
  e.key === "Enter" && !e.shiftKey && !t && (e.preventDefault(), j());
4384
4384
  },
4385
- className: "ci-block ci-w-full ci-resize-none ci-max-h-32 ci-pl-11 ci-pr-4 ci-py-2.5 ci-rounded-3xl ci-border-0 ci-bg-elevationL2 dark:ci-bg-elevationL2Dark ci-text-gray-900 dark:ci-text-white placeholder:ci-text-gray-500 dark:placeholder:ci-text-gray-400 ci-outline-none focus:ci-ring-2 focus:ci-ring-gray-400 dark:focus:ci-ring-gray-500 ci-text-sm",
4385
+ className: `${r ? "ci-overflow-hidden" : ""} ci-block ci-w-full ci-resize-none ci-max-h-32 ci-pl-11 ci-pr-4 ci-py-2.5 ci-rounded-3xl ci-border-0 ci-bg-elevationL2 dark:ci-bg-elevationL2Dark ci-text-gray-900 dark:ci-text-white placeholder:ci-text-gray-500 dark:placeholder:ci-text-gray-400 ci-outline-none focus:ci-ring-2 focus:ci-ring-gray-400 dark:focus:ci-ring-gray-500 ci-text-sm`,
4386
4386
  style: { height: Math.min(128, 40 + 20 * (u.split("\n").length - 1)) }
4387
4387
  })]
4388
4388
  }),
@@ -4407,14 +4407,14 @@ function Pr({ onSend: e, onTyping: t, onFile: n, disabled: r, disabledText: o, f
4407
4407
  }
4408
4408
  //#endregion
4409
4409
  //#region src/components/ChatWindow.tsx
4410
- var Fr = (e) => !!e && ![
4410
+ var Ir = (e) => !!e && ![
4411
4411
  "offline",
4412
4412
  "dnd",
4413
4413
  "busy",
4414
4414
  "ringing",
4415
4415
  "onhold"
4416
4416
  ].includes(e);
4417
- function Ir({ peer: e, actions: t, onDragStart: n }) {
4417
+ function Lr({ peer: e, actions: t, onDragStart: n }) {
4418
4418
  let { c: r, contacts: a, online: o, mobile: s, inactive: l, status: p, closeChat: m, openChat: h, markRead: g, order: _, me: v } = J(w((t) => ({
4419
4419
  c: t.conversations[e],
4420
4420
  contacts: t.contacts,
@@ -4463,17 +4463,17 @@ function Ir({ peer: e, actions: t, onDragStart: n }) {
4463
4463
  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" : ""}`,
4464
4464
  onPointerDown: n,
4465
4465
  children: [
4466
- r.kind === "group" ? /* @__PURE__ */ d(qn, {
4466
+ r.kind === "group" ? /* @__PURE__ */ d(Jn, {
4467
4467
  name: r.name ?? e,
4468
4468
  size: 36,
4469
4469
  avatar: r.avatar
4470
4470
  }) : /* @__PURE__ */ f("span", {
4471
4471
  className: "ci-relative",
4472
- children: [/* @__PURE__ */ d(Gn, {
4472
+ children: [/* @__PURE__ */ d(Kn, {
4473
4473
  contact: b,
4474
4474
  username: e,
4475
4475
  size: 36
4476
- }), /* @__PURE__ */ d(Kn, {
4476
+ }), /* @__PURE__ */ d(qn, {
4477
4477
  online: o[e],
4478
4478
  presence: b?.presence,
4479
4479
  mobile: s[e]
@@ -4496,7 +4496,7 @@ function Ir({ peer: e, actions: t, onDragStart: n }) {
4496
4496
  children: j ? "No longer active" : p === "online" ? r.kind === "group" ? k.map(O).join(", ") : r.typing ? "typing…" : o[e] ? "online" : s[e] ? "Mobile" : "offline" : p
4497
4497
  })]
4498
4498
  }),
4499
- !j && r.kind !== "group" && b?.number && Fr(b.presence) && /* @__PURE__ */ d(Z, {
4499
+ !j && r.kind !== "group" && b?.number && Ir(b.presence) && /* @__PURE__ */ d(Z, {
4500
4500
  variant: "call",
4501
4501
  title: `Call ${b.number}`,
4502
4502
  "aria-label": "Call",
@@ -4523,11 +4523,11 @@ function Ir({ peer: e, actions: t, onDragStart: n }) {
4523
4523
  children: [
4524
4524
  /* @__PURE__ */ f("span", {
4525
4525
  className: "ci-relative",
4526
- children: [/* @__PURE__ */ d(Gn, {
4526
+ children: [/* @__PURE__ */ d(Kn, {
4527
4527
  contact: a[e],
4528
4528
  username: e,
4529
4529
  size: 28
4530
- }), e !== v && /* @__PURE__ */ d(Kn, {
4530
+ }), e !== v && /* @__PURE__ */ d(qn, {
4531
4531
  online: o[e],
4532
4532
  presence: a[e]?.presence,
4533
4533
  mobile: s[e]
@@ -4543,7 +4543,7 @@ function Ir({ peer: e, actions: t, onDragStart: n }) {
4543
4543
  "aria-label": "Chat",
4544
4544
  onClick: () => h(e),
4545
4545
  children: Q.chat
4546
- }), a[e]?.number && Fr(a[e]?.presence) && /* @__PURE__ */ d(Z, {
4546
+ }), a[e]?.number && Ir(a[e]?.presence) && /* @__PURE__ */ d(Z, {
4547
4547
  variant: "call",
4548
4548
  title: `Call ${a[e]?.number}`,
4549
4549
  "aria-label": "Call",
@@ -4559,7 +4559,7 @@ function Ir({ peer: e, actions: t, onDragStart: n }) {
4559
4559
  /* @__PURE__ */ f("div", {
4560
4560
  className: "ci-flex-1 ci-min-h-0 ci-flex ci-flex-col ci-overflow-hidden ci-rounded-b-3xl",
4561
4561
  children: [
4562
- /* @__PURE__ */ d(yr, {
4562
+ /* @__PURE__ */ d(br, {
4563
4563
  messages: r.messages,
4564
4564
  typing: r.typing,
4565
4565
  group: r.kind === "group",
@@ -4589,10 +4589,10 @@ function Ir({ peer: e, actions: t, onDragStart: n }) {
4589
4589
  children: Q.close
4590
4590
  })]
4591
4591
  }),
4592
- /* @__PURE__ */ d(Pr, {
4592
+ /* @__PURE__ */ d(Fr, {
4593
4593
  focusKey: E,
4594
4594
  disabled: p !== "online" || j,
4595
- disabledText: j ? "This operator is no longer active" : void 0,
4595
+ disabledText: j ? "No longer active" : void 0,
4596
4596
  onSend: (n) => t.send(e, n, C ?? void 0).then(() => T(null)),
4597
4597
  onTyping: (n) => t.typing(e, n),
4598
4598
  onFile: (n) => t.upload(e, n)
@@ -4604,11 +4604,11 @@ function Ir({ peer: e, actions: t, onDragStart: n }) {
4604
4604
  }
4605
4605
  //#endregion
4606
4606
  //#region src/components/NewChat.tsx
4607
- async function Lr(e) {
4607
+ async function Rr(e) {
4608
4608
  let t = await createImageBitmap(e), n = Math.min(t.width, t.height), r = document.createElement("canvas");
4609
4609
  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);
4610
4610
  }
4611
- function Rr({ onOpen: e, onCreateGroup: t }) {
4611
+ function zr({ onOpen: e, onCreateGroup: t }) {
4612
4612
  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(() => {
4613
4613
  let e = Object.values(n), t = l.trim().toLowerCase();
4614
4614
  return t ? e.filter((e) => (e.name ?? "").toLowerCase().includes(t) || e.username.includes(t)) : e;
@@ -4665,11 +4665,11 @@ function Rr({ onOpen: e, onCreateGroup: t }) {
4665
4665
  children: [
4666
4666
  /* @__PURE__ */ f("span", {
4667
4667
  className: "ci-relative",
4668
- children: [/* @__PURE__ */ d(Gn, {
4668
+ children: [/* @__PURE__ */ d(Kn, {
4669
4669
  contact: e,
4670
4670
  username: e.username,
4671
4671
  size: 36
4672
- }), /* @__PURE__ */ d(Kn, {
4672
+ }), /* @__PURE__ */ d(qn, {
4673
4673
  online: r[e.username],
4674
4674
  presence: e.presence,
4675
4675
  mobile: i[e.username]
@@ -4716,7 +4716,7 @@ function Rr({ onOpen: e, onCreateGroup: t }) {
4716
4716
  type: "file",
4717
4717
  accept: "image/*",
4718
4718
  hidden: !0,
4719
- onChange: (e) => e.target.files?.[0] && Lr(e.target.files[0]).then(x).catch(() => {})
4719
+ onChange: (e) => e.target.files?.[0] && Rr(e.target.files[0]).then(x).catch(() => {})
4720
4720
  }),
4721
4721
  /* @__PURE__ */ d("button", {
4722
4722
  type: "button",
@@ -4751,22 +4751,22 @@ function Rr({ onOpen: e, onCreateGroup: t }) {
4751
4751
  }
4752
4752
  //#endregion
4753
4753
  //#region src/theme.ts
4754
- var zr = "chat-island-theme", Br = () => {
4754
+ var Br = "chat-island-theme", Vr = () => {
4755
4755
  try {
4756
- let e = localStorage.getItem(zr);
4756
+ let e = localStorage.getItem(Br);
4757
4757
  return e === "light" || e === "dark" || e === "system" ? e : void 0;
4758
4758
  } catch {
4759
4759
  return;
4760
4760
  }
4761
4761
  };
4762
- function Vr(e) {
4763
- let [t, n] = c(() => e ?? Br()), [r, a] = c(!1);
4764
- return i(() => n(e ?? Br()), [e]), i(() => {
4762
+ function Hr(e) {
4763
+ let [t, n] = c(() => e ?? Vr()), [r, a] = c(!1);
4764
+ return i(() => n(e ?? Vr()), [e]), i(() => {
4765
4765
  let e = (e) => {
4766
4766
  let t = e.detail?.theme;
4767
4767
  if (t === "light" || t === "dark" || t === "system") {
4768
4768
  try {
4769
- localStorage.setItem(zr, t);
4769
+ localStorage.setItem(Br, t);
4770
4770
  } catch {}
4771
4771
  n(t);
4772
4772
  }
@@ -4792,7 +4792,7 @@ function Vr(e) {
4792
4792
  }
4793
4793
  //#endregion
4794
4794
  //#region src/ChatIsland.tsx
4795
- function Hr() {
4795
+ function Ur() {
4796
4796
  let e = J.getState();
4797
4797
  return Object.values(e.conversations).map((t) => {
4798
4798
  let n = t.messages[t.messages.length - 1], r = e.contacts[t.peer];
@@ -4808,7 +4808,7 @@ function Hr() {
4808
4808
  unread: t.unread,
4809
4809
  members: t.members,
4810
4810
  last: n ? {
4811
- body: Gr(n.body),
4811
+ body: Kr(n.body),
4812
4812
  ts: n.ts,
4813
4813
  mine: n.mine,
4814
4814
  oob: n.oob,
@@ -4817,7 +4817,7 @@ function Hr() {
4817
4817
  };
4818
4818
  }).filter((e) => e.last || e.kind === "group").sort((e, t) => (t.last?.ts ?? 0) - (e.last?.ts ?? 0));
4819
4819
  }
4820
- var Ur = class extends t {
4820
+ var Wr = class extends t {
4821
4821
  state = { failed: !1 };
4822
4822
  failures = [];
4823
4823
  static getDerivedStateFromError() {
@@ -4835,7 +4835,7 @@ var Ur = class extends t {
4835
4835
  return this.state.failed ? null : this.props.children;
4836
4836
  }
4837
4837
  };
4838
- function Wr(e) {
4838
+ function Gr(e) {
4839
4839
  try {
4840
4840
  let [t, n, r] = atob(e).split(":");
4841
4841
  return t && n && r ? {
@@ -4847,9 +4847,9 @@ function Wr(e) {
4847
4847
  return null;
4848
4848
  }
4849
4849
  }
4850
- var Gr = (e) => (dr(e) ? "Attachment" : $(e)).replace(/```[^\n]*\n?/g, "").replace(/(\*\*|__|~~|`)/g, "").replace(/(^|\s)[*_](\S[^*_]*)[*_]/g, "$1$2").replace(/\s+/g, " ").trim();
4851
- function Kr({ 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 }) {
4852
- let g = o(() => Wr(e), [e]), _ = Vr(n), v = s(g), y = s(p), b = s(u);
4850
+ var Kr = (e) => (fr(e) ? "Attachment" : $(e)).replace(/```[^\n]*\n?/g, "").replace(/(\*\*|__|~~|`)/g, "").replace(/(^|\s)[*_](\S[^*_]*)[*_]/g, "$1$2").replace(/\s+/g, " ").trim();
4851
+ function qr({ 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 }) {
4852
+ let g = o(() => Gr(e), [e]), _ = Hr(n), v = s(g), y = s(p), b = s(u);
4853
4853
  i(() => {
4854
4854
  v.current = g, y.current = p, b.current = u;
4855
4855
  }, [
@@ -4912,7 +4912,7 @@ function Kr({ dataConfig: e, position: t = "bottom-right", theme: n, serviceWork
4912
4912
  if (!t || !n) return;
4913
4913
  let r = J.getState().conversations[e];
4914
4914
  try {
4915
- r?.kind === "group" && await t.leaveGroup(e, !!r.owner).catch(() => {}), await zn(n.host, n.token, e), J.getState().removeConversation(e);
4915
+ r?.kind === "group" && await t.leaveGroup(e, !!r.owner).catch(() => {}), await Bn(n.host, n.token, e), J.getState().removeConversation(e);
4916
4916
  } catch (e) {
4917
4917
  Y("chat-island-error", {
4918
4918
  scope: "delete",
@@ -5024,7 +5024,7 @@ function Kr({ dataConfig: e, position: t = "bottom-right", theme: n, serviceWork
5024
5024
  };
5025
5025
  C.current = t;
5026
5026
  let i = () => {
5027
- r && !D.current && (D.current = !0, Un(g, r).then((e) => {
5027
+ r && !D.current && (D.current = !0, Wn(g, r).then((e) => {
5028
5028
  if (!e) {
5029
5029
  D.current = !1, J.setState({ push: Notification.permission === "denied" ? "denied" : "ask" });
5030
5030
  return;
@@ -5046,15 +5046,15 @@ function Kr({ dataConfig: e, position: t = "bottom-right", theme: n, serviceWork
5046
5046
  let s = () => t.stop();
5047
5047
  window.addEventListener("pagehide", s), t.start();
5048
5048
  let c = () => {
5049
- Ln(g.host, g.token).then(e.setMobile).catch(() => {}), Rn(g.host, g.token).then(e.setInactive).catch(() => {});
5049
+ Rn(g.host, g.token).then(e.setMobile).catch(() => {}), zn(g.host, g.token).then(e.setInactive).catch(() => {});
5050
5050
  };
5051
5051
  c();
5052
5052
  let u = window.setInterval(c, 12e4);
5053
- In(g.host, g.token, g.username, (e) => J.setState({ myName: e })).then(e.setContacts).catch((e) => Y("chat-island-error", {
5053
+ Ln(g.host, g.token, g.username, (e) => J.setState({ myName: e })).then(e.setContacts).catch((e) => Y("chat-island-error", {
5054
5054
  scope: "contacts",
5055
5055
  message: e.message
5056
5056
  }));
5057
- 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 && N.remove(e)), h = X("chat-island-contacts", ({ contacts: t }) => t && e.setContacts(t)), _ = X("chat-island-conversations-request", () => Y("chat-island-conversations", { conversations: Hr() }));
5057
+ 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 && N.remove(e)), h = X("chat-island-contacts", ({ contacts: t }) => t && e.setContacts(t)), _ = X("chat-island-conversations-request", () => Y("chat-island-conversations", { conversations: Ur() }));
5058
5058
  return () => {
5059
5059
  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;
5060
5060
  };
@@ -5068,7 +5068,7 @@ function Kr({ dataConfig: e, position: t = "bottom-right", theme: n, serviceWork
5068
5068
  M === "online" && P && C.current?.announce(P.split(","));
5069
5069
  }, [M, P]);
5070
5070
  let te = 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 + "#" + Object.keys(e.inactive).length);
5071
- i(() => Y("chat-island-conversations", { conversations: Hr() }), [te]);
5071
+ i(() => Y("chat-island-conversations", { conversations: Ur() }), [te]);
5072
5072
  let ne = J((e) => Object.values(e.conversations).reduce((e, t) => e + t.unread, 0));
5073
5073
  if (i(() => Y("chat-island-unread", { total: ne }), [ne]), !g) return null;
5074
5074
  let re = m && !h && A.anchor ? {
@@ -5081,17 +5081,17 @@ function Kr({ dataConfig: e, position: t = "bottom-right", theme: n, serviceWork
5081
5081
  onClickCapture: A.onClickCapture,
5082
5082
  className: `chat-island-root ${_ ? "ci-dark" : ""} ci-fixed ${ie} ci-z-[9999] ci-flex ci-items-end ci-gap-3 ci-font-sans ci-select-none`,
5083
5083
  "data-status": M,
5084
- children: /* @__PURE__ */ f(Ur, { children: [
5085
- ee && /* @__PURE__ */ d(Ir, {
5084
+ children: /* @__PURE__ */ f(Wr, { children: [
5085
+ ee && /* @__PURE__ */ d(Lr, {
5086
5086
  peer: ee,
5087
5087
  actions: N,
5088
5088
  onDragStart: h ?? (m ? A.start : void 0)
5089
5089
  }),
5090
- j && /* @__PURE__ */ d(Rr, {
5090
+ j && /* @__PURE__ */ d(zr, {
5091
5091
  onOpen: (e) => J.getState().openChat(e),
5092
5092
  onCreateGroup: N.createGroup
5093
5093
  }),
5094
- /* @__PURE__ */ d(Xn, {
5094
+ /* @__PURE__ */ d(Zn, {
5095
5095
  onDragStart: h ?? (m ? A.start : void 0),
5096
5096
  pushButton: u !== "auto"
5097
5097
  })
@@ -5099,4 +5099,4 @@ function Kr({ dataConfig: e, position: t = "bottom-right", theme: n, serviceWork
5099
5099
  });
5100
5100
  }
5101
5101
  //#endregion
5102
- export { Kr as ChatIsland, Pn as contactsFromOperators };
5102
+ export { qr as ChatIsland, Fn as contactsFromOperators };