Skip to content

speeditor/colorsmw

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

94 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub release Lua UnitTests Codacy Badge

colorsmw

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

Installation

  • If you are on Fandom, see the Dev Wiki installation guidance.
  • If you are on a external MediaWiki instance:
    1. Create Module:Colors with the contents of colors.lua.
    2. Create Module:Colors/testcases with the contents of tests.lua.
    3. Create Module:Colors/i18n with the contents of i18n.lua.
    4. Create Template:Colors with the contents of colors.mediawiki.
    5. Create Template:Colors/doc with the contents of docs.mediawiki.
    6. Install Module:I18n v1.3.3 and Module:Testharness v2.0.5 on your wiki.

Usage

local colors = require("Dev:Colors")

Package members and methods

The following keys are exposed in the module package:

  • colors.main - template wrapper function
  • colors.wikia - template utility for accessing CSS colors
  • colors.css - template utility for Fandom CSS $parameter support
  • colors.text - template utility for high contrast text colors
  • colors.variables - template utility for CSS variables stylesheet generation
  • colors.fromRgb - color item creation from RGB tuple
  • colors.fromHsl - color item creation from HSL tuple
  • colors.parse - color parsing of any valid CSS color string
  • colors.instance - color instance test
  • colors.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())

Color item methods

Property getter-setter methods

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)

Processing methods

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 item
  • Color:complement - complement of color item

Output methods

These methods return a valid CSS color string.

Conditionals for color logic

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

About

Scribunto library for Fandom color processing, written in Lua.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages