@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.
- package/README.md +74 -11
- package/dist/bravophone.mjs +167 -161
- package/dist/bravophone.umd.js +4 -4
- package/host/popup.js +1 -1
- package/package.json +4 -2
package/dist/bravophone.mjs
CHANGED
|
@@ -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
|
|
368
|
-
return
|
|
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
|
|
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),
|
|
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),
|
|
394
|
+
y: Math.min(Math.max(0, e.y), i)
|
|
395
395
|
};
|
|
396
396
|
}
|
|
397
|
-
function
|
|
398
|
-
const
|
|
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:
|
|
403
|
+
return { x: i - u, y: 0, width: u, height: o };
|
|
404
404
|
case "left-half":
|
|
405
|
-
return { x: 0, y: 0, width:
|
|
405
|
+
return { x: 0, y: 0, width: r, height: o };
|
|
406
406
|
case "right-half":
|
|
407
|
-
return { x:
|
|
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:
|
|
413
|
+
return { x: 0, y: 0, width: i, height: d };
|
|
414
414
|
case "bottom-half":
|
|
415
|
-
return { x: 0, y: o - d, width:
|
|
415
|
+
return { x: 0, y: o - d, width: i, height: d };
|
|
416
416
|
case "max":
|
|
417
|
-
return { x: 0, y: 0, width:
|
|
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,
|
|
423
|
-
const o = window.innerWidth,
|
|
424
|
-
return (f || t) && d ? "left-half" : (f || t) && u ? "right-half" : f ?
|
|
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:
|
|
427
|
-
let t = { ...
|
|
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 = (
|
|
430
|
+
}, C = (n) => {
|
|
431
431
|
if (o) {
|
|
432
|
-
if (!
|
|
432
|
+
if (!n) {
|
|
433
433
|
o.hidden = !0;
|
|
434
434
|
return;
|
|
435
435
|
}
|
|
436
|
-
o.hidden = !1, o.style.left = `${
|
|
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
|
-
}, $ = (
|
|
439
|
-
const
|
|
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 +
|
|
442
|
-
}, j = (
|
|
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 =
|
|
445
|
-
t = { ...t, ...S, dock: null },
|
|
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:
|
|
448
|
-
y: v -
|
|
449
|
-
px: c.px +
|
|
447
|
+
x: h - l.x,
|
|
448
|
+
y: v - l.y,
|
|
449
|
+
px: c.px + n,
|
|
450
450
|
py: c.py + b
|
|
451
|
-
},
|
|
451
|
+
}, n = 0, b = 0;
|
|
452
452
|
}
|
|
453
|
-
t = R({ ...t, x: c.x +
|
|
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, ...
|
|
456
|
-
}, F = (
|
|
457
|
-
|
|
458
|
-
},
|
|
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 =
|
|
461
|
-
g === "drag" ? j(b,
|
|
462
|
-
},
|
|
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
|
-
|
|
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",
|
|
473
|
-
|
|
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
|
|
476
|
-
t = t.dock ? { ...t, ...
|
|
475
|
+
const U = () => {
|
|
476
|
+
t = t.dock ? { ...t, ...P(t.dock, t) } : R(t), z();
|
|
477
477
|
};
|
|
478
|
-
window.addEventListener("resize",
|
|
478
|
+
window.addEventListener("resize", U);
|
|
479
479
|
const G = {
|
|
480
|
-
start(
|
|
481
|
-
var b,
|
|
482
|
-
g = "drag", c = { px:
|
|
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(
|
|
484
|
+
move(n) {
|
|
485
485
|
if (g !== "drag" || !c) return;
|
|
486
|
-
const b =
|
|
487
|
-
j(b,
|
|
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(
|
|
499
|
-
const b =
|
|
500
|
-
|
|
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(
|
|
504
|
-
if (!
|
|
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, ...
|
|
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",
|
|
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:
|
|
517
|
+
function Ee({ frame: e, origin: a, onEvent: i }) {
|
|
518
518
|
const o = /* @__PURE__ */ new Map();
|
|
519
|
-
let
|
|
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
|
-
|
|
527
|
+
i == null || i("ready", (c = p.payload) != null ? c : {});
|
|
528
528
|
return;
|
|
529
529
|
}
|
|
530
530
|
if (p.type === "reply") {
|
|
531
|
-
const
|
|
532
|
-
if (!
|
|
533
|
-
o.delete(p.id), clearTimeout(
|
|
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" && (
|
|
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((
|
|
542
|
-
const w = `${Date.now()}-${++
|
|
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:
|
|
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,
|
|
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
|
|
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
|
|
584
|
-
return Math.min(Math.max(
|
|
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:
|
|
587
|
-
let
|
|
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 =
|
|
590
|
-
}, t = (
|
|
591
|
-
|
|
592
|
-
}, g = (
|
|
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 =
|
|
595
|
-
!u && Math.abs(x) < He || (u || (u = !0, e.classList.add("bp-launcher-dragging")),
|
|
596
|
-
}, p = (
|
|
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(
|
|
601
|
+
e.releasePointerCapture(l.pointerId);
|
|
602
602
|
} catch (w) {
|
|
603
603
|
}
|
|
604
|
-
x ?
|
|
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", (
|
|
607
|
-
(
|
|
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
|
-
|
|
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 { ...
|
|
614
|
+
return { ...r };
|
|
615
615
|
},
|
|
616
|
-
setSide(
|
|
617
|
-
|
|
616
|
+
setSide(l) {
|
|
617
|
+
r.side = l, f(), ie(r);
|
|
618
618
|
},
|
|
619
|
-
moveTo(
|
|
620
|
-
|
|
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:
|
|
632
|
-
const
|
|
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="${
|
|
645
|
-
<link rel="stylesheet" href="${
|
|
646
|
-
<link rel="stylesheet" href="${
|
|
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="${
|
|
665
|
-
<script src="${
|
|
666
|
-
<script src="${
|
|
667
|
-
<script src="${
|
|
668
|
-
<script defer src="${
|
|
669
|
-
<script defer src="${
|
|
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 = {},
|
|
690
|
+
function y(e, a = {}, i = []) {
|
|
691
691
|
const o = document.createElement(e);
|
|
692
|
-
for (const [
|
|
693
|
-
|
|
694
|
-
return
|
|
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:
|
|
699
|
+
token: i,
|
|
700
700
|
position: o = "bottom-right",
|
|
701
|
-
open:
|
|
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
|
-
// '
|
|
716
|
-
//
|
|
717
|
-
|
|
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:
|
|
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
|
|
729
|
-
const { width: s, height: M, margin: W } = ue,
|
|
730
|
-
"bottom-right": { x:
|
|
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:
|
|
734
|
+
"top-right": { x: N, y: W },
|
|
733
735
|
"top-left": { x: W, y: W }
|
|
734
736
|
};
|
|
735
|
-
return R({ ...(
|
|
736
|
-
})(), F = R(Le(_)),
|
|
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
|
-
|
|
741
|
-
|
|
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 ?
|
|
750
|
+
z ? n.setAttribute(
|
|
749
751
|
"srcdoc",
|
|
750
|
-
We({ version: x, parentOrigin: C, token:
|
|
751
|
-
) :
|
|
752
|
+
We({ version: x, parentOrigin: C, token: i, base: l })
|
|
753
|
+
) : n.setAttribute(
|
|
752
754
|
"src",
|
|
753
|
-
|
|
755
|
+
Be(new URL(a), { token: i, embed: "1", parent: location.origin })
|
|
754
756
|
);
|
|
755
|
-
const
|
|
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" }, [
|
|
761
|
-
f !== "bar" && k.classList.add("bp-chromeless"), k.hidden = !
|
|
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:
|
|
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:
|
|
800
|
+
frame: n,
|
|
799
801
|
origin: C,
|
|
800
802
|
onEvent: (s, M) => {
|
|
801
803
|
var W;
|
|
802
|
-
if (s === "ready" && (
|
|
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
|
|
805
|
-
|
|
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),
|
|
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
|
|
885
|
+
return U.addEventListener("click", () => O.hide()), B.addEventListener("click", () => O.minimize()), S.addEventListener("click", () => O.hide()), O;
|
|
884
886
|
}
|
|
885
|
-
function
|
|
886
|
-
const
|
|
887
|
-
for (const [o,
|
|
888
|
-
|
|
889
|
-
return a.token && (
|
|
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
|
|
893
|
+
const De = "";
|
|
892
894
|
let L = null;
|
|
893
|
-
const
|
|
894
|
-
function
|
|
895
|
-
var
|
|
896
|
-
(
|
|
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
|
-
|
|
900
|
+
r(a);
|
|
899
901
|
} catch (d) {
|
|
900
902
|
console.error("[Bravophone] listener falhou:", d);
|
|
901
903
|
}
|
|
902
|
-
}), (o =
|
|
904
|
+
}), (o = D.get("*")) == null || o.forEach((r) => {
|
|
903
905
|
try {
|
|
904
|
-
|
|
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
|
|
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
|
-
|
|
935
|
-
|
|
936
|
-
|
|
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:
|
|
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
|
|
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
|
|
1024
|
-
(
|
|
1029
|
+
var i;
|
|
1030
|
+
(i = D.get(e)) == null || i.delete(a);
|
|
1025
1031
|
},
|
|
1026
1032
|
destroy() {
|
|
1027
|
-
L == null || L.destroy(), L = null,
|
|
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.
|
|
1036
|
+
version: "0.3.0"
|
|
1031
1037
|
};
|
|
1032
|
-
typeof window != "undefined" && (window.Bravophone =
|
|
1038
|
+
typeof window != "undefined" && (window.Bravophone = ne);
|
|
1033
1039
|
export {
|
|
1034
|
-
|
|
1040
|
+
ne as default
|
|
1035
1041
|
};
|