| 1: | <?php | 
| 2: |  | 
| 3: |  | 
| 4: |  | 
| 5: |  | 
| 6: |  | 
| 7: |  | 
| 8: |  | 
| 9: |  | 
| 10: |  | 
| 11: |  | 
| 12: |  | 
| 13: |  | 
| 14: |  | 
| 15: |  | 
| 16: |  | 
| 17: |  | 
| 18: |  | 
| 19: |  | 
| 20: |  | 
| 21: |  | 
| 22: |  | 
| 23: |  | 
| 24: |  | 
| 25: |  | 
| 26: | namespace Kint\Renderer\Rich; | 
| 27: |  | 
| 28: | use Kint\Object\BasicObject; | 
| 29: | use Kint\Object\Representation\ColorRepresentation; | 
| 30: | use Kint\Object\Representation\Representation; | 
| 31: |  | 
| 32: | class ColorPlugin extends Plugin implements TabPluginInterface, ObjectPluginInterface | 
| 33: | { | 
| 34: | public function renderObject(BasicObject $o) | 
| 35: | { | 
| 36: | $r = $o->getRepresentation('color'); | 
| 37: |  | 
| 38: | if (!$r instanceof ColorRepresentation) { | 
| 39: | return; | 
| 40: | } | 
| 41: |  | 
| 42: | $children = $this->renderer->renderChildren($o); | 
| 43: |  | 
| 44: | $header = $this->renderer->renderHeader($o); | 
| 45: | $header .= '<div class="kint-color-preview"><div style="background:'; | 
| 46: | $header .= $r->getColor(ColorRepresentation::COLOR_RGBA); | 
| 47: | $header .= '"></div></div>'; | 
| 48: |  | 
| 49: | $header = $this->renderer->renderHeaderWrapper($o, (bool) \strlen($children), $header); | 
| 50: |  | 
| 51: | return '<dl>'.$header.$children.'</dl>'; | 
| 52: | } | 
| 53: |  | 
| 54: | public function renderTab(Representation $r) | 
| 55: | { | 
| 56: | if (!$r instanceof ColorRepresentation) { | 
| 57: | return; | 
| 58: | } | 
| 59: |  | 
| 60: | $out = ''; | 
| 61: |  | 
| 62: | if ($color = $r->getColor(ColorRepresentation::COLOR_NAME)) { | 
| 63: | $out .= '<dfn>'.$color."</dfn>\n"; | 
| 64: | } | 
| 65: | if ($color = $r->getColor(ColorRepresentation::COLOR_HEX_3)) { | 
| 66: | $out .= '<dfn>'.$color."</dfn>\n"; | 
| 67: | } | 
| 68: | if ($color = $r->getColor(ColorRepresentation::COLOR_HEX_6)) { | 
| 69: | $out .= '<dfn>'.$color."</dfn>\n"; | 
| 70: | } | 
| 71: |  | 
| 72: | if ($r->hasAlpha()) { | 
| 73: | if ($color = $r->getColor(ColorRepresentation::COLOR_HEX_4)) { | 
| 74: | $out .= '<dfn>'.$color."</dfn>\n"; | 
| 75: | } | 
| 76: | if ($color = $r->getColor(ColorRepresentation::COLOR_HEX_8)) { | 
| 77: | $out .= '<dfn>'.$color."</dfn>\n"; | 
| 78: | } | 
| 79: | if ($color = $r->getColor(ColorRepresentation::COLOR_RGBA)) { | 
| 80: | $out .= '<dfn>'.$color."</dfn>\n"; | 
| 81: | } | 
| 82: | if ($color = $r->getColor(ColorRepresentation::COLOR_HSLA)) { | 
| 83: | $out .= '<dfn>'.$color."</dfn>\n"; | 
| 84: | } | 
| 85: | } else { | 
| 86: | if ($color = $r->getColor(ColorRepresentation::COLOR_RGB)) { | 
| 87: | $out .= '<dfn>'.$color."</dfn>\n"; | 
| 88: | } | 
| 89: | if ($color = $r->getColor(ColorRepresentation::COLOR_HSL)) { | 
| 90: | $out .= '<dfn>'.$color."</dfn>\n"; | 
| 91: | } | 
| 92: | } | 
| 93: |  | 
| 94: | if (!\strlen($out)) { | 
| 95: | return false; | 
| 96: | } | 
| 97: |  | 
| 98: | return '<pre>'.$out.'</pre>'; | 
| 99: | } | 
| 100: | } | 
| 101: |  |