Browse Source

refactor hex to rgb in `setStyle` (#25572)

ycw 2 years ago
parent
commit
820b3bfd02
1 changed files with 7 additions and 14 deletions
  1. 7 14
      src/math/Color.js

+ 7 - 14
src/math/Color.js

@@ -242,24 +242,17 @@ class Color {
 			if ( size === 3 ) {
 			if ( size === 3 ) {
 
 
 				// #ff0
 				// #ff0
-				this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
-				this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
-				this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
-
-				ColorManagement.toWorkingColorSpace( this, colorSpace );
-
-				return this;
+				return this.setRGB(
+					parseInt( hex.charAt( 0 ), 16 ) / 15,
+					parseInt( hex.charAt( 1 ), 16 ) / 15,
+					parseInt( hex.charAt( 2 ), 16 ) / 15,
+					colorSpace
+				);
 
 
 			} else if ( size === 6 ) {
 			} else if ( size === 6 ) {
 
 
 				// #ff0000
 				// #ff0000
-				this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
-				this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
-				this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
-
-				ColorManagement.toWorkingColorSpace( this, colorSpace );
-
-				return this;
+				return this.setHex( parseInt( hex, 16 ), colorSpace );
 
 
 			} else {
 			} else {