Scribunto library for embedded color processing in the Fandom environment (extended documentation).
This Lua project is a direct port of https://dev.wikia.com/wiki/Colors (a JavaScript library by Pecoes), with support for alpha values.
A full author history of the original JS library is here:
https://dev.wikia.com/wiki/MediaWiki:Colors/code.js?action=history
Credit to many Dev Wiki translators! https://dev.wikia.com/wiki/Module:Colors/i18n?action=history
- If you are on Fandom, see the Dev Wiki installation guidance.
- If you are on a external MediaWiki instance:
- Create Module:Colors with the contents of
colors.lua
. - Create Module:Colors/testcases with the contents of
tests.lua
. - Create Module:Colors/i18n with the contents of
i18n.lua
. - Create Template:Colors with the contents of
colors.mediawiki
. - Create Template:Colors/doc with the contents of
docs.mediawiki
. - Install Module:I18n v1.3.3 and Module:Testharness v2.0.5 on your wiki.
- Create Module:Colors with the contents of
local colors = require("Dev:Colors")
The following keys are exposed in the module package:
colors.main
- template wrapper functioncolors.wikia
- template utility for accessing CSS colorscolors.css
- template utility for Fandom CSS $parameter supportcolors.text
- template utility for high contrast text colorscolors.variables
- template utility for CSS variables stylesheet generationcolors.fromRgb
- color item creation from RGB tuplecolors.fromHsl
- color item creation from HSL tuplecolors.parse
- color parsing of any valid CSS color stringcolors.instance
- color instance testcolors.params
- table of Fandom SASS colors for Lua modules
Example usage on a wiki:
<div style="{{#invoke:colors|css|1px solid $color-community-header}}"></div>
Example usage in a Lua module
local colors = require("Dev:Colors")
mw.log(colors.fromHsl(0.18, 74, 87):string())
These methods retrieve or override color properties. They accept a optional value parameter.
Color:red
- red color value (1-255)Color:green
- green color value (1-255)Color:blue
- blue color value (1-255)Color:hue
- hue color value (0-360)Color:sat
- saturation color value (0-100)Color:lum
- luminosity value (0-100)Color:alpha
- alpha value (0-100)
The methods marked * accept one optional modifier value parameter.
Color:rotate
* - color rotation by degree (0 to 360)Color:saturate
* - color saturation change by modifier (-100 to 100)Color:lighten
* - color lightness change by modifier (-100 to 100)Color:opacify
* - color alpha change by modifier (-100 to 100)Color:mix
- mixing with other color items or strings (scaled by 100, reverse weighted)
colors.parse('#fff'):mix('#000', 80):hex() -- outputs '#cccccc'
Color:invert
- inversion of color itemColor:complement
- complement of color item
These methods return a valid CSS color string.
Color:hex
- hexadecimal RGB string output (#RRGGBB(AA)
)Color:rgb
- RGB(A) functional string output (rgb(#,#%,#%)
)Color:hsl
- HSL(A) functional string output (hsl(#,#%,#%)
)Color:string
- hexadecimal or HSLA string string output (#RRGGBB
/hsla(#,#%,#%,#)
)
These methods return a boolean for use in Lua logic.
Color:bright
- brightness status for color item (accepts optional 1-100 limit parameter)Color:luminant
- luminance status for color item (accepts optional 1-100 limit parameter)Color:chromatic
- color saturation and visibility status for color item