mirror of
https://github.com/less/less.js.git
synced 2026-02-01 02:25:19 -05:00
Added min and max builtins.
This commit is contained in:
committed by
Luke Page
parent
d2255e64f6
commit
6df4e48976
@@ -266,6 +266,41 @@ tree.functions = {
|
||||
throw { type: "Argument", message: "argument must be a number" };
|
||||
}
|
||||
},
|
||||
_minmax: function (name, args) {
|
||||
args = Array.prototype.slice.call(args);
|
||||
switch(args.length) {
|
||||
case 0: throw { type: "Argument", message: "one or more arguments required" };
|
||||
case 1: return args[0];
|
||||
}
|
||||
var isMin = name == 'min';
|
||||
function f (a, b) {
|
||||
if(!(a instanceof tree.Dimension && b instanceof tree.Dimension)) {
|
||||
return null;
|
||||
}
|
||||
var ua = a.unify();
|
||||
var ub = b.unify();
|
||||
if(ua.unit.compare(ub.unit) != 0) {
|
||||
return null;
|
||||
}
|
||||
var val = ua.compare(ub);
|
||||
if(isMin && val > 0 || !isMin && val < 0) {
|
||||
return b;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
var val = args.reduce(f);
|
||||
if(val !== null) {
|
||||
return val;
|
||||
}
|
||||
return new(tree.Anonymous)(name +
|
||||
"(" + args.map(function (a) { return a.toCSS(); }).join(', ') + ")");
|
||||
},
|
||||
min: function () {
|
||||
return this._minmax('min', arguments);
|
||||
},
|
||||
max: function () {
|
||||
return this._minmax('max', arguments);
|
||||
},
|
||||
argb: function (color) {
|
||||
return new(tree.Anonymous)(color.toARGB());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user