Skip to content

Commit

Permalink
Update packages/@core/base/shared/src/colorful/convert.ts
Browse files Browse the repository at this point in the history
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
jinmao88 and coderabbitai[bot] authored Aug 7, 2024
1 parent d79189b commit 0fc35b1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/@core/base/shared/src/colorful/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ function isValidColor(color?: string) {
* 将HLS字符串转换为RGB颜色字符串
*
* 本函数接收一个表示HLS值的字符串,移除其中的度量单位,
* 并将其转换为TinyColor对象,以便进行颜色处理如果转换后的颜色无效,
* 则直接返回原始字符串;否则,返回转换后的RGB颜色字符串
* 并将其转换为TinyColor对象,以便进行颜色处理。
* 如果转换后的颜色无效,则直接返回原始字符串;
* 否则,返回转换后的RGB颜色字符串
*
* @param str 表示HLS颜色值的字符串,可能包含度量单位如'deg'、'grad'、'rad'或'turn'
* @returns 如果颜色值有效,则返回对应的RGB颜色字符串;如果无效,则返回原始字符串
*/
function hlsStringToRGBString(str: string): string {
// 创建TinyColor对象,用于处理颜色转换
// 移除HLS字符串中的度量单位,以便正确解析
const color = new TinyColor(
`hsl(${str.replaceAll(/deg|grad|rad|turn/g, '')})`,
`hsl(${str.replace(/deg|grad|rad|turn/g, '')})`,
);
// 检查颜色是否有效,如果无效则直接返回原始字符串
if (!color.isValid) {
Expand Down

0 comments on commit 0fc35b1

Please sign in to comment.