文本:修订间差异
来自卡厄思梦境WIKI
创建页面,内容为“local p = {} local colorMap = { ['红'] = '#ff4d4d', ['蓝'] = '#7be3fd', ['绿'] = '#a8f428', ['黄'] = '#ffe44d', ['橙'] = '#ed9703', ['粉'] = '#ffb3d9', ['灰'] = '#a0a0a0', ['热情'] = '#db3762', ['正义'] = '#2c8fd8', ['秩序'] = '#21bf80', ['本能'] = '#eda000', ['虚无'] = '#9900ff', } local function resolveColor(color) if not color or color == '' then return n…” |
小 将描边相关的重置与应用逻辑,改为直接注入内联 style |
||
| 第43行: | 第43行: | ||
local classes = { 'text-style' } | local classes = { 'text-style' } | ||
local styles = {} | local styles = { | ||
'-webkit-text-stroke: 0;', | |||
'paint-order: normal;' | |||
} | |||
local colorVal = resolveColor(color) | local colorVal = resolveColor(color) | ||
| 第69行: | 第72行: | ||
end | end | ||
local html = '<span class="' .. table.concat(classes, ' ') .. '" | local html = '<span class="' .. table.concat(classes, ' ') .. '" style="' .. table.concat(styles, ' ') .. '">' .. content .. '</span>' | ||
return html | return html | ||
end | end | ||
return p | return p | ||
2026年8月1日 (六) 16:10的最新版本
此模块的文档可以在模块:文本/doc创建
local p = {}
local colorMap = {
['红'] = '#ff4d4d',
['蓝'] = '#7be3fd',
['绿'] = '#a8f428',
['黄'] = '#ffe44d',
['橙'] = '#ed9703',
['粉'] = '#ffb3d9',
['灰'] = '#a0a0a0',
['热情'] = '#db3762',
['正义'] = '#2c8fd8',
['秩序'] = '#21bf80',
['本能'] = '#eda000',
['虚无'] = '#9900ff',
}
local function resolveColor(color)
if not color or color == '' then
return nil
end
if colorMap[color] then
return colorMap[color]
end
local hex = color
if string.sub(hex, 1, 1) ~= '#' then
hex = '#' .. hex
end
if string.match(hex, '^#[0-9a-fA-F]{3}$') or string.match(hex, '^#[0-9a-fA-F]{6}$') then
return hex
end
return color
end
function p.main(frame)
local args = frame:getParent().args
local color = args['颜色'] or ''
local stroke = args['描边'] or ''
local underline = args['下划线'] or ''
local italic = args['斜体'] or ''
local content = args[1] or ''
local classes = { 'text-style' }
local styles = {
'-webkit-text-stroke: 0;',
'paint-order: normal;'
}
local colorVal = resolveColor(color)
if colorVal then
table.insert(classes, 'text-style--colored')
table.insert(styles, 'color: ' .. colorVal .. ';')
end
local strokeVal = resolveColor(stroke)
if strokeVal then
table.insert(classes, 'text-style--stroked')
table.insert(styles, '-webkit-text-stroke: 1px ' .. strokeVal .. ';')
table.insert(styles, 'paint-order: stroke fill;')
if not colorVal then
table.insert(styles, 'color: #fff;')
end
end
if underline ~= '' then
table.insert(classes, 'text-style--underline')
end
if italic ~= '' then
table.insert(classes, 'text-style--italic')
end
local html = '<span class="' .. table.concat(classes, ' ') .. '" style="' .. table.concat(styles, ' ') .. '">' .. content .. '</span>'
return html
end
return p