UNPKG

antd-mobile

Version:

<img src="https://gw.alipayobjects.com/mdn/rms_ee68a8/afts/img/A*hjjDS5Yy-ooAAAAAAAAAAAAAARQnAQ" alt="logo" width="100%" />

28 lines (22 loc) 758 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.measureCSSLength = measureCSSLength; var _isDev = require("./is-dev"); var _devLog = require("./dev-log"); function measureCSSLength(raw) { const withUnit = raw.trim(); if (withUnit.endsWith('px')) { return parseFloat(withUnit); } else if (withUnit.endsWith('rem')) { return parseFloat(withUnit) * parseFloat(window.getComputedStyle(document.documentElement).fontSize); } else if (withUnit.endsWith('vw')) { return parseFloat(withUnit) * window.innerWidth / 100; } else { if (_isDev.isDev) { (0, _devLog.devError)('Global', 'You are using a not supported CSS unit. Only `px` `rem` and `vw` are supported.'); } return 0; } }