@@ -28,7 +28,7 @@ export interface LchValue {
2828type PrevCurrentValue = { [ key in keyof LchValue ] ?: undefined } | LchValue
2929
3030function randomColor ( ) : LchValue {
31- return { a : 100 , c : C_RANDOM , h : Math . round ( 360 * Math . random ( ) ) , l : 70 }
31+ return { a : 100 , c : C_RANDOM , h : Math . round ( 360 * Math . random ( ) ) , l : 0.7 }
3232}
3333
3434function parseHash ( ) : LchValue | undefined {
@@ -159,7 +159,7 @@ function aggressiveRoundValue<V extends Partial<LchValue>>(
159159) : V {
160160 let rounded = { ...value }
161161 if ( typeof rounded . l !== 'undefined' ) {
162- rounded . l = round2 ( rounded . l )
162+ rounded . l = type === 'oklch' ? round4 ( rounded . l ) : round2 ( rounded . l )
163163 }
164164 if ( typeof rounded . c !== 'undefined' ) {
165165 rounded . c = type === 'oklch' ? round4 ( rounded . c ) : round2 ( rounded . c )
@@ -179,7 +179,7 @@ function preciseRoundValue<V extends Partial<LchValue>>(
179179) : V {
180180 let rounded = { ...value }
181181 if ( typeof rounded . l !== 'undefined' ) {
182- rounded . l = round4 ( rounded . l )
182+ rounded . l = type === 'oklch' ? round6 ( rounded . l ) : round4 ( rounded . l )
183183 }
184184 if ( typeof rounded . c !== 'undefined' ) {
185185 rounded . c = type === 'oklch' ? round6 ( rounded . c ) : round4 ( rounded . c )
@@ -208,7 +208,7 @@ export function setCurrent(code: string, isRgbInput = false): boolean {
208208 parsed . g === 1 &&
209209 parsed . b === 1
210210 ) {
211- current . set ( { a : ( parsed . alpha ?? 1 ) * 100 , c : 0 , h : 0 , l : 100 } )
211+ current . set ( { a : ( parsed . alpha ?? 1 ) * 100 , c : 0 , h : 0 , l : 1 } )
212212 return true
213213 }
214214 let originSpace = getSpace ( parsed )
@@ -249,15 +249,15 @@ export function setCurrent(code: string, isRgbInput = false): boolean {
249249}
250250
251251export function valueToColor ( value : LchValue ) : AnyLch {
252- return build ( ( L_MAX * value . l ) / 100 , value . c , value . h , value . a / 100 )
252+ return build ( value . l * L_MAX_COLOR , value . c , value . h , value . a / 100 )
253253}
254254
255255export function colorToValue ( color : AnyLch ) : LchValue {
256256 return {
257257 a : ( color . alpha ?? 1 ) * 100 ,
258258 c : color . c ,
259259 h : color . h ?? 0 ,
260- l : ( 100 * color . l ) / L_MAX
260+ l : color . l / L_MAX_COLOR
261261 }
262262}
263263
0 commit comments