Added new round(n) function.

Rationale: Using unrounded computed widths leads to pixel errors.
This commit is contained in:
Bart Schuller
2011-02-14 23:47:41 +01:00
parent 0d95755e00
commit 202bcab8d2
3 changed files with 16 additions and 0 deletions

View File

@@ -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"
};
}
}
};

View File

@@ -20,6 +20,8 @@
hue: 98;
saturation: 12%;
lightness: 95%;
rounded: 11;
roundedpx: 3px;
}
#alpha {
alpha: rgba(153, 94, 51, 0.6);

View File

@@ -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 {