UNPKG

pixi.js

Version:

<p align="center"> <a href="https://pixijs.com" target="_blank" rel="noopener noreferrer"> <img height="150" src="https://files.pixijs.download/branding/pixijs-logo-transparent-dark.svg?v=1" alt="PixiJS logo"> </a> </p> <br/> <p align="center">

1 lines 6.85 kB
{"version":3,"file":"isMobile.mjs","sources":["../../../src/utils/browser/isMobile.ts"],"sourcesContent":["import isMobileJs from 'ismobilejs';\n\n// ismobilejs have different import behavior for CJS and ESM, so here is the hack\ntype isMobileJsType = typeof isMobileJs & { default?: typeof isMobileJs };\nconst isMobileCall = (isMobileJs as isMobileJsType).default ?? isMobileJs;\n\n/**\n * The result of the mobile device detection system.\n * Provides detailed information about device type and platform.\n * @example\n * ```ts\n * // Type usage with isMobile\n * const deviceInfo: isMobileResult = isMobile;\n *\n * // Check device categories\n * if (deviceInfo.apple.device) {\n * console.log('iOS Device Details:', {\n * isPhone: deviceInfo.apple.phone,\n * isTablet: deviceInfo.apple.tablet,\n * isUniversal: deviceInfo.apple.universal\n * });\n * }\n *\n * // Platform-specific checks\n * const platformInfo = {\n * isApple: deviceInfo.apple.device,\n * isAndroid: deviceInfo.android.device,\n * isAmazon: deviceInfo.amazon.device,\n * isWindows: deviceInfo.windows.device\n * };\n * ```\n * @category utils\n * @standard\n */\nexport type isMobileResult = {\n /**\n * Apple device detection information.\n * Provides detailed iOS device categorization.\n * @example\n * ```ts\n * // iOS device checks\n * if (isMobile.apple.device) {\n * if (isMobile.apple.tablet) {\n * // iPad-specific code\n * useTabletLayout();\n * } else if (isMobile.apple.phone) {\n * // iPhone-specific code\n * usePhoneLayout();\n * }\n * }\n * ```\n */\n apple: {\n /** Whether the device is an iPhone */\n phone: boolean;\n /** Whether the device is an iPod Touch */\n ipod: boolean;\n /** Whether the device is an iPad */\n tablet: boolean;\n /** Whether app is running in iOS universal mode */\n universal: boolean;\n /** Whether device is any Apple mobile device */\n device: boolean;\n };\n\n /**\n * Amazon device detection information.\n * Identifies Amazon Fire tablets and phones.\n * @example\n * ```ts\n * // Amazon Fire tablet detection\n * if (isMobile.amazon.tablet) {\n * // Fire tablet optimizations\n * optimizeForFireTablet();\n * }\n * ```\n */\n amazon: {\n /** Whether device is a Fire Phone */\n phone: boolean;\n /** Whether device is a Fire Tablet */\n tablet: boolean;\n /** Whether device is any Amazon mobile device */\n device: boolean;\n };\n\n /**\n * Android device detection information.\n * Categorizes Android phones and tablets.\n * @example\n * ```ts\n * // Android device handling\n * if (isMobile.android.device) {\n * // Check specific type\n * const deviceType = isMobile.android.tablet ?\n * 'tablet' : 'phone';\n * console.log(`Android ${deviceType} detected`);\n * }\n * ```\n */\n android: {\n /** Whether device is an Android phone */\n phone: boolean;\n /** Whether device is an Android tablet */\n tablet: boolean;\n /** Whether device is any Android device */\n device: boolean;\n };\n\n /**\n * Windows device detection information.\n * Identifies Windows phones and tablets.\n * @example\n * ```ts\n * // Windows device checks\n * if (isMobile.windows.tablet) {\n * // Surface tablet optimizations\n * enableTouchFeatures();\n * }\n * ```\n */\n windows: {\n /** Whether device is a Windows Phone */\n phone: boolean;\n /** Whether device is a Windows tablet */\n tablet: boolean;\n /** Whether device is any Windows mobile device */\n device: boolean;\n };\n\n /**\n * Other device detection information.\n * Covers additional platforms and browsers.\n * @example\n * ```ts\n * // Check other platforms\n * if (isMobile.other.blackberry10) {\n * // BlackBerry 10 specific code\n * } else if (isMobile.other.chrome) {\n * // Chrome mobile specific code\n * }\n * ```\n */\n other: {\n /** Whether device is a BlackBerry */\n blackberry: boolean;\n /** Whether device is a BlackBerry 10 */\n blackberry10: boolean;\n /** Whether browser is Opera Mobile */\n opera: boolean;\n /** Whether browser is Firefox Mobile */\n firefox: boolean;\n /** Whether browser is Chrome Mobile */\n chrome: boolean;\n /** Whether device is any other mobile device */\n device: boolean;\n };\n\n /**\n * Whether the device is any type of phone.\n * Combines detection across all platforms.\n * @example\n * ```ts\n * // Check if device is a phone\n * if (isMobile.phone) {\n * console.log('Running on a mobile phone');\n * }\n * ```\n */\n phone: boolean;\n\n /**\n * Whether the device is any type of tablet.\n * Combines detection across all platforms.\n * @example\n * ```ts\n * // Check if device is a tablet\n * if (isMobile.tablet) {\n * console.log('Running on a mobile tablet');\n * }\n * ```\n */\n tablet: boolean;\n\n /**\n * Whether the device is any type of mobile device.\n * True if any mobile platform is detected.\n * @example\n * ```ts\n * // Check if device is mobile\n * if (isMobile.any) {\n * console.log('Running on a mobile device');\n * }\n * ```\n */\n any: boolean;\n};\n\n/**\n * Detects whether the device is mobile and what type of mobile device it is.\n * Provides a comprehensive detection system for mobile platforms and devices.\n * @example\n * ```ts\n * import { isMobile } from 'pixi.js';\n *\n * // Check specific device types\n * if (isMobile.apple.tablet) {\n * console.log('Running on iPad');\n * }\n *\n * // Check platform categories\n * if (isMobile.android.any) {\n * console.log('Running on Android');\n * }\n *\n * // Conditional rendering\n * if (isMobile.phone) {\n * renderer.resolution = 2;\n * view.style.width = '100vw';\n * }\n * ```\n * @remarks\n * - Detects all major mobile platforms\n * - Distinguishes between phones and tablets\n * - Updates when navigator changes\n * - Common in responsive design\n * @category utils\n * @standard\n * @see {@link isMobileResult} For full type definition\n */\nexport const isMobile: isMobileResult = isMobileCall(globalThis.navigator);\n"],"names":[],"mappings":";;;AAIA,MAAM,YAAA,GAAgB,WAA8B,OAAW,IAAA,UAAA,CAAA;AAkOlD,MAAA,QAAA,GAA2B,YAAa,CAAA,UAAA,CAAW,SAAS;;;;"}