8000 ARGB input removed. ARGB output added with the function argb(Color). · websdotcom/less.js@71f15ac · GitHub
[go: up one dir, main page]

Skip to content

Commit 71f15ac

Browse files
committed
ARGB input removed. ARGB output added with the function argb(Color).
1 parent 24cc747 commit 71f15ac

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

lib/less/functions.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ tree.functions = {
147147
message: "math functions take numbers as parameters"
148148
};
149149
}
150+
},
151+
argb: function (color) {
152+
return new(tree.Anonymous)(color.toARGB());
153+
150154
}
151155
};
152156

lib/less/tree/color.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ tree.Color = function (rgb, a) {
1515
this.rgb = rgb.match(/.{2}/g).map(function (c) {
1616
return parseInt(c, 16);
1717
});
18-
} else if (rgb.length == 8) {
19-
this.alpha = parseInt(rgb.substring(0,2), 16) / 255.0;
20-
this.rgb = rgb.substr(2).match(/.{2}/g).map(function (c) {
21-
return parseInt(c, 16);
22-
});
2318
} else {
2419
this.rgb = rgb.split('').map(function (c) {
2520
return parseInt(c + c, 16);
@@ -91,6 +86,14 @@ tree.Color.prototype = {
9186
h /= 6;
9287
}
9388
return { h: h * 360, s: s, l: l, a: a };
89+
},
90+
toARGB: function () {
91+
var argb = [Math.round(this.alpha * 255)].concat(this.rgb);
92+
return '#' + argb.map(function (i) {
93+
i = Math.round(i);
94+
i = (i > 255 ? 255 : (i < 0 ? 0 : i)).toString(16);
95+
return i.length === 1 ? '0' + i : i;
96+
}).join('');
9497
}
9598
};
9699

test/css/colors.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#yelow #rgba {
88
color: rgba(255, 238, 170, 0.1);
99
}
10+
#yelow #argb {
11+
color: #1affeeaa;
12+
}
1013
#blue #short {
1114
color: #00f;
1215
}
@@ -16,6 +19,9 @@
1619
#blue #rgba {
1720
color: rgba(0, 0, 255, 0.1);
1821
}
22+
#blue #argb {
23+
color: #1a0000ff;
24+
}
1925
#alpha #hsla {
2026
color: rgba(61, 45, 41, 0.6);
2127
}

test/less/colors.less

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#rgba {
99
color: rgba(255, 238, 170, 0.1);
1010
}
11+
#argb {
12+
color: argb(rgba(255, 238, 170, 0.1));
13+
}
1114
}
1215

1316
#blue {
@@ -20,6 +23,9 @@
2023
#rgba {
2124
color: rgba(0, 0, 255, 0.1);
2225
}
26+
#argb {
27+
color: argb(rgba(0, 0, 255, 0.1));
28+
}
2329
}
2430

2531
#alpha #hsla {

0 commit comments

Comments
 (0)
0