@@ -58,7 +58,7 @@ endfunction
58
58
" Constructors
59
59
60
60
let s: RGB_HEX_RE = ' \v^#(\x{3}(\x{3})?)$'
61
- let s: RGB_RE = ' \v^rgb\((\d+),\s*(\d+),\s*(\d+)\)$'
61
+ let s: RGB_RE = ' \v^rgb\((\d+\%? ),\s*(\d+\%? ),\s*(\d+\%? )\)$'
62
62
let s: HSL_RE = ' \v^hsl\((\d+),\s*(\d+)\%,\s*(\d+)\%\)$'
63
63
let s: VIM_RGB_FILE = expand (' $VIMRUNTIME/rgb.txt' )
64
64
function ! s: parse (str) abort
@@ -76,9 +76,10 @@ function! s:parse(str) abort
76
76
return s: rgb (r , g , b )
77
77
endif
78
78
" e.g. rgb(255,255,255)
79
+ " e.g. rgb(100%,100%,100%)
79
80
let m = matchlist (a: str , s: RGB_RE )
80
81
if ! empty (m )
81
- let [r , g , b ] = [ str2float (m [1 ]), str2float ( m [ 2 ]), str2float ( m [ 3 ])]
82
+ let [r , g , b ] = map (m [1 : 3 ], ' s:_per2float(v:val, 255.0) ' )
82
83
return s: rgb (r , g , b )
83
84
endif
84
85
" e.g. hsl(0,0%,100%)
@@ -99,6 +100,10 @@ function! s:parse(str) abort
99
100
throw ' vital: Color: parse(): invalid format: ' . a: str
100
101
endfunction
101
102
103
+ function ! s: _per2float (per, n ) abort
104
+ return a: per = ~# ' %$' ? str2float (a: per [:-2 ]) * a: n / 100.0 : str2float (a: per )
105
+ endfunction
106
+
102
107
let s: RGB_FILE_RE = ' \v^\s*(\d+)\s+(\d+)\s+(\d+)\s+(.+)$'
103
108
function ! s: _parse_rgb_file (file ) abort
104
109
let color_map = {}
0 commit comments