@iasiv5/dsh-skills 1.0.0 → 1.0.2

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.
Files changed (37) hide show
  1. package/locale/en.json +6 -0
  2. package/locale/zh.json +6 -0
  3. package/package.json +4 -2
  4. package/skills/answer-me-with-html/SKILL.md +4 -2
  5. package/skills/answer-me-with-html/scripts/am.mjs +627 -192
  6. package/skills/guizang-ppt-skill/README.en.md +10 -8
  7. package/skills/guizang-ppt-skill/README.md +10 -8
  8. package/skills/guizang-ppt-skill/SKILL.md +20 -16
  9. package/skills/guizang-ppt-skill/assets/template-swiss.html +1068 -456
  10. package/skills/guizang-ppt-skill/assets/template.html +991 -225
  11. package/skills/guizang-ppt-skill/references/checklist.md +5 -4
  12. package/skills/guizang-ppt-skill/references/components.md +9 -5
  13. package/skills/guizang-ppt-skill/references/gz-components.md +289 -0
  14. package/skills/guizang-ppt-skill/references/layouts-swiss.md +17 -17
  15. package/skills/guizang-ppt-skill/references/layouts.md +1 -1
  16. package/skills/guizang-ppt-skill/references/themes-swiss.md +57 -86
  17. package/skills/guizang-ppt-skill/references/themes.md +65 -63
  18. package/skills/guizang-ppt-skill/scripts/gz-theme.mjs +434 -0
  19. package/skills/guizang-social-card-skill/HANDOFF.md +19 -1
  20. package/skills/guizang-social-card-skill/README.en.md +20 -7
  21. package/skills/guizang-social-card-skill/README.md +20 -7
  22. package/skills/guizang-social-card-skill/SKILL.md +7 -5
  23. package/skills/guizang-social-card-skill/assets/template-editorial-card.html +954 -126
  24. package/skills/guizang-social-card-skill/assets/template-swiss-card.html +588 -84
  25. package/skills/guizang-social-card-skill/package-lock.json +90 -1
  26. package/skills/guizang-social-card-skill/package.json +7 -4
  27. package/skills/guizang-social-card-skill/references/background-systems.md +7 -15
  28. package/skills/guizang-social-card-skill/references/components.md +16 -10
  29. package/skills/guizang-social-card-skill/references/gz-components.md +289 -0
  30. package/skills/guizang-social-card-skill/references/layout-recipes.md +1 -1
  31. package/skills/guizang-social-card-skill/references/production-workflow.md +10 -12
  32. package/skills/guizang-social-card-skill/references/style-system.md +1 -1
  33. package/skills/guizang-social-card-skill/references/theme-presets.md +59 -111
  34. package/skills/guizang-social-card-skill/scripts/gz-fonts.mjs +654 -0
  35. package/skills/guizang-social-card-skill/scripts/gz-theme.mjs +434 -0
  36. package/skills/guizang-social-card-skill/scripts/render.mjs +92 -0
  37. package/skills/guizang-social-card-skill/validate-social-deck.mjs +11 -6
@@ -1,98 +1,100 @@
1
1
  # 主题色预设(Themes)
2
2
 
3
- 5 套精心调配的主题色板,保证"电子杂志 × 电子墨水"的美学不垮。**不允许用户自定义颜色——色彩搭配错了画面瞬间变丑**,只从以下预设中挑选。
3
+ 5 套精心调配的主题色板,保证"电子杂志 × 电子墨水"的美学不垮。**不直接使用用户给的颜色值——色彩搭配错了画面瞬间变丑**。用户有品牌色或 logo 主色时,走下方「用户给了品牌色」流程生成受约束的主题;否则只从以下预设中挑选。
4
4
 
5
5
  ---
6
6
 
7
+ <!-- GZ:THEMES:START · guizang-design 生成,不要手改;改主题请改 guizang-design/tokens/palettes.json 后运行 scripts/sync-skill.mjs -->
7
8
  ## 使用方法
8
9
 
9
- 1. 问用户选哪套(或基于内容推荐一套)
10
- 2. 打开 `assets/template.html` 的 `<style>` 块
11
- 3. 找到开头的 `:root{` 块
12
- 4. **整体替换**标有"主题色"注释的那几行 `--ink` / `--ink-rgb` / `--paper` / `--paper-rgb` / `--paper-tint` / `--ink-tint`
13
- 5. 其他 CSS 都走 `var(--...)`,无需任何其他改动
10
+ 全部主题已内置在模板的 `GZ:TOKENS` 区块里。选定主题后,只改拷贝好的模板第一行 `<html>` 上的 `data-theme`:
14
11
 
15
- ---
12
+ ```html
13
+ <html lang="zh-CN" data-family="magazine" data-medium="slide" data-theme="indigo-porcelain">
14
+ ```
15
+
16
+ 不要改 `GZ:TOKENS` 区块,也不要在页面里写颜色值。文字、线条、强调色一律用语义变量:
17
+
18
+ | 变量 | 用途 |
19
+ |---|---|
20
+ | `--paper` / `--ink` | 底色 / 主文字 |
21
+ | `--text-body` / `--text-secondary` / `--text-helper` | 正文 / 次要 / 辅助文字,对比度已校验,代替 opacity |
22
+ | `--line` / `--line-strong` / `--line-subtle` | 分割线 |
23
+ | `--accent` | 强调色:色块、细线、圆点、高亮条 |
24
+ | `--accent-ink` | 强调色用作**小字**颜色时用它(浅色强调色会自动加深到可读) |
25
+ | `--accent-display` | 强调色用作**大字**(标题、KPI 数字)颜色时用它 |
26
+ | `--accent-on` / `--accent-on-rgb` | 强调色色块上的文字颜色(黄、绿上是墨色,蓝、橙上是白色) |
16
27
 
