Merge branch 'dev' into next

This commit is contained in:
chenjiahan
2020-06-19 06:45:40 +08:00
111 changed files with 4109 additions and 2285 deletions
+32
View File
@@ -9,3 +9,35 @@ export function addUnit(value?: string | number): string | undefined {
value = String(value);
return isNumeric(value) ? `${value}px` : value;
}
// cache
let rootFontSize: number;
function getRootFontSize() {
if (!rootFontSize) {
const doc = document.documentElement;
const fontSize =
doc.style.fontSize || window.getComputedStyle(doc).fontSize;
rootFontSize = parseFloat(fontSize);
}
return rootFontSize;
}
function convertRem(value: string) {
value = value.replace(/rem/g, '');
return +value * getRootFontSize();
}
export function unitToPx(value: string | number): number {
if (typeof value === 'number') {
return value;
}
if (value.indexOf('rem') !== -1) {
return convertRem(value);
}
return parseFloat(value);
}