<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh">
	<id>https://9on0wiki.gunmu.dns.navy/index.php?action=history&amp;feed=atom&amp;title=Module%3AColorRGB</id>
	<title>Module:ColorRGB - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://9on0wiki.gunmu.dns.navy/index.php?action=history&amp;feed=atom&amp;title=Module%3AColorRGB"/>
	<link rel="alternate" type="text/html" href="https://9on0wiki.gunmu.dns.navy/index.php?title=Module:ColorRGB&amp;action=history"/>
	<updated>2026-08-28T18:35:02Z</updated>
	<subtitle>本wiki上该页面的版本历史</subtitle>
	<generator>MediaWiki 1.46.0</generator>
	<entry>
		<id>https://9on0wiki.gunmu.dns.navy/index.php?title=Module:ColorRGB&amp;diff=778&amp;oldid=prev</id>
		<title>DoubleCircle：​&quot;展示卡片完善&quot;</title>
		<link rel="alternate" type="text/html" href="https://9on0wiki.gunmu.dns.navy/index.php?title=Module:ColorRGB&amp;diff=778&amp;oldid=prev"/>
		<updated>2026-08-28T09:13:47Z</updated>

		<summary type="html">&lt;p&gt;&amp;quot;展示卡片完善&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;-- Module:ColorRGB&lt;br /&gt;
