weex-nuke
Version:
基于 Rax 、Weex 的高性能组件体系 ~~
66 lines (56 loc) • 2.32 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
exports.calcFixedFont = calcFixedFont;
var _nukeEnv = require('../Env/index.js');
var isIpad = void 0;
if (_nukeEnv.isWeb) {
isIpad = navigator.userAgent.indexOf('iPad') > -1;
} else {
var env = typeof WXEnvironment !== 'string' ? WXEnvironment : {};
isIpad = env.platform.toLowerCase() === 'ios' && env.deviceModel.toLowerCase().indexOf('ipad') > -1;
}
function fitPad(style) {
var result = _extends({}, style);
var 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.
*/
function calcFixedFont(style) {
var fixedFont = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
var shouldFitPad = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
if (!style || !style.fontSize || !fixedFont) return style;
if (isIpad && shouldFitPad) return fitPad(style);
var result = _extends({}, style);
var 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 + (_nukeEnv.isWeb ? 'px' : 'wx');
if (isIpad && fitPad) {}
return result;
}
;