(hexColor: string)
| 44 | } |
| 45 | |
| 46 | export function removeHexAlpha(hexColor: string) { |
| 47 | // 移除可能存在的 # 前缀,并转换为大写 |
| 48 | const hexColorClone = hexColor.replace(/^#/, '').toUpperCase(); |
| 49 | |
| 50 | if (hexColorClone.length === 8) { |
| 51 | // 8位十六进制,移除最后两位 |
| 52 | return '#' + hexColorClone.slice(0, 6); |
| 53 | } else if (hexColorClone.length === 4) { |
| 54 | // 4位十六进制(简写形式),移除最后一位 |
| 55 | return '#' + hexColorClone.slice(0, 3); |
| 56 | } else if (hexColorClone.length === 6 || hexColorClone.length === 3) { |
| 57 | // 已经是标准的 6 位或 3 位形式,直接返回 |
| 58 | return '#' + hexColorClone; |
| 59 | } else { |
| 60 | return hexColor; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | export function isTransparent(color?: string) { |
| 65 | return color === TRANSPARENT; |
no outgoing calls
no test coverage detected