@@ -1952,25 +1952,21 @@ export class Nickname extends ShortFormatColorBase {
19521952
19531953export class Legacy implements Color {
19541954 readonly #rawParams: Color3D ;
1955- #rgbaInternal : Color4D ;
1955+ #rgba : Color4D ;
19561956 readonly #authoredText: string | null ;
1957- #formatInternal : LegacyColor ;
1957+ #format : LegacyColor ;
19581958 readonly channels : [ ColorChannel , ColorChannel , ColorChannel , ColorChannel ] =
19591959 [ ColorChannel . R , ColorChannel . G , ColorChannel . B , ColorChannel . ALPHA ] ;
19601960
19611961 static readonly #conversions: ColorConversions < Legacy > = {
1962- [ Format . HEX ] : ( self : Legacy ) => new Legacy ( self . #rgbaInternal, Format . HEX ) ,
1963- [ Format . HEXA ] : ( self : Legacy ) => new Legacy ( self . #rgbaInternal, Format . HEXA ) ,
1964- [ Format . RGB ] : ( self : Legacy ) => new Legacy ( self . #rgbaInternal, Format . RGB ) ,
1965- [ Format . RGBA ] : ( self : Legacy ) => new Legacy ( self . #rgbaInternal, Format . RGBA ) ,
1966- [ Format . HSL ] : ( self : Legacy ) =>
1967- new HSL ( ...rgbToHsl ( [ self . #rgbaInternal[ 0 ] , self . #rgbaInternal[ 1 ] , self . #rgbaInternal[ 2 ] ] ) , self . alpha ) ,
1968- [ Format . HSLA ] : ( self : Legacy ) =>
1969- new HSL ( ...rgbToHsl ( [ self . #rgbaInternal[ 0 ] , self . #rgbaInternal[ 1 ] , self . #rgbaInternal[ 2 ] ] ) , self . alpha ) ,
1970- [ Format . HWB ] : ( self : Legacy ) =>
1971- new HWB ( ...rgbToHwb ( [ self . #rgbaInternal[ 0 ] , self . #rgbaInternal[ 1 ] , self . #rgbaInternal[ 2 ] ] ) , self . alpha ) ,
1972- [ Format . HWBA ] : ( self : Legacy ) =>
1973- new HWB ( ...rgbToHwb ( [ self . #rgbaInternal[ 0 ] , self . #rgbaInternal[ 1 ] , self . #rgbaInternal[ 2 ] ] ) , self . alpha ) ,
1962+ [ Format . HEX ] : ( self : Legacy ) => new Legacy ( self . #rgba, Format . HEX ) ,
1963+ [ Format . HEXA ] : ( self : Legacy ) => new Legacy ( self . #rgba, Format . HEXA ) ,
1964+ [ Format . RGB ] : ( self : Legacy ) => new Legacy ( self . #rgba, Format . RGB ) ,
1965+ [ Format . RGBA ] : ( self : Legacy ) => new Legacy ( self . #rgba, Format . RGBA ) ,
1966+ [ Format . HSL ] : ( self : Legacy ) => new HSL ( ...rgbToHsl ( [ self . #rgba[ 0 ] , self . #rgba[ 1 ] , self . #rgba[ 2 ] ] ) , self . alpha ) ,
1967+ [ Format . HSLA ] : ( self : Legacy ) => new HSL ( ...rgbToHsl ( [ self . #rgba[ 0 ] , self . #rgba[ 1 ] , self . #rgba[ 2 ] ] ) , self . alpha ) ,
1968+ [ Format . HWB ] : ( self : Legacy ) => new HWB ( ...rgbToHwb ( [ self . #rgba[ 0 ] , self . #rgba[ 1 ] , self . #rgba[ 2 ] ] ) , self . alpha ) ,
1969+ [ Format . HWBA ] : ( self : Legacy ) => new HWB ( ...rgbToHwb ( [ self . #rgba[ 0 ] , self . #rgba[ 1 ] , self . #rgba[ 2 ] ] ) , self . alpha ) ,
19741970 [ Format . LCH ] : ( self : Legacy ) =>
19751971 new LCH ( ...ColorConverter . labToLch ( ...ColorConverter . xyzd50ToLab ( ...self . #toXyzd50( ) ) ) , self . alpha ) ,
19761972 [ Format . OKLCH ] : ( self : Legacy ) => new Oklch ( ...ColorConverter . xyzd50ToOklch ( ...self . #toXyzd50( ) ) , self . alpha ) ,
@@ -1997,15 +1993,15 @@ export class Legacy implements Color {
19971993 } ;
19981994
19991995 #toXyzd50( ) : Color3D {
2000- const [ r , g , b ] = this . #rgbaInternal ;
1996+ const [ r , g , b ] = this . #rgba ;
20011997 return ColorConverter . srgbToXyzd50 ( r , g , b ) ;
20021998 }
20031999
20042000 get alpha ( ) : number | null {
20052001 switch ( this . format ( ) ) {
20062002 case Format . HEXA :
20072003 case Format . RGBA :
2008- return this . #rgbaInternal [ 3 ] ;
2004+ return this . #rgba [ 3 ] ;
20092005 default :
20102006 return null ;
20112007 }
@@ -2022,7 +2018,7 @@ export class Legacy implements Color {
20222018
20232019 shortHex ( ) : ShortHex | null {
20242020 for ( let i = 0 ; i < 4 ; ++ i ) {
2025- const c = Math . round ( this . #rgbaInternal [ i ] * 255 ) ;
2021+ const c = Math . round ( this . #rgba [ i ] * 255 ) ;
20262022 // Check if the two digits of each are identical: #aabbcc => #abc
20272023 if ( c % 0x11 ) {
20282024 return null ;
@@ -2033,10 +2029,10 @@ export class Legacy implements Color {
20332029
20342030 constructor ( rgba : Color3D | Color4DOr3D , format : LegacyColor , authoredText ?: string ) {
20352031 this . #authoredText = authoredText || null ;
2036- this . #formatInternal = format ;
2032+ this . #format = format ;
20372033 this . #rawParams = [ rgba [ 0 ] , rgba [ 1 ] , rgba [ 2 ] ] ;
20382034
2039- this . #rgbaInternal = [
2035+ this . #rgba = [
20402036 clamp ( rgba [ 0 ] , { min : 0 , max : 1 } ) ,
20412037 clamp ( rgba [ 1 ] , { min : 0 , max : 1 } ) ,
20422038 clamp ( rgba [ 2 ] , { min : 0 , max : 1 } ) ,
@@ -2099,11 +2095,11 @@ export class Legacy implements Color {
20992095 }
21002096
21012097 format ( ) : LegacyColor {
2102- return this . #formatInternal ;
2098+ return this . #format ;
21032099 }
21042100
21052101 hasAlpha ( ) : boolean {
2106- return this . #rgbaInternal [ 3 ] !== 1 ;
2102+ return this . #rgba [ 3 ] !== 1 ;
21072103 }
21082104
21092105 detectHEXFormat ( ) : Format {
@@ -2115,11 +2111,11 @@ export class Legacy implements Color {
21152111 if ( format ) {
21162112 return this . as ( format ) . asString ( ) ;
21172113 }
2118- return this . #stringify( format , this . #rgbaInternal [ 0 ] , this . #rgbaInternal [ 1 ] , this . #rgbaInternal [ 2 ] ) ;
2114+ return this . #stringify( format , this . #rgba [ 0 ] , this . #rgba [ 1 ] , this . #rgba [ 2 ] ) ;
21192115 }
21202116 #stringify( format : LegacyColor | undefined , r : number , g : number , b : number ) : string {
21212117 if ( ! format ) {
2122- format = this . #formatInternal ;
2118+ format = this . #format ;
21232119 }
21242120
21252121 function toHexValue ( value : number ) : string {
@@ -2132,15 +2128,15 @@ export class Legacy implements Color {
21322128 case Format . RGBA : {
21332129 const start = Platform . StringUtilities . sprintf ( 'rgb(%d %d %d' , toRgbValue ( r ) , toRgbValue ( g ) , toRgbValue ( b ) ) ;
21342130 if ( this . hasAlpha ( ) ) {
2135- return start + Platform . StringUtilities . sprintf ( ' / %d%)' , Math . round ( this . #rgbaInternal [ 3 ] * 100 ) ) ;
2131+ return start + Platform . StringUtilities . sprintf ( ' / %d%)' , Math . round ( this . #rgba [ 3 ] * 100 ) ) ;
21362132 }
21372133 return start + ')' ;
21382134 }
21392135 case Format . HEX :
21402136 case Format . HEXA : {
21412137 if ( this . hasAlpha ( ) ) {
21422138 return Platform . StringUtilities
2143- . sprintf ( '#%s%s%s%s' , toHexValue ( r ) , toHexValue ( g ) , toHexValue ( b ) , toHexValue ( this . #rgbaInternal [ 3 ] ) )
2139+ . sprintf ( '#%s%s%s%s' , toHexValue ( r ) , toHexValue ( g ) , toHexValue ( b ) , toHexValue ( this . #rgba [ 3 ] ) )
21442140 . toLowerCase ( ) ;
21452141 }
21462142 return Platform . StringUtilities . sprintf ( '#%s%s%s' , toHexValue ( r ) , toHexValue ( g ) , toHexValue ( b ) ) . toLowerCase ( ) ;
@@ -2162,20 +2158,20 @@ export class Legacy implements Color {
21622158 }
21632159 isGamutClipped ( ) : boolean {
21642160 return ! equals (
2165- this . #rawParams. map ( toRgbValue ) ,
2166- [ this . #rgbaInternal [ 0 ] , this . #rgbaInternal [ 1 ] , this . #rgbaInternal [ 2 ] ] . map ( toRgbValue ) , WIDE_RANGE_EPSILON ) ;
2161+ this . #rawParams. map ( toRgbValue ) , [ this . #rgba [ 0 ] , this . #rgba [ 1 ] , this . #rgba [ 2 ] ] . map ( toRgbValue ) ,
2162+ WIDE_RANGE_EPSILON ) ;
21672163 }
21682164
21692165 rgba ( ) : Color4D {
2170- return [ ...this . #rgbaInternal ] ;
2166+ return [ ...this . #rgba ] ;
21712167 }
21722168
21732169 canonicalRGBA ( ) : Color4D {
21742170 const rgba = new Array ( 4 ) ;
21752171 for ( let i = 0 ; i < 3 ; ++ i ) {
2176- rgba [ i ] = Math . round ( this . #rgbaInternal [ i ] * 255 ) ;
2172+ rgba [ i ] = Math . round ( this . #rgba [ i ] * 255 ) ;
21772173 }
2178- rgba [ 3 ] = this . #rgbaInternal [ 3 ] ;
2174+ rgba [ 3 ] = this . #rgba [ 3 ] ;
21792175 return rgba as Color4D ;
21802176 }
21812177
@@ -2200,10 +2196,10 @@ export class Legacy implements Color {
22002196
22012197 invert ( ) : Legacy {
22022198 const rgba : Color4D = [ 0 , 0 , 0 , 0 ] ;
2203- rgba [ 0 ] = 1 - this . #rgbaInternal [ 0 ] ;
2204- rgba [ 1 ] = 1 - this . #rgbaInternal [ 1 ] ;
2205- rgba [ 2 ] = 1 - this . #rgbaInternal [ 2 ] ;
2206- rgba [ 3 ] = this . #rgbaInternal [ 3 ] ;
2199+ rgba [ 0 ] = 1 - this . #rgba [ 0 ] ;
2200+ rgba [ 1 ] = 1 - this . #rgba [ 1 ] ;
2201+ rgba [ 2 ] = 1 - this . #rgba [ 2 ] ;
2202+ rgba [ 3 ] = this . #rgba [ 3 ] ;
22072203 return new Legacy ( rgba , Format . RGBA ) ;
22082204 }
22092205
@@ -2212,38 +2208,38 @@ export class Legacy implements Color {
22122208 * Note: We override with an alpha of 50% to enhance the dimming effect.
22132209 */
22142210 grayscale ( ) : Legacy {
2215- const [ r , g , b ] = this . #rgbaInternal ;
2211+ const [ r , g , b ] = this . #rgba ;
22162212 const gray = r * 0.299 + g * 0.587 + b * 0.114 ;
22172213 return new Legacy ( [ gray , gray , gray , 0.5 ] , Format . RGBA ) ;
22182214 }
22192215
22202216 setAlpha ( alpha : number ) : Legacy {
2221- const rgba : Color4D = [ ...this . #rgbaInternal ] ;
2217+ const rgba : Color4D = [ ...this . #rgba ] ;
22222218 rgba [ 3 ] = alpha ;
22232219 return new Legacy ( rgba , Format . RGBA ) ;
22242220 }
22252221
22262222 blendWith ( fgColor : Legacy ) : Legacy {
2227- const rgba : Color4D = blendColors ( fgColor . #rgbaInternal , this . #rgbaInternal ) ;
2223+ const rgba : Color4D = blendColors ( fgColor . #rgba , this . #rgba ) ;
22282224 return new Legacy ( rgba , Format . RGBA ) ;
22292225 }
22302226
22312227 blendWithAlpha ( alpha : number ) : Legacy {
2232- const rgba : Color4D = [ ...this . #rgbaInternal ] ;
2228+ const rgba : Color4D = [ ...this . #rgba ] ;
22332229 rgba [ 3 ] *= alpha ;
22342230 return new Legacy ( rgba , Format . RGBA ) ;
22352231 }
22362232
22372233 setFormat ( format : LegacyColor ) : void {
2238- this . #formatInternal = format ;
2234+ this . #format = format ;
22392235 }
22402236
22412237 equal ( other : Color ) : boolean {
2242- const legacy = other . as ( this . #formatInternal ) ;
2243- return equals ( toRgbValue ( this . #rgbaInternal [ 0 ] ) , toRgbValue ( legacy . #rgbaInternal [ 0 ] ) , WIDE_RANGE_EPSILON ) &&
2244- equals ( toRgbValue ( this . #rgbaInternal [ 1 ] ) , toRgbValue ( legacy . #rgbaInternal [ 1 ] ) , WIDE_RANGE_EPSILON ) &&
2245- equals ( toRgbValue ( this . #rgbaInternal [ 2 ] ) , toRgbValue ( legacy . #rgbaInternal [ 2 ] ) , WIDE_RANGE_EPSILON ) &&
2246- equals ( this . #rgbaInternal [ 3 ] , legacy . #rgbaInternal [ 3 ] ) ;
2238+ const legacy = other . as ( this . #format ) ;
2239+ return equals ( toRgbValue ( this . #rgba [ 0 ] ) , toRgbValue ( legacy . #rgba [ 0 ] ) , WIDE_RANGE_EPSILON ) &&
2240+ equals ( toRgbValue ( this . #rgba [ 1 ] ) , toRgbValue ( legacy . #rgba [ 1 ] ) , WIDE_RANGE_EPSILON ) &&
2241+ equals ( toRgbValue ( this . #rgba [ 2 ] ) , toRgbValue ( legacy . #rgba [ 2 ] ) , WIDE_RANGE_EPSILON ) &&
2242+ equals ( this . #rgba [ 3 ] , legacy . #rgba [ 3 ] ) ;
22472243 }
22482244}
22492245
0 commit comments