跳转到内容
打开/关闭搜索
搜索
打开/关闭菜单
5
条目
6
文件
13
用户
665
编辑
久远澪Wiki
导航
首页
最近更改
随机页面
MediaWiki帮助
特殊页面
打开/关闭外观设置菜单
无法加载偏好设置。请检查您的网络连接并重试。
重试
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。
user-interface-preferences
个人工具
创建账号
登录
查看“︁Module:TextEffect”︁的源代码
来自久远澪Wiki
查看
阅读
查看源代码
查看历史
associated-pages
模块
讨论
更多操作
更多
工具
链入页面
相关更改
页面信息
←
Module:TextEffect
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
此页面已受到保护,不能编辑,因为它被嵌入以下开启“连锁保护”选项的页面:*
首页
您可以查看和复制此页面的源代码。
-- Module:TextEffect -- 解析文字背景效果串(如「毛玻璃+遮罩」「阴影 + 遮罩」「遮罩+毛玻璃」), -- 顺序无关、容忍空格,输出 CSS 类名(.text-bg-*)。 -- -- 函数: -- p.class(frame) 输出类名:{{#invoke:TextEffect|class|毛玻璃+遮罩+阴影}} -- p.text(frame) 渲染多段文字背景(由 Template:文字背景 调用): -- 位置1=默认效果,位置2..N=各段内容; -- 第 N 段(位置 N+1)可用 效果N/颜色N/浅色N/深色N/透明度N 覆盖。 -- 兼容单段命名用法:效果=...|内容=... local p = {} -- 效果名 → 类名(支持常见别名) local classMap = { ['毛玻璃'] = 'text-bg-glass', ['玻璃'] = 'text-bg-glass', ['遮罩'] = 'text-bg-mask', ['阴影'] = 'text-bg-shadow', } -- 效果串 → 类名串(含 .text-bg 前缀;去重、排序稳定) local function buildClasses(raw) if not raw then raw = '' end 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 -- 输出类名 function p.class(frame) local raw = frame.args[1] or frame.args['效果'] or frame.args['effect'] or '' return buildClasses(raw) end -- 渲染多段文字背景(供模板使用,取父帧全部参数) function p.text(frame) local args = (frame:getParent() and frame:getParent().args) or frame.args local defaultEffect = args['效果'] or args[1] or '' -- 收集段:位置 2..N 为各段内容;若无位置段但给了「内容」则作为单段 local segs = {} local i = 2 while args[i] and args[i] ~= '' do table.insert(segs, { content = args[i], idx = i }) i = i + 1 end if #segs == 0 and args['内容'] and args['内容'] ~= '' then table.insert(segs, { content = args['内容'], idx = 0 }) end if #segs == 0 then return '' end local out = {} for _, seg in ipairs(segs) do -- 段号:位置 N+1 → 第 N 段(覆盖参数为 效果N 等);命名「内容」段无编号 local n = seg.idx >= 2 and (seg.idx - 1) or 0 local getN = function(prefix) if n > 0 then local v = args[prefix .. n] if v and v ~= '' then return v end end return args[prefix] end local effect = getN('效果') if not effect or effect == '' then effect = defaultEffect end local cls = buildClasses(effect) local style = {} local function add(var, val) if val and val ~= '' then table.insert(style, var .. ':' .. val .. ';') end end add('--text-bg-color', getN('颜色')) add('--text-bg-color-light', getN('浅色')) add('--text-bg-color-night', getN('深色')) add('--text-bg-opacity', getN('透明度')) local span = '<span class="' .. cls .. '"' if #style > 0 then span = span .. ' style="' .. table.concat(style, '') .. '"' end span = span .. '>' .. seg.content .. '</span>' table.insert(out, span) end return table.concat(out, '<br/>') end return p
此页面嵌入的页面:
Module:TextEffect/doc
(
查看源代码
)
返回
Module:TextEffect
。
查看“︁Module:TextEffect”︁的源代码
来自久远澪Wiki