-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Non-destructive @keyframes
rule transformation.
#3163
Conversation
efbb351
to
404335b
Compare
@sorvell I have a lingering uncertainty about the semantics of custom property value propagation. Since the "selector" within a <style is="custom-style">
:root {
--left: 0px;
}
/* A selector: */
from {
--left: 10px;
}
</style>
<style is="custom-style">
@keyframes foo {
/* Not a selector: */
from {
left: var(--left);
}
}
</style>
<!-- A pathologically named element: -->
<from></from> Ideally, the property would be transformed to WDYT? |
5698e63
to
7ca41d5
Compare
I uncommented some ShadowDOM tests since the relevant Chrome bug has been fixed. Note: I did a lot of cleanup whitespace changes (moving |
b775213
to
3cc2d63
Compare
// 'unit/styling-cross-scope-var.html?dom=shadow', | ||
// 'unit/styling-cross-scope-apply.html?dom=shadow', | ||
'unit/styling-cross-scope-var.html?dom=shadow', | ||
'unit/styling-cross-scope-apply.html?dom=shadow', |
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.
The related Chrome bug was apparently fixed in M46, so I have reactivated these.
3cc2d63
to
d41cf2d
Compare
1d7fd4b
to
3adeade
Compare
rule.keyframesNameRx = new RegExp(rule.keyframesName, 'g'); | ||
rule.transformedKeyframesName = rule.keyframesName + '-' + scopeId; | ||
rule.transformedSelector = rule.transformedSelector || rule.selector; | ||
rule.selector = rule.transformedSelector.replace( |
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.
They scopeId
for a given element may change over time. In this case won't the selector fail to update?
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.
Will fix.
Let's add a test to cover using |
3adeade
to
34614da
Compare
621397c
to
5152f11
Compare
Extra tests added for |
applyKeyframeTransforms: function(rule, keyframeTransforms) { | ||
var input = rule.cssText; | ||
var output = rule.cssText; | ||
|
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.
Let's remove these empty lines. We generally don't space out function contents like this and prefer factoring instead.
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.
Will fix.
@@ -256,15 +307,55 @@ | |||
hostSelector; | |||
var hostRx = new RegExp(this.rx.HOST_PREFIX + rxHostSelector + | |||
this.rx.HOST_SUFFIX); | |||
|
|||
var keyframesRules = element._styles._keyframes; |
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.
Seems like this keyframes specific handling should be factored into a separate function
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.
Will fix.
Previously, the transformer did not disambiguate selectors in `@media` blocks and keyframes in `@keyframes` blocks. Now, the transformer can safely transform `@keyframes` blocks. Before a selector is transformed, if the selector has a parent, it is checked. If the checked parent is a `@keyframes` rule, the selector transformation is skipped. Element-specific `@keyframes` are suffixed with the scoped element name. For example, `@keyframes foo` in an element scoped with `x-el-0` will by transformed to `@keyframes foo-x-el-0`. References to that animation in the element's local styles will be updated as well. Added tests for the new keyframes transformation.
5152f11
to
b9f2482
Compare
!Polymer.StyleUtil.isKeyframesSelector(rule) && | ||
rule.cssText) { | ||
// NOTE: keyframe transforms only scope munge animation names, so it | ||
// is not necessary to apply them in ShadowDOM. |
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 left a reminder to hopefully lessen confusion in the future.
LGTM. Thanks for the contribution! |
…tion Non-destructive `@keyframes` rule transformation.
Previously, the transformer did not disambiguate selectors in
@media
blocks and keyframes in
@keyframes
blocks. Now, the transformer cansafely transform
@keyframes
blocks. Before a selector is transformed,if the selector has a parent, it is checked. If the checked parent is a
@keyframes
rule, the selector transformation is skipped.Element-specific
@keyframes
are suffixed with the scoped element name.For example,
@keyframes foo
in an element scoped withx-el-0
will bytransformed to
@keyframes foo-x-el-0
. References to that animation inthe element's local styles will be updated as well.
Added tests for the new keyframes transformation.
This change also fixes the accidental introduction of a vestigialsemicolon at the end of some generated styles.
@apply
in keyframesscopeId
doesn't get staleFixes #2399