UNPKG

964 BJavaScriptView Raw
1import { canUseDom } from './can-use-dom';
2import { isDev } from './is-dev';
3import { devError } from './dev-log';
4let tenPxTester = null;
5let tester = null;
6if (canUseDom) {
7 tenPxTester = document.createElement('div');
8 tenPxTester.className = 'adm-px-tester';
9 tenPxTester.style.setProperty('--size', '10');
10 document.body.appendChild(tenPxTester);
11 tester = document.createElement('div');
12 tester.className = 'adm-px-tester';
13 document.body.appendChild(tester);
14 if (isDev) {
15 if (window.getComputedStyle(tester).position !== 'fixed') {
16 devError('Global', 'The px tester is not rendering properly. Please make sure you have imported `antd-mobile/es/global`.');
17 }
18 }
19}
20export function convertPx(px) {
21 if (tenPxTester === null || tester === null) return px;
22 if (tenPxTester.getBoundingClientRect().height === 10) {
23 return px;
24 }
25 tester.style.setProperty('--size', px.toString());
26 return tester.getBoundingClientRect().height;
27}
\No newline at end of file