* Parse hex color to RGB floats * @param hex - Hex color string (#rgb or #rrggbb) * @returns RGB values 0-1 or null
(hex: string | undefined)
| 61 | * @returns RGB values 0-1 or null |
| 62 | */ |
| 63 | function parseColor(hex: string | undefined): number[] | null { |
| 64 | if (!hex || hex === 'none') return null |
| 65 | hex = hex.replace('#', '') |
| 66 | if (hex.length === 3) { |
| 67 | hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2] |
| 68 | } |
| 69 | const r = parseInt(hex.slice(0, 2), 16) / 255 |
| 70 | const g = parseInt(hex.slice(2, 4), 16) / 255 |
| 71 | const b = parseInt(hex.slice(4, 6), 16) / 255 |
| 72 | return [r, g, b] |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Escape string for PDF |