@bravophone/webphone 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -364,8 +364,8 @@ function Le(e) {
364
364
  try {
365
365
  const a = localStorage.getItem(ge);
366
366
  if (!a) return { ...e };
367
- const n = JSON.parse(a);
368
- return n.dock ? { ...e, ...n, ...U(n.dock, n) } : { ...e, ...n };
367
+ const i = JSON.parse(a);
368
+ return i.dock ? { ...e, ...i, ...P(i.dock, i) } : { ...e, ...i };
369
369
  } catch (a) {
370
370
  return { ...e };
371
371
  }
@@ -376,7 +376,7 @@ function K(e) {
376
376
  } catch (a) {
377
377
  }
378
378
  }
379
- function he(e) {
379
+ function le(e) {
380
380
  return {
381
381
  minWidth: e.minWidth,
382
382
  minHeight: e.minHeight,
@@ -387,104 +387,104 @@ function he(e) {
387
387
  };
388
388
  }
389
389
  function R(e) {
390
- const a = Math.max(0, window.innerWidth - e.width), n = Math.max(0, window.innerHeight - 40);
390
+ const a = Math.max(0, window.innerWidth - e.width), i = Math.max(0, window.innerHeight - 40);
391
391
  return {
392
392
  ...e,
393
393
  x: Math.min(Math.max(0, e.x), a),
394
- y: Math.min(Math.max(0, e.y), n)
394
+ y: Math.min(Math.max(0, e.y), i)
395
395
  };
396
396
  }
397
- function U(e, a) {
398
- const n = window.innerWidth, o = window.innerHeight, i = Math.round(n / 2), d = Math.round(o / 2), u = Math.min(a.width, n);
397
+ function P(e, a) {
398
+ const i = window.innerWidth, o = window.innerHeight, r = Math.round(i / 2), d = Math.round(o / 2), u = Math.min(a.width, i);
399
399
  switch (e) {
400
400
  case "left":
401
401
  return { x: 0, y: 0, width: u, height: o };
402
402
  case "right":
403
- return { x: n - u, y: 0, width: u, height: o };
403
+ return { x: i - u, y: 0, width: u, height: o };
404
404
  case "left-half":
405
- return { x: 0, y: 0, width: i, height: o };
405
+ return { x: 0, y: 0, width: r, height: o };
406
406
  case "right-half":
407
- return { x: n - i, y: 0, width: i, height: o };
407
+ return { x: i - r, y: 0, width: r, height: o };
408
408
  case "top":
409
409
  return { x: a.x, y: 0, width: u, height: d };
410
410
  case "bottom":
411
411
  return { x: a.x, y: o - d, width: u, height: d };
412
412
  case "top-half":
413
- return { x: 0, y: 0, width: n, height: d };
413
+ return { x: 0, y: 0, width: i, height: d };
414
414
  case "bottom-half":
415
- return { x: 0, y: o - d, width: n, height: d };
415
+ return { x: 0, y: o - d, width: i, height: d };
416
416
  case "max":
417
- return { x: 0, y: 0, width: n, height: o };
417
+ return { x: 0, y: 0, width: i, height: o };
418
418
  default:
419
419
  return { x: a.x, y: a.y, width: a.width, height: a.height };
420
420
  }
421
421
  }
422
- function ze(e, a, n) {
423
- const o = window.innerWidth, i = window.innerHeight, d = e <= V, u = e >= o - V, f = a <= V, t = a >= i - V;
424
- return (f || t) && d ? "left-half" : (f || t) && u ? "right-half" : f ? n || "max" : t ? "bottom-half" : d ? "left" : u ? "right" : null;
422
+ function ze(e, a, i) {
423
+ const o = window.innerWidth, r = window.innerHeight, d = e <= V, u = e >= o - V, f = a <= V, t = a >= r - V;
424
+ return (f || t) && d ? "left-half" : (f || t) && u ? "right-half" : f ? i || "max" : t ? "bottom-half" : d ? "left" : u ? "right" : null;
425
425
  }
426
- function Se({ root: e, handle: a, handles: n, preview: o, geometry: i, limits: d, topDock: u, onChange: f }) {
427
- let t = { ...i }, g = null, p = "", c = null, h = null, x = null, w = null;
426
+ function Se({ root: e, handle: a, handles: i, preview: o, geometry: r, limits: d, topDock: u, onChange: f }) {
427
+ let t = { ...r }, g = null, p = "", c = null, l = null, x = null, w = null;
428
428
  const z = () => {
429
429
  e.style.left = `${t.x}px`, e.style.top = `${t.y}px`, e.style.width = `${t.width}px`, e.style.height = `${t.height}px`, e.classList.toggle("bp-docked", !!t.dock), f == null || f(t);
430
- }, C = (r) => {
430
+ }, C = (n) => {
431
431
  if (o) {
432
- if (!r) {
432
+ if (!n) {
433
433
  o.hidden = !0;
434
434
  return;
435
435
  }
436
- o.hidden = !1, o.style.left = `${r.x}px`, o.style.top = `${r.y}px`, o.style.width = `${r.width}px`, o.style.height = `${r.height}px`;
436
+ o.hidden = !1, o.style.left = `${n.x}px`, o.style.top = `${n.y}px`, o.style.width = `${n.width}px`, o.style.height = `${n.height}px`;
437
437
  }
438
- }, $ = (r, b) => {
439
- const l = he(d);
438
+ }, $ = (n, b) => {
439
+ const h = le(d);
440
440
  let { x: v, y: S, width: E, height: H } = c;
441
- p.includes("e") && (E = c.width + r), p.includes("w") && (E = c.width - r), p.includes("s") && (H = c.height + b), p.includes("n") && (H = c.height - b), E = Math.min(l.maxWidth, Math.max(l.minWidth, E)), H = Math.min(l.maxHeight, Math.max(l.minHeight, H)), p.includes("w") && (v = c.x + (c.width - E)), p.includes("n") && (S = c.y + (c.height - H)), p.includes("e") && Math.abs(v + E - window.innerWidth) <= X && (E = window.innerWidth - v), p.includes("w") && Math.abs(v) <= X && (E += v, v = 0), p.includes("s") && Math.abs(S + H - window.innerHeight) <= X && (H = window.innerHeight - S), p.includes("n") && Math.abs(S) <= X && (H += S, S = 0), t = { ...t, x: v, y: S, width: E, height: H, dock: null }, z();
442
- }, j = (r, b, l, v) => {
441
+ p.includes("e") && (E = c.width + n), p.includes("w") && (E = c.width - n), p.includes("s") && (H = c.height + b), p.includes("n") && (H = c.height - b), E = Math.min(h.maxWidth, Math.max(h.minWidth, E)), H = Math.min(h.maxHeight, Math.max(h.minHeight, H)), p.includes("w") && (v = c.x + (c.width - E)), p.includes("n") && (S = c.y + (c.height - H)), p.includes("e") && Math.abs(v + E - window.innerWidth) <= X && (E = window.innerWidth - v), p.includes("w") && Math.abs(v) <= X && (E += v, v = 0), p.includes("s") && Math.abs(S + H - window.innerHeight) <= X && (H = window.innerHeight - S), p.includes("n") && Math.abs(S) <= X && (H += S, S = 0), t = { ...t, x: v, y: S, width: E, height: H, dock: null }, z();
442
+ }, j = (n, b, h, v) => {
443
443
  if (t.dock) {
444
- const S = w || { width: d.width, height: d.height }, E = h.x / Math.max(1, t.width);
445
- t = { ...t, ...S, dock: null }, h = { x: Math.round(S.width * E), y: Math.min(h.y, 32) }, c = {
444
+ const S = w || { width: d.width, height: d.height }, E = l.x / Math.max(1, t.width);
445
+ t = { ...t, ...S, dock: null }, l = { x: Math.round(S.width * E), y: Math.min(l.y, 32) }, c = {
446
446
  ...c,
447
- x: l - h.x,
448
- y: v - h.y,
449
- px: c.px + r,
447
+ x: h - l.x,
448
+ y: v - l.y,
449
+ px: c.px + n,
450
450
  py: c.py + b
451
- }, r = 0, b = 0;
451
+ }, n = 0, b = 0;
452
452
  }
453
- t = R({ ...t, x: c.x + r, y: c.y + b }), z(), x = ze(l, v, u), C(x ? U(x, t) : null);
453
+ t = R({ ...t, x: c.x + n, y: c.y + b }), z(), x = ze(h, v, u), C(x ? P(x, t) : null);
454
454
  }, _ = () => {
455
- x && (w = w || { width: t.width, height: t.height }, t = { ...t, ...U(x, t), dock: x }, z());
456
- }, F = (r, b) => (l) => {
457
- l.button === 0 && (r === "drag" && l.target.closest(".bp-btn") || (g = r, p = b || "", c = { px: l.clientX, py: l.clientY, ...t }, h = { x: l.clientX - t.x, y: l.clientY - t.y }, t.dock || (w = { width: t.width, height: t.height }), e.classList.add(r === "drag" ? "bp-dragging" : "bp-resizing"), l.currentTarget.setPointerCapture(l.pointerId), l.preventDefault()));
458
- }, D = (r) => {
455
+ x && (w = w || { width: t.width, height: t.height }, t = { ...t, ...P(x, t), dock: x }, z());
456
+ }, F = (n, b) => (h) => {
457
+ h.button === 0 && (n === "drag" && h.target.closest(".bp-btn") || (g = n, p = b || "", c = { px: h.clientX, py: h.clientY, ...t }, l = { x: h.clientX - t.x, y: h.clientY - t.y }, t.dock || (w = { width: t.width, height: t.height }), e.classList.add(n === "drag" ? "bp-dragging" : "bp-resizing"), h.currentTarget.setPointerCapture(h.pointerId), h.preventDefault()));
458
+ }, A = (n) => {
459
459
  if (!g || !c) return;
460
- const b = r.clientX - c.px, l = r.clientY - c.py;
461
- g === "drag" ? j(b, l, r.clientX, r.clientY) : $(b, l);
462
- }, A = (r) => {
460
+ const b = n.clientX - c.px, h = n.clientY - c.py;
461
+ g === "drag" ? j(b, h, n.clientX, n.clientY) : $(b, h);
462
+ }, B = (n) => {
463
463
  if (g) {
464
464
  e.classList.remove("bp-dragging", "bp-resizing"), C(null), g === "drag" && _(), g = null, p = "", c = null, x = null;
465
465
  try {
466
- r.currentTarget.releasePointerCapture(r.pointerId);
466
+ n.currentTarget.releasePointerCapture(n.pointerId);
467
467
  } catch (b) {
468
468
  }
469
469
  K(t);
470
470
  }
471
471
  };
472
- a.addEventListener("pointerdown", F("drag")), a.addEventListener("pointermove", D), a.addEventListener("pointerup", A), a.addEventListener("pointercancel", A), (n || []).forEach(({ el: r, dir: b }) => {
473
- r.addEventListener("pointerdown", F("resize", b)), r.addEventListener("pointermove", D), r.addEventListener("pointerup", A), r.addEventListener("pointercancel", A);
472
+ a.addEventListener("pointerdown", F("drag")), a.addEventListener("pointermove", A), a.addEventListener("pointerup", B), a.addEventListener("pointercancel", B), (i || []).forEach(({ el: n, dir: b }) => {
473
+ n.addEventListener("pointerdown", F("resize", b)), n.addEventListener("pointermove", A), n.addEventListener("pointerup", B), n.addEventListener("pointercancel", B);
474
474
  });
475
- const N = () => {
476
- t = t.dock ? { ...t, ...U(t.dock, t) } : R(t), z();
475
+ const U = () => {
476
+ t = t.dock ? { ...t, ...P(t.dock, t) } : R(t), z();
477
477
  };
478
- window.addEventListener("resize", N);
478
+ window.addEventListener("resize", U);
479
479
  const G = {
480
- start(r) {
481
- var b, l;
482
- g = "drag", c = { px: r.x, py: r.y, ...t }, h = { x: (b = r.cx) != null ? b : t.width / 2, y: (l = r.cy) != null ? l : 20 }, t.dock || (w = { width: t.width, height: t.height }), e.classList.add("bp-dragging");
480
+ start(n) {
481
+ var b, h;
482
+ g = "drag", c = { px: n.x, py: n.y, ...t }, l = { x: (b = n.cx) != null ? b : t.width / 2, y: (h = n.cy) != null ? h : 20 }, t.dock || (w = { width: t.width, height: t.height }), e.classList.add("bp-dragging");
483
483
  },
484
- move(r) {
484
+ move(n) {
485
485
  if (g !== "drag" || !c) return;
486
- const b = r.x - c.px, l = r.y - c.py;
487
- j(b, l, c.x + b + h.x, c.y + l + h.y);
486
+ const b = n.x - c.px, h = n.y - c.py;
487
+ j(b, h, c.x + b + l.x, c.y + h + l.y);
488
488
  },
489
489
  end() {
490
490
  g === "drag" && (e.classList.remove("bp-dragging"), C(null), _(), g = null, c = null, x = null, K(t));
@@ -495,28 +495,28 @@ function Se({ root: e, handle: a, handles: n, preview: o, geometry: i, limits: d
495
495
  get geometry() {
496
496
  return { ...t };
497
497
  },
498
- set(r) {
499
- const b = he(d), l = { ...t, ...r, dock: null };
500
- l.width = Math.min(b.maxWidth, Math.max(b.minWidth, l.width)), l.height = Math.min(b.maxHeight, Math.max(b.minHeight, l.height)), t = R(l), z(), K(t);
498
+ set(n) {
499
+ const b = le(d), h = { ...t, ...n, dock: null };
500
+ h.width = Math.min(b.maxWidth, Math.max(b.minWidth, h.width)), h.height = Math.min(b.maxHeight, Math.max(b.minHeight, h.height)), t = R(h), z(), K(t);
501
501
  },
502
502
  /** 'left' | 'right' | 'left-half' | 'right-half' | 'max' | 'float' */
503
- dock(r) {
504
- if (!r || r === "float") {
503
+ dock(n) {
504
+ if (!n || n === "float") {
505
505
  const b = w || { width: d.width, height: d.height };
506
506
  t = R({ ...t, ...b, dock: null });
507
507
  } else
508
- t.dock || (w = { width: t.width, height: t.height }), t = { ...t, ...U(r, t), dock: r };
508
+ t.dock || (w = { width: t.width, height: t.height }), t = { ...t, ...P(n, t), dock: n };
509
509
  z(), K(t);
510
510
  },
511
511
  destroy() {
512
- window.removeEventListener("resize", N);
512
+ window.removeEventListener("resize", U);
513
513
  }
514
514
  };
515
515
  }
516
516
  const be = "bravophone/v1";
517
- function Ee({ frame: e, origin: a, onEvent: n }) {
517
+ function Ee({ frame: e, origin: a, onEvent: i }) {
518
518
  const o = /* @__PURE__ */ new Map();
519
- let i = 0, d = !1;
519
+ let r = 0, d = !1;
520
520
  const u = [], f = (g) => {
521
521
  var c;
522
522
  if (g.origin !== a || g.source !== e.contentWindow) return;
@@ -524,27 +524,27 @@ function Ee({ frame: e, origin: a, onEvent: n }) {
524
524
  if (!(!p || p.protocol !== be)) {
525
525
  if (p.type === "ready") {
526
526
  for (d = !0; u.length; ) u.shift()();
527
- n == null || n("ready", (c = p.payload) != null ? c : {});
527
+ i == null || i("ready", (c = p.payload) != null ? c : {});
528
528
  return;
529
529
  }
530
530
  if (p.type === "reply") {
531
- const h = o.get(p.id);
532
- if (!h) return;
533
- o.delete(p.id), clearTimeout(h.timer), p.error ? h.reject(new Error(p.error)) : h.resolve(p.payload);
531
+ const l = o.get(p.id);
532
+ if (!l) return;
533
+ o.delete(p.id), clearTimeout(l.timer), p.error ? l.reject(new Error(p.error)) : l.resolve(p.payload);
534
534
  return;
535
535
  }
536
- p.type === "event" && (n == null || n(p.name, p.payload));
536
+ p.type === "event" && (i == null || i(p.name, p.payload));
537
537
  }
538
538
  };
539
539
  window.addEventListener("message", f);
540
540
  function t(g, p, { timeout: c = 15e3 } = {}) {
541
- return new Promise((h, x) => {
542
- const w = `${Date.now()}-${++i}`, z = () => {
541
+ return new Promise((l, x) => {
542
+ const w = `${Date.now()}-${++r}`, z = () => {
543
543
  var $;
544
544
  const C = setTimeout(() => {
545
545
  o.delete(w), x(new Error(`Bravophone: timeout no comando "${g}"`));
546
546
  }, c);
547
- o.set(w, { resolve: h, reject: x, timer: C }), ($ = e.contentWindow) == null || $.postMessage(
547
+ o.set(w, { resolve: l, reject: x, timer: C }), ($ = e.contentWindow) == null || $.postMessage(
548
548
  { protocol: be, type: "command", id: w, command: g, payload: p },
549
549
  a
550
550
  );
@@ -564,7 +564,7 @@ function Ee({ frame: e, origin: a, onEvent: n }) {
564
564
  }
565
565
  };
566
566
  }
567
- const me = "bravophone:launcher", He = 4, ie = 8;
567
+ const me = "bravophone:launcher", He = 4, re = 8;
568
568
  function Te(e) {
569
569
  try {
570
570
  const a = localStorage.getItem(me);
@@ -573,51 +573,51 @@ function Te(e) {
573
573
  return { ...e };
574
574
  }
575
575
  }
576
- function ne(e) {
576
+ function ie(e) {
577
577
  try {
578
578
  localStorage.setItem(me, JSON.stringify(e));
579
579
  } catch (a) {
580
580
  }
581
581
  }
582
582
  function q(e, a) {
583
- const n = Math.max(ie, window.innerHeight - a - ie);
584
- return Math.min(Math.max(ie, e), n);
583
+ const i = Math.max(re, window.innerHeight - a - re);
584
+ return Math.min(Math.max(re, e), i);
585
585
  }
586
- function $e({ el: e, side: a, y: n, onOpen: o }) {
587
- let i = { side: a, y: q(n, e.offsetHeight || 48) }, d = null, u = !1;
586
+ function $e({ el: e, side: a, y: i, onOpen: o }) {
587
+ let r = { side: a, y: q(i, e.offsetHeight || 48) }, d = null, u = !1;
588
588
  const f = () => {
589
- e.dataset.side = i.side, e.style.top = `${i.y}px`, e.style.right = i.side === "right" ? "0px" : "auto", e.style.left = i.side === "left" ? "0px" : "auto";
590
- }, t = (h) => {
591
- h.button === 0 && (d = { py: h.clientY, y: i.y }, u = !1, e.setPointerCapture(h.pointerId));
592
- }, g = (h) => {
589
+ e.dataset.side = r.side, e.style.top = `${r.y}px`, e.style.right = r.side === "right" ? "0px" : "auto", e.style.left = r.side === "left" ? "0px" : "auto";
590
+ }, t = (l) => {
591
+ l.button === 0 && (d = { py: l.clientY, y: r.y }, u = !1, e.setPointerCapture(l.pointerId));
592
+ }, g = (l) => {
593
593
  if (!d) return;
594
- const x = h.clientY - d.py;
595
- !u && Math.abs(x) < He || (u || (u = !0, e.classList.add("bp-launcher-dragging")), i.y = q(d.y + x, e.offsetHeight), f());
596
- }, p = (h) => {
594
+ const x = l.clientY - d.py;
595
+ !u && Math.abs(x) < He || (u || (u = !0, e.classList.add("bp-launcher-dragging")), r.y = q(d.y + x, e.offsetHeight), f());
596
+ }, p = (l) => {
597
597
  if (!d) return;
598
598
  const x = u;
599
599
  d = null, u = !1, e.classList.remove("bp-launcher-dragging");
600
600
  try {
601
- e.releasePointerCapture(h.pointerId);
601
+ e.releasePointerCapture(l.pointerId);
602
602
  } catch (w) {
603
603
  }
604
- x ? ne(i) : o == null || o();
604
+ x ? ie(r) : o == null || o();
605
605
  };
606
- e.addEventListener("pointerdown", t), e.addEventListener("pointermove", g), e.addEventListener("pointerup", p), e.addEventListener("pointercancel", p), e.addEventListener("keydown", (h) => {
607
- (h.key === "Enter" || h.key === " ") && (h.preventDefault(), o == null || o());
606
+ e.addEventListener("pointerdown", t), e.addEventListener("pointermove", g), e.addEventListener("pointerup", p), e.addEventListener("pointercancel", p), e.addEventListener("keydown", (l) => {
607
+ (l.key === "Enter" || l.key === " ") && (l.preventDefault(), o == null || o());
608
608
  });
609
609
  const c = () => {
610
- i.y = q(i.y, e.offsetHeight), f();
610
+ r.y = q(r.y, e.offsetHeight), f();
611
611
  };
612
612
  return window.addEventListener("resize", c), f(), {
613
613
  get state() {
614
- return { ...i };
614
+ return { ...r };
615
615
  },
616
- setSide(h) {
617
- i.side = h, f(), ne(i);
616
+ setSide(l) {
617
+ r.side = l, f(), ie(r);
618
618
  },
619
- moveTo(h) {
620
- i.y = q(h, e.offsetHeight), f(), ne(i);
619
+ moveTo(l) {
620
+ r.y = q(l, e.offsetHeight), f(), ie(r);
621
621
  },
622
622
  destroy() {
623
623
  window.removeEventListener("resize", c);
@@ -628,8 +628,8 @@ const Ie = "https://cdn.jsdelivr.net/npm";
628
628
  function Oe(e, a = "@bravophone/webphone") {
629
629
  return `${Ie}/${a}@${e}/host/`;
630
630
  }
631
- function We({ version: e, parentOrigin: a, token: n, base: o }) {
632
- const i = o || Oe(e), d = JSON.stringify({ parentOrigin: a, token: n || null }).replace(/</g, "\\u003c");
631
+ function We({ version: e, parentOrigin: a, token: i, base: o }) {
632
+ const r = o || Oe(e), d = JSON.stringify({ parentOrigin: a, token: i || null }).replace(/</g, "\\u003c");
633
633
  return `<!doctype html>
634
634
  <html lang="pt-BR">
635
635
  <head>
@@ -641,9 +641,9 @@ function We({ version: e, parentOrigin: a, token: n, base: o }) {
641
641
  elas resolvem contra a página do integrador — o documento herda o
642
642
  baseURI do pai — e somem todas: logo, atender, desligar, mudo, hold,
643
643
  transferir. Com <base>, resolvem contra o CDN. -->
644
- <base href="${i}">
645
- <link rel="stylesheet" href="${i}css/dark-theme.css">
646
- <link rel="stylesheet" href="${i}styles/theme-fixes.css">
644
+ <base href="${r}">
645
+ <link rel="stylesheet" href="${r}css/dark-theme.css">
646
+ <link rel="stylesheet" href="${r}styles/theme-fixes.css">
647
647
  <style>
648
648
  html, body { margin: 0; height: 100%; background: #10131c; overflow: hidden; }
649
649
  #app { height: 100%; }
@@ -661,12 +661,12 @@ function We({ version: e, parentOrigin: a, token: n, base: o }) {
661
661
  }
662
662
  })();
663
663
  <\/script>
664
- <script src="${i}shim/messages.js"><\/script>
665
- <script src="${i}shim/chrome-shim.js"><\/script>
666
- <script src="${i}js/libwebphone.js"><\/script>
667
- <script src="${i}js/bravophone-route-selector.js"><\/script>
668
- <script defer src="${i}popup.js"><\/script>
669
- <script defer src="${i}shim/guest-bridge.js"><\/script>
664
+ <script src="${r}shim/messages.js"><\/script>
665
+ <script src="${r}shim/chrome-shim.js"><\/script>
666
+ <script src="${r}js/libwebphone.js"><\/script>
667
+ <script src="${r}js/bravophone-route-selector.js"><\/script>
668
+ <script defer src="${r}popup.js"><\/script>
669
+ <script defer src="${r}shim/guest-bridge.js"><\/script>
670
670
  </head>
671
671
  <body>
672
672
  <noscript><strong>O webphone precisa de JavaScript habilitado.</strong></noscript>
@@ -687,18 +687,18 @@ const ue = {
687
687
  maxHeight: 1400,
688
688
  margin: 24
689
689
  };
690
- function y(e, a = {}, n = []) {
690
+ function y(e, a = {}, i = []) {
691
691
  const o = document.createElement(e);
692
- for (const [i, d] of Object.entries(a))
693
- i === "class" ? o.className = d : i === "text" ? o.textContent = d : d != null && o.setAttribute(i, d);
694
- return n.forEach((i) => o.appendChild(i)), o;
692
+ for (const [r, d] of Object.entries(a))
693
+ r === "class" ? o.className = d : r === "text" ? o.textContent = d : d != null && o.setAttribute(r, d);
694
+ return i.forEach((r) => o.appendChild(r)), o;
695
695
  }
696
696
  function Ce(e) {
697
697
  const {
698
698
  hostUrl: a,
699
- token: n,
699
+ token: i,
700
700
  position: o = "bottom-right",
701
- open: i = !1,
701
+ open: r = !1,
702
702
  launcher: d = !0,
703
703
  title: u = "BRAVOPHONE",
704
704
  // 'bar' por padrão: título, indicador de estado e controles visíveis.
@@ -712,12 +712,14 @@ function Ce(e) {
712
712
  launcherSide: g = "right",
713
713
  // Desenho da aba: 'phone-waves' | 'waveform' | 'headset' | 'chat-phone'
714
714
  launcherIcon: p = ae,
715
- // 'hosted' o iframe navega para hostUrl (padrão)
716
- // 'srcdoc' — o iframe roda na origem do site e busca o conteúdo no CDN
717
- mode: c = "hosted",
715
+ // 'srcdoc' é o padrão porque é o modo que funciona sem infraestrutura
716
+ // nossa: o webphone vem do CDN, travado nesta versão. 'hosted' navega
717
+ // para hostUrl e depende de um domínio publicado — se ele não existir,
718
+ // o iframe falha em DNS antes de qualquer outra coisa.
719
+ mode: c = "srcdoc",
718
720
  // Base dos assets no modo srcdoc. Padrão: o CDN travado nesta versão.
719
721
  // Serve para desenvolvimento (localhost) e para quem espelhar os assets.
720
- hostBase: h,
722
+ hostBase: l,
721
723
  version: x,
722
724
  emit: w
723
725
  } = e, z = c === "srcdoc", C = z ? window.location.origin : new URL(a).origin, $ = y("div", { "data-bravophone": "root" });
@@ -725,40 +727,40 @@ function Ce(e) {
725
727
  const j = $.attachShadow({ mode: "open" });
726
728
  j.appendChild(y("style", { text: Me }));
727
729
  const _ = (() => {
728
- var le;
729
- const { width: s, height: M, margin: W } = ue, P = window.innerWidth - s - W, ce = window.innerHeight - M - W, pe = {
730
- "bottom-right": { x: P, y: ce },
730
+ var he;
731
+ const { width: s, height: M, margin: W } = ue, N = window.innerWidth - s - W, ce = window.innerHeight - M - W, pe = {
732
+ "bottom-right": { x: N, y: ce },
731
733
  "bottom-left": { x: W, y: ce },
732
- "top-right": { x: P, y: W },
734
+ "top-right": { x: N, y: W },
733
735
  "top-left": { x: W, y: W }
734
736
  };
735
- return R({ ...(le = pe[o]) != null ? le : pe["bottom-right"], width: s, height: M });
736
- })(), F = R(Le(_)), D = y("span", { class: "bp-status", "data-state": "connecting" }), A = y("button", { class: "bp-btn bp-btn-min", title: "Minimizar", text: "—" }), N = y("button", { class: "bp-btn bp-btn-close", title: "Fechar", text: "×" }), G = y("div", { class: "bp-header" }, [
737
- D,
738
- y("span", { class: "bp-title", text: u }),
737
+ return R({ ...(he = pe[o]) != null ? he : pe["bottom-right"], width: s, height: M });
738
+ })(), F = R(Le(_)), A = y("span", { class: "bp-status", "data-state": "connecting" }), B = y("button", { class: "bp-btn bp-btn-min", title: "Minimizar", text: "—" }), U = y("button", { class: "bp-btn bp-btn-close", title: "Fechar", text: "×" }), G = y("div", { class: "bp-header" }, [
739
739
  A,
740
- N
741
- ]), r = y("iframe", {
740
+ y("span", { class: "bp-title", text: u }),
741
+ B,
742
+ U
743
+ ]), n = y("iframe", {
742
744
  class: "bp-frame",
743
745
  // allow= é obrigatório no modo hospedado (cross-origin). Em srcdoc o
744
746
  // microfone já é herdado do topo, mas declarar não custa e documenta.
745
747
  allow: "microphone; autoplay; clipboard-write; speaker-selection",
746
748
  title: "Webphone BRAVOPHONE"
747
749
  });
748
- z ? r.setAttribute(
750
+ z ? n.setAttribute(
749
751
  "srcdoc",
750
- We({ version: x, parentOrigin: C, token: n, base: h })
751
- ) : r.setAttribute(
752
+ We({ version: x, parentOrigin: C, token: i, base: l })
753
+ ) : n.setAttribute(
752
754
  "src",
753
- Ae(new URL(a), { token: n, embed: "1", parent: location.origin })
755
+ Be(new URL(a), { token: i, embed: "1", parent: location.origin })
754
756
  );
755
- const l = ["n", "s", "w", "e", "nw", "ne", "sw", "se"].map((s) => ({
757
+ const h = ["n", "s", "w", "e", "nw", "ne", "sw", "se"].map((s) => ({
756
758
  el: y("div", { class: `bp-h bp-h-${s}` }),
757
759
  dir: s
758
760
  })), v = y("div", { class: "bp-preview" });
759
761
  v.hidden = !0;
760
- const S = y("button", { class: "bp-btn bp-btn-close", title: "Fechar", text: "×" }), E = y("div", { class: "bp-overlay" }, [S]), H = y("div", { class: "bp-body" }, [r, E]), k = y("div", { class: "bp-root" }, [G, H, ...l.map((s) => s.el)]);
761
- f !== "bar" && k.classList.add("bp-chromeless"), k.hidden = !i;
762
+ const S = y("button", { class: "bp-btn bp-btn-close", title: "Fechar", text: "×" }), E = y("div", { class: "bp-overlay" }, [S]), H = y("div", { class: "bp-body" }, [n, E]), k = y("div", { class: "bp-root" }, [G, H, ...h.map((s) => s.el)]);
763
+ f !== "bar" && k.classList.add("bp-chromeless"), k.hidden = !r;
762
764
  const Q = y("span", { class: "bp-launcher-icon" });
763
765
  Q.innerHTML = J[p] || J[ae];
764
766
  const oe = y("span", { class: "bp-launcher-grip", "aria-hidden": "true" });
@@ -788,21 +790,21 @@ function Ce(e) {
788
790
  }), I = Se({
789
791
  root: k,
790
792
  handle: G,
791
- handles: l,
793
+ handles: h,
792
794
  preview: v,
793
795
  geometry: F,
794
796
  limits: ue,
795
797
  topDock: t,
796
798
  onChange: (s) => w("resize", { width: s.width, height: s.height, dock: s.dock || null })
797
799
  }), ee = Ee({
798
- frame: r,
800
+ frame: n,
799
801
  origin: C,
800
802
  onEvent: (s, M) => {
801
803
  var W;
802
- if (s === "ready" && (D.dataset.state = "ready", T.dataset.state = "ready", n && ee.call("auth", { token: n }).catch(() => {
804
+ if (s === "ready" && (A.dataset.state = "ready", T.dataset.state = "ready", i && ee.call("auth", { token: i }).catch(() => {
803
805
  })), s === "state") {
804
- const P = (W = M == null ? void 0 : M.state) != null ? W : "ready";
805
- D.dataset.state = P, T.dataset.state = P;
806
+ const N = (W = M == null ? void 0 : M.state) != null ? W : "ready";
807
+ A.dataset.state = N, T.dataset.state = N;
806
808
  }
807
809
  if (s === "call:incoming" && (O.show(), T.dataset.badge = "1", T.dataset.state = "ringing"), s === "call:answered" && (T.dataset.state = "incall"), s === "call:ended" && (delete T.dataset.badge, T.dataset.state = "ready"), s === "drag:start") {
808
810
  I.external.start(M);
@@ -856,7 +858,7 @@ function Ce(e) {
856
858
  O.hide();
857
859
  return;
858
860
  }
859
- Y = s != null ? s : !Y, k.classList.toggle("bp-minimized", Y), A.textContent = Y ? "▢" : "—";
861
+ Y = s != null ? s : !Y, k.classList.toggle("bp-minimized", Y), B.textContent = Y ? "▢" : "—";
860
862
  },
861
863
  move(s, M) {
862
864
  I.set({ x: s, y: M });
@@ -880,28 +882,28 @@ function Ce(e) {
880
882
  clearTimeout(te), ee.destroy(), I.destroy(), de.destroy(), v.remove(), $.remove();
881
883
  }
882
884
  };
883
- return N.addEventListener("click", () => O.hide()), A.addEventListener("click", () => O.minimize()), S.addEventListener("click", () => O.hide()), O;
885
+ return U.addEventListener("click", () => O.hide()), B.addEventListener("click", () => O.minimize()), S.addEventListener("click", () => O.hide()), O;
884
886
  }
885
- function Ae(e, a) {
886
- const n = new URL(e.href);
887
- for (const [o, i] of Object.entries(a))
888
- i != null && i !== "" && n.searchParams.set(o, i);
889
- return a.token && (n.searchParams.delete("token"), n.hash = `token=${encodeURIComponent(a.token)}`), n.href;
887
+ function Be(e, a) {
888
+ const i = new URL(e.href);
889
+ for (const [o, r] of Object.entries(a))
890
+ r != null && r !== "" && i.searchParams.set(o, r);
891
+ return a.token && (i.searchParams.delete("token"), i.hash = `token=${encodeURIComponent(a.token)}`), i.href;
890
892
  }
891
- const Be = "https://webphone.bravophone.com/embed/";
893
+ const De = "";
892
894
  let L = null;
893
- const B = /* @__PURE__ */ new Map();
894
- function De(e, a) {
895
- var n, o;
896
- (n = B.get(e)) == null || n.forEach((i) => {
895
+ const D = /* @__PURE__ */ new Map();
896
+ function Ae(e, a) {
897
+ var i, o;
898
+ (i = D.get(e)) == null || i.forEach((r) => {
897
899
  try {
898
- i(a);
900
+ r(a);
899
901
  } catch (d) {
900
902
  console.error("[Bravophone] listener falhou:", d);
901
903
  }
902
- }), (o = B.get("*")) == null || o.forEach((i) => {
904
+ }), (o = D.get("*")) == null || o.forEach((r) => {
903
905
  try {
904
- i({ event: e, payload: a });
906
+ r({ event: e, payload: a });
905
907
  } catch (d) {
906
908
  console.error("[Bravophone] listener falhou:", d);
907
909
  }
@@ -911,7 +913,7 @@ function m() {
911
913
  if (!L) throw new Error("Bravophone: chame Bravophone.init() antes.");
912
914
  return L;
913
915
  }
914
- const re = {
916
+ const ne = {
915
917
  /**
916
918
  * Monta o webphone na página.
917
919
  * @param {object} opts
@@ -931,11 +933,15 @@ const re = {
931
933
  if (L) return L;
932
934
  if (typeof window == "undefined" || !document.body)
933
935
  throw new Error("Bravophone: init() precisa rodar no browser, após o <body> existir.");
934
- return location.protocol !== "https:" && location.hostname !== "localhost" && console.warn("[Bravophone] Contexto inseguro: o microfone exige HTTPS ou localhost."), L = Ce({
935
- hostUrl: Be,
936
- version: re.version,
936
+ if (location.protocol !== "https:" && location.hostname !== "localhost" && console.warn("[Bravophone] Contexto inseguro: o microfone exige HTTPS ou localhost."), e.mode === "hosted" && !e.hostUrl)
937
+ throw new Error(
938
+ "Bravophone: mode 'hosted' exige hostUrl. Use mode 'srcdoc' (padrão) para carregar o webphone do CDN sem depender de um host próprio."
939
+ );
940
+ return L = Ce({
941
+ hostUrl: De,
942
+ version: ne.version,
937
943
  ...e,
938
- emit: De
944
+ emit: Ae
939
945
  }), L;
940
946
  },
941
947
  // ---- Controle da janela ----
@@ -1017,19 +1023,19 @@ const re = {
1017
1023
  /** Eventos: ready, state, call:dialing, call:incoming, call:answered,
1018
1024
  * call:ended, call:failed, resize, open, close, error. */
1019
1025
  on(e, a) {
1020
- return B.has(e) || B.set(e, /* @__PURE__ */ new Set()), B.get(e).add(a), () => re.off(e, a);
1026
+ return D.has(e) || D.set(e, /* @__PURE__ */ new Set()), D.get(e).add(a), () => ne.off(e, a);
1021
1027
  },
1022
1028
  off(e, a) {
1023
- var n;
1024
- (n = B.get(e)) == null || n.delete(a);
1029
+ var i;
1030
+ (i = D.get(e)) == null || i.delete(a);
1025
1031
  },
1026
1032
  destroy() {
1027
- L == null || L.destroy(), L = null, B.clear();
1033
+ L == null || L.destroy(), L = null, D.clear();
1028
1034
  },
1029
1035
  // Substituída em build time pelo valor do package.json (ver vite.config.js).
1030
- version: "0.2.1"
1036
+ version: "0.3.0"
1031
1037
  };
1032
- typeof window != "undefined" && (window.Bravophone = re);
1038
+ typeof window != "undefined" && (window.Bravophone = ne);
1033
1039
  export {
1034
- re as default
1040
+ ne as default
1035
1041
  };