dsh-design-studio 0.28.0 → 1.0.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/README.en.md +8 -7
- package/README.md +7 -6
- package/assets/demo.gif +0 -0
- package/assets/hero-sm.jpg +0 -0
- package/cordis.patch.yml +1 -1
- package/lib/canvthumb.js +55 -5
- package/lib/client.js +4683 -1462
- package/lib/core.js +425 -47
- package/lib/draft-page.js +2 -0
- package/lib/edits.js +69 -0
- package/lib/frames.js +52 -0
- package/lib/gallery/routes.js +22 -6
- package/lib/handoff.js +19 -4
- package/lib/history.js +6 -4
- package/lib/htmlpack.js +1 -1
- package/lib/index.js +199 -26
- package/lib/picker.js +114 -11
- package/lib/serve.js +5 -4
- package/package.json +1 -1
- package/skills/ui-design/SKILL.md +1 -1
package/lib/draft-page.js
CHANGED
|
@@ -706,6 +706,8 @@
|
|
|
706
706
|
if (visible(r)) { front = r; break }
|
|
707
707
|
}
|
|
708
708
|
if (!front) return
|
|
709
|
+
// 告诉右侧栏写到哪了(占这一屏高度的几成),外面那道扫光跟着往下走
|
|
710
|
+
try { parent.postMessage({ dshDraft: 'at', y: Math.max(0, Math.min(1, front.bottom / vh())) }, '*') } catch { /* 没有父页面 */ }
|
|
709
711
|
curs.forEach((c, k) => {
|
|
710
712
|
if (c.anim || now < c.busyTill + 500 || now < (c.restTill || 0)) return
|
|
711
713
|
if ((k === 2 && typing) || (k === 1 && painting)) return
|
package/lib/edits.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 用户在右侧栏亲手改了设计(调样式、改字、调节滑块、回到某一版)之后,模型下一步开始前插件补给它的一段说明。
|
|
3
|
+
*
|
|
4
|
+
* 为什么要:模型记得的是自己上次写的内容,不一定重读文件;用户手调的颜色、字,它接着改或做进项目时会用回旧样子(#28)。
|
|
5
|
+
* 走 DSH 的 agent/pre-step(和 DSH 自带的时间、操作卡片提醒一样),以「通知」的样子进对话:用户看得到一行,模型拿到全文。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
const CJK = /[㐀-鿿豈-]/
|
|
10
|
+
|
|
11
|
+
/** 用户这一轮说的话里有中文就用中文写说明,否则英文(DSH 没告诉插件界面语言) */
|
|
12
|
+
export function langOf(messages) {
|
|
13
|
+
for (const m of [...(messages || [])].reverse()) {
|
|
14
|
+
if (!m || !m.source || m.source.kind !== 'user') continue
|
|
15
|
+
const c = m.content
|
|
16
|
+
const text = typeof c === 'string' ? c : Array.isArray(c) ? c.filter((b) => b && b.type === 'text').map((b) => b.text).join('\n') : ''
|
|
17
|
+
if (text.trim()) return CJK.test(text) ? 'zh' : 'en'
|
|
18
|
+
}
|
|
19
|
+
return 'zh'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const cssText = (css) => Object.entries(css || {}).map(([k, v]) => `${k}: ${v || '(去掉)'}`).join('; ')
|
|
23
|
+
const cssTextEn = (css) => Object.entries(css || {}).map(([k, v]) => `${k}: ${v || '(removed)'}`).join('; ')
|
|
24
|
+
|
|
25
|
+
/** 一条手改记录说成一行 */
|
|
26
|
+
function line(e, zh) {
|
|
27
|
+
const files = (e.files || []).join(zh ? '、' : ', ') + (e.more ? (zh ? ` 等 ${e.files.length + e.more} 个文件` : ` and ${e.more} more`) : '')
|
|
28
|
+
if (e.kind === 'style') return zh
|
|
29
|
+
? `- ${files}:调样式「${e.name}」→ ${cssText(e.css)}(写在这个元素的行内 style 上)`
|
|
30
|
+
: `- ${files}: restyled "${e.name}" → ${cssTextEn(e.css)} (written as an inline style on that element)`
|
|
31
|
+
if (e.kind === 'rule') return zh
|
|
32
|
+
? `- ${files}:调样式「${e.name}」→ 写进 ${e.file} 的 ${e.sel} 规则:${cssText(e.css)}(用这条规则的各屏一起变)`
|
|
33
|
+
: `- ${files}: restyled "${e.name}" → written into the ${e.sel} rule in ${e.file}: ${cssTextEn(e.css)} (every screen using that rule changes)`
|
|
34
|
+
if (e.kind === 'text') return zh
|
|
35
|
+
? `- ${files}:改字「${e.before}」→「${e.after}」`
|
|
36
|
+
: `- ${files}: changed the text "${e.before}" to "${e.after}"`
|
|
37
|
+
if (e.kind === 'restore') return zh
|
|
38
|
+
? `- 整套设计回到了第 ${e.n} 版(${e.count} 个文件换回那一版的内容)`
|
|
39
|
+
: `- The whole design was restored to version ${e.n} (${e.count} files now hold that version's content)`
|
|
40
|
+
return zh ? `- ${files}:${e.label || '改了'}` : `- ${files}: ${e.label || 'edited'}`
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @param edits 核心记下的手改(见 core.js 的 noteEdit),旧的在前
|
|
45
|
+
* @returns {{ text, summary } | null}
|
|
46
|
+
*/
|
|
47
|
+
export function editsNotice(edits, lang = 'zh') {
|
|
48
|
+
const list = (edits || []).filter(Boolean)
|
|
49
|
+
if (!list.length) return null
|
|
50
|
+
const zh = lang !== 'en'
|
|
51
|
+
const roots = [...new Set(list.map((e) => e.root).filter(Boolean))]
|
|
52
|
+
const where = roots.length ? roots.map((r) => `\`${r}\``).join(zh ? '、' : ', ') : ''
|
|
53
|
+
const lines = list.map((e) => line(e, zh))
|
|
54
|
+
const text = zh
|
|
55
|
+
? [`〔设计工作台〕你上次写完之后,用户自己在右侧设计工作台里改了设计${where ? `(${where})` : ''},这些就是用户要的样子:`, ...lines,
|
|
56
|
+
'接着改这套设计、或者把它做进项目里之前:先重新读上面这些文件,以文件现在的内容为准,别照你之前写的内容来,也别把这些改回去(除非用户这次就是要你改)。行内 style 上的值是用户手调的:做成组件时把它并进组件的样式。'].join('\n')
|
|
57
|
+
: [`[Design Studio] Since you last wrote, the user edited the design by hand in the Design Studio sidebar${where ? ` (${where})` : ''}. This is how the user wants it:`, ...lines,
|
|
58
|
+
'Before you change this design again or build it into a project: re-read the files above and treat their current content as the truth. Do not go by what you wrote earlier, and do not undo these edits (unless the user asks for that now). Values in inline styles were tuned by the user: when you turn the element into a component, carry those values into the component\'s styles.'].join('\n')
|
|
59
|
+
const n = list.length
|
|
60
|
+
const summary = zh ? `用户在设计工作台里手改了 ${n} 处` : `The user hand-edited the design (${n} ${n === 1 ? 'edit' : 'edits'})`
|
|
61
|
+
return { text, summary }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** 给 DSH 的一条「通知」消息(和 @deepseek-ai/dsh-llm 的 createUserMessage 出来的一样:有 id、冻住) */
|
|
65
|
+
export function noticeMessage({ text, summary }, id) {
|
|
66
|
+
const deepFreeze = (o) => { Object.freeze(o); for (const v of Object.values(o)) if (v && typeof v === 'object' && !Object.isFrozen(v)) deepFreeze(v); return o }
|
|
67
|
+
return deepFreeze({ id, role: 'user', source: { kind: 'design-studio', form: 'notice', summary }, content: [{ type: 'text', text }] })
|
|
68
|
+
}
|
|
69
|
+
|
package/lib/frames.js
CHANGED
|
@@ -127,6 +127,58 @@ export function listFrames(dir = FRAMES_DIR) {
|
|
|
127
127
|
return out.sort((a, b) => a.name.localeCompare(b.name, 'zh'))
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
+
/** 库里这个外框的目录(id 不对、是自带的、没有 frame.json → '') */
|
|
131
|
+
export function frameDir(id, dir = FRAMES_DIR) {
|
|
132
|
+
const n = String(id || '')
|
|
133
|
+
if (!ID_RE.test(n) || RESERVED.has(n)) return ''
|
|
134
|
+
const d = path.join(dir, n)
|
|
135
|
+
return fs.existsSync(path.join(d, 'frame.json')) ? d : ''
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** 我的作品 › 外框 ⋯ 改名:只改 frame.json 里的 name(英文界面改 nameEn),先写临时文件再换上去 */
|
|
139
|
+
export function renameFrame(id, name, { en = false, dir = FRAMES_DIR } = {}) {
|
|
140
|
+
const d = frameDir(id, dir)
|
|
141
|
+
if (!d) return { ok: false, error: 'noFrame' }
|
|
142
|
+
const v = String(name || '').replace(/\s+/g, ' ').trim()
|
|
143
|
+
if (!v || v.length > (en ? 40 : 30)) return { ok: false, error: 'badName' }
|
|
144
|
+
const f = path.join(d, 'frame.json')
|
|
145
|
+
let raw
|
|
146
|
+
try { raw = JSON.parse(fs.readFileSync(f, 'utf8').replace(/^\uFEFF/, '')) } catch { return { ok: false, error: 'noFrame' } }
|
|
147
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return { ok: false, error: 'noFrame' }
|
|
148
|
+
raw[en ? 'nameEn' : 'name'] = v
|
|
149
|
+
const tmp = `${f}.${process.pid}.${Date.now()}.tmp`
|
|
150
|
+
try {
|
|
151
|
+
fs.writeFileSync(tmp, JSON.stringify(raw, null, 2) + '\n')
|
|
152
|
+
fs.renameSync(tmp, f)
|
|
153
|
+
} catch (e) {
|
|
154
|
+
try { fs.rmSync(tmp, { force: true }) } catch { /* 没写出来 */ }
|
|
155
|
+
return { ok: false, error: String((e && e.message) || e).slice(0, 160) }
|
|
156
|
+
}
|
|
157
|
+
return { ok: true }
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** 我的作品 › 外框 ⋯ 删除:挪进库里的 .trash/(名字带点,列外框时不认),30 天前挪进去的顺手清掉。
|
|
161
|
+
* 已经用它做的设计不受影响:外框的页面、样式当时就复制进设计目录了 */
|
|
162
|
+
export function removeFrame(id, dir = FRAMES_DIR) {
|
|
163
|
+
const d = frameDir(id, dir)
|
|
164
|
+
if (!d) return { ok: false, error: 'noFrame' }
|
|
165
|
+
const trash = path.join(dir, '.trash')
|
|
166
|
+
try {
|
|
167
|
+
fs.mkdirSync(trash, { recursive: true })
|
|
168
|
+
fs.renameSync(d, path.join(trash, `${path.basename(d)}-${Date.now()}`))
|
|
169
|
+
} catch (e) {
|
|
170
|
+
return { ok: false, error: String((e && e.message) || e).slice(0, 160) }
|
|
171
|
+
}
|
|
172
|
+
const old = Date.now() - 30 * 24 * 3600 * 1000
|
|
173
|
+
try {
|
|
174
|
+
for (const n of fs.readdirSync(trash)) {
|
|
175
|
+
const at = Number((n.match(/-(\d{13})$/) || [])[1])
|
|
176
|
+
if (at && at < old) fs.rmSync(path.join(trash, n), { recursive: true, force: true })
|
|
177
|
+
}
|
|
178
|
+
} catch { /* 清不掉下次再清 */ }
|
|
179
|
+
return { ok: true }
|
|
180
|
+
}
|
|
181
|
+
|
|
130
182
|
/** 资源文件(assets/ 下面的图、字体、样式):[相对路径],太大、太多就报 */
|
|
131
183
|
function assetsOf(src) {
|
|
132
184
|
const base = path.join(src, 'assets')
|
package/lib/gallery/routes.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* GET works 我的作品(顺手从设计台缓存补回以前的设计)
|
|
5
5
|
* POST works { op, dir, to? } pin / unpin / hide(移出列表)/ reveal(在文件夹里显示)/ relocate(挪走了,重新定位)
|
|
6
|
-
* GET workthumb ?id=
|
|
6
|
+
* GET workthumb ?id=&i= 作品缩略图(第 i 屏,默认第一屏,最多第三屏;无头浏览器截的,按文件修改时间缓存)
|
|
7
7
|
* POST pack { dir, license } 打成 zip:先规范化,再用和机器人同一份规则查;过了存到「下载」
|
|
8
8
|
* POST usezip { session, name, data } 拖进来的 zip →「用这个开始」:查、落到新文件夹、登记、打开
|
|
9
9
|
* GET inspire 灵感(参考图、网址、我的风格)
|
|
@@ -84,6 +84,9 @@ const hardMsg = (x, en) => {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
/** 一条作品记录 → 右侧栏卡片要的样子(目录不在了 exists: false) */
|
|
87
|
+
// 缩略图的截法改了就换一个:签名带上它,旧图自然作废(1.0:竖的截整屏)
|
|
88
|
+
const THUMB_V = '|t2'
|
|
89
|
+
|
|
87
90
|
export function describeWork(w) {
|
|
88
91
|
const dir = w.dir
|
|
89
92
|
let exists = false
|
|
@@ -103,7 +106,7 @@ export function describeWork(w) {
|
|
|
103
106
|
const first = screens[0] ? path.join(dir, screens[0]) : ''
|
|
104
107
|
const product = first ? splitTitle(headTitle(first)).product : ''
|
|
105
108
|
const kind = w.kind || (first ? parseMeta(metaOfFile(first)).kind : '') || 'web'
|
|
106
|
-
return { ...base, title: manifestTitle(dir) || product || w.title || path.basename(dir), kind, screens: screens.length, first: screens[0] || '', updated: Math.round(updated || w.updated || w.seen || 0), thumb: sig ? crypto.createHash('sha1').update(sig).digest('hex').slice(0, 10) : '' }
|
|
109
|
+
return { ...base, title: manifestTitle(dir) || product || w.title || path.basename(dir), kind, screens: screens.length, first: screens[0] || '', updated: Math.round(updated || w.updated || w.seen || 0), thumb: sig ? crypto.createHash('sha1').update(sig + THUMB_V).digest('hex').slice(0, 10) : '' }
|
|
107
110
|
}
|
|
108
111
|
|
|
109
112
|
export function createLibraryRoutes({ admit, readBody, json, tracker, library, inspiration, studio, open, storeLoad, version = '', exported, log = () => {}, thumbDir = THUMB_DIR, downloads = path.join(os.homedir(), 'Downloads'), sessionCwd = async (id) => tracker.cwdOf(id), render = renderPack, github = createGitHub({ log }), vocab = () => ({ categories: [], tags: [] }) }) {
|
|
@@ -174,7 +177,9 @@ export function createLibraryRoutes({ admit, readBody, json, tracker, library, i
|
|
|
174
177
|
const { origin } = await open({ kind: 'file', root: w.dir, file: path.join(w.dir, d.first) })
|
|
175
178
|
const [vw, vh] = KIND_SIZE[d.kind] || KIND_SIZE.web
|
|
176
179
|
const scale = Math.min(1, 480 / vw)
|
|
177
|
-
|
|
180
|
+
// 竖的(手机、小程序…)卡片上几部手机并排,截整屏;横的截上面一段
|
|
181
|
+
const tall = vh > vw * 1.15
|
|
182
|
+
const jpg = await browser.withPage({ url: `${origin}/${d.first.split('/').map(encodeURIComponent).join('/')}`, w: vw, h: tall ? vh : Math.min(vh, Math.round(vw * 1.25)), scale, offline: library.strictRoot(w.dir) }, async (page) => {
|
|
178
183
|
await prepare(page, false)
|
|
179
184
|
return page.shot({ quality: 70 })
|
|
180
185
|
})
|
|
@@ -194,14 +199,25 @@ export function createLibraryRoutes({ admit, readBody, json, tracker, library, i
|
|
|
194
199
|
const id = new URL(req.url, 'http://x').searchParams.get('id') || ''
|
|
195
200
|
const w = /^[0-9a-f]{16}$/.test(id) ? byId(id) : null
|
|
196
201
|
if (!w) return json(res, 404, { error: 'no such work' })
|
|
197
|
-
const
|
|
202
|
+
const i = Math.max(0, Math.min(2, Number(new URL(req.url, 'http://x').searchParams.get('i')) || 0))
|
|
203
|
+
let d = describeWork(w)
|
|
198
204
|
if (!d.exists || !d.first || !d.thumb) return json(res, 404, { error: 'no screens' })
|
|
199
|
-
|
|
205
|
+
// 首页卡片摆前三屏:第二、三屏各截一张,按那屏自己的修改时间缓存(文件名 <id>~<i>-<签名>,和第一屏的分开清)
|
|
206
|
+
let pre = d.id + '-'
|
|
207
|
+
if (i > 0) {
|
|
208
|
+
const f = listScreens(w.dir)[i]
|
|
209
|
+
if (!f) return json(res, 404, { error: 'no screens' })
|
|
210
|
+
let sig = ''
|
|
211
|
+
try { const st = fs.statSync(path.join(w.dir, f)); sig = `${f}:${Math.round(st.mtimeMs)}:${st.size}` } catch { return json(res, 404, { error: 'no screens' }) }
|
|
212
|
+
d = { ...d, first: f, thumb: crypto.createHash('sha1').update(sig + THUMB_V).digest('hex').slice(0, 10) }
|
|
213
|
+
pre = `${d.id}~${i}-`
|
|
214
|
+
}
|
|
215
|
+
const file = path.join(thumbDir, `${pre}${d.thumb}.jpg`)
|
|
200
216
|
if (!fs.existsSync(file)) {
|
|
201
217
|
try {
|
|
202
218
|
await makeThumb(w, d, file)
|
|
203
219
|
// 旧版本的缩略图清掉
|
|
204
|
-
for (const f of fs.readdirSync(thumbDir)) if (f.startsWith(
|
|
220
|
+
for (const f of fs.readdirSync(thumbDir)) if (f.startsWith(pre) && f !== path.basename(file)) fs.rmSync(path.join(thumbDir, f), { force: true })
|
|
205
221
|
} catch (e) {
|
|
206
222
|
log(e)
|
|
207
223
|
return json(res, 503, { error: 'thumb failed' })
|
package/lib/handoff.js
CHANGED
|
@@ -23,6 +23,8 @@ import { FRAMES_DIR } from './frames.js'
|
|
|
23
23
|
import { FRAME_MAIN, SLOT_BOX } from './slot.js'
|
|
24
24
|
|
|
25
25
|
export const HANDOFF_DIR = 'handoff'
|
|
26
|
+
/** 版本名里哪些是用户在右侧栏亲手改的(见 core.js:改字、调样式、调节滑块) */
|
|
27
|
+
const TUNED = /^(改字「|调样式「|调节:)/
|
|
26
28
|
const MAX_SCREENS = 12
|
|
27
29
|
const MAX_PARTS = 3 // 每屏最多截几段
|
|
28
30
|
|
|
@@ -383,7 +385,7 @@ export function unlinkIfLink(file) {
|
|
|
383
385
|
* 生成交接包。screens:[{ key, url, label }](预览服务器上的地址);root:设计目录。
|
|
384
386
|
* @returns { file, dir, md, shots, rows }
|
|
385
387
|
*/
|
|
386
|
-
export async function buildHandoff(browser, { root, screens, kind = 'web', size = [1280, 800], framework = 'react', dest = '', project = null, system = '', annotations = null, now = new Date() }) {
|
|
388
|
+
export async function buildHandoff(browser, { root, screens, kind = 'web', size = [1280, 800], framework = 'react', dest = '', project = null, system = '', annotations = null, tuned = [], now = new Date() }) {
|
|
387
389
|
const dir = path.join(root, HANDOFF_DIR)
|
|
388
390
|
const shotDir = path.join(dir, 'shots')
|
|
389
391
|
// handoff/、handoff/shots/ 得是设计目录里真的文件夹:是软链接就可能删到、写到别处去
|
|
@@ -397,7 +399,7 @@ export async function buildHandoff(browser, { root, screens, kind = 'web', size
|
|
|
397
399
|
const rows = browser && browser.available() ? await shootScreens(browser, list, size, kind, shotDir) : list.map((sc) => ({ key: sc.key, label: sc.label, title: '', links: [], shots: [], error: '没有 Chrome / Edge,没截图' }))
|
|
398
400
|
const htmlByKey = new Map()
|
|
399
401
|
for (const sc of list) { try { htmlByKey.set(sc.key, fs.readFileSync(path.join(root, sc.key), 'utf8')) } catch { /* 读不了 */ } }
|
|
400
|
-
const md = handoffMd({ root, rows, kind, size, framework, dest, project, system, annotations, htmlByKey, more: Math.max(0, screens.length - MAX_SCREENS), now })
|
|
402
|
+
const md = handoffMd({ root, rows, kind, size, framework, dest, project, system, annotations, tuned, htmlByKey, more: Math.max(0, screens.length - MAX_SCREENS), now })
|
|
401
403
|
const file = path.join(dir, 'HANDOFF.md')
|
|
402
404
|
unlinkIfLink(file)
|
|
403
405
|
fs.writeFileSync(file, md)
|
|
@@ -405,7 +407,7 @@ export async function buildHandoff(browser, { root, screens, kind = 'web', size
|
|
|
405
407
|
}
|
|
406
408
|
|
|
407
409
|
/** 交接说明 */
|
|
408
|
-
export function handoffMd({ root, rows, kind, size, framework, dest, project, system, annotations = null, htmlByKey, more = 0, now = new Date() }) {
|
|
410
|
+
export function handoffMd({ root, rows, kind, size, framework, dest, project, system, annotations = null, tuned = [], htmlByKey, more = 0, now = new Date() }) {
|
|
409
411
|
const fw = FRAMEWORKS[framework] || null
|
|
410
412
|
const same = framework === 'same' && project && project.framework
|
|
411
413
|
const fwLabel = same ? `${project.label}(跟项目一样)` : fw ? fw.label : framework
|
|
@@ -431,7 +433,7 @@ export function handoffMd({ root, rows, kind, size, framework, dest, project, sy
|
|
|
431
433
|
const keyOfLink = (p) => String(p || '').replace(/^\/+/, '').split(/[?#]/)[0]
|
|
432
434
|
const lines = []
|
|
433
435
|
lines.push(`# 交接:${name} → ${fwLabel}`, '')
|
|
434
|
-
lines.push(`> 给写代码的模型看:照这份把设计稿做成真页面。设计稿就是源码——每屏一个 HTML,样式在 tokens.css
|
|
436
|
+
lines.push(`> 给写代码的模型看:照这份把设计稿做成真页面。设计稿就是源码——每屏一个 HTML,样式在 tokens.css 等样式表里;元素上的行内 \`style="…"\` 多半是用户在工作台里手调的,值以它为准(做成组件时并进组件的样式)。先读源文件(现在的,别照你之前写过的内容),截图只用来对照,别凭截图猜数值。`, '')
|
|
435
437
|
lines.push('## 做什么', '')
|
|
436
438
|
lines.push(`- 设计目录:\`${root}\`(${rows.length} 屏${more ? `,另有 ${more} 屏没列进来` : ''},${kind} ${size[0]}×${size[1]})`)
|
|
437
439
|
// 目录里已经有别的东西、又不是 Node 项目(别的语言的仓库、后端……):别在原地或旁边跑脚手架
|
|
@@ -568,6 +570,19 @@ export function handoffMd({ root, rows, kind, size, framework, dest, project, sy
|
|
|
568
570
|
}
|
|
569
571
|
lines.push('')
|
|
570
572
|
|
|
573
|
+
// 用户在工作台里亲手改过的(#28):模型做组件时常照样式表里的那条规则来,手调写在行内的值就丢了
|
|
574
|
+
const hand = (tuned || []).filter((v) => v && TUNED.test(String(v.label || ''))).slice(0, 12)
|
|
575
|
+
if (hand.length) {
|
|
576
|
+
lines.push('## 用户手调过的(以这些为准)', '')
|
|
577
|
+
for (const v of hand) {
|
|
578
|
+
const d = new Date(v.at)
|
|
579
|
+
const p = (x) => String(x).padStart(2, '0')
|
|
580
|
+
const files = (v.changed || []).slice(0, 4).join('、') + ((v.changed || []).length > 4 ? ` 等 ${v.changed.length} 个文件` : '')
|
|
581
|
+
lines.push(`- ${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())} ${v.label}${files ? `(${files})` : ''}`)
|
|
582
|
+
}
|
|
583
|
+
lines.push('- 这些是用户在右侧栏亲手改的,文件里已经是改过的样子:照文件现在的内容做;写在行内 style 上的值要带进对应的组件,别按样式表里的旧值做。', '')
|
|
584
|
+
}
|
|
585
|
+
|
|
571
586
|
// 交互和状态
|
|
572
587
|
lines.push('## 交互和状态', '')
|
|
573
588
|
const inter = []
|
package/lib/history.js
CHANGED
|
@@ -118,9 +118,9 @@ export function createHistory({ base, now = Date.now, log = () => {} }) {
|
|
|
118
118
|
* 存一版:和最近一版一模一样就不存。
|
|
119
119
|
* @returns 新的一版 { n, at, label, files } / null(没变、不像设计目录、出错)
|
|
120
120
|
*/
|
|
121
|
-
function snapshot(root, label = '') {
|
|
121
|
+
function snapshot(root, label = '', by = '') {
|
|
122
122
|
try {
|
|
123
|
-
return take(root, label, false)
|
|
123
|
+
return take(root, label, false, by)
|
|
124
124
|
} catch (e) {
|
|
125
125
|
log(e)
|
|
126
126
|
return null
|
|
@@ -128,7 +128,7 @@ export function createHistory({ base, now = Date.now, log = () => {} }) {
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
/** snapshot 的本体:出错直接抛;strict 时目录太大(存不下)也抛 */
|
|
131
|
-
function take(root, label, strict) {
|
|
131
|
+
function take(root, label, strict, by = '') {
|
|
132
132
|
const found = collect(root)
|
|
133
133
|
if (!found && strict) throw new Error('目录太大(多半是整个项目),存不了现在的样子')
|
|
134
134
|
if (!found || !Object.keys(found).length) return null
|
|
@@ -151,7 +151,8 @@ export function createHistory({ base, now = Date.now, log = () => {} }) {
|
|
|
151
151
|
const list = load(root)
|
|
152
152
|
const last = list[list.length - 1]
|
|
153
153
|
if (last && !diffFiles(last.files, files).length) { sigs.set(root, sig); return null }
|
|
154
|
-
|
|
154
|
+
// by:谁改出来的这一版(ai 模型这一轮改完、me 手调写回、pre 手调写回之前;空的是这轮开始前 / 回退前)
|
|
155
|
+
const v = { n: last ? last.n + 1 : 1, at: now(), label: String(label || '').slice(0, 80), ...(by ? { by: String(by) } : {}), files }
|
|
155
156
|
list.push(v)
|
|
156
157
|
const cut = list.length > MAX_VERSIONS ? list.splice(0, list.length - MAX_VERSIONS) : []
|
|
157
158
|
save(root, list)
|
|
@@ -167,6 +168,7 @@ export function createHistory({ base, now = Date.now, log = () => {} }) {
|
|
|
167
168
|
n: v.n,
|
|
168
169
|
at: v.at,
|
|
169
170
|
label: v.label,
|
|
171
|
+
by: v.by || '',
|
|
170
172
|
changed: i ? diffFiles(all[i - 1].files, v.files) : [], // 最早的一版没得比
|
|
171
173
|
first: !i,
|
|
172
174
|
count: Object.keys(v.files).length,
|
package/lib/htmlpack.js
CHANGED
|
@@ -18,7 +18,7 @@ import { defang } from './serve.js'
|
|
|
18
18
|
/** 每屏的 <base>:一个不存在的地址(.invalid 不会被解析),屏里的相对链接都落在它下面,小脚本据此认出「站内跳转」 */
|
|
19
19
|
export const PACK_ORIGIN = 'https://ddp-pack.invalid'
|
|
20
20
|
export const PACK_MAX = 150 * 1024 * 1024 // 整个文件的上限(字符数):再大浏览器打开就很慢了
|
|
21
|
-
export const PACK_SCREENS =
|
|
21
|
+
export const PACK_SCREENS = 1000 // 画布只显示 60 屏,导出要全部(#29:有人的设计 400 多屏);真正拦的是 PACK_MAX
|
|
22
22
|
const ASSET_MIN = 2048 // 这么长以上的 data: 地址单独存一份(几屏共用的只存一次)
|
|
23
23
|
|
|
24
24
|
// ── 和 client.js 同一份数(测试比着)────────────────────────────────────────
|