17
- ## 🖋 墨水经典 (Monocle 默认)
28
+ ### 用户给了品牌色或 logo 主色
18
29
 
19
- **适合**:通用分享、商业发布、科技产品、任何场景都安全的默认选择。
20
- **调性**:纯墨黑 + 暖米白,杂志感最强,Monocle / Apricot / A Book Apart 风。
30
+ 不要直接使用这个颜色。运行:
21
31
 
22
- ```css
23
- --ink:#0a0a0b;
24
- --ink-rgb:10,10,11;
25
- --paper:#f1efea;
26
- --paper-rgb:241,239,234;
27
- --paper-tint:#e8e5de;
28
- --ink-tint:#18181a;
32
+ ```bash
33
+ node <SKILL_ROOT>/scripts/gz-theme.mjs brand "#4D6BFE" --family magazine
29
34
  ```
30
35
 
36
+ 把输出的 `[data-theme="brand"]{…}` 贴到 deck `<style>` 的末尾,再把 `data-theme` 改成 `brand`。
37
+ 脚本会把颜色收进本风格精调色板的明度 / 彩度区间,并检查 WCAG 与 APCA 对比度;不达标时会说明原因,这时从下面的预设里选。杂志风会把彩度压到 0.12 以内,高饱和的品牌色会变得更克制(例如 #FF2442 → #b75a59,第一行注释会写明调整);需要保留鲜艳度时用瑞士风。
38
+
31
39
  ---
32
40
 
33
- ## 🌊 靛蓝瓷 (Indigo Porcelain)
41
+ ## 🖋 墨水经典 · `ink-classic`(默认)
34
42
 
35
- **适合**:科技/研究/数据分享、工程师文化、深度内容、技术发布会。
36
- **调性**:深靛蓝 + 瓷白,冷静、理性、有深度,像学术期刊或蓝印花瓷器。
43
+ **适合**:通用分享、商业发布、科技产品、任何场景都安全的默认选择。
44
+ **调性**:纯墨黑 + 暖米白,杂志感最强,Monocle / Apricot / A Book Apart 风。
37
45
 
38
- ```css
39
- --ink:#0a1f3d;
40
- --ink-rgb:10,31,61;
41
- --paper:#f1f3f5;
42
- --paper-rgb:241,243,245;
43
- --paper-tint:#e4e8ec;
44
- --ink-tint:#152a4a;
45
- ```
46
+ | paper | ink | accent | accent-ink | accent-on | 正文对比度 |
47
+ |---|---|---|---|---|---|
48
+ | `#f1efea` | `#0a0a0b` | `#111111` | `#111111` | `#f1efea` | 12.3 / 91 |
46
49
 
47
50
  ---
48
51
 
49
- ## 🌿 森林墨 (Forest Ink)
52
+ ## 🌊 靛蓝瓷 · `indigo-porcelain`
50
53
 
51
- **适合**:自然/可持续/文化/非虚构内容、户外品牌、环保主题。
52
- **调性**:深森林绿 + 象牙,沉稳、有呼吸感,像旧版《国家地理》。
54
+ **适合**:科技/研究/数据分享、工程师文化、深度内容、技术发布会。
55
+ **调性**:深靛蓝 + 瓷白,冷静、理性、有深度,像学术期刊或蓝印花瓷器。
53
56
 
54
- ```css
55
- --ink:#1a2e1f;
56
- --ink-rgb:26,46,31;
57
- --paper:#f5f1e8;
58
- --paper-rgb:245,241,232;
59
- --paper-tint:#ece7da;
60
- --ink-tint:#253d2c;
61
- ```
57
+ | paper | ink | accent | accent-ink | accent-on | 正文对比度 |
58
+ |---|---|---|---|---|---|
59
+ | `#f1f3f5` | `#0a1f3d` | `#315d93` | `#315d93` | `#f1f3f5` | 9.3 / 87 |
62
60
 
63
61
  ---
64
62
 
65
- ## 🍂 牛皮纸 (Kraft Paper)
63
+ ## 🌿 森林墨 · `forest-ink`
66
64
 
67
- **适合**:怀旧/人文/阅读/历史/文学分享、独立杂志、手作品牌。
68
- **调性**:深棕 + 暖米,像牛皮信封或老笔记本,温暖、有年代感。
65
+ **适合**:自然/可持续/文化/非虚构内容、户外品牌、环保主题。
66
+ **调性**:深森林绿 + 象牙,沉稳、有呼吸感,像旧版《国家地理》。
69
67
 
70
- ```css
71
- --ink:#2a1e13;
72
- --ink-rgb:42,30,19;
73
- --paper:#eedfc7;
74
- --paper-rgb:238,223,199;
75
- --paper-tint:#e0d0b6;
76
- --ink-tint:#3a2a1d;
77
- ```
68
+ | paper | ink | accent | accent-ink | accent-on | 正文对比度 |
69
+ |---|---|---|---|---|---|
70
+ | `#f5f1e8` | `#1a2e1f` | `#2e6b4f` | `#2e6b4f` | `#f5f1e8` | 8.0 / 83 |
78
71
 
79
72
  ---
80
73
 
81
- ## 🌙 沙丘 (Dune)
74
+ ## 🍂 牛皮纸 · `kraft-paper`
82
75
 
83
- **适合**:艺术/设计/创意/时尚分享、画廊手册、审美优先的私享会。
84
- **调性**:炭灰 + 沙色,克制、高级、中性,像沙漠黄昏或建筑设计图册。
76
+ **适合**:怀旧/人文/阅读/历史/文学分享、独立杂志、手作品牌。
77
+ **调性**:深棕 + 暖米,像牛皮信封或老笔记本,温暖、有年代感。
85
78
 
