@wowlabtech/mini-app-adapter 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +98 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.js +98 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -665,6 +665,27 @@ var BaseMiniAppAdapter = class {
|
|
|
665
665
|
}
|
|
666
666
|
requestFullscreen() {
|
|
667
667
|
}
|
|
668
|
+
onViewportChange(callback) {
|
|
669
|
+
if (typeof window === "undefined") {
|
|
670
|
+
return () => {
|
|
671
|
+
};
|
|
672
|
+
}
|
|
673
|
+
const fallbackHeight = () => window.visualViewport?.height ?? window.innerHeight;
|
|
674
|
+
const notify = () => {
|
|
675
|
+
const height = fallbackHeight();
|
|
676
|
+
callback({ height, stableHeight: height });
|
|
677
|
+
};
|
|
678
|
+
notify();
|
|
679
|
+
const onResize = () => notify();
|
|
680
|
+
window.visualViewport?.addEventListener("resize", onResize);
|
|
681
|
+
window.visualViewport?.addEventListener("scroll", onResize);
|
|
682
|
+
window.addEventListener("resize", onResize);
|
|
683
|
+
return () => {
|
|
684
|
+
window.visualViewport?.removeEventListener("resize", onResize);
|
|
685
|
+
window.visualViewport?.removeEventListener("scroll", onResize);
|
|
686
|
+
window.removeEventListener("resize", onResize);
|
|
687
|
+
};
|
|
688
|
+
}
|
|
668
689
|
getViewportInsets() {
|
|
669
690
|
return void 0;
|
|
670
691
|
}
|
|
@@ -1406,6 +1427,63 @@ var TelegramMiniAppAdapter = class extends BaseMiniAppAdapter {
|
|
|
1406
1427
|
return void 0;
|
|
1407
1428
|
}
|
|
1408
1429
|
}
|
|
1430
|
+
onViewportChange(callback) {
|
|
1431
|
+
const disposers = [];
|
|
1432
|
+
const fallbackHeight = () => typeof window !== "undefined" ? window.visualViewport?.height ?? window.innerHeight : 0;
|
|
1433
|
+
const notify = (state) => {
|
|
1434
|
+
const heightCandidate = state?.height ?? this.safeHeightFromSdk();
|
|
1435
|
+
const stableCandidate = state?.stableHeight ?? this.stableHeightFromSdk();
|
|
1436
|
+
const height = Number.isFinite(heightCandidate) ? heightCandidate : fallbackHeight();
|
|
1437
|
+
const stableHeight = Number.isFinite(stableCandidate) && stableCandidate > 0 ? stableCandidate : height;
|
|
1438
|
+
callback({ height, stableHeight });
|
|
1439
|
+
};
|
|
1440
|
+
const ensureMounted = async () => {
|
|
1441
|
+
try {
|
|
1442
|
+
await ensureViewportMounted(this.getViewportMountOptions());
|
|
1443
|
+
} catch (error) {
|
|
1444
|
+
console.warn("[tvm-app-adapter] ensureViewportMounted failed:", error);
|
|
1445
|
+
}
|
|
1446
|
+
};
|
|
1447
|
+
void ensureMounted().finally(() => notify());
|
|
1448
|
+
const { sdkViewport } = this.getViewportMountOptions();
|
|
1449
|
+
if (typeof sdkViewport.on === "function") {
|
|
1450
|
+
try {
|
|
1451
|
+
const off2 = sdkViewport.on("change", (next) => notify(next));
|
|
1452
|
+
if (typeof off2 === "function") {
|
|
1453
|
+
disposers.push(off2);
|
|
1454
|
+
}
|
|
1455
|
+
} catch (error) {
|
|
1456
|
+
console.warn("[tvm-app-adapter] viewport.on(change) subscription failed:", error);
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
try {
|
|
1460
|
+
if (typeof sdkViewport.height?.sub === "function") {
|
|
1461
|
+
disposers.push(sdkViewport.height.sub(() => notify()));
|
|
1462
|
+
}
|
|
1463
|
+
if (typeof sdkViewport.stableHeight?.sub === "function") {
|
|
1464
|
+
disposers.push(sdkViewport.stableHeight.sub(() => notify()));
|
|
1465
|
+
}
|
|
1466
|
+
} catch (error) {
|
|
1467
|
+
console.warn("[tvm-app-adapter] viewport signal subscriptions failed:", error);
|
|
1468
|
+
}
|
|
1469
|
+
if (typeof window !== "undefined") {
|
|
1470
|
+
const onResize = () => notify();
|
|
1471
|
+
window.visualViewport?.addEventListener("resize", onResize);
|
|
1472
|
+
window.addEventListener("resize", onResize);
|
|
1473
|
+
disposers.push(() => {
|
|
1474
|
+
window.visualViewport?.removeEventListener("resize", onResize);
|
|
1475
|
+
window.removeEventListener("resize", onResize);
|
|
1476
|
+
});
|
|
1477
|
+
}
|
|
1478
|
+
return () => {
|
|
1479
|
+
disposers.forEach((dispose) => {
|
|
1480
|
+
try {
|
|
1481
|
+
dispose();
|
|
1482
|
+
} catch {
|
|
1483
|
+
}
|
|
1484
|
+
});
|
|
1485
|
+
};
|
|
1486
|
+
}
|
|
1409
1487
|
onAppearanceChange(callback) {
|
|
1410
1488
|
this.appearanceListeners.add(callback);
|
|
1411
1489
|
callback(this.environment.appearance);
|
|
@@ -1636,6 +1714,26 @@ var TelegramMiniAppAdapter = class extends BaseMiniAppAdapter {
|
|
|
1636
1714
|
}
|
|
1637
1715
|
};
|
|
1638
1716
|
}
|
|
1717
|
+
safeHeightFromSdk() {
|
|
1718
|
+
try {
|
|
1719
|
+
if (typeof import_sdk.viewport.height === "function") {
|
|
1720
|
+
return import_sdk.viewport.height();
|
|
1721
|
+
}
|
|
1722
|
+
} catch {
|
|
1723
|
+
return void 0;
|
|
1724
|
+
}
|
|
1725
|
+
return void 0;
|
|
1726
|
+
}
|
|
1727
|
+
stableHeightFromSdk() {
|
|
1728
|
+
try {
|
|
1729
|
+
if (typeof import_sdk.viewport.stableHeight === "function") {
|
|
1730
|
+
return import_sdk.viewport.stableHeight();
|
|
1731
|
+
}
|
|
1732
|
+
} catch {
|
|
1733
|
+
return void 0;
|
|
1734
|
+
}
|
|
1735
|
+
return void 0;
|
|
1736
|
+
}
|
|
1639
1737
|
notifyViewHide() {
|
|
1640
1738
|
for (const listener of this.viewHideListeners) {
|
|
1641
1739
|
try {
|