* Checks if a search string looks like a hex color code.
(searchValue: string)
| 52 | * Checks if a search string looks like a hex color code. |
| 53 | */ |
| 54 | function isHexColorSearch(searchValue: string): boolean { |
| 55 | const trimmed = searchValue.trim(); |
| 56 | // Must start with # or be a valid 3 or 6 character hex string |
| 57 | if (trimmed.startsWith('#')) { |
| 58 | const hex = trimmed.slice(1); |
| 59 | return /^[0-9A-Fa-f]{3}$/.test(hex) || /^[0-9A-Fa-f]{6}$/.test(hex); |
| 60 | } |
| 61 | // Also match without # if it's exactly 3 or 6 hex characters |
| 62 | return /^[0-9A-Fa-f]{6}$/.test(trimmed); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Calculates the color distance between two RGB colors using weighted Euclidean distance. |
no test coverage detected