1 | import { canUseDom } from './can-use-dom';
|
2 | import { isDev } from './is-dev';
|
3 | import { devError } from './dev-log';
|
4 | let tenPxTester = null;
|
5 | let tester = null;
|
6 | if (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 | }
|
20 | export 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 |