UNPKG

@dfsol/platform-detector

Version:

Universal platform detector for web, PWA, Telegram Mini Apps, and native mobile applications with Client Hints API, feature detection, and enhanced accuracy

124 lines 3.54 kB
import type { PlatformInfo, PlatformDetectorOptions, TMAAvailability } from './types.js'; /** * Detects the current platform and environment */ export declare class PlatformDetector { private options; private cache?; private cacheTimestamp?; constructor(options?: PlatformDetectorOptions); /** * Detect platform information with priority-based detection * Supports caching to improve performance */ detect(): PlatformInfo; /** * Perform actual detection logic */ private performDetection; /** * Detect operating system from user agent with enhanced iPadOS detection */ private detectOS; /** * Detect device type from user agent and OS with enhanced tablet detection */ private detectDevice; /** * Detect domain mode (app.* vs tg.*) */ private detectDomainMode; /** * Detect environment (development vs production) */ private detectEnvironment; /** * Detect if running as native mobile app (Capacitor/Cordova) */ private detectNative; /** * Detect if running in Telegram Mini App with strict checks * Supports both native Telegram SDK and @tma.js SDK */ private detectTelegram; /** * Validate Telegram WebApp with flexible checks for native app compatibility */ private validateTelegramWebApp; /** * Detect if running as PWA (installed) with comprehensive checks * Updated for 2025 standards including window-controls-overlay */ private detectPWA; /** * Get detailed Capacitor information from native API */ private getCapacitorInfo; /** * Get detailed Telegram information from WebApp SDK * Supports both native Telegram SDK and @tma.js SDK */ private getTelegramInfo; /** * Get Telegram information from @tma.js SDK */ private getTelegramInfoFromTmaJs; /** * Get screen information */ private getScreenInfo; /** * Create server-side platform info (SSR) */ private createServerSideInfo; /** * Check Telegram Mini App (TMA) availability and generate deep link */ checkTMAAvailability(botUsername: string): TMAAvailability; /** * Attempt to open URL in Telegram */ openInTelegram(botUsername: string): boolean; /** * Get browser type (Chrome, Safari, Firefox, Edge, etc.) */ getBrowserType(): string; /** * Detect browser family (rendering engine) */ private detectBrowserFamily; /** * Calculate detection confidence score */ private calculateConfidence; /** * Get display mode for PWA */ getDisplayMode(): string; /** * Check if the app can be installed as PWA */ isPWAInstallable(): boolean; /** * Monitor for platform changes */ watchForChanges(callback: (info: PlatformInfo) => void): () => void; /** * Async detection with Client Hints support * Provides enhanced accuracy for OS version and device info on Chrome/Edge */ detectAsync(): Promise<PlatformInfo>; /** * Clear detection cache */ clearCache(): void; } /** * Create a platform detector instance */ export declare function createPlatformDetector(options?: PlatformDetectorOptions): PlatformDetector; /** * Quick platform detection (convenience function) */ export declare function detectPlatform(options?: PlatformDetectorOptions): PlatformInfo; //# sourceMappingURL=detector.d.ts.map