-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Style Engine: Add a WP_Style_Engine_Processor object #42463
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
|
Size Change: 0 B Total Size: 1.26 MB ℹ️ View Unchanged
|
andrewserong
left a comment
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.
I like the direction this is taking, too! Just added a small comment to discuss naming.
I was also wondering if there are performance considerations for us to consider with doing an MD5 check on each declaration? For example, if we're json_encodeing to a string, can we do a string comparison on the JSON instead of the additional step of using an MD5 check, or is there a benefit from the extra step? PHP performance is definitely not my strong suit, so I wasn't sure on balance which is faster (comparing potentially really long strings, or doing an MD5 check first, and then comparing short strings) 🤔
This is a great point, and it's something I've had in the back of my head as we add more overhead. I've added a task to the project board to integrate some performance/speed tests. |
|
I added some tests, hope you don't mind! I like to see the output under various conditions. It's looking great! Especially the combine/merging functionality. |
fe6e002 to
5baaf51
Compare
Good point. I removed the extra |
|
I believe this is now ready for a final review... Once this gets in we can start refactoring global-styles and block-supports to use the Style Engine 🎉 |
andrewserong
left a comment
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.
Following discussions in other tickets for the Style Engine, this PR adds a
RendererProcessorto the style engine.Usage:
A complete example that can be used to test this:
With the above code, the
$cssat the end is.wp-block-button a:hover {color: var(--block-button-link-hover-color); background-color: #000;}.foo,.bar {color: red; font-size: 1em;}Please note the following in the final CSS:
.wp-block-button a:hoverselector we're addingbackground-color: black, and thenbackground-color: #000. In the final CSS the latter overrides the former so there are no duplicate entries for CSS properties under the same selector. This was part of previous PRs so not specifically a part of the Renderer, but worth highlighting since it is a big improvement over what we have now with strings concatenations..fooand.bar, but they have the same declarations so in the final CSS they get combined to.foo,.bar(reusing the concept from Add an inline styles handler #41896)