From 276b130ed8eebce1704dd995d34fe394f1667451 Mon Sep 17 00:00:00 2001 From: Martin Guillon Date: Tue, 6 Jul 2021 14:55:30 +0200 Subject: [PATCH] fix: finally Color.hex should be good --- packages/core/color/color-common.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/core/color/color-common.ts b/packages/core/color/color-common.ts index ea584b0da..3a32fe3c9 100644 --- a/packages/core/color/color-common.ts +++ b/packages/core/color/color-common.ts @@ -69,12 +69,11 @@ export class Color implements definition.Color { } get hex(): string { - if (this.a === 0xff) { - return SHARP + ((1 << 24) + (this.r << 16) + (this.g << 8) + this.b).toString(16).slice(1); - } else { - const hex = this._argb.toString(16); - return SHARP + hex.slice(2) + hex.slice(0, 2); + let result = SHARP + ('000000' + (this._argb & 0xFFFFFF).toString(16)).slice(-6); + if (this.a !== 0xff) { + return result += ('00' + (this.a).toString(16)).slice(-2); } + return result; } get name(): string {