diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..f7046f6a --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +/.buildpath +/.cache +/.metadata +/.project +/.settings +atlassian* +/nbproject +/sitemap +/sitemap.xml +/.idea +/.gitattributes +/.grunt \ No newline at end of file diff --git a/composer.json b/composer.json index b970db75..00064114 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "sabberworm/php-css-parser", + "name": "studioraz/php-css-parser", "type": "library", "description": "Parser for CSS Files written in PHP", "keywords": ["parser", "css", "stylesheet"], diff --git a/lib/Sabberworm/CSS/Parser.php b/lib/Sabberworm/CSS/Parser.php index 409b796d..e9e2ace3 100644 --- a/lib/Sabberworm/CSS/Parser.php +++ b/lib/Sabberworm/CSS/Parser.php @@ -200,6 +200,27 @@ private function parseAtRule() { } } + private function parseCalcHack(){ + + $sResult = null; + $sContent = null; + + while (true) { + $sContent = $this->parseCharacter(false); + + if ($sContent == ';') { + $this->iCurrentPosition--; + break; + } + if ($sContent === null) { + throw new SourceException("Non-well-formed quoted string {$this->peek(3)}", $this->iLineNo); + } + $sResult .= $sContent; + } + + return $sResult; + } + private function parseIdentifier($bAllowFunctions = true, $bIgnoreCase = true) { $sResult = $this->parseCharacter(true); if ($sResult === null) { @@ -438,6 +459,8 @@ private function parsePrimitiveValue() { $oValue = $this->parseStringValue(); } else if ($this->comes("progid:") && $this->oParserSettings->bLenientParsing) { $oValue = $this->parseMicrosoftFilter(); + } else if ($this->comes("calc")) { + $oValue = $this->parseCalcHack(); } else { $oValue = $this->parseIdentifier(true, false); } @@ -476,9 +499,17 @@ private function parseColorValue() { if ($this->comes('#')) { $this->consume('#'); $sValue = $this->parseIdentifier(false); + + if ($this->strlen($sValue) === 3) { $sValue = $sValue[0] . $sValue[0] . $sValue[1] . $sValue[1] . $sValue[2] . $sValue[2]; } + + if ($this->isColorName($sValue)) { + $sValue = $this->resolveColor($sValue); + } + + $aColor = array('r' => new Size(intval($sValue[0] . $sValue[1], 16), null, true, $this->iLineNo), 'g' => new Size(intval($sValue[2] . $sValue[3], 16), null, true, $this->iLineNo), 'b' => new Size(intval($sValue[4] . $sValue[5], 16), null, true, $this->iLineNo)); } else { $sColorMode = $this->parseIdentifier(false); @@ -724,4 +755,173 @@ private function strpos($sString, $sNeedle, $iOffset) { } } + private function getColorNameList() { + + return [ + 'black' => '000000', + 'navy' => '000080', + 'darkblue' => '00008b', + 'mediumblue' => '0000cd', + 'blue' => '0000ff', + 'darkgreen' => '006400', + 'green' => '008000', + 'teal' => '008080', + 'darkcyan' => '008b8b', + 'deepskyblue' => '00bfff', + 'darkturquoise' => '00ced1', + 'mediumspringgreen' => '00fa9a', + 'lime' => '00ff00', + 'springgreen' => '00ff7f', + 'aqua' => '00ffff', + 'cyan' => '00ffff', + 'midnightblue' => '191970', + 'dodgerblue' => '1e90ff', + 'lightseagreen' => '20b2aa', + 'forestgreen' => '228b22', + 'seagreen' => '2e8b57', + 'darkslategray' => '2f4f4f', + 'darkslategrey' => '2f4f4f', + 'limegreen' => '32cd32', + 'mediumseagreen' => '3cb371', + 'turquoise' => '40e0d0', + 'royalblue' => '4169e1', + 'steelblue' => '4682b4', + 'darkslateblue' => '483d8b', + 'mediumturquoise' => '48d1cc', + 'indigo ' => '4b0082', + 'darkolivegreen' => '556b2f', + 'cadetblue' => '5f9ea0', + 'cornflowerblue' => '6495ed', + 'rebeccapurple' => '663399', + 'mediumaquamarine' => '66cdaa', + 'dimgray' => '696969', + 'dimgrey' => '696969', + 'slateblue' => '6a5acd', + 'olivedrab' => '6b8e23', + 'slategray' => '708090', + 'slategrey' => '708090', + 'lightslategray' => '778899', + 'lightslategrey' => '778899', + 'mediumslateblue' => '7b68ee', + 'lawngreen' => '7cfc00', + 'chartreuse' => '7fff00', + 'aquamarine' => '7fffd4', + 'maroon' => '800000', + 'purple' => '800080', + 'olive' => '808000', + 'gray' => '808080', + 'grey' => '808080', + 'skyblue' => '87ceeb', + 'lightskyblue' => '87cefa', + 'blueviolet' => '8a2be2', + 'darkred' => '8b0000', + 'darkmagenta' => '8b008b', + 'saddlebrown' => '8b4513', + 'darkseagreen' => '8fbc8f', + 'lightgreen' => '90ee90', + 'mediumpurple' => '9370db', + 'darkviolet' => '9400d3', + 'palegreen' => '98fb98', + 'darkorchid' => '9932cc', + 'yellowgreen' => '9acd32', + 'sienna' => 'a0522d', + 'brown' => 'a52a2a', + 'darkgray' => 'a9a9a9', + 'darkgrey' => 'a9a9a9', + 'lightblue' => 'add8e6', + 'greenyellow' => 'adff2f', + 'paleturquoise' => 'afeeee', + 'lightsteelblue' => 'b0c4de', + 'powderblue' => 'b0e0e6', + 'firebrick' => 'b22222', + 'darkgoldenrod' => 'b8860b', + 'mediumorchid' => 'ba55d3', + 'rosybrown' => 'bc8f8f', + 'darkkhaki' => 'bdb76b', + 'silver' => 'c0c0c0', + 'mediumvioletred' => 'c71585', + 'indianred ' => 'cd5c5c', + 'peru' => 'cd853f', + 'chocolate' => 'd2691e', + 'tan' => 'd2b48c', + 'lightgray' => 'd3d3d3', + 'lightgrey' => 'd3d3d3', + 'thistle' => 'd8bfd8', + 'orchid' => 'da70d6', + 'goldenrod' => 'daa520', + 'palevioletred' => 'db7093', + 'crimson' => 'dc143c', + 'gainsboro' => 'dcdcdc', + 'plum' => 'dda0dd', + 'burlywood' => 'deb887', + 'lightcyan' => 'e0ffff', + 'lavender' => 'e6e6fa', + 'darksalmon' => 'e9967a', + 'violet' => 'ee82ee', + 'palegoldenrod' => 'eee8aa', + 'lightcoral' => 'f08080', + 'khaki' => 'f0e68c', + 'aliceblue' => 'f0f8ff', + 'honeydew' => 'f0fff0', + 'azure' => 'f0ffff', + 'sandybrown' => 'f4a460', + 'wheat' => 'f5deb3', + 'beige' => 'f5f5dc', + 'whitesmoke' => 'f5f5f5', + 'mintcream' => 'f5fffa', + 'ghostwhite' => 'f8f8ff', + 'salmon' => 'fa8072', + 'antiquewhite' => 'faebd7', + 'linen' => 'faf0e6', + 'lightgoldenrodyellow' => 'fafad2', + 'oldlace' => 'fdf5e6', + 'red' => 'ff0000', + 'fuchsia' => 'ff00ff', + 'magenta' => 'ff00ff', + 'deeppink' => 'ff1493', + 'orangered' => 'ff4500', + 'tomato' => 'ff6347', + 'hotpink' => 'ff69b4', + 'coral' => 'ff7f50', + 'darkorange' => 'ff8c00', + 'lightsalmon' => 'ffa07a', + 'orange' => 'ffa500', + 'lightpink' => 'ffb6c1', + 'pink' => 'ffc0cb', + 'gold' => 'ffd700', + 'peachpuff' => 'ffdab9', + 'navajowhite' => 'ffdead', + 'moccasin' => 'ffe4b5', + 'bisque' => 'ffe4c4', + 'mistyrose' => 'ffe4e1', + 'blanchedalmond' => 'ffebcd', + 'papayawhip' => 'ffefd5', + 'lavenderblush' => 'fff0f5', + 'seashell' => 'fff5ee', + 'cornsilk' => 'fff8dc', + 'lemonchiffon' => 'fffacd', + 'floralwhite' => 'fffaf0', + 'snow' => 'fffafa', + 'yellow' => 'ffff00', + 'lightyellow' => 'ffffe0', + 'ivory' => 'fffff0', + 'white' => 'ffffff' + ]; + + } + + private function isColorName($color) { + + $colors = $this->getColorNameList(); + return array_key_exists(strtolower($color), $colors); + + } + + private function resolveColor($color) { + + $colors = $this->getColorNameList(); + return $colors[strtolower($color)]; + + } + }