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/lib/index.js CHANGED
@@ -59,7 +59,7 @@ import { createLibraryRoutes } from './gallery/routes.js'
59
59
  import { createMarket } from './gallery/market.js'
60
60
  import { createMarketRoutes } from './gallery/market-routes.js'
61
61
  import { createPhotos, loadPhotoIndex, searchPhotos, onlyByTheme, ratioNote, isPhotoAsset, orientOf, MAX_PHOTOS } from './photos.js'
62
- import { createTracker, parseTarget, findRule, KINDS } from './core.js'
62
+ import { createTracker, parseTarget, findRule, allScreens, classSigs, exportOrder, KINDS } from './core.js'
63
63
  import { createDrafts } from './draft.js'
64
64
  import { createHistory } from './history.js'
65
65
  import { createPhone } from './phone.js'
@@ -70,11 +70,12 @@ import { createBrowser } from './browser.js'
70
70
  import { createCanvasThumbs, createDirRevs } from './canvthumb.js'
71
71
  import { designOf, fitSize, metaOfFile, sizeOf, pickScreens, measureAll, shootAll, cropIssues, formatMeasure, issueSnapshot, formatShots, whereOf, MAX_SCREENS, MAX_SIZES, MAX_SHOTS, MAX_CROPS } from './look.js'
72
72
  import { SYSTEMS_DIR, extractSystem, listSystems, setDefault, skillSection } from './system.js'
73
- import { saveFrame, listFrames, frameSection } from './frames.js'
73
+ import { saveFrame, listFrames, frameSection, frameDir, renameFrame, removeFrame } from './frames.js'
74
74
  import { readTweaks, applyTweaks, lintTweaks } from './tweaks.js'
75
75
  import { readAnnotations, lintAnnotations, annotationFindings, annotationSection } from './annotations.js'
76
76
  import { createImpl } from './impl.js'
77
- import { FRAMEWORKS, detectProject, projectFor, defaultFramework, buildHandoff, compareScreens, implUrl, implServe, defaultDest, pickedDest, within, pinRoots } from './handoff.js'
77
+ import { FRAMEWORKS, detectProject, projectFor, defaultFramework, buildHandoff, compareScreens, implUrl, implServe, defaultDest, pickedDest, within, pinRoots, frameCss } from './handoff.js'
78
+ import { editsNotice, noticeMessage, langOf } from './edits.js'
78
79
 
79
80
  export const name = 'dsh-design-studio'
80
81
  export const inject = ['webServer']
@@ -85,7 +86,10 @@ const LOOPBACK_HOST = /^(127\.0\.0\.1|localhost|\[::1\])(:\d+)?$/i
85
86
  const MAX_BODY = 64 * 1024
86
87
  const MAX_EXPORT = 48 * 1024 * 1024 // 导出图片的请求体(base64)
87
88
  const MAX_DOC = 160 * 1024 * 1024 // 导出 PDF / PPT 的请求体(几十屏的 JPEG,base64)
88
- const MAX_PAGES = 60
89
+ const MAX_PAGES = 1000 // PDF / PPT 最多几页(#29:画布只显示 60 屏,导出要全部)
90
+ const DOC_CHUNK = 40 // 分批传的时候一批最多几页(截图一张几百 KB,几百屏一次传不动)
91
+ const DOC_JOB_BYTES = 1024 * 1024 * 1024 // 一份 PDF / PPT 攒的图片最多这么多
92
+ const DOC_JOB_TTL = 10 * 60 * 1000 // 一批传完到下一批最多等多久(右侧栏关了、换了设计就别一直占着内存)
89
93
  const CHECK_WAIT = 30000 // check_design 等右侧栏量完的最长时间(右侧栏每屏最多等 6 秒载入 + 15 秒量完,几屏一起量)
90
94
  const HISTORY_DIR = path.join(os.homedir(), '.dsh', 'cache', 'dsh-design-studio', 'history')
91
95
  // 每个会话预览的是什么,存这里(DSH 重启后接着显示)
@@ -577,7 +581,7 @@ export const handoffTool = {
577
581
  if (framework === 'same' && !project.framework) return { text: `${dest} 里没有认得出的前端项目(package.json 里没有 React / Vue / Next / uni-app …,也不是 HBuilderX 或微信原生小程序的项目):framework 选 react、vue、next、html、uniapp 或 weapp。` }
578
582
  let r
579
583
  try {
580
- r = await buildHandoff(studio.browser, { root: t.root, screens: pick.list, kind, size, framework, dest, project, system: systemOfDir(t.root), annotations: studio.annotations > 0 ? readAnnotations(t.root) : null })
584
+ r = await buildHandoff(studio.browser, { root: t.root, screens: pick.list, kind, size, framework, dest, project, system: systemOfDir(t.root), annotations: studio.annotations > 0 ? readAnnotations(t.root) : null, tuned: studio.tracker.versions(id) })
581
585
  } catch (e) {
582
586
  return { text: `没写成交接包:${String((e && e.message) || e).slice(0, 200)}` }
583
587
  }
@@ -1211,9 +1215,24 @@ export function apply(ctx) {
1211
1215
  res.end(jpg)
1212
1216
  }
1213
1217
 
1214
- /** 外框库:GET 列出来(首页「套外框」下面挑外框用) */
1215
- function framesRoute(req, res) {
1218
+ /** 外框库:GET 列出来(首页「套外框」下面挑外框用);POST { op: rename | delete | reveal, id, name?, en? }(我的作品 › 外框 ⋯) */
1219
+ async function framesRoute(req, res) {
1216
1220
  if (!admit(req, res)) return
1221
+ if (req.method === 'POST') {
1222
+ let body
1223
+ try { body = await readBody(req) } catch (e) { return json(res, 400, { error: e.message }) }
1224
+ const id = String(body.id || '')
1225
+ const op = String(body.op || '')
1226
+ if (op === 'reveal') {
1227
+ const d = frameDir(id)
1228
+ if (!d) return json(res, 404, { error: 'noFrame' })
1229
+ const [cmd, args] = process.platform === 'darwin' ? ['open', [d]] : process.platform === 'win32' ? ['explorer', [d]] : ['xdg-open', [d]]
1230
+ execFile(cmd, args, (e) => { if (e && process.platform !== 'win32') log(e) }) // explorer 正常也返回 1
1231
+ return json(res, 200, { ok: true })
1232
+ }
1233
+ const r = op === 'rename' ? renameFrame(id, body.name, { en: !!body.en }) : op === 'delete' ? removeFrame(id) : { ok: false, error: 'bad op' }
1234
+ return json(res, r.ok ? 200 : r.error === 'noFrame' ? 404 : 400, r)
1235
+ }
1217
1236
  let list = []
1218
1237
  try { list = listFrames() } catch (e) { log(e) }
1219
1238
  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) })) })
