mirror of
https://github.com/less/less.js.git
synced 2026-01-22 21:58:14 -05:00
Added new round(n) function.
Rationale: Using unrounded computed widths leads to pixel errors.
This commit is contained in:
@@ -130,6 +130,18 @@ tree.functions = {
|
||||
}
|
||||
str = str.replace(/%%/g, '%');
|
||||
return new(tree.Quoted)('"' + str + '"', str);
|
||||
},
|
||||
round: function (n) {
|
||||
if (n instanceof tree.Dimension) {
|
||||
return new(tree.Dimension)(Math.round(number(n)), n.unit);
|
||||
} else if (typeof(n) === 'number') {
|
||||
return Math.round(n);
|
||||
} else {
|
||||
throw {
|
||||
error: "RuntimeError",
|
||||
message: "math functions take numbers as parameters"
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
hue: 98;
|
||||
saturation: 12%;
|
||||
lightness: 95%;
|
||||
rounded: 11;
|
||||
roundedpx: 3px;
|
||||
}
|
||||
#alpha {
|
||||
alpha: rgba(153, 94, 51, 0.6);
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
hue: hue(hsl(98, 12%, 95%));
|
||||
saturation: saturation(hsl(98, 12%, 95%));
|
||||
lightness: lightness(hsl(98, 12%, 95%));
|
||||
rounded: round(@r/3);
|
||||
roundedpx: round(10px / 3);
|
||||
}
|
||||
|
||||
#alpha {
|
||||
|
||||
Reference in New Issue
Block a user