dsh-project-flow 0.0.0-stage → 0.8.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.
@@ -0,0 +1,288 @@
1
+ /**
2
+ * 版式库:让插件越用越有审美。
3
+ *
4
+ * 思路很简单,但差别很大:
5
+ *
6
+ * - 规矩(aesthetic.mjs)压的是下限:不许蓝紫渐变、不许卡片装一切。写完就这些,不会长。
7
+ * - 这个库长的是上限:每次开工前去网上找几个优秀案例,**只抄骨不抄皮**——
8
+ * 网格怎么分、层级怎么压、留白留多少、视觉重心放哪。抄完入库,下次直接能用。
9
+ *
10
+ * 三条硬约束,不然会变成抄作业:
11
+ *
12
+ * 1. **只存结构,不存像素**。库里是「大标题压图 + 右侧三栏数据」这种句子,
13
+ * 不存图片、不存配色、不存文案。抄皮的东西一律不入库。
14
+ * 2. **每次只取几条,而且带随机**。永远取第一名,做十份东西十份一个样——
15
+ * 那是另一种模板味。
16
+ * 3. **要有反馈**。被采用且质检通过的结构加分,被判 FAIL 的减分。分低自然淘汰,
17
+ * 库会自己收敛到「这套活里真的好用的」那几条。
18
+ *
19
+ * 库文件放在 DSH home 下,不放在项目里:审美是跨项目的手艺,
20
+ * 每换一个工作区就归零,等于永远从零开始学。
21
+ */
22
+ import { mkdir, readFile, writeFile, rename } from 'node:fs/promises'
23
+ import { dirname, join } from 'node:path'
24
+ import { homedir } from 'node:os'
25
+ import { createHash } from 'node:crypto'
26
+ import { withSeeds } from './aesthetic-seeds.mjs'
27
+
28
+ /** 库文件位置。DSH_HOME 优先,跟 profile 走。 */
29
+ export function libraryPath(home = process.env.DSH_HOME ?? join(homedir(), '.dsh')) {
30
+ return join(home, 'project-flow', 'aesthetic-library.json')
31
+ }
32
+
33
+ /** 空的库。 */
34
+ export function emptyLibrary() {
35
+ return { version: 1, updatedAt: new Date().toISOString(), patterns: [] }
36
+ }
37
+
38
+ /**
39
+ * 读库。
40
+ *
41
+ * 返回的永远是「内置 40 条 + 采集到的」:内置那批随插件发布,是地基。
42
+ * 空库也有 40 条可用,不然第一次做东西就没有任何骨架,等于全靠模型自由发挥。
43
+ *
44
+ * 文件不在、坏了、字段不对,一律当成「只有内置」——不能因为库读不出来就把流水停了。
45
+ */
46
+ export async function loadLibrary(path = libraryPath()) {
47
+ let stored = []
48
+ try {
49
+ const text = await readFile(path, 'utf8')
50
+ const data = JSON.parse(text.replace(/^\uFEFF/u, ''))
51
+ stored = Array.isArray(data?.patterns) ? data.patterns.filter(isPattern) : []
52
+ } catch {
53
+ stored = []
54
+ }
55
+ return {
56
+ version: 1,
57
+ updatedAt: new Date().toISOString(),
58
+ patterns: withSeeds(stored),
59
+ }
60
+ }
61
+
62
+ /**
63
+ * 写库。
64
+ *
65
+ * 只落两种:采集来的,以及有战绩的内置条目。内置条目没被用过就不必写盘——
66
+ * 文字永远以插件里那份为准,写下来只是白占地方,还会让改了措辞的更新推不下去。
67
+ */
68
+ export async function saveLibrary(library, path = libraryPath()) {
69
+ const all = Array.isArray(library?.patterns) ? library.patterns.filter(isPattern) : []
70
+ const patterns = all.filter(pattern => pattern.builtin !== true
71
+ || (pattern.used ?? 0) > 0
72
+ || (pattern.wins ?? 0) > 0
73
+ || (pattern.score ?? 0) !== 0)
74
+ const payload = {
75
+ version: 1,
76
+ updatedAt: new Date().toISOString(),
77
+ patterns,
78
+ }
79
+ await mkdir(dirname(path), { recursive: true })
80
+ const temp = `${path}.tmp`
81
+ await writeFile(temp, `${JSON.stringify(payload, null, 2)}\n`, 'utf8')
82
+ await rename(temp, path)
83
+ return payload
84
+ }
85
+
86
+ /** 一条结构至少要有这些,缺了就是脏数据。 */
87
+ function isPattern(item) {
88
+ return item !== null
89
+ && typeof item === 'object'
90
+ && typeof item.id === 'string' && item.id !== ''
91
+ && typeof item.carrier === 'string' && item.carrier !== ''
92
+ && typeof item.name === 'string' && item.name !== ''
93
+ && typeof item.structure === 'string' && item.structure.length >= 8
94
+ }
95
+
96
+ /**
97
+ * 一条结构的指纹。
98
+ *
99
+ * 用载体 + 归一化后的结构描述算,这样同一个骨架从两个网站各搜到一次不会重复入库。
100
+ * 只比结构文本,不比来源——来源不同但骨架一样,那就是同一个骨架。
101
+ */
102
+ export function fingerprint(carrier, structure) {
103
+ const normalized = `${carrier}:${structure}`
104
+ .toLowerCase()
105
+ .replace(/[\s,。、;:""''()()【】\[\]—\-·.]+/gu, '')
106
+ return createHash('sha1').update(normalized).digest('hex').slice(0, 12)
107
+ }
108
+
109
+ /**
110
+ * 把搜到的一批结构并入库。
111
+ *
112
+ * 已有同指纹的:保留原分数,只更新来源和描述(描述可能更准确)。
113
+ * 新指纹:以 0 分入库,等被采用之后靠反馈往上走。
114
+ *
115
+ * @returns {{ library: object, added: number, merged: number }}
116
+ */
117
+ export function mergePatterns(library, incoming, now = new Date().toISOString()) {
118
+ const patterns = Array.isArray(library?.patterns) ? [...library.patterns] : []
119
+ const byId = new Map(patterns.map(pattern => [pattern.id, pattern]))
120
+ let added = 0
121
+ let merged = 0
122
+
123
+ for (const raw of Array.isArray(incoming) ? incoming : []) {
124
+ if (raw === null || typeof raw !== 'object') continue
125
+ const carrier = typeof raw.carrier === 'string' ? raw.carrier.trim() : ''
126
+ const structure = typeof raw.structure === 'string' ? raw.structure.trim() : ''
127
+ const name = typeof raw.name === 'string' ? raw.name.trim() : ''
128
+ if (carrier === '' || structure.length < 8) continue
129
+
130
+ const id = fingerprint(carrier, structure)
131
+ const existing = byId.get(id)
132
+ if (existing !== undefined) {
133
+ existing.structure = structure
134
+ if (name !== '') existing.name = name
135
+ if (typeof raw.why === 'string' && raw.why !== '') existing.why = raw.why
136
+ if (typeof raw.source === 'string' && raw.source !== '') existing.source = raw.source
137
+ existing.updatedAt = now
138
+ merged += 1
139
+ continue
140
+ }
141
+
142
+ const pattern = {
143
+ id,
144
+ carrier,
145
+ name: name === '' ? structure.slice(0, 16) : name,
146
+ structure,
147
+ ...(typeof raw.why === 'string' && raw.why !== '' ? { why: raw.why } : {}),
148
+ ...(typeof raw.source === 'string' && raw.source !== '' ? { source: raw.source } : {}),
149
+ tags: Array.isArray(raw.tags) ? raw.tags.filter(tag => typeof tag === 'string').slice(0, 6) : [],
150
+ score: 0,
151
+ used: 0,
152
+ wins: 0,
153
+ createdAt: now,
154
+ updatedAt: now,
155
+ }
156
+ patterns.push(pattern)
157
+ byId.set(id, pattern)
158
+ added += 1
159
+ }
160
+
161
+ return { library: { version: 1, updatedAt: now, patterns }, added, merged }
162
+ }
163
+
164
+ /**
165
+ * 挑这次要用的结构。
166
+ *
167
+ * 不按分数硬排第一——那样做十份东西十份一个样,只是换了一种模板味。
168
+ * 做法是:按分数分层,高分的进池子,池子里随机抽;分数相同的时候机会一样。
169
+ *
170
+ * @param carriers 这次命中的载体,只从这些载体里挑
171
+ * @param count 最多给几条
172
+ * @param random 注入随机源,测试用
173
+ */
174
+ export function pickPatterns(library, carriers, count = 4, random = Math.random) {
175
+ const wanted = new Set(Array.isArray(carriers) ? carriers : [])
176
+ const pool = (Array.isArray(library?.patterns) ? library.patterns : [])
177
+ .filter(pattern => wanted.has(pattern.carrier))
178
+
179
+ if (pool.length === 0) return []
180
+
181
+ // 分三层:用过的且赢过的、没用过的、被否过的。前两层优先,第三层兜底。
182
+ const rank = pattern => {
183
+ const wins = typeof pattern.wins === 'number' ? pattern.wins : 0
184
+ const used = typeof pattern.used === 'number' ? pattern.used : 0
185
+ const score = typeof pattern.score === 'number' ? pattern.score : 0
186
+ if (score < 0) return 0
187
+ if (used === 0) return 2
188
+ return wins > 0 ? 3 : 1
189
+ }
190
+
191
+ const buckets = new Map()
192
+ for (const pattern of pool) {
193
+ const key = rank(pattern)
194
+ if (!buckets.has(key)) buckets.set(key, [])
195
+ buckets.get(key).push(pattern)
196
+ }
197
+
198
+ const picked = []
199
+ for (const key of [3, 2, 1, 0]) {
200
+ const bucket = buckets.get(key)
201
+ if (bucket === undefined || bucket.length === 0) continue
202
+ const shuffled = [...bucket]
203
+ for (let index = shuffled.length - 1; index > 0; index -= 1) {
204
+ const swap = Math.floor(random() * (index + 1))
205
+ const hold = shuffled[index]
206
+ shuffled[index] = shuffled[swap]
207
+ shuffled[swap] = hold
208
+ }
209
+ picked.push(...shuffled)
210
+ if (picked.length >= count) break
211
+ }
212
+ return picked.slice(0, count)
213
+ }
214
+
215
+ /**
216
+ * 反馈:这一轮用到的结构,质检过了加分,没过分减分。
217
+ *
218
+ * `used` 记被用过几次,`wins` 记其中几次过关。分数夹在 -5 到 +10:
219
+ * 加到 10 就不再涨(一条结构不该永远压制别的),减到 -5 后基本不会被选中。
220
+ *
221
+ * @param verdict 'PASS' / 'FAIL'
222
+ */
223
+ export function feedbackPatterns(library, ids, verdict, now = new Date().toISOString()) {
224
+ const wanted = new Set(Array.isArray(ids) ? ids : [])
225
+ const good = verdict === 'PASS'
226
+ let touched = 0
227
+ const patterns = (Array.isArray(library?.patterns) ? library.patterns : []).map(pattern => {
228
+ if (!wanted.has(pattern.id)) return pattern
229
+ touched += 1
230
+ const used = (typeof pattern.used === 'number' ? pattern.used : 0) + 1
231
+ const wins = (typeof pattern.wins === 'number' ? pattern.wins : 0) + (good ? 1 : 0)
232
+ const raw = (typeof pattern.score === 'number' ? pattern.score : 0) + (good ? 1 : -1)
233
+ return {
234
+ ...pattern,
235
+ used,
236
+ wins,
237
+ score: Math.max(-5, Math.min(10, raw)),
238
+ lastVerdict: good ? 'PASS' : 'FAIL',
239
+ lastUsedAt: now,
240
+ }
241
+ })
242
+ return { library: { ...library, patterns, updatedAt: now }, touched }
243
+ }
244
+
245
+ /** 库的现状,给命令和状态看。 */
246
+ export function librarySummary(library) {
247
+ const patterns = Array.isArray(library?.patterns) ? library.patterns : []
248
+ const byCarrier = new Map()
249
+ for (const pattern of patterns) {
250
+ byCarrier.set(pattern.carrier, (byCarrier.get(pattern.carrier) ?? 0) + 1)
251
+ }
252
+ return {
253
+ total: patterns.length,
254
+ byCarrier: Object.fromEntries(byCarrier),
255
+ builtin: patterns.filter(pattern => pattern.builtin === true).length,
256
+ learned: patterns.filter(pattern => pattern.builtin !== true).length,
257
+ tried: patterns.filter(pattern => (pattern.used ?? 0) > 0).length,
258
+ proven: patterns.filter(pattern => (pattern.wins ?? 0) > 0).length,
259
+ }
260
+ }
261
+
262
+ /**
263
+ * 把挑出来的结构写成能给模型看的一段话。
264
+ *
265
+ * 只说骨架。不说「配色参考这张图」——那是抄皮,抄完四不像,还会撞车。
266
+ */
267
+ export function describePatterns(patterns) {
268
+ const list = Array.isArray(patterns) ? patterns : []
269
+ if (list.length === 0) return ''
270
+ const lines = [
271
+ '',
272
+ '## 从网上案例里提炼的版式骨架(只借结构,不借皮)',
273
+ '',
274
+ '这些是从真实优秀案例里抽出来的骨架。**只照结构做,不要照搬配色、文案、图片。**',
275
+ '抄皮会撞车,抄骨才长本事。',
276
+ '',
277
+ ]
278
+ for (const pattern of list) {
279
+ const marks = []
280
+ if ((pattern.wins ?? 0) > 0) marks.push(`用过 ${pattern.used ?? 0} 次,过关 ${pattern.wins ?? 0} 次`)
281
+ else if ((pattern.used ?? 0) > 0) marks.push(`用过 ${pattern.used ?? 0} 次`)
282
+ lines.push(`- **${pattern.name}**:${pattern.structure}`)
283
+ if (typeof pattern.why === 'string' && pattern.why !== '') lines.push(` - 适合:${pattern.why}`)
284
+ if (marks.length > 0) lines.push(` - 战绩:${marks.join(',')}`)
285
+ }
286
+ lines.push('', '选一到两条作为这次的主骨架。骨架定了再谈细节,别一开始就抠颜色。')
287
+ return lines.join('\n')
288
+ }
@@ -0,0 +1,373 @@
1
+ /**
2
+ * 内置版式骨架:40 条,随插件发布。
3
+ *
4
+ * 为什么要内置一批:
5
+ *
6
+ * 联网采集只能补「这个行业的新鲜做法」,补不了地基。一个刚装好的插件如果库是空的,
7
+ * 第一次做东西就没有任何骨架可依,等于全靠模型自由发挥——那又回到「每个选择都挑最安全的」。
8
+ * 所以地基得随插件一起来,联网采集负责往上加。
9
+ *
10
+ * 三条写这些条目的规矩:
11
+ *
12
+ * 1. **只写骨**。网格怎么分、层级怎么压、留白在哪、重心在哪。不写配色、字体、文案。
13
+ * 2. **每条必须能施工**。反例「现代简约大气」是废话;正例「标题压在整幅图上,右下角一行小字注解」。
14
+ * 3. **彼此不能同构**。40 条里有 3 条其实是同一个版式,那就等于只有 38 条。
15
+ *
16
+ * 这些是**默认分 0 分**的候选,不是推荐。用得好会加分,用不好会被减分——
17
+ * 内置不代表正确,只代表它是个起点。
18
+ */
19
+
20
+ /** @typedef {{ carrier: string, name: string, structure: string, why: string, tags: string[] }} Seed */
21
+
22
+ import { createHash } from 'node:crypto'
23
+
24
+ export const SEED_PATTERNS = [
25
+ // ── PPT / 演示文稿(12)────────────────────────────
26
+ {
27
+ carrier: 'ppt',
28
+ name: '大标题压图',
29
+ structure: '标题压在整幅铺满的图上,右下角一行小字注解,其余区域全部留白',
30
+ why: '开篇定调,气势靠留白',
31
+ tags: ['开场', '留白'],
32
+ },
33
+ {
34
+ carrier: 'ppt',
35
+ name: '三栏对比',
36
+ structure: '标题占左侧三分之一,右侧等分三栏放并列数据或三组对照内容',
37
+ why: '并列对比,弱化装饰',
38
+ tags: ['对比', '栅格'],
39
+ },
40
+ {
41
+ carrier: 'ppt',
42
+ name: '左文右图',
43
+ structure: '版面沿中线对半,左半纯文字左对齐,右半一张通高图不裁切',
44
+ why: '文图并重,最稳的分法',
45
+ tags: ['分栏', '图文'],
46
+ },
47
+ {
48
+ carrier: 'ppt',
49
+ name: '大字报数字',
50
+ structure: '单个数字占到版面宽度一半以上,只配一行不超过十五字的解释',
51
+ why: '一个数字说一件事',
52
+ tags: ['数据', '强调'],
53
+ },
54
+ {
55
+ carrier: 'ppt',
56
+ name: '横轴时间线',
57
+ structure: '一条横线贯穿整页,节点在其上下交错排布,节点只用短标签不用长句',
58
+ why: '进程与阶段',
59
+ tags: ['时间线', '进程'],
60
+ },
61
+ {
62
+ carrier: 'ppt',
63
+ name: '全屏引语',
64
+ structure: '一句话居中,字号占版面宽度三分之二,出处单独靠右下角',
65
+ why: '强调一个判断',
66
+ tags: ['引语', '大字'],
67
+ },
68
+ {
69
+ carrier: 'ppt',
70
+ name: '左目录右留白',
71
+ structure: '左侧竖排编号加章名列表,右侧三分之二整片留白只放一条细线分隔',
72
+ why: '章节页,节奏换气',
73
+ tags: ['目录', '章节'],
74
+ },
75
+ {
76
+ carrier: 'ppt',
77
+ name: '图表主导',
78
+ structure: '一张图占满内容区全宽,标题压在图左上角,图注贴右下角',
79
+ why: '证据页,图表说话',
80
+ tags: ['图表', '证据'],
81
+ },
82
+ {
83
+ carrier: 'ppt',
84
+ name: '对开双页',
85
+ structure: '左半只放一句结论大字,右半放支撑它的三条证据,中间一条竖线',
86
+ why: '结论配证据',
87
+ tags: ['对开', '论证'],
88
+ },
89
+ {
90
+ carrier: 'ppt',
91
+ name: '九宫格',
92
+ structure: '内容区等分三乘三九个格子,每格一句话或一个图形,格间不留间距只留细线',
93
+ why: '并列多条目',
94
+ tags: ['网格', '并列'],
95
+ },
96
+ {
97
+ carrier: 'ppt',
98
+ name: '上下分割',
99
+ structure: '上三分之一是标题带,下三分之二放内容,分界处用一条粗横线压住',
100
+ why: '信息量大时的骨架',
101
+ tags: ['分区', '横线'],
102
+ },
103
+ {
104
+ carrier: 'ppt',
105
+ name: '出血角标',
106
+ structure: '主图出血到页边不留边距,标题斜向压在图上的一角,正文退到另一角',
107
+ why: '刻意破格,一页只破一次',
108
+ tags: ['破格', '出血'],
109
+ },
110
+
111
+ // ── 网页 / 落地页(12)─────────────────────────────
112
+ {
113
+ carrier: 'page',
114
+ name: '首屏单主体',
115
+ structure: '首屏只有一句主标题与一个产品界面截图,其余模块全部压到折叠线以下',
116
+ why: '一屏一件事',
117
+ tags: ['首屏', '单主体'],
118
+ },
119
+ {
120
+ carrier: 'page',
121
+ name: '左右分栏',
122
+ structure: '首屏左右分栏,左侧五成半文案、右侧四成半表单,两侧顶端对齐',
123
+ why: '转化页,文案与动作同屏',
124
+ tags: ['分栏', '转化'],
125
+ },
126
+ {
127
+ carrier: 'page',
128
+ name: '通栏大图',
129
+ structure: '顶部一张通栏图占满宽,标题压在图上,图下开始两列正文',
130
+ why: '品牌感,情绪先行',
131
+ tags: ['通栏', '大图'],
132
+ },
133
+ {
134
+ carrier: 'page',
135
+ name: '交替图文',
136
+ structure: '每屏一组图文左右交替,图宽固定,文字块高度不强制对齐',
137
+ why: '功能罗列不枯燥',
138
+ tags: ['交替', '节奏'],
139
+ },
140
+ {
141
+ carrier: 'page',
142
+ name: '数据横贯',
143
+ structure: '三到四个大数字横排一行占满宽,每个数字下面一行说明,整块上下留双倍空白',
144
+ why: '信任建立',
145
+ tags: ['数据', '一排'],
146
+ },
147
+ {
148
+ carrier: 'page',
149
+ name: '索引式首屏',
150
+ structure: '首屏做成条目索引,每条一行大字号链接,右侧标页码或分类',
151
+ why: '内容站,导览优先',
152
+ tags: ['索引', '导航'],
153
+ },
154
+ {
155
+ carrier: 'page',
156
+ name: '粘性侧栏',
157
+ structure: '左侧窄栏固定目录随滚动常驻,右侧长文单列滚动,两者顶端对齐',
158
+ why: '长文档,随时定位',
159
+ tags: ['侧栏', '长文'],
160
+ },
161
+ {
162
+ carrier: 'page',
163
+ name: '三列定价',
164
+ structure: '三列等宽对比表,中间列底色加深一档并略微上提,其余两列平铺',
165
+ why: '选择页,突出主推',
166
+ tags: ['定价', '对比'],
167
+ },
168
+ {
169
+ carrier: 'page',
170
+ name: '不等高瀑布',
171
+ structure: '三列不等高网格,每张卡片保持原图比例不裁切,列间留固定间距',
172
+ why: '案例墙',
173
+ tags: ['网格', '案例'],
174
+ },
175
+ {
176
+ carrier: 'page',
177
+ name: '极简单列',
178
+ structure: '全文单列,行宽控制在六十五字符内,段落之间只用空白分隔不用分割线',
179
+ why: '阅读优先,最强留白',
180
+ tags: ['单列', '留白'],
181
+ },
182
+ {
183
+ carrier: 'page',
184
+ name: '分屏封面',
185
+ structure: '首屏上下两块大色块对分,标题压在分界线上,跨两块排布',
186
+ why: '强对比开场',
187
+ tags: ['分屏', '色块'],
188
+ },
189
+ {
190
+ carrier: 'page',
191
+ name: '竖向时间线',
192
+ structure: '一条竖线贯穿左侧三分之一处,节点右侧展开说明,节点之间间距不等以制造节奏',
193
+ why: '历程与版本',
194
+ tags: ['时间线', '纵向'],
195
+ },
196
+
197
+ // ── 图文卡片 / 封面(8)───────────────────────────
198
+ {
199
+ carrier: 'card',
200
+ name: '图上字下',
201
+ structure: '上半部一张满宽图,下半部两行字,行距收紧到一点二倍',
202
+ why: '最通用,靠图带点击',
203
+ tags: ['图文', '通用'],
204
+ },
205
+ {
206
+ carrier: 'card',
207
+ name: '单句大字',
208
+ structure: '整张只有一句话,字号大到占宽度八成,四周留白均等',
209
+ why: '观点卡,一句话说透',
210
+ tags: ['大字', '观点'],
211
+ },
212
+ {
213
+ carrier: 'card',
214
+ name: '色块对分',
215
+ structure: '上三分之二是纯色块,下三分之一是文字区,两者不重叠',
216
+ why: '系列统一,靠色块区分',
217
+ tags: ['色块', '分区'],
218
+ },
219
+ {
220
+ carrier: 'card',
221
+ name: '编号序列',
222
+ structure: '左上角一个大号序号,右下角两行小字,中间大片留白不放内容',
223
+ why: '系列更新,靠序号串联',
224
+ tags: ['序号', '系列'],
225
+ },
226
+ {
227
+ carrier: 'card',
228
+ name: '双图对比',
229
+ structure: '左右两张等宽图,中间一条竖线分隔,标题压在竖线顶端',
230
+ why: '前后或好坏对比',
231
+ tags: ['对比', '双图'],
232
+ },
233
+ {
234
+ carrier: 'card',
235
+ name: '内缩边框',
236
+ structure: '内容缩到画面中间七成,四周留白当边框,标题压在留白与内容的交界处',
237
+ why: '克制,适合文字为主',
238
+ tags: ['留白', '边框'],
239
+ },
240
+ {
241
+ carrier: 'card',
242
+ name: '竖排标题',
243
+ structure: '标题竖排在左侧一列,正文横排靠右,两者基线对齐',
244
+ why: '中文竖排,识别度高',
245
+ tags: ['竖排', '中文'],
246
+ },
247
+ {
248
+ carrier: 'card',
249
+ name: '底图压字',
250
+ structure: '整张铺一张图并整体压暗,文字全部压在画面最暗的那一块',
251
+ why: '情绪卡,图为主',
252
+ tags: ['压图', '情绪'],
253
+ },
254
+
255
+ // ── 文档 / 报告 / 简历(8)────────────────────────
256
+ {
257
+ carrier: 'doc',
258
+ name: '单栏长文',
259
+ structure: '正文单栏,每行控制在三十二个汉字左右,标题一律左对齐不居中',
260
+ why: '阅读体验最稳',
261
+ tags: ['单栏', '正文'],
262
+ },
263
+ {
264
+ carrier: 'doc',
265
+ name: '双栏报告',
266
+ structure: '左侧窄栏放注释与出处,右侧宽栏放正文,两栏基线对齐',
267
+ why: '严肃报告,注释不打断',
268
+ tags: ['双栏', '注释'],
269
+ },
270
+ {
271
+ carrier: 'doc',
272
+ name: '表格主导',
273
+ structure: '整页以一张表为主体,去掉全部竖线,横线只留表头与表尾',
274
+ why: '数据密集,一眼可比',
275
+ tags: ['表格', '数据'],
276
+ },
277
+ {
278
+ carrier: 'doc',
279
+ name: '提要框',
280
+ structure: '每个章节开头一个浅底提要框,框内三行以内,正文从框下开始',
281
+ why: '长文档,先给结论',
282
+ tags: ['提要', '章节'],
283
+ },
284
+ {
285
+ carrier: 'doc',
286
+ name: '编号层级',
287
+ structure: '层级只靠编号与字号表达,不用框线不用底色,一级两级字号差一倍',
288
+ why: '最干净的分层法',
289
+ tags: ['层级', '编号'],
290
+ },
291
+ {
292
+ carrier: 'doc',
293
+ name: '右侧边注',
294
+ structure: '正文占左侧四分之三,右侧四分之一窄栏放边注,边注比正文小两号',
295
+ why: '学术感,旁证清晰',
296
+ tags: ['边注', '窄栏'],
297
+ },
298
+ {
299
+ carrier: 'doc',
300
+ name: '章节隔页',
301
+ structure: '每章之前一页只放章节号与章名,编号大到占版面三分之一,其余全空',
302
+ why: '长文档换气',
303
+ tags: ['隔页', '章节'],
304
+ },
305
+ {
306
+ carrier: 'doc',
307
+ name: '左边线简历',
308
+ structure: '左侧一列时间与机构名左对齐,右侧放经历描述,两列之间留一道竖线',
309
+ why: '简历与履历',
310
+ tags: ['简历', '时间线'],
311
+ },
312
+ ]
313
+
314
+ /**
315
+ * 内置条目全部倒进库,缺的补上,已有的保留它的分数。
316
+ *
317
+ * 为什么分数要保留:内置只是「起点」,不代表它好用。一条内置骨架如果连续几次
318
+ * 被质检判 FAIL,它就该沉到后面去——这个判断只能来自实际战绩,不能来自「我写了它」。
319
+ *
320
+ * 文字部分永远以插件里的这份为准:改了措辞要能推下去,不然老用户永远看不到改进。
321
+ *
322
+ * @param patterns 用户库里的条目
323
+ * @returns 合并后的条目,内置在前
324
+ */
325
+ export function withSeeds(patterns) {
326
+ const byId = new Map()
327
+ for (const pattern of Array.isArray(patterns) ? patterns : []) {
328
+ if (pattern !== null && typeof pattern === 'object' && typeof pattern.id === 'string') {
329
+ byId.set(pattern.id, pattern)
330
+ }
331
+ }
332
+
333
+ const merged = []
334
+ const usedIds = new Set()
335
+
336
+ for (const seed of SEED_PATTERNS) {
337
+ const id = localFingerprint(seed.carrier, seed.structure)
338
+ usedIds.add(id)
339
+ const existing = byId.get(id)
340
+ merged.push({
341
+ ...seed,
342
+ id,
343
+ builtin: true,
344
+ // 战绩跟着走,文字以插件里的为准
345
+ score: typeof existing?.score === 'number' ? existing.score : 0,
346
+ used: typeof existing?.used === 'number' ? existing.used : 0,
347
+ wins: typeof existing?.wins === 'number' ? existing.wins : 0,
348
+ ...(existing?.lastVerdict === undefined ? {} : { lastVerdict: existing.lastVerdict }),
349
+ ...(existing?.lastUsedAt === undefined ? {} : { lastUsedAt: existing.lastUsedAt }),
350
+ })
351
+ }
352
+
353
+ // 网上采集来的,或者被改过措辞的老条目,原样留在后面
354
+ for (const [id, pattern] of byId) {
355
+ if (usedIds.has(id)) continue
356
+ merged.push(pattern)
357
+ }
358
+ return merged
359
+ }
360
+
361
+ /**
362
+ * 和 aesthetic-library.mjs 里的 fingerprint 必须是同一套算法,逐字相同。
363
+ *
364
+ * 不同的话,内置条目算出来的 id 和库里学到的对不上,同一条骨架会被当成两条,
365
+ * 战绩也就接不上。所以这里复制一份,而不是各写各的——
366
+ * 测试里有一条专门比两边的结果。
367
+ */
368
+ function localFingerprint(carrier, structure) {
369
+ const normalized = `${carrier}:${structure}`
370
+ .toLowerCase()
371
+ .replace(/[\s,。、;:""''()()【】\[\]—\-·.]+/gu, '')
372
+ return createHash('sha1').update(normalized).digest('hex').slice(0, 12)
373
+ }