-- 主题色 RGB 分量计算器：从 MediaWiki:Common.css 载入主题色 hex，计算 r/g/b 分量，&lt;br /&gt;
-- 输出 CSS 变量声明。颜色单一来源 = common.css 的 --color-* 变量（本模块不重复定义，&lt;br /&gt;
-- 改色只需改 common.css）。读取 common.css 失败时回退到内置默认色表。&lt;br /&gt;
-- 用法：&lt;br /&gt;
--   {{#invoke:ColorRGB|cardVars}} → 卡片所需两套分量（*-light/*-night），模板内联到 style&lt;br /&gt;
--   {{#invoke:ColorRGB|light}} / {{#invoke:ColorRGB|night}} → 输出整套分量&lt;br /&gt;
--   {{#invoke:ColorRGB|rgb|theme-soft}} → 输出单个颜色分量&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
-- 内置默认色表（仅当 common.css 读取失败时回退；正常以 common.css 为准）&lt;br /&gt;
local fallbackLight = {&lt;br /&gt;
	[&amp;#039;theme-soft&amp;#039;]     = &amp;#039;#F9FCF4&amp;#039;,&lt;br /&gt;
	[&amp;#039;theme&amp;#039;]          = &amp;#039;#F1F8E6&amp;#039;,&lt;br /&gt;
	[&amp;#039;theme-deep&amp;#039;]     = &amp;#039;#E0EFD0&amp;#039;,&lt;br /&gt;
	[&amp;#039;primary&amp;#039;]        = &amp;#039;#8FBC8F&amp;#039;,&lt;br /&gt;
	[&amp;#039;primary-deep&amp;#039;]   = &amp;#039;#2E6B45&amp;#039;,&lt;br /&gt;
	[&amp;#039;accent&amp;#039;]         = &amp;#039;#E8B96A&amp;#039;,&lt;br /&gt;
	[&amp;#039;accent-deep&amp;#039;]    = &amp;#039;#8A5A1E&amp;#039;,&lt;br /&gt;
	[&amp;#039;accent-bg&amp;#039;]      = &amp;#039;#FFF8EF&amp;#039;,&lt;br /&gt;
	[&amp;#039;accent-bg-soft&amp;#039;] = &amp;#039;#FDF2E3&amp;#039;,&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
-- 深色默认色表（回退用）&lt;br /&gt;
local fallbackNight = {&lt;br /&gt;
	[&amp;#039;theme-soft&amp;#039;]     = &amp;#039;#232D1D&amp;#039;,&lt;br /&gt;
	[&amp;#039;theme&amp;#039;]          = &amp;#039;#1D2618&amp;#039;,&lt;br /&gt;
	[&amp;#039;theme-deep&amp;#039;]     = &amp;#039;#303D2A&amp;#039;,&lt;br /&gt;
	[&amp;#039;primary&amp;#039;]        = &amp;#039;#7FAA85&amp;#039;,&lt;br /&gt;
	[&amp;#039;primary-deep&amp;#039;]   = &amp;#039;#A9CFAE&amp;#039;,&lt;br /&gt;
	[&amp;#039;accent&amp;#039;]         = &amp;#039;#E0A85C&amp;#039;,&lt;br /&gt;
	[&amp;#039;accent-deep&amp;#039;]    = &amp;#039;#F0C48A&amp;#039;,&lt;br /&gt;
	[&amp;#039;accent-bg&amp;#039;]      = &amp;#039;#2E2719&amp;#039;,&lt;br /&gt;
	[&amp;#039;accent-bg-soft&amp;#039;] = &amp;#039;#382D1C&amp;#039;,&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
-- 需要的颜色名（对应 common.css 的 --color-&amp;lt;name&amp;gt;）&lt;br /&gt;
local colorNames = {&lt;br /&gt;
	&amp;#039;theme-soft&amp;#039;, &amp;#039;theme&amp;#039;, &amp;#039;theme-deep&amp;#039;,&lt;br /&gt;
	&amp;#039;primary&amp;#039;, &amp;#039;primary-deep&amp;#039;,&lt;br /&gt;
	&amp;#039;accent&amp;#039;, &amp;#039;accent-deep&amp;#039;, &amp;#039;accent-bg&amp;#039;, &amp;#039;accent-bg-soft&amp;#039;,&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
-- 从 MediaWiki:Common.css 读取内容（Scribunto 依赖追踪会自动使其在编辑后失效）&lt;br /&gt;
local function getCss()&lt;br /&gt;
	local title = mw.title.new(&amp;#039;MediaWiki:Common.css&amp;#039;)&lt;br /&gt;
	return (title and title.getContent and title:getContent()) or &amp;#039;&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- 提取选择器后第一个 {...} 块内的 CSS 变量（--name: value;）&lt;br /&gt;
local function extractVars(css, selector)&lt;br /&gt;
	local vars = {}&lt;br /&gt;
	local start = css:find(selector, 1, true)&lt;br /&gt;
	if not start then return vars end&lt;br /&gt;
	local open = css:find(&amp;#039;{&amp;#039;, start)&lt;br /&gt;
	if not open then return vars end&lt;br /&gt;
	local close = css:find(&amp;#039;}&amp;#039;, open)&lt;br /&gt;
	if not close then return vars end&lt;br /&gt;
	for name, value in css:sub(open + 1, close - 1):gmatch(&amp;#039;%-%-([%w-]+)%s*:%s*([^;]+);&amp;#039;) do&lt;br /&gt;
		vars[name] = value:gsub(&amp;#039;^%s+&amp;#039;, &amp;#039;&amp;#039;):gsub(&amp;#039;%s+$&amp;#039;, &amp;#039;&amp;#039;)&lt;br /&gt;
	end&lt;br /&gt;
	return vars&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- 从 common.css 载入浅色/深色 palette（缺失/非法 hex 时回退内置）&lt;br /&gt;
local function getPalette(css, selector, fallback)&lt;br /&gt;
	local vars = extractVars(css, selector)&lt;br /&gt;
	local pal = {}&lt;br /&gt;
	for _, name in ipairs(colorNames) do&lt;br /&gt;
		local v = vars[&amp;#039;color-&amp;#039; .. name]&lt;br /&gt;
		if v and v:match(&amp;#039;^#%x+$&amp;#039;) then&lt;br /&gt;
			pal[name] = v&lt;br /&gt;
		else&lt;br /&gt;
			pal[name] = fallback[name]&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return pal&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- 模块级缓存（同一次页面解析内多次 invoke 复用）&lt;br /&gt;
local lightPal, nightPal&lt;br /&gt;
local function palettes()&lt;br /&gt;
	if not lightPal then&lt;br /&gt;
		local css = getCss()&lt;br /&gt;
		lightPal = getPalette(css, &amp;#039;:root&amp;#039;, fallbackLight)&lt;br /&gt;
		nightPal = getPalette(css, &amp;#039;html.skin-theme-clientpref-night&amp;#039;, fallbackNight)&lt;br /&gt;
	end&lt;br /&gt;
	return lightPal, nightPal&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- hex → r,g,b（支持 #RGB 与 #RRGGBB）&lt;br /&gt;
local function hexToRgb(hex)&lt;br /&gt;
	hex = (hex or &amp;#039;&amp;#039;):gsub(&amp;#039;#&amp;#039;, &amp;#039;&amp;#039;):lower()&lt;br /&gt;
	if #hex == 3 then&lt;br /&gt;
		hex = hex:gsub(&amp;#039;.&amp;#039;, function(c) return c .. c end)&lt;br /&gt;
	end&lt;br /&gt;
	if #hex ~= 6 then&lt;br /&gt;
		return 0, 0, 0&lt;br /&gt;
	end&lt;br /&gt;
	return tonumber(hex:sub(1, 2), 16),&lt;br /&gt;
		tonumber(hex:sub(3, 4), 16),&lt;br /&gt;
		tonumber(hex:sub(5, 6), 16)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- 单个颜色 → 三个分量变量&lt;br /&gt;
local function single(name, hex)&lt;br /&gt;
	local r, g, b = hexToRgb(hex)&lt;br /&gt;
	return string.format(&lt;br /&gt;
		&amp;#039;--color-%s-r: %d; --color-%s-g: %d; --color-%s-b: %d;&amp;#039;,&lt;br /&gt;
		name, r, name, g, name, b&lt;br /&gt;
	)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- 按名取 hex（先浅色后深色）&lt;br /&gt;
local function hexOf(name)&lt;br /&gt;
	local l, n = palettes()&lt;br /&gt;
	return l[name] or n[name]&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- 输出一个颜色的分量（按名或按 hex）&lt;br /&gt;
function p.rgb(frame)&lt;br /&gt;
	local args = frame.args&lt;br /&gt;
	local name = args[1] or args.name&lt;br /&gt;
	local hex = args[2] or args.hex or hexOf(name)&lt;br /&gt;
	if not name then&lt;br /&gt;
		return &amp;#039;&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
	return single(name, hex)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- 输出浅色全部颜色分量（供 :root）&lt;br /&gt;
function p.light(frame)&lt;br /&gt;
	local l = palettes()&lt;br /&gt;
	local out = {}&lt;br /&gt;
	for name, hex in pairs(l) do&lt;br /&gt;
		table.insert(out, single(name, hex))&lt;br /&gt;
	end&lt;br /&gt;
	return table.concat(out, &amp;#039;\n&amp;#039;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- 输出深色全部颜色分量（供深色块）&lt;br /&gt;
function p.night(frame)&lt;br /&gt;
	local n = palettes()&lt;br /&gt;
	local out = {}&lt;br /&gt;
	for name, hex in pairs(n) do&lt;br /&gt;
		table.insert(out, single(name, hex))&lt;br /&gt;
	end&lt;br /&gt;
	return table.concat(out, &amp;#039;\n&amp;#039;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- 输出卡片所需全部颜色分量（浅色 + 深色两套，供模板内联到 style：&lt;br /&gt;
-- 浅色用 *-light，深色用 *-night，styles.css 分别引用）&lt;br /&gt;
function p.cardVars(frame)&lt;br /&gt;
	local l, n = palettes()&lt;br /&gt;
	local out = {}&lt;br /&gt;
	for name, hex in pairs(l) do&lt;br /&gt;
		local r, g, b = hexToRgb(hex)&lt;br /&gt;
		table.insert(out, string.format(&lt;br /&gt;
			&amp;#039;--color-%s-r-light:%d;--color-%s-g-light:%d;--color-%s-b-light:%d;&amp;#039;,&lt;br /&gt;
			name, r, name, g, name, b&lt;br /&gt;
		))&lt;br /&gt;
	end&lt;br /&gt;
	for name, hex in pairs(n) do&lt;br /&gt;
		local r, g, b = hexToRgb(hex)&lt;br /&gt;
		table.insert(out, string.format(&lt;br /&gt;
			&amp;#039;--color-%s-r-night:%d;--color-%s-g-night:%d;--color-%s-b-night:%d;&amp;#039;,&lt;br /&gt;
			name, r, name, g, name, b&lt;br /&gt;
		))&lt;br /&gt;
	end&lt;br /&gt;
	return table.concat(out)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>DoubleCircle</name></author>
	</entry>
</feed>