Skip to content
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

Merged
merged 1 commit into from
Feb 4, 2016

Conversation

cdata
Copy link
Contributor

@cdata cdata commented Dec 5, 2015

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.

This change also fixes the accidental introduction of a vestigial
semicolon at the end of some generated styles.

Fixes #2399

@cdata
Copy link
Contributor Author

cdata commented Dec 5, 2015

@sorvell I have a lingering uncertainty about the semantics of custom property value propagation. Since the "selector" within a @keyframes block isn't actually a selector, it seems that it may be necessary to inform the style system that the effective scope is not what it typically expects. For an example of what I mean, consider the following arrangement:

<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 left: 0px. However, it may be the case that the value will end up being 10px due to selector matching.

WDYT?

@cdata cdata force-pushed the allow-keyframe-style-transformation branch 4 times, most recently from 5698e63 to 7ca41d5 Compare December 9, 2015 22:39
@cdata
Copy link
Contributor Author

cdata commented Dec 9, 2015

I uncommented some ShadowDOM tests since the relevant Chrome bug has been fixed.

Note: I did a lot of cleanup whitespace changes (moving <style> tags inside of templates), so viewing the diff with ?w=1 in the query params is recommended.

@cdata cdata force-pushed the allow-keyframe-style-transformation branch from b775213 to 3cc2d63 Compare December 10, 2015 01:39
// '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',
Copy link
Contributor Author

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.

@cdata cdata force-pushed the allow-keyframe-style-transformation branch from 3cc2d63 to d41cf2d Compare December 10, 2015 02:06
@cdata cdata force-pushed the allow-keyframe-style-transformation branch 2 times, most recently from 1d7fd4b to 3adeade Compare January 5, 2016 22:40
rule.keyframesNameRx = new RegExp(rule.keyframesName, 'g');
rule.transformedKeyframesName = rule.keyframesName + '-' + scopeId;
rule.transformedSelector = rule.transformedSelector || rule.selector;
rule.selector = rule.transformedSelector.replace(
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix.

@sorvell
Copy link
Contributor

sorvell commented Jan 8, 2016

Let's add a test to cover using @apply in keyframes. wdyt?

@cdata cdata force-pushed the allow-keyframe-style-transformation branch from 3adeade to 34614da Compare January 19, 2016 19:26
@cdata cdata force-pushed the allow-keyframe-style-transformation branch 4 times, most recently from 621397c to 5152f11 Compare February 2, 2016 18:55
@cdata
Copy link
Contributor Author

cdata commented Feb 2, 2016

Extra tests added for @mixin and style-scope changing. PTAL!

@kevinpschaaf kevinpschaaf added the p0 label Feb 4, 2016
applyKeyframeTransforms: function(rule, keyframeTransforms) {
var input = rule.cssText;
var output = rule.cssText;

Copy link
Contributor

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.

Copy link
Contributor Author

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;
Copy link
Contributor

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

Copy link
Contributor Author

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.
@cdata cdata force-pushed the allow-keyframe-style-transformation branch from 5152f11 to b9f2482 Compare February 4, 2016 22:52
!Polymer.StyleUtil.isKeyframesSelector(rule) &&
rule.cssText) {
// NOTE: keyframe transforms only scope munge animation names, so it
// is not necessary to apply them in ShadowDOM.
Copy link
Contributor Author

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.

@sorvell
Copy link
Contributor

sorvell commented Feb 4, 2016

LGTM. Thanks for the contribution!

sorvell pushed a commit that referenced this pull request Feb 4, 2016
…tion

Non-destructive `@keyframes` rule transformation.
@sorvell sorvell merged commit 9968266 into master Feb 4, 2016
@sorvell sorvell deleted the allow-keyframe-style-transformation branch February 4, 2016 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom properties cannot be set in @keyframe rules
4 participants