UNPKG

tma-helper

Version:

Telegram Mini Apps helper library for Vue 3 projects

4 lines (3 loc) 3.46 kB
(function(n,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(n=typeof globalThis<"u"?globalThis:n||self,i(n.TMAHelper={}))})(this,function(n){"use strict";var b=Object.defineProperty;var w=(n,i,r)=>i in n?b(n,i,{enumerable:!0,configurable:!0,writable:!0,value:r}):n[i]=r;var s=(n,i,r)=>w(n,typeof i!="symbol"?i+"":i,r);class i{constructor(){s(this,"webApp");var t;if(typeof window>"u"){console.error("[TMA Helper] Window object not found (non-browser environment)");return}const e=(t=window.Telegram)==null?void 0:t.WebApp;if(!e){console.error(`[TMA Helper] Telegram WebApp SDK not detected. Please include: <script src="https://telegram.org/js/telegram-web-app.js"><\/script>`);return}this.webApp=e,console.log("[TMA Helper] ✅ Telegram SDK initialized.")}get initData(){var e;return(e=this.webApp)==null?void 0:e.initData}get initDataUnsafe(){var e;return(e=this.webApp)==null?void 0:e.initDataUnsafe}get instance(){return this.webApp}get isAvailable(){return!!this.webApp}get safeAreaInset(){var e;return(e=this.webApp)==null?void 0:e.safeAreaInset}get contentSafeAreaInset(){var e;return(e=this.webApp)==null?void 0:e.contentSafeAreaInset}close(){var e;(e=this.webApp)==null||e.close()}hide(){var e;(e=this.webApp)==null||e.hide()}expand(){var e;(e=this.webApp)==null||e.expand()}disableVerticalSwipes(){var e;(e=this.webApp)==null||e.disableVerticalSwipes()}enableVerticalSwipes(){var e;(e=this.webApp)==null||e.enableVerticalSwipes()}enableClosingConfirmation(){var e;(e=this.webApp)==null||e.enableClosingConfirmation()}disableClosingConfirmation(){var e;(e=this.webApp)==null||e.disableClosingConfirmation()}lockOrientation(){var e;(e=this.webApp)==null||e.lockOrientation()}unlockOrientation(){var e;(e=this.webApp)==null||e.unlockOrientation()}hideBackButton(){var e,t;(t=(e=this.webApp)==null?void 0:e.BackButton)==null||t.hide()}showBackButton(){var e,t;(t=(e=this.webApp)==null?void 0:e.BackButton)==null||t.show()}onBackButtonClick(e){var t,p;(p=(t=this.webApp)==null?void 0:t.BackButton)==null||p.onClick(e)}hapticFeedback(e){var t,p;(p=(t=this.webApp)==null?void 0:t.HapticFeedback)==null||p.impactOccurred(e)}openTelegramLink(e){var t;(t=this.webApp)==null||t.openTelegramLink(e)}openLink(e){if(!this.webApp||!e)return;/^https?:\/\/t\.me|^t\.me/i.test(e)?this.webApp.openTelegramLink(e):this.webApp.openLink(e)}requestFullscreen(){var e;(e=this.webApp)==null||e.requestFullscreen()}exitFullscreen(){var e;(e=this.webApp)==null||e.exitFullscreen()}openInvoice(e,t){var p;(p=this.webApp)==null||p.openInvoice(e,c=>{t&&t(c)})}setHeaderColor(e){var t;(t=this.webApp)==null||t.setHeaderColor(e)}isVersionAtLeast(e){var t;return(t=this.webApp)==null?void 0:t.isVersionAtLeast(e)}}const r=new i;class o{constructor(){s(this,"webApp");this.checkEnvironment()}checkEnvironment(){if(typeof window>"u"){console.error("[TMA Helper] Window object not found. Are you in a browser?");return}window.Telegram&&window.Telegram.WebApp?(this.webApp=window.Telegram.WebApp,console.log("[TMA Helper] ✅ Telegram WebApp detected and ready.")):console.error(`[TMA Helper] ❌ Telegram WebApp not detected. Make sure the Telegram SDK script is loaded: Add <script src="https://telegram.org/js/telegram-web-app.js"><\/script> before your app runs.`)}getWebApp(){return this.webApp}}const a=new o;n.TMAHelper=o,n.Telegram=r,n.tmaHelper=a,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});