-
Notifications
You must be signed in to change notification settings - Fork 144
Add support for CSS3 calc #128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for your work!
Could you take a look at the issues I raised?
lib/Sabberworm/CSS/Parser.php
Outdated
@@ -520,6 +524,17 @@ private function parseURLValue() { | |||
return $oResult; | |||
} | |||
|
|||
private function parseCalcValue() { | |||
$func = $this->comes('calc', true) ? 'calc' : '-webkit-calc'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use $func = trim(consumeUntil('('))
to streamline this.
lib/Sabberworm/CSS/Parser.php
Outdated
@@ -434,6 +436,8 @@ private function parsePrimitiveValue() { | |||
$oValue = $this->parseColorValue(); | |||
} else if ($this->comes('url', true)) { | |||
$oValue = $this->parseURLValue(); | |||
} else if ($this->comes('calc', true) || $this->comes('-webkit-calc', true)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Support -moz-calc
as well. Also, is there an -o-calc
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done for -moz-calc
, but -o-calc
does not seem to exist https://www.w3schools.com/cssref/func_calc.asp
lib/Sabberworm/CSS/Parser.php
Outdated
$this->consume($func); | ||
$this->consumeWhiteSpace(); | ||
$this->consume('('); | ||
$aArguments = $this->parseValue(array('+', '-', '*', '/', ' '), '\Sabberworm\CSS\Value\CalcRuleValueList'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parsing the arguments using parseValue
probably means an expression like calc(50% -8px)
would be treated as calc(50% - 8px)
, not as an error (like it should).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I right in assuming that this does not support parenthesized subexpressions like calc( ( 100px / 2) / 2)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct for both. Should be fixed now :)
lib/Sabberworm/CSS/OutputFormat.php
Outdated
@@ -41,6 +41,10 @@ class OutputFormat { | |||
// This is what’s printed after the comma of value lists | |||
public $sSpaceBeforeListArgumentSeparator = ''; | |||
public $sSpaceAfterListArgumentSeparator = ''; | |||
|
|||
// This is what’s printed after the operators in a calc function | |||
public $sSpaceBeforeCalcListArgumentSeparator = ' '; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the spaces around -
and +
operators are mandatory, their output should not be affected by OutputFormat
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I removed this entirely in the last commit.
Fixes issue #79