From fd06ac17c1c63d1cd2c64156da926ef61ac8bc62 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Thu, 30 Sep 2021 02:07:44 -0500 Subject: [PATCH] refactor(utils): refactor aria color (#3742) --- packages/utils/aria.ts | 6 +++--- packages/utils/color.ts | 18 +++++++----------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/packages/utils/aria.ts b/packages/utils/aria.ts index b58be421eb..9fdafbe642 100644 --- a/packages/utils/aria.ts +++ b/packages/utils/aria.ts @@ -27,9 +27,9 @@ export const isVisible = (element: HTMLElement) => { export const obtainAllFocusableElements = ( element: HTMLElement ): HTMLElement[] => { - return Array.from(element.querySelectorAll(FOCUSABLE_ELEMENT_SELECTORS)) - .filter(isFocusable) - .filter(isVisible) as HTMLElement[] + return Array.from( + element.querySelectorAll(FOCUSABLE_ELEMENT_SELECTORS) + ).filter((item: HTMLElement) => isFocusable(item) && isVisible(item)) } /** diff --git a/packages/utils/color.ts b/packages/utils/color.ts index 96350041a8..841f51bb99 100644 --- a/packages/utils/color.ts +++ b/packages/utils/color.ts @@ -1,11 +1,8 @@ export function calcColorChannels(c: string) { let rawColor = c.replace('#', '') if (/^[0-9a-fA-F]{3}$/.test(rawColor)) { - const color = rawColor.split('') - for (let i = 2; i >= 0; i--) { - color.splice(i, 0, color[i]) - } - rawColor = color.join('') + rawColor = + rawColor[0].repeat(2) + rawColor[1].repeat(2) + rawColor[2].repeat(2) } if (/^[0-9a-fA-F]{6}$/.test(rawColor)) { return { @@ -13,12 +10,11 @@ export function calcColorChannels(c: string) { green: parseInt(rawColor.slice(2, 4), 16), blue: parseInt(rawColor.slice(4, 6), 16), } - } else { - return { - red: 255, - green: 255, - blue: 255, - } + } + return { + red: 255, + green: 255, + blue: 255, } }