86
- ```css
87
- --ink:#1f1a14;
88
- --ink-rgb:31,26,20;
89
- --paper:#f0e6d2;
90
- --paper-rgb:240,230,210;
91
- --paper-tint:#e3d7bf;
92
- --ink-tint:#2d2620;
93
- ```
79
+ | paper | ink | accent | accent-ink | accent-on | 正文对比度 |
80
+ |---|---|---|---|---|---|
81
+ | `#eedfc7` | `#2a1e13` | `#9b5a2e` | `#804212` | `#eedfc7` | 8.1 / 77 |
82
+
83
+ ---
84
+
85
+ ## 🌙 沙丘 · `dune`
86
+
87
+ **适合**:艺术/设计/创意/时尚分享、画廊手册、审美优先的私享会。
88
+ **调性**:炭灰 + 沙色,克制、高级、中性,像沙漠黄昏或建筑设计图册。
89
+
90
+ | paper | ink | accent | accent-ink | accent-on | 正文对比度 |
91
+ |---|---|---|---|---|---|
92
+ | `#f0e6d2` | `#1f1a14` | `#8f7650` | `#705833` | `#f0e6d2` | 9.2 / 82 |
93
+
94
+ > 强调色色块上的文字只用大号粗体(APCA 60)。
94
95
 
95
96
  ---
97
+ <!-- GZ:THEMES:END -->
96
98
 
97
99
  ## 推荐选择参考
98
100
 
@@ -116,7 +118,7 @@
116
118
  ## ❌ 不要做的事
117
119
 
118
120
  - ❌ **不允许混搭**(例如 ink 取墨水经典的,paper 取沙丘的)——会彻底违和
119
- - ❌ **不允许用户随便给一个 hex 值**——需委婉拒绝并展示 5 套预设让选
120
- - ❌ **不要直接修改 template.html 其他地方的颜色**——所有散落 rgba 都走 var,改 :root 一处即可
121
+ - ❌ **不要把用户给的 hex 值直接写进页面**——用 `scripts/gz-theme.mjs` 生成受约束的品牌主题;脚本判定不达标时,展示 5 套预设让选
122
+ - ❌ **不要直接修改 template.html 里的颜色**——所有颜色都走语义变量,换主题只改 `<html>` 的 `data-theme` 一处
121
123
 
122
124
  选定主题后在 skill 对话中告诉用户:"用 🖋 墨水经典 / 🌊 靛蓝瓷 ..."并在 deck 项目记录里备注,方便后续迭代时保持一致。
