Module:TextEffect
来自久远澪Wiki
更多操作
此模块的文档可以在Module:TextEffect/doc创建
-- Module:TextEffect
-- 解析文字背景效果串(如「毛玻璃+遮罩」「阴影 + 遮罩」「遮罩+毛玻璃」),
-- 顺序无关、容忍空格,输出 CSS 类名(.text-bg-*)。
-- 用法:{{#invoke:TextEffect|class|毛玻璃+遮罩+阴影}}
local p = {}
-- 效果名 → 类名(支持常见别名)
local classMap = {
['毛玻璃'] = 'text-bg-glass',
['玻璃'] = 'text-bg-glass',
['遮罩'] = 'text-bg-mask',
['阴影'] = 'text-bg-shadow',
}
-- 输出类名(含 .text-bg 前缀;去重、排序稳定)
function p.class(frame)
local raw = frame.args[1] or frame.args['效果'] or frame.args['effect'] or ''
local seen = {}
for part in raw:gmatch('[^%+]+') do
local name = part:gsub('^%s+', ''):gsub('%s+$', '')
local cls = classMap[name]
if cls then
seen[cls] = true
end
end
local out = { 'text-bg' }
for cls in pairs(seen) do
table.insert(out, cls)
end
table.sort(out)
return table.concat(out, ' ')
end
return p