Module:Color contrast: Difference between revisions
Content deleted Content added
synced changes from sandbox - created an access point to lum available to other modules |
m 49 revisions imported from wikipedia:Module:Color_contrast |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1:
--
-- This module implements
-- {{Color contrast ratio}}
-- {{Greater color contrast ratio}}
Line 9:
local HTMLcolor = mw.loadData( 'Module:Color contrast/colors' )
local function sRGB (v)
if (v <= 0.03928) then
v = v / 12.92
else
Line 56:
return ''
end
end▼
-- This exports the function for use in other modules.▼
-- The colour is passed as a string.▼
function p._lum(color)▼
return color2lum(color)▼
end
Line 88 ⟶ 82:
end
local h, s, l = mw.ustring.match(c,'^hsl%([%s]*([0-9][0-9%.]*)[%s]*,[%s]*([0-9][0-9%.]*)%%[%s]*,[%s]*([0-9][0-9%.]*)%%[%s]*%)$')
return hsl2lum(tonumber(h), tonumber(s)/100, tonumber(l)/100)
local R, G, B = mw.ustring.match(c,'^rgb%([%s]*([0-9][0-9]*)[%s]*,[%s]*([0-9][0-9]*)[%s]*,[%s]*([0-9][0-9]*)[%s]*%)$')
return rgbdec2lum(tonumber(R), tonumber(G), tonumber(B))
local R, G, B = mw.ustring.match(c,'^rgb%([%s]*([0-9][0-9%.]*)%%[%s]*,[%s]*([0-9][0-9%.]*)%%[%s]*,[%s]*([0-9][0-9%.]*)%%[%s]*%)$')
return rgbdec2lum(255*tonumber(R)/100, 255*tonumber(G)/100, 255*tonumber(B)/100)
-- remove leading # (if there is one) and whitespace
Line 127 ⟶ 121:
-- failure, return blank
return ''
▲end
▲-- This exports the function for use in other modules.
▲-- The colour is passed as a string.
▲function p._lum(color)
▲ return color2lum(color)
end
Line 147:
ratio2 = (ratio2 < 1) and 1/ratio2 or ratio2
end
if css then
local c1 = args[1] or ''
Line 164:
return 'background-color:' .. c1 .. '; color:' .. ((ratio1 > 0) and (ratio2 > 0) and ((ratio1 + bias > ratio2) and c2 or c3) or '') .. ';'
end
return (ratio1 > 0) and (ratio2 > 0) and ((ratio1 + bias > ratio2) and c2 or c3) or ''
end
Line 218:
--[[
Use {{#invoke:Color contrast|somecolor}} directly or
{{#invoke:Color contrast}} from a wrapper template.
|