@@ -0,0 +1,434 @@
1
+ #!/usr/bin/env node
2
+ // 歸藏设计系统 · 品牌主题生成(guizang-design v0.1.0 生成,不要手改)
3
+ //
4
+ // node scripts/gz-theme.mjs brand "#4D6BFE" [--family magazine|swiss] [--id brand]
5
+ //
6
+ // 用户给品牌色或 logo 主色时用:颜色被收进现有精调色板的明度 / 彩度区间,并通过 WCAG + APCA 对比度检查。
7
+ // 输出一段 [data-theme="<id>"]{…} CSS,贴进 deck 的 <style> 末尾,再把 <html> 的 data-theme 改成 <id>。
8
+ // 不达标时不输出主题,只给出原因。
9
+ // 色彩基础:sRGB ↔ OKLab / OKLCH、sRGB 色域映射、WCAG 2 对比度、APCA 对比度。
10
+ // 设计系统里所有「科学配色」都建立在这几个函数上:
11
+ // 用 OKLCH 描述颜色(明度 L、彩度 C、色相 H 互相独立,调一个不会把另外两个带偏),
12
+ // 用 WCAG + APCA 两套对比度卡住可读性。纯函数、无依赖。
13
+
14
+ const clamp = (x, lo, hi) => Math.min(hi, Math.max(lo, x))
15
+
16
+ // ---------- hex ----------
17
+
18
+ function parseHex(hex) {
19
+ const m = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(String(hex).trim())
20
+ if (!m) throw new TypeError(`不是合法的 hex 颜色:${hex}`)
21
+ let h = m[1]
22
+ if (h.length === 3) h = h.replace(/./g, (c) => c + c)
23
+ return [0, 2, 4].map((i) => parseInt(h.slice(i, i + 2), 16) / 255)
24
+ }
25
+
26
+ function toHex(rgb) {
27
+ return '#' + rgb.map((c) => Math.round(clamp(c, 0, 1) * 255).toString(16).padStart(2, '0')).join('')
28
+ }
29
+
30
+ // ---------- sRGB 传递函数 ----------
31
+
32
+ const toLinear = (c) => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4)
33
+ const fromLinear = (c) => (c <= 0.0031308 ? 12.92 * c : 1.055 * c ** (1 / 2.4) - 0.055)
34
+
35
+ // ---------- OKLab(Björn Ottosson, 2020) ----------
36
+
37
+ function rgbToOklab([r, g, b]) {
38
+ const R = toLinear(r), G = toLinear(g), B = toLinear(b)
39
+ const l = Math.cbrt(0.4122214708 * R + 0.5363325363 * G + 0.0514459929 * B)
40
+ const m = Math.cbrt(0.2119034982 * R + 0.6806995451 * G + 0.1073969566 * B)
41
+ const s = Math.cbrt(0.0883024619 * R + 0.2817188376 * G + 0.6299787005 * B)
42
+ return [
43
+ 0.2104542553 * l + 0.7936177850 * m - 0.0040720468 * s,
44
+ 1.9779984951 * l - 2.4285922050 * m + 0.4505937099 * s,
45
+ 0.0259040371 * l + 0.7827717662 * m - 0.8086757660 * s,
46
+ ]
47
+ }
48
+
49
+ // 返回未裁剪的 sRGB,可能超出 [0,1],由调用方判断是否在色域内
50
+ function oklabToRgb([L, a, b]) {
51
+ const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3
52
+ const m = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3
53
+ const s = (L - 0.0894841775 * a - 1.2914855480 * b) ** 3
54
+ return [
55
+ fromLinear(4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s),
56
+ fromLinear(-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s),
57
+ fromLinear(-0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s),
58
+ ]
59
+ }
60
+
61
+ // ---------- OKLCH ----------
62
+
63
+ function oklabToOklch([L, a, b]) {
64
+ const C = Math.hypot(a, b)
65
+ let H = (Math.atan2(b, a) * 180) / Math.PI
66
+ if (H < 0) H += 360
67
+ return { l: L, c: C, h: C < 1e-4 ? 0 : H }
68
+ }
69
+
70
+ function oklchToOklab({ l, c, h }) {
71
+ const r = (h * Math.PI) / 180
72
+ return [l, c * Math.cos(r), c * Math.sin(r)]
73
+ }
74
+
75
+ const hexToOklch = (hex) => oklabToOklch(rgbToOklab(parseHex(hex)))
76
+
77
+ const inGamut = (rgb, eps = 1e-6) => rgb.every((c) => c >= -eps && c <= 1 + eps)
78
+
79
+ // 保持明度和色相,二分降低彩度直到落进 sRGB。和 CSS Color 4 的思路一致,足够用于生成色板
80
+ function oklchToHex({ l, c, h }) {
81
+ l = clamp(l, 0, 1)
82
+ let rgb = oklabToRgb(oklchToOklab({ l, c, h }))
83
+ if (!inGamut(rgb)) {
84
+ let lo = 0, hi = c
85
+ while (hi - lo > 1e-5) {
86
+ const mid = (lo + hi) / 2
87
+ if (inGamut(oklabToRgb(oklchToOklab({ l, c: mid, h })))) lo = mid
88
+ else hi = mid
89
+ }
90
+ rgb = oklabToRgb(oklchToOklab({ l, c: lo, h }))
91
+ }
92
+ return toHex(rgb)
93
+ }
94
+
95
+ function maxChroma(l, h) {
96
+ let lo = 0, hi = 0.5
97
+ while (hi - lo > 1e-5) {
98
+ const mid = (lo + hi) / 2
99
+ if (inGamut(oklabToRgb(oklchToOklab({ l, c: mid, h })))) lo = mid
100
+ else hi = mid
101
+ }
102
+ return lo
103
+ }
104
+
105
+ // ---------- 对比度 ----------
106
+
107
+ function luminance(hex) {
108
+ const [r, g, b] = parseHex(hex).map(toLinear)
109
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b
110
+ }
111
+
112
+ // WCAG 2.x:1–21。正文 ≥ 4.5,大字 ≥ 3
113
+ function wcag(fg, bg) {
114
+ const a = luminance(fg), b = luminance(bg)
115
+ return (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05)
116
+ }
117
+
118
+ // APCA (SAPC 0.0.98G-4g):返回 Lc,深字浅底为正、浅字深底为负。
119
+ // 参考阈值:正文 |Lc| ≥ 75,大号正文 ≥ 60,标题 ≥ 45,不承担阅读的装饰 ≥ 30。
120
+ // WCAG 2 对深色背景和中等亮度颜色偏差很大,APCA 更接近人眼,两者都看。
121
+ function apca(fg, bg) {
122
+ const y = (hex) => {
123
+ const [r, g, b] = parseHex(hex).map((c) => c ** 2.4)
124
+ let Y = 0.2126729 * r + 0.7151522 * g + 0.072175 * b
125
+ if (Y < 0.022) Y += (0.022 - Y) ** 1.414
126
+ return Y
127
+ }
128
+ const Yt = y(fg), Yb = y(bg)
129
+ if (Math.abs(Yb - Yt) < 0.0005) return 0
130
+ if (Yb > Yt) {
131
+ const s = (Yb ** 0.56 - Yt ** 0.57) * 1.14
132
+ return s < 0.1 ? 0 : (s - 0.027) * 100
133
+ }
134
+ const s = (Yb ** 0.65 - Yt ** 0.62) * 1.14
135
+ return s > -0.1 ? 0 : (s + 0.027) * 100
136
+ }
137
+
138
+ // 两个颜色在 OKLab 里的距离(ΔEok,×100 便于阅读,≈2 以下肉眼难分)
139
+ function deltaE(a, b) {
140
+ const [L1, a1, b1] = rgbToOklab(parseHex(a))
141
+ const [L2, a2, b2] = rgbToOklab(parseHex(b))
142
+ return Math.hypot(L1 - L2, a1 - a2, b1 - b2) * 100
143
+ }
144
+
145
+ const formatOklch = ({ l, c, h }) => `oklch(${(l * 100).toFixed(1)}% ${c.toFixed(4)} ${h.toFixed(1)})`
146
+
147
+ // 从色板派生完整主题:文字角色、线条、accent-on、accent-ink、-rgb 三元组。
148
+ // 派生规则对所有主题一样,自定义品牌主题也走这里,所以「每套主题都可读」是由规则保证的,不靠逐个手调。
149
+ //
150
+ // 文字角色沿用现有模板的层级比例(PPT / 卡片里正文 .82、次要 .72 这类透明度),
151
+ // 但输出实色而不是透明度:导出 PDF 和截图时透明叠加会出问题,实色也能直接算对比度。
152
+ // 比例混出来的颜色对比度不够时,沿 OKLab 继续往墨色方向推,直到达到该角色的下限。
153
+
154
+
155
+ // APCA |Lc| 下限。参考 APCA 的使用建议:正文 75、大号正文 / 次要文字 60、标题 45、非阅读元素 15–30
156
+ const ROLE_FLOORS = {
157
+ textBody: { apca: 75, wcag: 7 },
158
+ textSecondary: { apca: 60, wcag: 4.5 },
159
+ textHelper: { apca: 60, wcag: 4.5 },
160
+ accentInk: { apca: 60, wcag: 4.5 },
161
+ // 色块上的正文级文字(≥ 16px):WCAG 4.5 + APCA 45。饱和中等明度的底色(安全橙)上 APCA 会低估深色字,
162
+ // WCAG 会高估白字,两个都要过
163
+ onText: { apca: 45, wcag: 4.5 },
164
+ // 大字(标题、KPI 大数字)只看 APCA 标题线 45:WCAG 对明亮饱和色(安全橙)严重低估可读性
165
+ accentDisplay: { apca: 45, wcag: 0 },
166
+ }
167
+
168
+ // 大字用的强调色:原色够大字标准就用原色(保持设计),不够就退到 accent-ink(柠檬黄这类浅色强调色)
169
+ const accentDisplay = (accent, accentInk, paper) => (passes(accent, paper, ROLE_FLOORS.accentDisplay) ? accent : accentInk)
170
+
171
+ // 在 OKLab 里线性混合:t=0 得到 a,t=1 得到 b
172
+ function mix(a, b, t) {
173
+ const A = rgbToOklab(parseHex(a))
174
+ const B = rgbToOklab(parseHex(b))
175
+ return toHex(oklabToRgb(A.map((v, i) => v + (B[i] - v) * t)))
176
+ }
177
+
178
+ const rgbTriplet = (hex) => parseHex(hex).map((c) => Math.round(c * 255)).join(',')
179
+
180
+ const passes = (fg, bg, floor) => Math.abs(apca(fg, bg)) >= floor.apca && wcag(fg, bg) >= floor.wcag
181
+
182
+ // 从 paper 往 ink 混,比例 t 起步;不达标就加大 t
183
+ function inkRole(ink, paper, t, floor) {
184
+ for (let k = t; k <= 1.0001; k += 0.01) {
185
+ const c = mix(paper, ink, Math.min(k, 1))
186
+ if (!floor || passes(c, paper, floor)) return { hex: c, ratio: +Math.min(k, 1).toFixed(2), adjusted: k > t + 1e-9 }
187
+ }
188
+ return { hex: ink, ratio: 1, adjusted: true }
189
+ }
190
+
191
+ // 保持色相,调整明度直到能当文字用:浅底往暗调,深底往亮调
192
+ function textSafeAccent(accent, paper, floor = ROLE_FLOORS.accentInk) {
193
+ if (passes(accent, paper, floor)) return { hex: accent, adjusted: false }
194
+ const { l, c, h } = hexToOklch(accent)
195
+ const dark = hexToOklch(paper).l < 0.5
196
+ for (let step = 1; step <= 200; step++) {
197
+ const L = dark ? l + step * 0.005 : l - step * 0.005
198
+ if (L <= 0 || L >= 1) break
199
+ const hex = oklchToHex({ l: L, c, h })
200
+ if (passes(hex, paper, floor)) return { hex, adjusted: true }
201
+ }
202
+ return { hex: dark ? '#ffffff' : '#000000', adjusted: true }
203
+ }
204
+
205
+ // 在 ink 和 paper 里选对比更强的那个当 accent 上的文字色
206
+ function onColor(bg, candidates) {
207
+ return candidates.reduce((best, c) => (Math.abs(apca(c, bg)) > Math.abs(apca(best, bg)) ? c : best))
208
+ }
209
+
210
+ // 色块上的正文级文字(高亮块正文、标签):设计指定的 accent-on 达到 ROLE_FLOORS.onText 就用它;
211
+ // 不达标(安全橙、中等明度的品牌绿上的白字)换成达标的候选;都不达标取 WCAG 最高的
212
+ function onText(bg, preferred, candidates) {
213
+ const floor = ROLE_FLOORS.onText
214
+ if (passes(preferred, bg, floor)) return preferred
215
+ return candidates.find((c) => passes(c, bg, floor)) || candidates.reduce((best, c) => (wcag(c, bg) > wcag(best, bg) ? c : best))
216
+ }
217
+
218
+ // 强调色小字既出现在纸色上,也出现在 paper-2 / 灰底卡片上:按两者里对比更低的那个底色来调
219
+ const harderBg = (fg, bgs) => bgs.reduce((a, b) => (Math.abs(apca(fg, b)) < Math.abs(apca(fg, a)) ? b : a))
220
+
221
+ function deriveMagazine(t) {
222
+ const roles = {
223
+ textBody: inkRole(t.ink, t.paper, 0.82, ROLE_FLOORS.textBody),
224
+ textSecondary: inkRole(t.ink, t.paper, 0.72, ROLE_FLOORS.textSecondary),
225
+ // 手调的 muted 达标就用它,否则从 paper→ink 派生一个达标的
226
+ textHelper: passes(t.muted, t.paper, ROLE_FLOORS.textHelper)
227
+ ? { hex: t.muted, adjusted: false }
228
+ : inkRole(t.ink, t.paper, 0.55, ROLE_FLOORS.textHelper),
229
+ lineStrong: inkRole(t.ink, t.paper, 0.45),
230
+ line: inkRole(t.ink, t.paper, 0.22),
231
+ lineSubtle: inkRole(t.ink, t.paper, 0.12),
232
+ accentInk: textSafeAccent(t.accent, harderBg(t.accent, [t.paper, t.paper2])),
233
+ }
234
+ return {
235
+ vars: {
236
+ '--paper': t.paper, '--paper-2': t.paper2, '--ink': t.ink, '--muted': t.muted,
237
+ '--accent': t.accent, '--accent-soft': t.accentSoft,
238
+ '--accent-on': onColor(t.accent, [t.ink, t.paper]),
239
+ '--accent-ink': roles.accentInk.hex,
240
+ '--accent-display': accentDisplay(t.accent, roles.accentInk.hex, t.paper),
241
+ // 反色块(以墨色为底)上的强调色文字:同色相提亮到可读,墨水经典的 #111 会变成浅灰
242
+ '--accent-ink-inverse': textSafeAccent(t.accent, t.ink).hex,
243
+ '--text-primary': t.ink,
244
+ '--text-body': roles.textBody.hex,
245
+ '--text-secondary': roles.textSecondary.hex,
246
+ '--text-helper': roles.textHelper.hex,
247
+ '--line-strong': roles.lineStrong.hex,
248
+ '--line': roles.line.hex,
249
+ '--line-subtle': roles.lineSubtle.hex,
250
+ '--ink-rgb': rgbTriplet(t.ink), '--paper-rgb': rgbTriplet(t.paper), '--accent-rgb': rgbTriplet(t.accent),
251
+ '--accent-on-rgb': rgbTriplet(onColor(t.accent, [t.ink, t.paper])),
252
+ '--accent-on-text': onText(t.accent, onColor(t.accent, [t.ink, t.paper]), [t.ink, t.paper, '#ffffff']),
253
+ '--accent-on-text-rgb': rgbTriplet(onText(t.accent, onColor(t.accent, [t.ink, t.paper]), [t.ink, t.paper, '#ffffff'])),
254
+ },
255
+ roles,
256
+ }
257
+ }
258
+
259
+ function deriveSwiss(n, t) {
260
+ const textBody = inkRole(n.ink, n.paper, 0.86, ROLE_FLOORS.textBody)
261
+ return {
262
+ vars: {
263
+ '--paper': n.paper, '--paper-2': n.grey1, '--ink': n.ink, '--muted': n.grey3,
264
+ '--grey-1': n.grey1, '--grey-2': n.grey2, '--grey-3': n.grey3,
265
+ '--accent': t.accent, '--accent-on': t.accentOn, '--accent-ink': t.accentInk,
266
+ '--accent-bright': t.accentBright, '--accent-deep': t.accentDeep,
267
+ '--accent-display': accentDisplay(t.accent, t.accentInk, n.paper),
268
+ // 墨色块上的强调色文字:优先用手调的 accent-bright(IKB 的亮蓝),不够再按规则提亮
269
+ '--accent-ink-inverse': textSafeAccent(t.accentBright, n.ink).hex,
270
+ '--accent-soft': mix(n.paper, t.accent, 0.14),
271
+ '--text-primary': n.ink,
272
+ '--text-body': textBody.hex,
273
+ '--text-secondary': n.textSecondary,
274
+ '--text-helper': n.grey3,
275
+ '--text-placeholder': n.textPlaceholder,
276
+ '--text-on-color': t.accentOn,
277
+ '--line-strong': n.textPlaceholder,
278
+ '--line': n.grey2,
279
+ '--line-subtle': n.borderSubtle,
280
+ '--ink-rgb': rgbTriplet(n.ink), '--paper-rgb': rgbTriplet(n.paper), '--accent-rgb': rgbTriplet(t.accent),
281
+ '--accent-on-rgb': rgbTriplet(t.accentOn),
282
+ '--accent-on-text': onText(t.accent, t.accentOn, [n.ink, '#ffffff']),
283
+ '--accent-on-text-rgb': rgbTriplet(onText(t.accent, t.accentOn, [n.ink, '#ffffff'])),
284
+ },
285
+ roles: { textBody },
286
+ }
287
+ }
288
+
289
+ // 对一套已派生的主题做可读性体检,返回不达标项(不抛错,由调用方决定是失败还是警告)
290
+ function auditTheme(vars) {
291
+ const bg = vars['--paper']
292
+ const checks = [
293
+ ['--text-body', ROLE_FLOORS.textBody],
294
+ ['--text-secondary', ROLE_FLOORS.textSecondary],
295
+ ['--text-helper', ROLE_FLOORS.textHelper],
296
+ ['--accent-ink', ROLE_FLOORS.accentInk],
297
+ ]
298
+ const out = []
299
+ for (const [k, floor] of checks) {
300
+ const fg = vars[k]
301
+ const r = { token: k, fg, bg, wcag: +wcag(fg, bg).toFixed(2), apca: +apca(fg, bg).toFixed(1) }
302
+ if (!passes(fg, bg, floor)) out.push({ ...r, floor })
303
+ }
304
+ // 强调色小字也会放在 paper-2 / 灰底卡片上
305
+ const bg2 = vars['--paper-2']
306
+ if (bg2 && !passes(vars['--accent-ink'], bg2, ROLE_FLOORS.accentInk)) {
307
+ out.push({ token: '--accent-ink', fg: vars['--accent-ink'], bg: bg2, wcag: +wcag(vars['--accent-ink'], bg2).toFixed(2), apca: +apca(vars['--accent-ink'], bg2).toFixed(1), floor: ROLE_FLOORS.accentInk })
308
+ }
309
+ // 色块上的正文级文字
310
+ const onT = vars['--accent-on-text']
311
+ if (onT && !passes(onT, vars['--accent'], ROLE_FLOORS.onText)) {
312
+ out.push({ token: '--accent-on-text', fg: onT, bg: vars['--accent'], apca: +apca(onT, vars['--accent']).toFixed(1), wcag: +wcag(onT, vars['--accent']).toFixed(2), note: '色块上只放大号粗体' })
313
+ }
314
+ // accent 上的文字:大号粗体允许到 Lc 45(APCA 标题线),小字要 60
315
+ const onLc = Math.abs(apca(vars['--accent-on'], vars['--accent']))
316
+ if (onLc < 60) out.push({ token: '--accent-on', fg: vars['--accent-on'], bg: vars['--accent'], apca: +onLc.toFixed(1), wcag: +wcag(vars['--accent-on'], vars['--accent']).toFixed(2), note: onLc >= 45 ? '只能用于大号粗体' : '不可用于文字' })
317
+ return out
318
+ }
319
+
320
+ // 受约束的品牌主题:用户给任意品牌色,生成一套符合家族审美的主题。
321
+ //
322
+ // 不直接用原色。每个颜色槽位都有一个明度 / 彩度区间,区间来自现有精调色板的 OKLCH 实测
323
+ // (见 docs/decisions.md D9),品牌色只贡献色相和「有多鲜艳」的倾向,最终落在区间里。
324
+ // 生成后走和内置主题同一套派生与体检(lib/theme.mjs),不达标就不返回主题。
325
+
326
+
327
+ const r3 = (x) => Math.round(x * 1000) / 1000
328
+
329
+ // 由 tokens/palettes.json 的浅色杂志主题实测(node 脚本见 docs/decisions.md D9)
330
+ const MAGAZINE_BANDS = {
331
+ paper: { l: [0.909, 0.963], c: [0.003, 0.036] },
332
+ paper2: { l: [0.864, 0.929], c: [0.007, 0.039] },
333
+ ink: { l: [0.145, 0.279], c: [0.002, 0.063] },
334
+ muted: { l: [0.499, 0.527], c: [0.015, 0.044] },
335
+ accent: { l: [0.4, 0.58], c: [0.04, 0.12] },
336
+ accentSoft: { l: [0.792, 0.905], c: [0.018, 0.063] },
337
+ }
338
+
339
+ // 瑞士风四个强调色实测彩度 0.181–0.207,下限放宽到 0.15;明度不限,但要留出能派生 bright / deep 的空间
340
+ const SWISS_BANDS = { accent: { l: [0.35, 0.9], c: [0.15, 0.32] } }
341
+
342
+ function place(slot, l, c, h, band, notes) {
343
+ const L = clamp(l, ...band.l)
344
+ const C = Math.min(clamp(c, ...band.c), maxChroma(L, h))
345
+ if (Math.abs(L - l) > 0.02) notes.push(`${slot} 明度 ${r3(l)} → ${r3(L)}`)
346
+ if (Math.abs(C - c) > 0.01) notes.push(`${slot} 彩度 ${r3(c)} → ${r3(C)}`)
347
+ return oklchToHex({ l: L, c: C, h })
348
+ }
349
+
350
+ // 纸张是「有一点颜色的米白」:现有 5 套里 4 套是暖米色(色相 80–90°),靛蓝瓷是几乎无彩的冷白。
351
+ // 所以暖色系品牌把纸张色相往 85° 拉,其余色相只留极低彩度,避免红色品牌生成粉色纸
352
+ function paperTone(b, neutral) {
353
+ if (neutral) return { h: 85, c: 0.007 }
354
+ const warm = b.h >= 20 && b.h <= 115
355
+ return warm ? { h: 85 + (b.h - 85) * 0.3, c: clamp(b.c * 0.05, 0.006, 0.014) } : { h: b.h, c: clamp(b.c * 0.02, 0.003, 0.006) }
356
+ }
357
+
358
+ function magazineFromBrand(brandHex, { name = '品牌主题' } = {}) {
359
+ const b = hexToOklch(brandHex)
360
+ const notes = []
361
+ const B = MAGAZINE_BANDS
362
+ // 品牌色很灰(c<0.02)时按墨水经典处理:色相没有意义,强调色就用墨色
363
+ const neutral = b.c < 0.02
364
+ const h = neutral ? 85 : b.h
365
+ const paper = paperTone(b, neutral)
366
+ const ink = place('ink', 0.22, neutral ? 0.004 : clamp(b.c * 0.35, 0.01, 0.06), h, B.ink, [])
367
+ if (neutral) notes.push('品牌色接近中性灰,强调色改用墨色(同墨水经典)')
368
+ const accent = neutral ? ink : place('accent', b.l, b.c, b.h, B.accent, notes)
369
+ const t = {
370
+ name, scheme: 'light',
371
+ paper: place('paper', 0.95, paper.c, paper.h, B.paper, []),
372
+ paper2: place('paper2', 0.91, paper.c + 0.006, paper.h, B.paper2, []),
373
+ ink,
374
+ muted: place('muted', 0.51, neutral ? 0.015 : clamp(b.c * 0.3, 0.015, 0.044), h, B.muted, []),
375
+ accent,
376
+ }
377
+ t.accentSoft = neutral ? place('accentSoft', 0.86, 0.018, paper.h, B.accentSoft, []) : place('accentSoft', 0.85, clamp(hexToOklch(accent).c * 0.35, 0.018, 0.063), b.h, B.accentSoft, [])
378
+ return finish('magazine', t, deriveMagazine(t), notes)
379
+ }
380
+
381
+ function swissFromBrand(brandHex, neutrals, { name = '品牌主题' } = {}) {
382
+ const b = hexToOklch(brandHex)
383
+ const notes = []
384
+ if (b.c < 0.04) {
385
+ return { ok: false, reason: `品牌色 ${brandHex} 几乎没有彩度,瑞士风需要一个高饱和强调色。可以改用杂志风,或从 logo 里另选一个颜色。` }
386
+ }
387
+ const accent = place('accent', b.l, b.c, b.h, SWISS_BANDS.accent, notes)
388
+ const a = hexToOklch(accent)
389
+ const t = {
390
+ name, accent,
391
+ accentBright: oklchToHex({ l: Math.min(a.l + 0.18, 0.92), c: a.c, h: a.h }),
392
+ accentDeep: oklchToHex({ l: Math.max(a.l - 0.15, 0.2), c: a.c, h: a.h }),
393
+ }
394
+ // accent-on / accent-ink 交给派生规则算,和内置主题一致
395
+ const probe = deriveSwiss(neutrals, { ...t, accentOn: neutrals.ink, accentInk: accent })
396
+ t.accentOn = pickOn(accent, neutrals)
397
+ // 强调色小字也放在灰底卡片(grey-1)上,按更暗的灰底来调
398
+ t.accentInk = textSafe(accent, neutrals.grey1)
399
+ return finish('swiss', t, deriveSwiss(neutrals, t), notes)
400
+ }
401
+
402
+ const pickOn = (accent, n) => (Math.abs(apca('#ffffff', accent)) > Math.abs(apca(n.ink, accent)) ? '#ffffff' : n.ink)
403
+ const textSafe = (accent, paper) => textSafeAccent(accent, paper).hex
404
+
405
+ function finish(family, theme, derived, notes) {
406
+ const problems = auditTheme(derived.vars)
407
+ const hard = problems.filter((p) => !p.note)
408
+ if (hard.length) return { ok: false, family, theme, reason: hard.map((p) => `${p.token} 对比度不足(APCA ${p.apca})`).join(';') }
409
+ return { ok: true, family, theme, vars: derived.vars, notes, limits: problems.filter((p) => p.note).map((p) => `${p.token}:${p.note}`) }
410
+ }
411
+
412
+ // 预览用:把品牌色和生成结果并排给出
413
+ const describe = (r) => (r.ok ? `${r.family} ✓ accent ${r.theme.accent} paper ${r.theme.paper || ''} ink ${r.theme.ink || ''}${r.notes.length ? '|调整:' + r.notes.join(',') : ''}` : `✗ ${r.reason}`)
414
+
415
+ const SWISS_NEUTRALS = {"paper":"#fafaf8","ink":"#0a0a0a","grey1":"#f0f0ee","grey2":"#d4d4d2","grey3":"#737373","textSecondary":"#525252","textPlaceholder":"#a3a3a3","borderSubtle":"#e0e0e0"}
416
+ const args = process.argv.slice(2)
417
+ const opt = (k, d) => (args.includes(k) ? args[args.indexOf(k) + 1] : d)
418
+ if (args[0] !== 'brand' || !args[1]) {
419
+ console.error('用法:node scripts/gz-theme.mjs brand "#4D6BFE" [--family magazine|swiss] [--id brand]')
420
+ process.exit(1)
421
+ }
422
+ const family = opt('--family', 'magazine'), id = opt('--id', 'brand')
423
+ const r = family === 'swiss' ? swissFromBrand(args[1], SWISS_NEUTRALS) : magazineFromBrand(args[1])
424
+ if (!r.ok) { console.error('✗ ' + r.reason); process.exit(1) }
425
+ const v = r.vars
426
+ // 一行说清楚:强调色调了什么、小字和色块上的文字各用什么颜色、有什么限制
427
+ const parts = [
428
+ r.notes.length ? r.notes.join(';') : `强调色保持 ${v['--accent']}`,
429
+ `小字强调色 ${v['--accent-ink']}`,
430
+ `色块上的文字 ${v['--accent-on-text']}${v['--accent-on-text'] !== v['--accent-on'] ? `(${v['--accent-on']} 只够大号粗体)` : ''}`,
431
+ ...r.limits.filter((l) => !l.startsWith('--accent-on:')),
432
+ ]
433
+ console.log(`/* 品牌主题 ${args[1]} · ${family}:${parts.join(';')} */`)
434
+ console.log(`[data-theme="${id}"]{${Object.entries(r.vars).map(([k, v]) => `${k}:${v}`).join(';')};color-scheme:light}`)
@@ -84,7 +84,25 @@ v0.13 起:git 仓库。`local-tests/` 整目录在 `.gitignore` 中,commit
84
84
 
