2
0

(embed) Add size and icon picker in bubble settings (#508)

This commit is contained in:
Baptiste Arnaud
2023-05-15 15:22:04 +02:00
committed by GitHub
parent 123926f273
commit 0f91b34497
15 changed files with 256 additions and 108 deletions

20
packages/lib/hexToRgb.ts Normal file
View File

@@ -0,0 +1,20 @@
export const hexToRgb = (hex: string): [r: number, g: number, b: number] => {
const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i
hex = hex.replace(shorthandRegex, (_m, r, g, b) => {
return r + r + g + g + b + b
})
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)
return result
? [
parseInt(result[1], 16),
parseInt(result[2], 16),
parseInt(result[3], 16),
]
: [0, 0, 0]
}
export const isLight = (hexColor: string) =>
(([r, g, b]) => (r * 299 + g * 587 + b * 114) / 1000 > 155)(
hexToRgb(hexColor)
)