Skip to content

Commit

Permalink
Port keyframe name fix from ShadyCSS (#5038)
Browse files Browse the repository at this point in the history
* Port keyframe name fix from ShadyCSS

Fixes #3475

* animate border instead

* Port Edge 16 test fixes from 2.x
  • Loading branch information
dfreedm authored Jan 24, 2018
1 parent 7b6ff53 commit 9721433
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/lib/style-properties.html
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,10 @@
// Transforms `@keyframes` names to be unique for the current host.
// Example: @keyframes foo-anim -> @keyframes foo-anim-x-foo-0
_scopeKeyframes: function(rule, scopeId) {
rule.keyframesNameRx = new RegExp(rule.keyframesName, 'g');
// Animation names are of the form [\w-], so ensure that the name regex does not partially apply
// to similarly named keyframe names by checking for a word boundary at the beginning and
// a non-word boundary or `-` at the end.
rule.keyframesNameRx = new RegExp('\\b' + rule.keyframesName + '(?!\\B|-)', 'g');
rule.transformedKeyframesName = rule.keyframesName + '-' + scopeId;
rule.transformedSelector = rule.transformedSelector || rule.selector;
rule.selector = rule.transformedSelector.replace(
Expand Down
5 changes: 5 additions & 0 deletions test/unit/custom-style.html
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,11 @@
assertComputed(el, '11px', 'right');
assertComputed(el, '12px', 'top');

// Avoid Edge 16 bug with CSS Custom Properties and Fonts.
if (navigator.userAgent.match('Edge/16') && Polymer.Settings.useNativeCSSProperties) {
return;
}

// Because FireFox and Chrome parse font-family differently...
var computed = getComputedStyle(el);
assert.equal(computed['font-family'].replace(/['"]+/g, ''), 'Varela font');
Expand Down
5 changes: 5 additions & 0 deletions test/unit/styling-cross-scope-apply.html
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,11 @@
})

test('mixins apply to @keyframe rules', function(done) {
if (navigator.userAgent.match('Edge/16') && Polymer.Settings.useNativeCSSProperties) {
// skip test due to missing variable support in keyframes
// https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/12084341/
this.skip();
}
var xKeyframes1 = styled.$.keyframes1;
var xKeyframes2 = styled.$.keyframes2;
var completed = 0;
Expand Down
70 changes: 70 additions & 0 deletions test/unit/styling-cross-scope-var.html
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,57 @@
</script>
</dom-module>

<dom-module id="prefix-keyframes">
<template>
<style>
:host {
--time: 0.1s;
border: 0px solid rgb(0, 0, 0);
display: block;
/* Prefix required by Safari <= 8 */
-webkit-animation-duration: var(--time);
-webkit-animation-fill-mode: forwards;
animation-duration: var(--time);
animation-fill-mode: forwards;
}

:host([animated]) {
/* Prefix required by Safari <= 8 */
-webkit-animation-name: border-width;
animation-name: border-width;
}

/* Prefix required by Safari <= 8 */
@-webkit-keyframes border {}
@-webkit-keyframes border-width {
to {
border-top-width: 10px;
}
}
@keyframes border {}
@keyframes border-width {
to {
border-top-width: 10px;
}
}
</style>
</template>
<script>
HTMLImports.whenReady(function() {
Polymer({
is: 'prefix-keyframes',
properties: {
animated: {
type: Boolean,
value: false,
reflectToAttribute: true
}
}
});
});
</script>
</dom-module>

<dom-module id="x-scope">
<template>
<style>
Expand Down Expand Up @@ -509,6 +560,7 @@
<div id="me">x-scope</div>
<x-keyframes id="keyframes"></x-keyframes>
<x-keyframes id="keyframes2"></x-keyframes>
<prefix-keyframes id="prefix"></prefix-keyframes>
<x-child-scope id="child"></x-child-scope>
<x-child-scope id="child2"></x-child-scope>
<x-overrides id="overrides1a"></x-overrides>
Expand Down Expand Up @@ -939,6 +991,24 @@
xKeyframes.animated = true;
});

test('keyframes are transformed correctly', function(done) {
var xKeyframes = styled.$.prefix;
var onAnimationEnd = function() {
assertComputed(xKeyframes, '10px');

xKeyframes.removeEventListener('animationend', onAnimationEnd);
xKeyframes.removeEventListener('webkitAnimationEnd', onAnimationEnd);
xKeyframes.animated = false;
done();
};

assertComputed(xKeyframes, '0px');
xKeyframes.addEventListener('animationend', onAnimationEnd);
xKeyframes.addEventListener('webkitAnimationEnd', onAnimationEnd);

xKeyframes.animated = true;
})

test('mutiple elements in document', function() {
var e$ = document.querySelectorAll('simple-element');
assertComputed(e$[0].$.inner, '10px');
Expand Down
5 changes: 5 additions & 0 deletions test/unit/styling-scoped.html
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@
});

test('keyframes change scope', function(done) {
if (navigator.userAgent.match('Edge/16') && Polymer.Settings.useNativeCSSProperties) {
// skip test due to missing variable support in keyframes
// https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/12084341/
this.skip();
}
var xKeyframes = styled.$.keyframes;

var onAnimationEnd = function() {
Expand Down

0 comments on commit 9721433

Please sign in to comment.