@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.d.cts
CHANGED
|
@@ -56,6 +56,10 @@ interface MiniAppViewportInsets {
|
|
|
56
56
|
safeArea: MiniAppSafeAreaInsets;
|
|
57
57
|
contentSafeArea: MiniAppSafeAreaInsets;
|
|
58
58
|
}
|
|
59
|
+
interface MiniAppViewportState {
|
|
60
|
+
height: number;
|
|
61
|
+
stableHeight: number;
|
|
62
|
+
}
|
|
59
63
|
interface MiniAppInitOptions {
|
|
60
64
|
/**
|
|
61
65
|
* Enables verbose logs for platforms that support it.
|
|
@@ -170,6 +174,10 @@ interface MiniAppAdapter {
|
|
|
170
174
|
* Requests fullscreen mode if supported by the platform.
|
|
171
175
|
*/
|
|
172
176
|
requestFullscreen?(): void;
|
|
177
|
+
/**
|
|
178
|
+
* Subscribes to viewport size changes. Returns disposer.
|
|
179
|
+
*/
|
|
180
|
+
onViewportChange?(callback: (state: MiniAppViewportState) => void): () => void;
|
|
173
181
|
/**
|
|
174
182
|
* Returns viewport safe area insets if supported by the platform.
|
|
175
183
|
*/
|
|
@@ -307,6 +315,10 @@ declare abstract class BaseMiniAppAdapter implements MiniAppAdapter {
|
|
|
307
315
|
getLaunchParams(): unknown;
|
|
308
316
|
decodeStartParam(_param: string): unknown;
|
|
309
317
|
requestFullscreen(): void;
|
|
318
|
+
onViewportChange(callback: (state: {
|
|
319
|
+
height: number;
|
|
320
|
+
stableHeight: number;
|
|
321
|
+
}) => void): () => void;
|
|
310
322
|
getViewportInsets(): MiniAppViewportInsets | undefined;
|
|
311
323
|
shareMessage(_message: string): Promise<void>;
|
|
312
324
|
shareUrl(_url: string, _text: string): void;
|
|
@@ -402,6 +414,10 @@ declare class TelegramMiniAppAdapter extends BaseMiniAppAdapter {
|
|
|
402
414
|
decodeStartParam(param: string): unknown;
|
|
403
415
|
requestFullscreen(): void;
|
|
404
416
|
getViewportInsets(): MiniAppViewportInsets | undefined;
|
|
417
|
+
onViewportChange(callback: (state: {
|
|
418
|
+
height: number;
|
|
419
|
+
stableHeight: number;
|
|
420
|
+
}) => void): () => void;
|
|
405
421
|
onAppearanceChange(callback: (appearance: 'dark' | 'light' | undefined) => void): () => void;
|
|
406
422
|
setBackButtonVisibility(visible: boolean): void;
|
|
407
423
|
enableVerticalSwipes(): void;
|
|
@@ -420,6 +436,8 @@ declare class TelegramMiniAppAdapter extends BaseMiniAppAdapter {
|
|
|
420
436
|
private prepareViewport;
|
|
421
437
|
private requestFullscreenInternal;
|
|
422
438
|
private getViewportMountOptions;
|
|
439
|
+
private safeHeightFromSdk;
|
|
440
|
+
private stableHeightFromSdk;
|
|
423
441
|
private notifyViewHide;
|
|
424
442
|
private notifyViewRestore;
|
|
425
443
|
protected onDestroy(): void;
|
|
@@ -536,4 +554,4 @@ declare function trackPixelEvent(event: string, payload?: Record<string, unknown
|
|
|
536
554
|
|
|
537
555
|
declare function getPlatform(): MiniAppPlatform;
|
|
538
556
|
|
|
539
|
-
export { AdapterProvider, BaseMiniAppAdapter, type CreateAdapterOptions, MaxMiniAppAdapter, type MiniAppAdapter, type MiniAppCapability, type MiniAppEnvironmentInfo, type MiniAppInitOptions, type MiniAppPlatform, type MiniAppPopupOptions, type MiniAppQrScanOptions, ShellMiniAppAdapter, TelegramMiniAppAdapter, VKMiniAppAdapter, WebMiniAppAdapter, configureVkPixel, createAdapter, createShellAPI, detectPlatform, getActiveAdapter, getPlatform, isShell, isShellAndroid, isShellIOS, readShellPlatform, requestShellPushPermission, shell, storeShellToken, trackConversionEvent, trackPixelEvent, useAdapterTheme, useMiniAppAdapter, useSafeArea };
|
|
557
|
+
export { AdapterProvider, BaseMiniAppAdapter, type CreateAdapterOptions, MaxMiniAppAdapter, type MiniAppAdapter, type MiniAppCapability, type MiniAppEnvironmentInfo, type MiniAppInitOptions, type MiniAppPlatform, type MiniAppPopupOptions, type MiniAppQrScanOptions, type MiniAppViewportState, ShellMiniAppAdapter, TelegramMiniAppAdapter, VKMiniAppAdapter, WebMiniAppAdapter, configureVkPixel, createAdapter, createShellAPI, detectPlatform, getActiveAdapter, getPlatform, isShell, isShellAndroid, isShellIOS, readShellPlatform, requestShellPushPermission, shell, storeShellToken, trackConversionEvent, trackPixelEvent, useAdapterTheme, useMiniAppAdapter, useSafeArea };
|
package/dist/index.d.ts
CHANGED
|
@@ -56,6 +56,10 @@ interface MiniAppViewportInsets {
|
|
|
56
56
|
safeArea: MiniAppSafeAreaInsets;
|
|
57
57
|
contentSafeArea: MiniAppSafeAreaInsets;
|
|
58
58
|
}
|
|
59
|
+
interface MiniAppViewportState {
|
|
60
|
+
height: number;
|
|
61
|
+
stableHeight: number;
|
|
62
|
+
}
|
|
59
63
|
interface MiniAppInitOptions {
|
|
60
64
|
/**
|
|
61
65
|
* Enables verbose logs for platforms that support it.
|
|
@@ -170,6 +174,10 @@ interface MiniAppAdapter {
|
|
|
170
174
|
* Requests fullscreen mode if supported by the platform.
|
|
171
175
|
*/
|
|
172
176
|
requestFullscreen?(): void;
|
|
177
|
+
/**
|
|
178
|
+
* Subscribes to viewport size changes. Returns disposer.
|
|
179
|
+
*/
|
|
180
|
+
onViewportChange?(callback: (state: MiniAppViewportState) => void): () => void;
|
|
173
181
|
/**
|
|
174
182
|
* Returns viewport safe area insets if supported by the platform.
|
|
175
183
|
*/
|
|
@@ -307,6 +315,10 @@ declare abstract class BaseMiniAppAdapter implements MiniAppAdapter {
|
|
|
307
315
|
getLaunchParams(): unknown;
|
|
308
316
|
decodeStartParam(_param: string): unknown;
|
|
309
317
|
requestFullscreen(): void;
|
|
318
|
+
onViewportChange(callback: (state: {
|
|
319
|
+
height: number;
|
|
320
|
+
stableHeight: number;
|
|
321
|
+
}) => void): () => void;
|
|
310
322
|
getViewportInsets(): MiniAppViewportInsets | undefined;
|
|
311
323
|
shareMessage(_message: string): Promise<void>;
|
|
312
324
|
shareUrl(_url: string, _text: string): void;
|
|
@@ -402,6 +414,10 @@ declare class TelegramMiniAppAdapter extends BaseMiniAppAdapter {
|
|
|
402
414
|
decodeStartParam(param: string): unknown;
|
|
403
415
|
requestFullscreen(): void;
|
|
404
416
|
getViewportInsets(): MiniAppViewportInsets | undefined;
|
|
417
|
+
onViewportChange(callback: (state: {
|
|
418
|
+
height: number;
|
|
419
|
+
stableHeight: number;
|
|
420
|
+
}) => void): () => void;
|
|
405
421
|
onAppearanceChange(callback: (appearance: 'dark' | 'light' | undefined) => void): () => void;
|
|
406
422
|
setBackButtonVisibility(visible: boolean): void;
|
|
407
423
|
enableVerticalSwipes(): void;
|
|
@@ -420,6 +436,8 @@ declare class TelegramMiniAppAdapter extends BaseMiniAppAdapter {
|
|
|
420
436
|
private prepareViewport;
|
|
421
437
|
private requestFullscreenInternal;
|
|
422
438
|
private getViewportMountOptions;
|
|
439
|
+
private safeHeightFromSdk;
|
|
440
|
+
private stableHeightFromSdk;
|
|
423
441
|
private notifyViewHide;
|
|
424
442
|
private notifyViewRestore;
|
|
425
443
|
protected onDestroy(): void;
|
|
@@ -536,4 +554,4 @@ declare function trackPixelEvent(event: string, payload?: Record<string, unknown
|
|
|
536
554
|
|
|
537
555
|
declare function getPlatform(): MiniAppPlatform;
|
|
538
556
|
|
|
539
|
-
export { AdapterProvider, BaseMiniAppAdapter, type CreateAdapterOptions, MaxMiniAppAdapter, type MiniAppAdapter, type MiniAppCapability, type MiniAppEnvironmentInfo, type MiniAppInitOptions, type MiniAppPlatform, type MiniAppPopupOptions, type MiniAppQrScanOptions, ShellMiniAppAdapter, TelegramMiniAppAdapter, VKMiniAppAdapter, WebMiniAppAdapter, configureVkPixel, createAdapter, createShellAPI, detectPlatform, getActiveAdapter, getPlatform, isShell, isShellAndroid, isShellIOS, readShellPlatform, requestShellPushPermission, shell, storeShellToken, trackConversionEvent, trackPixelEvent, useAdapterTheme, useMiniAppAdapter, useSafeArea };
|
|
557
|
+
export { AdapterProvider, BaseMiniAppAdapter, type CreateAdapterOptions, MaxMiniAppAdapter, type MiniAppAdapter, type MiniAppCapability, type MiniAppEnvironmentInfo, type MiniAppInitOptions, type MiniAppPlatform, type MiniAppPopupOptions, type MiniAppQrScanOptions, type MiniAppViewportState, ShellMiniAppAdapter, TelegramMiniAppAdapter, VKMiniAppAdapter, WebMiniAppAdapter, configureVkPixel, createAdapter, createShellAPI, detectPlatform, getActiveAdapter, getPlatform, isShell, isShellAndroid, isShellIOS, readShellPlatform, requestShellPushPermission, shell, storeShellToken, trackConversionEvent, trackPixelEvent, useAdapterTheme, useMiniAppAdapter, useSafeArea };
|
package/dist/index.js
CHANGED
|
@@ -607,6 +607,27 @@ var BaseMiniAppAdapter = class {
|
|
|
607
607
|
}
|
|
608
608
|
requestFullscreen() {
|
|
609
609
|
}
|
|
610
|
+
onViewportChange(callback) {
|
|
611
|
+
if (typeof window === "undefined") {
|
|
612
|
+
return () => {
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
const fallbackHeight = () => window.visualViewport?.height ?? window.innerHeight;
|
|
616
|
+
const notify = () => {
|
|
617
|
+
const height = fallbackHeight();
|
|
618
|
+
callback({ height, stableHeight: height });
|
|
619
|
+
};
|
|
620
|
+
notify();
|
|
621
|
+
const onResize = () => notify();
|
|
622
|
+
window.visualViewport?.addEventListener("resize", onResize);
|
|
623
|
+
window.visualViewport?.addEventListener("scroll", onResize);
|
|
624
|
+
window.addEventListener("resize", onResize);
|
|
625
|
+
return () => {
|
|
626
|
+
window.visualViewport?.removeEventListener("resize", onResize);
|
|
627
|
+
window.visualViewport?.removeEventListener("scroll", onResize);
|
|
628
|
+
window.removeEventListener("resize", onResize);
|
|
629
|
+
};
|
|
630
|
+
}
|
|
610
631
|
getViewportInsets() {
|
|
611
632
|
return void 0;
|
|
612
633
|
}
|
|
@@ -1379,6 +1400,63 @@ var TelegramMiniAppAdapter = class extends BaseMiniAppAdapter {
|
|
|
1379
1400
|
return void 0;
|
|
1380
1401
|
}
|
|
1381
1402
|
}
|
|
1403
|
+
onViewportChange(callback) {
|
|
1404
|
+
const disposers = [];
|
|
1405
|
+
const fallbackHeight = () => typeof window !== "undefined" ? window.visualViewport?.height ?? window.innerHeight : 0;
|
|
1406
|
+
const notify = (state) => {
|
|
1407
|
+
const heightCandidate = state?.height ?? this.safeHeightFromSdk();
|
|
1408
|
+
const stableCandidate = state?.stableHeight ?? this.stableHeightFromSdk();
|
|
1409
|
+
const height = Number.isFinite(heightCandidate) ? heightCandidate : fallbackHeight();
|
|
1410
|
+
const stableHeight = Number.isFinite(stableCandidate) && stableCandidate > 0 ? stableCandidate : height;
|
|
1411
|
+
callback({ height, stableHeight });
|
|
1412
|
+
};
|
|
1413
|
+
const ensureMounted = async () => {
|
|
1414
|
+
try {
|
|
1415
|
+
await ensureViewportMounted(this.getViewportMountOptions());
|
|
1416
|
+
} catch (error) {
|
|
1417
|
+
console.warn("[tvm-app-adapter] ensureViewportMounted failed:", error);
|
|
1418
|
+
}
|
|
1419
|
+
};
|
|
1420
|
+
void ensureMounted().finally(() => notify());
|
|
1421
|
+
const { sdkViewport } = this.getViewportMountOptions();
|
|
1422
|
+
if (typeof sdkViewport.on === "function") {
|
|
1423
|
+
try {
|
|
1424
|
+
const off2 = sdkViewport.on("change", (next) => notify(next));
|
|
1425
|
+
if (typeof off2 === "function") {
|
|
1426
|
+
disposers.push(off2);
|
|
1427
|
+
}
|
|
1428
|
+
} catch (error) {
|
|
1429
|
+
console.warn("[tvm-app-adapter] viewport.on(change) subscription failed:", error);
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
try {
|
|
1433
|
+
if (typeof sdkViewport.height?.sub === "function") {
|
|
1434
|
+
disposers.push(sdkViewport.height.sub(() => notify()));
|
|
1435
|
+
}
|
|
1436
|
+
if (typeof sdkViewport.stableHeight?.sub === "function") {
|
|
1437
|
+
disposers.push(sdkViewport.stableHeight.sub(() => notify()));
|
|
1438
|
+
}
|
|
1439
|
+
} catch (error) {
|
|
1440
|
+
console.warn("[tvm-app-adapter] viewport signal subscriptions failed:", error);
|
|
1441
|
+
}
|
|
1442
|
+
if (typeof window !== "undefined") {
|
|
1443
|
+
const onResize = () => notify();
|
|
1444
|
+
window.visualViewport?.addEventListener("resize", onResize);
|
|
1445
|
+
window.addEventListener("resize", onResize);
|
|
1446
|
+
disposers.push(() => {
|
|
1447
|
+
window.visualViewport?.removeEventListener("resize", onResize);
|
|
1448
|
+
window.removeEventListener("resize", onResize);
|
|
1449
|
+
});
|
|
1450
|
+
}
|
|
1451
|
+
return () => {
|
|
1452
|
+
disposers.forEach((dispose) => {
|
|
1453
|
+
try {
|
|
1454
|
+
dispose();
|
|
1455
|
+
} catch {
|
|
1456
|
+
}
|
|
1457
|
+
});
|
|
1458
|
+
};
|
|
1459
|
+
}
|
|
1382
1460
|
onAppearanceChange(callback) {
|
|
1383
1461
|
this.appearanceListeners.add(callback);
|
|
1384
1462
|
callback(this.environment.appearance);
|
|
@@ -1609,6 +1687,26 @@ var TelegramMiniAppAdapter = class extends BaseMiniAppAdapter {
|
|
|
1609
1687
|
}
|
|
1610
1688
|
};
|
|
1611
1689
|
}
|
|
1690
|
+
safeHeightFromSdk() {
|
|
1691
|
+
try {
|
|
1692
|
+
if (typeof rawViewport.height === "function") {
|
|
1693
|
+
return rawViewport.height();
|
|
1694
|
+
}
|
|
1695
|
+
} catch {
|
|
1696
|
+
return void 0;
|
|
1697
|
+
}
|
|
1698
|
+
return void 0;
|
|
1699
|
+
}
|
|
1700
|
+
stableHeightFromSdk() {
|
|
1701
|
+
try {
|
|
1702
|
+
if (typeof rawViewport.stableHeight === "function") {
|
|
1703
|
+
return rawViewport.stableHeight();
|
|
1704
|
+
}
|
|
1705
|
+
} catch {
|
|
1706
|
+
return void 0;
|
|
1707
|
+
}
|
|
1708
|
+
return void 0;
|
|
1709
|
+
}
|
|
1612
1710
|
notifyViewHide() {
|
|
1613
1711
|
for (const listener of this.viewHideListeners) {
|
|
1614
1712
|
try {
|