dsh-design-studio 0.15.0 → 0.16.1

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 CHANGED
@@ -47,6 +47,7 @@ If DSH can't reach the npm registry, it falls back to a mirror in China. To upda
47
47
  - **Your brand, and real code:** give a site URL to extract a brand design system and design with it from then on; turn a finished design into React / Vue / HTML (mini programs straight into uni-app or native WeChat code, HBuilderX projects included), compared screen by screen against the design.
48
48
 
49
49
  See [all features](https://github.com/OrderG-X/dsh-design-studio/blob/main/docs/features.md) for every feature, the tool parameters and the security design, and [development](https://github.com/OrderG-X/dsh-design-studio/blob/main/docs/development.md) for dev setup and tests.
50
+ - **Built-in photo library:** for designs that rely on photos (hotels, food, cafes, fitness, beauty, fashion, education, travel), the model uses real-looking photos instead of only drawing illustrations. About 8 MB is downloaded the first time it is needed. All of them are AI-generated placeholders, so replace them with real photos before launch.
50
51
 
51
52
  ## Feedback
52
53
 
package/README.md CHANGED
@@ -47,6 +47,7 @@
47
47
  - **照品牌风格做、转成代码**:给官网地址,提一套品牌设计系统,以后都照它做;做好的设计转成 React / Vue / HTML,小程序直接转成 uni-app 或原生小程序代码(HBuilderX 建的项目也认得出),逐屏和设计稿比对。
48
48
 
49
49
  全部功能、工具参数和安全设计见[完整功能](https://github.com/OrderG-X/dsh-design-studio/blob/main/docs/功能详解.md);开发和测试见[开发说明](https://github.com/OrderG-X/dsh-design-studio/blob/main/docs/开发.md)。
50
+ - **自带照片库**:民宿酒店、餐饮、奶茶咖啡、健身、美妆、服饰、教育、旅行风景这些靠照片说话的设计,模型会直接用上照片,不再只画插画。第一次用到时下载约 8 MB。都是 AI 生成的示意图,上线前请换成真实照片。
50
51
 
51
52
  ## 反馈
52
53
 
package/lib/browser.js CHANGED
@@ -13,6 +13,7 @@ import { spawn, execFile } from 'node:child_process'
13
13
 
14
14
  const IDLE_MS = 90000 // 闲置多久关掉
15
15
  const CALL_MS = 30000 // 一条指令最多等多久
16
+ const CLOSE_MS = 600 // 让浏览器自己关,最多等多久再强杀
16
17
  const LOAD_MS = 15000 // 页面载入最多等多久(到点照样往下走:有个图一直载不完也能量)
17
18
  const MAX_PAGES = 3 // 同时开几个页面
18
19
  const MAX_PSEUDO = 1500 // 伪元素最多问几个宿主的框(多了只问靠后的:底栏一般写在最后)
@@ -69,6 +70,7 @@ function sweep(dir = os.tmpdir(), now = Date.now()) {
69
70
  export function createBrowser({ bin = findBrowser(), log = () => {}, idleMs = IDLE_MS, launch = spawn, platform = process.platform } = {}) {
70
71
  let proc = null
71
72
  let starting = null
73
+ let closing = null // 正在等浏览器自己退出
72
74
  let dir = ''
73
75
  let seq = 0
74
76
  let open = 0
@@ -151,6 +153,7 @@ export function createBrowser({ bin = findBrowser(), log = () => {}, idleMs = ID
151
153
  }
152
154
 
153
155
  async function start() {
156
+ if (closing) await closing // 上一个还在关:等它退了再开,别往快关掉的浏览器发命令
154
157
  if (proc) return
155
158
  if (starting) return starting
156
159
  if (!bin) throw new Error('no-browser')
@@ -181,15 +184,23 @@ export function createBrowser({ bin = findBrowser(), log = () => {}, idleMs = ID
181
184
  function stop() {
182
185
  clearTimeout(idle)
183
186
  const p = proc
184
- if (!p) return
185
- try { p.stdio[3].end() } catch { /* 已经断了 */ }
187
+ if (!p || closing) return
188
+ // 等它真退出:这段时间来的新任务不能接着用这条快断的管道
189
+ let done
190
+ closing = new Promise((r) => { done = r })
191
+ const kill = setTimeout(() => { try { p.kill('SIGKILL') } catch { /* 已经退了 */ } }, platform === 'win32' ? CLOSE_MS * 5 : CLOSE_MS)
192
+ p.once('exit', () => { clearTimeout(kill); closing = null; done() })
186
193
  if (platform === 'win32') {
194
+ try { p.stdio[3].end() } catch { /* 已经断了 */ }
187
195
  execFile('taskkill', ['/pid', String(p.pid), '/T', '/F'], (err) => {
188
196
  if (!err) return
189
197
  log(err)
190
198
  try { p.kill() } catch { /* 已经退了 */ }
191
199
  })
192
- } else { try { p.kill('SIGKILL') } catch { /* 已经退了 */ } }
200
+ return
201
+ }
202
+ // 先让它自己关:系统临时目录里的 com.google.Chrome.XXXXXX 只有它自己删得掉,强杀就留下了。等一会儿还没退再杀
203
+ try { p.stdio[3].write(`${JSON.stringify({ id: ++seq, method: 'Browser.close' })}\0`); p.stdio[3].end() } catch { /* 已经断了 */ }
193
204
  }
194
205
 
195
206
  /** 插件停用:关掉浏览器,排队等页面的都失败,之后再也不开 */
package/lib/client.js CHANGED
@@ -193,8 +193,11 @@ window.__ModuleLoader__.load({
193
193
  xoOver: '{n} 个页面比画幅大,会被裁',
194
194
  xoLong: '{n} 个页面是长页,只会截首屏',
195
195
  xoLongPpt: '{n} 个页面是长页,PPT 只会截首屏',
196
+ xoMoved: '{n} 个页面现在不在页顶,只会截现在看到的这一段',
197
+ xoMovedPpt: '{n} 个页面现在不在页顶,PPT 只会截现在看到的这一段',
196
198
  xoLongH: '{n} 个页面比指定高度长,下面会被裁',
197
199
  xoDead: '{n} 个链接点了可能没反应',
200
+ xoAi: '用了 {n} 张 AI 示意图,上线前记得换成真实照片',
198
201
  xoFail: '{n} 屏没量到,结果可能不全',
199
202
  xoAgain: '重新检查',
200
203
  xoGone: '设计换了,这次导出取消了',
@@ -497,6 +500,7 @@ window.__ModuleLoader__.load({
497
500
  dMore: '版本、在手机上看、刷新、在浏览器里打开',
498
501
  dZoom: '按住 {mod} 滚动也能缩放',
499
502
  dScreen: '换一屏、看全部、多尺寸、换类型',
503
+ dCanvas: '回到画布,看全部的屏',
500
504
  toolsT: '工具',
501
505
  editAddr: '换一个地址',
502
506
  textShort: '改字',
@@ -567,6 +571,7 @@ window.__ModuleLoader__.load({
567
571
  stBrand: '正在提取品牌',
568
572
  stCode: '正在转成代码',
569
573
  stCompare: '正在逐像素对比',
574
+ stPhotos: '正在挑照片',
570
575
  stShell: '正在跑命令',
571
576
  stRead: '正在看文件',
572
577
  stWeb: '正在查资料',
@@ -998,8 +1003,11 @@ window.__ModuleLoader__.load({
998
1003
  xoOver: '{n} page(s) are larger than the canvas and will be cut off',
999
1004
  xoLong: '{n} long page(s): only the first screen is captured',
1000
1005
  xoLongPpt: '{n} long page(s): the PPT only captures the first screen',
1006
+ xoMoved: '{n} page(s) are scrolled away from the top: only what is showing now is captured',
1007
+ xoMovedPpt: '{n} page(s) are scrolled away from the top: the PPT only captures what is showing now',
1001
1008
  xoLongH: '{n} page(s) are taller than the set height and will be cut off',
1002
1009
  xoDead: '{n} link(s) may do nothing when clicked',
1010
+ xoAi: 'Uses {n} AI placeholder photo(s). Replace them with real photos before launch',
1003
1011
  xoFail: '{n} screen(s) could not be measured, so this may be incomplete',
1004
1012
  xoAgain: 'Check again',
1005
1013
  xoGone: 'The design changed, so this export was cancelled',
@@ -1301,6 +1309,7 @@ window.__ModuleLoader__.load({
1301
1309
  dMore: 'Versions, view on phone, refresh, open in browser',
1302
1310
  dZoom: 'Hold {mod} and scroll to zoom too',
1303
1311
  dScreen: 'Switch screens, see all, sizes or type',
1312
+ dCanvas: 'Back to the canvas to see every screen',
1304
1313
  toolsT: 'Tools',
1305
1314
  editAddr: 'Change address',
1306
1315
  textShort: 'Text',
@@ -1371,6 +1380,7 @@ window.__ModuleLoader__.load({
1371
1380
  stBrand: 'Extracting the brand',
1372
1381
  stCode: 'Turning it into code',
1373
1382
  stCompare: 'Comparing pixel by pixel',
1383
+ stPhotos: 'Picking photos',
1374
1384
  stShell: 'Running a command',
1375
1385
  stRead: 'Reading files',
1376
1386
  stWeb: 'Looking things up',
@@ -2263,6 +2273,10 @@ window.__ModuleLoader__.load({
2263
2273
  .ddp-demo .lay.out.b{transform:translateX(12%)}
2264
2274
  .ddp-banner{position:absolute;left:50%;top:10px;transform:translateX(-50%);z-index:6;display:flex;align-items:center;gap:6px;max-width:calc(100% - 20px);padding:4px 4px 4px 12px;border-radius:999px;
2265
2275
  background:var(--dsw-alias-bg-layer-1);box-shadow:0 8px 24px rgba(0,0,0,.18),0 0 0 .5px var(--dsw-alias-border-l3);font-size:12px;white-space:nowrap;animation:ddp-in .2s ${EASE}}
2276
+ .ddp-banner.side{left:calc((100% - 296px) / 2);max-width:calc(100% - 320px)}
2277
+ .ddp-banner.side>em{display:none}
2278
+ .ddp-stage.isl:has(>.ddp-banner:not(.side))>.ddp-tokens{top:100px;max-height:calc(100% - 100px - 74px)}
2279
+ .ddp-stage.isl.bz:has(>.ddp-banner:not(.side))>.ddp-tokens{top:142px;max-height:calc(100% - 142px - 74px)}
2266
2280
  .ddp-banner>svg{width:14px;height:14px;flex:none;color:${ACCENT}}
2267
2281
  .ddp-banner>span{overflow:hidden;text-overflow:ellipsis;min-width:0;margin-right:2px}
2268
2282
  /* 试用横幅:「试用中」蓝字、屏名正文、提示淡;窄了先收提示 */
@@ -2563,6 +2577,8 @@ window.__ModuleLoader__.load({
2563
2577
 
2564
2578
  .ddp-libwrap>.ddp-toast{z-index:3}
2565
2579
  /* 浮块窄了:先截屏名,到 440 再收按钮上的字,400 收工具坞里的演示(演示时横幅上能退出) */
2580
+ @container (max-width:560px){.ddp-top>.tl .lab .lb{display:none}.ddp-top>.tl .ddp-btn.lab{padding:0 6px}}
2581
+ @container (max-width:490px){.ddp-top .lab .lb,.ddp-top .pri .lb{display:none}.ddp-top .ddp-btn.lab{padding:0 6px}}
2566
2582
  @container (max-width:440px){.ddp-isl .lab .lb,.ddp-isl .pri .lb{display:none}.ddp-isl .ddp-btn.lab{padding:0 6px}.ddp-tool{width:36px;height:36px}.ddp-tool span{display:none}.ddp-dock .ddp-sep{height:20px}}
2567
2583
  @container (max-width:380px){.ddp-tool{width:32px}.ddp-kind.ddp-where{min-width:64px}}
2568
2584
  /* 标注底栏:右侧栏窄时「这支笔怎么用」折成两行,不被三个按钮挤成省略号 */
@@ -4811,7 +4827,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
4811
4827
  // 模型在做什么:按它调的工具说人话(写文件另算,见 busyPhase)
4812
4828
  const TOOL_PHASE = [
4813
4829
  [/^check_design$/, 'stCheck'], [/^look_design$/, 'stLook'], [/^preview_page$/, 'stPreview'], [/^extract_design_system$/, 'stBrand'],
4814
- [/^handoff_design$/, 'stCode'], [/^compare_design$/, 'stCompare'], [/^ask_user_question$/, 'asking'],
4830
+ [/^handoff_design$/, 'stCode'], [/^compare_design$/, 'stCompare'], [/^find_photos$/, 'stPhotos'], [/^ask_user_question$/, 'asking'],
4815
4831
  [/^(bash|shell|sh|zsh|powershell|pwsh|exec|run_command|terminal)$/i, 'stShell'],
4816
4832
  [/^skill$/i, 'stSkill'],
4817
4833
  [/web|fetch|browse|http/i, 'stWeb'],
@@ -5193,6 +5209,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
5193
5209
  checkFocus: (i) => { if (curRef.current) postTo(curRef.current, { type: 'checkFocus', i }) },
5194
5210
  checkClear: () => { if (curRef.current) postTo(curRef.current, { type: 'checkClear' }) },
5195
5211
  unpin: () => { if (curRef.current) postTo(curRef.current, { type: 'unpin' }) }, // 去掉「已选」虚线框
5212
+ holdScroll: () => { if (curRef.current) postTo(curRef.current, { type: 'holdScroll' }) }, // 用户要在这个位置上画:闪改动别再滚回去
5196
5213
  // 画笔标注:这一屏的页面(iframe)现在摆在哪,拼图时按它的位置放截图
5197
5214
  frame: () => wins.current.get(curRef.current) || null,
5198
5215
  }
@@ -7230,12 +7247,12 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7230
7247
  */
7231
7248
  function precheckOf(list, kind, limit) {
7232
7249
  const fixed = kind === 'slides' || kind === 'poster'
7233
- const r = { over: 0, long: 0, dead: 0, fail: 0 }
7250
+ const r = { over: 0, long: 0, moved: 0, dead: 0, fail: 0, ai: new Set(list.flatMap((m) => (Array.isArray(m.aiPhotos) ? m.aiPhotos : []))).size }
7234
7251
  for (const m of list) {
7235
7252
  if (m.failed) { r.fail++; continue }
7236
7253
  const tall = m.pageH > (limit || m.h) + 2
7237
7254
  if (m.pageW > m.w + 2 || (fixed && tall)) r.over++
7238
- if (!fixed && tall) r.long++
7255
+ if (!fixed && tall) { if (!limit && (m.sy || 0) > 1) r.moved++; else r.long++ } // 一屏:滚过的截的是现在这段,不是首屏
7239
7256
  const from = limit ? 0 : m.sy || 0 // 一屏:只看现在看得到的那段
7240
7257
  const to = limit || from + m.h
7241
7258
  r.dead += (Array.isArray(m.dead) ? m.dead : []).filter((y) => y >= from && y < to).length
@@ -7285,8 +7302,9 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7285
7302
  const limit = opts.fit === 'page' ? Infinity : opts.fit === 'height' && fitHOk(opts.fitH) ? +opts.fitH : 0
7286
7303
  const rep = list ? precheckOf(list, kind, limit) : null
7287
7304
  const canFit = list ? fitCanvas(list, kind, size) : ''
7288
- const cut = rep && (rep.over || rep.long)
7305
+ const cut = rep && (rep.over || rep.long || rep.moved)
7289
7306
  const longKey = opts.fit === 'height' ? 'xoLongH' : !opts.fit && (kind === 'web' || kind === 'email') ? 'xoLongPpt' : 'xoLong'
7307
+ const movedKey = !opts.fit && (kind === 'web' || kind === 'email') ? 'xoMovedPpt' : 'xoMoved'
7290
7308
  const seg = (k, items) => h('div', { className: 'seg', role: 'radiogroup' }, ...items.map(([v, label]) => h('button', { key: String(v), type: 'button', role: 'radio', 'aria-checked': opts[k] === v, className: opts[k] === v ? 'on' : '', onClick: () => setOpts({ ...opts, [k]: v }) }, label)))
7291
7309
  const bad = (opts.layout === 'custom' && !layoutOk(opts.custom)) || (opts.fit === 'height' && !fitHOk(opts.fitH))
7292
7310
  const go = async (format) => {
@@ -7300,11 +7318,13 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7300
7318
  !rep ? h('div', { className: 'chk' }, h('p', null, t('xoChecking'))) : h('div', { className: 'chk' + (cut ? ' warn' : '') },
7301
7319
  rep.over ? h('p', null, t('xoOver', { n: rep.over })) : null,
7302
7320
  rep.long ? h('p', null, t(longKey, { n: rep.long })) : null,
7321
+ rep.moved ? h('p', null, t(movedKey, { n: rep.moved })) : null,
7303
7322
  rep.dead ? h('p', null, t('xoDead', { n: rep.dead })) : null,
7323
+ rep.ai ? h('p', null, t('xoAi', { n: rep.ai })) : null,
7304
7324
  rep.fail ? h('p', null, t('xoFail', { n: rep.fail })) : null,
7305
7325
  !cut && !rep.dead && !rep.fail ? h('p', null, t('xoClean')) : null,
7306
7326
  rep.over && canFit ? h('button', { className: 'lk', onClick: () => onResize(canFit) }, t('xoResize', { size: canFit.replace('x', '×') })) : null,
7307
- rep.long && opts.fit !== 'page' ? h('button', { className: 'lk', onClick: () => setOpts({ ...opts, fit: 'page' }) }, t('xoFull')) : null,
7327
+ (rep.long || rep.moved) && opts.fit !== 'page' ? h('button', { className: 'lk', onClick: () => setOpts({ ...opts, fit: 'page' }) }, t('xoFull')) : null,
7308
7328
  h('button', { className: 'lk', onClick: () => setAgain((n) => n + 1) }, t('xoAgain'))),
7309
7329
  h('h4', null, t('xoLayout')),
7310
7330
  seg('layout', [['auto', t('xoAuto')], ['16:9', '16:9'], ['4:3', '4:3'], ['a3', t('xoA3')], ['custom', t('xoCustom')]]),
@@ -7333,6 +7353,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7333
7353
  if (name) { try { localStorage.setItem('ddp-author', name) } catch { /* 不记也行 */ } }
7334
7354
  try { setRes(await post('pack', { session: sid, dir: root, license: lic, author: name, lang: t('lang') === 'en' ? 'en' : 'zh' })) } catch (e) { setRes({ error: e.message }) } finally { setBusy(false) }
7335
7355
  }
7356
+ const aiN = (res && res.aiPhotos) || 0
7336
7357
  const fixed = res && res.notes ? Object.entries(res.notes.reduce((m, n) => { m[n.code] = (m[n.code] || 0) + 1; return m }, {})).map(([k, n]) => t('pkNote_' + k, { n })).join(t('sep')) : ''
7337
7358
  return h('div', { className: 'ddp-tokens ddp-pack', onPointerDown: (e) => e.stopPropagation() },
7338
7359
  h('header', null, h(I.download), h('b', null, t('pkTitle')), h('button', { className: 'ddp-btn', title: '×', onClick: onClose }, h(I.close))),
@@ -7353,6 +7374,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7353
7374
  h('ol', null, ...res.errors.slice(0, 30).map((e, i) => h('li', { key: i }, e.msg))),
7354
7375
  res.errors.length > 30 || res.more ? h('p', null, t('pkMore', { n: res.errors.length - 30 + (res.more || 0) })) : null) : null,
7355
7376
  fixed ? h('p', { className: 'note' }, t('pkFixed', { list: fixed })) : null,
7377
+ aiN ? h('p', { className: 'note' }, t('xoAi', { n: aiN })) : null,
7356
7378
  res && res.flags && res.flags.length ? h('div', { className: 'note' }, t('pkFlags'), h('ul', null, ...res.flags.slice(0, 8).map((f, i) => h('li', { key: i }, f.msg))),
7357
7379
  res.flags.length > 8 || res.flagsMore ? h('p', null, t('pkMore', { n: res.flags.length - 8 + (res.flagsMore || 0) })) : null) : null,
7358
7380
  res && res.skipped && res.skipped.length ? h('p', { className: 'note' }, t('pkSkipped', { list: res.skipped.slice(0, 8).join(t('sep')) + (res.skipped.length > 8 ? '…' : '') })) : null),
@@ -7400,6 +7422,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7400
7422
  if (r.share.slug) q.set('slug', r.share.slug)
7401
7423
  return `${GALLERY_REPO}/issues/new?${q}`
7402
7424
  }
7425
+ const aiN = (res && res.aiPhotos) || 0
7403
7426
  const fixed = res && res.notes ? Object.entries(res.notes.reduce((m, n) => { m[n.code] = (m[n.code] || 0) + 1; return m }, {})).map(([k, n]) => t('pkNote_' + k, { n })).join(t('sep')) : ''
7404
7427
  const done = res && res.ok && res.share
7405
7428
  return h('div', { className: 'ddp-tokens ddp-pack ddp-share', onPointerDown: (e) => e.stopPropagation() },
@@ -7435,6 +7458,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7435
7458
  h('ol', null, ...res.errors.slice(0, 30).map((e, i) => h('li', { key: i }, e.msg))),
7436
7459
  res.errors.length > 30 || res.more ? h('p', null, t('pkMore', { n: res.errors.length - 30 + (res.more || 0) })) : null) : null,
7437
7460
  fixed ? h('p', { className: 'note' }, t('pkFixed', { list: fixed })) : null,
7461
+ aiN ? h('p', { className: 'note' }, t('xoAi', { n: aiN })) : null,
7438
7462
  res && res.flags && res.flags.length ? h('div', { className: 'note' }, t('pkFlags'), h('ul', null, ...res.flags.slice(0, 8).map((f, i) => h('li', { key: i }, f.msg))),
7439
7463
  res.flags.length > 8 || res.flagsMore ? h('p', null, t('pkMore', { n: res.flags.length - 8 + (res.flagsMore || 0) })) : null) : null),
7440
7464
  h('footer', { className: 'row' },
@@ -8518,21 +8542,24 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
8518
8542
  if (!api) throw new Error('not loaded')
8519
8543
  return api
8520
8544
  }
8521
- const captureOf = async (sc, full, map, maxH) => {
8545
+ // 这次导出截到的 AI 示意图(文件名去重):每种导出结束的提示里都带一句「上线前换成真实照片」
8546
+ const aiTail = (ai) => (ai && ai.size ? ' · ' + t('xoAi', { n: ai.size }) : '')
8547
+ const captureOf = async (sc, full, map, maxH, ai) => {
8522
8548
  const api = await apiOf(sc, map)
8523
8549
  const r = await api.capture({ full: !!full, scale: 2, ...(maxH ? { maxH } : {}) })
8550
+ if (ai && Array.isArray(r.aiPhotos)) for (const x of r.aiPhotos) ai.add(x)
8524
8551
  return { img: await loadImg(r.png), w: r.w, h: r.h, links: Array.isArray(r.links) ? r.links : [], top: typeof r.top === 'boolean' ? r.top : null, title: String(r.title || '').trim() }
8525
8552
  }
8526
8553
  // 导出用的标题:屏多的时候有的屏没在画布上挂过,手上没有它的标题,用截图时页面报的
8527
8554
  const exportTitle = (sc, r) => (infoOf(ik(sc)) || {}).title || r.title || sc.label
8528
8555
 
8529
8556
  const targetKey = st && st.target ? (st.target.kind === 'file' ? `file|${st.target.root}` : `proxy|${st.target.port}`) : ''
8530
- const saveImage = async (name, blob) => {
8557
+ const saveImage = async (name, blob, ai) => {
8531
8558
  const png = await blobB64(blob)
8532
8559
  const r = await post('export', { session: sid, name, png, target: targetKey })
8533
8560
  const copied = await copyImage(blob)
8534
8561
  const file = String(r.path || '').split(/[\\/]/).pop()
8535
- say(t(copied ? 'exportedCopied' : 'exported', { name: file }), { label: t('reveal'), run: () => post('reveal', { path: r.path }).catch(() => {}) })
8562
+ say(t(copied ? 'exportedCopied' : 'exported', { name: file }) + aiTail(ai), { label: t('reveal'), run: () => post('reveal', { path: r.path }).catch(() => {}) })
8536
8563
  }
8537
8564
 
8538
8565
  const designId = JSON.stringify([sid, targetKey, ver ? ver.n : 0])
@@ -8585,6 +8612,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
8585
8612
  const design = designNow.current
8586
8613
  const stamp = designSeq.current
8587
8614
  const gone = () => designSeq.current !== stamp
8615
+ const aiShot = new Set() // 这次导出截到的 AI 示意图(每次导出各记各的,连着导出不串)
8588
8616
  try {
8589
8617
  const prefix = ver ? `v${ver.n}-` : ''
8590
8618
  const suffix = dark ? '-dark' : ''
@@ -8600,7 +8628,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
8600
8628
  const seen = await measureAll(map)
8601
8629
  const rep = precheckOf(seen, kind, long ? Infinity : 0)
8602
8630
  deadN = rep.dead
8603
- const sig = rep.over || rep.long ? [design, shown.map(ik).join(','), size.join('x'), long ? 1 : 0, seen.map((m) => (m.failed ? '-' : `${m.pageW}x${m.pageH}`)).join(',')].join('|') : ''
8631
+ const sig = rep.over || rep.long || rep.moved ? [design, shown.map(ik).join(','), size.join('x'), long ? 1 : 0, seen.map((m) => (m.failed ? '-' : `${m.pageW}x${m.pageH}`)).join(',')].join('|') : ''
8604
8632
  if (sig && warned.current !== sig) {
8605
8633
  warned.current = sig
8606
8634
  say(t('xoWarn'))
@@ -8613,7 +8641,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
8613
8641
  for (const sc of shown) {
8614
8642
  if (gone()) break
8615
8643
  try {
8616
- const r = await captureOf(sc, long, map, maxH)
8644
+ const r = await captureOf(sc, long, map, maxH, aiShot)
8617
8645
  const cut = maxH && r.h > maxH
8618
8646
  pages.push({ jpg: await jpegB64(cut ? cropImg(r.img, r.h, maxH) : r.img), w: r.w, h: cut ? maxH : r.h, title: exportTitle(sc, r), links: r.links })
8619
8647
  keys.push(sc.key)
@@ -8634,7 +8662,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
8634
8662
  const file = String(r.path || '').split(/[\\/]/).pop()
8635
8663
  const miss = shown.length - pages.length
8636
8664
  const sheets = Math.ceil(pages.length / cols)
8637
- say((miss ? t('exportedDocMiss', { name: file, n: sheets, miss }) : t('exportedDoc', { name: file, n: sheets })) + (deadN ? ' · ' + t('xoDead', { n: deadN }) : ''), { label: t('reveal'), run: () => post('reveal', { path: r.path }).catch(() => {}) })
8665
+ say((miss ? t('exportedDocMiss', { name: file, n: sheets, miss }) : t('exportedDoc', { name: file, n: sheets })) + (deadN ? ' · ' + t('xoDead', { n: deadN }) : '') + aiTail(aiShot), { label: t('reveal'), run: () => post('reveal', { path: r.path }).catch(() => {}) })
8638
8666
  })
8639
8667
  return
8640
8668
  }
@@ -8643,7 +8671,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
8643
8671
  await withFrames(async (map) => {
8644
8672
  for (const sc of shown) {
8645
8673
  if (gone()) break
8646
- try { const c = await captureOf(sc, false, map); shots.push({ img: c.img, top: c.top, title: exportTitle(sc, c) }) } catch (e) { console.warn('[dsh-design-studio] 截图失败', sc.key, e) }
8674
+ try { const c = await captureOf(sc, false, map, 0, aiShot); shots.push({ img: c.img, top: c.top, title: exportTitle(sc, c) }) } catch (e) { console.warn('[dsh-design-studio] 截图失败', sc.key, e) }
8647
8675
  }
8648
8676
  })
8649
8677
  if (gone()) { say(t('xoGone')); return }
@@ -8661,7 +8689,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
8661
8689
  accent: colors.accent || ACCENT,
8662
8690
  mark: t('madeWith'),
8663
8691
  })
8664
- await saveImage(prefix + (sp.brand || 'showcase') + suffix, blob)
8692
+ await saveImage(prefix + (sp.brand || 'showcase') + suffix, blob, aiShot)
8665
8693
  return
8666
8694
  }
8667
8695
  const k = key || (canvas ? sel || focus : focus)
@@ -8670,17 +8698,17 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
8670
8698
  const base = prefix + sc.key.replace(/\.html?$/i, '') + suffix
8671
8699
  // 画布屏多的时候这屏可能没挂着(镜头一动也可能撤掉):在背后单独挂一份来截
8672
8700
  let shot = null
8673
- if (canvas && shown.length > LIVE_MAX) await withFrames(async (map) => { shot = await captureOf(sc, mode === 'long', map) }, [sc])
8674
- else shot = await captureOf(sc, mode === 'long')
8701
+ if (canvas && shown.length > LIVE_MAX) await withFrames(async (map) => { shot = await captureOf(sc, mode === 'long', map, 0, aiShot) }, [sc])
8702
+ else shot = await captureOf(sc, mode === 'long', undefined, 0, aiShot)
8675
8703
  if (gone()) { say(t('xoGone')); return }
8676
8704
  const { img, top } = shot
8677
- if (mode === 'frame') await saveImage(base, await composeOne(kind, size, img, labelOf(sc), top, meta.os))
8705
+ if (mode === 'frame') await saveImage(base, await composeOne(kind, size, img, labelOf(sc), top, meta.os), aiShot)
8678
8706
  else {
8679
8707
  const c = document.createElement('canvas')
8680
8708
  c.width = img.width
8681
8709
  c.height = img.height
8682
8710
  c.getContext('2d').drawImage(img, 0, 0)
8683
- await saveImage(base + (mode === 'long' ? '-full' : ''), await canvasBlob(c))
8711
+ await saveImage(base + (mode === 'long' ? '-full' : mode === 'raw' && FRAMED[kind] ? '-plain' : ''), await canvasBlob(c), aiShot)
8684
8712
  }
8685
8713
  } catch (e) {
8686
8714
  say(e.message === 'designChanged' ? t('xoGone') : t('exportFail', { msg: e.message }))
@@ -8860,7 +8888,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
8860
8888
  closeCheck()
8861
8889
  setPane('')
8862
8890
  // 之前点选 / 调样式留下的「已选」框别夹在标注里
8863
- for (const a of apis.current.values()) if (a && a.unpin) a.unpin()
8891
+ for (const a of apis.current.values()) { if (a && a.unpin) a.unpin(); if (a && a.holdScroll) a.holdScroll() }
8864
8892
  setMarkSize(box.w && box.h > TOP_R + BOT_R ? { w: box.w, h: box.h - TOP_R - BOT_R } : null)
8865
8893
  setMark(true)
8866
8894
  }
@@ -9142,6 +9170,8 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
9142
9170
  const exSc = shown.find((x) => x.key === (canvas ? sel || focus : focus)) || shown[0]
9143
9171
  const exName = exSc ? dropBrand(shortOf(exSc)) + (takeTag(exSc) ? ' · ' + takeTag(exSc) : '') : ''
9144
9172
  const libOpen = () => { setLibFocus(''); if (lib) setLib(''); else libDefaultThen((k) => setLib((c) => c || k)) }
9173
+ const onCanvas = canvas && !inMulti && !demo && homeAt !== 'on' && !(ver && cmp)
9174
+ const toCanvas = () => { homeAway(); setMulti(false); setCmp(false); if (demo) setDemo(null); change({ view: 'canvas' }) }
9145
9175
  const dockTight = box.w > 0 && box.w <= 400 // 侧栏很窄:底部工具坞只放得下四个,「试用」进「更多」
9146
9176
  const tool = (cls, on, desc, off, run, Icon, label) => h('button', { className: 'ddp-tool' + (cls ? ' ' + cls : '') + (on ? ' on' : ''), ...tipA(label, desc, on ? 'Esc' : ''), 'aria-pressed': !!on, disabled: !!off, onClick: run }, h(Icon), h('span', null, label))
9147
9177
  const islands = editing
@@ -9152,9 +9182,10 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
9152
9182
  h('div', { key: 'top', className: 'ddp-top' },
9153
9183
  h('div', { className: 'ddp-isl tl' },
9154
9184
  h('button', { className: 'ddp-btn lab' + (homeAt === 'on' ? ' sel' : ''), ...tipA(t('homeBtn'), t('dHome'), homeAt === 'on' ? 'Esc' : ''), 'aria-pressed': homeAt === 'on', onClick: () => (homeAt === 'on' ? homeClose() : homeOpen()) }, h(I.home), h('span', { className: 'lb' }, t('homeBtn'))),
9185
+ h('button', { className: 'ddp-btn lab' + (onCanvas ? ' sel' : ''), ...tipA(t('canvasShort'), t('dCanvas')), 'aria-pressed': onCanvas, disabled: !url, onClick: toCanvas }, h(I.canvas), h('span', { className: 'lb' }, t('canvasShort'))),
9155
9186
  h('span', { className: 'ddp-sep' }),
9156
9187
  h(ScreenMenu, { t, hidden: hiddenN, hiddenText, label: scrLabel, tip: [scrLabel || stLabel, t('dScreen')], src: stLabel, busy, list: screens.map((x) => { const L = takeTag(x); return { key: x.key, label: dropBrand(shortOf(x)) + (L ? ' · ' + L : '') } }), cur: curKey, canvas: canvas && !inMulti && !demo, open: scrMenu, setOpen: setScrMenu,
9157
- onPick: pickScreen, onAll: () => { setMulti(false); if (demo) setDemo(null); change({ view: 'canvas' }) }, onOther: () => setEditing(true),
9188
+ onPick: pickScreen, onAll: toCanvas, onOther: () => setEditing(true),
9158
9189
  sizes: mark ? null : { on: inMulti, off: !sizeSet || !!ver, tip: sizeSet ? t('sizes') : t('sizesNo'), note: sizeSet ? '' : t('sizesNoShort'), run: () => setMulti(!inMulti) },
9159
9190
  kind, onKind: mark ? null : (k) => change({ kind: k }) })),
9160
9191
  h('div', { className: 'ddp-isl tr' },
@@ -9616,12 +9647,14 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
9616
9647
  const old = now ? { key: now.key, id: `v${ver.n}|${now.key}`, v: ver.n, url: vbase + encodeURIComponent(now.key), label: now.label } : null
9617
9648
  const fill = kind === 'web'
9618
9649
  const [dw, dh] = deviceBox(kind, size)
9619
- const z = fill ? 1 : Math.max(0.05, Math.min(1, (box.w - 32) / dw, (ah - 16 - (ver ? 46 : 0)) / dh))
9650
+ // 右边开着版本面板:手机这类有外框的让到面板左边(和单看时一样)
9651
+ const aside = !fill && !!(ck || styleEdit || panel || pane || hist || phone) && box.w - 296 >= 240 ? 296 : 0
9652
+ const z = fill ? 1 : Math.max(0.05, Math.min(1, (box.w - aside - 32) / dw, (ah - 16 - (ver ? 46 : 0)) / dh))
9620
9653
  // 两边的小标签不跟着画面缩小(缩了看不清);手机、平板躲开状态栏
9621
9654
  const tagAt = (side) => ({ top: kind === 'app' || kind === 'miniprogram' || kind === 'tablet' ? 60 : 10, transform: `scale(${1 / z})`, transformOrigin: 'top ' + side })
9622
9655
  const screenOf = (sc) => h(Screen, { t, remote, onPageDrag: pageDrag, src: sc.url, label: labelOf(sc), busy: false, born: false, picking: false, dark, zoom: z, reloadSeq,
9623
9656
  apis: apis.current, apiKey: 'cmp|' + ik(sc), onMeta: (m, title, toks, dk) => remember(ik(sc), m, title, toks, dk), onTop: (dk) => setTop(ik(sc), dk) })
9624
- body = h('div', { className: 'ddp-single' },
9657
+ body = h('div', { className: 'ddp-single', style: aside ? { right: aside } : undefined },
9625
9658
  h('div', { className: 'ddp-fit' + (fill ? ' fill' : ''), style: fill ? undefined : { width: dw, height: dh, transform: `translate(-50%, -50%) scale(${z})` } },
9626
9659
  // 胶囊那块露的是哪一边(把手拖过胶囊中间就是左边那一版),胶囊就跟哪一边的顶栏
9627
9660
  now ? h(Device, { kind, w: size[0], h: size[1], fill, label: labelOf(now), top: tops[ik(has && (cx / 100) * size[0] > size[0] - CAP.right - CAP.w / 2 ? old : now)], os: meta.os },
@@ -9756,7 +9789,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
9756
9789
  }) : null,
9757
9790
  hist ? h(HistoryPanel, { t, versions, ver, onPick: (v) => { setVer(v); if (!v) setCmp(false) }, onClose: () => setHist(false) }) : null,
9758
9791
  mark && !markOff ? h(MarkLayer, { t, sending: markBusy, frames: markFrames, onCancel: () => { markRun.current++; setMark(false) }, onSend: sendMark, onCopy: canCopyImage() ? copyMark : null }) : null,
9759
- demo ? h('div', { className: 'ddp-banner' },
9792
+ demo ? h('div', { className: 'ddp-banner' + side },
9760
9793
  h(I.play),
9761
9794
  h('b', null, t('demoOn')),
9762
9795
  h('span', { className: 'nm' }, dropBrand((infoOf(demoKey) || {}).title || demoKey.replace(/\.html?$/i, ''))),
@@ -9764,9 +9797,9 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
9764
9797
  h('button', { className: 'ddp-btn', ...tipA(t('demoBack')), disabled: demo.stack.length < 2, onClick: demoBack }, h(I.back)),
9765
9798
  h('button', { className: 'ddp-btn', ...tipA(t('demoRestart')), disabled: demo.stack.length < 2, onClick: demoRestart }, h(I.refresh)),
9766
9799
  h('button', { className: 'ddp-btn', ...tipA(t('demoExit'), '', 'Esc'), onClick: () => setDemo(null) }, h(I.close))) : null,
9767
- ver ? h('div', { className: 'ddp-banner' },
9800
+ ver ? h('div', { className: 'ddp-banner' + side },
9768
9801
  h(I.history),
9769
- h('span', null, t('viewing', { n: ver.n, time: hhmm(ver.at) })),
9802
+ h('span', { title: t('viewing', { n: ver.n, time: hhmm(ver.at) }) }, side ? t('vN', { n: ver.n }) : t('viewing', { n: ver.n, time: hhmm(ver.at) })),
9770
9803
  h('button', { className: 'ddp-go sec' + (cmp ? ' on' : ''), onClick: () => setCmp(!cmp) }, t('compare')),
9771
9804
  h('button', { className: 'ddp-go pri', onClick: doRestore }, t('restore')),
9772
9805
  h('button', { className: 'ddp-btn', title: t('backNow'), onClick: () => { setVer(null); setCmp(false) } }, h(I.close))) : null,
package/lib/core.js CHANGED
@@ -67,8 +67,13 @@ export function parseSize(input) {
67
67
 
68
68
  /** 右侧显示的几屏:超过上限时留最新生成的,最早的先收起来。keep:正打开的那屏,不在里面也留着(挤掉最早的一屏) */
69
69
  export function listScreens(root, keep = '') {
70
- const kept = screensByBirth(root).slice(-MAX_SCREENS)
71
- if (keep && !kept.includes(keep)) { if (kept.length >= MAX_SCREENS) kept.shift(); kept.push(keep) }
70
+ const born = screensByBirth(root)
71
+ let kept = born.slice(-MAX_SCREENS)
72
+ if (keep && !kept.includes(keep)) {
73
+ if (kept.length >= MAX_SCREENS) kept.shift()
74
+ // 按创建顺序放回原位(打开文件夹取的是最早的一屏,别排到最后);不在顶层的(一般不会有)放最后
75
+ kept = born.includes(keep) ? born.filter((x) => x === keep || kept.includes(x)) : [...kept, keep]
76
+ }
72
77
  return inManifestOrder(root, kept)
73
78
  }
74
79
 
@@ -922,6 +927,8 @@ export function createTracker({ open, drafts = null, skipPorts = () => new Set()
922
927
  if (p) settle(sessionId, st, part, absOf(sessionId, p))
923
928
  }
924
929
  }
930
+ // 第一屏的草稿开始流了:右侧栏关着就什么都看不到,弹一次(规矩和模型开了新页面一样,「自动打开预览」关着不弹)
931
+ if (draft && !st.target && autoOpen()) st.openRev++
925
932
  if (draft && !draft.origin) {
926
933
  open({ kind: 'file', file: draft.serve, root }).then((r) => {
927
934
  if (st.draft === draft) draft.origin = r.origin
@@ -281,6 +281,28 @@ export function createMarket({
281
281
  return buf
282
282
  }
283
283
 
284
+ /**
285
+ * 下一个 npm 包,返回 check(文件列表) 的结果(照片库用)。几个源抢着下;check 抛错算这个源失败,接着等别的源。
286
+ * 包内容对不对由调用方按自己钉死的哈希判断,这里不验签名。
287
+ */
288
+ async function fetchPackage(name, want, { cap = MAX.packs, limits, timing: t, check = (x) => x } = {}) {
289
+ if (!online()) throw new MarketError('off')
290
+ let value
291
+ try {
292
+ ({ value } = await race(registries, async (reg, signal) => {
293
+ const info = await lookup(reg, name, want, signal)
294
+ const buf = await download(info, cap, signal)
295
+ return check(untar(buf, limits))
296
+ }, t || timing))
297
+ } catch (e) {
298
+ // 下着下着开了「不联网」:不管几个源各报什么错,都算开关挡的
299
+ if (!online()) throw new MarketError('off')
300
+ throw e
301
+ }
302
+ if (!online()) throw new MarketError('off')
303
+ return value
304
+ }
305
+
284
306
  /** 解析、验签名、查格式和 serial;过了返回 index(不写盘) */
285
307
  function accept(bytes, sig, { floor = state().serial } = {}) {
286
308
  if (!keys.length) throw new MarketError('nokeys')
@@ -619,5 +641,5 @@ export function createMarket({
619
641
  return r === base || r.startsWith(base + path.sep) || r.startsWith(path.resolve(stageDir) + path.sep)
620
642
  }
621
643
 
622
- return { view, refresh, maybeRefresh, abort, entry, thumbFile, stage, shotFile, strictHtml, isStaging, state, url: (e) => e.submission || `${REPO_URL}/tree/main/${e.type === 'system' ? 'systems' : e.type === 'style' ? 'styles' : 'templates'}/${e.id}` }
644
+ return { fetchPackage, view, refresh, maybeRefresh, abort, entry, thumbFile, stage, shotFile, strictHtml, isStaging, state, url: (e) => e.submission || `${REPO_URL}/tree/main/${e.type === 'system' ? 'systems' : e.type === 'style' ? 'styles' : 'templates'}/${e.id}` }
623
645
  }
@@ -10,8 +10,19 @@
10
10
 
11
11
  import fs from 'node:fs'
12
12
  import path from 'node:path'
13
- import { checkPack, normalizeHtml, titleOf, metaKind, message, LIMITS, capsOf, FORMAT, pctBytes, imageInfo } from './policy.js'
13
+ import { cleanPath, checkPack, normalizeHtml, titleOf, metaKind, message, LIMITS, capsOf, FORMAT, pctBytes, imageInfo } from './policy.js'
14
14
  import { writeZip } from './zip.js'
15
+ import { isPhotoAsset } from '../photos.js'
16
+ import { decodeEntities } from './html.js'
17
+
18
+ /** 页面文本 → 去掉注释、解开各种转义、全小写,用来判断提没提到某个文件 */
19
+ function refsFold(s) {
20
+ const t = decodeEntities(s.replace(/<!--[\s\S]*?-->/g, ' ').replace(/\/\*[\s\S]*?\*\//g, ' ')).text
21
+ return t
22
+ .replace(/\\([0-9a-f]{1,6})\s?/gi, (m, h) => { const c = parseInt(h, 16); return c > 0 && c <= 0x10ffff ? String.fromCodePoint(c) : m })
23
+ .replace(/%[0-9a-f]{2}/gi, (m) => { try { return decodeURIComponent(m) } catch { return m } })
24
+ .toLowerCase()
25
+ }
15
26
 
16
27
  const PACK_EXT = /\.(html|css|svg|png|jpe?g|webp|gif|avif|json|md)$/i
17
28
  const SKIP_DIRS = new Set(['refs', 'exports', 'handoff', 'drafts', 'node_modules', 'dist', 'build'])
@@ -276,8 +287,18 @@ export function packDesign(root, { screens, version = '', license = '', author =
276
287
  files.push({ path: f.path, data })
277
288
  }
278
289
  }
290
+ // 自带照片库的图:找图时多拿的、页面没用上的不打包。宁可多带:页面里(解码后)提到这个文件名就留,注释里的不算
291
+ const refText = files.filter((f) => /\.(html|css|svg)$/i.test(f.path)).map((f) => refsFold(Buffer.from(f.data).toString('utf8'))).join('\n')
292
+ const dropped = new Set()
293
+ for (let i = files.length - 1; i >= 0; i--) {
294
+ const f = files[i]
295
+ if (!isPhotoAsset(f.path)) continue
296
+ if (refText.includes(path.posix.basename(f.path).toLowerCase())) notes.push({ code: 'aiPhoto', x: f.path })
297
+ else { skipped.push(f.path); dropped.add(f.path.toLowerCase()); files.splice(i, 1) }
298
+ }
279
299
  const order = screens.filter((s) => htmls.has(s))
280
300
  const manifest = buildManifest({ existing, screens: order, htmls, version, license, author, title, description, shareHash })
301
+ if (dropped.size && Array.isArray(manifest.assets)) manifest.assets = manifest.assets.filter((x) => !(x && typeof x.path === 'string' && dropped.has(String(cleanPath(x.path) || x.path).toLowerCase())))
281
302
  files.unshift({ path: 'design.json', data: Buffer.from(JSON.stringify(manifest, null, 2) + '\n', 'utf8') })
282
303
  const r = checkPack(files, { mode })
283
304
  // 只该留在作者电脑上的东西(分享记号):哪个文件里有都拦
@@ -265,7 +265,7 @@ export function createLibraryRoutes({ admit, readBody, json, tracker, library, i
265
265
  }
266
266
  }
267
267
  flags.sort((a, b) => Number(PERSONAL_CODES.has(b.code)) - Number(PERSONAL_CODES.has(a.code))) // 个人信息的提醒排最前面
268
- const out = { ok: p.ok, errors: p.errors.slice(0, 60), more: Math.max(0, p.errors.length - 60), flags: flags.slice(0, 30), flagsMore: Math.max(0, flags.length - 30), notes: p.notes.slice(0, 60), skipped: p.skipped, bytes: p.bytes, title: p.manifest.title, screens: p.manifest.screens.length }
268
+ const out = { ok: p.ok, errors: p.errors.slice(0, 60), more: Math.max(0, p.errors.length - 60), flags: flags.slice(0, 30), flagsMore: Math.max(0, flags.length - 30), notes: p.notes.filter((x) => x.code !== 'aiPhoto').slice(0, 60), aiPhotos: p.notes.filter((x) => x.code === 'aiPhoto').length, skipped: p.skipped, bytes: p.bytes, title: p.manifest.title, screens: p.manifest.screens.length }
269
269
  if (!p.ok) return json(res, 200, out)
270
270
  try {
271
271
  fs.mkdirSync(downloads, { recursive: true })
package/lib/handoff.js CHANGED
@@ -9,6 +9,7 @@
9
9
  * 回一张「设计稿 | 做出来的 | 差异」拼图、差了多少,和差得最多的几块分别是哪个元素。
10
10
  */
11
11
 
12
+ import { PHOTO_PREFIX, isPhotoAsset } from './photos.js'
12
13
  import fs from 'node:fs'
13
14
  import os from 'node:os'
14
15
  import path from 'node:path'
@@ -179,6 +180,23 @@ export function within(p, root) {
179
180
  return a === b || a.startsWith(b.endsWith(path.sep) ? b : b + path.sep)
180
181
  }
181
182
 
183
+ /** 把允许的目录当场解析成真实路径钉住,返回判断函数(之后目录被换成软链,边界也不跟着变) */
184
+ /** 本机时间,写明时区:2026-11-10 12:07(UTC+8) */
185
+ export function localStamp(d) {
186
+ const p = (n) => String(n).padStart(2, '0')
187
+ const off = -d.getTimezoneOffset()
188
+ const a = Math.abs(off)
189
+ return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}(UTC${off < 0 ? '-' : '+'}${Math.floor(a / 60)}${a % 60 ? ':' + p(a % 60) : ''})`
190
+ }
191
+
192
+ export function pinRoots(roots) {
193
+ const pins = roots.filter(Boolean).map((r) => fold(realish(r)))
194
+ return (p) => {
195
+ const a = fold(realish(p))
196
+ return pins.some((b) => a === b || a.startsWith(b.endsWith(path.sep) ? b : b + path.sep))
197
+ }
198
+ }
199
+
182
200
  /**
183
201
  * 代码放进 dest 时算哪个项目:dest 自己就是项目就用它;不是、但已经在某个项目里面(比如选了它的 src/pages)→ 用往上最近的那个
184
202
  * (往上找到家目录为止,家目录本身不算:有人在家目录放 package.json;还不存在的目录不往上找:那是要新建的项目)
@@ -375,7 +393,7 @@ export function handoffMd({ root, rows, kind, size, framework, dest, project, sy
375
393
  else lines.push(`- 做到:\`${dest}\``)
376
394
  lines.push(`- 框架:${fwLabel}`)
377
395
  if (system) lines.push(`- 设计系统:${system}(设计用的是它的 tokens.css / components.css,项目里也照它)`)
378
- lines.push(`- 生成时间:${now.toISOString().slice(0, 16).replace('T', ' ')}`, '')
396
+ lines.push(`- 生成时间:${localStamp(now)}`, '')
379
397
  if (kind === 'miniprogram' && !mini) {
380
398
  // 小程序的设计、选的是网页框架:做成手机网页,别混进小程序的写法
381
399
  lines.push('## 小程序设计做成网页(H5)', '')
@@ -516,6 +534,8 @@ export function handoffMd({ root, rows, kind, size, framework, dest, project, sy
516
534
  walk(root, '', 0)
517
535
  lines.push('## 图片和字体', '')
518
536
  lines.push(assets.length ? `- ${assets.slice(0, 30).map((a) => `\`${a}\``).join('、')}${assets.length > 30 ? ' …' : ''}:照原样复制进项目的静态资源目录(${mini ? (uni ? `\`${at}static/\`` : taro ? `\`${at}assets/\`` : `\`${at}images/\` 之类`) : 'public/ 或 src/assets/'})` : '- 没有单独的图片、字体文件(图形都写在 HTML / SVG 里)。')
537
+ const aiPhotos = assets.filter((x) => isPhotoAsset(x))
538
+ if (aiPhotos.length) lines.push(`- 文件名带 \`${PHOTO_PREFIX}\` 的 ${aiPhotos.length} 张是 AI 生成的示意图:先照常接上,做完提醒用户上线前换成真实照片。`)
519
539
  if (mini) lines.push(`- 小程序主包不能超过 2MB:大图放服务器用网址;字体文件要用 \`${api}.loadFontFace\` 从网址加载,加载不了就用系统字体。`)
520
540
  lines.push('')
521
541