| 173 | type CSSColor color.RGBA |
| 174 | |
| 175 | func (color CSSColor) String() string { |
| 176 | if color.A == 255 { |
| 177 | buf := make([]byte, 7) |
| 178 | buf[0] = '#' |
| 179 | hex.Encode(buf[1:], []byte{color.R, color.G, color.B}) |
| 180 | if buf[1] == buf[2] && buf[3] == buf[4] && buf[5] == buf[6] { |
| 181 | buf[2] = buf[3] |
| 182 | buf[3] = buf[5] |
| 183 | buf = buf[:4] |
| 184 | } |
| 185 | return string(buf) |
| 186 | } else if color.A == 0 { |
| 187 | return "rgba(0,0,0,0)" |
| 188 | } |
| 189 | a := float64(color.A) / 255.0 |
| 190 | return fmt.Sprintf("rgba(%d,%d,%d,%v)", int(float64(color.R)/a), int(float64(color.G)/a), int(float64(color.B)/a), dec(a)) |
| 191 | } |
| 192 | |
| 193 | func rgbaColor(col color.Color) color.RGBA { |
| 194 | r, g, b, a := col.RGBA() |