@wexio/messenger-widget-react 1.0.27 → 1.0.29

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.
@@ -293,8 +293,12 @@ async function E(e) {
293
293
  }
294
294
  //#endregion
295
295
  //#region components/widget/tabs/messages-tab/composer/voice-recorder-bar/index.tsx
296
- function D({ onComplete: o, onCancel: c, onError: _ }) {
297
- let v = i("messages"), y = d(null), b = d(null), x = d(null), S = d(null), D = d([]), k = d(null), [A, j] = f("recording"), [M, N] = f(0), [P, F] = f(!1), I = d(null), L = d(!1);
296
+ function D(e) {
297
+ let t = e?.name ?? "", n = e?.message ?? "";
298
+ return t === "NotAllowedError" || t === "PermissionDeniedError" ? "denied" : t === "NotFoundError" || t === "NotReadableError" || t === "OverconstrainedError" || t === "SecurityError" || t === "AbortError" || t === "TypeError" || /not found|could not start|secure origin|not readable|in use/i.test(n) ? "failed" : /permission|denied|not allowed/i.test(n) ? "denied" : "failed";
299
+ }
300
+ function O({ onComplete: o, onCancel: c, onError: _ }) {
301
+ let v = i("messages"), y = d(null), b = d(null), x = d(null), S = d(null), O = d([]), A = d(null), [j, M] = f("recording"), [N, P] = f(0), [F, I] = f(!1), L = d(null), R = d(!1);
298
302
  return u(() => {
299
303
  let e = y.current;
300
304
  if (!e) return;
@@ -303,7 +307,7 @@ function D({ onComplete: o, onCancel: c, onError: _ }) {
303
307
  return;
304
308
  }
305
309
  let t = !1;
306
- L.current = !1;
310
+ R.current = !1;
307
311
  let n = getComputedStyle(e), r = n.getPropertyValue("--wx-primary").trim() || "#5b6cff", i = n.getPropertyValue("--wx-fg-muted").trim() || "#6b7280", a = l.create({
308
312
  container: e,
309
313
  waveColor: i,
@@ -317,7 +321,7 @@ function D({ onComplete: o, onCancel: c, onError: _ }) {
317
321
  interact: !0,
318
322
  hideScrollbar: !0
319
323
  });
320
- b.current = a, a.on("play", () => F(!0)), a.on("pause", () => F(!1)), a.on("finish", () => F(!1));
324
+ b.current = a, a.on("play", () => I(!0)), a.on("pause", () => I(!1)), a.on("finish", () => I(!1));
321
325
  let o = a.registerPlugin(C.create({
322
326
  continuousWaveform: !0,
323
327
  continuousWaveformDuration: 60,
@@ -326,7 +330,7 @@ function D({ onComplete: o, onCancel: c, onError: _ }) {
326
330
  x.current = o;
327
331
  let s = null, c = null;
328
332
  return o.startMic().then((e) => {
329
- if (t || L.current) {
333
+ if (t || R.current) {
330
334
  try {
331
335
  e.getTracks().forEach((e) => {
332
336
  e.stop();
@@ -338,25 +342,25 @@ function D({ onComplete: o, onCancel: c, onError: _ }) {
338
342
  return;
339
343
  }
340
344
  let n = T(), r = n ? new MediaRecorder(e, { mimeType: n }) : new MediaRecorder(e);
341
- S.current = r, c = r, D.current = [], r.addEventListener("dataavailable", (e) => {
342
- e.data && e.data.size > 0 && D.current.push(e.data);
345
+ S.current = r, c = r, O.current = [], r.addEventListener("dataavailable", (e) => {
346
+ e.data && e.data.size > 0 && O.current.push(e.data);
343
347
  }), r.addEventListener("stop", () => {
344
- if (t || L.current) return;
348
+ if (t || R.current) return;
345
349
  try {
346
350
  o.stopMic();
347
351
  } catch {}
348
- s !== null && (clearInterval(s), s = null, k.current = null);
349
- let e = r.mimeType || n || "audio/webm", i = new Blob(D.current, { type: e });
352
+ s !== null && (clearInterval(s), s = null, A.current = null);
353
+ let e = r.mimeType || n || "audio/webm", i = new Blob(O.current, { type: e });
350
354
  E(i).then((n) => {
351
- if (t || L.current) return;
355
+ if (t || R.current) return;
352
356
  let r = e.includes("mp4") ? "mp4" : "webm";
353
- I.current = {
357
+ L.current = {
354
358
  base64: n,
355
359
  mimetype: e.split(";")[0].trim(),
356
360
  size: i.size,
357
361
  filename: `voice-${Date.now()}.${r}`
358
362
  }, a.loadBlob(i).then(() => {
359
- if (!(t || L.current)) {
363
+ if (!(t || R.current)) {
360
364
  try {
361
365
  a.setOptions({ interact: !0 });
362
366
  } catch {}
@@ -364,18 +368,16 @@ function D({ onComplete: o, onCancel: c, onError: _ }) {
364
368
  a.setTime(0);
365
369
  } catch {}
366
370
  }
367
- }).catch(() => {}), j("preview");
371
+ }).catch(() => {}), M("preview");
368
372
  }).catch(() => _("failed"));
369
373
  }), r.start();
370
374
  let i = performance.now();
371
375
  s = window.setInterval(() => {
372
376
  let e = performance.now() - i, t = Math.floor(e / 1e3);
373
- N((e) => e === t ? e : t);
374
- }, 250), k.current = s;
377
+ P((e) => e === t ? e : t);
378
+ }, 250), A.current = s;
375
379
  }).catch((e) => {
376
- if (t) return;
377
- let n = e?.message ?? "";
378
- _(n.includes("Permission") || n.includes("denied") ? "denied" : "failed");
380
+ t || _(D(e));
379
381
  }), () => {
380
382
  t = !0, s !== null && clearInterval(s);
381
383
  try {
@@ -398,10 +400,10 @@ function D({ onComplete: o, onCancel: c, onError: _ }) {
398
400
  transition: { duration: .18 },
399
401
  className: a("flex items-center gap-1.5 rounded-wx-lg border border-wx-border bg-wx-bg px-2 py-2"),
400
402
  children: [
401
- /* @__PURE__ */ m(O, {
403
+ /* @__PURE__ */ m(k, {
402
404
  Icon: t,
403
405
  onClick: () => {
404
- L.current = !0;
406
+ R.current = !0;
405
407
  try {
406
408
  S.current?.state === "recording" && S.current.stop();
407
409
  } catch {}
@@ -419,22 +421,22 @@ function D({ onComplete: o, onCancel: c, onError: _ }) {
419
421
  /* @__PURE__ */ h("div", {
420
422
  className: "flex h-9 min-w-0 flex-1 items-center gap-2 rounded-full bg-wx-bg-elevated px-3",
421
423
  children: [
422
- A === "recording" && /* @__PURE__ */ m("span", {
424
+ j === "recording" && /* @__PURE__ */ m("span", {
423
425
  "aria-hidden": "true",
424
426
  className: "h-2 w-2 shrink-0 animate-pulse rounded-full bg-wx-danger"
425
427
  }),
426
428
  /* @__PURE__ */ m("div", {
427
429
  ref: y,
428
430
  "aria-hidden": "true",
429
- className: a("min-w-0 flex-1 overflow-hidden", A !== "preview" && "pointer-events-none")
431
+ className: a("min-w-0 flex-1 overflow-hidden", j !== "preview" && "pointer-events-none")
430
432
  }),
431
433
  /* @__PURE__ */ m("span", {
432
434
  className: "shrink-0 font-mono text-xs tabular-nums text-wx-fg-muted",
433
- children: w(M)
435
+ children: w(N)
434
436
  })
435
437
  ]
436
438
  }),
437
- A === "recording" && /* @__PURE__ */ m(e.button, {
439
+ j === "recording" && /* @__PURE__ */ m(e.button, {
438
440
  type: "button",
439
441
  onClick: () => {
440
442
  try {
@@ -452,18 +454,18 @@ function D({ onComplete: o, onCancel: c, onError: _ }) {
452
454
  className: a("flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition-colors", "text-wx-fg-muted hover:bg-wx-bg-elevated hover:text-wx-fg"),
453
455
  children: /* @__PURE__ */ m(g, { size: 14 })
454
456
  }),
455
- A === "preview" && /* @__PURE__ */ h(p, { children: [/* @__PURE__ */ m(O, {
456
- Icon: P ? n : r,
457
+ j === "preview" && /* @__PURE__ */ h(p, { children: [/* @__PURE__ */ m(k, {
458
+ Icon: F ? n : r,
457
459
  onClick: () => {
458
460
  let e = b.current;
459
461
  e && (e.isPlaying() ? e.pause() : e.play());
460
462
  },
461
- ariaLabel: v(P ? "pauseRecording" : "playPreview"),
463
+ ariaLabel: v(F ? "pauseRecording" : "playPreview"),
462
464
  intent: "ghost"
463
465
  }), /* @__PURE__ */ m(e.button, {
464
466
  type: "button",
465
467
  onClick: () => {
466
- let e = I.current;
468
+ let e = L.current;
467
469
  e && o(e);
468
470
  },
469
471
  "aria-label": v("sendCta"),
@@ -480,7 +482,7 @@ function D({ onComplete: o, onCancel: c, onError: _ }) {
480
482
  ]
481
483
  }, "voice-recorder");
482
484
  }
483
- function O({ Icon: t, onClick: n, ariaLabel: r, intent: i, size: o = 16 }) {
485
+ function k({ Icon: t, onClick: n, ariaLabel: r, intent: i, size: o = 16 }) {
484
486
  let s = c();
485
487
  return /* @__PURE__ */ m(e.button, {
486
488
  type: "button",
@@ -502,6 +504,6 @@ function O({ Icon: t, onClick: n, ariaLabel: r, intent: i, size: o = 16 }) {
502
504
  });
503
505
  }
504
506
  //#endregion
505
- export { D as VoiceRecorderBar };
507
+ export { O as VoiceRecorderBar };
506
508
 
507
- //# sourceMappingURL=widget-react-B3JUsNG42.js.map
509
+ //# sourceMappingURL=widget-react-zxHGJvC92.js.map