($color: string)
| 679 | let context: CanvasRenderingContext2D; |
| 680 | |
| 681 | function domParseColor($color: string) { |
| 682 | if (!context) { |
| 683 | canvas = document.createElement('canvas'); |
| 684 | canvas.width = 1; |
| 685 | canvas.height = 1; |
| 686 | context = canvas.getContext('2d', {willReadFrequently: true})!; |
| 687 | } |
| 688 | context.fillStyle = $color; |
| 689 | context.fillRect(0, 0, 1, 1); |
| 690 | const d = context.getImageData(0, 0, 1, 1).data; |
| 691 | const color = `rgba(${d[0]}, ${d[1]}, ${d[2]}, ${(d[3] / 255).toFixed(2)})`; |
| 692 | return parseRGB(color); |
| 693 | } |