Is there any way to pass one mixin or style\'s declaration to another mixin as an input parameter?
Let\'s take a look at an example with animation keyframes. Followi
I just simplified a little ScottS' way, separateing @keframes from -animation:
.keyframes(@name, @from, @to) {
@newline: `"\n"`;
.Local(@x){};
.Local(@x) when (@x="") {(~"}@{newline}/*"){a:a}/**/};
.setVendor(@pre, @vendor) {
(~"@{pre}@@{vendor}keyframes @{name} {@{newline}from") {
.from(@from);
}
to {
.to(@to);
}
.Local(@vendor);
}
.setVendor("" , "-webkit-");
.setVendor(~"}@{newline}", "-moz-");
.setVendor(~"}@{newline}", "-o-");
.setVendor(~"}@{newline}", "");
}
.animation(...) {
-webkit-animation: @arguments;
-moz-animation: @arguments;
-o-animation: @arguments;
animation: @arguments;
}
.from(a1-from){ width: 10px; }
.to(a1-to) { width: 20px; }
.keyframes(a1-animation, a1-from, a1-to);
.selector {
// some other css
.animation(a1-animation 1s infinite linear);
}
@-webkit-keyframes a1-animation {
from {
width: 10px;
}
to {
width: 20px;
}
}
@-moz-keyframes a1-animation {
from {
width: 10px;
}
to {
width: 20px;
}
}
@-o-keyframes a1-animation {
from {
width: 10px;
}
to {
width: 20px;
}
}
@keyframes a1-animation {
from {
width: 10px;
}
to {
width: 20px;
}
}
/* {
a: a;
}
/**/
.selector {
// some other css
-webkit-animation: a1-animation 1s infinite linear;
-moz-animation: a1-animation 1s infinite linear;
-o-animation: a1-animation 1s infinite linear;
animation: a1-animation 1s infinite linear;
}
So animation is now separated from @keyframes, but we got to pay the price. There is a nasty:
/* {
a: a;
}
/**/
but it shouldn't be a problem -> propably all of us push CSS files through any kinds of minifiers which cut comments out.