Skip to content

Commit 231d062

Browse files
committed
Move from % in L to float because % has issue with calc() in relative colors
1 parent e52e5c7 commit 231d062

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

lib/colors.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ export function formatLch(color: AnyLch): string {
136136
let { alpha, c, h, l } = color
137137
let postfix = ''
138138
if (typeof alpha !== 'undefined' && alpha < 1) {
139-
postfix = ` / ${toPercent(alpha)}`
139+
postfix = ` / ${clean(100 * alpha)}%`
140140
}
141-
return `${COLOR_FN}(${toPercent(l / L_MAX)} ${c} ${h}${postfix})`
141+
return `${COLOR_FN}(${clean(l / L_MAX)} ${c} ${h}${postfix})`
142142
}
143143

144144
// Hack to avoid ,999999 because of float bug implementation
@@ -149,10 +149,6 @@ export function clean(value: number, precision = 2): number {
149149
)
150150
}
151151

152-
export function toPercent(value: number): string {
153-
return `${clean(100 * value)}%`
154-
}
155-
156152
export function isHexNotation(value: string): boolean {
157153
return /^#?([\da-f]{3}|[\da-f]{4}|[\da-f]{6}|[\da-f]{8})$/i.test(value)
158154
}

stores/formats.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
lrgb,
2121
oklab,
2222
p3,
23-
toPercent,
2423
toRgb
2524
} from '../lib/colors.ts'
2625
import { current, valueToColor } from './current.ts'
@@ -32,7 +31,7 @@ function formatOklab(color: Oklab): string {
3231
if (typeof alpha !== 'undefined' && alpha < 1) {
3332
postfix = ` / ${clean(alpha)}`
3433
}
35-
return `oklab(${toPercent(l)} ${clean(a)} ${clean(b)}${postfix})`
34+
return `oklab(${clean(l)} ${clean(a)} ${clean(b)}${postfix})`
3635
}
3736

3837
function formatVec(color: AnyRgb): string {

0 commit comments

Comments
 (0)