1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import { toTypeString } from '@vue/shared'
- export const toRawType = (value: any) => toTypeString(value).slice(8, -1)
- export const normalizeUnitToStyle = (
- unit: number | string
- ): number | string => {
- if (unit === 0) {
- return unit
- } else if (typeof unit === 'number') {
- return unit ? (unit <= 1 && unit >= 0 ? `${100 * unit}%` : `${unit}px`) : 0
- } else if (unit.includes('px')) {
- return normalizeUnitToStyle(Number.parseFloat(unit))
- } else if (unit.includes('%')) {
- return normalizeUnitToStyle(Number.parseFloat(unit) / 100)
- } else {
- return Number(unit)
- }
- }
- export const os = () => {
- const ua = navigator ? navigator.userAgent : ''
- const isWindowsPhone = /(?:Windows Phone)/.test(ua)
- const isSymbian = /(?:SymbianOS)/.test(ua) || isWindowsPhone
- const isAndroid = /(?:Android)/.test(ua)
- const isFireFox = /(?:Firefox)/.test(ua)
- // const isChrome = /(?:Chrome|CriOS)/.test(ua);
- let isTablet =
- /(?:iPad|PlayBook)/.test(ua) ||
- (isAndroid && !/(?:Mobile)/.test(ua)) ||
- (isFireFox && /(?:Tablet)/.test(ua))
- const isPhone = /(?:iPhone)/.test(ua) && !isTablet
- const isPc = !isPhone && !isAndroid && !isSymbian
- if (isPc && navigator && navigator.maxTouchPoints > 1) {
- isTablet = true
- }
- return {
- isTablet,
- isPhone,
- isAndroid,
- isPc,
- }
- }
|