-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathunits.ts
More file actions
57 lines (41 loc) · 1.12 KB
/
units.ts
File metadata and controls
57 lines (41 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* eslint-disable */
import { rem as remObs, vh as vhObs, vw as vwObs } from "../reactivity";
import type { StyleFunctionResolver } from "./resolve";
export const em: StyleFunctionResolver = (resolve, func, get) => {
let value = func[2];
if (!value) {
return;
}
let emValue = resolve([{}, "var", ["__rn-css-em"]]);
if (typeof emValue !== "number") {
emValue = get(remObs);
}
if (typeof emValue !== "number") {
return;
}
return round(Number(value) * emValue);
};
export const vw: StyleFunctionResolver = (_, func, get) => {
const value = func[2];
if (typeof value !== "number") {
return;
}
return round(get(vwObs) * (value / 100));
};
export const vh: StyleFunctionResolver = (_, func, get) => {
const value = func[2];
if (typeof value !== "number") {
return;
}
return round((value / 100) * get(vhObs));
};
export const rem: StyleFunctionResolver = (_, func, get) => {
const value = func[2];
if (typeof value !== "number") {
return;
}
return round(value * get(remObs));
};
function round(number: number) {
return Math.round((number + Number.EPSILON) * 100) / 100;
}