Module:Color contrast:修订间差异

删除的内容 添加的内容
enwiki>Axolitl
Implement edit request, for real this time
标签:已被回退
CaelLab-import​(留言 | 贡献)
huifu bei enwiki daoru dingti de banben (shangyiban zhwiki>Xiplus-abot)
标签:手工回退
 
第1行:
--
-- This module implements
-- {{Color contrast ratio}}
-- {{Greater color contrast ratio}}
-- {{ColorToLum}}
-- {{RGBColorToLum}}
--
local p = {}
第82行:
end
 
-- convert from hsl / hsla (accepts comma or space delimiters)
if mw.ustring.match(c,'^hsla?hsl%([%s]*[0-9][0-9%.]*[%s]*[,%s][%s]*[0-9][0-9%.]*%%[%s]*[,%s][%s]*[0-9][0-9%.]*%%.[%s]*%)$') then
local h, s, l = mw.ustring.match(c,'^hsla?hsl%([%s]*([0-9][0-9%.]*)[%s]*[,%s][%s]*([0-9][0-9%.]*)%%[%s]*[,%s][%s]*([0-9][0-9%.]*)%%.[%s]*%)$')
return hsl2lum(tonumber(h), tonumber(s)/100, tonumber(l)/100)
end
 
-- convert from rgb / rgba (numeric values 0 to 255)
if mw.ustring.match(c,'^rgba?rgb%([%s]*[0-9][0-9]*[%s]*[,%s][%s]*[0-9][0-9]*[%s]*[,%s][%s]*[0-9][0-9]*.[%s]*%)$') then
local R, G, B = mw.ustring.match(c,'^rgba?rgb%([%s]*([0-9][0-9]*)[%s]*[,%s][%s]*([0-9][0-9]*)[%s]*[,%s][%s]*([0-9][0-9]*).[%s]*%)$')
return rgbdec2lum(tonumber(R), tonumber(G), tonumber(B))
end
 
-- convert from rgb / rgba percent
if mw.ustring.match(c,'^rgba?rgb%([%s]*[0-9][0-9%.]*%%[%s]*[,%s][%s]*[0-9][0-9%.]*%%[%s]*[,%s][%s]*[0-9][0-9%.]*%%.[%s]*%)$') then
local R, G, B = mw.ustring.match(c,'^rgba?rgb%([%s]*([0-9][0-9%.]*)%%[%s]*[,%s][%s]*([0-9][0-9%.]*)%%[%s]*[,%s][%s]*([0-9][0-9%.]*)%%.[%s]*%)$')
return rgbdec2lum(255*tonumber(R)/100, 255*tonumber(G)/100, 255*tonumber(B)/100)
end
第105行:
-- split into rgb
local cs = mw.text.split(c or '', '')
if( #cs == 6 or #cs == 8 ) then -- Accepts 6 digits (#RRGGBB) or 8 digits (#RRGGBBAA)
local R = 16*tonumber('0x' .. cs[1]) + tonumber('0x' .. cs[2])
local G = 16*tonumber('0x' .. cs[3]) + tonumber('0x' .. cs[4])
第111行:
 
return rgbdec2lum(R, G, B)
elseif ( #cs == 3 or #cs == 4 ) then -- Accepts 3 digits (#RGB) or 4 digits (#RGBA)
local R = 16*tonumber('0x' .. cs[1]) + tonumber('0x' .. cs[1])
local G = 16*tonumber('0x' .. cs[2]) + tonumber('0x' .. cs[2])
第133行:
local css = (args['css'] and args['css'] ~= '') and true or false
local v1 = color2lum(args[1] or '')
local c2 = args[2] or 'white#FFFFFF'
local v2 = color2lum(c2)
local c3 = args[3] or 'black#000000'
local v3 = color2lum(c3)
local ratio1 = -1;
第150行:
if css then
local c1 = args[1] or ''
if stringmw.ustring.match(c1, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]?$') or
stringmw.ustring.match(c1, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]?[A-Fa-f0-9]?$') then
c1 = '#' .. c1
end
if stringmw.ustring.match(c2, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]?$') or
stringmw.ustring.match(c2, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]?[A-Fa-f0-9]?$') then
c2 = '#' .. c2
end
if stringmw.ustring.match(c3v3, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]?$') or
stringmw.ustring.match(c3v3, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]?[A-Fa-f0-9]?$') then
c3 = '#' .. c3
end
第184行:
function p._styleratio(args)
local style = (args[1] or ''):lower()
local bg, fg = 'white', 'black'
local lum_bg, lum_fg = 1, 0
 
if args[2] then
local lum = color2lum(args[2])
if lum ~= '' then bg, lum_bg = args[2], lum end
end
if args[3] then
local lum = color2lum(args[3])
if lum ~= '' then fg, lum_fg = args[3], lum end
end
 
第198行 ⟶ 第199行:
for k = 1,#slist do
local s = slist[k]
local propk, valv = s:match( '^[%s]*([^:]-):([^:]-)[%s;]*$' )
propk = propk or ''
valv = valv or ''
if (propk:match('^[%s]*(background)[%s]*$') or propk:match('^[%s]*(background%-color)[%s]*$')) then
local lum = color2lum(valv)
if( lum ~= '' ) then bg, lum_bg = v, lum end
elseif (propk:match('^[%s]*(color)[%s]*$')) then
local lum = color2lum(valv)
if( lum ~= '' ) then bg, lum_fg = v, lum end
end
end
第221行 ⟶ 第222行:
 
Parameters:
-- |1= — required; A color to check.
--]]
function p.lum(frame)