@@ -1356,7 +1375,7 @@ export function apply(ctx) {
1356
1375
  let body
1357
1376
  try { body = await readBody(req) } catch (e) { return json(res, 400, { error: e.message }) }
1358
1377
  try {
1359
- const r = tracker.restoreVersion(String(body.session || ''), Number(body.n))
1378
+ const r = tracker.restoreVersion(String(body.session || ''), Number(body.n), { root: typeof body.root === 'string' ? body.root : '', at: Number(body.at) || 0 })
1360
1379
  json(res, 200, { ...r, versions: tracker.versions(String(body.session || '')) })
1361
1380
  } catch (e) {
1362
1381
  json(res, 400, { error: e.message })
@@ -1370,7 +1389,7 @@ export function apply(ctx) {
1370
1389
  let body
1371
1390
  try { body = await readBody(req) } catch (e) { return json(res, 400, { error: e.message }) }
1372
1391
  try {
1373
- json(res, 200, tracker.editText(String(body.session || ''), { key: body.key, before: body.before, after: body.after, nth: body.nth }))
1392
+ json(res, 200, tracker.editText(String(body.session || ''), { key: body.key, before: body.before, after: body.after, nth: body.nth, sig: typeof body.sig === 'string' ? body.sig : '', raw: typeof body.raw === 'string' ? body.raw : '' }))
1374
1393
  } catch (e) {
1375
1394
  json(res, 500, { error: e.message })
1376
1395
  }
@@ -1383,12 +1402,75 @@ export function apply(ctx) {
1383
1402
  let body
1384
1403
  try { body = await readBody(req) } catch (e) { return json(res, 400, { error: e.message }) }
1385
1404
  try {
1386
- json(res, 200, tracker.editStyle(String(body.session || ''), { key: body.key, loc: body.loc, css: body.css, name: body.name }))
1405
+ const id = String(body.session || '')
1406
+ // 右侧栏点的时候是哪套设计:中途换了(这次保存晚到)就不写,免得写进另一套同名的屏
1407
+ if (typeof body.target === 'string' && body.target !== targetKeyOf(tracker.stateOf(id).target)) return json(res, 200, { ok: false, reason: 'moved' })
1408
+ const rule = body.rule && typeof body.rule === 'object' ? body.rule : null
1409
+ if (rule) return json(res, 200, styleToRule(id, body, rule))
1410
+ json(res, 200, tracker.editStyle(id, { key: body.key, loc: body.loc, css: body.css, name: body.name, imp: Array.isArray(body.imp) ? body.imp.slice(0, 20) : [] }))
1387
1411
  } catch (e) {
1388
1412
  json(res, 500, { error: e.message })
1389
1413
  }
1390
1414
  }
1391
1415
 
1416
+ /**
1417
+ * 调样式「各屏一起改」:写进右侧栏指的那条规则({ href, sel, n, cls },href 是预览地址上的样式表)。
1418
+ * 只认这个会话预览的本地目录里的 .css;外框的样式表(锁着的)不写。写不了给 { ok: false, reason },右侧栏退回只改这一处
1419
+ */
1420
+ function styleToRule(id, body, rule) {
1421
+ const st = tracker.stateOf(id)
1422
+ const t = st && st.target
1423
+ if (!t || t.kind !== 'file' || !st.origin) return { ok: false, reason: 'not-file' }
1424
+ let u
1425
+ try { u = new URL(String(rule.href || '')) } catch { return { ok: false, reason: 'no-rule' } }
1426
+ if (u.origin !== st.origin || u.pathname.startsWith('/__dsh_design__/') || !/\.css$/i.test(u.pathname)) return { ok: false, reason: 'no-rule' }
1427
+ const hit = resolveInRoot(t.root, u.pathname)
1428
+ if (!hit || !hit.real) return { ok: false, reason: 'no-rule' }
1429
+ const key = String(body.key || path.basename(t.file))
1430
+ let html = ''
1431
+ try { html = fs.readFileSync(path.join(t.root, path.basename(key)), 'utf8') } catch { /* 读不了就当没套外框 */ }
1432
+ const locked = new Set(frameCss(t.root, [html]).map((x) => x.toLowerCase()))
1433
+ if (locked.has(path.basename(hit.abs).toLowerCase())) return { ok: false, reason: 'frame' }
1434
+ return tracker.editRule(id, { key, loc: body.loc, file: hit.abs, sel: String(rule.sel || '').slice(0, 400), n: Math.max(0, Math.floor(Number(rule.n) || 0)), css: body.css, name: body.name, cls: String(rule.cls || '').slice(0, 80) })
1435
+ }
1436
+
1437
+ /**
1438
+ * 「各屏一起改」默认勾不勾(#28):设计里所有屏(收起来的也算)带这个 class 的元素,是不是都和选中的同一种(sig:picker 算的「标签|class」)。
1439
+ * 有一处不一样(.btn 既是按钮又是链接)、读不了、太大:same: false,右侧栏默认只改这一处。
1440
+ * 按目录 + class 记一下(各屏的修改时间、大小都没变就不重读),点来点去不用每次全读
1441
+ */
1442
+ const shareSeen = new Map() // `${root}|${cls}` → { stamp, sigs: Set(sig) },只留最近 20 个
1443
+ async function shareCheckRoute(req, res) {
1444
+ if (!admit(req, res)) return
1445
+ if (req.method !== 'POST') return json(res, 405, { error: 'method not allowed' })
1446
+ let body
1447
+ try { body = await readBody(req) } catch (e) { return json(res, 400, { error: e.message }) }
1448
+ const st = tracker.stateOf(String(body.session || ''))
1449
+ const t = st && st.target
1450
+ const cls = String(body.cls || '')
1451
+ const sig = String(body.sig || '')
1452
+ if (!t || t.kind !== 'file' || !/^-?[_a-zA-Z][\w-]{0,79}$/.test(cls) || !sig) return json(res, 200, { same: false })
1453
+ const files = allScreens(t.root).slice(0, MAX_PAGES)
1454
+ const stats = files.map((k) => { try { return fs.statSync(path.join(t.root, k)) } catch { return null } })
1455
+ const stamp = files.map((k, i) => (stats[i] ? `${k}:${stats[i].mtimeMs}:${stats[i].size}` : '')).join('|')
1456
+ const ck = `${t.root}|${cls}`
1457
+ let hit = shareSeen.get(ck)
1458
+ if (!hit || hit.stamp !== stamp) {
1459
+ const sigs = new Set()
1460
+ for (const [i, k] of files.entries()) {
1461
+ if (!stats[i]) continue // 刚删掉的屏不算
1462
+ if (stats[i].size > 2 * 1024 * 1024) { sigs.add('?'); break }
1463
+ try { for (const x of classSigs(fs.readFileSync(path.join(t.root, k), 'utf8'), cls)) sigs.add(x) } catch { sigs.add('?') }
1464
+ if (sigs.size > 1) break
1465
+ }
1466
+ hit = { stamp, sigs }
1467
+ shareSeen.delete(ck)
1468
+ shareSeen.set(ck, hit)
1469
+ while (shareSeen.size > 20) shareSeen.delete(shareSeen.keys().next().value)
1470
+ }
1471
+ json(res, 200, { target: targetKeyOf(t), same: hit.sigs.size === 1 && hit.sigs.has(sig) })
1472
+ }
1473
+
1392
1474
  /**
1393
1475
  * 调样式交给模型前:每项样式胜出的那条规则在源码第几行(picker 给 { href, sel, n },这里在设计目录的文件里找)。
1394
1476
  * 只认这个会话预览的本地目录里的文件;开发服务器的样式多半是编译出来的,不找
@@ -1645,26 +1727,98 @@ export function apply(ctx) {
1645
1727
  saveExport(res, String(body.session || ''), body.name, 'png', buf)
1646
1728
  }
1647
1729
 
1648
- /** 几屏拼成 PDF / PPT:每屏一页,页面大小按那一屏的 CSS 尺寸 */
1730
+ /**
1731
+ * 屏多过上限(#29):导出用的全部屏,按导出的先后(显示的照右侧栏的顺序,收起来的照设计清单 / 生成先后插回原位),带页面标题(导出的目录、演示的下拉里用)。
1732
+ * 右侧栏导出前现问这一份,不靠它自己记的(刚加的屏、改了名的收起来的屏,它都还没轮询到)。没收起来的给空(右侧栏就用显示的这些)
1733
+ */
1734
+ async function hiddenRoute(req, res) {
1735
+ if (!admit(req, res)) return
1736
+ if (req.method !== 'POST') return json(res, 405, { error: 'method not allowed' })
1737
+ let body
1738
+ try { body = await readBody(req) } catch (e) { return json(res, 400, { error: e.message }) }
1739
+ const session = String(body.session || '')
1740
+ const st = tracker.stateOf(session)
1741
+ const t = st.target
1742
+ const hid = tracker.hiddenScreens(session)
1743
+ if (!hid.length) return json(res, 200, { target: targetKeyOf(t), list: [] })
1744
+ const on = new Set(hid)
1745
+ const all = exportOrder(st.screens, hid, allScreens(t.root))
1746
+ const keys = all.slice(0, MAX_PAGES) // 一次最多导出这么多屏,多的(排在最后的)右侧栏提示没导出
1747
+ const list = keys.map((key) => {
1748
+ let title = ''
1749
+ try {
1750
+ const fd = fs.openSync(path.join(t.root, key), 'r')
1751
+ try { const buf = Buffer.alloc(8192); const n = fs.readSync(fd, buf, 0, buf.length, 0); title = (/<title[^>]*>([^<]{1,120})<\/title>/i.exec(buf.subarray(0, n).toString('utf8')) || [])[1] || '' } finally { fs.closeSync(fd) }
1752
+ } catch { title = '' }
1753
+ return { key, title: title.replace(/\s+/g, ' ').trim(), hidden: on.has(key) }
1754
+ })
1755
+ json(res, 200, { target: targetKeyOf(t), list, cut: all.length - keys.length })
1756
+ }
1757
+
1758
+ // PDF / PPT 分批传(#29):几百屏的截图一次传不动,右侧栏每截几十屏传一批,最后一批带 done 再拼。job → { session, pages, bytes, at }
1759
+ const docJobs = new Map()
1760
+ const sweepDocJobs = () => { const old = Date.now() - DOC_JOB_TTL; for (const [k, j] of docJobs) if (j.at < old) docJobs.delete(k) }
1761
+ // 导出到一半退出 / 右侧栏关了:没人再来传,也按时清掉攒着的截图(不等下一次导出)
1762
+ ctx.effect(() => { const iv = setInterval(sweepDocJobs, 60 * 1000); if (iv.unref) iv.unref(); return () => { clearInterval(iv); docJobs.clear() } }, 'dsh-design-studio: doc jobs')
1763
+
1764
+ /** 一页截图:JPEG + CSS 尺寸 + 标题 + 跳转链接;不是 JPEG 给 null */
1765
+ function docPage(p) {
1766
+ const jpg = Buffer.from(String((p && p.jpg) || ''), 'base64')
1767
+ const info = jpegInfo(jpg)
1768
+ if (!info) return null
1769
+ // 页面大小(CSS 像素):没给或不像话就按图片的一半算(截图是 2 倍)
1770
+ const ok = (v) => Number.isFinite(+v) && +v >= 16 && +v <= 30000
1771
+ const w = ok(p.w) && ok(p.h) ? +p.w : info.width / 2
1772
+ const h = ok(p.w) && ok(p.h) ? +p.h : info.height / 2
1773
+ // 跳转链接原样带过去,doc.js 里挑掉不合法的;分批传的链接写的是目标屏的 key(到最后才知道它是第几页)
1774
+ return { jpg, w, h, key: typeof p.key === 'string' ? p.key.slice(0, 300) : '', title: String(p.title || '').slice(0, 80), links: Array.isArray(p.links) ? p.links.slice(0, 50) : [] }
1775
+ }
1776
+
1777
+ /** 几屏拼成 PDF / PPT:每屏一页,页面大小按那一屏的 CSS 尺寸。带 job 的是分批传:没 done 的只攒着 */
1649
1778
  async function docRoute(req, res) {
1650
1779
  if (!admit(req, res)) return
1651
1780
  if (req.method !== 'POST') return json(res, 405, { error: 'method not allowed' })
1652
1781
  let body
1653
1782
  try { body = await readBody(req, MAX_DOC) } catch (e) { return json(res, 400, { error: e.message }) }
1783
+ const session = String(body.session || '')
1784
+ const job = typeof body.job === 'string' && /^[a-z0-9]{8,40}$/i.test(body.job) ? body.job : ''
1785
+ let pages = []
1786
+ if (job) {
1787
+ sweepDocJobs()
1788
+ if (body.cancel) { if (docJobs.get(job)?.session === session) docJobs.delete(job); return json(res, 200, { ok: true }) } // 导出到一半换了设计
1789
+ // at:右侧栏说之前已经传了几页。前面传过、这里却没了(等太久被清掉、DSH 重启过),或页数对不上:别拿半截拼,整份重来
1790
+ const sent = typeof body.at === 'number' ? Math.max(0, Math.floor(body.at)) : -1
1791
+ let j = docJobs.get(job)
1792
+ if (!j) {
1793
+ if (sent > 0) return json(res, 410, { error: 'jobGone' })
1794
+ j = { session, pages: [], bytes: 0, at: Date.now() }
1795
+ docJobs.set(job, j)
1796
+ }
1797
+ if (j.session !== session) return json(res, 400, { error: 'job' })
1798
+ if (sent >= 0 && j.pages.length !== sent) { docJobs.delete(job); return json(res, 409, { error: 'jobGone' }) }
1799
+ for (const p of Array.isArray(body.pages) ? body.pages.slice(0, DOC_CHUNK) : []) {
1800
+ const pg = docPage(p)
1801
+ if (!pg) { docJobs.delete(job); return json(res, 400, { error: '不是 JPEG' }) }
1802
+ j.bytes += pg.jpg.length
1803
+ if (j.pages.length >= MAX_PAGES || j.bytes > DOC_JOB_BYTES) { docJobs.delete(job); return json(res, 413, { error: 'tooBig' }) }
1804
+ j.pages.push(pg)
1805
+ }
1806
+ j.at = Date.now()
1807
+ if (!body.done) return json(res, 200, { ok: true, n: j.pages.length })
1808
+ docJobs.delete(job)
1809
+ pages = j.pages
1810
+ // 链接:目标屏的 key 换成第几页(没截上的屏不算)
1811
+ const at = new Map(pages.map((p, i) => [p.key, i]))
1812
+ for (const p of pages) p.links = p.links.map((l) => (l && typeof l.key === 'string' ? { x: l.x, y: l.y, w: l.w, h: l.h, to: at.has(l.key) ? at.get(l.key) : -1 } : l)).filter((l) => l && l.to >= 0)
1813
+ } else {
1814
+ for (const p of Array.isArray(body.pages) ? body.pages.slice(0, MAX_PAGES) : []) {
1815
+ const pg = docPage(p)
1816
+ if (!pg) return json(res, 400, { error: '不是 JPEG' })
1817
+ pages.push(pg)
1818
+ }
1819
+ }
1654
1820
  const format = body.format === 'pdf' || body.format === 'pptx' ? body.format : ''
1655
1821
  if (!format) return json(res, 400, { error: 'format 只能是 pdf / pptx' })
1656
- const pages = []
1657
- for (const p of Array.isArray(body.pages) ? body.pages.slice(0, MAX_PAGES) : []) {
1658
- const jpg = Buffer.from(String((p && p.jpg) || ''), 'base64')
1659
- const info = jpegInfo(jpg)
1660
- if (!info) return json(res, 400, { error: '不是 JPEG' })
1661
- // 页面大小(CSS 像素):没给或不像话就按图片的一半算(截图是 2 倍)
1662
- const ok = (v) => Number.isFinite(+v) && +v >= 16 && +v <= 30000
1663
- const w = ok(p.w) && ok(p.h) ? +p.w : info.width / 2
1664
- const h = ok(p.w) && ok(p.h) ? +p.h : info.height / 2
1665
- // 跳转链接原样带过去,doc.js 里挑掉不合法的
1666
- pages.push({ jpg, w, h, title: String(p.title || '').slice(0, 80), links: Array.isArray(p.links) ? p.links.slice(0, 50) : [] })
1667
- }
1668
1822
  if (!pages.length) return json(res, 400, { error: '没有页面' })
1669
1823
  const title = String(body.title || '').slice(0, 120)
1670
1824
  let buf
@@ -1675,8 +1829,8 @@ export function apply(ctx) {
1675
1829
  } catch (e) {
1676
1830
  return json(res, 400, { error: e.message })
1677
1831
  }
1678
- if (targetMoved(res, String(body.session || ''), body.target)) return
1679
- saveExport(res, String(body.session || ''), body.name, format, buf)
1832
+ if (targetMoved(res, session, body.target)) return
1833
+ saveExport(res, session, body.name, format, buf)
1680
1834
  }
1681
1835
 
1682
1836
  /** 整套 HTML 演示的参数(导出和公网链接共用):挑掉不合法、重复的屏;画幅、深浅色、调节值按右侧栏给的。没有屏给 null */
@@ -1822,6 +1976,8 @@ export function apply(ctx) {
1822
1976
  return json(res, 200, phone.status(session))
1823
1977
  }
1824
1978
  if (!tracker.snapshot(session).origin) return json(res, 400, { error: '还没有在预览的页面' })
1979
+ // keep:右侧栏只是换了一屏,入口已经关了(别处点了停止、闲着自动关)就别重开
1980
+ if (body.keep === true && !phone.status(session).on) return json(res, 200, phone.status(session))
1825
1981
  const st = await phone.start(session, typeof body.path === 'string' && body.path.startsWith('/') ? body.path : '/')
1826
1982
  // 二维码一行一串 0 / 1,右侧栏画成 SVG
1827
1983
  json(res, 200, st.on ? { ...st, qr: qrMatrix(st.url).map((row) => row.map((c) => (c ? 1 : 0)).join('')) } : st)
@@ -1909,7 +2065,7 @@ export function apply(ctx) {
1909
2065
  })
1910
2066
  const mk = createMarketRoutes({ admit, readBody, json, tracker, library, market, open, systemsDir: SYSTEMS_DIR, log, sessionCwd })
1911
2067
 
1912
- 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, htmlpack: htmlPackRoute, pubshare: pubShareRoute, reveal: revealRoute, phone: phoneRoute, check: checkRoute, locate: locateRoute, tweak: tweakRoute, systems: systemsRoute, frames: framesRoute, systhumb: systhumbRoute, project: projectRoute, impl: implRoute, implcmp: implCmpRoute, implshot: implShotRoute }
2068
+ const routes = { works: lib.works, workthumb: lib.workthumb, scrthumb: canvasThumbs.route, verthumb: canvasThumbs.verRoute, 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, hidden: hiddenRoute, edit: editRoute, style: styleRoute, sharecheck: shareCheckRoute, bundle: bundleRoute, ref: refRoute, export: exportRoute, doc: docRoute, htmlpack: htmlPackRoute, pubshare: pubShareRoute, reveal: revealRoute, phone: phoneRoute, check: checkRoute, locate: locateRoute, tweak: tweakRoute, systems: systemsRoute, frames: framesRoute, systhumb: systhumbRoute, project: projectRoute, impl: implRoute, implcmp: implCmpRoute, implshot: implShotRoute }
1913
2069
  for (const [key, handler] of Object.entries(routes)) {
1914
2070
  ctx.effect(() => ctx.webServer.register({
1915
2071
  kind: 'exact',
@@ -1942,6 +2098,23 @@ export function apply(ctx) {
1942
2098
  log(e)
1943
2099
  }
1944
2100
  }, { global: true })
2101
+ // 用户在右侧栏亲手改了设计:模型下一步开始前补一条说明(DSH 自带的时间、操作卡片提醒也是这么加的),
2102
+ // 免得它凭自己之前写的内容接着改、做进项目时用回旧样子(#28)。老版本 DSH 没有这个事件,就只是收不到
2103
+ ctx.on('agent/pre-step', async (payload, next) => {
2104
+ const decision = typeof next === 'function' ? await next() : undefined
2105
+ try {
2106
+ if (!decision || decision.kind !== 'enter' || !Array.isArray(decision.messages) || (payload && payload.signal && payload.signal.aborted)) return decision
2107
+ const id = payload && payload.agent && payload.agent.session && payload.agent.session.id
2108
+ if (!id) return decision
2109
+ const edits = tracker.takeEdits(String(id))
2110
+ const note = editsNotice(edits, langOf(decision.messages))
2111
+ if (!note) return decision
2112
+ return { ...decision, messages: [...decision.messages, noticeMessage(note, crypto.randomUUID())] }
2113
+ } catch (e) {
2114
+ log(e)
2115
+ return decision
2116
+ }
2117
+ }, { prepend: true })
1945
2118
  // 模型边说边推的流:写大文件时参数要流好几分钟,靠它提前知道在写哪个文件(老版本 DSH 没有这个事件,就只是收不到)
1946
2119
  ctx.on('agent/assistant-stream', (e) => {
1947
2120
  try {
package/lib/picker.js CHANGED
@@ -429,6 +429,7 @@
429
429
  // 调样式:选中它(留虚线框),接着还能点别的
430
430
  const el = under(e.clientX, e.clientY)
431
431
  if (!el || el === document.body) return
432
+ rip(e.clientX, e.clientY)
432
433
  styleSelect(el)
433
434
  post({ type: 'stylePick', payload: { ...styleInfo(el), href: here() } })
434
435
  return
@@ -447,6 +448,7 @@
447
448
  const el = under(e.clientX, e.clientY)
448
449
  if (!el) return
449
450
  payload = { kind: 'element', ...describe(el) }
451
+ rip(e.clientX, e.clientY)
450
452
  place(el.getBoundingClientRect(), 'done')
451
453
  pin(null, el, nameOf(el))
452
454
  }
@@ -584,9 +586,12 @@
584
586
  @keyframes hl{0%{opacity:0;transform:scale(1.035)}9%{opacity:1;transform:scale(1)}78%{opacity:1}100%{opacity:0}}
585
587
  @keyframes sweep{to{transform:translateX(110%)}}
586
588
  .pin{position:absolute;pointer-events:none;border:calc(1.5px * var(--k, 1)) dashed #4d6bfe;border-radius:5px;background:rgba(77,107,254,.05);
587
- animation:pin-in .25s ease-out}
589
+ animation:pin-in .34s cubic-bezier(.3,1.4,.4,1)}
590
+ .rip{position:absolute;width:calc(36px * var(--k, 1));height:calc(36px * var(--k, 1));margin:calc(-18px * var(--k, 1)) 0 0 calc(-18px * var(--k, 1));border-radius:50%;
591
+ box-shadow:0 0 0 calc(2px * var(--k, 1)) #4d6bfe;opacity:0;pointer-events:none;animation:rip .5s cubic-bezier(.2,.8,.2,1)}
592
+ @keyframes rip{from{opacity:.75;transform:scale(.3)}to{opacity:0;transform:scale(1.5)}}
588
593
  .pin span{opacity:.92}
589
- @keyframes pin-in{from{opacity:0}}
594
+ @keyframes pin-in{from{opacity:0;transform:scale(1.12)}}
590
595
  .ck{position:absolute;pointer-events:none;border:calc(2px * var(--k, 1)) solid #f59e0b;border-radius:4px;background:rgba(245,158,11,.08)}
591
596
  .ck.hi{border-color:#e5484d;background:rgba(229,72,77,.08)}
592
597
  .ck b{position:absolute;left:calc(-9px * var(--k, 1));top:calc(-9px * var(--k, 1));min-width:18px;height:18px;padding:0 4px;box-sizing:border-box;border-radius:9px;
@@ -594,6 +599,8 @@
594
599
  transform:scale(var(--k, 1));transform-origin:0 0;box-shadow:0 2px 6px rgba(0,0,0,.25)}
595
600
  .ck.hi b{background:#e5484d}
596
601
  .ck.on{animation:ck-on 1.2s ease-out}
602
+ .ck.on b{animation:ck-pop .7s cubic-bezier(.2,.8,.2,1)}
603
+ @keyframes ck-pop{25%,75%{scale:1.3}50%{scale:1}}
597
604
  .an{position:absolute;pointer-events:none;border-radius:4px}
598
605
  .an.sel{outline:calc(2px * var(--k, 1)) solid #4d6bfe;outline-offset:calc(1px * var(--k, 1));background:rgba(77,107,254,.07)}
599
606
  .an b{position:absolute;left:calc((var(--i, 0) * 21px - 9px) * var(--k, 1));top:calc(-9px * var(--k, 1));min-width:18px;height:18px;padding:0 4px;box-sizing:border-box;border-radius:9px;
@@ -608,6 +615,7 @@
608
615
  font:600 12px/18px -apple-system,BlinkMacSystemFont,system-ui,sans-serif;white-space:nowrap;transform:scale(var(--k, 1));transform-origin:0 100%}
609
616
  .cut.low b{bottom:auto;top:100%;margin:calc(3px * var(--k, 1)) 0 0;transform-origin:0 0}
610
617
  @keyframes ck-on{0%,40%{box-shadow:0 0 0 calc(6px * var(--k, 1)) rgba(229,72,77,.35)}100%{box-shadow:0 0 0 0 rgba(229,72,77,0)}}
618
+ @media (prefers-reduced-motion:reduce){.pin,.ck.on b{animation:none}.rip{display:none}}
611
619
  .scan{position:fixed;left:0;right:0;top:0;height:38vh;pointer-events:none;opacity:0;
612
620
  background:linear-gradient(180deg,rgba(77,107,254,0),rgba(77,107,254,.06) 55%,rgba(124,140,255,.22) 92%,rgba(77,107,254,0));
613
621
  animation:scan var(--dur, 1.2s) cubic-bezier(.45,0,.25,1) forwards}
@@ -667,6 +675,18 @@
667
675
  return { left: r.left + scrollX, top: r.top + scrollY, width: r.width, height: r.height }
668
676
  }
669
677
 
678
+ /** 点选落点一圈水波(选择、调样式点元素时) */
679
+ function rip(x, y) {
680
+ try { if (matchMedia('(prefers-reduced-motion: reduce)').matches) return } catch { /* 照常放 */ }
681
+ const { root } = fxRoot()
682
+ const r = document.createElement('i')
683
+ r.className = 'rip'
684
+ r.style.left = x + scrollX + 'px'
685
+ r.style.top = y + scrollY + 'px'
686
+ root.append(r)
687
+ setTimeout(() => r.remove(), 600)
688
+ }
689
+
670
690
  function flash(els) {
671
691
  const { root } = fxRoot()
672
692
  els.forEach((el, i) => {
@@ -1295,9 +1315,11 @@
1295
1315
  if (same && seed.scroll) scrollTo(seed.scroll.x, seed.scroll.y)
1296
1316
  pending = same && seed.sig ? compare(seed.sig, snapshot()) : null
1297
1317
  const meta = document.querySelector('meta[name="dsh-design"]')
1318
+ const err = document.querySelector('meta[name="dsh-error"]') // 预览服务器给的出错页(文件没了 / 开发服务器连不上)
1298
1319
  post({
1299
1320
  type: 'ready',
1300
1321
  title: document.title,
1322
+ err: err ? String(err.getAttribute('content') || 'missing').slice(0, 20) : '',
1301
1323
  href: here(),
1302
1324
  meta: meta ? String(meta.getAttribute('content') || '').slice(0, 80) : '',
1303
1325
  tokens: tokensOf(),
@@ -1408,6 +1430,38 @@
1408
1430
  const c = (s.replace(/\[[^\]]*\]|\([^()]*\)/g, '').match(/(?:^|[\s>+~,])[a-z][\w-]*|::[\w-]+/gi) || []).length
1409
1431
  return a * 1e6 + b * 1e3 + c + extra
1410
1432
  }
1433
+ // 像状态的 class(is-active、on、selected……):比「是不是同一种元素」时不算
1434
+ const STATE_CLS = /^(is-|has-)|^(active|on|sel|selected|current|hidden|show|open|disabled|checked|focus|hover)$/
1435
+ /**
1436
+ * 「各屏一起改」能不能写进这条规则:选择器(命中 el 的那一支)最后一节里得有 el 自己的一个 class(cls),
1437
+ * uni:选择器没有逗号并列、页面上这条规则命中的都和 el 是同一种(同标签、去掉状态 class 后 class 一样)——是的话(再经服务端核对各屏)默认各屏一起改;
1438
+ * 「button」「.card a」这种没有 el 的 class 的给 null(只改这一处)
1439
+ */
1440
+ function sharedOf(el, sel) {
1441
+ let cls = ''
1442
+ for (const part of splitList(sel)) {
1443
+ try { if (!el.matches(part)) continue } catch { continue }
1444
+ // 最后一节:顶层(括号、方括号外)最后一个组合符之后
1445
+ let depth = 0
1446
+ let at = 0
1447
+ for (let i = 0; i < part.length; i++) {
1448
+ const ch = part[i]
1449
+ if (ch === '(' || ch === '[') depth++
1450
+ else if (ch === ')' || ch === ']') depth--
1451
+ else if (!depth && (ch === ' ' || ch === '>' || ch === '+' || ch === '~')) at = i + 1
1452
+ }
1453
+ const last = part.slice(at).replace(/\[[^\]]*\]|\((?:[^()]|\([^()]*\))*\)/g, '')
1454
+ for (const m of last.matchAll(/\.(-?[_a-zA-Z][\w-]*)/g)) if (el.classList.contains(m[1]) && !STATE_CLS.test(m[1])) { cls = m[1]; break }
1455
+ if (cls) break
1456
+ }
1457
+ if (!cls) return null
1458
+ const sig = (x) => x.tagName + '|' + [...x.classList].filter((c) => !STATE_CLS.test(c)).sort().join(' ')
1459
+ let hits = []
1460
+ try { hits = [...document.querySelectorAll(sel)] } catch { return null }
1461
+ const me = sig(el)
1462
+ // 逗号并列的(.save-btn, .cancel-btn):别的屏可能是另一种元素,各屏核对只查得到 cls 这一种 → 不默认勾
1463
+ return { cls, cnt: hits.length, uni: splitList(sel).length === 1 && hits.every((x) => sig(x) === me), sig: me.slice(0, 300) }
1464
+ }
1411
1465
  // 面板上的几项各看哪些写法(简写也算)
1412
1466
  const LONGHANDS = {
1413
1467
  'font-size': ['font-size', 'font'], 'font-weight': ['font-weight', 'font'], color: ['color'], background: ['background', 'background-color'],
@@ -1474,8 +1528,12 @@
1474
1528
  for (const k of keys) {
1475
1529
  const b = best[k]
1476
1530
  const inl = (LONGHANDS[k] || [k]).find((L) => el.style.getPropertyValue(L))
1477
- if (inl && (!b || !b.imp || el.style.getPropertyPriority(inl) === 'important')) out[k] = { inline: true, ...(b ? { sel: clip(b.sel, 200), href: b.href, n: b.n } : {}) }
1478
- else if (b) out[k] = { sel: clip(b.sel, 200), href: b.href, n: b.n, ...(b.maybe ? { maybe: true } : {}) }
1531
+ const sh = b && b.sel.length <= 200 && keys === STYLE_KEYS ? sharedOf(el, b.sel) : null
1532
+ const share = sh ? { cls: sh.cls, cnt: sh.cnt, uni: sh.uni, sig: sh.sig } : {}
1533
+ // imp:现在生效的这个值带 !important(行内的、规则的都算):预览和保存都照样带,不然第二次调同一个元素会被规则盖回去
1534
+ const inlImp = !!inl && el.style.getPropertyPriority(inl) === 'important'
1535
+ if (inl && (!b || !b.imp || inlImp)) out[k] = { inline: true, ...(b ? { sel: clip(b.sel, 200), href: b.href, n: b.n, ...share, ...(b.maybe ? { maybe: true } : {}) } : {}), ...(inlImp ? { imp: true } : {}) }
1536
+ else if (b) out[k] = { sel: clip(b.sel, 200), href: b.href, n: b.n, ...share, ...(b.maybe ? { maybe: true } : {}), ...(b.imp ? { imp: true } : {}) }
1479
1537
  }
1480
1538
  return out
1481
1539
  }
@@ -1516,12 +1574,21 @@
1516
1574
  }
1517
1575
 
1518
1576
  /** css:属性 → 值(这次一共改了哪些);每次从原样重来,去掉的那项就回去了 */
1577
+ let styleImpEl = null
1578
+ let styleImp = new Set()
1519
1579
  function styleApply(css) {
1520
1580
  if (!styleEl) return
1521
1581
  styleRevert()
1582
+ // 胜出的规则带 !important(行内没带):预览也带上,不然拖了看不出变化(保存时右侧栏一样带)
1583
+ if (styleImpEl !== styleEl) {
1584
+ styleImpEl = styleEl
1585
+ let r = {}
1586
+ try { r = rulesOf(styleEl) } catch { r = {} }
1587
+ styleImp = new Set(Object.keys(r).filter((k) => r[k] && r[k].imp))
1588
+ }
1522
1589
  for (const [k, v] of Object.entries(css || {})) {
1523
1590
  if (!STYLE_KEYS.includes(k) || typeof v !== 'string' || !v) continue
1524
- styleEl.style.setProperty(k, v)
1591
+ styleEl.style.setProperty(k, v, styleImp.has(k) ? 'important' : '')
1525
1592
  }
1526
1593
  placePin()
1527
1594
  }
@@ -1569,6 +1636,12 @@
1569
1636
  let textEdit = false
1570
1637
  let editUi = null
1571
1638
  let editing = null // { span, node, before, nth }
1639
+ let editLang = 'zh'
1640
+ // 正在改的那段字上面的小标签:什么字 · 字号 / 粗细(和右侧栏灵动条上的按键提示一起看)
1641
+ const ED_TX = {
1642
+ zh: { h: '标题', p: '正文', button: '按钮', a: '链接', label: '标签', li: '列表', text: '文字', w7: '粗', w5: '中', w4: '常规' },
1643
+ en: { h: 'Heading', p: 'Body', button: 'Button', a: 'Link', label: 'Label', li: 'List', text: 'Text', w7: 'Bold', w5: 'Medium', w4: 'Regular' },
1644
+ }
1572
1645
 
1573
1646
  function countIn(hay, needle) {
1574
1647
  if (!needle) return 0
@@ -1616,11 +1689,16 @@
1616
1689
  hostEl.style.setProperty('--k', K)
1617
1690
  const root = hostEl.attachShadow({ mode: 'closed' })
1618
1691
  root.innerHTML = `<style>:host{all:initial}
1619
- .box{position:fixed;z-index:2147483646;pointer-events:none;display:none;border-radius:3px;border:calc(1.5px * var(--k, 1)) dashed #4d6bfe;background:rgba(77,107,254,.06)}
1692
+ .box{position:fixed;z-index:2147483646;pointer-events:none;display:none;border-radius:3px;border:calc(1.5px * var(--k, 1)) dashed #4fa8ff;background:rgba(79,168,255,.07)}
1693
+ .tag{position:fixed;z-index:2147483647;pointer-events:none;display:none;align-items:center;gap:4px;height:18px;padding:0 7px 0 5px;border-radius:6px;transform:translateY(-100%) scale(var(--k, 1));transform-origin:0 100%;
1694
+ background:linear-gradient(100deg,#a594ff,#5ec8f2 55%,#67e0c3);color:#0b1020;font:600 11px/18px -apple-system,system-ui,sans-serif;white-space:nowrap;box-shadow:0 4px 14px rgba(40,90,200,.28);animation:tg .22s cubic-bezier(.2,.8,.2,1) both}
1695
+ .tag svg{width:11px;height:11px}
1696
+ @keyframes tg{from{opacity:0;transform:translateY(calc(-100% + 4px)) scale(var(--k, 1))}}
1697
+ @media (prefers-reduced-motion:reduce){.tag{animation:none}}
1620
1698
  .hint{position:fixed;left:50%;top:10px;transform:translateX(-50%) scale(var(--k, 1));transform-origin:50% 0;z-index:2147483647;pointer-events:none;padding:6px 12px;border-radius:999px;
1621
1699
  background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-ui,sans-serif;white-space:nowrap;box-shadow:0 4px 16px rgba(0,0,0,.25)}</style>
1622
- <div class="box"></div><div class="hint">点文字直接改 · 回车保存 · Esc 退出</div>`
1623
- editUi = { host: hostEl, box: root.querySelector('.box'), hint: root.querySelector('.hint') }
1700
+ <div class="box"></div><div class="tag"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"><path d="M5 6h14M12 6v13"/></svg><span></span></div><div class="hint">点文字直接改 · 回车保存 · Esc 退出</div>`
1701
+ editUi = { host: hostEl, box: root.querySelector('.box'), hint: root.querySelector('.hint'), tag: root.querySelector('.tag') }
1624
1702
  if (!hint) editUi.hint.style.display = 'none'
1625
1703
  document.documentElement.appendChild(hostEl)
1626
1704
  }
@@ -1639,6 +1717,23 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
1639
1717
  Object.assign(editUi.box.style, { display: 'block', left: r.left - 3 + 'px', top: r.top - 2 + 'px', width: r.width + 6 + 'px', height: r.height + 4 + 'px' })
1640
1718
  }
1641
1719
 
1720
+ /** 正在改的字上面挂标签(span 为空就收起);滚动时跟着挪 */
1721
+ function editTag(span) {
1722
+ if (!editUi) return
1723
+ const tg = editUi.tag
1724
+ if (!span || !span.isConnected) { tg.style.display = 'none'; return }
1725
+ const el = span.parentElement || span
1726
+ const tx = ED_TX[editLang] || ED_TX.zh
1727
+ const tn = el.closest('h1,h2,h3,h4,h5,h6,button,a,label,li,p')
1728
+ const kind = !tn ? tx.text : /^H\d$/.test(tn.tagName) ? tx.h : tx[tn.tagName.toLowerCase()] || tx.text
1729
+ const cs = getComputedStyle(el)
1730
+ const w = parseInt(cs.fontWeight, 10) || 400
1731
+ tg.querySelector('span').textContent = `${kind} · ${Math.round(parseFloat(cs.fontSize) || 0)} / ${w >= 600 ? tx.w7 : w >= 500 ? tx.w5 : tx.w4}`
1732
+ const r = span.getBoundingClientRect()
1733
+ Object.assign(tg.style, { display: 'flex', left: Math.max(2, r.left - 3) + 'px', top: Math.max(20 * K, r.top - 5) + 'px' })
1734
+ }
1735
+ function onEditScroll() { if (editing) editTag(editing.span) }
1736
+
1642
1737
  function onEditMove(e) {
1643
1738
  if (!textEdit || editing) return
1644
1739
  editBox(textAt(e.clientX, e.clientY))
@@ -1659,7 +1754,7 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
1659
1754
  const nth = nthOf(node, before)
1660
1755
  const span = document.createElement('span')
1661
1756
  span.setAttribute('data-dsh-edit', '')
1662
- span.style.cssText = 'outline:calc(2px * var(--dsh-k, 1)) solid #4d6bfe;outline-offset:2px;border-radius:2px;cursor:text;caret-color:#4d6bfe'
1757
+ span.style.cssText = 'outline:calc(1.5px * var(--dsh-k, 1)) solid #4fa8ff;outline-offset:3px;border-radius:3px;cursor:text;caret-color:#4fa8ff;box-shadow:0 0 0 calc(5px * var(--dsh-k, 1)) rgba(79,168,255,.14)'
1663
1758
  span.style.setProperty('--dsh-k', K)
1664
1759
  try { span.contentEditable = 'plaintext-only' } catch { span.contentEditable = 'true' }
1665
1760
  if (span.contentEditable !== 'plaintext-only') span.contentEditable = 'true'
@@ -1667,6 +1762,8 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
1667
1762
  span.appendChild(node)
1668
1763
  editing = { span, node, before, nth, raw: node.data }
1669
1764
  editBox(null)
1765
+ editTag(span)
1766
+ post({ type: 'editing', on: true })
1670
1767
  span.focus()
1671
1768
  const sel = getSelection()
1672
1769
  const range = document.createRange()
@@ -1681,6 +1778,8 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
1681
1778
  const ed = editing
1682
1779
  if (!ed) return
1683
1780
  editing = null
1781
+ editTag(null)
1782
+ post({ type: 'editing', on: false })
1684
1783
  const after = normWs(ed.span.innerText)
1685
1784
  const text = document.createTextNode(save && after ? ed.raw.replace(ed.raw.trim(), after) : ed.raw)
1686
1785
  if (ed.span.parentNode) ed.span.parentNode.replaceChild(text, ed.span)
@@ -1689,6 +1788,7 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
1689
1788
 
1690
1789
  function onEditKey(e) {
1691
1790
  if (!textEdit) return
1791
+ if (e.isComposing || e.keyCode === 229) return // 输入法还在选字:回车选词、Esc 取消组字都归输入法,别提前保存 / 丢掉这次改字
1692
1792
  if (editing) {
1693
1793
  if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); finishEdit(true) }
1694
1794
  else if (e.key === 'Escape') { e.preventDefault(); finishEdit(false) }
@@ -1697,7 +1797,8 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
1697
1797
  if (e.key === 'Escape') { e.preventDefault(); post({ type: 'editDone' }) }
1698
1798
  }
1699
1799
 
1700
- function setTextEdit(on, hint = true) {
1800
+ function setTextEdit(on, hint = true, lang) {
1801
+ if (lang) editLang = lang === 'en' ? 'en' : 'zh'
1701
1802
  if (on === textEdit) return
1702
1803
  if (on && styleOn) setStyleMode(false)
1703
1804
  textEdit = on
@@ -1707,12 +1808,14 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
1707
1808
  addEventListener('mousemove', onEditMove, true)
1708
1809
  addEventListener('click', onEditClick, true)
1709
1810
  addEventListener('keydown', onEditKey, true)
1811
+ addEventListener('scroll', onEditScroll, true)
1710
1812
  } else {
1711
1813
  finishEdit(true)
1712
1814
  document.documentElement.style.removeProperty('cursor')
1713
1815
  removeEventListener('mousemove', onEditMove, true)
1714
1816
  removeEventListener('click', onEditClick, true)
1715
1817
  removeEventListener('keydown', onEditKey, true)
1818
+ removeEventListener('scroll', onEditScroll, true)
1716
1819
  editUnmount()
1717
1820
  }
1718
1821
  }
@@ -5512,7 +5615,7 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
5512
5615
  else if (d.type === 'annotHit') hitAnnot(Number(d.x), Number(d.y))
5513
5616
  else if (d.type === 'theme') { setDark(d.dark); postTop(); setTimeout(postTop, 400) }
5514
5617
  else if (d.type === 'demo') demo = !!d.on
5515
- else if (d.type === 'edit') setTextEdit(!!d.on, d.hint !== false)
5618
+ else if (d.type === 'edit') setTextEdit(!!d.on, d.hint !== false, d.lang)
5516
5619
  else if (d.type === 'styleMode') setStyleMode(!!d.on)
5517
5620
  else if (d.type === 'styleSel') onStyleSel(d.selector)
5518
5621
  else if (d.type === 'style') { styleApply(d.css); queueTop() }
package/lib/serve.js CHANGED
@@ -185,8 +185,9 @@ function send(res, code, body, headers = {}) {
185
185
  res.end(body)
186
186
  }
187
187
 
188
- function errorPage(title, detail, retry) {
189
- return injectPicker(`<!doctype html><html><head><meta charset="utf-8">${retry ? '<meta http-equiv="refresh" content="2">' : ''}
188
+ // code:missing(文件没了)/ down(开发服务器连不上);页面里的设计台脚本报给右侧栏,那一屏换成出错卡(重试 / 让模型改)
189
+ function errorPage(title, detail, retry, code) {
190
+ return injectPicker(`<!doctype html><html><head><meta charset="utf-8"><meta name="dsh-error" content="${code || 'missing'}">${retry ? '<meta http-equiv="refresh" content="2">' : ''}
190
191
  <title>${title}</title><style>
191
192
  html,body{height:100%;margin:0}body{display:flex;align-items:center;justify-content:center;font:14px/1.6 -apple-system,system-ui,sans-serif;color:#8a8f98;background:transparent}
192
193
  div{text-align:center;max-width:360px;padding:24px}b{display:block;color:#c9ccd2;font-weight:500;margin-bottom:4px}
@@ -458,7 +459,7 @@ export function createHub({ log = () => {}, onChange = () => {}, onWatch = () =>
458
459
  }
459
460
  }
460
461
  if (!file) {
461
- const html = errorPage('找不到这个文件', String(pathname).replace(/[<>&]/g, ''), false)
462
+ const html = errorPage('找不到这个文件', String(pathname).replace(/[<>&]/g, ''), false, 'missing')
462
463
  return send(res, 404, html, { 'Content-Type': 'text/html; charset=utf-8' })
463
464
  }
464
465
  const ext = path.extname(file).toLowerCase()
@@ -642,7 +643,7 @@ export function createHub({ log = () => {}, onChange = () => {}, onWatch = () =>
642
643
  if (gone) return
643
644
  entry.upHost = ''
644
645
  if (res.headersSent) return res.destroy()
645
- const html = errorPage(`连不上 localhost:${entry.port}`, '开发服务器可能还没启动,起来后这里会自动刷新。', true)
646
+ const html = errorPage(`连不上 localhost:${entry.port}`, '开发服务器可能还没启动,起来后这里会自动刷新。', true, 'down')
646
647
  send(res, 502, html, { 'Content-Type': 'text/html; charset=utf-8' })
647
648
  })
648
649
  req.pipe(up)