Sha256: 6769be4fc9b6d699528cd2e18d6a7cf09989dba29aa274d05bf012a56cb160a9

Contents?: true

Size: 1.27 KB

Versions: 9

Compression:

Stored size: 1.27 KB

Contents

(function (tree) {

//
// A number with a unit
//
tree.Dimension = function (value, unit) {
    this.value = parseFloat(value);
    this.unit = unit || null;
};

tree.Dimension.prototype = {
    eval: function () { return this },
    toColor: function () {
        return new(tree.Color)([this.value, this.value, this.value]);
    },
    toCSS: function () {
        var css = this.value + this.unit;
        return css;
    },

    // In an operation between two Dimensions,
    // we default to the first Dimension's unit,
    // so `1px + 2em` will yield `3px`.
    // In the future, we could implement some unit
    // conversions such that `100cm + 10mm` would yield
    // `101cm`.
    operate: function (op, other) {
        return new(tree.Dimension)
                  (tree.operate(op, this.value, other.value),
                  this.unit || other.unit);
    },

    // TODO: Perform unit conversion before comparing
    compare: function (other) {
        if (other instanceof tree.Dimension) {
            if (other.value > this.value) {
                return -1;
            } else if (other.value < this.value) {
                return 1;
            } else {
                return 0;
            }
        } else {
            return -1;
        }
    }
};

})(require('../tree'));

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
less-2.3.0 lib/less/js/lib/less/tree/dimension.js
less-2.2.2 lib/less/js/lib/less/tree/dimension.js
less-2.2.1 lib/less/js/lib/less/tree/dimension.js
less-2.2.0 lib/less/js/lib/less/tree/dimension.js
less-2.1.0 lib/less/js/lib/less/tree/dimension.js
less-2.0.12 lib/less/js/lib/less/tree/dimension.js
less-2.0.11 lib/less/js/lib/less/tree/dimension.js
less-2.0.10 lib/less/js/lib/less/tree/dimension.js
less-2.0.9 lib/less/js/lib/less/tree/dimension.js