2023-10-23 13:02:17 +00:00
|
|
|
import { opacity as colorOpacity } from '../consts/opacity'
|
2023-06-06 11:46:54 +00:00
|
|
|
|
2023-10-23 13:02:17 +00:00
|
|
|
export type RGBAColor = `rgba(${string} / ${string}%)`
|
2023-06-06 11:46:54 +00:00
|
|
|
|
2023-10-23 13:02:17 +00:00
|
|
|
export type HexColor = `#${string}`
|
2023-06-06 11:46:54 +00:00
|
|
|
|
2023-10-23 13:02:17 +00:00
|
|
|
type Opacity = keyof typeof colorOpacity
|
|
|
|
|
|
|
|
export function getColorWithOpacity(
|
|
|
|
color: RGBAColor | HexColor,
|
|
|
|
opacity: Opacity
|
|
|
|
): string {
|
|
|
|
if (color.startsWith('rgba')) {
|
|
|
|
return color
|
|
|
|
.replace(' / ', '/')
|
|
|
|
.replace(/\s/g, ',')
|
|
|
|
.replace(/(\d+)%/, `${colorOpacity[opacity].decimal}`)
|
|
|
|
}
|
2023-06-06 11:46:54 +00:00
|
|
|
|
2023-10-23 13:02:17 +00:00
|
|
|
return `${color}${colorOpacity[opacity].hex}`
|
|
|
|
}
|