mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-18 22:01:42 +08:00
fix: color hex getter fix
This commit is contained in:
@ -72,7 +72,8 @@ export class Color implements definition.Color {
|
||||
if (this.a === 0xff) {
|
||||
return SHARP + ((1 << 24) + (this.r << 16) + (this.g << 8) + this.b).toString(16).slice(1);
|
||||
} else {
|
||||
return SHARP + this._argb.toString(16);
|
||||
const hex = this._argb.toString(16);
|
||||
return SHARP + hex.slice(2) + hex.slice(0, 2);
|
||||
}
|
||||
}
|
||||
|
||||
@ -160,7 +161,6 @@ export class Color implements definition.Color {
|
||||
return hex;
|
||||
}
|
||||
|
||||
|
||||
public toString(): string {
|
||||
return this.hex;
|
||||
}
|
||||
@ -245,7 +245,9 @@ export class Color implements definition.Color {
|
||||
*/
|
||||
public toHslString() {
|
||||
const hsl = rgbToHsl(this.r / 255, this.g / 255, this.b / 255);
|
||||
const h = Math.round(hsl.h * 360), s = Math.round(hsl.s * 100), l = Math.round(hsl.l * 100);
|
||||
const h = Math.round(hsl.h * 360),
|
||||
s = Math.round(hsl.s * 100),
|
||||
l = Math.round(hsl.l * 100);
|
||||
const a = this.a;
|
||||
return a == 255 ? 'hsl(' + h + ', ' + s + '%, ' + l + '%)' : 'hsla(' + h + ', ' + s + '%, ' + l + '%, ' + (a / 255).toFixed(2) + ')';
|
||||
}
|
||||
@ -265,7 +267,9 @@ export class Color implements definition.Color {
|
||||
*/
|
||||
public toHsvString() {
|
||||
const hsv = rgbToHsv(this.r / 255, this.g / 255, this.b / 255);
|
||||
const h = Math.round(hsv.h * 360), s = Math.round(hsv.s * 100), v = Math.round(hsv.v * 100);
|
||||
const h = Math.round(hsv.h * 360),
|
||||
s = Math.round(hsv.s * 100),
|
||||
v = Math.round(hsv.v * 100);
|
||||
const a = this.a;
|
||||
return a == 255 ? 'hsv(' + h + ', ' + s + '%, ' + v + '%)' : 'hsva(' + h + ', ' + s + '%, ' + v + '%, ' + (a / 255).toFixed(2) + ')';
|
||||
}
|
||||
@ -285,7 +289,7 @@ export class Color implements definition.Color {
|
||||
* @param amount (between 0 and 100)
|
||||
*/
|
||||
public desaturate(amount: number) {
|
||||
amount = (amount === 0) ? 0 : (amount || 10);
|
||||
amount = amount === 0 ? 0 : amount || 10;
|
||||
const hsl = rgbToHsl(this.r / 255, this.g / 255, this.b / 255);
|
||||
hsl.s -= amount / 100;
|
||||
hsl.s = Math.min(1, Math.max(0, hsl.s));
|
||||
@ -298,7 +302,7 @@ export class Color implements definition.Color {
|
||||
* @param amount (between 0 and 100)
|
||||
*/
|
||||
public saturate(amount: number) {
|
||||
amount = (amount === 0) ? 0 : (amount || 10);
|
||||
amount = amount === 0 ? 0 : amount || 10;
|
||||
const hsl = rgbToHsl(this.r / 255, this.g / 255, this.b / 255);
|
||||
hsl.s += amount / 100;
|
||||
hsl.s = Math.min(1, Math.max(0, hsl.s));
|
||||
@ -319,7 +323,7 @@ export class Color implements definition.Color {
|
||||
* @param amount (between 0 and 100)
|
||||
*/
|
||||
public lighten(amount: number) {
|
||||
amount = (amount === 0) ? 0 : (amount || 10);
|
||||
amount = amount === 0 ? 0 : amount || 10;
|
||||
const hsl = rgbToHsl(this.r / 255, this.g / 255, this.b / 255);
|
||||
hsl.l += amount / 100;
|
||||
hsl.l = Math.min(1, Math.max(0, hsl.l));
|
||||
@ -345,7 +349,7 @@ export class Color implements definition.Color {
|
||||
* @param amount (between 0 and 100)
|
||||
*/
|
||||
public darken(amount: number) {
|
||||
amount = (amount === 0) ? 0 : (amount || 10);
|
||||
amount = amount === 0 ? 0 : amount || 10;
|
||||
const hsl = rgbToHsl(this.r / 255, this.g / 255, this.b / 255);
|
||||
hsl.l -= amount / 100;
|
||||
hsl.l = Math.min(1, Math.max(0, hsl.l));
|
||||
@ -378,14 +382,14 @@ export class Color implements definition.Color {
|
||||
const p = amount / 100;
|
||||
|
||||
const rgba = {
|
||||
r: ((color2.r - color1.r) * p) + color1.r,
|
||||
g: ((color2.g - color1.g) * p) + color1.g,
|
||||
b: ((color2.b - color1.b) * p) + color1.b,
|
||||
a: ((color2.a - color1.a) * p) + color1.a
|
||||
r: (color2.r - color1.r) * p + color1.r,
|
||||
g: (color2.g - color1.g) * p + color1.g,
|
||||
b: (color2.b - color1.b) * p + color1.b,
|
||||
a: (color2.a - color1.a) * p + color1.a,
|
||||
};
|
||||
|
||||
return new Color(rgba.a, rgba.r, rgba.g, rgba.b);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function isRgbOrRgba(value: string): boolean {
|
||||
|
Reference in New Issue
Block a user