UNPKG

weex-nuke

Version:

基于 Rax 、Weex 的高性能组件体系 ~~

55 lines (49 loc) 1.76 kB
import { isWeb } from 'nuke-env'; let isIpad; if (isWeb) { isIpad = navigator.userAgent.indexOf('iPad') > -1; } else { const env = typeof WXEnvironment !== 'string' ? WXEnvironment : {}; isIpad = env.platform.toLowerCase() === 'ios' && env.deviceModel.toLowerCase().indexOf('ipad') > -1; } function fitPad(style) { const result = { ...style }; let fontSize = style.fontSize; if ((typeof fontSize === 'string' && fontSize.indexOf('rem') > 0) || typeof fontSize === 'number') { fontSize = parseInt(fontSize, 10); } if (typeof fontSize === 'string' && fontSize.indexOf('px') > 0) { fontSize = parseInt(fontSize, 10) * 2; } result.fontSize = fontSize; return result; } // appInfo.platform.toLowerCase() === 'ios' && // appInfo.deviceModel.toLowerCase() === 'ipad'; /** * parse fontSize to a fixed font. * if style: * fontSize:'28rem' or * fontSize:28, or * fontSize:'14px' * and fixedFont=true * will turns to: * font-size 14px (in web) / 14wx (in ios and android weex ). * But if in ipad, things go other way, if you choose fitPad, font-size will roll back to rem to fit screen. */ export function calcFixedFont(style, fixedFont = true, shouldFitPad = true) { if (!style || !style.fontSize || !fixedFont) return style; if (isIpad && shouldFitPad) return fitPad(style); const result = { ...style }; let fontSize = style.fontSize; if ((typeof fontSize === 'string' && fontSize.indexOf('rem') > 0) || typeof fontSize === 'number') { fontSize = Math.floor(parseInt(fontSize, 10) / 2); } if (typeof fontSize === 'string' && fontSize.indexOf('px') > 0) { fontSize = parseInt(fontSize, 10); } result.fontSize = fontSize + (isWeb ? 'px' : 'wx'); if (isIpad && fitPad) { } return result; }