Global Lua Modules/Colors

Colors is a library for embedded color processing in the Fandom environment. It ports and extends functionality from the Colors JavaScript library from Pecoes.
== Features ==
* Color parameter support in Lua modules
* Color parameter insertion in wiki templates
* Color variable parsing for style templating
* Color item creation and conversion utilities
* A vast array of color processing methods
* Alpha and boolean support for flexible color logic
== Demo ==
This demo uses to render the color scheme.
== How to install ==
There are two components you can install:
=== Module ===
The module itself can be invoked globally with the following code:
local colors = require('Dev:Colors')
=== Template ===
=== Variables stylesheet ===
To install the CSS variables stylesheet:
Add the following text to your sandbox:
{{#tag:pre|{{colors|variables|s = 4}}}}
Copy the contents of the code block to MediaWiki:Variables.css.
Then follow these CSS installation instructions:
If you would prefer automatic updates (despite lower server-side efficiency, & potential security implications), you can use the following instructions.
== Usage ==
=== Example usage on a wiki ===
Rendered output on desktop:
=== Example usage in a Lua module ===
local colors = require("Dev:Colors")
mw.log(colors.fromHsl(214, 0.15, 0.8):string())
-- expected output '#414b58'
== Package members and methods ==
The following keys are exposed in the module package:
=== Template utilites ===
;colors.wikia
:Simple color parameter getter (list).
:This returns a color from the parameter table.
:Usage: {{colors|wikia|key}}
;colors.css
:Color parameter parser for inline styling.
:Usage: {{colors|css|styling}}
;colors.text
:Color generator for high-contrast text.
:Accounts for luminance when |lum=true.
:Usage: {{colors|text|background color|dark text color|light text color}}
;colors.variables
:CSS variables stylesheet generator.
:Arguments: s - optional whitespace flag.
:Usage: {{colors|variables|s = 4}}
=== Other library methods ===
;colors.instance
:Color instance test for Lua modules.
:Usage: colors.instance('#ffffff')
;colors.params
:Table of Fandom SASS colors for Lua modules (list).
:Usage: colors.params[string_key]
=== Color item creation ===
There are three ways to construct a new color in your Lua module:
;colors.fromRgb
:Color instance creation from RGB tuple.
:Fourth argument is optional alpha value (0-1).
:Usage: colors.fromRgb(255, 255, 255, 0.2)
;colors.fromHsl
:Color instance creation from HSL tuple.
:Fourth argument is optional alpha value (0-1).
:Usage: colors.fromHsl(0, 0, 1, 0.2)
;colors.parse
:Color parsing of any valid CSS color string.
:Usage: colors.parse('#ffffff')
== Color parameters ==
There are 23 parameters supported in the library. Request more in the talkpage. 
These can be accessed in three ways:
* colors.params table in your Lua module
* colors.wikia template method
* $parameter syntax in colors.css, colors.text and colors.parse
== Color items and methods ==
A newly constructed Color instance will store certain color data:
local color = colors.parse('cyan')
-- {table} color.tup Color tuple
mw.log(unpack(color.tup)) -- '0 255 255'
-- {string} color.typ Color type
mw.log(color.tup) -- 'rgb'
-- {string} color.alp Color alpha channel
mw.log(color.alp) -- 1
Some color methods are also available.
=== Property getter-setter methods ===
These methods retrieve or override color properties. (* = optional)
Method 	Purpose 	Parameters
Color:red 	red color value 	setter value* (1-255)
Color:green	green color value 	setter value* (1-255)
Color:blue 	blue color value 	setter value* (1-255)
Color:hue 	hue color value 	setter value* (0-360)
Color:sat 	saturation color value	setter value* (0-100)
Color:lum 	lightness value 	setter value* (0-100)
Color:alpha	alpha value 	setter value* (0-100)
=== Processing methods ===
These methods are for post-processing color operations. (* = optional)
Method 	Purpose 	Parameters
Color:rotate 	color rotation by degree	cycle value (0 to 360)
Color:saturate 	color saturation change 	modifier (-100 to 100)
Color:lighten* 	color lightness change 	modifier (-100 to 100)
Color:opacify 	color alpha change 	modifier (-100 to 100)
Color:mix 	
* mixing with other color items or strings
* note: this is reverse weighted
colors.parse('#fff')
 :mix('#000', 80):hex()
 -- outputs '#cccccc'	
* 1: CSS color string, or Color
* 2: weight* (0 to 100; def. 50)
Color:invert 	inversion of color item 	N/A
Color:complement	complement of color item	N/A
=== Conditionals for color logic ===
These methods return a boolean for use in Lua logic. (* = optional)
Method 	Purpose 	Parameters
Color:bright 	brightness status for color item 	limit* (1-100)
Color:luminant 	luminance status for color item 	limit* (1-100)
Color:chromatic	color saturation and visibility status	N/A
=== Output methods ===
These methods return a valid CSS color string.
Method 	Purpose 	Format
Color:hex 	hexadecimal RGB string output 	'#RRGGBB(AA)'
Color:rgb 	RGB(A) functional string 	'rgb(#,#,#)'
Color:hsl 	HSL(A) functional string 	'hsl(#,#%,#%)'
Color:string	hexadecimal or HSLA string string	'#RRGGBB'/'hsla(#,#%,#%,#)'