Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| NamedColors | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
| lookup | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Css\Value; |
| 6 | |
| 7 | /** |
| 8 | * CSS named colors per CSS Color Module 4 §6.1. All keys are lower-case; |
| 9 | * the value parser lowercases identifier input before lookup. |
| 10 | * |
| 11 | * The table is hand-maintained. Adding entries is additive (minor bump). |
| 12 | * |
| 13 | * @internal Used by the value parser only; consumers should construct `Color` |
| 14 | * values directly with explicit RGB. |
| 15 | */ |
| 16 | final class NamedColors |
| 17 | { |
| 18 | /** @var array<string, array{0:int,1:int,2:int}> name → [r, g, b] (0-255) */ |
| 19 | public const array TABLE = [ |
| 20 | 'aliceblue' => [240, 248, 255], |
| 21 | 'antiquewhite' => [250, 235, 215], |
| 22 | 'aqua' => [0, 255, 255], |
| 23 | 'aquamarine' => [127, 255, 212], |
| 24 | 'azure' => [240, 255, 255], |
| 25 | 'beige' => [245, 245, 220], |
| 26 | 'bisque' => [255, 228, 196], |
| 27 | 'black' => [0, 0, 0], |
| 28 | 'blanchedalmond' => [255, 235, 205], |
| 29 | 'blue' => [0, 0, 255], |
| 30 | 'blueviolet' => [138, 43, 226], |
| 31 | 'brown' => [165, 42, 42], |
| 32 | 'burlywood' => [222, 184, 135], |
| 33 | 'cadetblue' => [95, 158, 160], |
| 34 | 'chartreuse' => [127, 255, 0], |
| 35 | 'chocolate' => [210, 105, 30], |
| 36 | 'coral' => [255, 127, 80], |
| 37 | 'cornflowerblue' => [100, 149, 237], |
| 38 | 'cornsilk' => [255, 248, 220], |
| 39 | 'crimson' => [220, 20, 60], |
| 40 | 'cyan' => [0, 255, 255], |
| 41 | 'darkblue' => [0, 0, 139], |
| 42 | 'darkcyan' => [0, 139, 139], |
| 43 | 'darkgoldenrod' => [184, 134, 11], |
| 44 | 'darkgray' => [169, 169, 169], |
| 45 | 'darkgreen' => [0, 100, 0], |
| 46 | 'darkgrey' => [169, 169, 169], |
| 47 | 'darkkhaki' => [189, 183, 107], |
| 48 | 'darkmagenta' => [139, 0, 139], |
| 49 | 'darkolivegreen' => [85, 107, 47], |
| 50 | 'darkorange' => [255, 140, 0], |
| 51 | 'darkorchid' => [153, 50, 204], |
| 52 | 'darkred' => [139, 0, 0], |
| 53 | 'darksalmon' => [233, 150, 122], |
| 54 | 'darkseagreen' => [143, 188, 143], |
| 55 | 'darkslateblue' => [72, 61, 139], |
| 56 | 'darkslategray' => [47, 79, 79], |
| 57 | 'darkslategrey' => [47, 79, 79], |
| 58 | 'darkturquoise' => [0, 206, 209], |
| 59 | 'darkviolet' => [148, 0, 211], |
| 60 | 'deeppink' => [255, 20, 147], |
| 61 | 'deepskyblue' => [0, 191, 255], |
| 62 | 'dimgray' => [105, 105, 105], |
| 63 | 'dimgrey' => [105, 105, 105], |
| 64 | 'dodgerblue' => [30, 144, 255], |
| 65 | 'firebrick' => [178, 34, 34], |
| 66 | 'floralwhite' => [255, 250, 240], |
| 67 | 'forestgreen' => [34, 139, 34], |
| 68 | 'fuchsia' => [255, 0, 255], |
| 69 | 'gainsboro' => [220, 220, 220], |
| 70 | 'ghostwhite' => [248, 248, 255], |
| 71 | 'gold' => [255, 215, 0], |
| 72 | 'goldenrod' => [218, 165, 32], |
| 73 | 'gray' => [128, 128, 128], |
| 74 | 'green' => [0, 128, 0], |
| 75 | 'greenyellow' => [173, 255, 47], |
| 76 | 'grey' => [128, 128, 128], |
| 77 | 'honeydew' => [240, 255, 240], |
| 78 | 'hotpink' => [255, 105, 180], |
| 79 | 'indianred' => [205, 92, 92], |
| 80 | 'indigo' => [75, 0, 130], |
| 81 | 'ivory' => [255, 255, 240], |
| 82 | 'khaki' => [240, 230, 140], |
| 83 | 'lavender' => [230, 230, 250], |
| 84 | 'lavenderblush' => [255, 240, 245], |
| 85 | 'lawngreen' => [124, 252, 0], |
| 86 | 'lemonchiffon' => [255, 250, 205], |
| 87 | 'lightblue' => [173, 216, 230], |
| 88 | 'lightcoral' => [240, 128, 128], |
| 89 | 'lightcyan' => [224, 255, 255], |
| 90 | 'lightgoldenrodyellow' => [250, 250, 210], |
| 91 | 'lightgray' => [211, 211, 211], |
| 92 | 'lightgreen' => [144, 238, 144], |
| 93 | 'lightgrey' => [211, 211, 211], |
| 94 | 'lightpink' => [255, 182, 193], |
| 95 | 'lightsalmon' => [255, 160, 122], |
| 96 | 'lightseagreen' => [32, 178, 170], |
| 97 | 'lightskyblue' => [135, 206, 250], |
| 98 | 'lightslategray' => [119, 136, 153], |
| 99 | 'lightslategrey' => [119, 136, 153], |
| 100 | 'lightsteelblue' => [176, 196, 222], |
| 101 | 'lightyellow' => [255, 255, 224], |
| 102 | 'lime' => [0, 255, 0], |
| 103 | 'limegreen' => [50, 205, 50], |
| 104 | 'linen' => [250, 240, 230], |
| 105 | 'magenta' => [255, 0, 255], |
| 106 | 'maroon' => [128, 0, 0], |
| 107 | 'mediumaquamarine' => [102, 205, 170], |
| 108 | 'mediumblue' => [0, 0, 205], |
| 109 | 'mediumorchid' => [186, 85, 211], |
| 110 | 'mediumpurple' => [147, 112, 219], |
| 111 | 'mediumseagreen' => [60, 179, 113], |
| 112 | 'mediumslateblue' => [123, 104, 238], |
| 113 | 'mediumspringgreen' => [0, 250, 154], |
| 114 | 'mediumturquoise' => [72, 209, 204], |
| 115 | 'mediumvioletred' => [199, 21, 133], |
| 116 | 'midnightblue' => [25, 25, 112], |
| 117 | 'mintcream' => [245, 255, 250], |
| 118 | 'mistyrose' => [255, 228, 225], |
| 119 | 'moccasin' => [255, 228, 181], |
| 120 | 'navajowhite' => [255, 222, 173], |
| 121 | 'navy' => [0, 0, 128], |
| 122 | 'oldlace' => [253, 245, 230], |
| 123 | 'olive' => [128, 128, 0], |
| 124 | 'olivedrab' => [107, 142, 35], |
| 125 | 'orange' => [255, 165, 0], |
| 126 | 'orangered' => [255, 69, 0], |
| 127 | 'orchid' => [218, 112, 214], |
| 128 | 'palegoldenrod' => [238, 232, 170], |
| 129 | 'palegreen' => [152, 251, 152], |
| 130 | 'paleturquoise' => [175, 238, 238], |
| 131 | 'palevioletred' => [219, 112, 147], |
| 132 | 'papayawhip' => [255, 239, 213], |
| 133 | 'peachpuff' => [255, 218, 185], |
| 134 | 'peru' => [205, 133, 63], |
| 135 | 'pink' => [255, 192, 203], |
| 136 | 'plum' => [221, 160, 221], |
| 137 | 'powderblue' => [176, 224, 230], |
| 138 | 'purple' => [128, 0, 128], |
| 139 | 'rebeccapurple' => [102, 51, 153], |
| 140 | 'red' => [255, 0, 0], |
| 141 | 'rosybrown' => [188, 143, 143], |
| 142 | 'royalblue' => [65, 105, 225], |
| 143 | 'saddlebrown' => [139, 69, 19], |
| 144 | 'salmon' => [250, 128, 114], |
| 145 | 'sandybrown' => [244, 164, 96], |
| 146 | 'seagreen' => [46, 139, 87], |
| 147 | 'seashell' => [255, 245, 238], |
| 148 | 'sienna' => [160, 82, 45], |
| 149 | 'silver' => [192, 192, 192], |
| 150 | 'skyblue' => [135, 206, 235], |
| 151 | 'slateblue' => [106, 90, 205], |
| 152 | 'slategray' => [112, 128, 144], |
| 153 | 'slategrey' => [112, 128, 144], |
| 154 | 'snow' => [255, 250, 250], |
| 155 | 'springgreen' => [0, 255, 127], |
| 156 | 'steelblue' => [70, 130, 180], |
| 157 | 'tan' => [210, 180, 140], |
| 158 | 'teal' => [0, 128, 128], |
| 159 | 'thistle' => [216, 191, 216], |
| 160 | 'tomato' => [255, 99, 71], |
| 161 | 'turquoise' => [64, 224, 208], |
| 162 | 'violet' => [238, 130, 238], |
| 163 | 'wheat' => [245, 222, 179], |
| 164 | 'white' => [255, 255, 255], |
| 165 | 'whitesmoke' => [245, 245, 245], |
| 166 | 'yellow' => [255, 255, 0], |
| 167 | 'yellowgreen' => [154, 205, 50], |
| 168 | ]; |
| 169 | |
| 170 | public static function lookup(string $name): ?Color |
| 171 | { |
| 172 | $key = strtolower($name); |
| 173 | if (!isset(self::TABLE[$key])) { |
| 174 | // 'transparent' and 'currentcolor' are special — handled separately. |
| 175 | return null; |
| 176 | } |
| 177 | [$r, $g, $b] = self::TABLE[$key]; |
| 178 | return new Color($r / 255.0, $g / 255.0, $b / 255.0); |
| 179 | } |
| 180 | } |