diff --git a/lib/less/functions.js b/lib/less/functions.js index 8c0f1031..699183ce 100644 --- a/lib/less/functions.js +++ b/lib/less/functions.js @@ -264,28 +264,34 @@ tree.functions = { _minmax: function (isMin, 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]; + case 0: throw { type: "Argument", message: "one or more arguments required" }; } - var i, j, current, currentUnified, referenceUnified, unit, + var i, j, current, currentUnified, referenceUnified, unit, unitStatic, unitClone, order = [], // elems only contains original argument values. values = {}; // key is the unit.toString() for unified tree.Dimension values, // value is the index into the order array. for (i = 0; i < args.length; i++) { current = args[i]; if (!(current instanceof tree.Dimension)) { - order.push(current); + if(Array.isArray(args[i].value)) { + Array.prototype.push.apply(args, Array.prototype.slice.call(args[i].value)); + } continue; } - currentUnified = current.unify(); - unit = currentUnified.unit.toString(); - j = values[unit]; + currentUnified = current.unit.toString() === "" && unitClone !== undefined ? new(tree.Dimension)(current.value, unitClone).unify() : current.unify(); + unit = currentUnified.unit.toString() === "" && unitStatic !== undefined ? unitStatic : currentUnified.unit.toString(); + unitStatic = unit !== "" && unitStatic === undefined || unit !== "" && order[0].unify().unit.toString() === "" ? unit : unitStatic; + unitClone = unit !== "" && unitClone === undefined ? current.unit.toString() : unitClone; + j = values[""] !== undefined && unit !== "" && unit === unitStatic ? values[""] : values[unit]; if (j === undefined) { + if(unitStatic !== undefined && unit !== unitStatic) { + throw{ type: "Argument", message: "incompatible types" }; + } values[unit] = order.length; order.push(current); continue; } - referenceUnified = order[j].unify(); + referenceUnified = order[j].unit.toString() === "" && unitClone !== undefined ? new(tree.Dimension)(order[j].value, unitClone).unify() : order[j].unify(); if ( isMin && currentUnified.value < referenceUnified.value || !isMin && currentUnified.value > referenceUnified.value) { order[j] = current; @@ -294,8 +300,7 @@ tree.functions = { if (order.length == 1) { return order[0]; } - args = order.map(function (a) { return a.toCSS(this.env); }) - .join(this.env.compress ? "," : ", "); + args = order.map(function (a) { return a.toCSS(this.env); }).join(this.env.compress ? "," : ", "); return new(tree.Anonymous)((isMin ? "min" : "max") + "(" + args + ")"); }, min: function () { @@ -304,6 +309,9 @@ tree.functions = { max: function () { return this._minmax(false, arguments); }, + obtain: function (n) { + return new(tree.Anonymous)(n.unit); + }, argb: function (color) { return new(tree.Anonymous)(color.toARGB()); }, diff --git a/lib/less/tree/dimension.js b/lib/less/tree/dimension.js index 93bed32f..f96078ec 100644 --- a/lib/less/tree/dimension.js +++ b/lib/less/tree/dimension.js @@ -161,6 +161,7 @@ tree.UnitConversions = { 'cm': 0.01, 'mm': 0.001, 'in': 0.0254, + 'px': 0.0254 / 96, 'pt': 0.0254 / 72, 'pc': 0.0254 / 72 * 12 },