85
85
  仅记录"什么时候新增/变更了哪些可见资产",不记录文风调整。
86
86
 
87
- ### v0.15 · 2026-07-01(本轮)
87
+ ### v0.16 · 2026-10-30(本轮)
88
+
89
+ 主题:**接入 guizang-design 共享设计系统**。PPT、卡片、网页三个 skill 共用一套主题、字号、字体和背景特效,卡片这次先接入。视觉回归用迁移前后同一组卡片逐张比对,再由 agent 用新 skill 实做两套测试卡片验证。
90
+
91
+ **新增**
92
+ - `scripts/render.mjs`:一条命令出图。按页面实际用字把字体子集化内置、等背景定格和图标就绪、按画板尺寸截图并核对尺寸,取代每次现写的 `render.cjs`。需要先在 skill 目录 `npm install`。
93
+ - `scripts/gz-theme.mjs`:受约束的品牌主题生成。用户给品牌色或 logo 主色时用它,不再拒绝品牌色,也不允许直接用原色。
94
+ - `scripts/gz-fonts.mjs`:字体子集化内置;`add` 子命令登记本机商业字体,出图时内置、不上传。
95
+ - `references/gz-components.md`:三个 skill 共用的组件写法。
96
+
97
+ **修改**
98
+ - 两份种子模板的主题、字号、字体、背景特效换成设计系统生成的 `GZ:*` 区块,主题改由 `<html data-theme>` 切换(Swiss 旧的 `data-accent` 仍有效)。
99
+ - Editorial 背景改用共享 inkflow:原版 WebGL 没有预乘 alpha,纸色被冲成接近纯白,现在恢复米色纸张和墨流晕染。
100
+ - 强调色小字统一用对比度达标的 `--accent-ink`,大字用 `--accent-display`;柠檬黄等浅色主题的强调文字不再看不清。
101
+ - 中文不用斜体:pullquote / callout 去掉 italic。
102
+ - `validate-social-deck.mjs`:字号下限与设计系统一致;风格优先按 `data-family` 判断(修好 Swiss 被误判成 Editorial);配对预览里的副本不重复校验。
103
+ - 公众号配对预览按实际宽度排版,不再被裁。
104
+
105
+ ### v0.15 · 2026-07-01
88
106
 
89
107
  主题:**Live Photo 从一次测试能力收口成 Skill 规则**。本轮把两天聊天里关于平台限制、拼图版式、长视频处理、品类判断、发布路径和执行失误的结论写回文档,并补上文档测试。
90
108