From 5b9527ab04fb8b55d57784430ec3a4daa42f8307 Mon Sep 17 00:00:00 2001 From: huangteng02 Date: Tue, 2 Feb 2021 17:28:57 +0800 Subject: [PATCH 1/2] feat: Remove redundant code --- packages/utils/src/getDOMInfo.ts | 48 +++++++++++++++++--------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/packages/utils/src/getDOMInfo.ts b/packages/utils/src/getDOMInfo.ts index 636c7d5c4..211170409 100644 --- a/packages/utils/src/getDOMInfo.ts +++ b/packages/utils/src/getDOMInfo.ts @@ -1,19 +1,27 @@ +export const round = Math.round; + +export const getComputedStyle = (dom: HTMLElement) => { + return window.getComputedStyle(dom); +}; + export const getDOMPadding = (dom: HTMLElement) => { return { - left: parseInt(window.getComputedStyle(dom).paddingLeft), - right: parseInt(window.getComputedStyle(dom).paddingRight), - bottom: parseInt(window.getComputedStyle(dom).paddingTop), - top: parseInt(window.getComputedStyle(dom).paddingBottom), + left: parseInt(getComputedStyle(dom).paddingLeft), + right: parseInt(getComputedStyle(dom).paddingRight), + bottom: parseInt(getComputedStyle(dom).paddingTop), + top: parseInt(getComputedStyle(dom).paddingBottom), }; }; + export const getDOMMargin = (dom: HTMLElement) => { return { - left: parseInt(window.getComputedStyle(dom).marginLeft), - right: parseInt(window.getComputedStyle(dom).marginRight), - bottom: parseInt(window.getComputedStyle(dom).marginTop), - top: parseInt(window.getComputedStyle(dom).marginBottom), + left: parseInt(getComputedStyle(dom).marginLeft), + right: parseInt(getComputedStyle(dom).marginRight), + bottom: parseInt(getComputedStyle(dom).marginTop), + top: parseInt(getComputedStyle(dom).marginBottom), }; }; + export const getDOMInfo = (dom: HTMLElement) => { const { x, @@ -29,26 +37,22 @@ export const getDOMInfo = (dom: HTMLElement) => { padding = getDOMPadding(dom); return { - x: Math.round(x), - y: Math.round(y), - top: Math.round(top), - left: Math.round(left), - bottom: Math.round(bottom), - right: Math.round(right), - width: Math.round(width), - height: Math.round(height), - outerWidth: Math.round(width + margin.left + margin.right), - outerHeight: Math.round(height + margin.top + margin.bottom), + x: round(x), + y: round(y), + top: round(top), + left: round(left), + bottom: round(bottom), + right: round(right), + width: round(width), + height: round(height), + outerWidth: round(width + margin.left + margin.right), + outerHeight: round(height + margin.top + margin.bottom), margin, padding, inFlow: dom && dom.parentElement && !!styleInFlow(dom, dom.parentElement), }; }; -export const getComputedStyle = (dom: HTMLElement) => { - return window.getComputedStyle(dom); -}; - export const styleInFlow = (el: HTMLElement, parent: HTMLElement) => { const style: any = getComputedStyle(el); const parentStyle: any = getComputedStyle(parent); From 33822a845ba62acd0f5dd0379af4b17e331b583a Mon Sep 17 00:00:00 2001 From: huangteng02 Date: Thu, 4 Feb 2021 13:40:47 +0800 Subject: [PATCH 2/2] feat: keep Math.round --- packages/utils/src/getDOMInfo.ts | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/packages/utils/src/getDOMInfo.ts b/packages/utils/src/getDOMInfo.ts index 211170409..0d6da1910 100644 --- a/packages/utils/src/getDOMInfo.ts +++ b/packages/utils/src/getDOMInfo.ts @@ -1,5 +1,3 @@ -export const round = Math.round; - export const getComputedStyle = (dom: HTMLElement) => { return window.getComputedStyle(dom); }; @@ -37,16 +35,16 @@ export const getDOMInfo = (dom: HTMLElement) => { padding = getDOMPadding(dom); return { - x: round(x), - y: round(y), - top: round(top), - left: round(left), - bottom: round(bottom), - right: round(right), - width: round(width), - height: round(height), - outerWidth: round(width + margin.left + margin.right), - outerHeight: round(height + margin.top + margin.bottom), + x: Math.round(x), + y: Math.round(y), + top: Math.round(top), + left: Math.round(left), + bottom: Math.round(bottom), + right: Math.round(right), + width: Math.round(width), + height: Math.round(height), + outerWidth: Math.round(width + margin.left + margin.right), + outerHeight: Math.round(height + margin.top + margin.bottom), margin, padding, inFlow: dom && dom.parentElement && !!styleInFlow(dom, dom.parentElement),