(color, format = "smart", fallback = "#000000")
| 50 | } |
| 51 | |
| 52 | export function serializeColorForPicker(color, format = "smart", fallback = "#000000") { |
| 53 | const { red, green, blue, alpha } = getRgbColorChannels(color, fallback); |
| 54 | |
| 55 | if (format === "rgba") { |
| 56 | return `rgba(${red}, ${green}, ${blue}, ${alpha})`; |
| 57 | } |
| 58 | |
| 59 | const hex = [red, green, blue] |
| 60 | .map((channel) => channel.toString(16).padStart(2, "0")) |
| 61 | .join("") |
| 62 | .toUpperCase(); |
| 63 | |
| 64 | if (format === "smart" && alpha < 1) { |
| 65 | return `rgba(${red}, ${green}, ${blue}, ${alpha})`; |
| 66 | } |
| 67 | |
| 68 | return `#${hex}`; |
| 69 | } |
no test coverage detected