1+ --- @class one_monokai.colors
2+ --- @field [ string] string | number
13local colors = {}
24
3- --- @class colors
5+ --- @type one_monokai. colors
46local defaults = {
57 fg = " #abb2bf" ,
68 bg = " #282c34" ,
@@ -27,12 +29,11 @@ local defaults = {
2729 none = " NONE" ,
2830}
2931
30- --- @type colors
3132colors = vim .deepcopy (defaults )
3233
33- --- Converts a hex color to an RGB table
34- --- @param color string #Hex color
35- --- @return integer[] #RGB table {r, g, b}
34+ --- Converts a hex color to an RGB table.
35+ --- @param color string #Hex color.
36+ --- @return integer[] #RGB table {r, g, b}.
3637local function hex2rgb (color )
3738 color = color :lower ()
3839
4546
4647--- Blends two hex colors together based on the alpha value.
4748---
48- --- [View source](https://github.com/folke/tokyonight.nvim/blob/main/lua/tokyonight/util.lua)
49- --- @param fg string #Foreground hex color
50- --- @param bg string #Background hex color
51- --- @param alpha number #Blend factor between 0 (only bg) and 1 (only fg)
52- --- @return string #Hex color of the resulting blended color
49+ --- [View source](https://github.com/folke/tokyonight.nvim/blob/main/lua/tokyonight/util.lua).
50+ --- @param fg string #Foreground hex color.
51+ --- @param bg string #Background hex color.
52+ --- @param alpha number #Blend factor between 0 (only bg) and 1 (only fg).
53+ --- @return string #Hex color of the resulting blended color.
5354local function blend (fg , bg , alpha )
5455 local bg_rgb = hex2rgb (bg )
5556 local fg_rgb = hex2rgb (fg )
@@ -61,25 +62,25 @@ local function blend(fg, bg, alpha)
6162 return (" #%02x%02x%02x" ):format (r , g , b )
6263end
6364
64- --- Darkens the current hex color
65+ --- Darkens the current hex color.
6566--- @param s string
66- --- @param alpha number #Value between 0 and 1
67+ --- @param alpha number #Value between 0 and 1.
6768function string .darken (s , alpha )
6869 return blend (s , " #000000" , alpha )
6970end
7071
71- --- Lightens the current hex color
72+ --- Lightens the current hex color.
7273--- @param s string
73- --- @param alpha number #Value between 0 and 1
74+ --- @param alpha number #Value between 0 and 1.
7475function string .lighten (s , alpha )
7576 return blend (s , " #ffffff" , alpha )
7677end
7778
78- --- Resolve and retrieve the value of a color
79- --- @param name string #Name of the color
80- --- @param value string | number #Value of the color
81- --- @return string | number ? #Hex color or 24-bit RGB value, or default if invalid
82- local function resolve_color (name , value )
79+ --- Resolve and retrieve the value of a color.
80+ --- @param name string #Name of the color.
81+ --- @param value string | number #Value of the color.
82+ --- @return string | number ? #Hex color or 24-bit RGB value, or default if invalid.
83+ local function resolve (name , value )
8384 local color_type = type (value )
8485
8586 -- Resolve string first to optimize the common case
115116local config = require " one_monokai.config"
116117
117118for name , value in pairs (config .colors or {}) do
118- colors [name ] = resolve_color (name , value )
119+ colors [name ] = resolve (name , value )
119120end
120121
121122return colors
0 commit comments