@liforma/client 0.4.3 → 0.4.4
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/CHANGELOG.md +12 -0
- package/dist/next/index.js +169 -161
- package/dist/next/index.js.map +1 -1
- package/dist/next/v2/experience.d.ts +8 -0
- package/dist/next/v2/experience.d.ts.map +1 -1
- package/dist/next/v2/experienceEvents.d.ts +5 -0
- package/dist/next/v2/experienceEvents.d.ts.map +1 -1
- package/dist/next/v2/shims/embedBaseUrl.d.ts +3 -2
- package/dist/next/v2/shims/embedBaseUrl.d.ts.map +1 -1
- package/dist/next/v2/types/sessionManifest.d.ts +12 -0
- package/dist/next/v2/types/sessionManifest.d.ts.map +1 -1
- package/dist/npm/index.js +153 -145
- package/dist/npm/index.js.map +1 -1
- package/dist/npm/v2/experience.d.ts +8 -0
- package/dist/npm/v2/experience.d.ts.map +1 -1
- package/dist/npm/v2/experienceEvents.d.ts +5 -0
- package/dist/npm/v2/experienceEvents.d.ts.map +1 -1
- package/dist/npm/v2/shims/embedBaseUrl.d.ts +3 -2
- package/dist/npm/v2/shims/embedBaseUrl.d.ts.map +1 -1
- package/dist/npm/v2/speechOnlyManifest.d.ts.map +1 -1
- package/dist/npm/v2/types/sessionManifest.d.ts +12 -0
- package/dist/npm/v2/types/sessionManifest.d.ts.map +1 -1
- package/dist/npm/v2/types/sessionManifestSchema.d.ts +19 -0
- package/dist/npm/v2/types/sessionManifestSchema.d.ts.map +1 -1
- package/dist/react/component/experienceComponentLaunch.d.ts.map +1 -1
- package/dist/react/component/experienceComponentTypes.d.ts +2 -0
- package/dist/react/component/experienceComponentTypes.d.ts.map +1 -1
- package/dist/react/index.js +320 -306
- package/dist/react/index.js.map +1 -1
- package/dist/react/v2/experience.d.ts +8 -0
- package/dist/react/v2/experience.d.ts.map +1 -1
- package/dist/react/v2/experienceEvents.d.ts +5 -0
- package/dist/react/v2/experienceEvents.d.ts.map +1 -1
- package/dist/react/v2/shims/embedBaseUrl.d.ts +3 -2
- package/dist/react/v2/shims/embedBaseUrl.d.ts.map +1 -1
- package/dist/react/v2/types/sessionManifest.d.ts +12 -0
- package/dist/react/v2/types/sessionManifest.d.ts.map +1 -1
- package/dist/sdk/v2/client.js +6 -6
- package/dist/sdk/v2/client.js.map +1 -1
- package/dist/svelte/Experience.svelte +7 -0
- package/package.json +1 -1
package/dist/next/index.js
CHANGED
|
@@ -1391,35 +1391,38 @@ function ct() {
|
|
|
1391
1391
|
let e = st();
|
|
1392
1392
|
return e ? e.endsWith("/embed") ? e : `${e}/embed` : T() ? ot : at;
|
|
1393
1393
|
}
|
|
1394
|
-
function lt(e, t
|
|
1394
|
+
function lt(e, t) {
|
|
1395
|
+
return e?.trim() || t?.trim() || void 0;
|
|
1396
|
+
}
|
|
1397
|
+
function ut(e, t, n, r, i, a, o, s) {
|
|
1395
1398
|
let c = (e ?? ct()).replace(/\/$/, ""), l = c.endsWith("/embed") ? c : `${c}/embed`, u = new URL(l), d = n?.trim();
|
|
1396
|
-
d && u.searchParams.set("locationId", d);
|
|
1399
|
+
d && (u.searchParams.set("backdropId", d), u.searchParams.set("locationId", d));
|
|
1397
1400
|
let f = r?.trim();
|
|
1398
|
-
return f && u.searchParams.set("avatarId", f), (i === "face" || i === "medium") && u.searchParams.set("fit", i), a === "widget" && u.searchParams.set("ui", "widget"), o && u.searchParams.set("close", "1"), t && u.searchParams.set("debug", "true"), (s === 2 || s === 3 || s === 4) && u.searchParams.set("cast", String(s)),
|
|
1401
|
+
return f && u.searchParams.set("avatarId", f), (i === "face" || i === "medium") && u.searchParams.set("fit", i), a === "widget" && u.searchParams.set("ui", "widget"), o && u.searchParams.set("close", "1"), t && u.searchParams.set("debug", "true"), (s === 2 || s === 3 || s === 4) && u.searchParams.set("cast", String(s)), dt(u.toString());
|
|
1399
1402
|
}
|
|
1400
|
-
function
|
|
1403
|
+
function dt(e) {
|
|
1401
1404
|
if (typeof location > "u") return e;
|
|
1402
1405
|
let t = new URL(e);
|
|
1403
1406
|
return t.searchParams.set("parentOrigin", location.origin), t.toString();
|
|
1404
1407
|
}
|
|
1405
|
-
function
|
|
1408
|
+
function ft(e) {
|
|
1406
1409
|
return new URL(e).origin;
|
|
1407
1410
|
}
|
|
1408
1411
|
//#endregion
|
|
1409
1412
|
//#region src/v2/experienceEvents.ts
|
|
1410
|
-
function
|
|
1413
|
+
function pt() {
|
|
1411
1414
|
return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? `evt_${crypto.randomUUID().replace(/-/g, "").slice(0, 12)}` : `evt_${Date.now().toString(36)}${Math.random().toString(36).slice(2, 8)}`;
|
|
1412
1415
|
}
|
|
1413
|
-
function
|
|
1416
|
+
function mt(e, t, n) {
|
|
1414
1417
|
return {
|
|
1415
|
-
id:
|
|
1418
|
+
id: pt(),
|
|
1416
1419
|
type: e,
|
|
1417
1420
|
sessionId: t,
|
|
1418
1421
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1419
1422
|
data: n
|
|
1420
1423
|
};
|
|
1421
1424
|
}
|
|
1422
|
-
function
|
|
1425
|
+
function ht() {
|
|
1423
1426
|
return {
|
|
1424
1427
|
ready: /* @__PURE__ */ new Set(),
|
|
1425
1428
|
started: /* @__PURE__ */ new Set(),
|
|
@@ -1438,39 +1441,39 @@ function mt() {
|
|
|
1438
1441
|
conversationProcessorError: /* @__PURE__ */ new Set()
|
|
1439
1442
|
};
|
|
1440
1443
|
}
|
|
1441
|
-
function
|
|
1444
|
+
function gt(e, t, n) {
|
|
1442
1445
|
return e[t].add(n), () => e[t].delete(n);
|
|
1443
1446
|
}
|
|
1444
|
-
function
|
|
1447
|
+
function _t(e, t, n) {
|
|
1445
1448
|
for (let r of e[t]) r(n);
|
|
1446
1449
|
}
|
|
1447
|
-
function
|
|
1450
|
+
function vt(e) {
|
|
1448
1451
|
for (let t of Object.keys(e)) e[t].clear();
|
|
1449
1452
|
}
|
|
1450
1453
|
//#endregion
|
|
1451
1454
|
//#region src/v2/speech/types.ts
|
|
1452
|
-
function
|
|
1455
|
+
function yt(e) {
|
|
1453
1456
|
return "data" in e && "format" in e && e.format != null && !("track" in e);
|
|
1454
1457
|
}
|
|
1455
|
-
function
|
|
1458
|
+
function bt(e) {
|
|
1456
1459
|
return "url" in e && typeof e.url == "string";
|
|
1457
1460
|
}
|
|
1458
|
-
function
|
|
1461
|
+
function xt(e) {
|
|
1459
1462
|
if (!("track" in e)) return !1;
|
|
1460
1463
|
let t = e.track;
|
|
1461
1464
|
return typeof t != "object" || !t ? !1 : typeof MediaStreamTrack < "u" && t instanceof MediaStreamTrack ? !0 : "kind" in t && "readyState" in t;
|
|
1462
1465
|
}
|
|
1463
|
-
function
|
|
1464
|
-
return !
|
|
1466
|
+
function St(e) {
|
|
1467
|
+
return !yt(e) && !bt(e) && !xt(e) && "encoding" in e && typeof e.encoding == "string";
|
|
1465
1468
|
}
|
|
1466
|
-
var
|
|
1469
|
+
var Ct = [
|
|
1467
1470
|
8e3,
|
|
1468
1471
|
16e3,
|
|
1469
1472
|
22050,
|
|
1470
1473
|
24e3,
|
|
1471
1474
|
44100,
|
|
1472
1475
|
48e3
|
|
1473
|
-
],
|
|
1476
|
+
], wt = {
|
|
1474
1477
|
MAX_CHUNK_BYTES: 64 * 1024,
|
|
1475
1478
|
RECOMMENDED_CHUNK_MS_MIN: 20,
|
|
1476
1479
|
RECOMMENDED_CHUNK_MS_MAX: 200,
|
|
@@ -1481,14 +1484,14 @@ var St = [
|
|
|
1481
1484
|
MAX_UTTERANCE_DURATION_MS: 9e4,
|
|
1482
1485
|
MAX_PENDING_WRITES: 8,
|
|
1483
1486
|
DEFAULT_WRITE_TIMEOUT_MS: 5e3
|
|
1484
|
-
},
|
|
1487
|
+
}, Tt = class extends Error {
|
|
1485
1488
|
operation;
|
|
1486
1489
|
requiredCapability;
|
|
1487
1490
|
name = "UnsupportedSpeechOperationError";
|
|
1488
1491
|
constructor(e, t) {
|
|
1489
1492
|
super(`Speech operation "${e}" requires capability "${t}".`), this.operation = e, this.requiredCapability = t;
|
|
1490
1493
|
}
|
|
1491
|
-
},
|
|
1494
|
+
}, Et = class extends Error {
|
|
1492
1495
|
name = "SpeechUtteranceClosedError";
|
|
1493
1496
|
constructor(e = "Cannot write to a closed or cancelled speech utterance.") {
|
|
1494
1497
|
super(e);
|
|
@@ -1498,72 +1501,72 @@ var St = [
|
|
|
1498
1501
|
constructor(e, t) {
|
|
1499
1502
|
super(e, t);
|
|
1500
1503
|
}
|
|
1501
|
-
},
|
|
1504
|
+
}, Dt = class extends Error {
|
|
1502
1505
|
name = "SpeechBufferTimeoutError";
|
|
1503
1506
|
constructor(e = "Timed out waiting for speech buffer capacity.") {
|
|
1504
1507
|
super(e);
|
|
1505
1508
|
}
|
|
1506
1509
|
};
|
|
1507
|
-
function
|
|
1510
|
+
function Ot(e = "none") {
|
|
1508
1511
|
return {
|
|
1509
1512
|
mode: e,
|
|
1510
1513
|
trackedDurationMs: 0,
|
|
1511
1514
|
fallbackDurationMs: 0
|
|
1512
1515
|
};
|
|
1513
1516
|
}
|
|
1514
|
-
function Ot(e) {
|
|
1515
|
-
return St.includes(e);
|
|
1516
|
-
}
|
|
1517
1517
|
function kt(e) {
|
|
1518
|
+
return Ct.includes(e);
|
|
1519
|
+
}
|
|
1520
|
+
function At(e) {
|
|
1518
1521
|
if (e.encoding !== "pcm_s16le") throw new Q(`Unsupported audio encoding: ${e.encoding}`);
|
|
1519
1522
|
if (e.channels !== 1) throw new Q(`Unsupported channel count: ${e.channels}`);
|
|
1520
|
-
if (!
|
|
1523
|
+
if (!kt(e.sampleRate)) throw new Q(`Unsupported sample rate: ${e.sampleRate}`);
|
|
1521
1524
|
}
|
|
1522
|
-
function
|
|
1523
|
-
if (
|
|
1524
|
-
|
|
1525
|
+
function jt(e) {
|
|
1526
|
+
if (yt(e)) {
|
|
1527
|
+
At(e.format);
|
|
1525
1528
|
return;
|
|
1526
1529
|
}
|
|
1527
|
-
if (
|
|
1530
|
+
if (bt(e)) {
|
|
1528
1531
|
if (!e.url.trim()) throw new Q("Audio URL must be non-empty.");
|
|
1529
|
-
if (e.sampleRate !== void 0 && !
|
|
1532
|
+
if (e.sampleRate !== void 0 && !kt(e.sampleRate)) throw new Q(`Unsupported sample rate: ${e.sampleRate}`);
|
|
1530
1533
|
return;
|
|
1531
1534
|
}
|
|
1532
|
-
if (
|
|
1535
|
+
if (xt(e)) {
|
|
1533
1536
|
if (e.track.kind !== "audio") throw new Q("speech.play track must be an audio MediaStreamTrack.");
|
|
1534
|
-
if (e.sampleRate !== void 0 && !
|
|
1537
|
+
if (e.sampleRate !== void 0 && !kt(e.sampleRate)) throw new Q(`Unsupported sample rate: ${e.sampleRate}`);
|
|
1535
1538
|
return;
|
|
1536
1539
|
}
|
|
1537
|
-
if (
|
|
1540
|
+
if (St(e)) {
|
|
1538
1541
|
let t = e.encoding.trim().toLowerCase();
|
|
1539
1542
|
if (!t) throw new Q("Encoded audio MIME type is required.");
|
|
1540
1543
|
if (t === "pcm_s16le") throw new Q("Use format: { encoding: \"pcm_s16le\", … } for raw PCM.");
|
|
1541
|
-
if (e.sampleRate !== void 0 && !
|
|
1544
|
+
if (e.sampleRate !== void 0 && !kt(e.sampleRate)) throw new Q(`Unsupported sample rate: ${e.sampleRate}`);
|
|
1542
1545
|
return;
|
|
1543
1546
|
}
|
|
1544
1547
|
throw new Q("Unsupported speech.play audio shape.");
|
|
1545
1548
|
}
|
|
1546
|
-
function
|
|
1547
|
-
if (e.format) return
|
|
1549
|
+
function Mt(e) {
|
|
1550
|
+
if (e.format) return At(e.format), e.format;
|
|
1548
1551
|
if (e.track) {
|
|
1549
1552
|
let t = {
|
|
1550
1553
|
encoding: "pcm_s16le",
|
|
1551
1554
|
sampleRate: e.sampleRate ?? 24e3,
|
|
1552
1555
|
channels: 1
|
|
1553
1556
|
};
|
|
1554
|
-
return
|
|
1557
|
+
return At(t), t;
|
|
1555
1558
|
}
|
|
1556
1559
|
throw new Q("createUtterance requires format or track.");
|
|
1557
1560
|
}
|
|
1558
|
-
function
|
|
1561
|
+
function Nt(e) {
|
|
1559
1562
|
return e instanceof Uint8Array ? e : new Uint8Array(e);
|
|
1560
1563
|
}
|
|
1561
|
-
function
|
|
1564
|
+
function Pt(e) {
|
|
1562
1565
|
return e === "replace-active" || e === "replace-all" ? "interrupt" : "enqueue";
|
|
1563
1566
|
}
|
|
1564
1567
|
//#endregion
|
|
1565
1568
|
//#region src/byo/pcm.ts
|
|
1566
|
-
function
|
|
1569
|
+
function Ft(e) {
|
|
1567
1570
|
let t = new Uint8Array(e.length * 2), n = new DataView(t.buffer);
|
|
1568
1571
|
for (let t = 0; t < e.length; t++) {
|
|
1569
1572
|
let r = Math.max(-1, Math.min(1, e[t]));
|
|
@@ -1573,11 +1576,11 @@ function Pt(e) {
|
|
|
1573
1576
|
}
|
|
1574
1577
|
//#endregion
|
|
1575
1578
|
//#region src/byo/resample.ts
|
|
1576
|
-
function
|
|
1579
|
+
function It(e, t, n, r, i) {
|
|
1577
1580
|
let a = -.5 * e + 1.5 * t - 1.5 * n + .5 * r, o = e - 2.5 * t + 2 * n - .5 * r, s = -.5 * e + .5 * n, c = t;
|
|
1578
1581
|
return ((a * i + o) * i + s) * i + c;
|
|
1579
1582
|
}
|
|
1580
|
-
function
|
|
1583
|
+
function Lt(e, t) {
|
|
1581
1584
|
if (!(e > 0) || !(t > 0)) throw Error("Resampler rates must be positive");
|
|
1582
1585
|
if (e === t) return {
|
|
1583
1586
|
fromRate: e,
|
|
@@ -1600,7 +1603,7 @@ function It(e, t) {
|
|
|
1600
1603
|
let a = [];
|
|
1601
1604
|
for (; i + 2 < r.length - 1;) {
|
|
1602
1605
|
let e = Math.floor(i), t = i - e, o = Math.max(0, e - 1), s = Math.min(r.length - 1, e + 1), c = Math.min(r.length - 1, e + 2);
|
|
1603
|
-
a.push(
|
|
1606
|
+
a.push(It(r[o], r[e], r[s], r[c], t)), i += n;
|
|
1604
1607
|
}
|
|
1605
1608
|
let o = Math.max(0, Math.floor(i) - 1);
|
|
1606
1609
|
return o > 0 && (r = r.subarray(o), i -= o), a.length ? Float32Array.from(a) : new Float32Array();
|
|
@@ -1612,7 +1615,7 @@ function It(e, t) {
|
|
|
1612
1615
|
}
|
|
1613
1616
|
//#endregion
|
|
1614
1617
|
//#region src/byo/audioCapture.ts
|
|
1615
|
-
var
|
|
1618
|
+
var Rt = "liforma-pcm-capture", zt = `
|
|
1616
1619
|
class LiformaPcmCaptureProcessor extends AudioWorkletProcessor {
|
|
1617
1620
|
process(inputs) {
|
|
1618
1621
|
const ch = inputs[0] && inputs[0][0];
|
|
@@ -1624,29 +1627,29 @@ class LiformaPcmCaptureProcessor extends AudioWorkletProcessor {
|
|
|
1624
1627
|
return true;
|
|
1625
1628
|
}
|
|
1626
1629
|
}
|
|
1627
|
-
registerProcessor('${
|
|
1628
|
-
`,
|
|
1629
|
-
function Bt() {
|
|
1630
|
-
return zt ||= URL.createObjectURL(new Blob([Rt], { type: "application/javascript" })), zt;
|
|
1631
|
-
}
|
|
1630
|
+
registerProcessor('${Rt}', LiformaPcmCaptureProcessor);
|
|
1631
|
+
`, Bt = null;
|
|
1632
1632
|
function Vt() {
|
|
1633
|
+
return Bt ||= URL.createObjectURL(new Blob([zt], { type: "application/javascript" })), Bt;
|
|
1634
|
+
}
|
|
1635
|
+
function Ht() {
|
|
1633
1636
|
return window.AudioContext || window.webkitAudioContext || null;
|
|
1634
1637
|
}
|
|
1635
|
-
async function
|
|
1636
|
-
let { mediaStream: t, targetSampleRate: n, onPcm: r, shouldSend: i, onLog: a } = e, o =
|
|
1638
|
+
async function Ut(e) {
|
|
1639
|
+
let { mediaStream: t, targetSampleRate: n, onPcm: r, shouldSend: i, onLog: a } = e, o = Ht();
|
|
1637
1640
|
if (!o) throw Error("Web Audio is required for audio capture");
|
|
1638
1641
|
let s = new o(), c = s.createMediaStreamSource(t), l = s.createGain();
|
|
1639
1642
|
l.gain.value = 0;
|
|
1640
|
-
let u = s.sampleRate, d =
|
|
1643
|
+
let u = s.sampleRate, d = Lt(u, n), f = !1, p = !1, m = (e) => {
|
|
1641
1644
|
if (f || i && !i()) return;
|
|
1642
1645
|
let t = d.push(e);
|
|
1643
|
-
t.length !== 0 && r(
|
|
1646
|
+
t.length !== 0 && r(Ft(t));
|
|
1644
1647
|
}, h = () => void 0;
|
|
1645
1648
|
return await (async () => {
|
|
1646
1649
|
if (typeof s.audioWorklet?.addModule != "function") return !1;
|
|
1647
1650
|
try {
|
|
1648
|
-
await s.audioWorklet.addModule(
|
|
1649
|
-
let e = new AudioWorkletNode(s,
|
|
1651
|
+
await s.audioWorklet.addModule(Vt());
|
|
1652
|
+
let e = new AudioWorkletNode(s, Rt, {
|
|
1650
1653
|
numberOfInputs: 1,
|
|
1651
1654
|
numberOfOutputs: 1,
|
|
1652
1655
|
outputChannelCount: [1]
|
|
@@ -1696,7 +1699,7 @@ async function Ht(e) {
|
|
|
1696
1699
|
}
|
|
1697
1700
|
//#endregion
|
|
1698
1701
|
//#region src/v2/speech/captureMediaStreamTrack.ts
|
|
1699
|
-
async function
|
|
1702
|
+
async function Wt(e) {
|
|
1700
1703
|
let { track: t, utterance: n, sampleRate: r, signal: i } = e;
|
|
1701
1704
|
if (typeof MediaStreamTrack > "u" || !(t instanceof MediaStreamTrack)) throw new Q("MediaStreamTrack is not available in this environment.");
|
|
1702
1705
|
if (t.kind !== "audio") throw new Q("speech.play track must be an audio MediaStreamTrack.");
|
|
@@ -1705,18 +1708,18 @@ async function Ut(e) {
|
|
|
1705
1708
|
s || (s = !0, c?.stop(), c = null);
|
|
1706
1709
|
};
|
|
1707
1710
|
try {
|
|
1708
|
-
c = await
|
|
1711
|
+
c = await Ut({
|
|
1709
1712
|
mediaStream: a,
|
|
1710
1713
|
targetSampleRate: r,
|
|
1711
1714
|
shouldSend: () => !s && !i?.aborted,
|
|
1712
1715
|
onPcm: (e) => {
|
|
1713
1716
|
if (s || i?.aborted) return;
|
|
1714
|
-
let t =
|
|
1717
|
+
let t = Nt(e);
|
|
1715
1718
|
o = o.then(async () => {
|
|
1716
1719
|
if (s || i?.aborted) return;
|
|
1717
1720
|
let e = 0;
|
|
1718
1721
|
for (; e < t.byteLength;) {
|
|
1719
|
-
let r = Math.min(e +
|
|
1722
|
+
let r = Math.min(e + wt.MAX_CHUNK_BYTES, t.byteLength);
|
|
1720
1723
|
if ((r - e) % 2 == 1 && --r, r <= e) break;
|
|
1721
1724
|
let i = t.subarray(e, r);
|
|
1722
1725
|
e = r, i.byteLength !== 0 && await n.write(i);
|
|
@@ -1740,10 +1743,10 @@ async function Ut(e) {
|
|
|
1740
1743
|
}
|
|
1741
1744
|
//#endregion
|
|
1742
1745
|
//#region src/v2/speech/speechController.ts
|
|
1743
|
-
async function
|
|
1744
|
-
if (
|
|
1745
|
-
if (
|
|
1746
|
-
let t =
|
|
1746
|
+
async function Gt(e, t) {
|
|
1747
|
+
if (xt(e)) throw new Q("MediaStreamTrack play is handled on the host before embed.");
|
|
1748
|
+
if (yt(e)) {
|
|
1749
|
+
let t = Nt(e.data);
|
|
1747
1750
|
if (t.byteLength & 1) throw new Q("PCM byte length must be even.");
|
|
1748
1751
|
return {
|
|
1749
1752
|
kind: "pcm",
|
|
@@ -1751,17 +1754,17 @@ async function Wt(e, t) {
|
|
|
1751
1754
|
format: e.format
|
|
1752
1755
|
};
|
|
1753
1756
|
}
|
|
1754
|
-
if (
|
|
1757
|
+
if (bt(e)) return {
|
|
1755
1758
|
kind: "url",
|
|
1756
1759
|
url: e.url.trim(),
|
|
1757
1760
|
...e.sampleRate === void 0 ? {} : { sampleRate: e.sampleRate }
|
|
1758
1761
|
};
|
|
1759
|
-
if (!
|
|
1762
|
+
if (!St(e)) throw new Q("Unsupported speech.play audio shape.");
|
|
1760
1763
|
let n;
|
|
1761
1764
|
if (typeof Blob < "u" && e.data instanceof Blob) {
|
|
1762
1765
|
if (t?.aborted) throw new DOMException("Play aborted.", "AbortError");
|
|
1763
1766
|
n = new Uint8Array(await e.data.arrayBuffer());
|
|
1764
|
-
} else n =
|
|
1767
|
+
} else n = Nt(e.data);
|
|
1765
1768
|
return {
|
|
1766
1769
|
kind: "encoded",
|
|
1767
1770
|
data: n.slice().buffer,
|
|
@@ -1769,10 +1772,10 @@ async function Wt(e, t) {
|
|
|
1769
1772
|
...e.sampleRate === void 0 ? {} : { sampleRate: e.sampleRate }
|
|
1770
1773
|
};
|
|
1771
1774
|
}
|
|
1772
|
-
function
|
|
1775
|
+
function Kt() {
|
|
1773
1776
|
return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? `utt_${crypto.randomUUID().replace(/-/g, "").slice(0, 12)}` : `utt_${Date.now().toString(36)}${Math.random().toString(36).slice(2, 8)}`;
|
|
1774
1777
|
}
|
|
1775
|
-
function
|
|
1778
|
+
function qt(e, t = "completed") {
|
|
1776
1779
|
return {
|
|
1777
1780
|
utteranceId: e.speechId,
|
|
1778
1781
|
characterId: e.characterId,
|
|
@@ -1786,13 +1789,13 @@ function Kt(e, t = "completed") {
|
|
|
1786
1789
|
}
|
|
1787
1790
|
};
|
|
1788
1791
|
}
|
|
1789
|
-
function
|
|
1792
|
+
function Jt(e) {
|
|
1790
1793
|
return e instanceof Error ? e : new Q(String(e));
|
|
1791
1794
|
}
|
|
1792
|
-
function
|
|
1795
|
+
function Yt(e) {
|
|
1793
1796
|
return e instanceof DOMException && e.name === "AbortError" || e instanceof Error && e.name === "AbortError";
|
|
1794
1797
|
}
|
|
1795
|
-
var
|
|
1798
|
+
var Xt = class {
|
|
1796
1799
|
id;
|
|
1797
1800
|
characterId;
|
|
1798
1801
|
result;
|
|
@@ -1821,29 +1824,29 @@ var Yt = class {
|
|
|
1821
1824
|
queue: e.queue,
|
|
1822
1825
|
...e.transcript === void 0 ? {} : { transcript: e.transcript }
|
|
1823
1826
|
}).catch((e) => {
|
|
1824
|
-
throw this.fail(
|
|
1827
|
+
throw this.fail(Jt(e)), Jt(e);
|
|
1825
1828
|
}), this.signal?.addEventListener("abort", () => {
|
|
1826
1829
|
this.cancel();
|
|
1827
1830
|
}, { once: !0 });
|
|
1828
1831
|
}
|
|
1829
1832
|
async write(e, t) {
|
|
1830
|
-
if (this.closed || this.settled || (await this.beginPromise.catch(() => void 0), this.closed || this.settled)) throw new
|
|
1831
|
-
let n =
|
|
1833
|
+
if (this.closed || this.settled || (await this.beginPromise.catch(() => void 0), this.closed || this.settled)) throw new Et();
|
|
1834
|
+
let n = Nt(e);
|
|
1832
1835
|
if (n.byteLength & 1) throw new Q("PCM chunk byte length must be even (complete s16 samples).");
|
|
1833
|
-
if (n.byteLength >
|
|
1836
|
+
if (n.byteLength > wt.MAX_CHUNK_BYTES) throw new Q(`PCM chunk exceeds MAX_CHUNK_BYTES (${wt.MAX_CHUNK_BYTES}).`);
|
|
1834
1837
|
if (n.byteLength === 0) return;
|
|
1835
|
-
let r = t?.timeoutMs ??
|
|
1838
|
+
let r = t?.timeoutMs ?? wt.DEFAULT_WRITE_TIMEOUT_MS;
|
|
1836
1839
|
await this.acquireWriteSlot(r);
|
|
1837
1840
|
let i = n.byteLength / 2 / this.sampleRate * 1e3;
|
|
1838
|
-
if (this.bufferedMs + i >
|
|
1841
|
+
if (this.bufferedMs + i > wt.MAX_UTTERANCE_DURATION_MS) throw this.releaseWriteSlot(), new Q("Utterance exceeds MAX_UTTERANCE_DURATION_MS.");
|
|
1839
1842
|
let a = async () => {
|
|
1840
|
-
if (this.closed || this.settled) throw new
|
|
1843
|
+
if (this.closed || this.settled) throw new Et();
|
|
1841
1844
|
let e = this.requireHost(), t = n.slice(), i = e.speechUtteranceWrite({
|
|
1842
1845
|
utteranceId: this.id,
|
|
1843
1846
|
audio: t.buffer,
|
|
1844
1847
|
byteLength: t.byteLength
|
|
1845
1848
|
}), a = await Promise.race([i, new Promise((e, t) => {
|
|
1846
|
-
setTimeout(() => t(new
|
|
1849
|
+
setTimeout(() => t(new Dt()), r);
|
|
1847
1850
|
})]);
|
|
1848
1851
|
this.bufferedMs = Math.max(0, a.bufferedMs);
|
|
1849
1852
|
}, o = this.writeChain.then(a, a);
|
|
@@ -1855,7 +1858,7 @@ var Yt = class {
|
|
|
1855
1858
|
}
|
|
1856
1859
|
}
|
|
1857
1860
|
async setTranscript(e) {
|
|
1858
|
-
if (this.closed || this.settled || (await this.beginPromise.catch(() => void 0), this.closed || this.settled)) throw new
|
|
1861
|
+
if (this.closed || this.settled || (await this.beginPromise.catch(() => void 0), this.closed || this.settled)) throw new Et();
|
|
1859
1862
|
await this.requireHost().speechUtteranceSetTranscript({
|
|
1860
1863
|
utteranceId: this.id,
|
|
1861
1864
|
transcript: e
|
|
@@ -1872,7 +1875,7 @@ var Yt = class {
|
|
|
1872
1875
|
});
|
|
1873
1876
|
return this.resolve(t), t;
|
|
1874
1877
|
} catch (e) {
|
|
1875
|
-
let t =
|
|
1878
|
+
let t = Jt(e);
|
|
1876
1879
|
throw this.fail(t), t;
|
|
1877
1880
|
}
|
|
1878
1881
|
}
|
|
@@ -1890,11 +1893,11 @@ var Yt = class {
|
|
|
1890
1893
|
characterId: this.characterId,
|
|
1891
1894
|
status: "cancelled",
|
|
1892
1895
|
durationMs: 0,
|
|
1893
|
-
animation:
|
|
1896
|
+
animation: Ot("none")
|
|
1894
1897
|
};
|
|
1895
1898
|
return this.resolve(t), t;
|
|
1896
1899
|
} catch (e) {
|
|
1897
|
-
let t =
|
|
1900
|
+
let t = Jt(e);
|
|
1898
1901
|
throw this.fail(t), t;
|
|
1899
1902
|
}
|
|
1900
1903
|
}
|
|
@@ -1907,19 +1910,19 @@ var Yt = class {
|
|
|
1907
1910
|
return e;
|
|
1908
1911
|
}
|
|
1909
1912
|
resolve(e) {
|
|
1910
|
-
this.settled || (this.settled = !0, this.settleResolve(Object.freeze(e)), this.flushWriteWaiters(new
|
|
1913
|
+
this.settled || (this.settled = !0, this.settleResolve(Object.freeze(e)), this.flushWriteWaiters(new Et()));
|
|
1911
1914
|
}
|
|
1912
1915
|
fail(e) {
|
|
1913
1916
|
this.settled || (this.settled = !0, this.settleReject(e), this.flushWriteWaiters(e));
|
|
1914
1917
|
}
|
|
1915
1918
|
async acquireWriteSlot(e) {
|
|
1916
|
-
if (this.pendingWriteCount <
|
|
1919
|
+
if (this.pendingWriteCount < wt.MAX_PENDING_WRITES) {
|
|
1917
1920
|
this.pendingWriteCount += 1;
|
|
1918
1921
|
return;
|
|
1919
1922
|
}
|
|
1920
1923
|
await new Promise((t, n) => {
|
|
1921
1924
|
let r = setTimeout(() => {
|
|
1922
|
-
n(new
|
|
1925
|
+
n(new Dt());
|
|
1923
1926
|
}, e);
|
|
1924
1927
|
this.pendingWriteWaiters.push({
|
|
1925
1928
|
resolve: () => {
|
|
@@ -1938,13 +1941,13 @@ var Yt = class {
|
|
|
1938
1941
|
for (; this.pendingWriteWaiters.length > 0;) this.pendingWriteWaiters.shift()?.reject(e);
|
|
1939
1942
|
}
|
|
1940
1943
|
};
|
|
1941
|
-
function
|
|
1944
|
+
function Zt(e) {
|
|
1942
1945
|
let t = null, n = (t, n) => {
|
|
1943
|
-
if (!e.getCapabilities()[n]) throw new
|
|
1946
|
+
if (!e.getCapabilities()[n]) throw new Tt(t, n);
|
|
1944
1947
|
}, r = {
|
|
1945
1948
|
async speak(r) {
|
|
1946
1949
|
if (e.assertSessionStarted(), n("speak", "textSpeech"), r.signal?.aborted) throw new DOMException("Speak aborted.", "AbortError");
|
|
1947
|
-
let i =
|
|
1950
|
+
let i = Pt(r.queue ?? "append");
|
|
1948
1951
|
i === "interrupt" && (e.onProcessorInterrupt?.(), t &&= (t.cancel(), null));
|
|
1949
1952
|
let a = e.getIframeHost();
|
|
1950
1953
|
if (!a) throw new Q("Speech session is not attached.");
|
|
@@ -1964,41 +1967,41 @@ function Xt(e) {
|
|
|
1964
1967
|
return;
|
|
1965
1968
|
}
|
|
1966
1969
|
t.addEventListener("abort", s, { once: !0 }), o.then((e) => {
|
|
1967
|
-
t.removeEventListener("abort", s), n(
|
|
1970
|
+
t.removeEventListener("abort", s), n(qt(e, "completed"));
|
|
1968
1971
|
}, (a) => {
|
|
1969
|
-
if (t.removeEventListener("abort", s),
|
|
1972
|
+
if (t.removeEventListener("abort", s), Yt(a)) {
|
|
1970
1973
|
n({
|
|
1971
1974
|
utteranceId: "utt_interrupted",
|
|
1972
1975
|
characterId: r.characterId ?? e.getActiveCharacterId(),
|
|
1973
1976
|
status: "interrupted",
|
|
1974
1977
|
durationMs: 0,
|
|
1975
1978
|
transcript: r.text,
|
|
1976
|
-
animation:
|
|
1979
|
+
animation: Ot("none")
|
|
1977
1980
|
});
|
|
1978
1981
|
return;
|
|
1979
1982
|
}
|
|
1980
|
-
i(
|
|
1983
|
+
i(Jt(a));
|
|
1981
1984
|
});
|
|
1982
1985
|
});
|
|
1983
1986
|
}
|
|
1984
1987
|
try {
|
|
1985
|
-
return
|
|
1988
|
+
return qt(await o, "completed");
|
|
1986
1989
|
} catch (t) {
|
|
1987
|
-
if (
|
|
1990
|
+
if (Yt(t)) return {
|
|
1988
1991
|
utteranceId: "utt_interrupted",
|
|
1989
1992
|
characterId: r.characterId ?? e.getActiveCharacterId(),
|
|
1990
1993
|
status: "interrupted",
|
|
1991
1994
|
durationMs: 0,
|
|
1992
1995
|
transcript: r.text,
|
|
1993
|
-
animation:
|
|
1996
|
+
animation: Ot("none")
|
|
1994
1997
|
};
|
|
1995
|
-
throw
|
|
1998
|
+
throw Jt(t);
|
|
1996
1999
|
}
|
|
1997
2000
|
},
|
|
1998
2001
|
async play(i) {
|
|
1999
|
-
if (e.assertSessionStarted(), n("play", "externalSpeechAudio"),
|
|
2002
|
+
if (e.assertSessionStarted(), n("play", "externalSpeechAudio"), jt(i.audio), i.signal?.aborted) throw new DOMException("Play aborted.", "AbortError");
|
|
2000
2003
|
let a = i.queue ?? "append";
|
|
2001
|
-
if ((a === "replace-active" || a === "replace-all") && (e.onProcessorInterrupt?.(), t &&= (t.cancel(), null)),
|
|
2004
|
+
if ((a === "replace-active" || a === "replace-all") && (e.onProcessorInterrupt?.(), t &&= (t.cancel(), null)), xt(i.audio)) {
|
|
2002
2005
|
let e = i.audio.sampleRate ?? 24e3;
|
|
2003
2006
|
return r.createUtterance({
|
|
2004
2007
|
format: {
|
|
@@ -2014,7 +2017,7 @@ function Xt(e) {
|
|
|
2014
2017
|
}
|
|
2015
2018
|
let o = e.getIframeHost();
|
|
2016
2019
|
if (!o) throw new Q("Speech session is not attached.");
|
|
2017
|
-
let s = await
|
|
2020
|
+
let s = await Gt(i.audio, i.signal);
|
|
2018
2021
|
return o.speechPlay({
|
|
2019
2022
|
source: s,
|
|
2020
2023
|
characterId: i.characterId,
|
|
@@ -2026,13 +2029,13 @@ function Xt(e) {
|
|
|
2026
2029
|
},
|
|
2027
2030
|
createUtterance(r) {
|
|
2028
2031
|
e.assertSessionStarted(), n("createUtterance", "externalSpeechAudio");
|
|
2029
|
-
let i =
|
|
2032
|
+
let i = Mt(r);
|
|
2030
2033
|
if (r.track && r.track.kind !== "audio") throw new Q("createUtterance track must be an audio MediaStreamTrack.");
|
|
2031
2034
|
let a = r.queue ?? "replace-active";
|
|
2032
2035
|
if (a !== "replace-active" && a !== "replace-all") throw new Q("createUtterance queue must be replace-active or replace-all.");
|
|
2033
2036
|
e.onProcessorInterrupt?.(), t &&= (t.cancel(), null);
|
|
2034
|
-
let o = new
|
|
2035
|
-
id:
|
|
2037
|
+
let o = new Xt({
|
|
2038
|
+
id: Kt(),
|
|
2036
2039
|
characterId: r.characterId ?? e.getActiveCharacterId(),
|
|
2037
2040
|
format: i,
|
|
2038
2041
|
queue: a,
|
|
@@ -2044,7 +2047,7 @@ function Xt(e) {
|
|
|
2044
2047
|
t === o && (t = null);
|
|
2045
2048
|
}), r.track && (async () => {
|
|
2046
2049
|
try {
|
|
2047
|
-
if (await
|
|
2050
|
+
if (await Wt({
|
|
2048
2051
|
track: r.track,
|
|
2049
2052
|
utterance: o,
|
|
2050
2053
|
sampleRate: i.sampleRate,
|
|
@@ -2072,16 +2075,16 @@ function Xt(e) {
|
|
|
2072
2075
|
}
|
|
2073
2076
|
//#endregion
|
|
2074
2077
|
//#region src/v2/types/sessionInteraction.ts
|
|
2075
|
-
function
|
|
2078
|
+
function Qt(e) {
|
|
2076
2079
|
let t = e?.trim();
|
|
2077
2080
|
return t === "full" || t === "face" || t === "medium" ? t : void 0;
|
|
2078
2081
|
}
|
|
2079
2082
|
//#endregion
|
|
2080
2083
|
//#region src/v2/experience.ts
|
|
2081
|
-
function
|
|
2084
|
+
function $t(e) {
|
|
2082
2085
|
return !!(e.showClose === !0 || e.returnUrl?.trim() || e.closeButton === !0 || e.closeButton && typeof e.closeButton == "object" && e.closeButton.visible !== !1);
|
|
2083
2086
|
}
|
|
2084
|
-
var
|
|
2087
|
+
var en = class e {
|
|
2085
2088
|
bootstrap;
|
|
2086
2089
|
conversationProcessor;
|
|
2087
2090
|
iframeHost = null;
|
|
@@ -2096,16 +2099,16 @@ var $t = class e {
|
|
|
2096
2099
|
attached = !1;
|
|
2097
2100
|
pendingFit = null;
|
|
2098
2101
|
closeHandlers = [];
|
|
2099
|
-
eventRegistry =
|
|
2102
|
+
eventRegistry = ht();
|
|
2100
2103
|
readyEnvelope = null;
|
|
2101
2104
|
startedEnvelope = null;
|
|
2102
2105
|
conversationCache = [];
|
|
2103
2106
|
speech;
|
|
2104
2107
|
constructor(e) {
|
|
2105
|
-
this.bootstrap = e, this.conversationProcessor = e.conversationProcessor ?? null, this.resolvedSession = e.kind === "launch" ? e.session ?? null : null, this.launchToken = e.kind === "launch" ? e.launch : null, this.speech =
|
|
2108
|
+
this.bootstrap = e, this.conversationProcessor = e.conversationProcessor ?? null, this.resolvedSession = e.kind === "launch" ? e.session ?? null : null, this.launchToken = e.kind === "launch" ? e.launch : null, this.speech = Zt({
|
|
2106
2109
|
getIframeHost: () => this.iframeHost,
|
|
2107
2110
|
assertSessionStarted: () => this.assertSessionStarted(),
|
|
2108
|
-
getCapabilities: () =>
|
|
2111
|
+
getCapabilities: () => tn(this.resolvedSession),
|
|
2109
2112
|
getActiveCharacterId: () => "character_unknown",
|
|
2110
2113
|
onProcessorInterrupt: () => {
|
|
2111
2114
|
this.processorAbortController?.abort(), this.processorAbortController = null;
|
|
@@ -2120,6 +2123,9 @@ var $t = class e {
|
|
|
2120
2123
|
kind: "launch",
|
|
2121
2124
|
launch: n,
|
|
2122
2125
|
session: t.session,
|
|
2126
|
+
backdropId: t.backdropId,
|
|
2127
|
+
locationId: t.locationId,
|
|
2128
|
+
avatarId: t.avatarId,
|
|
2123
2129
|
embedBaseUrl: t.embedBaseUrl,
|
|
2124
2130
|
debug: t.debug,
|
|
2125
2131
|
speechOnly: t.speechOnly,
|
|
@@ -2137,6 +2143,7 @@ var $t = class e {
|
|
|
2137
2143
|
secondaryLocale: t.secondaryLocale,
|
|
2138
2144
|
learningLocale: t.learningLocale,
|
|
2139
2145
|
language: t.language,
|
|
2146
|
+
backdropId: t.backdropId,
|
|
2140
2147
|
locationId: t.locationId,
|
|
2141
2148
|
avatarId: t.avatarId,
|
|
2142
2149
|
castSize: t.castSize,
|
|
@@ -2157,6 +2164,7 @@ var $t = class e {
|
|
|
2157
2164
|
secondaryLocale: t.secondaryLocale,
|
|
2158
2165
|
learningLocale: t.learningLocale,
|
|
2159
2166
|
language: t.language,
|
|
2167
|
+
backdropId: t.backdropId,
|
|
2160
2168
|
locationId: t.locationId,
|
|
2161
2169
|
avatarId: t.avatarId,
|
|
2162
2170
|
castSize: t.castSize,
|
|
@@ -2179,7 +2187,7 @@ var $t = class e {
|
|
|
2179
2187
|
return null;
|
|
2180
2188
|
}
|
|
2181
2189
|
on(e, t) {
|
|
2182
|
-
let n =
|
|
2190
|
+
let n = gt(this.eventRegistry, e, t);
|
|
2183
2191
|
return e === "ready" && this.readyEnvelope && queueMicrotask(() => t(this.readyEnvelope)), e === "started" && this.startedEnvelope && queueMicrotask(() => t(this.startedEnvelope)), n;
|
|
2184
2192
|
}
|
|
2185
2193
|
async attach(e) {
|
|
@@ -2193,7 +2201,7 @@ var $t = class e {
|
|
|
2193
2201
|
if (this.closed) throw Error("Session has ended.");
|
|
2194
2202
|
if (this.attached && this.iframeHost) return this.createPlayerFacade();
|
|
2195
2203
|
this.iframeHost &&= (this.iframeHost.destroy(), null), this.attachReturnUrl = e.returnUrl?.trim() || null;
|
|
2196
|
-
let t = this.bootstrap.embedBaseUrl ?? ct(), n = this.bootstrap.debug === !0, r = this.bootstrap.speechOnly === !0, i =
|
|
2204
|
+
let t = this.bootstrap.embedBaseUrl ?? ct(), n = this.bootstrap.debug === !0, r = this.bootstrap.speechOnly === !0, i = ut(t, n, r ? void 0 : lt(this.bootstrap.backdropId, this.bootstrap.locationId), r ? void 0 : this.bootstrap.avatarId, e.fit, this.bootstrap.ui, $t(e), this.bootstrap.kind === "launch" ? void 0 : this.bootstrap.castSize), a = ft(i), o = null, s = new Promise((e) => {
|
|
2197
2205
|
o = e;
|
|
2198
2206
|
}), c = null, l = new Promise((e) => {
|
|
2199
2207
|
c = e;
|
|
@@ -2328,7 +2336,7 @@ var $t = class e {
|
|
|
2328
2336
|
this.assertSessionStarted(), await this.iframeHost.focusCharacter(e);
|
|
2329
2337
|
}
|
|
2330
2338
|
async setFit(e) {
|
|
2331
|
-
let t =
|
|
2339
|
+
let t = Qt(e);
|
|
2332
2340
|
if (!t) throw Error("setFit requires \"full\", \"medium\", or \"face\".");
|
|
2333
2341
|
if (this.closed) throw Error("Session has ended.");
|
|
2334
2342
|
this.pendingFit = t, !(!this.attached || !this.iframeHost) && await this.iframeHost.setFit(t);
|
|
@@ -2342,7 +2350,7 @@ var $t = class e {
|
|
|
2342
2350
|
this.close();
|
|
2343
2351
|
}
|
|
2344
2352
|
destroy() {
|
|
2345
|
-
this.closed || (this.closed = !0, this.processorAbortController?.abort(), this.processorAbortController = null, this.endpointAbortController?.abort(), this.endpointAbortController = null, this.attachInFlight = null, this.iframeHost?.destroy(), this.iframeHost = null,
|
|
2353
|
+
this.closed || (this.closed = !0, this.processorAbortController?.abort(), this.processorAbortController = null, this.endpointAbortController?.abort(), this.endpointAbortController = null, this.attachInFlight = null, this.iframeHost?.destroy(), this.iframeHost = null, vt(this.eventRegistry), this.readyEnvelope = null, this.startedEnvelope = null, this.closeHandlers.length = 0, this.attached = !1);
|
|
2346
2354
|
}
|
|
2347
2355
|
resolveMintInteraction() {
|
|
2348
2356
|
return this.bootstrap.kind === "launch" ? {} : {
|
|
@@ -2354,8 +2362,8 @@ var $t = class e {
|
|
|
2354
2362
|
return this.resolvedSession?.id ?? "";
|
|
2355
2363
|
}
|
|
2356
2364
|
emitWrapped(e, t) {
|
|
2357
|
-
let n =
|
|
2358
|
-
return
|
|
2365
|
+
let n = mt(e, this.getSessionId(), t);
|
|
2366
|
+
return _t(this.eventRegistry, e, n), n;
|
|
2359
2367
|
}
|
|
2360
2368
|
queueProcessorTurn(e) {
|
|
2361
2369
|
if (!e.isFinal || !e.text.trim() || !this.conversationProcessor) return;
|
|
@@ -2414,7 +2422,7 @@ var $t = class e {
|
|
|
2414
2422
|
};
|
|
2415
2423
|
}
|
|
2416
2424
|
};
|
|
2417
|
-
function
|
|
2425
|
+
function tn(e) {
|
|
2418
2426
|
return e ? {
|
|
2419
2427
|
textSpeech: e.capabilities.speech.output,
|
|
2420
2428
|
externalSpeechAudio: e.capabilities.speech.externalAudio
|
|
@@ -2425,41 +2433,41 @@ function en(e) {
|
|
|
2425
2433
|
}
|
|
2426
2434
|
//#endregion
|
|
2427
2435
|
//#region src/widget/dockGeometry.ts
|
|
2428
|
-
var
|
|
2429
|
-
function
|
|
2436
|
+
var nn = "(min-width: 768px)", rn = 24, an = .5, on = 1200, sn = .85, cn = 9 / 16;
|
|
2437
|
+
function ln() {
|
|
2430
2438
|
if (typeof window > "u") return 800;
|
|
2431
2439
|
let e = window.screen?.availHeight;
|
|
2432
2440
|
return typeof e == "number" && e > 0 ? e : window.innerHeight;
|
|
2433
2441
|
}
|
|
2434
|
-
function
|
|
2435
|
-
let i = Math.max(160, Math.min(t - n * 2, t *
|
|
2436
|
-
return s > a && (s = a, o = s /
|
|
2442
|
+
function un(e = typeof window < "u" ? window.innerWidth : 1280, t = typeof window < "u" ? window.innerHeight : 800, n = rn, r = typeof window < "u" ? ln() : 800) {
|
|
2443
|
+
let i = Math.max(160, Math.min(t - n * 2, t * sn)), a = Math.max(120, e - n * 2), o = Math.min(r * an, on, i), s = o * cn;
|
|
2444
|
+
return s > a && (s = a, o = s / cn, o > i && (o = i, s = o * cn)), {
|
|
2437
2445
|
width: Math.round(s),
|
|
2438
2446
|
height: Math.round(o)
|
|
2439
2447
|
};
|
|
2440
2448
|
}
|
|
2441
|
-
function
|
|
2449
|
+
function dn(e, t = typeof window < "u" ? window.innerWidth : 1280, n = typeof window < "u" ? window.innerHeight : 800, r = rn) {
|
|
2442
2450
|
return {
|
|
2443
2451
|
left: Math.max(r, t - e.width - r),
|
|
2444
2452
|
top: Math.max(r, n - e.height - r)
|
|
2445
2453
|
};
|
|
2446
2454
|
}
|
|
2447
|
-
function
|
|
2455
|
+
function fn(e, t, n, r = typeof window < "u" ? window.innerWidth : 1280, i = typeof window < "u" ? window.innerHeight : 800, a = rn) {
|
|
2448
2456
|
let o = Math.max(a, r - n.width - a), s = Math.max(a, i - n.height - a);
|
|
2449
2457
|
return {
|
|
2450
2458
|
left: Math.min(Math.max(a, e), o),
|
|
2451
2459
|
top: Math.min(Math.max(a, t), s)
|
|
2452
2460
|
};
|
|
2453
2461
|
}
|
|
2454
|
-
function
|
|
2455
|
-
return e(
|
|
2462
|
+
function pn(e = typeof window < "u" ? window.matchMedia.bind(window) : () => ({ matches: !0 })) {
|
|
2463
|
+
return e(nn).matches;
|
|
2456
2464
|
}
|
|
2457
2465
|
//#endregion
|
|
2458
2466
|
//#region src/widget/mountExperienceWidget.ts
|
|
2459
|
-
function
|
|
2467
|
+
function mn(e) {
|
|
2460
2468
|
return e === "bottom-right" || e === "bottom-left" ? e : "static";
|
|
2461
2469
|
}
|
|
2462
|
-
function
|
|
2470
|
+
function hn(e) {
|
|
2463
2471
|
if (typeof e == "number" && Number.isFinite(e)) return `${e}px`;
|
|
2464
2472
|
let t = typeof e == "string" ? e.trim() : "";
|
|
2465
2473
|
return t ? /^\d+(\.\d+)?$/.test(t) ? `${t}px` : t : "16px";
|
|
@@ -2467,8 +2475,8 @@ function mn(e) {
|
|
|
2467
2475
|
function $(e) {
|
|
2468
2476
|
return e === "expanded" || e === "docked";
|
|
2469
2477
|
}
|
|
2470
|
-
var
|
|
2471
|
-
function
|
|
2478
|
+
var gn = "<svg viewBox=\"0 0 24 24\" aria-hidden=\"true\" focusable=\"false\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 0 0 2.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 0 0 1.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 0 0-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 0 0-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 0 0-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 0 0-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 0 0 1.066-2.573c-.94-1.543.826-3.31 2.37-2.37c1 .608 2.296.07 2.572-1.065\"/><path d=\"M9 12a3 3 0 1 0 6 0a3 3 0 0 0-6 0\"/></svg>", _n = "<svg viewBox=\"0 0 24 24\" aria-hidden=\"true\" focusable=\"false\"><path fill=\"currentColor\" d=\"M18.3 5.71a1 1 0 0 0-1.41 0L12 10.59 7.11 5.7A1 1 0 0 0 5.7 7.11L10.59 12l-4.9 4.89a1 1 0 1 0 1.42 1.42L12 13.41l4.89 4.9a1 1 0 0 0 1.42-1.42L13.41 12l4.9-4.89a1 1 0 0 0-.01-1.4Z\"/></svg>", vn = "<svg viewBox=\"0 0 24 24\" aria-hidden=\"true\" focusable=\"false\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M18 10h-4V6m6-2l-6 6m-8 4h4v4m0-4l-6 6\"/></svg>", yn = "<svg viewBox=\"0 0 24 24\" aria-hidden=\"true\" focusable=\"false\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M16 4h4v4m-6 2l6-6M8 20H4v-4m0 4l6-6\"/></svg>";
|
|
2479
|
+
function bn(e, t, n) {
|
|
2472
2480
|
W(de);
|
|
2473
2481
|
let r = w({
|
|
2474
2482
|
galleryThumb: t.galleryThumb,
|
|
@@ -2498,7 +2506,7 @@ function yn(e, t, n) {
|
|
|
2498
2506
|
}
|
|
2499
2507
|
return e.replaceChildren(i), n?.parallax === !1 ? () => {} : ue(i);
|
|
2500
2508
|
}
|
|
2501
|
-
function
|
|
2509
|
+
function xn(e) {
|
|
2502
2510
|
return e.startButton ? {
|
|
2503
2511
|
...e.startButton,
|
|
2504
2512
|
label: e.startButton.label ?? e.startButtonLabel ?? "Tap to talk",
|
|
@@ -2510,7 +2518,7 @@ function bn(e) {
|
|
|
2510
2518
|
variant: "primary"
|
|
2511
2519
|
};
|
|
2512
2520
|
}
|
|
2513
|
-
function
|
|
2521
|
+
function Sn(e) {
|
|
2514
2522
|
let t = !1, n = () => {
|
|
2515
2523
|
t || e();
|
|
2516
2524
|
}, r = () => {
|
|
@@ -2530,12 +2538,12 @@ function xn(e) {
|
|
|
2530
2538
|
t = !0, window.removeEventListener("load", r), i?.();
|
|
2531
2539
|
};
|
|
2532
2540
|
}
|
|
2533
|
-
function
|
|
2541
|
+
function Cn(e, t) {
|
|
2534
2542
|
he(me);
|
|
2535
2543
|
let n = t.experienceId?.trim();
|
|
2536
2544
|
if (!n) throw Error("ExperienceWidget requires experienceId.");
|
|
2537
|
-
let r = t.prefetch ?? "onExpand", i =
|
|
2538
|
-
a.className = "liforma-ew", a.dataset.state = "collapsed", a.dataset.prefetch = r, a.dataset.position = i, a.style.setProperty("--liforma-ew-max-w", t.expandedMaxWidth ?? "100%"), a.style.setProperty("--liforma-ew-max-h", t.expandedMaxHeight ?? "100%"), i !== "static" && a.style.setProperty("--liforma-ew-offset",
|
|
2545
|
+
let r = t.prefetch ?? "onExpand", i = mn(t.position), a = document.createElement("div");
|
|
2546
|
+
a.className = "liforma-ew", a.dataset.state = "collapsed", a.dataset.prefetch = r, a.dataset.position = i, a.style.setProperty("--liforma-ew-max-w", t.expandedMaxWidth ?? "100%"), a.style.setProperty("--liforma-ew-max-h", t.expandedMaxHeight ?? "100%"), i !== "static" && a.style.setProperty("--liforma-ew-offset", hn(t.offset));
|
|
2539
2547
|
let o = document.createElement("button");
|
|
2540
2548
|
o.type = "button", o.className = "liforma-ew__hit", o.setAttribute("aria-label", t.alt), o.disabled = !0;
|
|
2541
2549
|
let s = document.createElement("div");
|
|
@@ -2555,11 +2563,11 @@ function Sn(e, t) {
|
|
|
2555
2563
|
let m = document.createElement("span");
|
|
2556
2564
|
m.className = "liforma-ew__drag-grip", m.setAttribute("aria-hidden", "true");
|
|
2557
2565
|
let h = document.createElement("button");
|
|
2558
|
-
h.type = "button", h.className = "liforma-ew__icon-btn liforma-ew__dock-toggle", h.innerHTML =
|
|
2566
|
+
h.type = "button", h.className = "liforma-ew__icon-btn liforma-ew__dock-toggle", h.innerHTML = vn, h.setAttribute("aria-label", "Reduce");
|
|
2559
2567
|
let g = document.createElement("button");
|
|
2560
|
-
g.type = "button", g.className = "liforma-ew__icon-btn liforma-ew__settings", g.innerHTML =
|
|
2568
|
+
g.type = "button", g.className = "liforma-ew__icon-btn liforma-ew__settings", g.innerHTML = gn, g.setAttribute("aria-label", "Audio settings"), g.setAttribute("aria-pressed", "false");
|
|
2561
2569
|
let _ = document.createElement("button");
|
|
2562
|
-
_.type = "button", _.className = "liforma-ew__icon-btn liforma-ew__close", _.innerHTML =
|
|
2570
|
+
_.type = "button", _.className = "liforma-ew__icon-btn liforma-ew__close", _.innerHTML = _n, _.setAttribute("aria-label", "Close"), p.append(m, h, g, _);
|
|
2563
2571
|
let v = document.createElement("div");
|
|
2564
2572
|
v.className = "liforma-ew__stage";
|
|
2565
2573
|
let y = document.createElement("div");
|
|
@@ -2587,11 +2595,11 @@ function Sn(e, t) {
|
|
|
2587
2595
|
p.style.left = `${e + n - a - 10}px`, p.style.top = `${t + 10}px`, p.style.right = "auto", p.style.bottom = "auto", p.style.width = "auto", p.style.height = "auto";
|
|
2588
2596
|
}, oe = (e, t) => {
|
|
2589
2597
|
if (R() !== "docked") return;
|
|
2590
|
-
let n =
|
|
2598
|
+
let n = un(), r = fn(e - te, t - ne, n);
|
|
2591
2599
|
N = r.left, P = r.top, V(r.left, r.top, n.width, n.height);
|
|
2592
2600
|
}, se = (e, t) => {
|
|
2593
2601
|
if (R() !== "docked" || !Number.isFinite(e) || !Number.isFinite(t) || e === 0 && t === 0) return;
|
|
2594
|
-
let n =
|
|
2602
|
+
let n = un(), r = N ?? f.getBoundingClientRect().left, i = P ?? f.getBoundingClientRect().top, a = fn(r + e, i + t, n);
|
|
2595
2603
|
N = a.left, P = a.top, V(a.left, a.top, n.width, n.height);
|
|
2596
2604
|
}, ce = (e) => {
|
|
2597
2605
|
I === "toolbar" && (F === null || e.pointerId !== F || (e.preventDefault(), oe(e.clientX, e.clientY)));
|
|
@@ -2600,12 +2608,12 @@ function Sn(e, t) {
|
|
|
2600
2608
|
let t = I;
|
|
2601
2609
|
F = null, I = null, p.classList.remove("liforma-ew__toolbar--dragging"), a.classList.remove("liforma-ew--dock-dragging"), t === "toolbar" && L && (L = !1, window.removeEventListener("pointermove", ce), window.removeEventListener("pointerup", H), window.removeEventListener("pointercancel", H));
|
|
2602
2610
|
}, le = (e, t, n) => {
|
|
2603
|
-
if (S || R() !== "docked" || !
|
|
2611
|
+
if (S || R() !== "docked" || !pn() || F !== null) return;
|
|
2604
2612
|
F = n, I = "toolbar", p.classList.add("liforma-ew__toolbar--dragging"), a.classList.add("liforma-ew--dock-dragging");
|
|
2605
2613
|
let r = f.getBoundingClientRect();
|
|
2606
2614
|
te = e - r.left, ne = t - r.top, L || (L = !0, window.addEventListener("pointermove", ce), window.addEventListener("pointerup", H), window.addEventListener("pointercancel", H));
|
|
2607
2615
|
}, ue = (e) => {
|
|
2608
|
-
if (S || R() !== "docked" || !
|
|
2616
|
+
if (S || R() !== "docked" || !pn() || F !== null) return;
|
|
2609
2617
|
F = e.pointerId, I = "player", p.classList.add("liforma-ew__toolbar--dragging"), a.classList.add("liforma-ew--dock-dragging");
|
|
2610
2618
|
let t = f.getBoundingClientRect();
|
|
2611
2619
|
N = t.left, P = t.top;
|
|
@@ -2614,15 +2622,15 @@ function Sn(e, t) {
|
|
|
2614
2622
|
}, U = (e) => {
|
|
2615
2623
|
I === "player" && (F === null || e.pointerId !== F || H());
|
|
2616
2624
|
}, W = () => {
|
|
2617
|
-
let e =
|
|
2625
|
+
let e = pn(), t = R();
|
|
2618
2626
|
if (!e || t !== "expanded" && t !== "docked") {
|
|
2619
2627
|
h.hidden = !0;
|
|
2620
2628
|
return;
|
|
2621
2629
|
}
|
|
2622
|
-
h.hidden = !1, t === "docked" ? (h.innerHTML =
|
|
2630
|
+
h.hidden = !1, t === "docked" ? (h.innerHTML = yn, h.setAttribute("aria-label", "Maximize")) : (h.innerHTML = vn, h.setAttribute("aria-label", "Reduce"));
|
|
2623
2631
|
}, fe = (e) => {
|
|
2624
|
-
let t =
|
|
2625
|
-
n =
|
|
2632
|
+
let t = un(), n = e && N !== null && P !== null ? fn(N, P, t) : dn(t);
|
|
2633
|
+
n = fn(n.left, n.top, t), N = n.left, P = n.top, V(n.left, n.top, t.width, t.height), W();
|
|
2626
2634
|
}, pe = () => {
|
|
2627
2635
|
a.classList.remove("liforma-ew--session-revealed"), requestAnimationFrame(() => {
|
|
2628
2636
|
requestAnimationFrame(() => {
|
|
@@ -2669,7 +2677,7 @@ function Sn(e, t) {
|
|
|
2669
2677
|
w = !0, a.dataset.warm = "true", l.hidden = !1, D || (o.tabIndex = -1, o.setAttribute("aria-hidden", "true")), t.onPrefetchReady?.();
|
|
2670
2678
|
}, xe = (e) => {
|
|
2671
2679
|
A?.(), A = null;
|
|
2672
|
-
let t =
|
|
2680
|
+
let t = bn(s, e, { parallax: ie });
|
|
2673
2681
|
return t ? (A = t, !0) : !1;
|
|
2674
2682
|
}, Se = () => {
|
|
2675
2683
|
if (xe(_e)) {
|
|
@@ -2698,7 +2706,7 @@ function Sn(e, t) {
|
|
|
2698
2706
|
...t.embedBaseUrl ? { embedBaseUrl: t.embedBaseUrl } : {}
|
|
2699
2707
|
}), we = () => ({
|
|
2700
2708
|
...t.fit ? { fit: t.fit } : {},
|
|
2701
|
-
startButton:
|
|
2709
|
+
startButton: xn(t),
|
|
2702
2710
|
...t.showFeedback === void 0 ? {} : { showFeedback: t.showFeedback }
|
|
2703
2711
|
}), J = (e = !0) => {
|
|
2704
2712
|
o.hidden = !0, u.hidden = !1, p.hidden = !1, u.setAttribute("aria-modal", "true"), ae(), a.dataset.state = "expanded", K(null), typeof document < "u" && (k = document.body.style.overflow, document.body.style.overflow = "hidden"), W(), e && t.onExpanded?.();
|
|
@@ -2730,7 +2738,7 @@ function Sn(e, t) {
|
|
|
2730
2738
|
Ee(), Te(), t.onCollapsed?.(), t.onClose?.();
|
|
2731
2739
|
}
|
|
2732
2740
|
}, Oe = () => {
|
|
2733
|
-
S ||
|
|
2741
|
+
S || pn() && R() === "expanded" && G(() => {
|
|
2734
2742
|
Y();
|
|
2735
2743
|
});
|
|
2736
2744
|
}, ke = () => {
|
|
@@ -2749,7 +2757,7 @@ function Sn(e, t) {
|
|
|
2749
2757
|
let e = O;
|
|
2750
2758
|
l.hidden = !1, (async () => {
|
|
2751
2759
|
try {
|
|
2752
|
-
let t = await
|
|
2760
|
+
let t = await en.startSession(Ce());
|
|
2753
2761
|
if (S || e !== O) {
|
|
2754
2762
|
t.destroy();
|
|
2755
2763
|
return;
|
|
@@ -2808,7 +2816,7 @@ function Sn(e, t) {
|
|
|
2808
2816
|
x = !0, w = !1, T = !1, E = !1, D = !1, delete a.dataset.warm, delete a.dataset.live, l.hidden = !0, l.replaceChildren(), b &&= (b.destroy(), null), (async () => {
|
|
2809
2817
|
try {
|
|
2810
2818
|
J();
|
|
2811
|
-
let t = await
|
|
2819
|
+
let t = await en.startSession(Ce());
|
|
2812
2820
|
if (S || e !== O) {
|
|
2813
2821
|
t.destroy();
|
|
2814
2822
|
return;
|
|
@@ -2875,13 +2883,13 @@ function Sn(e, t) {
|
|
|
2875
2883
|
}, Re = (e) => {
|
|
2876
2884
|
e.stopPropagation(), $(a.dataset.state) && b?.toggleAudioSettings();
|
|
2877
2885
|
}, ze = (e) => {
|
|
2878
|
-
R() === "docked" &&
|
|
2886
|
+
R() === "docked" && pn() && (e.target?.closest("button") || (e.preventDefault(), le(e.clientX, e.clientY, e.pointerId)));
|
|
2879
2887
|
}, Be = (e) => {
|
|
2880
2888
|
e.key === "Escape" && $(a.dataset.state) && (e.preventDefault(), De());
|
|
2881
2889
|
}, Ve = () => {
|
|
2882
2890
|
if (!S) {
|
|
2883
2891
|
if (R() === "docked") {
|
|
2884
|
-
if (!
|
|
2892
|
+
if (!pn()) {
|
|
2885
2893
|
ke();
|
|
2886
2894
|
return;
|
|
2887
2895
|
}
|
|
@@ -2892,9 +2900,9 @@ function Sn(e, t) {
|
|
|
2892
2900
|
}
|
|
2893
2901
|
W();
|
|
2894
2902
|
}
|
|
2895
|
-
}, He = typeof window < "u" ? window.matchMedia(
|
|
2903
|
+
}, He = typeof window < "u" ? window.matchMedia(nn) : null, Ue = () => {
|
|
2896
2904
|
if (!S) {
|
|
2897
|
-
if (R() === "docked" && !
|
|
2905
|
+
if (R() === "docked" && !pn()) {
|
|
2898
2906
|
ke();
|
|
2899
2907
|
return;
|
|
2900
2908
|
}
|
|
@@ -2905,7 +2913,7 @@ function Sn(e, t) {
|
|
|
2905
2913
|
e.stopPropagation(), De();
|
|
2906
2914
|
}), h.addEventListener("click", Ie), g.addEventListener("click", Re), p.addEventListener("pointerdown", ze), window.addEventListener("keydown", Be), window.addEventListener("resize", Ve), He?.addEventListener("change", Ue), Se(), W(), r === "eager" ? queueMicrotask(() => {
|
|
2907
2915
|
S || Ne();
|
|
2908
|
-
}) : r === "idle" && (ee =
|
|
2916
|
+
}) : r === "idle" && (ee = Sn(() => {
|
|
2909
2917
|
S || Ne();
|
|
2910
2918
|
})), {
|
|
2911
2919
|
root: a,
|
|
@@ -2927,12 +2935,12 @@ function Sn(e, t) {
|
|
|
2927
2935
|
}
|
|
2928
2936
|
//#endregion
|
|
2929
2937
|
//#region src/react/ExperienceWidget.tsx
|
|
2930
|
-
function
|
|
2938
|
+
function wn(t) {
|
|
2931
2939
|
let r = n(null), { experienceId: i, alt: o, galleryThumb: s, avatarImage: c, backgroundImage: l, foregroundImage: u, fallbackImage: d, prefetch: f = "onExpand", parallax: p = !0, position: m = "static", offset: h, sessionEndpoint: g, language: _, mode: v, speechInputMode: y, speechOnly: b, fit: x, embedBaseUrl: S, expandedMaxWidth: C, expandedMaxHeight: w, startButtonLabel: T, startButton: E, showFeedback: D, className: O = "", onExpanded: k, onCollapsed: A, onStarted: ee, onClose: j, onError: M, onPrefetchReady: N, onFeedback: P, onFeedbackFailed: F } = t, te = m === "bottom-right" || m === "bottom-left";
|
|
2932
2940
|
return e(() => {
|
|
2933
2941
|
let e = r.current;
|
|
2934
2942
|
if (!e || !i.trim()) return;
|
|
2935
|
-
let t =
|
|
2943
|
+
let t = Cn(e, {
|
|
2936
2944
|
experienceId: i,
|
|
2937
2945
|
alt: o,
|
|
2938
2946
|
galleryThumb: s,
|
|
@@ -3009,6 +3017,6 @@ function Cn(t) {
|
|
|
3009
3017
|
});
|
|
3010
3018
|
}
|
|
3011
3019
|
//#endregion
|
|
3012
|
-
export { pe as ExperienceThumbnail,
|
|
3020
|
+
export { pe as ExperienceThumbnail, wn as ExperienceWidget, v as createLiformaSessionRouteHandler };
|
|
3013
3021
|
|
|
3014
3022
|
//# sourceMappingURL=index.js.map
|