dsh-design-studio 1.0.2 → 1.2.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/lib/core.js CHANGED
@@ -37,6 +37,7 @@ const MAX_ROUTES = 300 // 开发服务器的路由先都记着(只为算出收
37
37
 
38
38
  // 设计类型:决定右侧用什么画幅显示(网页框、手机、小程序、平板、桌面软件窗口、海报、幻灯片、邮件、图表)
39
39
  import { KINDS } from './kinds.js'
40
+ import { mockOf } from './mock.js'
40
41
  export { KINDS }
41
42
  const KIND_ALIAS = {
42
43
  website: 'web', site: 'web', page: 'web', landing: 'web', dashboard: 'web',
@@ -1489,6 +1490,11 @@ export function createTracker({ open, drafts = null, skipPorts = () => new Set()
1489
1490
  return r
1490
1491
  }
1491
1492
 
1493
+ /** 这套设计的模拟数据:{ fp, err },没有 mock.json 给 null */
1494
+ function mockInfo(root) {
1495
+ try { const m = mockOf(root); return m ? { fp: m.fp, err: m.err || '' } : null } catch { return null }
1496
+ }
1497
+
1492
1498
  /** 版本列表(新的在前);开发服务器没有版本(项目自己有 git) */
1493
1499
  function versions(id) {
1494
1500
  const st = states.get(id)
@@ -1565,6 +1571,7 @@ export function createTracker({ open, drafts = null, skipPorts = () => new Set()
1565
1571
  vrev: st.vrev,
1566
1572
  trust: file ? trust() : '', // 「哪些算别人做的」的指纹:所有会话共用,远程看的右侧栏按它作废留着的打包结果
1567
1573
  watch: file ? watchTag(target.root) : '', // 预览服务器有没有在监听这个目录(开始 / 停止监听就变):画布缩略图按它重新要(停了就得自己定时再要)
1574
+ mock: file ? mockInfo(target.root) : null, // 模拟数据(#30):有 mock.json 才有;fp 变了右侧栏的「数据」面板重新连
1568
1575
  focus: file ? path.basename(target.file) : target.path,
1569
1576
  hidden: st.hidden || 0, // 超过上限收起来的屏数
1570
1577
  maxScreens: MAX_SCREENS,
package/lib/drift.js ADDED
@@ -0,0 +1,222 @@
1
+ /**
2
+ * 共用部件各屏写得不一样(#30 第 1 步):同一个 class 的样式,在好几屏自己的 <style> 里各写了一份、写得还不一样。
3
+ *
4
+ * 屏一多、上下文一压缩,模型照抄部件时最容易走样(字号、边距、颜色差一点),单看哪屏都说得过去,放一起就乱。
5
+ * 这里不开浏览器,只读文件:把每屏 <style> 里「.类名」开头的规则按选择器归到一起,比声明,写法不止一种的报出来。
6
+ * 只是提醒(不算体检的问题数):改法是挪进共用的 app.css,各屏删掉自己那份。
7
+ *
8
+ * 只比各屏自己的 <style>:共用的 app.css / tokens.css 本来就只有一份。<link> 进来的样式不看。
9
+ */
10
+ import fs from 'node:fs'
11
+ import path from 'node:path'
12
+
13
+ const MAX_FILES = 600 // 屏再多也只读这么多(几百屏的原型也够)
14
+ const MAX_BYTES = 512 * 1024 // 一屏超过这么大不读
15
+ const MAX_ITEMS = 8
16
+ const PLACE = /^(top|left|right|bottom|inset(-[a-z-]+)?|z-index|position|order|grid-(area|column|row)(-[a-z]+)?|transform|translate|rotate|scale|align-self|justify-self|place-self)$/
17
+
18
+ /** 同一个值的不同记法写成一样(#FFF / #ffffff、0px / 0、.5 / 0.5、单双引号),不然报成「写得不一样」 */
19
+ export function sameValue(v) {
20
+ return String(v)
21
+ .replace(/#([0-9a-f]{3,8})\b/gi, (m, h) => '#' + (h.length === 3 || h.length === 4 ? [...h].map((c) => c + c).join('') : h).toLowerCase())
22
+ .replace(/(^|[\s,(/])0(?:px|em|rem|vh|vw|pt)(?=$|[\s,)/])/g, '$10')
23
+ .replace(/(^|[\s,(/+*-])\.(\d)/g, '$10.$2')
24
+ .replace(/'/g, '"')
25
+ }
26
+
27
+ /** 选择器列表按最外层的逗号分开(:is(.a, .b)、[title="a,b"] 里的逗号不算) */
28
+ export function splitTop(head) {
29
+ const out = []
30
+ let depth = 0
31
+ let quote = ''
32
+ let at = 0
33
+ for (let i = 0; i < head.length; i++) {
34
+ const c = head[i]
35
+ if (quote) { if (c === '\\') i++; else if (c === quote) quote = ''; continue }
36
+ if (c === '"' || c === "'") quote = c
37
+ else if (c === '(' || c === '[') depth++
38
+ else if ((c === ')' || c === ']') && depth > 0) depth--
39
+ else if (c === ',' && !depth) { out.push(head.slice(at, i)); at = i + 1 }
40
+ }
41
+ out.push(head.slice(at))
42
+ return out
43
+ }
44
+
45
+ /** 一段 CSS → [{ sel, decls }](@media 里的规则带上条件当选择器的一部分;@keyframes、@font-face 跳过) */
46
+ export function cssRules(css) {
47
+ const out = []
48
+ const src = String(css || '').replace(/\/\*[\s\S]*?\*\//g, '')
49
+ const walk = (text, prefix, depth) => {
50
+ let i = 0
51
+ while (i < text.length) {
52
+ const open = text.indexOf('{', i)
53
+ if (open < 0) break
54
+ const head = text.slice(i, open).trim()
55
+ // 找配对的 }
56
+ let d = 1
57
+ let j = open + 1
58
+ while (j < text.length && d) { const c = text[j]; if (c === '{') d++; else if (c === '}') d--; j++ }
59
+ const body = text.slice(open + 1, j - 1)
60
+ i = j
61
+ if (!head) continue
62
+ if (head.startsWith('@')) {
63
+ if (depth < 2 && /^@(media|supports|container|layer)\b/i.test(head)) walk(body, prefix + head.replace(/\s+/g, ' ') + ' ', depth + 1)
64
+ continue
65
+ }
66
+ if (body.includes('{')) continue // 嵌套写法(CSS nesting):不认,跳过
67
+ const decls = body.split(';').map((x) => x.trim()).filter(Boolean).map((x) => {
68
+ const k = x.indexOf(':')
69
+ return k > 0 ? [x.slice(0, k).trim().toLowerCase(), sameValue(x.slice(k + 1).trim().replace(/\s+/g, ' ').replace(/\s*,\s*/g, ',').replace(/\s*!\s*important$/i, ' !important'))] : null
70
+ }).filter(Boolean)
71
+ if (!decls.length) continue
72
+ for (const sel of splitTop(head).map((x) => x.trim().replace(/\s+/g, ' ')).filter(Boolean)) out.push({ sel: prefix + sel, decls })
73
+ }
74
+ }
75
+ walk(src, '', 0)
76
+ return out
77
+ }
78
+
79
+ /** 这个选择器像不像「部件」:以 .类名 开头(可以带后代 / 伪类),不碰状态、不是整页的 */
80
+ export function partSel(sel) {
81
+ const s = sel.replace(/^@[^ ]+ [^.]*?(?=\.)/, '') // @media (…) .card → .card
82
+ if (!/^\.[A-Za-z_][\w-]*/.test(s)) return false
83
+ if (/\[data-state|\[data-theme|\[data-mode/.test(sel)) return false // 状态、深浅色各屏本来就不一样
84
+ return true
85
+ }
86
+
87
+ /** 一屏 HTML 里每个 class 用在哪几种标签上(整页只扫一遍;class 按整词认,.card 不算 card-title) */
88
+ function tagTable(html) {
89
+ const out = new Map()
90
+ const re = /<([a-zA-Z][\w-]*)\b[^>]*?\sclass\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+))/g
91
+ let m
92
+ while ((m = re.exec(html))) {
93
+ const tag = m[1].toLowerCase()
94
+ for (const c of (m[2] ?? m[3] ?? m[4] ?? '').split(/\s+/)) {
95
+ if (!c) continue
96
+ if (!out.has(c)) out.set(c, new Set())
97
+ out.get(c).add(tag)
98
+ }
99
+ }
100
+ return out
101
+ }
102
+
103
+ /** 一屏 HTML 里自己写的样式(<style media="(max-width: 600px)"> 的包成 @media,和别的断点分开比) */
104
+ export function inlineCss(html) {
105
+ // 注释掉的旧 <style> 不算(浏览器里它不生效)
106
+ // <template> 里的(没放进页面就不生效)也不算
107
+ return [...String(html || '').replace(/<!--[\s\S]*?(?:-->|$)/g, '').replace(/<template\b[\s\S]*?<\/template\s*>/gi, '').matchAll(/<style\b([^>]*)>([\s\S]*?)<\/style>/gi)].map((m) => {
108
+ const media = /\bmedia\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i.exec(m[1])
109
+ const q = media ? String(media[1] ?? media[2] ?? media[3] ?? '').trim() : ''
110
+ return q && !/^(all|screen)$/i.test(q) ? `@media ${q.replace(/[{}]/g, '')} {${m[2]}}` : m[2]
111
+ }).join('\n')
112
+ }
113
+
114
+ /**
115
+ * 比各屏:pages = [{ key, html }] → [{ sel, screens 写了它的屏数, variants 几种写法, props: [{ prop, values: [{ v, keys }] }] }]
116
+ * 同一屏里同一个选择器写了几次:按出现顺序合起来(后面的盖前面的),和浏览器一样
117
+ */
118
+ /** 几个方向并排(home-a / home-b,或 login / login-b):本来就故意不一样,这几屏不比(和画布认方向一个规则) */
119
+ export function takeKeys(keys) {
120
+ const VAR = /^(.+)-([a-z])\.html?$/i
121
+ const stem = (k) => { const v = VAR.exec(k); return (v ? v[1] : k.replace(/\.html?$/i, '')).toLowerCase() }
122
+ const by = new Map()
123
+ for (const k of keys) { const s = stem(k); if (!by.has(s)) by.set(s, []); by.get(s).push(k) }
124
+ const out = new Set()
125
+ for (const list of by.values()) if (list.length > 1 && list.some((k) => VAR.test(k))) for (const k of list) out.add(k)
126
+ return out
127
+ }
128
+
129
+ export function compareParts(pages, { max = MAX_ITEMS } = {}) {
130
+ const takes = takeKeys(pages.map((p) => p.key))
131
+ pages = pages.filter((p) => !takes.has(p.key))
132
+ const bySel = new Map() // sel → Map(key → Map(prop → value))
133
+ const htmlOf = new Map(pages.map((p) => [p.key, String(p.html || '')]))
134
+ for (const { key, html } of pages) {
135
+ const mine = new Map()
136
+ for (const r of cssRules(inlineCss(html))) {
137
+ if (!partSel(r.sel)) continue
138
+ if (!mine.has(r.sel)) mine.set(r.sel, new Map())
139
+ const m = mine.get(r.sel)
140
+ // 后写的盖前面的;前面那条带 !important、后面的没带:前面的赢(和浏览器一样)
141
+ for (const [k, v] of r.decls) if (!(/ !important$/.test(m.get(k) || '') && !/ !important$/.test(v))) m.set(k, v)
142
+ }
143
+ for (const [sel, m] of mine) {
144
+ if (!bySel.has(sel)) bySel.set(sel, new Map())
145
+ bySel.get(sel).set(key, m)
146
+ }
147
+ }
148
+ const out = []
149
+ // 标签表用到才建(屏多、样式多的设计,只有真写得不一样的部件才要看标签)
150
+ const tables = new Map()
151
+ const tagsOf = (key, cls) => {
152
+ if (!tables.has(key)) tables.set(key, tagTable(htmlOf.get(key)))
153
+ return tables.get(key).get(cls) || new Set()
154
+ }
155
+ for (const [sel, per] of bySel) {
156
+ if (per.size < 2) continue
157
+ // 哪几项不一样:只比两屏以上都写了、值又不一样的(一屏多写一项 = 这页自己加的,不算走样);
158
+ // 位置类的(top / left / z-index / grid-area…)各页本来就摆得不一样,不比
159
+ const props = new Set([...per.values()].flatMap((m) => [...m.keys()]))
160
+ const diff = []
161
+ let shared = 0
162
+ for (const p of props) {
163
+ if (PLACE.test(p)) continue
164
+ const vals = new Map()
165
+ let n = 0
166
+ for (const [key, m] of per) { if (!m.has(p)) continue; n++; const v = m.get(p); if (!vals.has(v)) vals.set(v, []); vals.get(v).push(key) }
167
+ if (n < 2) continue
168
+ shared++
169
+ if (vals.size > 1) diff.push({ prop: p, values: [...vals].map(([v, keys]) => ({ v, keys })).sort((x, y) => y.keys.length - x.keys.length) })
170
+ }
171
+ if (!diff.length) continue
172
+ // 只写了一两项的(.issue{padding-bottom:10px} 对 12px)差一项就是走样;共同写了好几项、一大半都不一样的才当撞名字
173
+ if (shared >= 3 && diff.length * 2 > shared) continue
174
+ // 不是同一个部件、只是撞了名字(首页的 .title 是大标题、详情页的 .title 是小节标题):
175
+ // 标签对不上(一屏是 h1、一屏是 h2)不算;声明一大半都不一样也不算——走了样的部件只差几项
176
+ const cls = /^(?:@[^ ]+ [^.]*?)?\.([A-Za-z_][\w-]*)/.exec(sel)
177
+ if (cls) {
178
+ const tags = [...per.keys()].map((k) => tagsOf(k, cls[1]))
179
+ const known = tags.filter((x) => x.size)
180
+ const seen = new Map() // 标签 → 几屏用它
181
+ for (const x of known) for (const tg of x) seen.set(tg, (seen.get(tg) || 0) + 1)
182
+ if (known.length >= 2 && ![...seen.values()].some((n) => n >= 2)) continue
183
+ }
184
+ const variants = new Set([...per.values()].filter((m) => diff.some((d) => m.has(d.prop))).map((m) => JSON.stringify(diff.map((d) => (m.has(d.prop) ? m.get(d.prop) : null))))).size
185
+ if (variants < 2) continue
186
+ out.push({ sel, screens: per.size, variants, props: diff.slice(0, 4), more: Math.max(0, diff.length - 4), keys: [...per.keys()] })
187
+ }
188
+ // 写的屏越多、写法越多的越要紧
189
+ out.sort((a, b) => b.screens - a.screens || b.variants - a.variants || (a.sel < b.sel ? -1 : 1))
190
+ return { items: out.slice(0, max), more: Math.max(0, out.length - max) }
191
+ }
192
+
193
+ /** 读一套设计的各屏(keys 是相对 root 的文件名)再比 */
194
+ export function partDrift(root, keys) {
195
+ const pages = []
196
+ for (const key of (keys || []).slice(0, MAX_FILES)) {
197
+ const f = path.join(root, key)
198
+ try {
199
+ const st = fs.statSync(f)
200
+ if (!st.isFile() || st.size > MAX_BYTES) continue
201
+ pages.push({ key, html: fs.readFileSync(f, 'utf8') })
202
+ } catch { /* 读不了的跳过 */ }
203
+ }
204
+ return compareParts(pages)
205
+ }
206
+
207
+ const short = (keys, n = 3) => keys.slice(0, n).map((k) => k.replace(/\.html?$/i, '')).join('、') + (keys.length > n ? ` 等 ${keys.length} 屏` : '')
208
+
209
+ /** 给模型的字(体检结果后面接着) */
210
+ export function formatDrift(r, total) {
211
+ if (!r || !r.items.length) return ''
212
+ const lines = [`\n共用部件各屏写得不一样(不算进问题数,是提醒):同一个 class 在几屏自己的 <style> 里各写了一份、还不一样,放一起看会乱。`]
213
+ for (const it of r.items) {
214
+ const ps = it.props.map((p) => `${p.prop}:${p.values.map((x) => `${x.v || '没写'}(${short(x.keys)})`).join(' / ')}`)
215
+ lines.push(`- ${it.sel}:${it.screens} 屏里有 ${it.variants} 种写法。${ps.join(';')}${it.more ? `;还有 ${it.more} 项不同` : ''}`)
216
+ }
217
+ if (r.more) lines.push(`- 还有 ${r.more} 个部件也这样`)
218
+ lines.push(total > 6
219
+ ? '改法:定一种写法挪进共用的 app.css,各屏删掉自己那份。屏多,先告诉用户哪几个部件不一致、问要不要统一,他说改再改,别一口气把所有屏都改了。'
220
+ : '改法:定一种写法(多数屏用的那种)挪进共用的 app.css,各屏删掉自己那份。')
221
+ return lines.join('\n')
222
+ }
@@ -264,7 +264,8 @@ export function packDesign(root, { screens, version = '', license = '', author =
264
264
  // 不在画布上的顶层页面(方向稿删掉了、改名前的旧文件):不打包
265
265
  if (/\.html$/i.test(f.path) && !f.path.includes('/') && !screenSet.has(f.path.toLowerCase())) { skipped.push(f.path); continue }
266
266
  // 别的 JSON(设置、记录、导出的数据…):模板用不上(不能跑脚本),可能带着个人信息,不打包;只留调节滑块的 tweaks.json
267
- if (/\.json$/i.test(f.path) && f.path !== 'tweaks.json') { skipped.push(f.path); continue }
267
+ // 和模拟数据 mock.json(#30:原型的数据源,少了它页面上的绑定全是占位、几种状态一起露出来;JSON 整份查个人信息)
268
+ if (/\.json$/i.test(f.path) && f.path !== 'tweaks.json' && f.path !== 'mock.json') { skipped.push(f.path); continue }
268
269
  let data
269
270
  try {
270
271
  const st = fs.statSync(f.abs)
@@ -291,7 +292,8 @@ export function packDesign(root, { screens, version = '', license = '', author =
291
292
  }
292
293
  }
293
294
  // 自带照片库的图:找图时多拿的、页面没用上的不打包。宁可多带:页面里(解码后)提到这个文件名就留,注释里的不算
294
- const refText = files.filter((f) => /\.(html|css|svg)$/i.test(f.path)).map((f) => refsFold(Buffer.from(f.data).toString('utf8'))).join('\n')
295
+ // mock.json 也算(#30:头像、商品图写在模拟数据里,页面用 data-mock-attr 绑上)
296
+ const refText = files.filter((f) => /\.(html|css|svg)$/i.test(f.path) || f.path === 'mock.json').map((f) => refsFold(Buffer.from(f.data).toString('utf8'))).join('\n')
295
297
  const dropped = new Set()
296
298
  for (let i = files.length - 1; i >= 0; i--) {
297
299
  const f = files[i]
package/lib/handoff.js CHANGED
@@ -21,6 +21,62 @@ import { annotationsMd } from './annotations.js'
21
21
  import { tokensOf } from './system.js'
22
22
  import { FRAMES_DIR } from './frames.js'
23
23
  import { FRAME_MAIN, SLOT_BOX } from './slot.js'
24
+ import { statesOfHtml } from './states.js'
25
+ import { mockOf } from './mock.js'
26
+
27
+ /**
28
+ * 交接文档里的「页面状态」:写了几个状态的屏,列出状态、各状态用到的样式条数、哪些按钮会切到哪个状态
29
+ * @param htmlByKey 屏 → HTML;css 共用样式表的内容(数 [data-state] 规则用)
30
+ */
31
+ export function statesMd(htmlByKey, css = '') {
32
+ const out = []
33
+ for (const [key, html] of htmlByKey) {
34
+ const st = statesOfHtml(html)
35
+ if (!st.length) continue
36
+ const all = String(html) + '\n' + css
37
+ const uses = (n) => (all.match(new RegExp(`\\[data-state\\s*=\\s*["']?${n}["']?\\s*\\]`, 'g')) || []).length
38
+ const names = st.map((x, i) => `\`${x.name}\`${x.label !== x.name ? `(${x.label})` : ''}${i === 0 ? '·默认' : ''}${uses(x.name) ? `,样式 ${uses(x.name)} 处` : ''}`)
39
+ const go = new Set()
40
+ for (const m of String(html).matchAll(/(?:href|data-href|data-to)\s*=\s*["']([^"'#]*?)\?state=([A-Za-z0-9_-]{1,32})/gi)) go.add(`${m[1] ? m[1].replace(/^\.?\//, '') : key} → ${m[2]}`)
41
+ out.push(`- ${key} 有 ${st.length} 个状态:${names.join(';')}。是同一个页面的几种样子:做成一个组件 + 状态(如 \`status: ${st.map((x) => `'${x.name}'`).join(' | ')}\`),按 \`[data-state="…"]\` 那几条样式显示 / 隐藏,别拆成几个页面${go.size ? `;会切状态的链接:${[...go].slice(0, 8).join('、')}` : ''}。`)
42
+ }
43
+ return out
44
+ }
45
+
46
+ /**
47
+ * 交接文档里的「模拟数据」(#30):设计目录里有 mock.json 才有。原型的数据都在这一份里、各屏用 data-mock-* 绑上;
48
+ * 转代码时做成一份初始数据 + 全局状态,页面从状态里读、点了改状态
49
+ */
50
+ export function mockMd(htmlByKey, root) {
51
+ const m = mockOf(root)
52
+ if (!m) return []
53
+ const top = Object.keys(m.data)
54
+ const out = [
55
+ `- 原型的数据都在设计目录的 \`mock.json\` 里${m.err ? `(现在读不出来:${m.err}——先修好再做)` : top.length ? `(顶层:${top.slice(0, 12).join('、')}${top.length > 12 ? ' 等' : ''})` : ''},各屏用 \`data-mock-*\` 绑在上面。照搬成项目里的一份初始数据 + 一个全局状态(Pinia / Zustand / Context / 小程序的全局 store 之类):页面上的值从状态里读,点了改状态,换页还在;以后接真接口只换状态的来源,页面不用动。`,
56
+ '- 写法对照:`data-mock-text` 显示值;`data-mock-show` 条件显示;`data-mock-each="x in list"` + `<template>` 是列表;`data-mock-class` / `data-mock-attr` 按条件加 class、属性;`data-mock-model` 双向绑定的输入框;`data-mock-set="a = …; b = …"` 点了改数据(做成点击事件);`data-mock-reset` 恢复初始数据(演示用)。',
57
+ ]
58
+ const topSet = new Set(top)
59
+ const follow = []
60
+ for (const [key, html] of htmlByKey) {
61
+ const src = String(html)
62
+ const st = /<meta\b[^>]*>/gi
63
+ for (const mm of src.matchAll(st)) {
64
+ if (!/\bname\s*=\s*["']?dsh-states["'\s/>]/i.test(mm[0])) continue
65
+ const d = /\bdata-mock\s*=\s*["']([^"']+)["']/i.exec(mm[0])
66
+ if (d) follow.push(`${key}(${d[1].trim()})`)
67
+ }
68
+ const used = new Set()
69
+ let sets = 0
70
+ for (const a of src.matchAll(/\sdata-mock-(text|show|each|set|model|class|attr)\s*=\s*(?:"([^"]*)"|'([^']*)')/gi)) {
71
+ if (a[1].toLowerCase() === 'set') sets++
72
+ const v = (a[2] !== undefined ? a[2] : a[3] || '').replace(/'[^']*'|"[^"]*"/g, ' ')
73
+ for (const p of v.matchAll(/[A-Za-z_$\u4e00-\u9fa5][\w$\u4e00-\u9fa5]*(?:\.[\w$\u4e00-\u9fa5]+|\[\d+\])*/g)) if (topSet.has(p[0].split(/[.[]/)[0])) used.add(p[0])
74
+ }
75
+ if (used.size || sets) out.push(`- ${key}:用到 ${[...used].slice(0, 8).map((x) => `\`${x}\``).join('、') || '(只有改数据的按钮)'}${used.size > 8 ? ` 等 ${used.size} 个字段` : ''}${sets ? `;点了改数据 ${sets} 处` : ''}`)
76
+ }
77
+ if (follow.length) out.push(`- 状态跟着数据走的屏:${follow.slice(0, 8).join('、')}——这几屏的状态别放在页面自己里,读全局状态的那个字段(一处改了所有页一起变)。`)
78
+ return out
79
+ }
24
80
 
25
81
  export const HANDOFF_DIR = 'handoff'
26
82
  /** 版本名里哪些是用户在右侧栏亲手改的(见 core.js:改字、调样式、调节滑块) */
@@ -601,6 +657,11 @@ export function handoffMd({ root, rows, kind, size, framework, dest, project, sy
601
657
  if (bits.length) inter.push(`- ${key}:${bits.join(';')}`)
602
658
  }
603
659
  lines.push(...(inter.length ? inter : ['- 设计稿里没有脚本和表单,纯展示。']))
660
+ // 一页多状态(#30):同一个页面的几种样子写在一个文件里,转代码时是一个组件带状态,不是几个页面
661
+ const stLines = statesMd(htmlByKey, [...sheets, 'tokens.css'].map((n) => { try { return fs.readFileSync(path.join(root, n), 'utf8') } catch { return '' } }).join('\n'))
662
+ if (stLines.length) lines.push(...stLines)
663
+ lines.push(...mockMd(htmlByKey, root))
664
+ if ([...htmlByKey.values()].some((h) => /\sdata-back\b/i.test(slotHtml(h)))) lines.push('- 写了 `data-back` 的返回按钮:做成「返回上一页」(router.back() / navigation.goBack()),没有上一页时才去它写的 href。')
604
665
  if (hover) lines.push(`- 悬停 / 聚焦 / 按下的样式 ${hover} 处:照搬,别丢。`)
605
666
  if ([...htmlByKey.values()].some((h) => /prefers-color-scheme\s*:\s*dark|data-theme=["']?dark/.test(h)) || /\[data-theme=["']?dark/.test(Object.keys(tok).length ? fs.readFileSync(path.join(root, 'tokens.css'), 'utf8') : '')) lines.push('- 有深色样式:项目里也要能切(跟系统,或 `<html data-theme="dark">`)。')
606
667
  const tw = readTweaks(root)