1+ --- @class one_monokai.colors
12local colors = {}
23
3- --- @class colors
4+ --- @type one_monokai. colors
45local defaults = {
56 fg = " #abb2bf" ,
67 bg = " #282c34" ,
@@ -27,12 +28,11 @@ local defaults = {
2728 none = " NONE" ,
2829}
2930
30- --- @type colors
3131colors = vim .deepcopy (defaults )
3232
33- --- Converts a hex color to an RGB table
34- --- @param color string #Hex color
35- --- @return integer[] #RGB table {r, g, b}
33+ --- Converts a hex color to an RGB table.
34+ --- @param color string #Hex color.
35+ --- @return integer[] #RGB table {r, g, b}.
3636local function hex2rgb (color )
3737 color = color :lower ()
3838
4545
4646--- Blends two hex colors together based on the alpha value.
4747---
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
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.
5353local function blend (fg , bg , alpha )
5454 local bg_rgb = hex2rgb (bg )
5555 local fg_rgb = hex2rgb (fg )
@@ -61,25 +61,25 @@ local function blend(fg, bg, alpha)
6161 return (" #%02x%02x%02x" ):format (r , g , b )
6262end
6363
64- --- Darkens the current hex color
64+ --- Darkens the current hex color.
6565--- @param s string
66- --- @param alpha number #Value between 0 and 1
66+ --- @param alpha number #Value between 0 and 1.
6767function string .darken (s , alpha )
6868 return blend (s , " #000000" , alpha )
6969end
7070
71- --- Lightens the current hex color
71+ --- Lightens the current hex color.
7272--- @param s string
73- --- @param alpha number #Value between 0 and 1
73+ --- @param alpha number #Value between 0 and 1.
7474function string .lighten (s , alpha )
7575 return blend (s , " #ffffff" , alpha )
7676end
7777
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 )
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 (name , value )
8383 local color_type = type (value )
8484
8585 -- Resolve string first to optimize the common case
115115local config = require " one_monokai.config"
116116
117117for name , value in pairs (config .colors or {}) do
118- colors [name ] = resolve_color (name , value )
118+ colors [name ] = resolve (name , value )
119119end
120120
121121return colors
0 commit comments