mirror of
https://github.com/less/less.js.git
synced 2026-04-09 03:00:20 -04:00
color() function parses color string
This commit is contained in:
@@ -170,6 +170,13 @@ tree.functions = {
|
||||
},
|
||||
percentage: function(n) {
|
||||
return new(tree.Dimension)(n.value * 100, '%');
|
||||
},
|
||||
color: function (n) {
|
||||
if (n instanceof tree.Quoted) {
|
||||
return new(tree.Color)(n.value.slice(1));
|
||||
} else {
|
||||
throw { type: "Argument", message: "argument must be a string" };
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
rounded: 11;
|
||||
roundedpx: 3px;
|
||||
percentage: 20%;
|
||||
color: #ff0011;
|
||||
}
|
||||
#alpha {
|
||||
alpha: rgba(153, 94, 51, 0.6);
|
||||
|
||||
@@ -10,7 +10,7 @@ less.tree.functions.add = function (a, b) {
|
||||
less.tree.functions.increment = function (a) {
|
||||
return new(less.tree.Dimension)(a.value + 1);
|
||||
}
|
||||
less.tree.functions.color = function (str) {
|
||||
less.tree.functions._color = function (str) {
|
||||
if (str.value === "evil red") { return new(less.tree.Color)("600") }
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#functions {
|
||||
@var: 10;
|
||||
color: color("evil red"); // #660000
|
||||
color: _color("evil red"); // #660000
|
||||
width: increment(15);
|
||||
height: undefined("self");
|
||||
border-width: add(2, 3);
|
||||
@@ -29,6 +29,7 @@
|
||||
rounded: round(@r/3);
|
||||
roundedpx: round(10px / 3);
|
||||
percentage: percentage(10px / 50);
|
||||
color: color("#ff0011");
|
||||
}
|
||||
|
||||
#alpha {
|
||||
|
||||
Reference in New Issue
Block a user