mirror of
https://github.com/maxmx03/solarized.nvim.git
synced 2026-09-10 07:26:26 -04:00
feat: utils.math removed, colors hsl func removed, improv darken,lighten
This commit is contained in:
parent
81ede69c3c
commit
d618ab9ea1
52
README.md
52
README.md
|
|
@ -294,12 +294,6 @@ local colorhelper = require('solarized.utils.colors')
|
|||
-- Convert a hex color code to RGB
|
||||
colorhelper.hex_to_rgb('#ffffff')
|
||||
|
||||
-- Convert RGB values to HSL
|
||||
colorhelper.rgb_to_hsl(255, 255, 255)
|
||||
|
||||
-- Convert HSL values to RGB
|
||||
colorhelper.hsl_to_rgb(0, 0, 100)
|
||||
|
||||
-- Darken a color by a specified percentage
|
||||
colorhelper.darken('#ffffff', 100)
|
||||
|
||||
|
|
@ -334,29 +328,25 @@ collaboration, please follow the guidelines below:
|
|||
```
|
||||
|
||||
```bash
|
||||
ok 1 - Color Conversions Convert hex to RGB
|
||||
ok 2 - Color Conversions Convert RGB to hex
|
||||
ok 3 - Color Conversions Convert RGB to HSL
|
||||
ok 4 - Color Conversions Convert HSL to RGB
|
||||
ok 5 - Color Conversions Darken the color by percentage
|
||||
ok 6 - Color Conversions Lighten the color by percentage
|
||||
ok 7 - Color Conversions Blend colors
|
||||
ok 8 - Configuration Default configuration
|
||||
ok 9 - Configuration Unique configuration table instances
|
||||
ok 10 - Configuration Extend default configuration
|
||||
ok 11 - Initialization Loads without encountering any errors
|
||||
ok 12 - Initialization Background is set to light
|
||||
ok 13 - Math Round to the nearest integer
|
||||
ok 14 - Math Return the value of the first parameter and the sign of the second parameter
|
||||
ok 15 - Palette Extend solarized color palette
|
||||
ok 16 - Palette Correct any invalid colors when extending the solarized palette
|
||||
ok 17 - Setup Customizing Highlight Groups
|
||||
ok 18 - Setup Changing Comment Style
|
||||
ok 19 - Setup Changing Function Style
|
||||
ok 20 - Setup Customizable Highlight Groups Without Losing Previous Configuration
|
||||
ok 21 - Setup Ability to Change the Default Theme
|
||||
|
||||
# Success: 21
|
||||
ok 1 - Color Conversions Convert hex to RGB
|
||||
ok 2 - Color Conversions Convert RGB to hex
|
||||
ok 3 - Color Conversions Darken the color by percentage
|
||||
ok 4 - Color Conversions Lighten the color by percentage
|
||||
ok 5 - Color Conversions Blend colors
|
||||
ok 6 - Configuration Default configuration
|
||||
ok 7 - Configuration Unique configuration table instances
|
||||
ok 8 - Configuration Extend default configuration
|
||||
ok 9 - Initialization Loads without encountering any errors
|
||||
ok 10 - Initialization Background is set to light
|
||||
ok 11 - Palette Extend solarized color palette
|
||||
ok 12 - Palette Correct any invalid colors when extending the solarized palette
|
||||
ok 13 - Setup Customizing Highlight Groups
|
||||
ok 14 - Setup Changing Comment Style
|
||||
ok 15 - Setup Changing Function Style
|
||||
ok 16 - Setup Customizable Highlight Groups Without Losing Previous Configuration
|
||||
ok 17 - Setup Ability to Change the Default Theme
|
||||
1..17
|
||||
# Success: 17
|
||||
```
|
||||
|
||||
3. **Pull Request**: When submitting a pull request, select the `dev` branch
|
||||
|
|
@ -385,3 +375,7 @@ Ethan Schoonover
|
|||
- [tokyonight](https://github.com/folke/tokyonight.nvim)
|
||||
|
||||
[](https://github.com/glepnir)
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
*solarized.nvim.txt* For NVIM v0.9.1 Last change: 2023 December 20
|
||||
*solarized.nvim.txt* For NVIM v0.9.1 Last change: 2023 December 21
|
||||
|
||||
==============================================================================
|
||||
Table of Contents *solarized.nvim-table-of-contents*
|
||||
|
|
@ -324,12 +324,6 @@ COLORHELPER ~
|
|||
-- Convert a hex color code to RGB
|
||||
colorhelper.hex_to_rgb('#ffffff')
|
||||
|
||||
-- Convert RGB values to HSL
|
||||
colorhelper.rgb_to_hsl(255, 255, 255)
|
||||
|
||||
-- Convert HSL values to RGB
|
||||
colorhelper.hsl_to_rgb(0, 0, 100)
|
||||
|
||||
-- Darken a color by a specified percentage
|
||||
colorhelper.darken('#ffffff', 100)
|
||||
|
||||
|
|
@ -367,29 +361,25 @@ are installed for running tests:
|
|||
<
|
||||
|
||||
>bash
|
||||
ok 1 - Color Conversions Convert hex to RGB
|
||||
ok 2 - Color Conversions Convert RGB to hex
|
||||
ok 3 - Color Conversions Convert RGB to HSL
|
||||
ok 4 - Color Conversions Convert HSL to RGB
|
||||
ok 5 - Color Conversions Darken the color by percentage
|
||||
ok 6 - Color Conversions Lighten the color by percentage
|
||||
ok 7 - Color Conversions Blend colors
|
||||
ok 8 - Configuration Default configuration
|
||||
ok 9 - Configuration Unique configuration table instances
|
||||
ok 10 - Configuration Extend default configuration
|
||||
ok 11 - Initialization Loads without encountering any errors
|
||||
ok 12 - Initialization Background is set to light
|
||||
ok 13 - Math Round to the nearest integer
|
||||
ok 14 - Math Return the value of the first parameter and the sign of the second parameter
|
||||
ok 15 - Palette Extend solarized color palette
|
||||
ok 16 - Palette Correct any invalid colors when extending the solarized palette
|
||||
ok 17 - Setup Customizing Highlight Groups
|
||||
ok 18 - Setup Changing Comment Style
|
||||
ok 19 - Setup Changing Function Style
|
||||
ok 20 - Setup Customizable Highlight Groups Without Losing Previous Configuration
|
||||
ok 21 - Setup Ability to Change the Default Theme
|
||||
|
||||
# Success: 21
|
||||
ok 1 - Color Conversions Convert hex to RGB
|
||||
ok 2 - Color Conversions Convert RGB to hex
|
||||
ok 3 - Color Conversions Darken the color by percentage
|
||||
ok 4 - Color Conversions Lighten the color by percentage
|
||||
ok 5 - Color Conversions Blend colors
|
||||
ok 6 - Configuration Default configuration
|
||||
ok 7 - Configuration Unique configuration table instances
|
||||
ok 8 - Configuration Extend default configuration
|
||||
ok 9 - Initialization Loads without encountering any errors
|
||||
ok 10 - Initialization Background is set to light
|
||||
ok 11 - Palette Extend solarized color palette
|
||||
ok 12 - Palette Correct any invalid colors when extending the solarized palette
|
||||
ok 13 - Setup Customizing Highlight Groups
|
||||
ok 14 - Setup Changing Comment Style
|
||||
ok 15 - Setup Changing Function Style
|
||||
ok 16 - Setup Customizable Highlight Groups Without Losing Previous Configuration
|
||||
ok 17 - Setup Ability to Change the Default Theme
|
||||
1..17
|
||||
# Success: 17
|
||||
<
|
||||
|
||||
|
||||
|
|
@ -427,6 +417,10 @@ CREDITS AND REFERENCE 🎉 *solarized.nvim-credits-and-reference-🎉*
|
|||
|
||||
<https://github.com/glepnir>
|
||||
|
||||
>
|
||||
|
||||
<
|
||||
|
||||
==============================================================================
|
||||
1. Links *solarized.nvim-links*
|
||||
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
local M = {}
|
||||
|
||||
function M.copysign(x, y)
|
||||
if y > 0 or (y == 0 and math.atan2(y, -1) > 0) then
|
||||
return math.abs(x)
|
||||
else
|
||||
return -math.abs(x)
|
||||
end
|
||||
end
|
||||
|
||||
function M.round(x)
|
||||
local absx, y
|
||||
absx = math.abs(x)
|
||||
y = math.floor(absx)
|
||||
|
||||
if absx - y >= 0.5 then
|
||||
y = y + 1.0
|
||||
end
|
||||
|
||||
return M.copysign(y, x)
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
local Math = require('solarized.utils.Math')
|
||||
local M = {}
|
||||
|
||||
--- Convert a hexadecimal color code to RGB color values
|
||||
|
|
@ -25,140 +24,38 @@ function M.rgb_to_hex(red, green, blue)
|
|||
return string.format('#%02x%02x%02x', red, green, blue)
|
||||
end
|
||||
|
||||
--- Converts RGB (Red, Green, Blue) color values to HSL (Hue, Saturation, Lightness) color values.
|
||||
---
|
||||
--- @param r number The red component of the RGB color (0-255).
|
||||
--- @param g number The green component of the RGB color (0-255).
|
||||
--- @param b number The blue component of the RGB color (0-255).
|
||||
--- @return number h The hue value in degrees (0-360).
|
||||
--- @return number s The saturation value as a percentage (0-100).
|
||||
--- @return number l The lightness value as a percentage (0-100).
|
||||
function M.rgb_to_hsl(r, g, b)
|
||||
-- Convert RGB values to the range 0-1
|
||||
r = r / 255
|
||||
g = g / 255
|
||||
b = b / 255
|
||||
|
||||
-- Find the minimum and maximum values
|
||||
local min = math.min(r, g, b)
|
||||
local max = math.max(r, g, b)
|
||||
|
||||
-- Calculate luminance (L)
|
||||
local l = (max + min) / 2
|
||||
|
||||
-- Check if there is saturation
|
||||
local s
|
||||
if min == max then
|
||||
-- If min and max are equal, there is no saturation
|
||||
s = 0
|
||||
else
|
||||
if l <= 0.5 then
|
||||
s = (max - min) / (max + min)
|
||||
else
|
||||
s = (max - min) / (2 - max - min)
|
||||
end
|
||||
end
|
||||
|
||||
-- Calculate hue (H)
|
||||
local h
|
||||
if max == min then
|
||||
-- If max and min are equal, it's a shade of gray (H is undefined)
|
||||
h = 0
|
||||
else
|
||||
if max == r then
|
||||
h = (g - b) / (max - min)
|
||||
elseif max == g then
|
||||
h = 2 + (b - r) / (max - min)
|
||||
else
|
||||
h = 4 + (r - g) / (max - min)
|
||||
end
|
||||
h = h / 6 -- Convert to range 0-1
|
||||
if h < 0 then
|
||||
h = h + 1
|
||||
end -- Add 1 if negative
|
||||
end
|
||||
|
||||
-- Convert hue to degrees
|
||||
h = h * 360
|
||||
|
||||
return Math.round(h), Math.round(s * 100), Math.round(l * 100)
|
||||
end
|
||||
|
||||
--- Converts HSL (Hue, Saturation, Lightness) color values to RGB (Red, Green, Blue) color values.
|
||||
---
|
||||
--- @param h number The hue value in degrees (0-360).
|
||||
--- @param s number The saturation value as a percentage (0-100).
|
||||
--- @param l number The lightness value as a percentage (0-100).
|
||||
--- @return number red The red component of the RGB color (0-255).
|
||||
--- @return number green The green component of the RGB color (0-255).
|
||||
--- @return number blue The blue component of the RGB color (0-255).
|
||||
function M.hsl_to_rgb(h, s, l)
|
||||
h = h / 360
|
||||
s = s / 100
|
||||
l = l / 100
|
||||
|
||||
local function hueToRgb(p, q, t)
|
||||
if t < 0 then
|
||||
t = t + 1
|
||||
end
|
||||
if t > 1 then
|
||||
t = t - 1
|
||||
end
|
||||
if t < 1 / 6 then
|
||||
return p + (q - p) * 6 * t
|
||||
end
|
||||
if t < 1 / 2 then
|
||||
return q
|
||||
end
|
||||
if t < 2 / 3 then
|
||||
return p + (q - p) * (2 / 3 - t) * 6
|
||||
end
|
||||
return p
|
||||
end
|
||||
|
||||
if s == 0 then
|
||||
local gray = Math.round(l * 255)
|
||||
return gray, gray, gray
|
||||
else
|
||||
local q = l < 0.5 and l * (1 + s) or l + s - l * s
|
||||
local p = 2 * l - q
|
||||
|
||||
local red = Math.round(hueToRgb(p, q, h + 1 / 3) * 255)
|
||||
local green = Math.round(hueToRgb(p, q, h) * 255)
|
||||
local blue = Math.round(hueToRgb(p, q, h - 1 / 3) * 255)
|
||||
|
||||
return red, green, blue
|
||||
end
|
||||
end
|
||||
|
||||
--- Darken a color by a given percentage
|
||||
--- Darken a color by a given distance
|
||||
---
|
||||
--- @param color string The color to be darkened in any valid color format
|
||||
--- @param percent number The percentage by which the color should be darkened (between 0 and 100)
|
||||
--- @param percentage number The distance by which the color should be darkened (between 1 and 10)
|
||||
--- @return string color The resulting darkened color in the same format as the input color
|
||||
function M.darken(color, percent)
|
||||
local r, g, b = M.hex_to_rgb(color)
|
||||
local h, s, l = M.rgb_to_hsl(r, g, b)
|
||||
function M.darken(color, percentage)
|
||||
local red, green, blue = M.hex_to_rgb(color)
|
||||
local i = 1
|
||||
local result = {
|
||||
red = red * (1 - (percentage / 100) * i),
|
||||
green = green * (1 - (percentage / 100) * i),
|
||||
blue = blue * (1 - (percentage / 100) * i),
|
||||
}
|
||||
|
||||
l = l * (1 - percent / 100)
|
||||
|
||||
local new_r, new_g, new_b = M.hsl_to_rgb(h, s, l)
|
||||
return M.rgb_to_hex(new_r, new_g, new_b)
|
||||
return M.rgb_to_hex(result.red, result.green, result.blue)
|
||||
end
|
||||
|
||||
--- Lighten a color by a given percentage
|
||||
---
|
||||
--- @param color string The color to be lightened in any valid color format
|
||||
--- @param percent number The percentage by which the color should be lightened (between 0 and 100)
|
||||
--- @param percentage number The percentage by which the color should be lightened (between 1 and 10)
|
||||
--- @return string color The resulting lightened color in the same format as the input color
|
||||
function M.lighten(color, percent)
|
||||
local r, g, b = M.hex_to_rgb(color)
|
||||
local h, s, l = M.rgb_to_hsl(r, g, b)
|
||||
function M.lighten(color, percentage)
|
||||
local red, green, blue = M.hex_to_rgb(color)
|
||||
local i = 1
|
||||
local result = {
|
||||
red = red + (255 - red) * i * (percentage / 100),
|
||||
green = green + (255 - green) * i * (percentage / 100),
|
||||
blue = blue + (255 - blue) * i * (percentage / 100),
|
||||
}
|
||||
|
||||
l = l + (100 - l) * (percent / 100)
|
||||
|
||||
local new_r, new_g, new_b = M.hsl_to_rgb(h, s, l)
|
||||
return M.rgb_to_hex(new_r, new_g, new_b)
|
||||
return M.rgb_to_hex(result.red, result.green, result.blue)
|
||||
end
|
||||
|
||||
--- Blend two colors with a given alpha value
|
||||
|
|
|
|||
Loading…
Reference in a new issue