From 054940ccc294055cfa41efc635839b68a979cebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E6=85=A7=E5=BC=BA?= Date: Wed, 6 Dec 2023 17:00:27 +0800 Subject: [PATCH] feat hsl --- src/util.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/util.ts b/src/util.ts index 3d93814..cdfe0ab 100644 --- a/src/util.ts +++ b/src/util.ts @@ -70,6 +70,7 @@ export const calculateOffset = ( const centerOffsetX = targetWidth / 2; const centerOffsetY = targetHeight / 2; const hsb = color.toHsb(); + const hsv = color.toHsv(); // Exclusion of boundary cases if ( @@ -83,18 +84,19 @@ export const calculateOffset = ( switch (type) { case 'hue': return { - x: (hsb.h / 360) * width - centerOffsetX, + x: ((hsv.h || hsb.h) / 360) * width - centerOffsetX, y: -centerOffsetY / 3, }; case 'alpha': return { - x: (hsb.a / 1) * width - centerOffsetX, + x: (hsv.a / 1) * width - centerOffsetX, y: -centerOffsetY / 3, }; } } + return { - x: hsb.s * width - centerOffsetX, - y: (1 - hsb.b) * height - centerOffsetY, + x: hsv.s * width - centerOffsetX, + y: (1 - hsv.v) * height - centerOffsetY, }; };