From d369a18208dea9fa84b976b95c7a415eca765e79 Mon Sep 17 00:00:00 2001 From: xmlwizard Date: Thu, 19 Dec 2024 15:00:47 +0200 Subject: [PATCH] fix: alpha() now sets the alpha value on arrays as expected --- lib/utils.ts | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/lib/utils.ts b/lib/utils.ts index 1ffbe4ec..c543f8ad 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -83,44 +83,34 @@ console.log(myColor) // #b2c3f180 */ -// ! fix bug when setting alpha value to array'./ function alpha( color: ColorToken = "cyan", amount: Amount | undefined = undefined, ): Amount extends undefined ? number : ColorToken { // @ts-ignore: - let alphaChannel: number; - - // @ts-ignore: - let len: number, + let alphaChannel: number, + len: number, hasMode: string | undefined, hasAlpha: boolean, alphaIdx: number - // @ts-ignore: - - if (isArray(color)) { - len = color?.length + if (isArray(color)) // @ts-ignore: - hasMode = (color as ColorTuple).find((c) => - eq(typeof c, "string") - ) - hasAlpha = (color as ColorTuple).filter((channel) => - eq(typeof channel, "number") - ) - // if the length is 4 then the alpha is arr.length - 1 - .length === - 4 - - alphaIdx = hasAlpha ? len - 1 : hasMode ? 4 : 3 + [len, hasMode, hasAlpha, alphaIdx, alphaChannel] = + [color?.length, (color as ColorTuple).find((c) => + eq(typeof c, "string") + ), + (color as ColorTuple).filter((channel) => + eq(typeof channel, "number") + ).length === 4, + // @ts-ignore: - alphaChannel = color[alphaIdx] - } - + hasAlpha ? len - 1 : hasMode ? 4 : 3, color[alphaIdx] + ];