Skip to content

Commit d59d2f8

Browse files
committed
Alteração para fazer o CALC do CSS3 funcionar
Gambi furiosa mesmo
1 parent ccbd4ae commit d59d2f8

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

lib/Sabberworm/CSS/Parser.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private function parseList(CSSList $oList, $bIsRoot = false) {
113113
throw new SourceException("Unexpected end of document", $this->iLineNo);
114114
}
115115
}
116-
116+
117117
private function parseListItem(CSSList $oList, $bIsRoot = false) {
118118
if ($this->comes('@')) {
119119
$oAtRule = $this->parseAtRule();
@@ -286,12 +286,14 @@ private function parseCharacter($bIsForIdentifier) {
286286
}
287287
if ($bIsForIdentifier) {
288288
$peek = ord($this->peek());
289-
// Ranges: a-z A-Z 0-9 - _
290-
if (($peek >= 97 && $peek <= 122) ||
291-
($peek >= 65 && $peek <= 90) ||
292-
($peek >= 48 && $peek <= 57) ||
293-
($peek === 45) ||
294-
($peek === 95) ||
289+
if (($peek >= 97 && $peek <= 122) || // a-z
290+
($peek >= 65 && $peek <= 90) || // A-Z
291+
($peek >= 48 && $peek <= 57) || // 0-9
292+
($peek === 42) || // *
293+
($peek === 43) || // +
294+
($peek === 45) || // -
295+
($peek === 47) || // /
296+
($peek === 95) || // _
295297
($peek > 0xa1)) {
296298
return $this->consume(1);
297299
}
@@ -428,7 +430,7 @@ private static function listDelimiterForRule($sRule) {
428430
private function parsePrimitiveValue() {
429431
$oValue = null;
430432
$this->consumeWhiteSpace();
431-
if (is_numeric($this->peek()) || ($this->comes('-.') && is_numeric($this->peek(1, 2))) || (($this->comes('-') || $this->comes('.')) && is_numeric($this->peek(1, 1)))) {
433+
if (is_numeric($this->peek()) || ($this->comes('-.') && is_numeric($this->peek(1, 2))) || (($this->comes('-') || $this->comes('+') || $this->comes('*') || $this->comes('/') || $this->comes('.')) && is_numeric($this->peek(1, 1)))) {
432434
$oValue = $this->parseNumericValue();
433435
} else if ($this->comes('#') || $this->comes('rgb', true) || $this->comes('hsl', true)) {
434436
$oValue = $this->parseColorValue();
@@ -446,10 +448,14 @@ private function parsePrimitiveValue() {
446448
}
447449

448450
private function parseNumericValue($bForColor = false) {
451+
$sOperator = '';
449452
$sSize = '';
450-
if ($this->comes('-')) {
451-
$sSize .= $this->consume('-');
452-
}
453+
$sOperatorPossibilities = ['+', '-', '*', '/'];
454+
foreach ($sOperatorPossibilities as $sOperatorPossibility) {
455+
if ($this->comes($sOperatorPossibility)) {
456+
$sOperator = $this->consume($sOperatorPossibility);
457+
}
458+
}
453459
while (is_numeric($this->peek()) || $this->comes('.')) {
454460
if ($this->comes('.')) {
455461
$sSize .= $this->consume('.');
@@ -468,7 +474,7 @@ private function parseNumericValue($bForColor = false) {
468474
}
469475
}
470476
}
471-
return new Size(floatval($sSize), $sUnit, $bForColor, $this->iLineNo);
477+
return new Size($sOperator . floatval($sSize), $sUnit, $bForColor, $this->iLineNo);
472478
}
473479

474480
private function parseColorValue() {

lib/Sabberworm/CSS/Value/Size.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Size extends PrimitiveValue {
1414

1515
public function __construct($fSize, $sUnit = null, $bIsColorComponent = false, $iLineNo = 0) {
1616
parent::__construct($iLineNo);
17-
$this->fSize = floatval($fSize);
17+
$this->fSize = $fSize;
1818
$this->sUnit = $sUnit;
1919
$this->bIsColorComponent = $bIsColorComponent;
2020
}
@@ -28,7 +28,7 @@ public function getUnit() {
2828
}
2929

3030
public function setSize($fSize) {
31-
$this->fSize = floatval($fSize);
31+
$this->fSize = $fSize;
3232
}
3333

3434
public function getSize() {

0 commit comments

Comments
 (0)