You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When writing animations I don't want @keyframes rules appear in final .css files if they are not used (because if we support lots of animations that will be great amount of code). So I put a @keyframes rule inside a mixin, like this:
.play() {
@keyframes play {
from {
margin-top: 0;
}
to {
margin-top: 100px;
}
}
}
But if I call that mixin for several times, the @keyframes rule will also be repeated.
.test {
.play();
}
.test2 {
.play();
}
will output (in global scope):
@keyframes play {from{margin-top:0;}to{margin-top:100px;}}@keyframes play {from{margin-top:0;}to{margin-top:100px;}}
Is there a way to avoid this? (I'm using lessc 1.4.2)
However, instead of grouping it's more of a "collapse" situation. It would also need to be optional, however, since there may be a valid reason someone might want to override a @keyframe rule.
It seems that in both cases, some sort of syntax to indicate that a rule is allowed to be "grouped" or "collapsed" would be necessary.
@lukeapage
I had considered that but it doesn't really solve the problem. I hope to 'Lessify' animation libraries like animate.css but it contains huge amount of @keyframes rules. If they cannot be produced into .css files upon mixin calls, I will have to output all of them. If I put them in mixins, I will only get those are actually used but with duplicates. I can't figure out a perfect solution in this case...
@lukeapage
Agree. So what I expect is that perhaps Less can offer some mechanism (maybe compilation option?) to automatically remove duplicate @keyframes rules (or even more general, other potential uncascaded rules) except the last one (by default it is turned off).
directly write all @keyframes rules in the global scope, some of which may be unused, or
put @keyframes rules in mixins and output them only when mixins are called, which generates duplicates.
Your last comment is right, unused @keyframes rules cannot be removed because they might be referenced elsewhere. So I think there should be a way to remove duplicates.
@lukeapage
The problem discussed in this issue doesn't seem to be solved in 1.7. The problem here is duplication after each mixin call, while 1.7 supported using rulesets as variables.
OK, I'll reopen this (probably @lukeapage mean some other @keyframes related feature not "removing duplicates"). So far I have not seen anyone was planning to implement this.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Activity
Soviut commentedon Aug 22, 2013
This seems to fall into the same area as grouping media queries.
#950
However, instead of grouping it's more of a "collapse" situation. It would also need to be optional, however, since there may be a valid reason someone might want to override a
@keyframerule.It seems that in both cases, some sort of syntax to indicate that a rule is allowed to be "grouped" or "collapsed" would be necessary.
Justineo commentedon Aug 22, 2013
@keyframesrules don't cascade so the last one always wins. I think overriding is not a problem because you just need to pick the last rule.lukeapage commentedon Aug 22, 2013
You could get round this by setting a global variable and using a guard so
the mixin doesn't run if the variable is set...
Justineo commentedon Aug 22, 2013
@lukeapage
I had considered that but it doesn't really solve the problem. I hope to 'Lessify' animation libraries like animate.css but it contains huge amount of
@keyframesrules. If they cannot be produced into.cssfiles upon mixin calls, I will have to output all of them. If I put them in mixins, I will only get those are actually used but with duplicates. I can't figure out a perfect solution in this case...lukeapage commentedon Sep 1, 2013
it would need to be an option - some people might want a key frame referenced inline or in another stylesheet.
Justineo commentedon Sep 2, 2013
@lukeapage
Agree. So what I expect is that perhaps Less can offer some mechanism (maybe compilation option?) to automatically remove duplicate
@keyframesrules (or even more general, other potential uncascaded rules) except the last one (by default it is turned off).lukeapage commentedon Sep 2, 2013
I thought your problem was unused keyframes, not duplicates?
Justineo commentedon Sep 2, 2013
I can think of two choices:
@keyframesrules in the global scope, some of which may be unused, or@keyframesrules in mixins and output them only when mixins are called, which generates duplicates.Your last comment is right, unused
@keyframesrules cannot be removed because they might be referenced elsewhere. So I think there should be a way to remove duplicates.Justineo commentedon Sep 23, 2013
I found
@counter-stylerules being a similar case as this one.http://dev.w3.org/csswg/css-counter-styles-3/#the-counter-style-rule
lukeapage commentedon Feb 17, 2014
Feature will be in next minor release - 1.7
Justineo commentedon Apr 22, 2014
@lukeapage
The problem discussed in this issue doesn't seem to be solved in 1.7. The problem here is duplication after each mixin call, while 1.7 supported using rulesets as variables.
seven-phases-max commentedon Apr 23, 2014
OK, I'll reopen this (probably @lukeapage mean some other
@keyframesrelated feature not "removing duplicates"). So far I have not seen anyone was planning to implement this.Justineo commentedon Dec 7, 2014
https://github.com/Justineo/less-plugin-unique-directives
Not fully tested yet.
[-]@keyframes inside mixins[/-][+]Automatically remove @keyframes duplicates[/+]stale commentedon Nov 14, 2017
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
atang-gfm commentedon Jun 4, 2024
Hi @Justineo , wondering if you found a better solution to this problem?