UNPKG

@alifd/meet-react

Version:

Fusion Mobile React UI System Component

104 lines 3.84 kB
import { isMiniApp, isWeChatMiniProgram, isByteDanceMicroApp, isWeb, isNode } from '@uni/env'; import { isUndef } from './fp'; function formatVersion(v) { return String(v).replace(/_/g, '.'); } function getOSInfo(ua) { var OSList = { ios: /(like Mac OS X)/i, android: /Android/i, wp: /Windows Phone/i, bb: /(BlackBerry)|(RIM)/i, win: /(Windows 95)|(Win95)|(Windows_95)|(Windows ME)|(Windows 98)|(Win98)|(Windows NT 5.0)|(Windows 2000)|(Windows NT)|(WinNT)|(Windows XP)/i, linux: /(Linux)|(X11)/i, macos: /(Mac_PowerPC)|(Macintosh)/i, robot: /(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(ia_archiver)/i }; var os = { name: 'unknown', version: '0.0.0' }; if (/Windows\sPhone\s(?:OS\s)?([\d.]+)/.test(ua)) { os.version = RegExp.$1; } else if (/Safari/.test(ua) && /Android[\s/]([\d.]+)/.test(ua)) { os.version = RegExp.$1; } else if (/(iPhone|iPad|iPod)/.test(ua) && /OS ([\d_.]+) like Mac OS X/.test(ua)) { os.version = RegExp.$1; } os.version = formatVersion(os.version); for (var _osName in OSList) { var Reg = OSList[_osName]; if (Reg.test(ua)) { os.name = _osName; break; } } return os; } export var isStrictMiniApp = isMiniApp && !isWeb; export var isStrictWechatMiniProgram = isWeChatMiniProgram && !isWeb; export var isStrictByteDanceMicroApp = isByteDanceMicroApp && !isWeb; export var isMiniappPlatform = !isWeb && (isMiniApp || isWeChatMiniProgram || isByteDanceMicroApp); var systemInfo; if (isStrictMiniApp) { systemInfo = my.getSystemInfoSync(); } else if (isStrictWechatMiniProgram) { systemInfo = wx.getSystemInfoSync(); } else if (isStrictByteDanceMicroApp) { systemInfo = tt.getSystemInfoSync(); } var name = 'unknown'; var version = '0.0.0'; if (isStrictWechatMiniProgram) { var _systemInfo = systemInfo, system = _systemInfo.system; name = system.split(' ')[0].toLowerCase(); version = system.split(' ')[1]; } else if (isStrictMiniApp) { var _systemInfo2 = systemInfo, _system = _systemInfo2.system, platform = _systemInfo2.platform; name = platform.toLowerCase(); version = _system; } else if (isStrictByteDanceMicroApp) { var _systemInfo3 = systemInfo, _system2 = _systemInfo3.system, _platform = _systemInfo3.platform; name = _platform.toLowerCase(); version = _system2; } else if (isNode) { systemInfo = { screenWidth: 0, screenHeight: 0, windowWidth: 0, windowHeight: 0, devicePixelRatio: 1 }; } else { var UA = isUndef(navigator) ? '' : navigator.userAgent; var info = getOSInfo(UA); name = info.name; version = info.version; } export { systemInfo }; export var screenWidth = systemInfo && !isUndef(systemInfo.screenWidth) ? systemInfo.screenWidth : window.screen.width; export var screenHeight = systemInfo && !isUndef(systemInfo.screenHeight) ? systemInfo.screenHeight : window.screen.height; export var windowWidth = systemInfo && !isUndef(systemInfo.windowWidth) ? systemInfo.windowWidth : document.documentElement.clientWidth; export var windowHeight = systemInfo && !isUndef(systemInfo.windowHeight) ? systemInfo.windowHeight : document.documentElement.clientHeight; export var dpr = systemInfo && (systemInfo.devicePixelRatio || systemInfo.pixelRatio) ? systemInfo.devicePixelRatio || systemInfo.pixelRatio : window.devicePixelRatio; export var osName = name; export var osVersion = version; export var isIOS = name === 'ios'; export var isAndroid = name === 'android'; export var screenRate = screenWidth / 750; export var screenPixelRatio = isMiniappPlatform ? 1 : windowWidth / 750; export var isProduction = function isProduction() { var PRODUCTION_ENV = 'production'; var result = false; try { if (process.env.NODE_ENV === PRODUCTION_ENV) { result = true; } } catch (err) {} return result; };