关于「四类站点的落地手册与四件套蒸馏规格」,《跨站设计令牌与感知色彩》给出的定量结论是什么?
结论:GK01 是一套干净的小型令牌,五类检查都通过。GK02 至 GK06 各复现第二章 p22 的一类错误,GK07 复现一条四跳的别名链,只出警告。GK08 与 GK09 是本章 p73 的主题环与缺失的父主题。GK10 是 Sharma 等人的第一组测试数据,2.0425,用来证明实现本身没有写错。GK11 与 GK12 是第一章样本里 B07 与 B08 的主色:1.4971 在容差之内,12.272 越界。GK13 是第四章的次要文字修正,0.7686,在修订版的 1.0 之内。GK14 与 GK15 是第六章 p64 的两道分隔护栏:精品站候选红离危险红 9.2967,不足 10.0,拒绝;报告蓝与牌卡紫相距 17.3691,通过。GK16 至 GK18 是本章 p72 的色阶:等色差弦长法变异系数 0.0167,通过;等明度法 0.1225,超过 0.05,K8;在 0.40 到 0.38 这么窄的明度里硬取 15 档,出现重复的颜色,K7 与 K8 同时触发。GK19 与 GK20 是不合法的输入,返回 E0。八个 K 码每一个都至少有一条样本触发。
数据口径:多站视觉漂移用令牌偏离数、色差与第一印象评分三个量描述,不合成总分;证据分为五级,每一次统一工程预先登记十项内容。 全部品牌、站点、颜色与评分都是虚构样本,全部计算由书中程序生成;涉及法规之处只写一般框架,不是法律意见。
对照数据表
下表数字由本章 Python 程序原样打印,可重新运行复现。 程序只用 Python 标准库与结论吻合的打印值: 0.0167, 0.1225, 0.40, 0.7686, 01, 02
GK01 clean set token_graph PASS OK
GK02 p22 R03 broken alias token_graph REFUSE K1 broken=["comp.badge.bg"]
GK03 p22 C02 alias cycle token_graph REFUSE K2 cycles=[["sys.color.focus-ring","sys.color.link"]]
GK04 p22 K05 layer skip token_graph REFUSE K4 layer=["comp.card.radius"]
GK05 p65 B05 literal token_graph REFUSE K5 literal=["comp.badge.bg"]
GK06 p22 B07 type clash token_graph REFUSE K6 type_clash=["comp.button.primary.pad"]
GK07 four-hop chain warns token_graph PASS OK warnings=["DEPTH comp.chart.mark"]
GK08 p73 theme cycle token_graph REFUSE K2 cycles=[["t:card-dusk","t:card-moon","t:card-night"]]
GK09 p73 missing theme parent token_graph REFUSE K1 broken=["t:card-sun"]
GK10 Sharma pair 1 delta_e PASS OK de00=2.0425; band=2.5; mode="max"
GK11 p10 B07 primary delta_e PASS OK de00=1.4971; band=2.0; mode="max"
GK12 p10 B08 primary delta_e REFUSE K3 de00=12.272; band=2.0; mode="max"
GK13 p71 muted fix, band 1.0 delta_e PASS OK de00=0.7686; band=1.0; mode="max"
GK14 p64 wine vs danger delta_e REFUSE K3 de00=9.2967; band=10.0; mode="min"
GK15 p64 report vs card delta_e PASS OK de00=17.3691; band=10.0; mode="min"
GK16 p72 jade chords ramp PASS OK cv=0.0167; step_min=6.99; step_max=7.32
ramp #C2FFDF #97E5BE #7BC8A3 #62AF8A #4C9976 #378563 #217251 #005D3E #00462E
GK17 p72 jade equal L ramp REFUSE K8 cv=0.1225; step_min=5.92; step_max=8.39
GK18 15 steps in L 0.40-0.38 ramp REFUSE K7+K8 cv=0.8823; step_min=0.0; step_max=0.43
GK19 two steps ramp REFUSE E0
GK20 colour by name delta_e REFUSE E0
cases 20; first codes E0 x2, K1 x2, K2 x2, K3 x2, K4 x1, K5 x1, K6 x1, K7 x1, K8 x1, OK x7查看完整验算程序
# Chapter 7. p74: Style-kit additions from this book: ops token_graph, delta_e, ramp; refusal codes K1-K8.
# Each op takes one dict and returns verdict (PASS | REFUSE), code (OK | first refusal), refusals_hit,
# warnings and its result fields, in the style kit's contract. The cases below are the kit's new golden
# table; expected values are this program's own output. Token names and values follow chapter 2 (p20,
# p22), the live colours chapter 1 (p10) and the themes p73.
# K1 broken link an alias names a missing token, or a theme ("t:" prefix) a missing parent
# K2 cycle an alias chain or a theme "extends" chain returns to itself
# K3 dE00 out of band mode "max": dE00 > band (drift); mode "min": dE00 < band (separation)
# K4 layer skip a comp token aliases a ref token directly
# K5 literal a literal value outside the ref layer
# K6 type clash a colour slot resolves to a length, or a length slot to a colour
# K7 ramp order L* of the generated ramp is not strictly decreasing
# K8 ramp uneven coefficient of variation of the dE00 steps exceeds cv_max (default 0.05)
# Warning DEPTH (more than 3 hops) does not refuse. E0 (bad input) is the kit's existing code, reused.
import json
import re
from statistics import fmean, pstdev
import math
def lin8(c):
return c / 12.92 if c <= 0.04045 else ((c + 0.055) / 1.055) ** 2.4
def rgb(h):
return [int(h[i:i + 2], 16) / 255 for i in (1, 3, 5)]
def lum(h): # WCAG 2.1 relative luminance (0.03928 threshold as the standard writes it)
v = [c / 12.92 if c <= 0.03928 else ((c + 0.055) / 1.055) ** 2.4 for c in rgb(h)]
return math.fsum(w * c for w, c in zip((0.2126, 0.7152, 0.0722), v))
def ratio(a, b):
x, y = lum(a), lum(b)
return (max(x, y) + 0.05) / (min(x, y) + 0.05)
def lab(h):
r, g, b = (lin8(c) for c in rgb(h))
x = math.fsum((0.4124564 * r, 0.3575761 * g, 0.1804375 * b)) / 0.95047
y = math.fsum((0.2126729 * r, 0.7151522 * g, 0.0721750 * b))
z = math.fsum((0.0193339 * r, 0.1191920 * g, 0.9503041 * b)) / 1.08883
e, k = 216 / 24389, 24389 / 27
f = [t ** (1 / 3) if t > e else (k * t + 16) / 116 for t in (x, y, z)]
return 116 * f[1] - 16, 500 * (f[0] - f[1]), 200 * (f[1] - f[2])
def de00(h1, h2): # CIEDE2000 (Sharma, Wu and Dalal 2005)
(L1, a1, b1), (L2, a2, b2) = labx(h1), labx(h2)
c7 = ((math.hypot(a1, b1) + math.hypot(a2, b2)) / 2) ** 7
g = 0.5 * (1 - math.sqrt(c7 / (c7 + 25 ** 7)))
a1, a2 = (1 + g) * a1, (1 + g) * a2
c1, c2 = math.hypot(a1, b1), math.hypot(a2, b2)
h1 = math.degrees(math.atan2(b1, a1)) % 360 if c1 else 0.0
h2 = math.degrees(math.atan2(b2, a2)) % 360 if c2 else 0.0
dh = 0.0 if c1 * c2 == 0 else (h2 - h1 if abs(h2 - h1) <= 180 else
(h2 - h1 - 360 if h2 - h1 > 180 else h2 - h1 + 360))
dH = 2 * math.sqrt(c1 * c2) * math.sin(math.radians(dh / 2))
lb, cb = (L1 + L2) / 2, (c1 + c2) / 2
if c1 * c2 == 0:
hb = h1 + h2
elif abs(h1 - h2) <= 180:
hb = (h1 + h2) / 2
else:
hb = (h1 + h2 + 360) / 2 if h1 + h2 < 360 else (h1 + h2 - 360) / 2
t = (1 - 0.17 * math.cos(math.radians(hb - 30)) + 0.24 * math.cos(math.radians(2 * hb))
+ 0.32 * math.cos(math.radians(3 * hb + 6)) - 0.20 * math.cos(math.radians(4 * hb - 63)))
rc = 2 * math.sqrt(cb ** 7 / (cb ** 7 + 25 ** 7))
rt = -math.sin(math.radians(60 * math.exp(-(((hb - 275) / 25) ** 2)))) * rc
sl = 1 + 0.015 * (lb - 50) ** 2 / math.sqrt(20 + (lb - 50) ** 2)
sc, sh = 1 + 0.045 * cb, 1 + 0.015 * cb * t
return math.sqrt(((L2 - L1) / sl) ** 2 + ((c2 - c1) / sc) ** 2 + (dH / sh) ** 2
+ rt * ((c2 - c1) / sc) * (dH / sh))
M1 = ((0.4122214708, 0.5363325363, 0.0514459929), (0.2119034982, 0.6806995451, 0.1073969566),
(0.0883024619, 0.2817188376, 0.6299787005))
M2 = ((0.2104542553, 0.7936177850, -0.0040720468), (1.9779984951, -2.4285922050, 0.4505937099),
(0.0259040371, 0.7827717662, -0.8086757660))
I2 = ((1, 0.3963377774, 0.2158037573), (1, -0.1055613458, -0.0638541728), (1, -0.0894841775, -1.2914855480))
I1 = ((4.0767416621, -3.3077115913, 0.2309699292), (-1.2684380046, 2.6097574011, -0.3413193965),
(-0.0041960863, -0.7034186147, 1.7076147010))
def mul(m, v):
return [math.fsum(a * b for a, b in zip(row, v)) for row in m]
def oklab(h): # Ottosson (2020)
return mul(M2, [math.copysign(abs(c) ** (1 / 3), c) for c in mul(M1, [lin8(c) for c in rgb(h)])])
def from_oklab(L, C, hue):
v = mul(I1, [c ** 3 for c in mul(I2, (L, C * math.cos(hue), C * math.sin(hue)))])
if any(c < -1e-9 or c > 1 + 1e-9 for c in v):
return None
v = [12.92 * c if c <= 0.0031308 else 1.055 * c ** (1 / 2.4) - 0.055 for c in (max(0.0, c) for c in v)]
return "#%02X%02X%02X" % tuple(round(min(1.0, c) * 255) for c in v)
HEX = "0123456789ABCDEF"
ALIAS = re.compile(r"^\{([a-z0-9.\-]+)\}$")
COLOUR_END = {"bg", "fg", "border", "focus", "error", "mark", "strike-fg", "fill", "track"}
LENGTH_END = {"pad", "radius", "size", "gap"}
class Refuse(Exception):
pass
def labx(x):
if isinstance(x, (list, tuple)) and len(x) == 3:
return tuple(float(v) for v in x)
if isinstance(x, str) and len(x) == 7 and x[0] == "#" and all(c in HEX for c in x[1:].upper()):
return lab(x.upper())
raise Refuse("E0")
def answer(op, hits, warnings=(), **fields):
out = {"op": op, "verdict": "REFUSE" if hits else "PASS", "code": hits[0] if hits else "OK",
"refusals_hit": hits, "warnings": list(warnings)}
out.update(fields)
return out
def expected(name):
last = name.split(".")[-1]
if name.startswith("sys.color.") or (name.startswith("comp.") and last in COLOUR_END):
return "colour"
if name.startswith(("sys.space.", "sys.radius.", "sys.size.")) or (name.startswith("comp.")
and last in LENGTH_END):
return "length"
return None
def token_graph(inp):
t, themes = inp["tokens"], inp.get("themes", {})
broken, cycles, layer, literal, clash, deep = [], [], [], [], [], []
for n in sorted(t):
seen, cur, ok = [n], t[n], True
while ALIAS.match(cur):
nxt = ALIAS.match(cur).group(1)
if nxt not in t:
broken.append(n)
ok = False
break
if nxt in seen:
ring = sorted(seen[seen.index(nxt):])
if ring not in cycles:
cycles.append(ring)
ok = False
break
seen.append(nxt)
cur = t[nxt]
m = ALIAS.match(t[n])
if m and n.startswith("comp.") and m.group(1).startswith("ref."):
layer.append(n)
if not m and not n.startswith("ref."):
literal.append(n)
if ok:
kind = "colour" if cur.startswith("#") else "length" if cur.endswith("px") else None
if expected(n) and kind and expected(n) != kind:
clash.append(n)
if len(seen) - 1 > 3:
deep.append(n)
for th in sorted(themes):
seen, cur = [], th
while cur in themes and cur not in seen:
seen.append(cur)
cur = themes[cur].get("extends")
if cur is not None and cur not in themes:
broken.append("t:" + seen[-1])
elif cur is not None:
ring = sorted("t:" + s for s in seen[seen.index(cur):])
if ring not in cycles:
cycles.append(ring)
hits = [c for c, bad in (("K1", broken), ("K2", cycles), ("K4", layer), ("K5", literal), ("K6", clash))
if bad]
return answer("token_graph", hits, ["DEPTH " + d for d in deep], broken=sorted(set(broken)),
cycles=cycles, layer=layer, literal=literal, type_clash=clash)
def delta_e(inp):
band, mode = float(inp.get("band", 2.0)), inp.get("mode", "max")
if mode not in ("max", "min"):
raise Refuse("E0")
d = de00(inp["a"], inp["b"])
bad = d > band if mode == "max" else d < band
return answer("delta_e", ["K3"] if bad else [], de00=round(d, 4), band=band, mode=mode)
def ramp(inp):
anchor, n = inp["anchor"], int(inp.get("steps", 9))
hi, lo = float(inp.get("l_max", 0.95)), float(inp.get("l_min", 0.35))
cv_max, mode = float(inp.get("cv_max", 0.05)), inp.get("mode", "chord")
if not (3 <= n <= 15 and 0 < lo < hi < 1) or mode not in ("chord", "oklab-l"):
raise Refuse("E0")
labx(anchor)
L0, a0, b0 = oklab(anchor.upper())
C0, hue = math.hypot(a0, b0), math.atan2(b0, a0)
def clip(L):
if from_oklab(L, C0, hue):
return from_oklab(L, C0, hue)
a, b = 0.0, C0
for _ in range(40):
m = (a + b) / 2
a, b = (m, b) if from_oklab(L, m, hue) else (a, m)
return from_oklab(L, a, hue)
if mode == "oklab-l":
out = [clip(hi - (hi - lo) * k / (n - 1)) for k in range(n)]
else:
path = [clip(hi - (hi - lo) * i / 600) for i in range(601)]
def walk(d):
idx = [0]
for _ in range(n - 1):
j = idx[-1] + 1
while j < 600 and de00(path[idx[-1]], path[j]) < d:
j += 1
idx.append(j)
return idx
a, b = 0.5, 40.0
for _ in range(30):
m = (a + b) / 2
a, b = (m, b) if walk(m)[-1] < 600 else (a, m)
idx = walk(a)
idx[-1] = 600
out = [path[i] for i in idx]
steps = [de00(x, y) for x, y in zip(out, out[1:])]
cv = pstdev(steps) / fmean(steps)
Ls = [lab(h)[0] for h in out]
hits = (["K7"] if not all(x > y for x, y in zip(Ls, Ls[1:])) else []) + (["K8"] if cv > cv_max else [])
return answer("ramp", hits, ramp=out, cv=round(cv, 4), step_min=round(min(steps), 2),
step_max=round(max(steps), 2))
OPS = {"token_graph": token_graph, "delta_e": delta_e, "ramp": ramp}
def run(inp):
try:
if inp.get("op") not in OPS:
raise Refuse("E0")
return OPS[inp["op"]](inp)
except (Refuse, KeyError, TypeError, ValueError):
return answer(inp.get("op"), ["E0"])
BASE = {"ref.color.ink.900": "#1B1B20", "ref.color.gold.500": "#B8913F", "ref.color.wine.700": "#8C2F39",
"ref.color.ink.050": "#F7F5F0", "ref.radius.2": "8px", "ref.space.4": "16px",
"sys.color.text-body": "{ref.color.ink.900}", "sys.color.surface": "{ref.color.ink.050}",
"sys.color.primary": "{ref.color.wine.700}", "sys.color.accent": "{ref.color.gold.500}",
"sys.color.link": "{sys.color.primary}", "sys.color.focus-ring": "{sys.color.accent}",
"sys.radius.card": "{ref.radius.2}", "sys.space.inset-md": "{ref.space.4}",
"comp.button.primary.bg": "{sys.color.primary}", "comp.button.primary.pad": "{sys.space.inset-md}",
"comp.button.ghost.fg": "{sys.color.link}", "comp.card.bg": "{sys.color.surface}",
"comp.card.radius": "{sys.radius.card}", "comp.badge.bg": "{sys.color.accent}",
"comp.input.focus": "{sys.color.focus-ring}", "comp.chart.mark": "{comp.button.primary.bg}"}
def g(**edits):
return {"op": "token_graph", "tokens": dict(BASE, **edits)}
CASES = [
("GK01", "clean set", g()),
("GK02", "p22 R03 broken alias", g(**{"comp.badge.bg": "{sys.color.highlight}"})),
("GK03", "p22 C02 alias cycle", g(**{"sys.color.link": "{sys.color.focus-ring}",
"sys.color.focus-ring": "{sys.color.link}"})),
("GK04", "p22 K05 layer skip", g(**{"comp.card.radius": "{ref.radius.2}"})),
("GK05", "p65 B05 literal", g(**{"comp.badge.bg": "#B8913F"})),
("GK06", "p22 B07 type clash", g(**{"comp.button.primary.pad": "{sys.color.accent}"})),
("GK07", "four-hop chain warns", g(**{"comp.chart.mark": "{comp.button.ghost.fg}"})),
("GK08", "p73 theme cycle", dict(g(), themes={"card-base": {}, "card-night": {"extends": "card-dusk"},
"card-moon": {"extends": "card-night"},
"card-dusk": {"extends": "card-moon"}})),
("GK09", "p73 missing theme parent", dict(g(), themes={"card-base": {},
"card-sun": {"extends": "card-solar"}})),
("GK10", "Sharma pair 1", {"op": "delta_e", "a": [50, 2.6772, -79.7751], "b": [50, 0, -82.7485],
"band": 2.5}),
("GK11", "p10 B07 primary", {"op": "delta_e", "a": "#863036", "b": "#8C2F39"}),
("GK12", "p10 B08 primary", {"op": "delta_e", "a": "#900A05", "b": "#8C2F39"}),
("GK13", "p71 muted fix, band 1.0", {"op": "delta_e", "a": "#2773C9", "b": "#2771C7", "band": 1.0}),
("GK14", "p64 wine vs danger", {"op": "delta_e", "a": "#A3242F", "b": "#C33A32", "band": 10.0,
"mode": "min"}),
("GK15", "p64 report vs card", {"op": "delta_e", "a": "#1F5FA8", "b": "#6B4FA0", "band": 10.0,
"mode": "min"}),
("GK16", "p72 jade chords", {"op": "ramp", "anchor": "#2E7D5B"}),
("GK17", "p72 jade equal L", {"op": "ramp", "anchor": "#2E7D5B", "mode": "oklab-l"}),
("GK18", "15 steps in L 0.40-0.38", {"op": "ramp", "anchor": "#2E7D5B", "mode": "oklab-l", "steps": 15,
"l_max": 0.40, "l_min": 0.38}),
("GK19", "two steps", {"op": "ramp", "anchor": "#2E7D5B", "steps": 2}),
("GK20", "colour by name", {"op": "delta_e", "a": "wine", "b": "#8C2F39"}),
]
SHOW = {"token_graph": ("broken", "cycles", "layer", "literal", "type_clash", "warnings"),
"delta_e": ("de00", "band", "mode"), "ramp": ("cv", "step_min", "step_max")}
if __name__ == "__main__":
tally = {}
for cid, note, inp in CASES:
out = run(inp)
tally[out["code"]] = tally.get(out["code"], 0) + 1
keys = [k for k in SHOW.get(out["op"], ()) if out["code"] != "E0"]
detail = "; ".join("{}={}".format(k, json.dumps(out[k], separators=(",", ":"))) for k in keys
if out.get(k) not in ([], None))
hits = "+".join(out["refusals_hit"]) or "OK"
line = "{} {:24} {:11} {:6} {:5} {}".format(cid, note, out["op"], out["verdict"], hits, detail)
print(line.rstrip())
if cid == "GK16":
print(" ramp " + " ".join(out["ramp"]))
codes = ", ".join("{} x{}".format(k, v) for k, v in sorted(tally.items()))
print("cases {}; first codes {}".format(len(CASES), codes))唯一数据源与引用
范雅福(Fan, Y.). (2026). 《跨三十站设计令牌代数、色彩感知均匀空间与品牌权威第一印象毫秒学》第 7 章「四类站点的落地手册与四件套蒸馏规格」(版本 0.1.0). 5D Library. DOI 待发布
DOI 待发布 · 专著页正式发布后上线(本站暂无专著页) · 5DL-B-140 · v0.1.0 · CC-BY-NC-ND-4.0
BibTeX
@book{fan2026140,
author = {Fan, Yafu},
title = {Design-Token Algebra across Thirty Sites, Perceptually Uniform Colour Spaces and the Millisecond Science of Brand-Authority First Impressions},
year = {2026},
publisher = {5D Library},
edition = {0.1.0},
note = {DOI pending}
}