Skip to content

Commit e52e5c7

Browse files
committed
Allow to paste color numbers without function
1 parent c21d3cf commit e52e5c7

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/colors.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ export function parseAnything(value: string): Color | undefined {
109109
if (/^[\w-]+:\s*(#\w+|\w+\([^)]+\))$/.test(value)) {
110110
value = value.replace(/^[\w-]+:\s*/, '')
111111
}
112+
if (/^\s*[\d.]+%?\s+[\d.]+\s+[\d.]+\s*$/.test(value)) {
113+
value = `${COLOR_FN}(${value})`
114+
}
112115
return parse(value)
113116
}
114117

test/inputs.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,11 @@ test('understands hex without #', () => {
2020
setCurrent('ff0000')
2121
deepStrictEqual(current.get(), { a: 100, c: 0.2577, h: 29.23, l: 62.8 })
2222
})
23+
24+
test('understands OKLCH without function', () => {
25+
setCurrent('80% 0.1 195')
26+
deepStrictEqual(current.get(), { a: 100, c: 0.1, h: 195, l: 80 })
27+
28+
setCurrent('0.8 0.1 195')
29+
deepStrictEqual(current.get(), { a: 100, c: 0.1, h: 195, l: 80 })
30+
})

0 commit comments

Comments
 (0)