dsh-design-studio 0.23.0 → 0.24.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
@@ -48,6 +48,7 @@ const KIND_ALIAS = {
48
48
  mail: 'email', newsletter: 'email', edm: 'email',
49
49
  mindmap: 'diagram', 'mind-map': 'diagram', roadmap: 'diagram', architecture: 'diagram', arch: 'diagram', flowchart: 'diagram', 思维导图: 'diagram', 导图: 'diagram', 脑图: 'diagram', 路线图: 'diagram', 技术路线图: 'diagram', 架构图: 'diagram', 图表: 'diagram',
50
50
  dsh: 'dshplugin', 'dsh-plugin': 'dshplugin', dshplug: 'dshplugin', harness: 'dshplugin', dsh插件: 'dshplugin', 'dsh 插件': 'dshplugin',
51
+ frame: 'framed', 外框: 'framed', 自定外框: 'framed', 套外框: 'framed',
51
52
  }
52
53
 
53
54
  /** 类型名(含常见别名)→ KINDS 里的一个;认不出返回 '' */
package/lib/frames.js ADDED
@@ -0,0 +1,436 @@
1
+ /**
2
+ * 外框库:用户自己的外框(浏览器插件弹窗、某个软件的侧栏 …),做设计时原样套上,模型只写 data-slot 里面。
3
+ *
4
+ * <库>/<id>/frame.json { id, name, nameEn?, desc?, size: [w, h], css: [..], frames: [{ id, file, name, desc?, slots: { main: '说明', .. } }] }
5
+ * <库>/<id>/<位置>.html 一个位置一个页面:根元素 data-frame="<id>/<位置 id>",槽位 data-slot;
6
+ * 存的时候写进 <meta name="dsh-design" content="framed WxH"> 和 <template id="dsh-frame">(指纹、几处样式)
7
+ * <库>/<id>/*.css、assets/ 外框的样式、图
8
+ *
9
+ * 存:save_frame 工具给一个写好外框的文件夹 → 检查 frame.json → 无头浏览器打开每个位置(浅色、深色)算指纹、量样式、截图 → 写进库。
10
+ * 指纹和样式是页面里的设计台脚本算的(和体检「外框被改动」同一段代码),复制到设计目录的页面自己带着,换台电脑打开也能查。
11
+ * 技能目录里的 DSH 外框(frames/dsh)是自带的,不在库里;id「dsh」留给它。
12
+ */
13
+
14
+ import fs from 'node:fs'
15
+ import os from 'node:os'
16
+ import path from 'node:path'
17
+ import { createHub } from './serve.js'
18
+ import { prepare } from './look.js'
19
+ import { srcsetParts } from './bundle.js'
20
+
21
+ export const FRAMES_DIR = process.env.DSH_DESIGN_FRAMES_DIR || path.join(os.homedir(), '.dsh', 'design-frames') // 测试时用环境变量换到临时目录
22
+ export const ID_RE = /^[a-z0-9][a-z0-9-]{0,39}$/
23
+ const SLOT_RE = /^[a-z][a-z0-9-]{0,30}$/
24
+ const FILE_RE = /^[\w.-]{1,80}$/
25
+ const RESERVED = new Set(['dsh'])
26
+ const MAX_POS = 8
27
+ const MAX_ASSETS = 5 * 1024 * 1024
28
+ const MAX_ASSET_FILES = 200
29
+ const ASSET_EXT = /\.(svg|png|jpe?g|webp|gif|avif|ico|woff2?|ttf|otf|css)$/i
30
+
31
+ const plainFile = (f) => typeof f === 'string' && FILE_RE.test(f) && !/^\.+$/.test(f)
32
+
33
+ /** 写好外框的文件夹 → { m: 整理过的 frame.json, problems: [...] } */
34
+ export function readManifest(src) {
35
+ const problems = []
36
+ let raw
37
+ try {
38
+ raw = JSON.parse(fs.readFileSync(path.join(src, 'frame.json'), 'utf8').replace(/^/, ''))
39
+ } catch (e) {
40
+ return { m: null, problems: [fs.existsSync(path.join(src, 'frame.json')) ? `frame.json 不是合法的 JSON:${String(e.message).slice(0, 120)}` : `${src} 里没有 frame.json`] }
41
+ }
42
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return { m: null, problems: ['frame.json 要是一个对象'] }
43
+ const id = String(raw.id || '')
44
+ if (!ID_RE.test(id)) problems.push(`id「${id}」不行:只用小写字母、数字和连字符,40 个字以内(比如 chrome-popup)`)
45
+ else if (RESERVED.has(id)) problems.push(`id「${id}」留给自带的 DSH 外框了,换一个`)
46
+ const name = String(raw.name || '').trim()
47
+ if (!name || name.length > 30) problems.push('name 要写(外框叫什么,30 个字以内,如「Chrome 插件弹窗」)')
48
+ const size = Array.isArray(raw.size) ? raw.size.map(Number) : []
49
+ if (size.length !== 2 || !size.every((n) => Number.isInteger(n) && n >= 200 && n <= 4000)) problems.push('size 写成 [宽, 高],整数,200–4000(外框整个画面多大,如 [400, 600])')
50
+ const css = (Array.isArray(raw.css) ? raw.css : raw.css ? [raw.css] : []).map(String)
51
+ for (const f of css) {
52
+ if (!plainFile(f) || !/\.css$/i.test(f)) problems.push(`css「${f}」要是这个文件夹里的 .css 文件名(不带目录)`)
53
+ else if (!fs.existsSync(path.join(src, f))) problems.push(`css「${f}」找不到`)
54
+ }
55
+ const list = Array.isArray(raw.frames) ? raw.frames : []
56
+ if (!list.length || list.length > MAX_POS) problems.push(`frames 写 1–${MAX_POS} 个位置:[{ id, file, name, slots: { main: '说明' } }]`)
57
+ const seen = new Set()
58
+ const frames = list.slice(0, MAX_POS).map((f, i) => {
59
+ const x = f && typeof f === 'object' ? f : {}
60
+ const fid = String(x.id || '')
61
+ const tag = `frames[${i}]${fid ? `(${fid})` : ''}`
62
+ if (!ID_RE.test(fid)) problems.push(`${tag} 的 id 只用小写字母、数字和连字符`)
63
+ else if (seen.has(fid)) problems.push(`${tag} 的 id 重复了`)
64
+ seen.add(fid)
65
+ const file = String(x.file || '')
66
+ if (!plainFile(file) || !/\.html?$/i.test(file)) problems.push(`${tag} 的 file 要是这个文件夹里的 .html 文件名`)
67
+ else if (!fs.existsSync(path.join(src, file))) problems.push(`${tag} 的 file「${file}」找不到`)
68
+ const slots = x.slots && typeof x.slots === 'object' && !Array.isArray(x.slots) ? x.slots : {}
69
+ const names = Object.keys(slots)
70
+ if (!names.includes('main')) problems.push(`${tag} 的 slots 里要有 main(插件 / 页面主体放的地方)`)
71
+ for (const s of names) if (!SLOT_RE.test(s)) problems.push(`${tag} 的槽位名「${s}」只用小写字母、数字和连字符`)
72
+ const fname = String(x.name || '').trim()
73
+ if (!fname) problems.push(`${tag} 要写 name(这个位置叫什么,如「弹窗」)`)
74
+ return { id: fid, file, name: fname.slice(0, 30), desc: String(x.desc || '').slice(0, 200), slots: Object.fromEntries(names.map((s) => [s, String(slots[s] || '').slice(0, 200)])) }
75
+ })
76
+ const m = { id, name: name.slice(0, 30), nameEn: String(raw.nameEn || '').slice(0, 40), desc: String(raw.desc || '').slice(0, 300), size, css, frames }
77
+ return { m, problems }
78
+ }
79
+
80
+ /** 页面开头的类型标记换成(或补上)framed WxH */
81
+ export function ensureMeta(html, w, h) {
82
+ const tag = `<meta name="dsh-design" content="framed ${w}x${h}">`
83
+ const re = /<meta\b[^>]*\bname\s*=\s*["']?dsh-design\b[^>]*>/i
84
+ if (re.test(html)) return html.replace(re, tag)
85
+ return headInsertAfterCharset(html, tag)
86
+ }
87
+
88
+ /**
89
+ * 外框库写进页面的那段(指纹、几处样式):<template id="dsh-frame">JSON</template>(不用 <script>:分享到设计市场不收脚本)。
90
+ * 有就换掉;新写的放在 </head> 前面(别把开头的类型标记挤到读取范围外)。< > & 都转成 \\u 写法,模板里的字就是原样的 JSON
91
+ */
92
+ export function injectFrameData(html, data) {
93
+ const json = JSON.stringify(data).replace(/</g, '\\u003c').replace(/>/g, '\\u003e').replace(/&/g, '\\u0026')
94
+ const tag = `<template id="dsh-frame">${json}</template>`
95
+ const re = /<(script|template)\b[^>]*\bid\s*=\s*["']?dsh-frame["']?[^>]*>[\s\S]*?<\/\1\s*>/gi
96
+ const clean = html.replace(re, '')
97
+ const end = /<\/head\s*>/i.exec(clean)
98
+ if (end) return clean.slice(0, end.index) + tag + '\n' + clean.slice(end.index)
99
+ return headInsertAfterCharset(clean, tag)
100
+ }
101
+
102
+ function headInsertAfterCharset(html, tag) {
103
+ const cs = /<meta\b[^>]*\bcharset\b[^>]*>/i.exec(html)
104
+ if (cs) return html.slice(0, cs.index + cs[0].length) + '\n' + tag + html.slice(cs.index + cs[0].length)
105
+ const hd = /<head\b[^>]*>/i.exec(html)
106
+ if (hd) return html.slice(0, hd.index + hd[0].length) + '\n' + tag + html.slice(hd.index + hd[0].length)
107
+ // 没写 <head>:放在 doctype、<html> 后面(放到 doctype 前面页面会进怪异模式)
108
+ const dt = /^\ufeff?\s*(?:<!--[\s\S]*?-->\s*)*<!doctype[^>]*>/i.exec(html)
109
+ let at = dt ? dt[0].length : 0
110
+ const ht = /<html\b[^>]*>/i.exec(html.slice(at))
111
+ if (ht && !/\S/.test(html.slice(at, at + ht.index).replace(/<!--[\s\S]*?-->/g, ''))) at += ht.index + ht[0].length
112
+ return html.slice(0, at) + '\n' + tag + html.slice(at)
113
+ }
114
+
115
+ /** 库里的外框:[{ id, name, nameEn, desc, size, dir, frames }],按名字排;坏的跳过 */
116
+ export function listFrames(dir = FRAMES_DIR) {
117
+ let names = []
118
+ try { names = fs.readdirSync(dir) } catch { return [] }
119
+ const out = []
120
+ for (const n of names) {
121
+ if (!ID_RE.test(n) || RESERVED.has(n)) continue
122
+ const d = path.join(dir, n)
123
+ const { m, problems } = readManifest(d)
124
+ if (!m || problems.length || m.id !== n) continue
125
+ out.push({ ...m, dir: d })
126
+ }
127
+ return out.sort((a, b) => a.name.localeCompare(b.name, 'zh'))
128
+ }
129
+
130
+ /** 资源文件(assets/ 下面的图、字体、样式):[相对路径],太大、太多就报 */
131
+ function assetsOf(src) {
132
+ const base = path.join(src, 'assets')
133
+ const out = []
134
+ const odd = []
135
+ let total = 0
136
+ const walk = (d, depth) => {
137
+ let ents = []
138
+ try { ents = fs.readdirSync(d, { withFileTypes: true }) } catch { return }
139
+ for (const e of ents) {
140
+ if (e.name.startsWith('.')) continue
141
+ const p = path.join(d, e.name)
142
+ if (e.isDirectory() && depth < 3) walk(p, depth + 1)
143
+ else if (e.isFile() && ASSET_EXT.test(e.name)) {
144
+ total += fs.statSync(p).size
145
+ out.push(path.relative(src, p))
146
+ } else odd.push(path.relative(src, p))
147
+ }
148
+ }
149
+ walk(base, 0)
150
+ return { files: out, total, odd }
151
+ }
152
+
153
+ /**
154
+ * 存库只复制 frame.json 的 css、位置 HTML、assets/:这几样里引用的本地文件(@import、url()、<link href>、src、<use href>)
155
+ * 不在里面、但源文件夹里(或外面)确实有的列出来(「frame.css 引用的 tokens.css」),存进库会缺
156
+ */
157
+ export function missingRefs(src, m, assetFiles = []) {
158
+ const keep = new Set([...m.css, ...m.frames.map((f) => f.file), ...assetFiles].map((x) => x.split(path.sep).join('/')))
159
+ const out = []
160
+ const look = (file, refs) => {
161
+ for (const r0 of refs) {
162
+ const r = String(r0 || '').trim().replace(/^["']|["']$/g, '')
163
+ if (!r || /^(?:[a-z][a-z0-9+.-]*:|\/\/|#)/i.test(r)) continue // data: http: blob: … / 本页 #id
164
+ let rel = r.split(/[?#]/)[0]
165
+ try { rel = decodeURIComponent(rel) } catch { /* 原样 */ }
166
+ if (!rel) continue
167
+ // / 开头的按预览的根(源文件夹)算:存外框时预览开的就是源文件夹
168
+ const abs = rel.startsWith('/') ? path.resolve(src, `.${rel}`) : path.resolve(src, path.dirname(file), rel)
169
+ if (!fs.existsSync(abs)) { out.push(`${file} 引用的 ${r}(找不到这个文件)`); continue } // 漏写了图、路径写错:存进库打开也是缺的
170
+ const inSrc = path.relative(src, abs)
171
+ const key = inSrc.split(path.sep).join('/')
172
+ if (inSrc.startsWith('..') || path.isAbsolute(inSrc) || !keep.has(key)) out.push(`${file} 引用的 ${r}`)
173
+ }
174
+ }
175
+ const cssRefs = (text0) => { const text = text0.replace(/\/\*[\s\S]*?\*\//g, ''); return [ // 注释里写的不算
176
+ ...[...text.matchAll(/@import\s+(?:url\(\s*)?(?:"([^"]+)"|'([^']+)'|([^"')\s;]+))/gi)].map((x) => x[1] ?? x[2] ?? x[3]),
177
+ ...[...text.matchAll(/url\(\s*(?:"([^"]*)"|'([^']*)'|([^"')\s]+))\s*\)/gi)].map((x) => x[1] ?? x[2] ?? x[3]),
178
+ // image-set("logo.svg" 1x, …):不带 url() 的字符串也是图
179
+ // (type("image/avif") 里是类型、不是文件,先去掉)
180
+ ...[...text.matchAll(/image-set\(((?:[^()]|\([^()]*\))*)\)/gi)].flatMap((x) => [...x[1].replace(/\b(?:type|url)\(\s*(?:"[^"]*"|'[^']*'|[^)]*)\)/gi, '').matchAll(/"([^"]+)"|'([^']+)'/g)].map((m) => m[1] ?? m[2])),
181
+ ] }
182
+ const read = (f) => { try { return fs.readFileSync(path.join(src, f), 'utf8') } catch { return '' } }
183
+ for (const f of [...m.css, ...assetFiles.filter((x) => /\.css$/i.test(x))]) look(f.split(path.sep).join('/'), cssRefs(read(f)))
184
+ // 位置 HTML、assets/ 里的 SVG(雪碧图里 <image href="../leaf.svg">)一样查
185
+ for (const file of [...m.frames.map((fr) => fr.file), ...assetFiles.filter((x) => /\.svg$/i.test(x))]) {
186
+ const html = read(file).replace(/<!--[\s\S]*?-->/g, '')
187
+ const refs = []
188
+ // 属性值三种写法:双引号、单引号、不带引号(里面可以是另一种引号:style="background:url('logo.svg')")
189
+ // 属性值里的实体解回来:&quot; &apos; &lt; &gt; &amp;、数字的(&#38; &#x26;)
190
+ const NAMED = { quot: '"', apos: "'", lt: '<', gt: '>', amp: '&', nbsp: '\u00a0' }
191
+ const unEnt = (v) => v.replace(/&(?:#(\d+)|#x([0-9a-f]+)|([a-z]+));/gi, (m, d, x, n) => {
192
+ if (d || x) { try { return String.fromCodePoint(d ? Number(d) : parseInt(x, 16)) } catch { return m } }
193
+ return Object.prototype.hasOwnProperty.call(NAMED, n.toLowerCase()) ? NAMED[n.toLowerCase()] : m
194
+ })
195
+ const attrs = (tag, names) => [...tag.matchAll(new RegExp(`\\s(?:${names})\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s"'>]+))`, 'gi'))].map((a) => unEnt(a[1] ?? a[2] ?? a[3] ?? ''))
196
+ for (const t of html.matchAll(/<([a-z][a-z0-9-]*)\b(?:"[^"]*"|'[^']*'|[^>"'])*>/gi)) {
197
+ const tag = t[0]
198
+ const name = t[1].toLowerCase()
199
+ if (/^(link|use|image|feimage)$/.test(name)) refs.push(...attrs(tag, 'href|xlink:href'))
200
+ if (/^(script|img|source|video|audio|iframe|input|embed)$/.test(name)) refs.push(...attrs(tag, 'src'))
201
+ for (const v of attrs(tag, 'srcset')) refs.push(...srcsetParts(v).map(([u]) => u))
202
+ for (const v of attrs(tag, 'style')) refs.push(...cssRefs(v))
203
+ }
204
+ for (const st of html.matchAll(/<style\b[^>]*>([\s\S]*?)<\/style\s*>/gi)) refs.push(...cssRefs(st[1]))
205
+ look(file.split(path.sep).join('/'), refs)
206
+ }
207
+ return [...new Set(out)]
208
+ }
209
+
210
+ /**
211
+ * 外框的样式文件、assets/ 每个文件的指纹 { 'assets/icons.svg': 'ab12cd34' }(体检时页面按同样的算法再算一遍:
212
+ * 雪碧图里的图标形状、图、字体被改了也认得出)。按字节算 FNV,去掉 \r(Windows 上换行可能被改成 \r\n);
213
+ * 最多 30 个、每个 1 MB 以内、合起来 4 MB 以内(大的不记)
214
+ */
215
+ const strCodes = (t) => { const a = new Uint8Array(t.length); for (let i = 0; i < t.length; i++) a[i] = t.charCodeAt(i) & 0xff; return a }
216
+ export function assetHashes(src, files) {
217
+ const out = {}
218
+ let total = 0
219
+ for (const f0 of files) {
220
+ if (Object.keys(out).length >= 30) break
221
+ const f = f0.split(path.sep).join('/')
222
+ let buf
223
+ try { buf = fs.readFileSync(path.join(src, f0)) } catch { continue }
224
+ if (buf.length > 1024 * 1024 || total + buf.length > 4 * 1024 * 1024) continue
225
+ total += buf.length
226
+ // 开头带 BOM 的(记事本存的 UTF-8、UTF-16):浏览器(picker.js fileHash)读到的是按 BOM 解码后的字,这边也先解码,再按同样的办法(每个字取低 8 位)算
227
+ let codes = buf
228
+ if (buf[0] === 0xef && buf[1] === 0xbb && buf[2] === 0xbf) codes = strCodes(buf.subarray(3).toString('utf8'))
229
+ else if (buf[0] === 0xff && buf[1] === 0xfe) codes = strCodes(buf.subarray(2).toString('utf16le'))
230
+ else if (buf[0] === 0xfe && buf[1] === 0xff) codes = strCodes(Buffer.from(buf.subarray(2)).swap16().toString('utf16le'))
231
+ let h = 0x811c9dc5
232
+ for (const b of codes) { if (b === 13) continue; h ^= b; h = Math.imul(h, 0x01000193) }
233
+ out[f] = (h >>> 0).toString(16).padStart(8, '0')
234
+ }
235
+ return out
236
+ }
237
+
238
+ /** 开一个位置量一遍(浅色、深色):问题、截图、要写进页面的那段放进 out */
239
+ async function measureFrame(browser, { url, w, h, m, f, want }, out) {
240
+ const { bad, images } = out
241
+ await browser.withPage({ url, w, h }, async (page) => {
242
+ await prepare(page, false)
243
+ // 量哪些:浅色、深色下看得见的外框元素合起来(只在深色显示的按钮、图标也查)
244
+ let paths = await page.eval('window.__dshDesign.framePaths()')
245
+ let hasDark = false
246
+ // 深色量两种(外框没写深色也切,force):真的深色媒体 + 切深色(系统深色、check_design dark),
247
+ // 浅色媒体 + 画布切深色(系统浅色时在画布上切);只写了 @media 的外框两种可能不一样。体检时深色哪种对上都行
248
+ const any = Array.isArray(paths) && paths.length > 0
249
+ const media = async (dk) => { if (page.media) await page.media(dk) }
250
+ const DARKS = page.media ? [true, false] : [false]
251
+ if (any) {
252
+ const seen = new Set(paths.map((x) => JSON.stringify(x)))
253
+ for (const dm of DARKS) {
254
+ await media(dm)
255
+ if (await page.eval('window.__dshDesign.dark(true, true)')) hasDark = true
256
+ await page.eval('window.__dshDesign.settle()')
257
+ for (const x of (await page.eval('window.__dshDesign.framePaths()')) || []) if (!seen.has(JSON.stringify(x))) { seen.add(JSON.stringify(x)); paths.push(x) }
258
+ await page.eval('window.__dshDesign.dark(false)')
259
+ }
260
+ paths = paths.slice(0, 200)
261
+ await media(false)
262
+ await page.eval('window.__dshDesign.settle()')
263
+ }
264
+ const light = await page.eval(`window.__dshDesign.frameInfo(${Array.isArray(paths) && paths.length ? JSON.stringify(paths) : ''})`)
265
+ if (!light || !light.found) { bad.push(`${f.file}:没找到外框的根元素。最外层包住整个外框的元素写 data-frame="${want}",槽位写 data-slot`); return }
266
+ if (!light.id) { bad.push(`${f.file}:带 data-frame 的元素里没有 data-slot 槽位`); return }
267
+ if (light.id !== want) bad.push(`${f.file}:根元素写的是 data-frame="${light.id}",要写 data-frame="${want}"`)
268
+ // 写在 <html> / <body> 上:切深色会往 <html> 加属性、远程看会往 <body> 末尾塞图标,都算进外框指纹;
269
+ // 写在 <dialog> / <details> 上:用户一开合整个外框就变了 → 都会误报
270
+ if (['html', 'body', 'dialog', 'details'].includes(light.tag)) bad.push(`${f.file}:data-frame 写在了 <${light.tag}> 上。外面包一层 <div data-frame="${want}">,外框都放进去(铺满画面)`)
271
+ const decl = Object.keys(f.slots)
272
+ const miss = decl.filter((s) => !light.slots.includes(s))
273
+ const extra = [...new Set(light.slots.filter((s) => !decl.includes(s)))]
274
+ const dup = [...new Set(light.slots.filter((s, i) => light.slots.indexOf(s) !== i))]
275
+ if (miss.length) bad.push(`${f.file}:frame.json 里的槽位页面上没有:${miss.join('、')}`)
276
+ if (extra.length) bad.push(`${f.file}:页面上的槽位 frame.json 没写:${extra.join('、')}(写进 slots 并说明放什么)`)
277
+ if (dup.length) bad.push(`${f.file}:槽位重名:${dup.join('、')}`)
278
+ if (light.nested && light.nested.length) bad.push(`${f.file}:槽位套在槽位里面(${light.nested.join('、')}):槽位要并排,不能嵌套`)
279
+ if (light.rect.w < w * 0.9 || light.rect.h < h * 0.9) bad.push(`${f.file}:外框根元素只有 ${light.rect.w}×${light.rect.h},要铺满整个画面 ${w}×${h}`)
280
+ images.push({ key: `${m.id}-${f.id}`, label: `${m.name} · ${f.name}(浅色)`, jpg: await page.shot() })
281
+ const darks = [] // 每种深色量出来的 e(量不成的是 null)
282
+ let atDark = true
283
+ if (any) {
284
+ for (const dm of DARKS) {
285
+ await media(dm)
286
+ await page.eval('window.__dshDesign.dark(true, true)')
287
+ await page.eval('window.__dshDesign.settle()')
288
+ const dk = await page.eval(`window.__dshDesign.frameInfo(${JSON.stringify(light.probes.e.map((x) => x[0]))})`)
289
+ const okd = dk && dk.sig === light.sig && dk.probes
290
+ darks.push(okd ? dk.probes.e : null)
291
+ if (okd && JSON.stringify(dk.at) !== JSON.stringify(light.at)) atDark = false // 深色样式让外框挪了位置(居中的根变宽变窄):位置不记
292
+ if (okd && hasDark && !images.some((x) => x.key === `${m.id}-${f.id}-dark`)) images.push({ key: `${m.id}-${f.id}-dark`, label: `${m.name} · ${f.name}(深色)`, jpg: await page.shot() })
293
+ await page.eval('window.__dshDesign.dark(false)')
294
+ }
295
+ await media(false)
296
+ }
297
+ const e = light.probes.e.map(([p, v], i) => {
298
+ const ds = darks.map((dk) => (dk && dk[i] && JSON.stringify(dk[i][0]) === JSON.stringify(p) ? dk[i][1] : null)).filter(Boolean)
299
+ if (!ds.length) return [p, v]
300
+ // 哪一套量出来跟着内容变(null)就几套都不查
301
+ const nul = v.map((x, k) => x === null || ds.some((d) => d[k] === null))
302
+ const fix = (arr) => arr.map((x, k) => (nul[k] ? null : x))
303
+ const lv = fix(v)
304
+ const [dv, dv2] = ds.map(fix)
305
+ const same = (x, y) => JSON.stringify(x) === JSON.stringify(y)
306
+ if (dv2 && !same(dv2, dv)) return [p, lv, dv, dv2] // 两种深色不一样:都记
307
+ return same(dv, lv) ? [p, lv] : [p, lv, dv]
308
+ })
309
+ // 值去重放进表:元素那里只记第几个(-1 = 不查),页面里那段小一些
310
+ const table = []
311
+ const at = new Map()
312
+ const idx = (arr) => arr.map((x) => {
313
+ if (x === null) return -1
314
+ if (!at.has(x)) { at.set(x, table.length); table.push(x) }
315
+ return at.get(x)
316
+ })
317
+ // 写成整串(末尾「没画伪元素」的那一大段截掉,体检时超出长度的当「没画」;-1 不查不能截),
318
+ // 或者只写和 base 不一样的 {第几个: 值}(浅色比上一个元素、深色比自己的浅色)——哪个短用哪个
319
+ const pick = (ix, arr, base) => {
320
+ const full = ix.slice()
321
+ while (full.length && arr[full.length - 1] === '-') full.pop()
322
+ if (!base) return full
323
+ const d = {}
324
+ ix.forEach((v, k) => { if (v !== base[k]) d[k] = v })
325
+ return JSON.stringify(d).length < JSON.stringify(full).length ? d : full
326
+ }
327
+ let prev = null
328
+ const rows = e.map(([p, lv, ...ds]) => {
329
+ const lix = idx(lv)
330
+ const row = [p, pick(lix, lv, prev), ...ds.map((d) => pick(idx(d), d, lix))]
331
+ prev = lix
332
+ return row
333
+ })
334
+ out.data = { id: want, sv: light.sv || 1, sig: light.sig, ...(hasDark ? {} : { fd: 1 }), ...(Array.isArray(light.at) && atDark ? { at: light.at } : {}), ...(light.refs && Object.keys(light.refs).length ? { rs: light.refs } : {}), ...(Array.isArray(light.od) ? { od: light.od } : {}), ...(Array.isArray(light.dl) ? { dl: light.dl } : {}), probes: { p: light.probes.p, v: table, e: rows } }
335
+ })
336
+ }
337
+
338
+ /**
339
+ * 存一个外框进库。
340
+ * @returns { ok, id, dir, text, images: [{ key, label, jpg }] };没存成 ok 是 false,text 里写为什么
341
+ */
342
+ export async function saveFrame({ browser, src, dir = FRAMES_DIR, hubFactory = createHub }) {
343
+ const { m, problems } = readManifest(src)
344
+ if (!m || problems.length) return { ok: false, text: `外框没存:frame.json 有问题\n${problems.map((x) => `- ${x}`).join('\n')}`, images: [] }
345
+ const assets = assetsOf(src)
346
+ if (assets.total > MAX_ASSETS) return { ok: false, text: `外框没存:assets/ 太大(${Math.round(assets.total / 1024)} KB,最多 ${MAX_ASSETS / 1024 / 1024} MB)`, images: [] }
347
+ if (assets.odd.length) return { ok: false, text: `外框没存:assets/ 里有收不了的:${assets.odd.slice(0, 5).join('、')}(只收图、字体、样式,最多套 3 层文件夹)`, images: [] }
348
+ if (assets.files.length > MAX_ASSET_FILES) return { ok: false, text: `外框没存:assets/ 里文件太多(${assets.files.length} 个,最多 ${MAX_ASSET_FILES} 个):图标合成一个 svg 雪碧图,或者删掉用不到的`, images: [] }
349
+ // 外框是固定的样子:不收脚本(<script>、onclick 这种、javascript: 地址)——脚本一改外框的属性、class,体检就报外框被改
350
+ const scripted = m.frames.filter((fr) => { let t = ''; try { t = fs.readFileSync(path.join(src, fr.file), 'utf8').replace(/<!--[\s\S]*?-->/g, '') } catch { return false } return /<script\b/i.test(t) || /<[a-z][^>]*\son[a-z]+\s*=/i.test(t) || /=\s*["']?\s*javascript:/i.test(t) }).map((fr) => fr.file)
351
+ if (scripted.length) return { ok: false, text: `外框没存:${scripted.join('、')} 里有脚本(<script>、onclick 这种、javascript: 地址)。外框只放固定的样子,去掉脚本再存;要点了有反应的写在设计的槽位里。`, images: [] }
352
+ const lost = missingRefs(src, m, assets.files)
353
+ if (lost.length) return { ok: false, text: `外框没存:这些文件引用了找不到、或不会复制进库的文件(存进库后会缺):\n${lost.slice(0, 12).map((x) => `- ${x}`).join('\n')}${lost.length > 12 ? `\n- …还有 ${lost.length - 12} 处` : ''}\n样式文件写进 frame.json 的 css,图、字体、别的样式放进 assets/,再存一次。`, images: [] }
354
+ if (!browser || !browser.available()) return { ok: false, text: '外框没存:这台电脑上没找到能用的 Chrome / Edge,算不了外框的指纹。', images: [] }
355
+ const [w, h] = m.size
356
+ const hub = hubFactory({ parents: () => [] })
357
+ const datas = new Map()
358
+ const images = []
359
+ const bad = []
360
+ try {
361
+ const entry = await hub.open({ kind: 'file', root: src })
362
+ for (const f of m.frames) {
363
+ const want = `${m.id}/${f.id}`
364
+ const url = `${entry.origin}/${encodeURIComponent(f.file)}`
365
+ // 刚写完的文件:预览服务器可能晚一点发「文件变了」,页面量到一半自己刷新 → 再开一次
366
+ let last = null
367
+ for (let attempt = 0; attempt < 3; attempt++) {
368
+ const mine = { bad: [], images: [], data: null }
369
+ try {
370
+ await measureFrame(browser, { url, w, h, m, f, want }, mine)
371
+ bad.push(...mine.bad)
372
+ images.push(...mine.images)
373
+ if (mine.data) datas.set(f.id, mine.data)
374
+ last = null
375
+ break
376
+ } catch (e) {
377
+ last = e
378
+ }
379
+ }
380
+ if (last) bad.push(`${f.file}:打不开(${String((last && last.message) || last).slice(0, 160)})`)
381
+ }
382
+ } finally {
383
+ hub.closeAll()
384
+ }
385
+ if (bad.length) return { ok: false, text: `外框没存:\n${bad.map((x) => `- ${x}`).join('\n')}`, images }
386
+
387
+ // 写进库:先写到旁边的临时目录,写完换上去(同名的旧外框整个换掉;已经用旧外框做的设计页面里带着旧指纹,照样能查)
388
+ const out = path.join(dir, m.id)
389
+ const tmp = path.join(dir, `.${m.id}.${process.pid}.${Date.now()}`)
390
+ fs.mkdirSync(tmp, { recursive: true })
391
+ try {
392
+ const ah = assetHashes(src, [...m.css, ...assets.files])
393
+ for (const f of m.frames) {
394
+ let html = fs.readFileSync(path.join(src, f.file), 'utf8')
395
+ html = injectFrameData(ensureMeta(html, w, h), { ...datas.get(f.id), ...(Object.keys(ah).length ? { ah } : {}) })
396
+ fs.writeFileSync(path.join(tmp, f.file), html)
397
+ }
398
+ for (const c of m.css) fs.copyFileSync(path.join(src, c), path.join(tmp, c))
399
+ for (const a of assets.files) {
400
+ fs.mkdirSync(path.dirname(path.join(tmp, a)), { recursive: true })
401
+ fs.copyFileSync(path.join(src, a), path.join(tmp, a))
402
+ }
403
+ fs.writeFileSync(path.join(tmp, 'frame.json'), JSON.stringify({ ...m, savedAt: new Date().toISOString() }, null, 2) + '\n')
404
+ // 旧的先改名留着,新的换上去成功了再删旧的;换不上(Windows 上目录被占用)就把旧的改回来,库里不会两头都没了
405
+ const old = fs.existsSync(out) ? path.join(dir, `.${m.id}.old.${process.pid}.${Date.now()}`) : ''
406
+ if (old) fs.renameSync(out, old)
407
+ try {
408
+ fs.renameSync(tmp, out)
409
+ } catch (e) {
410
+ if (old) { try { fs.renameSync(old, out) } catch { /* 留着 .old 目录,至少没删 */ } }
411
+ throw e
412
+ }
413
+ if (old) { try { fs.rmSync(old, { recursive: true, force: true }) } catch { /* 删不掉的旧目录名字带点、列外框时不认 */ } }
414
+ } catch (e) {
415
+ fs.rmSync(tmp, { recursive: true, force: true })
416
+ return { ok: false, text: `外框没存:写进外框库出错(${String((e && e.message) || e).slice(0, 160)})`, images }
417
+ }
418
+ const lines = m.frames.map((f) => `- ${f.name}:${f.file}(槽位 ${Object.keys(f.slots).join('、')})`)
419
+ const text = [
420
+ `外框「${m.name}」(${m.id},${w}×${h})存进外框库了:${out}`,
421
+ ...lines,
422
+ `附上每个位置的截图(${images.some((x) => x.key.endsWith('-dark')) ? '浅色、深色' : '只有浅色:外框没写深色样式'}),对照用户给的截图 / 说明看一遍,不像就改源文件再存一次。`,
423
+ `用它做设计:把 ${out} 里的 ${[...m.css, ...(assets.files.length ? ['assets/'] : [])].join('、') || '样式文件'} 和要用的位置 HTML 用复制命令原样复制进设计目录(别重新手写),只改 data-slot 里面;样式都从 [data-slot="main"] 开头。`,
424
+ ].join('\n')
425
+ return { ok: true, id: m.id, dir: out, text, images }
426
+ }
427
+
428
+ /** 技能里加一段:库里有哪些外框(每次加载技能现读) */
429
+ export function frameSection(dir = FRAMES_DIR) {
430
+ const list = listFrames(dir)
431
+ const head = '\n\n## 外框库(用户自己的外框)\n\n'
432
+ const how = '用户要给某个软件 / 浏览器插件 / 平台做界面、说「套上 XX 的外框」「照这张截图做个外框」:读 `references/frames.md`,照截图或说明写外框,调 `save_frame` 存进库,再用它出设计。'
433
+ if (!list.length) return head + how + '\n'
434
+ const line = (x) => `- 「${x.name}」(${x.id},${x.size[0]}×${x.size[1]}):${x.dir};位置:${x.frames.map((f) => `${f.name}(${f.file},槽位 ${Object.keys(f.slots).join('、')})`).join(';')}`
435
+ return `${head}${list.slice(0, 12).map(line).join('\n')}\n\n用户点名用某个外框(首页选了「套外框」再选外框,消息里会写「外框:名字(id)」):照 \`references/frames.md\` 的「用外框」做,类型标记写 framed。\n\n${how}\n`
436
+ }
package/lib/index.js CHANGED
@@ -65,6 +65,7 @@ import { createBrowser } from './browser.js'
65
65
  import { createCanvasThumbs, createDirRevs } from './canvthumb.js'
66
66
  import { designOf, fitSize, metaOfFile, sizeOf, pickScreens, measureAll, shootAll, cropIssues, formatMeasure, issueSnapshot, formatShots, whereOf, MAX_SCREENS, MAX_SIZES, MAX_SHOTS, MAX_CROPS } from './look.js'
67
67
  import { SYSTEMS_DIR, extractSystem, listSystems, setDefault, skillSection } from './system.js'
68
+ import { saveFrame, listFrames, frameSection } from './frames.js'
68
69
  import { readTweaks, applyTweaks, lintTweaks } from './tweaks.js'
69
70
  import { readAnnotations, lintAnnotations, annotationFindings, annotationSection } from './annotations.js'
70
71
  import { FRAMEWORKS, detectProject, projectFor, defaultFramework, buildHandoff, compareScreens, implUrl, defaultDest, pickedDest, within, pinRoots } from './handoff.js'
@@ -120,6 +121,7 @@ export const skillProvider = {
120
121
  // 用户的设计系统(默认用哪套、库里有哪些)每次现读,提了新的下次加载技能就知道
121
122
  let extra = ''
122
123
  try { extra = skillSection() } catch (e) { studio.log(e) }
124
+ try { extra += frameSection() } catch (e) { studio.log(e) }
123
125
  if (studio.annotations > 0) extra += annotationSection()
124
126
  return { name, description, whenToUse, invocation, provider, source, resourceBase, content: (await fs.promises.readFile(designSkill.locator, 'utf8')) + extra }
125
127
  },
@@ -143,7 +145,7 @@ export const previewTool = {
143
145
  kind: {
144
146
  type: 'string',
145
147
  enum: KINDS,
146
- description: '设计类型:web 网页(默认)、app 手机 App 界面(390×844)、miniprogram 微信小程序(375×812,外框带右上角胶囊)、tablet 平板、desktop 桌面软件(1280×800 的 Mac 窗口;Windows 软件在页面 meta 写 desktop windows)、poster 海报 / 社媒图(1080×1350)、slides 幻灯片(16:9)、email 邮件、diagram 图表(思维导图、技术路线图、产品路线图、架构图,默认 1600×1000,图多大画幅跟着多大)、dshplugin DSH 插件(1280×800,套 DSH 桌面端外框,只设计插件那块:左侧栏入口 / 设置分区 / 会话标签页 / 右侧栏面板)',
148
+ description: '设计类型:web 网页(默认)、app 手机 App 界面(390×844)、miniprogram 微信小程序(375×812,外框带右上角胶囊)、tablet 平板、desktop 桌面软件(1280×800 的 Mac 窗口;Windows 软件在页面 meta 写 desktop windows)、poster 海报 / 社媒图(1080×1350)、slides 幻灯片(16:9)、email 邮件、diagram 图表(思维导图、技术路线图、产品路线图、架构图,默认 1600×1000,图多大画幅跟着多大)、dshplugin DSH 插件(1280×800,套 DSH 桌面端外框,只设计插件那块:左侧栏入口 / 设置分区 / 会话标签页 / 右侧栏面板)、framed 套外框(外框库里用户自己的外框,画幅跟外框走,只设计槽位里那块)',
147
149
  },
148
150
  size: { type: 'string', description: '画幅尺寸,可选,如 1080x1920;不填按类型的默认尺寸' },
149
151
  screens: {
@@ -471,6 +473,48 @@ export const systemTool = {
471
473
  },
472
474
  }
473
475
 
476
+ /** save_frame 工具:把写好的外框存进外框库(检查、算指纹、截图) */
477
+ export const frameTool = {
478
+ name: 'save_frame',
479
+ description:
480
+ '把写好的「外框」存进用户的外框库(~/.dsh/design-frames/<id>/),以后做设计原样套上、只改槽位。' +
481
+ '用户要给某个软件 / 浏览器插件 / 平台做界面、说「照这张截图做个外框」「套上 XX 的外框」时:先读 ui-design 技能的 references/frames.md,在一个文件夹里写好 frame.json、每个位置一个 HTML(根元素 data-frame="<id>/<位置>",槽位 data-slot,必须有 main)和样式,再调它。' +
482
+ '它检查 frame.json 和槽位对不对,用无头浏览器打开每个位置(浅色、深色)算外框指纹(体检「外框被改动」靠它),截图回给你核对;同 id 再存一次就覆盖。',
483
+ parameters: specToJsonSchema({
484
+ dir: { type: 'string', required: true, description: '写好外框的文件夹(里面有 frame.json),绝对路径或相对会话目录' },
485
+ }),
486
+ output: {
487
+ schema: {
488
+ type: 'object',
489
+ additionalProperties: false,
490
+ properties: { text: { type: 'string' }, images: { type: 'array', items: { type: 'object' } } },
491
+ required: ['text'],
492
+ },
493
+ render: (_args, value) => withImages(value),
494
+ },
495
+ async execute(args, exec, ctx) {
496
+ const session = exec && exec.agent && exec.agent.session
497
+ const id = (session && session.id) || ''
498
+ const a = args || {}
499
+ if (typeof a.dir !== 'string' || !a.dir.trim()) return { text: '没给 dir:写好外框的文件夹(里面有 frame.json)。' }
500
+ const cwd = studio.tracker && id ? studio.tracker.cwdOf(id) : os.homedir()
501
+ const src = resolvePath(a.dir, cwd)
502
+ let st = null
503
+ try { st = fs.statSync(src) } catch { /* 下面说 */ }
504
+ if (!st || !st.isDirectory()) return { text: `找不到文件夹:${src}` }
505
+ let r
506
+ try {
507
+ r = await saveFrame({ browser: studio.browser, src })
508
+ } catch (e) {
509
+ return { text: `外框没存:${String((e && e.message) || e).slice(0, 300)}` }
510
+ }
511
+ if (!r.images.length) return { text: r.text }
512
+ const kept = await keepImages(ctx, id || 'frame', r.images, true)
513
+ if (kept.images) return { text: r.text, images: kept.images }
514
+ return { text: r.text }
515
+ },
516
+ }
517
+
474
518
  /** 设计目录里的 tokens.css 是不是从库里哪套设计系统复制来的(文件头写着「设计系统「名字」」) */
475
519
  function systemOfDir(root) {
476
520
  try {
@@ -979,6 +1023,14 @@ export function apply(ctx) {
979
1023
  }
980
1024
  }
981
1025
 
1026
+ /** 外框库:GET 列出来(首页「套外框」下面挑外框用) */
1027
+ function framesRoute(req, res) {
1028
+ if (!admit(req, res)) return
1029
+ let list = []
1030
+ try { list = listFrames() } catch (e) { log(e) }
1031
+ json(res, 200, { frames: list.map((x) => ({ id: x.id, name: x.name, nameEn: x.nameEn, size: x.size, positions: x.frames.map((f) => f.name) })) })
1032
+ }
1033
+
982
1034
  /** 设计系统库:GET 列出来;POST { id, default: true / false } 设 / 取消默认 */
983
1035
  async function systemsRoute(req, res) {
984
1036
  if (!admit(req, res)) return
@@ -1539,7 +1591,7 @@ export function apply(ctx) {
1539
1591
  })
1540
1592
  const mk = createMarketRoutes({ admit, readBody, json, tracker, library, market, open, systemsDir: SYSTEMS_DIR, log, sessionCwd })
1541
1593
 
1542
- const routes = { works: lib.works, workthumb: lib.workthumb, scrthumb: canvasThumbs.route, pack: lib.pack, usezip: lib.usezip, ghauth: lib.ghauth, submit: lib.submit, inspire: lib.inspire, inspimg: lib.inspimg, ...mk, state, open: openRoute, view: viewRoute, close: closeRoute, history: historyRoute, restore: restoreRoute, edit: editRoute, style: styleRoute, bundle: bundleRoute, ref: refRoute, export: exportRoute, doc: docRoute, reveal: revealRoute, phone: phoneRoute, check: checkRoute, locate: locateRoute, tweak: tweakRoute, systems: systemsRoute, systhumb: systhumbRoute, project: projectRoute }
1594
+ const routes = { works: lib.works, workthumb: lib.workthumb, scrthumb: canvasThumbs.route, pack: lib.pack, usezip: lib.usezip, ghauth: lib.ghauth, submit: lib.submit, inspire: lib.inspire, inspimg: lib.inspimg, ...mk, state, open: openRoute, view: viewRoute, close: closeRoute, history: historyRoute, restore: restoreRoute, edit: editRoute, style: styleRoute, bundle: bundleRoute, ref: refRoute, export: exportRoute, doc: docRoute, reveal: revealRoute, phone: phoneRoute, check: checkRoute, locate: locateRoute, tweak: tweakRoute, systems: systemsRoute, frames: framesRoute, systhumb: systhumbRoute, project: projectRoute }
1543
1595
  for (const [key, handler] of Object.entries(routes)) {
1544
1596
  ctx.effect(() => ctx.webServer.register({
1545
1597
  kind: 'exact',
package/lib/kinds.js CHANGED
@@ -2,10 +2,10 @@
2
2
  // client.js 是单独打包进页面的,有自己的一份,靠 test-client 里的对照测试看住。
3
3
 
4
4
  /** 设计类型和默认画幅(宽, 高) */
5
- export const KIND_SIZE = { web: [1280, 800], app: [390, 844], miniprogram: [375, 812], tablet: [820, 1180], desktop: [1280, 800], poster: [1080, 1350], slides: [1280, 720], email: [640, 960], diagram: [1600, 1000], dshplugin: [1280, 800] }
5
+ export const KIND_SIZE = { web: [1280, 800], app: [390, 844], miniprogram: [375, 812], tablet: [820, 1180], desktop: [1280, 800], poster: [1080, 1350], slides: [1280, 720], email: [640, 960], diagram: [1600, 1000], dshplugin: [1280, 800], framed: [1280, 800] }
6
6
 
7
7
  /** 全部类型(顺序 = 界面里列出的顺序) */
8
8
  export const KINDS = Object.keys(KIND_SIZE)
9
9
 
10
10
  /** 页面 <meta name="dsh-design"> 里认的类型别名(比 core 的 parseKind 少,故意不合并) */
11
- export const META_ALIAS = { phone: 'app', mobile: 'app', ios: 'app', android: 'app', mini: 'miniprogram', miniapp: 'miniprogram', weapp: 'miniprogram', wechat: 'miniprogram', 小程序: 'miniprogram', pad: 'tablet', ipad: 'tablet', pc: 'desktop', electron: 'desktop', tauri: 'desktop', mac: 'desktop', macos: 'desktop', windows: 'desktop', win: 'desktop', 桌面: 'desktop', 桌面软件: 'desktop', social: 'poster', image: 'poster', slide: 'slides', deck: 'slides', ppt: 'slides', mail: 'email', mindmap: 'diagram', roadmap: 'diagram', architecture: 'diagram', flowchart: 'diagram', 思维导图: 'diagram', 导图: 'diagram', 路线图: 'diagram', 架构图: 'diagram', 图表: 'diagram', dsh: 'dshplugin', 'dsh-plugin': 'dshplugin', dsh插件: 'dshplugin' }
11
+ export const META_ALIAS = { phone: 'app', mobile: 'app', ios: 'app', android: 'app', mini: 'miniprogram', miniapp: 'miniprogram', weapp: 'miniprogram', wechat: 'miniprogram', 小程序: 'miniprogram', pad: 'tablet', ipad: 'tablet', pc: 'desktop', electron: 'desktop', tauri: 'desktop', mac: 'desktop', macos: 'desktop', windows: 'desktop', win: 'desktop', 桌面: 'desktop', 桌面软件: 'desktop', social: 'poster', image: 'poster', slide: 'slides', deck: 'slides', ppt: 'slides', mail: 'email', mindmap: 'diagram', roadmap: 'diagram', architecture: 'diagram', flowchart: 'diagram', 思维导图: 'diagram', 导图: 'diagram', 路线图: 'diagram', 架构图: 'diagram', 图表: 'diagram', dsh: 'dshplugin', 'dsh-plugin': 'dshplugin', dsh插件: 'dshplugin', frame: 'framed', 外框: 'framed', 自定外框: 'framed', 套外框: 'framed' }
package/lib/look.js CHANGED
@@ -465,9 +465,15 @@ export function detailOf(it) {
465
465
  : `伸进左上角红绿灯 ${it.px}px(外框画的、盖在页面上面,在 x 20–72、y 20–32:工具栏 / 侧栏顶上左边空出 80px,标题、按钮从 x 80 以后放)`
466
466
  case 'jserr': return `${it.msg}${it.src ? `(${it.src}${it.line ? `:${it.line}` : ''})` : ''}`
467
467
  case 'missing': return `${WHAT[it.what] || '文件'} ${it.src} 载不出来(路径写错了,或者文件不在)`
468
- case 'frame': return it.what === 'style'
469
- ? `外框的样式被改了:${it.sel} 的 ${it.prop} 应该是 ${it.want},现在是 ${it.got}。多半是插件样式写了 body / * / button 这种不带前缀的选择器,或者改了 dsh-shell.css:插件样式都从 [data-slot="main"] 开头,dsh-shell.css 从技能目录 frames/dsh/ 重新原样复制`
470
- : `外框(${it.frame})的结构或文字被改了:外框只能原样复制(技能目录 frames/dsh/),插件只写 data-slot 里面。重新复制外框,再把槽位里的内容放回去`
468
+ case 'frame': {
469
+ const dsh = /^dsh\//.test(String(it.frame || ''))
470
+ const from = dsh ? '技能目录 frames/dsh/' : '外框库(~/.dsh/design-frames/)'
471
+ if (it.what === 'asset') return `外框的文件 ${it.got} 被改了(和外框库里的不一样):外框的样式文件、assets/ 都只能原样复制(${from})。重新复制一份盖回去,插件自己的样式、图放别的文件`
472
+ if (it.what === 'nosig') return `外框(${it.frame})没登记,查不了有没有被改:先调 save_frame 把外框存进外框库,再从库里用复制命令原样复制进设计目录`
473
+ return it.what === 'style'
474
+ ? `外框的样式被改了:${it.sel} 的 ${it.prop} 应该是 ${it.want},现在是 ${it.got}。多半是插件样式写了 body / * / button 这种不带前缀的选择器,或者改了${dsh ? ' dsh-shell.css' : '外框的样式文件'}:插件样式都从 [data-slot="main"] 开头,${dsh ? 'dsh-shell.css' : '外框的样式文件'}从${from}重新原样复制`
475
+ : `外框(${it.frame})的结构或文字被改了:外框只能原样复制(${from}),插件只写 data-slot 里面。重新复制外框,再把槽位里的内容放回去`
476
+ }
471
477
  case 'dgsize': return `图有 ${it.w}×${it.h},画幅只有 ${it.vw}×${it.vh}:把 meta 改成 diagram ${it.w}x${it.h}(preview_page 的 size 也改),或者删减节点、改小间距`
472
478
  case 'dgli': return '字直接写在 li 里,或者 li 的第一个孩子不是 <span class="mm-node">:连线会对不上,改成 <li><span class="mm-node">…</span><ul>…</ul></li>'
473
479
  case 'dgmany': return it.what === 'box' ? `一行 ${it.n} 个框(最多 ${it.max} 个):拆成两行,或者合并几个` : `这一层 ${it.n} 个分支(最多 ${it.max} 个):合并几个、往下多分一层,或者拆成两张图`