@hia/theme-core 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/color/apca.d.ts +48 -0
- package/dist/color/apca.js +94 -0
- package/dist/color/color-name.js +30 -12
- package/dist/color/contrast.d.ts +46 -0
- package/dist/color/contrast.js +113 -1
- package/dist/color/image-extract.d.ts +56 -0
- package/dist/color/image-extract.js +217 -0
- package/dist/color/semantic.d.ts +52 -0
- package/dist/color/semantic.js +68 -0
- package/dist/color/vision.d.ts +22 -0
- package/dist/color/vision.js +63 -0
- package/dist/data/mood-primary-colors.d.ts +77 -0
- package/dist/data/mood-primary-colors.js +83 -0
- package/dist/export/dtcg.d.ts +70 -0
- package/dist/export/dtcg.js +433 -0
- package/dist/export/inject-template.js +6 -2
- package/dist/export/registry.js +5 -1
- package/dist/export/tailwind.js +13 -1
- package/dist/export/tailwind4.d.ts +14 -0
- package/dist/export/tailwind4.js +66 -0
- package/dist/export/wordpress.js +1 -1
- package/dist/gradient/render.d.ts +4 -2
- package/dist/gradient/render.js +44 -5
- package/dist/index.d.ts +16 -1
- package/dist/index.js +36 -4
- package/dist/studio.js +14 -4
- package/dist/theme.js +26 -7
- package/dist/token/css.js +23 -3
- package/dist/token/json.js +6 -0
- package/dist/token/radius.d.ts +38 -0
- package/dist/token/radius.js +94 -0
- package/dist/types.d.ts +31 -0
- package/package.json +1 -1
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @lang zh-CN 图片提色(`W-tb-P39`,ADR-014):从像素数据提取主/副色候选与渐变配置。
|
|
3
|
+
* **确定性算法**:降采样(最长边 ≤512px,最近邻)→ sRGB→OKLab → 中位切分(按 L/a/b 最宽轴
|
|
4
|
+
* 递归,k=8)→ 代表色 + 计数 → 近色合并(OKLab 距离阈值)→ 模式加权排序。
|
|
5
|
+
* 同图同参必得同结果(可单测复现);**纯计算无 IO**——解码与像素获取由宿主完成(隐私边界:
|
|
6
|
+
* 零网络请求由宿主侧断言)。
|
|
7
|
+
*
|
|
8
|
+
* @lang en Image colour extraction (`W-tb-P39`, ADR-014): derives primary/secondary candidates and a gradient
|
|
9
|
+
* config from pixel data. **Deterministic**: downsample (longest edge ≤512px, nearest neighbour) → sRGB→OKLab
|
|
10
|
+
* → median cut (split on the widest L/a/b axis, k=8) → representative colours + counts → near-colour merge
|
|
11
|
+
* (OKLab distance threshold) → mode-weighted ordering. Same input always yields the same output (unit-testable
|
|
12
|
+
* reproduction); **pure computation, no IO** — decoding/pixels are the host's job (privacy: zero network
|
|
13
|
+
* requests asserted host-side).
|
|
14
|
+
*/
|
|
15
|
+
import { hexToRgb, rgbToHex, rgbToOklab, oklabToRgb, normalizeHex } from './convert.js';
|
|
16
|
+
import { nameColor } from './color-name.js';
|
|
17
|
+
import { bestOnColor } from './contrast.js';
|
|
18
|
+
/** @lang zh-CN 降采样上限(最长边,ADR-014 决策 6)。 @lang en Downsample cap (longest edge, ADR-014 decision 6). */
|
|
19
|
+
export const IMAGE_EXTRACT_MAX_DIM = 512;
|
|
20
|
+
/** @lang zh-CN 聚类数(中位切分叶子数)。 @lang en Cluster count (median-cut leaves). */
|
|
21
|
+
export const IMAGE_EXTRACT_CLUSTERS = 8;
|
|
22
|
+
/** @lang zh-CN 近色合并阈值(OKLab 距离)。 @lang en Near-colour merge threshold (OKLab distance). */
|
|
23
|
+
export const IMAGE_EXTRACT_MERGE_DIST = 0.09;
|
|
24
|
+
/** @lang zh-CN 最近邻降采样:最长边超过 maxDim 时按整数步长抽点(不插值,确定性)。 @lang en Nearest-neighbour downsample: integer stride sampling when the longest edge exceeds maxDim (no interpolation, deterministic). */
|
|
25
|
+
export function downsamplePixels(input, maxDim = IMAGE_EXTRACT_MAX_DIM) {
|
|
26
|
+
const longest = Math.max(input.width, input.height);
|
|
27
|
+
if (longest <= maxDim)
|
|
28
|
+
return input;
|
|
29
|
+
const step = Math.ceil(longest / maxDim);
|
|
30
|
+
const w = Math.floor(input.width / step), h = Math.floor(input.height / step);
|
|
31
|
+
const out = new Uint8ClampedArray(w * h * 4);
|
|
32
|
+
let o = 0;
|
|
33
|
+
for (let y = 0; y < h; y++) {
|
|
34
|
+
for (let x = 0; x < w; x++) {
|
|
35
|
+
const si = (y * step * input.width + x * step) * 4;
|
|
36
|
+
out[o++] = input.data[si];
|
|
37
|
+
out[o++] = input.data[si + 1];
|
|
38
|
+
out[o++] = input.data[si + 2];
|
|
39
|
+
out[o++] = 255;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return { data: out, width: w, height: h };
|
|
43
|
+
}
|
|
44
|
+
/** @lang zh-CN 跳过全透明像素。 @lang en Fully transparent pixels are skipped. */
|
|
45
|
+
function isOpaque(data, i) { return data[i + 3] > 0; }
|
|
46
|
+
/** @lang zh-CN 中位切分:像素按 OKLab 坐标递归二分(最宽轴取中位),直至 k 个叶子或不可再分。 @lang en Median cut: pixels split recursively on OKLab (median of the widest axis) until k leaves or unsplittable. */
|
|
47
|
+
function medianCut(pixels, k) {
|
|
48
|
+
let buckets = [pixels];
|
|
49
|
+
while (buckets.length < k) {
|
|
50
|
+
// 选含像素最多且极差最大的桶与轴(并列取轴序 L→a→b,确定性)。
|
|
51
|
+
// <lang en>Pick the bucket with the most pixels and the widest range (ties break L→a→b, deterministic).</lang>
|
|
52
|
+
let bestIdx = -1, bestAxis = -1, bestRange = 0;
|
|
53
|
+
buckets.forEach((bucket, idx) => {
|
|
54
|
+
if (bucket.length < 2)
|
|
55
|
+
return;
|
|
56
|
+
for (const axis of [0, 1, 2]) {
|
|
57
|
+
let lo = Infinity, hi = -Infinity;
|
|
58
|
+
for (const p of bucket) {
|
|
59
|
+
lo = Math.min(lo, p[axis]);
|
|
60
|
+
hi = Math.max(hi, p[axis]);
|
|
61
|
+
}
|
|
62
|
+
const range = hi - lo;
|
|
63
|
+
if (range > bestRange) {
|
|
64
|
+
bestRange = range;
|
|
65
|
+
bestIdx = idx;
|
|
66
|
+
bestAxis = axis;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
if (bestIdx < 0 || bestRange <= 0)
|
|
71
|
+
break;
|
|
72
|
+
const bucket = buckets[bestIdx];
|
|
73
|
+
// 中位切分:按轴排序取中位(奇数取上中位,确定性)。
|
|
74
|
+
// <lang en>Median split: sort along the axis and cut at the upper median (deterministic).</lang>
|
|
75
|
+
const axis = bestAxis;
|
|
76
|
+
const sorted = [...bucket].sort((a, b) => a[axis] - b[axis]);
|
|
77
|
+
const mid = Math.floor(sorted.length / 2);
|
|
78
|
+
buckets = buckets.filter((_, i) => i !== bestIdx).concat([sorted.slice(0, mid), sorted.slice(mid)]);
|
|
79
|
+
}
|
|
80
|
+
return buckets;
|
|
81
|
+
}
|
|
82
|
+
/** @lang zh-CN OKLab 距离(欧氏)。 @lang en OKLab distance (Euclidean). */
|
|
83
|
+
function labDist(a, b) {
|
|
84
|
+
return Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2]);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* @lang zh-CN 图片提色主入口:降采样 → 不透明像素 → OKLab 中位切分 → 代表色(桶均值)→
|
|
88
|
+
* 近色合并 → 模式加权排序 → 主/副/渐变推导。纯函数、确定性。
|
|
89
|
+
* @lang en The main extraction entry: downsample → opaque pixels → OKLab median cut → representative colours
|
|
90
|
+
* (bucket means) → near-colour merge → mode-weighted ordering → primary/secondary/gradient. Pure and
|
|
91
|
+
* deterministic.
|
|
92
|
+
*/
|
|
93
|
+
export function extractImagePalette(input, mode = 'balanced') {
|
|
94
|
+
const { data, width, height } = downsamplePixels(input);
|
|
95
|
+
const pixels = [];
|
|
96
|
+
for (let i = 0; i < width * height; i++) {
|
|
97
|
+
const si = i * 4;
|
|
98
|
+
if (!isOpaque(data, si))
|
|
99
|
+
continue;
|
|
100
|
+
pixels.push(rgbToOklab([data[si] / 255, data[si + 1] / 255, data[si + 2] / 255]));
|
|
101
|
+
}
|
|
102
|
+
if (!pixels.length)
|
|
103
|
+
return { candidates: [], primary: '', secondary: '', gradient: null };
|
|
104
|
+
const buckets = medianCut(pixels, IMAGE_EXTRACT_CLUSTERS);
|
|
105
|
+
// 代表色 = 桶内**逐轴中位数**(非均值)——离散色图的代表色不再被邻色拉偏(青条带不会变绿),
|
|
106
|
+
// 且中位数同样是确定性的。
|
|
107
|
+
// <lang en>Representative = per-axis **median** of the bucket (not the mean): on discrete-colour images the
|
|
108
|
+
// representative stops drifting toward neighbours (a cyan strip stays cyan), and the median is equally
|
|
109
|
+
// deterministic.</lang>
|
|
110
|
+
let clusters = buckets
|
|
111
|
+
.filter(b => b.length > 0)
|
|
112
|
+
.map(bucket => {
|
|
113
|
+
const median = (axis) => {
|
|
114
|
+
const sorted = bucket.map(p => p[axis]).sort((x, y) => x - y);
|
|
115
|
+
return sorted[Math.floor(sorted.length / 2)];
|
|
116
|
+
};
|
|
117
|
+
const hex = rgbToHex(oklabToRgb([median(0), median(1), median(2)]));
|
|
118
|
+
return { hex, lab: hexToLab(hex), population: bucket.length };
|
|
119
|
+
});
|
|
120
|
+
// 近色合并:距离 ≤ 阈值的簇并入近邻(计票相加),减少同色多卡。
|
|
121
|
+
// <lang en>Merge near colours: clusters within the threshold fold into their nearest neighbour (votes sum).</lang>
|
|
122
|
+
const merged = [];
|
|
123
|
+
for (const c of clusters) {
|
|
124
|
+
const near = merged.find(m => labDist(m.lab, c.lab) <= IMAGE_EXTRACT_MERGE_DIST);
|
|
125
|
+
if (near) {
|
|
126
|
+
near.population += c.population;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
merged.push({ ...c });
|
|
130
|
+
}
|
|
131
|
+
clusters = merged;
|
|
132
|
+
const total = clusters.reduce((sum, c) => sum + c.population, 0);
|
|
133
|
+
// 模式加权:balanced=计票;vivid=彩度×计票;bright/dark 在计票上乘以明度偏好因子。
|
|
134
|
+
// <lang en>Mode weighting: balanced = votes; vivid = chroma×votes; bright/dark multiply votes by a
|
|
135
|
+
// lightness-preference factor.</lang>
|
|
136
|
+
const weighted = clusters.map(c => {
|
|
137
|
+
const { L, C } = c.lab;
|
|
138
|
+
let score = c.population;
|
|
139
|
+
// vivid = **彩度平方优先**:小面积高彩点缀能超越大面积低彩底色(线性加权补不开 60:1 的计票差)。
|
|
140
|
+
// <lang en>vivid = **chroma-squared first**: small vivid accents outrank large muted backdrops (a linear
|
|
141
|
+
// weight cannot close a 60:1 population gap).</lang>
|
|
142
|
+
if (mode === 'vivid')
|
|
143
|
+
score = c.population * Math.pow(C * 5, 2);
|
|
144
|
+
// bright/dark = 明度线性偏置(幅度小于 vivid——明暗偏好是温和重排)。
|
|
145
|
+
// <lang en>bright/dark apply a linear lightness bias (milder than vivid — lightness preference is a gentle
|
|
146
|
+
// reordering).</lang>
|
|
147
|
+
if (mode === 'bright')
|
|
148
|
+
score = c.population * (0.3 + L * 1.2);
|
|
149
|
+
if (mode === 'dark')
|
|
150
|
+
score = c.population * (0.3 + (1 - L) * 1.2);
|
|
151
|
+
return { ...c, score };
|
|
152
|
+
}).sort((a, b) => b.score - a.score);
|
|
153
|
+
// 候选卡(最多 6):色名走 ISCC-NBS 管线;weight 为加权占比。
|
|
154
|
+
// <lang en>Candidate cards (≤6): names via the ISCC-NBS pipeline; weight is the weighted share.</lang>
|
|
155
|
+
const top = weighted.slice(0, 6);
|
|
156
|
+
const candidates = top.map(c => {
|
|
157
|
+
const n = nameColor(c.hex);
|
|
158
|
+
return { hex: normalizeHex(c.hex), name: n.zh, nameEn: n.en, weight: c.score / Math.max(1, weighted.reduce((s, w) => s + w.score, 0)), population: c.population };
|
|
159
|
+
});
|
|
160
|
+
const primary = candidates[0]?.hex ?? '';
|
|
161
|
+
// 副色:与主色色相差最大(≥30°)且对比 ≥3 的候选;无则回退主色最佳前景。
|
|
162
|
+
// <lang en>Secondary: the candidate with the largest hue gap from the primary (≥30°) and contrast ≥3;
|
|
163
|
+
// fallback is the primary's best foreground.</lang>
|
|
164
|
+
let secondary = '';
|
|
165
|
+
const pLab = hexToLab(primary);
|
|
166
|
+
for (const c of top) {
|
|
167
|
+
if (c.hex === primary)
|
|
168
|
+
continue;
|
|
169
|
+
// 主判据:色相差 ≥30° 且对比 ≥3(可用下限);全不满足回退第二候选,再回退最佳前景。
|
|
170
|
+
// <lang en>Primary rule: hue gap ≥30° with contrast ≥3 (usability floor); fall back to the second
|
|
171
|
+
// candidate, then to the primary's best foreground.</lang>
|
|
172
|
+
let dh = Math.abs(hexToLab(c.hex).h - pLab.h);
|
|
173
|
+
if (dh > 180)
|
|
174
|
+
dh = 360 - dh;
|
|
175
|
+
if (dh >= 30 && contrastOk(primary, c.hex)) {
|
|
176
|
+
secondary = c.hex;
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (!secondary && candidates.length > 1)
|
|
181
|
+
secondary = candidates[1].hex;
|
|
182
|
+
if (!secondary)
|
|
183
|
+
secondary = bestOnColor(primary).hex;
|
|
184
|
+
// 渐变:最暗/最亮候选(按 OKLab L)。
|
|
185
|
+
// <lang en>Gradient: darkest/brightest candidates by OKLab L.</lang>
|
|
186
|
+
const byL = [...top].sort((a, b) => hexToLab(a.hex).L - hexToLab(b.hex).L);
|
|
187
|
+
const gradient = byL.length >= 2 && byL[0].hex !== byL[byL.length - 1].hex
|
|
188
|
+
? { start: byL[0].hex, end: byL[byL.length - 1].hex }
|
|
189
|
+
: null;
|
|
190
|
+
return { candidates, primary, secondary, gradient };
|
|
191
|
+
}
|
|
192
|
+
/** @lang zh-CN HEX → OKLab(内部便捷)。 @lang en HEX → OKLab (internal convenience). */
|
|
193
|
+
function hexToLab(hex) {
|
|
194
|
+
const lab = rgbToOklab(hexToRgb(hex));
|
|
195
|
+
const L = lab[0], a = lab[1], b = lab[2];
|
|
196
|
+
const C = Math.hypot(a, b), h = (Math.atan2(b, a) * 180 / Math.PI + 360) % 360;
|
|
197
|
+
return Object.assign([L, a, b], { L, C, h });
|
|
198
|
+
}
|
|
199
|
+
/** @lang zh-CN 对比度 ≥3 判定(副色可用性下限)。 @lang en Contrast ≥3 check (secondary usability floor). */
|
|
200
|
+
function contrastOk(a, b) {
|
|
201
|
+
const la = luminanceOf(a), lb = luminanceOf(b);
|
|
202
|
+
const hi = Math.max(la, lb), lo = Math.min(la, lb);
|
|
203
|
+
return (hi + 0.05) / (lo + 0.05) >= 3;
|
|
204
|
+
}
|
|
205
|
+
function luminanceOf(hex) {
|
|
206
|
+
const [r = 0, g = 0, b = 0] = hexToRgb(hex).map(c => c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4));
|
|
207
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* @lang zh-CN 从提取结果构造渐变方向建议:暗→亮用 135deg(对角),亮→暗用 315deg。
|
|
211
|
+
* @lang en Suggests a gradient direction from the extraction: dark→light uses 135deg (diagonal), the reverse
|
|
212
|
+
* uses 315deg.
|
|
213
|
+
*/
|
|
214
|
+
export function suggestGradientDirection(start, end) {
|
|
215
|
+
return luminanceOf(start) <= luminanceOf(end) ? '135deg' : '315deg';
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=image-extract.js.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @lang zh-CN 语义状态色派生(`W-tb-P37`,ADR-012):从主色派生 success/info/warning/danger 四组完整
|
|
3
|
+
* RoleColor(10 阶 + on 色)。**色相按语义固定**(状态语义是约定俗成的,不随主题漂移),
|
|
4
|
+
* **明度与彩度特征随主色**——低明度主题得到低明度状态色,防止"灰主题配荧光状态色"。
|
|
5
|
+
* 派生值是预填值,用户可逐组覆盖(ADR-012 决策 3);覆盖后不随主色刷新。
|
|
6
|
+
*
|
|
7
|
+
* @lang en Semantic status token derivation (`W-tb-P37`, ADR-012): derive success/info/warning/danger as full
|
|
8
|
+
* RoleColors (10 steps + on) from the primary. **Hues are semantically fixed** (status semantics are
|
|
9
|
+
* conventional and must not drift with the theme), while **lightness/chroma character follows the primary** —
|
|
10
|
+
* a dim theme gets dim status colours, avoiding neon statuses on muted themes. Derived values are prefills;
|
|
11
|
+
* users may override per group (ADR-012 decision 3), after which they stop following the primary.
|
|
12
|
+
*/
|
|
13
|
+
import type { SemanticStatusKey, SemanticTokens } from '../types.js';
|
|
14
|
+
/**
|
|
15
|
+
* @lang zh-CN 语义状态色相锚点(OKLCH 角度,按 2026 主流设计系统约定):
|
|
16
|
+
* success 绿 145 / info 蓝 250 / warning 琥珀 70 / danger 红 25。
|
|
17
|
+
* **不要改动这些色相**——语义色的可辨识度依赖约定;个性化走覆盖机制而非改锚点。
|
|
18
|
+
* @lang en Semantic hue anchors (OKLCH degrees, per 2026 mainstream conventions):
|
|
19
|
+
* success green 145 / info blue 250 / warning amber 70 / danger red 25.
|
|
20
|
+
* **Do not change these** — recognisability depends on convention; personalise via overrides, not anchors.
|
|
21
|
+
*/
|
|
22
|
+
export declare const SEMANTIC_HUES: Record<SemanticStatusKey, number>;
|
|
23
|
+
/** @lang zh-CN 语义状态中英文名(RoleColor.name 消费)。 @lang en Bilingual status names (consumed as RoleColor.name). */
|
|
24
|
+
export declare const SEMANTIC_NAMES: Record<SemanticStatusKey, {
|
|
25
|
+
zh: string;
|
|
26
|
+
en: string;
|
|
27
|
+
}>;
|
|
28
|
+
/**
|
|
29
|
+
* @lang zh-CN 从主色派生语义状态色组(ADR-012 决策 2)。
|
|
30
|
+
* 继承规则:语义基色的 L = 主色 L 向 0.55(通用可读档)收敛 40%;C = 主色 C 的 85% 并按语义色相
|
|
31
|
+
* 的可显示上限做色域映射(琥珀/绿高彩度可行,蓝红易越域,交给 gamutMap 收敛)。
|
|
32
|
+
* 每组产出与角色色同构的 10 阶 + on 色(bestOnColor)。
|
|
33
|
+
* @lang en Derives the semantic group from the primary (ADR-012 decision 2).
|
|
34
|
+
* Inheritance: the semantic base L converges 40% from the primary L toward 0.55 (a general readable level);
|
|
35
|
+
* C = 85% of the primary's C with per-hue gamut mapping (amber/green tolerate high chroma, blue/red clip).
|
|
36
|
+
* Each group yields the same 10-step scale + on colour as role colours.
|
|
37
|
+
*/
|
|
38
|
+
export declare function deriveSemanticTokens(primaryHex: string): SemanticTokens;
|
|
39
|
+
/**
|
|
40
|
+
* @lang zh-CN 判断语义组是否为派生态(ADR-012 决策 3):`semanticDerived[key]` 为 true 表示仍随主色刷新;
|
|
41
|
+
* 缺省视为用户值(旧预设/手动填入不跟随主色)。
|
|
42
|
+
* @lang en Whether a semantic group is still derived (ADR-012 decision 3): `semanticDerived[key] === true`
|
|
43
|
+
* keeps following the primary; absent means user-managed (old presets and manual input do not follow).
|
|
44
|
+
*/
|
|
45
|
+
export declare function isSemanticDerived(flags: Record<string, boolean> | undefined, key: SemanticStatusKey): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* @lang zh-CN 深拷贝语义组(防调用方后续修改污染已构建主题,与 cloneGradientSettings 同语义)。
|
|
48
|
+
* @lang en Deep-copies a semantic group (prevents external mutation polluting the built theme, same semantics
|
|
49
|
+
* as cloneGradientSettings).
|
|
50
|
+
*/
|
|
51
|
+
export declare function cloneSemanticTokens(tokens: SemanticTokens): SemanticTokens;
|
|
52
|
+
//# sourceMappingURL=semantic.d.ts.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { gamutMapOklch, hexToOklch, clamp } from '../color/convert.js';
|
|
2
|
+
import { tonalScale } from '../color/scale.js';
|
|
3
|
+
import { bestOnColor } from '../color/contrast.js';
|
|
4
|
+
/**
|
|
5
|
+
* @lang zh-CN 语义状态色相锚点(OKLCH 角度,按 2026 主流设计系统约定):
|
|
6
|
+
* success 绿 145 / info 蓝 250 / warning 琥珀 70 / danger 红 25。
|
|
7
|
+
* **不要改动这些色相**——语义色的可辨识度依赖约定;个性化走覆盖机制而非改锚点。
|
|
8
|
+
* @lang en Semantic hue anchors (OKLCH degrees, per 2026 mainstream conventions):
|
|
9
|
+
* success green 145 / info blue 250 / warning amber 70 / danger red 25.
|
|
10
|
+
* **Do not change these** — recognisability depends on convention; personalise via overrides, not anchors.
|
|
11
|
+
*/
|
|
12
|
+
export const SEMANTIC_HUES = { success: 145, info: 250, warning: 70, danger: 25 };
|
|
13
|
+
/** @lang zh-CN 语义状态中英文名(RoleColor.name 消费)。 @lang en Bilingual status names (consumed as RoleColor.name). */
|
|
14
|
+
export const SEMANTIC_NAMES = {
|
|
15
|
+
success: { zh: '成功', en: 'Success' },
|
|
16
|
+
info: { zh: '信息', en: 'Info' },
|
|
17
|
+
warning: { zh: '警告', en: 'Warning' },
|
|
18
|
+
danger: { zh: '危险', en: 'Danger' }
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* @lang zh-CN 从主色派生语义状态色组(ADR-012 决策 2)。
|
|
22
|
+
* 继承规则:语义基色的 L = 主色 L 向 0.55(通用可读档)收敛 40%;C = 主色 C 的 85% 并按语义色相
|
|
23
|
+
* 的可显示上限做色域映射(琥珀/绿高彩度可行,蓝红易越域,交给 gamutMap 收敛)。
|
|
24
|
+
* 每组产出与角色色同构的 10 阶 + on 色(bestOnColor)。
|
|
25
|
+
* @lang en Derives the semantic group from the primary (ADR-012 decision 2).
|
|
26
|
+
* Inheritance: the semantic base L converges 40% from the primary L toward 0.55 (a general readable level);
|
|
27
|
+
* C = 85% of the primary's C with per-hue gamut mapping (amber/green tolerate high chroma, blue/red clip).
|
|
28
|
+
* Each group yields the same 10-step scale + on colour as role colours.
|
|
29
|
+
*/
|
|
30
|
+
export function deriveSemanticTokens(primaryHex) {
|
|
31
|
+
const primary = hexToOklch(primaryHex);
|
|
32
|
+
const out = {};
|
|
33
|
+
// 收敛公式:L_sem = L_primary + (0.55 - L_primary) * 0.4 —— 主色很暗/很亮时语义色仍回到可读区间,
|
|
34
|
+
// 同时保留"暗主题→略暗状态色"的家族感(40% 收敛而非拉平)。
|
|
35
|
+
// <lang en>Convergence: L_sem = L_primary + (0.55 − L_primary) × 0.4 — very dark/bright primaries still land
|
|
36
|
+
// in the readable band while keeping the family feel (40% convergence, not flattening).</lang>
|
|
37
|
+
const LBase = clamp(primary.L + (0.55 - primary.L) * 0.4, 0.4, 0.72);
|
|
38
|
+
const CBase = Math.max(primary.C * 0.85, 0.09); // 低彩主色也要保证状态色可辨(下限 0.09)。
|
|
39
|
+
for (const key of ['success', 'info', 'warning', 'danger']) {
|
|
40
|
+
const hue = SEMANTIC_HUES[key];
|
|
41
|
+
// 色域映射:C 可能超出该色相的可显示范围,gamutMap 收敛后再生成色阶。
|
|
42
|
+
// <lang en>Gamut map first: C may exceed the hue's displayable range, then build the scale.</lang>
|
|
43
|
+
const { hex } = gamutMapOklch(LBase, CBase, hue);
|
|
44
|
+
const scale = tonalScale(hex);
|
|
45
|
+
const role = { name: SEMANTIC_NAMES[key].zh, value: hex, scale, on: bestOnColor(hex).hex };
|
|
46
|
+
out[key] = role;
|
|
47
|
+
}
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* @lang zh-CN 判断语义组是否为派生态(ADR-012 决策 3):`semanticDerived[key]` 为 true 表示仍随主色刷新;
|
|
52
|
+
* 缺省视为用户值(旧预设/手动填入不跟随主色)。
|
|
53
|
+
* @lang en Whether a semantic group is still derived (ADR-012 decision 3): `semanticDerived[key] === true`
|
|
54
|
+
* keeps following the primary; absent means user-managed (old presets and manual input do not follow).
|
|
55
|
+
*/
|
|
56
|
+
export function isSemanticDerived(flags, key) {
|
|
57
|
+
return flags?.[key] === true;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* @lang zh-CN 深拷贝语义组(防调用方后续修改污染已构建主题,与 cloneGradientSettings 同语义)。
|
|
61
|
+
* @lang en Deep-copies a semantic group (prevents external mutation polluting the built theme, same semantics
|
|
62
|
+
* as cloneGradientSettings).
|
|
63
|
+
*/
|
|
64
|
+
export function cloneSemanticTokens(tokens) {
|
|
65
|
+
const cloneRole = (r) => ({ name: r.name, value: r.value, scale: { ...r.scale }, on: r.on });
|
|
66
|
+
return { success: cloneRole(tokens.success), info: cloneRole(tokens.info), warning: cloneRole(tokens.warning), danger: cloneRole(tokens.danger) };
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=semantic.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** @lang zh-CN 色觉模拟类型(三主型,严重度固定 1.0)。 @lang en CVD simulation types (three main ones, severity 1.0). */
|
|
2
|
+
export type CvdType = 'protanopia' | 'deuteranopia' | 'tritanopia';
|
|
3
|
+
/** @lang zh-CN 类型双语标签,供滤镜下拉直接消费。 @lang en Bilingual type labels, consumed directly by filter dropdowns. */
|
|
4
|
+
export declare const CVD_LABELS: Record<CvdType, {
|
|
5
|
+
zh: string;
|
|
6
|
+
en: string;
|
|
7
|
+
}>;
|
|
8
|
+
/**
|
|
9
|
+
* @lang zh-CN Machado 2009 severity 1.0 的 3×3 矩阵(线性 RGB → 线性 RGB)。
|
|
10
|
+
* 每行和 ≈ 1,故灰阶(R=G=B)映射后仍为灰阶;行为已由单测锁定。
|
|
11
|
+
* @lang en Machado 2009 severity-1.0 3×3 matrices (linear RGB → linear RGB). Rows sum to ≈1, so greys map to
|
|
12
|
+
* greys — asserted by tests.
|
|
13
|
+
*/
|
|
14
|
+
export declare const MACHADO_2009_SEV1: Record<CvdType, readonly [number, number, number, number, number, number, number, number, number]>;
|
|
15
|
+
/**
|
|
16
|
+
* @lang zh-CN 对单个 HEX 色做色觉模拟:线性空间应用矩阵后钳制、编码回 HEX。
|
|
17
|
+
* 纯函数;负值钳 0、正值钳 1(矩阵可能把分量推出色域)。
|
|
18
|
+
* @lang en Simulates CVD on one HEX colour: applies the matrix in linear space, clamps, re-encodes to HEX.
|
|
19
|
+
* Pure; negative channels clamp to 0 and >1 to 1 (matrices can push components out of gamut).
|
|
20
|
+
*/
|
|
21
|
+
export declare function simulateCvd(hex: string, type: CvdType): string;
|
|
22
|
+
//# sourceMappingURL=vision.d.ts.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @lang zh-CN 色觉缺陷模拟(`W-tb-P36`):Machado & Oliveira & Fernandes 2009 模型,三种主型
|
|
3
|
+
* (红色弱 protan / 绿色弱 deutan / 蓝黄色弱 tritan)取**严重度 1.0** 的全量矩阵。
|
|
4
|
+
* 变换作用于**线性 RGB**(先 gamma 解码、矩阵相乘、再编码回去)——与论文定义及
|
|
5
|
+
* DaltonLens-Python 参考实现一致;灰阶在行和 ≈1 的性质下保持不变。
|
|
6
|
+
*
|
|
7
|
+
* 来源登记(原则②):Machado, Oliveira & Fernandes, "A Physiologically-based Model for
|
|
8
|
+
* Simulation of Color Vision Deficiency", IEEE Computer Graphics and Applications 25(5), 2009。
|
|
9
|
+
* 矩阵转写自 DaltonLens-Python(MIT,`daltonlens/simulate.py` 的 machado_2009_matrices),
|
|
10
|
+
* 该项目又转引自 colour-science 的 machado2010 数据集。本文件为**自研实现**(MIT 主库),
|
|
11
|
+
* 仅复制论文发表的矩阵数值并注明出处。
|
|
12
|
+
*
|
|
13
|
+
* 参考对照副本:`temp/daltonlens-simulate-reference.py`(T-tb-CLEANUP 清理范围)。
|
|
14
|
+
*
|
|
15
|
+
* @lang en Colour-vision-deficiency simulation (`W-tb-P36`): the Machado, Oliveira & Fernandes 2009 model,
|
|
16
|
+
* three main types (protan / deutan / tritan) at **severity 1.0**. The transform applies to **linear RGB**
|
|
17
|
+
* (gamma-decode, matrix multiply, re-encode) — matching the paper and the DaltonLens-Python reference;
|
|
18
|
+
* greys are invariant because each matrix row sums to ≈1.
|
|
19
|
+
*
|
|
20
|
+
* Source registry (research-first policy): Machado, Oliveira & Fernandes, "A Physiologically-based Model
|
|
21
|
+
* for Simulation of Color Vision Deficiency", IEEE CG&A 25(5), 2009. Matrix values transcribed from
|
|
22
|
+
* DaltonLens-Python (MIT, machado_2009_matrices), which in turn cites colour-science's machado2010 dataset.
|
|
23
|
+
* This file is our own implementation (MIT main repo): only the published paper values are used, credited.
|
|
24
|
+
*
|
|
25
|
+
* Reference copy kept at temp/daltonlens-simulate-reference.py (T-tb-CLEANUP scope).
|
|
26
|
+
*/
|
|
27
|
+
import { hexToRgb, linearToSrgb, rgbToHex, srgbToLinear } from './convert.js';
|
|
28
|
+
/** @lang zh-CN 类型双语标签,供滤镜下拉直接消费。 @lang en Bilingual type labels, consumed directly by filter dropdowns. */
|
|
29
|
+
export const CVD_LABELS = {
|
|
30
|
+
protanopia: { zh: '红色弱模拟', en: 'Protanopia preview' },
|
|
31
|
+
deuteranopia: { zh: '绿色弱模拟', en: 'Deuteranopia preview' },
|
|
32
|
+
tritanopia: { zh: '蓝黄色弱模拟', en: 'Tritanopia preview' }
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* @lang zh-CN Machado 2009 severity 1.0 的 3×3 矩阵(线性 RGB → 线性 RGB)。
|
|
36
|
+
* 每行和 ≈ 1,故灰阶(R=G=B)映射后仍为灰阶;行为已由单测锁定。
|
|
37
|
+
* @lang en Machado 2009 severity-1.0 3×3 matrices (linear RGB → linear RGB). Rows sum to ≈1, so greys map to
|
|
38
|
+
* greys — asserted by tests.
|
|
39
|
+
*/
|
|
40
|
+
export const MACHADO_2009_SEV1 = {
|
|
41
|
+
protanopia: [0.152286, 1.052583, -0.204868, 0.114503, 0.786281, 0.099216, -0.003882, -0.048116, 1.051998],
|
|
42
|
+
deuteranopia: [0.367322, 0.860646, -0.227968, 0.280085, 0.672501, 0.047413, -0.011820, 0.042940, 0.968881],
|
|
43
|
+
tritanopia: [1.255528, -0.076749, -0.178779, -0.078411, 0.930809, 0.147602, 0.004733, 0.691367, 0.303900]
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* @lang zh-CN 对单个 HEX 色做色觉模拟:线性空间应用矩阵后钳制、编码回 HEX。
|
|
47
|
+
* 纯函数;负值钳 0、正值钳 1(矩阵可能把分量推出色域)。
|
|
48
|
+
* @lang en Simulates CVD on one HEX colour: applies the matrix in linear space, clamps, re-encodes to HEX.
|
|
49
|
+
* Pure; negative channels clamp to 0 and >1 to 1 (matrices can push components out of gamut).
|
|
50
|
+
*/
|
|
51
|
+
export function simulateCvd(hex, type) {
|
|
52
|
+
const [r, g, b] = hexToRgb(hex).map(srgbToLinear);
|
|
53
|
+
const m = MACHADO_2009_SEV1[type];
|
|
54
|
+
// 行 × 列:新通道 = 矩阵行与线性 RGB 向量的点积。
|
|
55
|
+
// <lang en>New channel = dot product of a matrix row with the linear RGB vector.</lang>
|
|
56
|
+
const out = [
|
|
57
|
+
m[0] * r + m[1] * g + m[2] * b,
|
|
58
|
+
m[3] * r + m[4] * g + m[5] * b,
|
|
59
|
+
m[6] * r + m[7] * g + m[8] * b
|
|
60
|
+
];
|
|
61
|
+
return rgbToHex(out.map(linearToSrgb));
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=vision.js.map
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @lang zh-CN **情感主色独立数据集**(`W-tb-P34`,维护者校正后重做)。
|
|
3
|
+
*
|
|
4
|
+
* **为什么是独立数据集**:维护者明确要求"情感主色不能关联其它颜色数据"。
|
|
5
|
+
* 早前版本把 24 情感映射到 44 个主色候选库(宝典首色频次 → OKLab 最近邻 → 投票),
|
|
6
|
+
* 结果是语义无关的颜色被最近邻吸到同几个点上(低沉→亮黄、平和→粉红、四个情感挤在同一个粉色),
|
|
7
|
+
* 一望即知是错的。根因不是参数没调好,是**方法本身串了数据源**:候选库是"网站/流行色"的策展集合,
|
|
8
|
+
* 与情感语义没有关系。
|
|
9
|
+
*
|
|
10
|
+
* 本表自带色值,不引用 `primaryCandidates`,也与它零耦合——改候选库不影响本表,反之亦然。
|
|
11
|
+
*
|
|
12
|
+
* **取色依据**:配色宝典为每个情感提供八种组合形态的具体色号,
|
|
13
|
+
* 其中 **单色色彩组合(单色系)** 只用一个色相做明暗变化,最接近"该情感的色彩主张";
|
|
14
|
+
* 其余形态(补色/冲突/三元)混入对比色相,取"首色"只会得到组合排列的噪声。
|
|
15
|
+
* 每条的 `anchor` 是该情感单色系里**只用单一色号的那个组合**(即该情感的核本色相),
|
|
16
|
+
* `secondary` 取该情感单色系中出现频次最高的兄弟色号(同色相不同明暗,天然成对)。
|
|
17
|
+
*
|
|
18
|
+
* 这与宝典的文字描述一致:强烈=离不开红、热情=金橙、平静=蓝、低沉=灰紫、专职=灰黑底衬。
|
|
19
|
+
*
|
|
20
|
+
* **色名为什么有策展值**:自动命名只有 9 档修饰语 × 13 个色相,同一色系的相邻明暗阶必然撞名
|
|
21
|
+
* ——`#DF0029` 与 `#E33539` 都会得到"强红"、古典与可靠都会得到"暗蓝"。这在 44 色候选库里无伤大雅
|
|
22
|
+
* (本来就有分组),但摆在 24 张情感卡上就是明晃晃的重复。故对**撞名的那 8 条**给出策展色名,
|
|
23
|
+
* 其余 16 条仍是自动命名的结果。策展名与色值一一对应,由单测守住(同名即失败)。
|
|
24
|
+
*
|
|
25
|
+
* @lang en **Standalone mood → primary dataset** (`W-tb-P34`, redone after the maintainer's correction).
|
|
26
|
+
*
|
|
27
|
+
* **Why standalone**: the maintainer required that mood primaries must not be tied to any other colour
|
|
28
|
+
* dataset. An earlier version mapped the 24 moods onto the 44-candidate primary library (leading-colour
|
|
29
|
+
* frequency → OKLab nearest neighbour → weighted vote), and semantically unrelated colours collapsed onto
|
|
30
|
+
* the same few points (低沉→bright yellow, 平静→pink, four moods on one pink). The cause was the method
|
|
31
|
+
* mixing datasets, not bad tuning: the candidate library is a curated set of site/trending colours and has
|
|
32
|
+
* nothing to do with mood semantics.
|
|
33
|
+
*
|
|
34
|
+
* This table carries its own colours, references no `primaryCandidates`, and is fully decoupled from it.
|
|
35
|
+
*
|
|
36
|
+
* **Colour source**: the colour handbook gives concrete palette numbers for eight combo forms per mood.
|
|
37
|
+
* **Mono (single-hue) combos** vary one hue's lightness only, which is closest to "this mood's colour
|
|
38
|
+
* claim"; the other forms mix contrasting hues, so their leading colour is mostly arrangement noise.
|
|
39
|
+
* Each row's `anchor` is the palette number used alone in that mood's mono set (the mood's core hue), and
|
|
40
|
+
* `secondary` is the most frequent sibling number in the same set — same hue, different lightness, a natural
|
|
41
|
+
* pair. This matches the handbook's own prose: 强烈 = red-bound, 热情 = golden orange, 平静 = blue,
|
|
42
|
+
* 低沉 = grey-purple, 专职 = grey/black base under accents.
|
|
43
|
+
*/
|
|
44
|
+
/** @lang zh-CN 一条情感主色记录。 @lang en One mood-primary record. */
|
|
45
|
+
export interface MoodPrimaryColor {
|
|
46
|
+
/** @lang zh-CN 情感名(与 `TONE_MOODS` 同源)。 @lang en Mood name (same source as `TONE_MOODS`). */
|
|
47
|
+
mood: string;
|
|
48
|
+
/** @lang zh-CN 宝典色号(可回溯到宝典单色系组合)。 @lang en Handbook palette number (traceable to the mono combo). */
|
|
49
|
+
anchor: number;
|
|
50
|
+
/** @lang zh-CN 主色 HEX(该情感的核本色相)。 @lang en Primary HEX (the mood's core hue). */
|
|
51
|
+
hex: string;
|
|
52
|
+
/** @lang zh-CN 主色中文色名。 @lang en Primary Chinese colour name. */
|
|
53
|
+
zh: string;
|
|
54
|
+
/** @lang zh-CN 主色英文色名。 @lang en Primary English colour name. */
|
|
55
|
+
en: string;
|
|
56
|
+
/** @lang zh-CN 同色系兄弟色号(该情感单色系里频次最高的另一色)。 @lang en Sibling number (most frequent other shade in the mono set). */
|
|
57
|
+
secondaryAnchor: number;
|
|
58
|
+
/** @lang zh-CN 副色 HEX。 @lang en Secondary HEX. */
|
|
59
|
+
secondaryHex: string;
|
|
60
|
+
/** @lang zh-CN 副色中文色名。 @lang en Secondary Chinese colour name. */
|
|
61
|
+
secondaryZh: string;
|
|
62
|
+
/** @lang zh-CN 副色英文色名。 @lang en Secondary English colour name. */
|
|
63
|
+
secondaryEn: string;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* @lang zh-CN 24 情感 → 核本色相与同色系副色(独立数据集,不与主色候选库关联)。
|
|
67
|
+
* 顺序与 `TONE_MOODS` 一致,便于 UI 稳定呈现。
|
|
68
|
+
* @lang en 24 moods → core hue plus its same-hue secondary (standalone; no relation to the candidate library).
|
|
69
|
+
* Ordered like `TONE_MOODS` so the UI renders stably.
|
|
70
|
+
*/
|
|
71
|
+
export declare const MOOD_PRIMARY_COLORS: readonly MoodPrimaryColor[];
|
|
72
|
+
/**
|
|
73
|
+
* @lang zh-CN 按情感名取主色记录;未知情感返回 `undefined`(不编造默认值)。
|
|
74
|
+
* @lang en Looks up a mood record by name; returns `undefined` for unknown moods (never fabricates a default).
|
|
75
|
+
*/
|
|
76
|
+
export declare function moodPrimaryColorFor(mood: string): MoodPrimaryColor | undefined;
|
|
77
|
+
//# sourceMappingURL=mood-primary-colors.d.ts.map
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @lang zh-CN **情感主色独立数据集**(`W-tb-P34`,维护者校正后重做)。
|
|
3
|
+
*
|
|
4
|
+
* **为什么是独立数据集**:维护者明确要求"情感主色不能关联其它颜色数据"。
|
|
5
|
+
* 早前版本把 24 情感映射到 44 个主色候选库(宝典首色频次 → OKLab 最近邻 → 投票),
|
|
6
|
+
* 结果是语义无关的颜色被最近邻吸到同几个点上(低沉→亮黄、平和→粉红、四个情感挤在同一个粉色),
|
|
7
|
+
* 一望即知是错的。根因不是参数没调好,是**方法本身串了数据源**:候选库是"网站/流行色"的策展集合,
|
|
8
|
+
* 与情感语义没有关系。
|
|
9
|
+
*
|
|
10
|
+
* 本表自带色值,不引用 `primaryCandidates`,也与它零耦合——改候选库不影响本表,反之亦然。
|
|
11
|
+
*
|
|
12
|
+
* **取色依据**:配色宝典为每个情感提供八种组合形态的具体色号,
|
|
13
|
+
* 其中 **单色色彩组合(单色系)** 只用一个色相做明暗变化,最接近"该情感的色彩主张";
|
|
14
|
+
* 其余形态(补色/冲突/三元)混入对比色相,取"首色"只会得到组合排列的噪声。
|
|
15
|
+
* 每条的 `anchor` 是该情感单色系里**只用单一色号的那个组合**(即该情感的核本色相),
|
|
16
|
+
* `secondary` 取该情感单色系中出现频次最高的兄弟色号(同色相不同明暗,天然成对)。
|
|
17
|
+
*
|
|
18
|
+
* 这与宝典的文字描述一致:强烈=离不开红、热情=金橙、平静=蓝、低沉=灰紫、专职=灰黑底衬。
|
|
19
|
+
*
|
|
20
|
+
* **色名为什么有策展值**:自动命名只有 9 档修饰语 × 13 个色相,同一色系的相邻明暗阶必然撞名
|
|
21
|
+
* ——`#DF0029` 与 `#E33539` 都会得到"强红"、古典与可靠都会得到"暗蓝"。这在 44 色候选库里无伤大雅
|
|
22
|
+
* (本来就有分组),但摆在 24 张情感卡上就是明晃晃的重复。故对**撞名的那 8 条**给出策展色名,
|
|
23
|
+
* 其余 16 条仍是自动命名的结果。策展名与色值一一对应,由单测守住(同名即失败)。
|
|
24
|
+
*
|
|
25
|
+
* @lang en **Standalone mood → primary dataset** (`W-tb-P34`, redone after the maintainer's correction).
|
|
26
|
+
*
|
|
27
|
+
* **Why standalone**: the maintainer required that mood primaries must not be tied to any other colour
|
|
28
|
+
* dataset. An earlier version mapped the 24 moods onto the 44-candidate primary library (leading-colour
|
|
29
|
+
* frequency → OKLab nearest neighbour → weighted vote), and semantically unrelated colours collapsed onto
|
|
30
|
+
* the same few points (低沉→bright yellow, 平静→pink, four moods on one pink). The cause was the method
|
|
31
|
+
* mixing datasets, not bad tuning: the candidate library is a curated set of site/trending colours and has
|
|
32
|
+
* nothing to do with mood semantics.
|
|
33
|
+
*
|
|
34
|
+
* This table carries its own colours, references no `primaryCandidates`, and is fully decoupled from it.
|
|
35
|
+
*
|
|
36
|
+
* **Colour source**: the colour handbook gives concrete palette numbers for eight combo forms per mood.
|
|
37
|
+
* **Mono (single-hue) combos** vary one hue's lightness only, which is closest to "this mood's colour
|
|
38
|
+
* claim"; the other forms mix contrasting hues, so their leading colour is mostly arrangement noise.
|
|
39
|
+
* Each row's `anchor` is the palette number used alone in that mood's mono set (the mood's core hue), and
|
|
40
|
+
* `secondary` is the most frequent sibling number in the same set — same hue, different lightness, a natural
|
|
41
|
+
* pair. This matches the handbook's own prose: 强烈 = red-bound, 热情 = golden orange, 平静 = blue,
|
|
42
|
+
* 低沉 = grey-purple, 专职 = grey/black base under accents.
|
|
43
|
+
*/
|
|
44
|
+
/**
|
|
45
|
+
* @lang zh-CN 24 情感 → 核本色相与同色系副色(独立数据集,不与主色候选库关联)。
|
|
46
|
+
* 顺序与 `TONE_MOODS` 一致,便于 UI 稳定呈现。
|
|
47
|
+
* @lang en 24 moods → core hue plus its same-hue secondary (standalone; no relation to the candidate library).
|
|
48
|
+
* Ordered like `TONE_MOODS` so the UI renders stably.
|
|
49
|
+
*/
|
|
50
|
+
export const MOOD_PRIMARY_COLORS = [
|
|
51
|
+
{ mood: '强烈', anchor: 4, hex: '#DF0029', zh: '烈红', en: 'Fiery Red', secondaryAnchor: 2, secondaryHex: '#B2001F', secondaryZh: '深红', secondaryEn: 'Deep Red' },
|
|
52
|
+
{ mood: '丰富', anchor: 1, hex: '#8B0016', zh: '深棕', en: 'Deep Brown', secondaryAnchor: 2, secondaryHex: '#B2001F', secondaryZh: '深红', secondaryEn: 'Deep Red' },
|
|
53
|
+
{ mood: '浪漫', anchor: 7, hex: '#F5A89A', zh: '浅红', en: 'Light Red', secondaryAnchor: 6, secondaryHex: '#EE7C6B', secondaryZh: '中红', secondaryEn: 'Moderate Red' },
|
|
54
|
+
{ mood: '奔放', anchor: 12, hex: '#E33539', zh: '焰红', en: 'Flame Red', secondaryAnchor: 10, secondaryHex: '#B6292B', secondaryZh: '深红', secondaryEn: 'Deep Red' },
|
|
55
|
+
{ mood: '土性', anchor: 10, hex: '#B6292B', zh: '深红', en: 'Deep Red', secondaryAnchor: 9, secondaryHex: '#8E1E20', secondaryZh: '深棕', secondaryEn: 'Deep Brown' },
|
|
56
|
+
{ mood: '友善', anchor: 20, hex: '#EC870E', zh: '强橙', en: 'Strong Orange', secondaryAnchor: 18, secondaryHex: '#BD6B09', secondaryZh: '中橙', secondaryEn: 'Moderate Orange' },
|
|
57
|
+
{ mood: '柔和', anchor: 22, hex: '#F5B16D', zh: '浅橙', en: 'Light Orange', secondaryAnchor: 19, secondaryHex: '#D0770B', secondaryZh: '中橙', secondaryEn: 'Moderate Orange' },
|
|
58
|
+
{ mood: '热情', anchor: 28, hex: '#F1AF00', zh: '鲜橙', en: 'Vivid Orange', secondaryAnchor: 27, secondaryHex: '#D59B00', secondaryZh: '鲜橙', secondaryEn: 'Vivid Orange' },
|
|
59
|
+
{ mood: '动感', anchor: 36, hex: '#F9F400', zh: '亮黄', en: 'Brilliant Yellow', secondaryAnchor: 34, secondaryHex: '#C7C300', secondaryZh: '鲜黄', secondaryEn: 'Vivid Yellow' },
|
|
60
|
+
{ mood: '高雅', anchor: 39, hex: '#FFFAB3', zh: '淡黄', en: 'Pale Yellow', secondaryAnchor: 35, secondaryHex: '#DCD800', secondaryZh: '鲜黄', secondaryEn: 'Vivid Yellow' },
|
|
61
|
+
{ mood: '流行', anchor: 44, hex: '#5BBD2B', zh: '强绿', en: 'Strong Green', secondaryAnchor: 42, secondaryHex: '#489620', secondaryZh: '强绿', secondaryEn: 'Strong Green' },
|
|
62
|
+
{ mood: '清新', anchor: 52, hex: '#00A06B', zh: '中绿', en: 'Moderate Green', secondaryAnchor: 49, secondaryHex: '#006241', secondaryZh: '暗绿', secondaryEn: 'Dark Green' },
|
|
63
|
+
{ mood: '传统', anchor: 49, hex: '#006241', zh: '暗绿', en: 'Dark Green', secondaryAnchor: 51, secondaryHex: '#008C5E', secondaryZh: '中绿', secondaryEn: 'Moderate Green' },
|
|
64
|
+
{ mood: '清爽', anchor: 60, hex: '#00A6AD', zh: '中青', en: 'Moderate Cyan', secondaryAnchor: 59, secondaryHex: '#009298', secondaryZh: '中青', secondaryEn: 'Moderate Cyan' },
|
|
65
|
+
{ mood: '热带', anchor: 62, hex: '#6EC3C9', zh: '浅青', en: 'Light Cyan', secondaryAnchor: 59, secondaryHex: '#009298', secondaryZh: '中青', secondaryEn: 'Moderate Cyan' },
|
|
66
|
+
{ mood: '古典', anchor: 68, hex: '#205AA7', zh: '宝蓝', en: 'Sapphire Blue', secondaryAnchor: 69, secondaryHex: '#426EB4', secondaryZh: '中蓝', secondaryEn: 'Moderate Blue' },
|
|
67
|
+
{ mood: '可靠', anchor: 65, hex: '#103667', zh: '藏青', en: 'Navy Blue', secondaryAnchor: 67, secondaryHex: '#1B4F93', secondaryZh: '暗蓝', secondaryEn: 'Dark Blue' },
|
|
68
|
+
{ mood: '平静', anchor: 70, hex: '#7388C1', zh: '中蓝', en: 'Moderate Blue', secondaryAnchor: 72, secondaryHex: '#BFCAE6', secondaryZh: '浅蓝', secondaryEn: 'Light Blue' },
|
|
69
|
+
{ mood: '堂皇', anchor: 76, hex: '#3A2885', zh: '深紫', en: 'Deep Purple', secondaryAnchor: 73, secondaryHex: '#211551', secondaryZh: '暗紫', secondaryEn: 'Dark Purple' },
|
|
70
|
+
{ mood: '神奇', anchor: 84, hex: '#5D0C7B', zh: '茄紫', en: 'Eggplant', secondaryAnchor: 86, secondaryHex: '#8C63A4', secondaryZh: '中品红', secondaryEn: 'Moderate Magenta' },
|
|
71
|
+
{ mood: '怀旧', anchor: 86, hex: '#8C63A4', zh: '暮紫', en: 'Dusk Purple', secondaryAnchor: 83, secondaryHex: '#52096C', secondaryZh: '深品红', secondaryEn: 'Deep Magenta' },
|
|
72
|
+
{ mood: '活力', anchor: 92, hex: '#A2007C', zh: '洋红', en: 'Carmine', secondaryAnchor: 90, secondaryHex: '#780062', secondaryZh: '深品红', secondaryEn: 'Deep Magenta' },
|
|
73
|
+
{ mood: '低沉', anchor: 94, hex: '#C57CAC', zh: '灰紫', en: 'Ash Purple', secondaryAnchor: 92, secondaryHex: '#A2007C', secondaryZh: '深品红', secondaryEn: 'Deep Magenta' },
|
|
74
|
+
{ mood: '专职', anchor: 102, hex: '#898989', zh: '中灰', en: 'Moderate Grey', secondaryAnchor: 99, secondaryHex: '#C2C2C2', secondaryZh: '浅灰', secondaryEn: 'Light Grey' }
|
|
75
|
+
];
|
|
76
|
+
/**
|
|
77
|
+
* @lang zh-CN 按情感名取主色记录;未知情感返回 `undefined`(不编造默认值)。
|
|
78
|
+
* @lang en Looks up a mood record by name; returns `undefined` for unknown moods (never fabricates a default).
|
|
79
|
+
*/
|
|
80
|
+
export function moodPrimaryColorFor(mood) {
|
|
81
|
+
return MOOD_PRIMARY_COLORS.find(m => m.mood === mood);
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=mood-primary-colors.js.map
|