Skip to content

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

Merged
merged 6 commits into from
Jul 2, 2018
Merged

Conversation

raxbg
Copy link
Contributor

@raxbg raxbg commented Jun 28, 2018

Fixes issue #79

Copy link
Collaborator

@sabberworm sabberworm left a 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?

@@ -520,6 +524,17 @@ private function parseURLValue() {
return $oResult;
}

private function parseCalcValue() {
$func = $this->comes('calc', true) ? 'calc' : '-webkit-calc';
Copy link
Collaborator

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.

@@ -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)) {
Copy link
Collaborator

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?

Copy link
Contributor Author

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

$this->consume($func);
$this->consumeWhiteSpace();
$this->consume('(');
$aArguments = $this->parseValue(array('+', '-', '*', '/', ' '), '\Sabberworm\CSS\Value\CalcRuleValueList');
Copy link
Collaborator

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).

Copy link
Collaborator

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)?

Copy link
Contributor Author

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 :)

@@ -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 = ' ';
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants