Module colorizer.color

Helper functions to parse different colour formats

Functions

argb_hex_parser (line, i) parse for 0xaarrggbb and return rgb hex.
hsl_to_rgb (h, s, l) Converts an HSL color value to RGB.
hsl_function_parser (line, i, opts) Parse for hsl() hsla() css function and return rgb hex.
hue_to_rgb (p, q, t) Convert hsl colour values to rgb.
is_bright (r, g, b) Determine whether to use black or white text.
name_parser (line, i, opts) Grab all the colour values from vim.api.nvim_get_color_map and create a lookup table.
rgb_function_parser (line, i) Parse for rgb() css function and return rgb hex.
rgba_function_parser (line, i) Parse for rgba() css function and return rgb hex.
rgba_hex_parser (line, i, opts) parse for #rrggbbaa and return rgb hex.


Functions

argb_hex_parser (line, i)
parse for 0xaarrggbb and return rgb hex. a format used in android apps

Parameters:

  • line string: line to parse
  • i number: index of line from where to start parsing

Returns:

  1. number|nil: index of line where the hex value ended
  2. string|nil: rgb hex value
hsl_to_rgb (h, s, l)
Converts an HSL color value to RGB.

Parameters:

  • h number: Hue
  • s number: Saturation
  • l number: Lightness

Returns:

    number|nil,number|nil,number|nil
hsl_function_parser (line, i, opts)
Parse for hsl() hsla() css function and return rgb hex. For more info: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/hsl

Parameters:

  • line string: Line to parse
  • i number: Index of line from where to start parsing
  • opts table: Values passed from matchers like prefix

Returns:

  1. number|nil: Index of line where the hsla/hsl function ended
  2. string|nil: rgb hex value
hue_to_rgb (p, q, t)
Convert hsl colour values to rgb. Source: https://gist.github.com/mjackson/5311256

Parameters:

  • p number
  • q number
  • t number

Returns:

    number
is_bright (r, g, b)
Determine whether to use black or white text.

ref: https://stackoverflow.com/a/1855903/837964 https://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color

Parameters:

  • r number: Red
  • g number: Green
  • b number: Blue
name_parser (line, i, opts)
Grab all the colour values from vim.api.nvim_get_color_map and create a lookup table. COLOR_MAP is used to store the colour values

Parameters:

  • line string: Line to parse
  • i number: Index of line from where to start parsing
  • opts table: Currently contains whether tailwind is enabled or not
rgb_function_parser (line, i)
Parse for rgb() css function and return rgb hex.

Parameters:

  • line string: Line to parse
  • i number: Index of line from where to start parsing

Returns:

  1. number|nil: Index of line where the rgb function ended
  2. string|nil: rgb hex value
rgba_function_parser (line, i)
Parse for rgba() css function and return rgb hex. Todo consider removing the regexes here Todo this might not be the best approach to alpha channel. Things like pumblend might be useful here.

Parameters:

  • line string: Line to parse
  • i number: Index of line from where to start parsing

Returns:

  1. number|nil: Index of line where the rgba function ended
  2. string|nil: rgb hex value
rgba_hex_parser (line, i, opts)
parse for #rrggbbaa and return rgb hex. a format used in android apps

Parameters:

  • line string: line to parse
  • i number: index of line from where to start parsing
  • opts table: Containing minlen, maxlen, valid_lengths

Returns:

  1. number|nil: index of line where the hex value ended
  2. string|nil: rgb hex value
generated by LDoc 1.4.6 Last updated - February