| 32 | } |
| 33 | |
| 34 | const parseColor = (colorStr: string): RGBA | null => { |
| 35 | if (colorStr.startsWith("rgb:")) { |
| 36 | const parts = colorStr.substring(4).split("/") |
| 37 | return RGBA.fromInts( |
| 38 | parseInt(parts[0], 16) >> 8, // Convert 16-bit to 8-bit |
| 39 | parseInt(parts[1], 16) >> 8, |
| 40 | parseInt(parts[2], 16) >> 8, |
| 41 | 255, |
| 42 | ) |
| 43 | } |
| 44 | if (colorStr.startsWith("#")) { |
| 45 | return RGBA.fromHex(colorStr) |
| 46 | } |
| 47 | if (colorStr.startsWith("rgb(")) { |
| 48 | const parts = colorStr.substring(4, colorStr.length - 1).split(",") |
| 49 | return RGBA.fromInts(parseInt(parts[0]), parseInt(parts[1]), parseInt(parts[2]), 255) |
| 50 | } |
| 51 | return null |
| 52 | } |
| 53 | |
| 54 | const handler = (data: Buffer) => { |
| 55 | const str = data.toString() |