Comments (12)
Hi @BenPayton,
Thanks for the report <3
The shorthand border
property can indeed be specified with the values in any order, so this definitely looks like a bug.
There are some restrictions on the ordering of values in the background
shorthand, but I don't see that your input violates these. I also note that your output includes background-attachment: scroll
when you didn't specify this in the input, which doesn't seem right either.
We'll need to investigate this further. If you are able to delve into the code to find out why what's going wrong is, that would be greatly appreciated, but no worries if not.
from php-css-parser.
Thanks. A quick look at RuleSet\DeclarationBlock\expandBackgroundShorthand() shows it sets an array of default properties in $aBgProperties
. It appears that background-attachment: scroll
and background-color: transparent
end up as rules unless it specifically finds different values in the original shorthand declaration. Since my example has no background-attachment
value, it gets scroll
by default. As for background-color
, it looks like it specifically looks for instances of Color
and I'm guessing a color name isn't being recognized as such.
from php-css-parser.
I think if we were to recognize named colors and parse them into Color
, it would allow us to uniformly fix the problems in both expansions.
from php-css-parser.
distinguishing a border-style from a colour, which would need a list of named values of one or other to separate them (there are far fewer border style constants, so I'd use those for the sieve).
I think border-style has a higher chance of a new value being added to the spec than a new named color being introduced. The last named color added was rebeccapurple in honor of Rebecca Meyer and that was already in violation of the long-standing rule against adding new named colors.
from php-css-parser.
Your analysis makes sense.
A quick look at RuleSet\DeclarationBlock\expandBackgroundShorthand() shows it sets an array of default properties in
$aBgProperties
. It appears thatbackground-attachment: scroll
andbackground-color: transparent
end up as rules unless it specifically finds different values in the original shorthand declaration. Since my example has nobackground-attachment
value, it getsscroll
by default.
On reflection, I think that is correct behaviour. I often forget that the shorthand syntax replaces all longhand properties, including any that are not provided (with default values being used for those missing, and no 'cascade' for them). Apologies.
As for
background-color
, it looks like it specifically looks for instances ofColor
and I'm guessing a color name isn't being recognized as such.
Yes. Color
doesn't cover named colours, only rgb(a)
, hsl
, etc., and hex values. Named colours are retained as string
.
Looking at expandBackgroundShorthand
, it seems there is a missing else
which would cover the case of a named colour (assuming there's nothing else it could be).
The border
issue is similar, but it looks like in expandBorderShorthand
there needs to be a means of distinguishing a border-style
from a colour, which would need a list of named values of one or other to separate them (there are far fewer border style constants, so I'd use those for the sieve).
Longer term, we are considering introducing classes to represent specific types of named values (e.g. #353), instead of using string
, but that's some way off.
In the meantime, we are backporting bugfixes to an 8.5.x branch.
Would you be willing to have a crack at a couple of pull requests (PRs) to fix these two problems? (I think the background
and border
issues should be tackled seperately, for now.) We'd also want tests added (that fail before and pass with the code change). No worries if not (I see you only just created a GitHub account), but it would speed things up if you are able to contribute.
Thanks.
from php-css-parser.
Thank you for the response. Agreed on the default background rules, that should be correct behavior. It makes sense both expandBackgroundShorthand
and expandBorderShorthand
simply need checks for named colors. By replacing color names with hex values in my own project before running expandShorthands
everything appears to work as expected.
I don't think I will have the time commitment to contribute unfortunately, so I will leave it to someone more capable. Thanks again for your help.
from php-css-parser.
IMHO expandShorthands
isn’t functionality expected in a parser and we should consider removing it. It sounds like something a third-party could maintain as a separate lib.
expandShorthands
needs to be updated whenever the specs change. For example, we don’t recognize (or reset) background-origin
nor background-clip
or background-size
, which can also be specified in the shorthand (but that wasn’t the case when the functionality was first implemented).
Similarly, I am not sure whether we support expanding background
shorthands correctly if more than one background was specified…
from php-css-parser.
IMHO
expandShorthands
isn’t functionality expected in a parser and we should consider removing it. It sounds like something a third-party could maintain as a separate lib.
I agree. I've just created #512 for this.
from php-css-parser.
So I'd suggest closing this as "sorry, won't fix anymore". Would you be okay with this, @sabberworm @JakeQZ ?
from php-css-parser.
So I'd suggest closing this as "sorry, won't fix anymore". Would you be okay with this, @sabberworm @JakeQZ ?
Fine by me. Though I would still like to pursue support for parsing named colors as Color
instances.
from php-css-parser.
Though I would still like to pursue support for parsing named colors as
Color
instances.
I agree and have created #514 for this.
from php-css-parser.
So I'd suggest closing this as "sorry, won't fix anymore". Would you be okay with this, @sabberworm @JakeQZ ?
Fine by me. Though I would still like to pursue support for parsing named colors as
Color
instances.
Agree with all this. Though it would be good for the existing (incomplete) implementation of expanding shorthands to be made clearly available for anyone who wants to use it as a basis for providing that functionality in a separate package (or just in their own project) - I've commented to that effect in #512.
from php-css-parser.
Related Issues (20)
- Add contrubutor guidelines
- Provide an interface for `RuleSet|CSSList|Import|Charset` HOT 1
- Provide an interface for `CSSList|Rule|RuleSet|Value`
- Provide an interface for `AtRuleBlockList|KeyFrame|Charset|CSSNamespace|Import|AtRuleSet|DeclarationBlock`
- Provide an interface for `AtRuleBlockList|KeyFrame|Charset|CSSNamespace|Import|AtRuleSet` HOT 1
- Provide an interface for `CSSList|RuleSet`
- Provide an interface for `RuleValueList|CSSFunction|CSSString|LineName|Size|URL`
- Link the relevant specs/docs from the README
- Set up the infrastructure for class aliases HOT 1
- Fixer does not want EOL at end of empty class/interface HOT 1
- Drop `expandShorthands`/`createShorthands`/`create*Shorthand`/`expand*Shorthand`
- Deprecate/deactivate `expandShorthands`/`createShorthands`/`create*Shorthand`/`expand*Shorthand` HOT 1
- Model named colors as `Color` instances instead of strings HOT 3
- Automate creation of the UML diagram
- Update the `gh-pages` branch with the API documentation whenever we push to `main`
- Add support for CSS Nesting
- Use the development PHP INI on CI
- Switch the code covera to Coveralls
- Add a GitHub Action that comments on pull requests if tests are missing
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-css-parser.