dsh-design-studio 0.22.0 → 0.23.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/browser.js CHANGED
@@ -11,7 +11,7 @@ import os from 'node:os'
11
11
  import path from 'node:path'
12
12
  import { spawn, execFile } from 'node:child_process'
13
13
 
14
- const IDLE_MS = 90000 // 闲置多久关掉
14
+ const IDLE_MS = 30000 // 闲置多久关掉(#21:原来 90 秒,活动监视器里 Chrome Helper 挂太久;再开一次约 1 秒)
15
15
  const CALL_MS = 30000 // 一条指令最多等多久
16
16
  const CLOSE_MS = 600 // 让浏览器自己关,最多等多久再强杀
17
17
  const LOAD_MS = 15000 // 页面载入最多等多久(到点照样往下走:有个图一直载不完也能量)
@@ -54,7 +54,7 @@ const PREFIX = 'dsh-design-browser-'
54
54
  const STALE_MS = 3600 * 1000 // 一小时没动过的临时用户目录:上回没删掉的(DSH 被强退、插件进程直接退出)
55
55
  let swept = false
56
56
 
57
- /** 清掉以前留下的临时用户目录(每个进程只扫一次;正在用的浏览器闲置 90 秒就关,不会一小时不动) */
57
+ /** 清掉以前留下的临时用户目录(每个进程只扫一次;正在用的浏览器闲置 30 秒就关,不会一小时不动) */
58
58
  function sweep(dir = os.tmpdir(), now = Date.now()) {
59
59
  if (swept) return
60
60
  swept = true
@@ -210,9 +210,9 @@ export function createBrowser({ bin = findBrowser(), log = () => {}, idleMs = ID
210
210
  stop()
211
211
  }
212
212
 
213
- const touch = () => {
213
+ const touch = (ms = idleMs) => {
214
214
  clearTimeout(idle)
215
- if (!open) idle = setTimeout(() => { if (!open) stop() }, idleMs)
215
+ if (!open) idle = setTimeout(() => { if (!open) stop() }, ms)
216
216
  }
217
217
 
218
218
  /**
@@ -223,7 +223,7 @@ export function createBrowser({ bin = findBrowser(), log = () => {}, idleMs = ID
223
223
  * allow(网址):给了就只让它说行的页面载入(主页面、iframe,连跳转、脚本改地址都算),别的拦下,记在 page.blocked
224
224
  * offline:断网渲染(设计库的检查):所有请求(样式、图片、字体、接口 …)只放行和页面同源的,别的一律拦下,记在 page.blocked
225
225
  */
226
- async function withPage({ url, w, h, scale = 1, dark = false, allow = null, offline = false }, fn) {
226
+ async function withPage({ url, w, h, scale = 1, dark = false, allow = null, offline = false, linger = idleMs }, fn) {
227
227
  if (dead) throw new Error('browser closed')
228
228
  if (open >= MAX_PAGES) await new Promise((r) => queue.push(r))
229
229
  if (dead) throw new Error('browser closed')
@@ -317,7 +317,7 @@ export function createBrowser({ bin = findBrowser(), log = () => {}, idleMs = ID
317
317
  open--
318
318
  const next = queue.shift()
319
319
  if (next) next()
320
- touch()
320
+ touch(Math.min(linger, idleMs)) // 后台活(画布缩略图)可以要求早点关
321
321
  }
322
322
  }
323
323
 
package/lib/canvthumb.js CHANGED
@@ -172,7 +172,7 @@ export function createCanvasThumbs({ tracker, browser, trust = () => '', strictR
172
172
  const b = browser()
173
173
  if (!b || !b.available()) throw new Error('no browser')
174
174
  let title = ''
175
- const jpg = await b.withPage({ url: o.url, w: o.w, h: o.h, scale: Math.min(1, WIDTH / o.w), dark: o.dark, offline: strictRoot(o.root) }, async (page) => {
175
+ const jpg = await b.withPage({ url: o.url, w: o.w, h: o.h, scale: Math.min(1, WIDTH / o.w), dark: o.dark, offline: strictRoot(o.root), linger: 10000 }, async (page) => {
176
176
  const { info } = await prepare(page, o.dark)
177
177
  title = cut(String((info && info.title) || '').replace(/\s+/g, ' ').trim(), 80)
178
178
  return page.shot({ quality: 72 })
package/lib/client.js CHANGED
@@ -80,7 +80,6 @@ window.__ModuleLoader__.load({
80
80
  homeRecent: '接着做',
81
81
  homeRecentAll: '全部作品 →',
82
82
  waysHtml: '打开已有的 HTML',
83
- moreWays: '其他开始方式',
84
83
  emptyHint: '输入文件路径,或本地端口(比如 5173)',
85
84
  emptyHintPick: '点「浏览…」选一个、直接拖进来,或输入文件路径 / 本地端口(比如 5173)',
86
85
  browse: '浏览…',
@@ -107,7 +106,6 @@ window.__ModuleLoader__.load({
107
106
  placeholder: '/路径/index.html 或 5173',
108
107
  go: '打开',
109
108
  pick: '选择',
110
- pickTip: '点选元素或框选区域,发给模型(Esc 取消)',
111
109
  pickAny: '点选任意一屏里的元素,或拖出一块区域 · Esc 取消',
112
110
  pickOne: '点选一个元素,或拖出一块区域 · Esc 取消',
113
111
  pickArea: '选中区域',
@@ -132,10 +130,7 @@ window.__ModuleLoader__.load({
132
130
  chipTokens: '建设计变量',
133
131
  pickElems: '{n} 个元素',
134
132
  textAny: '点任意一屏里的文字直接改 · 回车保存 · Esc 退出',
135
- refPick: '照参考图改风格…',
136
- refChoose: '选一张',
137
133
  refPickTip: '选一张参考图,照它的风格改(也可以把图片拖进预览区,或在这里粘贴)',
138
- refEmpty: '照参考图做:拖进来、粘贴,或',
139
134
  refDrop: '松开,作为参考图',
140
135
  refDropSub: '存进设计目录的 refs/,提取配色放进输入框',
141
136
  refNotImage: '只认图片(PNG / JPG / WebP / GIF)',
@@ -173,7 +168,6 @@ window.__ModuleLoader__.load({
173
168
  kindDiagram: '图表',
174
169
  kindDshplugin: "DSH 插件",
175
170
  tokens: '设计规范',
176
- tokensTip: '点一个放进输入框,补一句怎么改;改它所有屏一起变',
177
171
  tokensEmpty: '这套设计还没有设计变量(:root 上的 CSS 变量),颜色字号散在各处,改起来不统一。',
178
172
  tokensAsk: '让模型建一份',
179
173
  tokensAskText: '按 ui-design 技能给这套设计建一份 tokens.css(颜色、字体、字号、间距、圆角、阴影),所有屏都改成用这些变量。',
@@ -184,7 +178,6 @@ window.__ModuleLoader__.load({
184
178
  gRadius: '圆角',
185
179
  gShadow: '阴影',
186
180
  gOther: '其他',
187
- exportT: '导出',
188
181
  exFrame: '{name} · 带外框',
189
182
  exRaw: '{name} · 纯画面',
190
183
  exLong: '{name} · 整页长图',
@@ -231,7 +224,6 @@ window.__ModuleLoader__.load({
231
224
  exWhere: '存到设计目录的 exports/;图片还会复制到剪贴板',
232
225
  exportedDoc: '已导出 {name}({n} 页)',
233
226
  check: '设计体检',
234
- checkTip: '设计体检:量一量文字溢出、重叠、对比度、点击区、字号',
235
227
  checking: '正在体检…',
236
228
  checkNone: '没发现问题',
237
229
  checkSum: '{s} 屏 · {n} 个问题',
@@ -241,7 +233,6 @@ window.__ModuleLoader__.load({
241
233
  checkFail: '没查成:{msg}',
242
234
  checkLayout: '页面还没排好版,这次没量成,过一会儿再查一次',
243
235
  checkNote: '只量得出排版上的硬伤,好不好看还得你看',
244
- checkCount: '设计体检:上次量出 {n} 个问题,点开看',
245
236
  checkAsk: '〔设计体检〕发现 {n} 个问题:',
246
237
  checkTail: '请逐个修好:改源文件,只动有问题的地方;颜色、字号能改设计变量就改设计变量。',
247
238
  ckToolHead: '量了 {s} 屏,发现 {n} 个问题。逐个改源文件,只动有问题的地方;颜色、字号能改设计变量就改设计变量:',
@@ -379,7 +370,6 @@ window.__ModuleLoader__.load({
379
370
  mkUndo: '撤销',
380
371
  mkRedo: '重做',
381
372
  mkClear: '全部清掉',
382
- mkHint: '在页面上画,画完点「发到对话」',
383
373
  mkHow_pen: '按住拖动,随手画',
384
374
  mkHow_hl: '按住拖过去,把要改的地方涂亮',
385
375
  mkHow_arrow: '从起点按住,拖到要指的地方',
@@ -449,12 +439,8 @@ window.__ModuleLoader__.load({
449
439
  styleArrow: '{prop} {from} → {to}',
450
440
  styleJoin: ';',
451
441
  lang: 'zh',
452
- stylesHead: '或者先挑个风格',
453
- stylesTip: '点开看样板,满意了点「用这个风格」,再说要做什么',
454
442
  stylesMore: '更多风格({n})',
455
443
  stylesLess: '收起',
456
- stylesOpen: '换个风格…',
457
- stylesTitle: '换个风格',
458
444
  stylesSwap: '点一个看样板;「用这个风格」让模型把现在的设计换成它(只换配色、字体、圆角,布局和文字不动)',
459
445
  stylesAll: '全部风格',
460
446
  stylePrev: '上一个(←)',
@@ -518,7 +504,6 @@ window.__ModuleLoader__.load({
518
504
  dStyle: '点一个元素,拖滑块调字号、颜色、圆角和间距',
519
505
  dMark: '画圈、画箭头、写字,拼成一张图发给模型',
520
506
  dPlay: '像真的 App 一样点,按钮会跳到对应的屏',
521
- dLib: '存过的设计、风格和模板,也能逛设计市场',
522
507
  dLook: '改配色、字体,或整套换个风格',
523
508
  dCheck: '找出文字溢出、重叠、看不清、按钮太小',
524
509
  dCheckN: '上次找到 {n} 个问题,点开看',
@@ -550,18 +535,15 @@ window.__ModuleLoader__.load({
550
535
  dScreen: '换一屏、看全部、多尺寸、换类型',
551
536
  dCanvas: '回到画布,看全部的屏',
552
537
  toolsT: '工具',
553
- editAddr: '换一个地址',
554
538
  textShort: '改字',
555
539
  styleShort: '样式',
556
540
  markShort: '画笔',
557
- viewT: '视图',
558
541
  canvasShort: '画布',
559
- singleShort: '单页',
560
542
  sizesShort: '多尺寸',
543
+ fitShort: "按画幅显示",
544
+ fitTip: "网页单看、演示、对比时按画幅整屏缩放显示(写了画幅默认就是这样);关掉就铺满右侧栏,宽度跟着侧栏变",
561
545
  look: '外观',
562
- lookTip: '外观:配色、字体、整套风格',
563
546
  deliver: '导出',
564
- deliverTip: '导出:转成代码、存成图片 / PDF / PPT、打包分享',
565
547
  exFiles: '存成文件',
566
548
  checkShort: '体检',
567
549
  zoomT: '缩放',
@@ -631,10 +613,6 @@ window.__ModuleLoader__.load({
631
613
  updated: '已更新{file}',
632
614
  updatedN: '已更新{file} · {n} 处改动',
633
615
  updatedWhole: '已更新{file} · 整页重排',
634
- tryHead: '试试这样说',
635
- try1: '帮我设计一个社区健身房的会员 App',
636
- try2: '做一个精品咖啡店的落地页',
637
- try3: '做一张周末市集的活动海报',
638
616
  inserted: '已放进输入框,补一句要怎么改',
639
617
  insertedSend: '已放进输入框,发出去就行',
640
618
  copied: '已复制,粘贴到输入框里',
@@ -642,8 +620,6 @@ window.__ModuleLoader__.load({
642
620
  openFailed: '打不开:{msg}',
643
621
  headerTip: '设计台',
644
622
  tweaks: '调节滑块',
645
- twTip: '模型给这套设计做的几个维度:拖的时候所有屏一起变,还没写进文件。',
646
- twEmpty: '这套设计还没有专属滑块。让模型挑几个最值得试的维度(留白、圆角、主色、排法……),做成滑块放在这里。',
647
623
  twMake: '让模型做几个',
648
624
  twFix: '让模型修好',
649
625
  twMakeText: '〔调节滑块〕给这套设计做 3–5 个调节滑块:挑最值得试的维度(比如留白、圆角、主色、卡片排法),照 ui-design 技能「调节滑块」一节写进设计目录的 tweaks.json,把样式接上,做完用 check_design 查一遍。',
@@ -654,15 +630,12 @@ window.__ModuleLoader__.load({
654
630
  twAskHead: '〔调节〕我在右侧调节滑块里调成了下面这样:',
655
631
  twAskTail: '照这个改设计(改样式源文件,tweaks.json 里对应的 value 也改成新值)。',
656
632
  twAskTip: '让模型照这几个值改设计(可以顺手调整相关的地方)',
657
- twSaveTip: 'CSS 变量写进 tokens.css 的默认值,属性写到每屏的 <html> 上(改前改后各存一版)',
658
633
  twNoWrite: '开发服务器的页面不能直接保存,发到对话让模型改',
659
634
  twVer: '正在看旧版本:回到当前版本再保存',
660
635
  twMoved: '设计已经换了,没写回;再拖一次',
661
636
  twSaved: '已保存 {n} 项',
662
637
  twMissed: '{names} 在样式里没找到默认值,没保存:发到对话让模型改',
663
638
  systems: '品牌设计系统',
664
- sysOpen: '品牌设计系统…',
665
- sysEmptyLine: '用自己的品牌:',
666
639
  sysTip: '从你的网站或项目里提取的颜色、字体、圆角和组件。设为默认后,做新设计都照它来。',
667
640
  sysEmpty: '还没有。在上面填你的网站地址或项目文件夹,让模型提一套。',
668
641
  sysDefault: '默认',
@@ -708,11 +681,9 @@ window.__ModuleLoader__.load({
708
681
  libMarket: '市场',
709
682
  libWorks: '我的作品',
710
683
  libInspire: '灵感',
711
- libLine: '以前做的设计、存下的灵感、朋友给的设计包:',
712
684
  libOpen: '打开设计库',
713
685
  libClose: '返回',
714
686
  libFail: '没办成:{msg}',
715
- mkSoon: '设计市场正在准备:下一版就能在这里逛别人做的模板、风格和设计系统。',
716
687
  mkZip: '朋友给你的设计 zip,直接拖进右侧栏就能用。',
717
688
  mkLoading: '正在读市场…',
718
689
  tplStartHead: '从模板开始',
@@ -742,7 +713,6 @@ window.__ModuleLoader__.load({
742
713
  mkBack: '返回市场',
743
714
  mkStaging: '正在下载这一套…',
744
715
  mkStageFail: '没下载下来:{msg}',
745
- mkShots: '截图',
746
716
  mkLive: '实时看',
747
717
  mkLiveTip: '在关死的沙盒里打开(不跑脚本、不联网)',
748
718
  mkShotsBack: '看截图',
@@ -817,7 +787,6 @@ window.__ModuleLoader__.load({
817
787
  inUrlAdd: '存下',
818
788
  inUrlDo: '提取设计系统',
819
789
  inDel: '删除',
820
- inNone: '还没有',
821
790
  inLocal: '灵感只存在你电脑上,不上传。',
822
791
  inSaved: '已存进灵感',
823
792
  zipDrop: '用这个设计包开始',
@@ -969,7 +938,6 @@ window.__ModuleLoader__.load({
969
938
  homeRecent: 'Continue',
970
939
  homeRecentAll: 'All designs →',
971
940
  waysHtml: 'Open existing HTML',
972
- moreWays: 'Other ways to start',
973
941
  emptyHint: 'Enter a file path or a local port (like 5173)',
974
942
  emptyHintPick: 'Click "Browse…", drop it here, or enter a file path / local port (like 5173)',
975
943
  browse: 'Browse…',
@@ -996,7 +964,6 @@ window.__ModuleLoader__.load({
996
964
  placeholder: '/path/index.html or 5173',
997
965
  go: 'Open',
998
966
  pick: 'Select',
999
- pickTip: 'Click an element or drag a region to send it to the model (Esc to cancel)',
1000
967
  pickAny: 'Click an element in any screen, or drag a region · Esc to cancel',
1001
968
  pickOne: 'Click an element or drag a region · Esc to cancel',
1002
969
  pickArea: 'Selected region',
@@ -1021,10 +988,7 @@ window.__ModuleLoader__.load({
1021
988
  chipTokens: 'Create design tokens',
1022
989
  pickElems: '{n} elements',
1023
990
  textAny: 'Click text in any screen to edit · Enter to save · Esc to stop',
1024
- refPick: 'Restyle from a reference…',
1025
- refChoose: 'Choose one',
1026
991
  refPickTip: 'Pick a reference image to restyle after (or drop / paste an image into the preview)',
1027
- refEmpty: 'Design from a reference image: drop it, paste it, or',
1028
992
  refDrop: 'Drop to use as a reference',
1029
993
  refDropSub: 'Saved to refs/ in the design folder; its colors go into the input',
1030
994
  refNotImage: 'Images only (PNG / JPG / WebP / GIF)',
@@ -1062,7 +1026,6 @@ window.__ModuleLoader__.load({
1062
1026
  kindDiagram: 'Diagram',
1063
1027
  kindDshplugin: "DSH plugin",
1064
1028
  tokens: 'Design tokens',
1065
- tokensTip: 'Click one to put it in the input, then say how to change it. All screens follow',
1066
1029
  tokensEmpty: 'This design has no tokens yet (CSS variables on :root), so colors and sizes are scattered.',
1067
1030
  tokensAsk: 'Ask the model for one',
1068
1031
  tokensAskText: 'Following the ui-design skill, create a tokens.css for this design (colors, fonts, type sizes, spacing, radii, shadows) and make every screen use those variables.',
@@ -1073,7 +1036,6 @@ window.__ModuleLoader__.load({
1073
1036
  gRadius: 'Radii',
1074
1037
  gShadow: 'Shadows',
1075
1038
  gOther: 'Other',
1076
- exportT: 'Export',
1077
1039
  exFrame: '{name} · in frame',
1078
1040
  exRaw: '{name} · plain',
1079
1041
  exLong: '{name} · full page',
@@ -1120,7 +1082,6 @@ window.__ModuleLoader__.load({
1120
1082
  exWhere: 'Saved to exports/ in the design folder; images are also copied to the clipboard',
1121
1083
  exportedDoc: 'Exported {name} ({n} pages)',
1122
1084
  check: 'Design check',
1123
- checkTip: 'Design check: measure overflowing or overlapping text, contrast, tap targets and type sizes',
1124
1085
  checking: 'Checking…',
1125
1086
  checkNone: 'No problems found',
1126
1087
  checkSum: '{s} screens · {n} problems',
@@ -1130,7 +1091,6 @@ window.__ModuleLoader__.load({
1130
1091
  checkFail: 'Check failed: {msg}',
1131
1092
  checkLayout: 'The page was not laid out yet, so it was not measured. Check again in a moment.',
1132
1093
  checkNote: 'Only measurable layout problems; whether it looks good is still up to you',
1133
- checkCount: 'Design check: {n} problems last time. Click to see them',
1134
1094
  checkAsk: '[Design check] Found {n} problems:',
1135
1095
  checkTail: 'Please fix each one in the source files, touching only what is listed; for colors and type sizes, change the design tokens where possible.',
1136
1096
  ckToolHead: 'Measured {s} screens and found {n} problems. Fix each one in the source files, touching only what is listed; for colors and type sizes, change the design tokens where possible:',
@@ -1268,7 +1228,6 @@ window.__ModuleLoader__.load({
1268
1228
  mkUndo: 'Undo',
1269
1229
  mkRedo: 'Redo',
1270
1230
  mkClear: 'Clear all',
1271
- mkHint: 'Draw on the page, then click Send to chat',
1272
1231
  mkHow_pen: 'Press and drag to draw freehand',
1273
1232
  mkHow_hl: 'Drag over what needs changing to highlight it',
1274
1233
  mkHow_arrow: 'Press at the start and drag to what you mean',
@@ -1338,12 +1297,8 @@ window.__ModuleLoader__.load({
1338
1297
  styleArrow: '{prop} {from} → {to}',
1339
1298
  styleJoin: '; ',
1340
1299
  lang: 'en',
1341
- stylesHead: 'Or pick a style first',
1342
- stylesTip: 'Open one to preview, click "Use this style", then say what to make',
1343
1300
  stylesMore: 'More styles ({n})',
1344
1301
  stylesLess: 'Show less',
1345
- stylesOpen: 'Try another style…',
1346
- stylesTitle: 'Change the style',
1347
1302
  stylesSwap: 'Pick one to see a sample; "Use this style" has the model restyle the current design (colors, fonts and corners only; layout and copy stay)',
1348
1303
  stylesAll: 'All styles',
1349
1304
  stylePrev: 'Previous (←)',
@@ -1406,7 +1361,6 @@ window.__ModuleLoader__.load({
1406
1361
  dStyle: 'Click an element, then drag sliders for size, colors, radius and spacing',
1407
1362
  dMark: 'Draw circles, arrows and notes, sent to the model as one image',
1408
1363
  dPlay: 'Click through it like a real app; buttons jump to their screens',
1409
- dLib: 'Saved designs, styles and templates, plus the design market',
1410
1364
  dLook: 'Change colors and fonts, or switch the whole style',
1411
1365
  dCheck: 'Find overflowing or overlapping text, low contrast and tiny tap targets',
1412
1366
  dCheckN: '{n} problems last time. Click to see them',
@@ -1438,18 +1392,15 @@ window.__ModuleLoader__.load({
1438
1392
  dScreen: 'Switch screens, see all, sizes or type',
1439
1393
  dCanvas: 'Back to the canvas to see every screen',
1440
1394
  toolsT: 'Tools',
1441
- editAddr: 'Change address',
1442
1395
  textShort: 'Text',
1443
1396
  styleShort: 'Style',
1444
1397
  markShort: 'Draw',
1445
- viewT: 'View',
1446
1398
  canvasShort: 'Canvas',
1447
- singleShort: 'Single',
1448
1399
  sizesShort: 'Sizes',
1400
+ fitShort: "Fit to canvas size",
1401
+ fitTip: "Show the whole screen at its canvas size, scaled to fit, in single view, demo and compare (the default when a size is set); turn off to fill the side panel width",
1449
1402
  look: 'Look',
1450
- lookTip: 'Look: colors, fonts and overall style',
1451
1403
  deliver: 'Export',
1452
- deliverTip: 'Export: build as code, save images / PDF / PPT, pack and share',
1453
1404
  exFiles: 'Save as file',
1454
1405
  checkShort: 'Check',
1455
1406
  zoomT: 'Zoom',
@@ -1519,10 +1470,6 @@ window.__ModuleLoader__.load({
1519
1470
  updated: 'Updated{file}',
1520
1471
  updatedN: 'Updated{file} · {n} changes',
1521
1472
  updatedWhole: 'Updated{file} · whole page',
1522
- tryHead: 'Try saying',
1523
- try1: 'Design a member app for a neighborhood gym',
1524
- try2: 'Make a landing page for a specialty coffee shop',
1525
- try3: 'Make a poster for a weekend street market',
1526
1473
  inserted: 'Added to the input. Say what to change',
1527
1474
  insertedSend: 'Added to the input. Just send it',
1528
1475
  copied: 'Copied. Paste it into the input',
@@ -1530,8 +1477,6 @@ window.__ModuleLoader__.load({
1530
1477
  openFailed: 'Could not open: {msg}',
1531
1478
  headerTip: 'Design Studio',
1532
1479
  tweaks: 'Tweaks',
1533
- twTip: 'Knobs the model made for this design. Every screen follows as you drag; nothing is written yet.',
1534
- twEmpty: 'This design has no tweaks yet. Ask the model to pick the dimensions most worth trying (spacing, radius, brand color, layout…) and put them here as knobs.',
1535
1480
  twMake: 'Ask the model',
1536
1481
  twFix: 'Ask the model to fix it',
1537
1482
  twMakeText: '[Tweaks] Make 3–5 tweaks for this design: pick the dimensions most worth trying (spacing, radius, brand color, card layout…), write them to tweaks.json in the design folder as the ui-design skill describes under "Tweaks", wire up the styles, then run check_design.',
@@ -1542,15 +1487,12 @@ window.__ModuleLoader__.load({
1542
1487
  twAskHead: '[Tweaks] I set the tweaks in the sidebar to these values:',
1543
1488
  twAskTail: 'Change the design to match (edit the style sources and update the matching values in tweaks.json).',
1544
1489
  twAskTip: 'Let the model apply these values (and adjust related details)',
1545
- twSaveTip: 'CSS variables go into the defaults in tokens.css, attributes onto each screen\'s <html> (a version is kept before and after)',
1546
1490
  twNoWrite: 'Dev-server pages cannot be saved here. Send it to the chat instead',
1547
1491
  twVer: 'Viewing an old version. Go back to the current one to save',
1548
1492
  twMoved: 'The design changed, so nothing was written. Try again',
1549
1493
  twSaved: 'Saved {n}',
1550
1494
  twMissed: 'No default found in the styles for {names}, not saved. Send it to the chat instead',
1551
1495
  systems: 'Brand design systems',
1552
- sysOpen: 'Brand design systems…',
1553
- sysEmptyLine: 'Use your own brand:',
1554
1496
  sysTip: 'Colors, fonts, radii and components pulled from your site or project. The default one is used for every new design.',
1555
1497
  sysEmpty: 'None yet. Enter your website or project folder above and let the model extract one.',
1556
1498
  sysDefault: 'Default',
@@ -1595,11 +1537,9 @@ window.__ModuleLoader__.load({
1595
1537
  libMarket: 'Gallery',
1596
1538
  libWorks: 'My designs',
1597
1539
  libInspire: 'Inspiration',
1598
- libLine: 'Past designs, saved inspiration, design packs from friends:',
1599
1540
  libOpen: 'Open the library',
1600
1541
  libClose: 'Back',
1601
1542
  libFail: 'That did not work: {msg}',
1602
- mkSoon: 'The design gallery is on its way: the next version lets you browse templates, styles and design systems made by others.',
1603
1543
  mkZip: 'Got a design zip from a friend? Drop it on the sidebar to use it.',
1604
1544
  mkLoading: 'Loading the gallery…',
1605
1545
  tplStartHead: 'Start from a template',
@@ -1629,7 +1569,6 @@ window.__ModuleLoader__.load({
1629
1569
  mkBack: 'Back to gallery',
1630
1570
  mkStaging: 'Downloading this design…',
1631
1571
  mkStageFail: 'Could not download it: {msg}',
1632
- mkShots: 'Screenshots',
1633
1572
  mkLive: 'Live view',
1634
1573
  mkLiveTip: 'Opens in a locked sandbox (no scripts, no network)',
1635
1574
  mkShotsBack: 'Screenshots',
@@ -1704,7 +1643,6 @@ window.__ModuleLoader__.load({
1704
1643
  inUrlAdd: 'Save',
1705
1644
  inUrlDo: 'Extract design system',
1706
1645
  inDel: 'Delete',
1707
- inNone: 'Nothing yet',
1708
1646
  inLocal: 'Inspiration stays on your computer and is never uploaded.',
1709
1647
  inSaved: 'Saved to inspiration',
1710
1648
  zipDrop: 'Start from this design pack',
@@ -1934,9 +1872,6 @@ window.__ModuleLoader__.load({
1934
1872
  .ddp-btn.sel{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.14));color:var(--dsw-alias-label-primary)}
1935
1873
  .ddp-btn.pick{padding:0 9px}
1936
1874
  .ddp-btn .cr{width:10px;height:10px;margin-left:-2px;opacity:.6}
1937
- .ddp-seg{display:inline-flex;padding:2px;border-radius:7px;background:var(--dsw-alias-bg-layer-2);flex:none}
1938
- .ddp-seg .ddp-btn{height:24px;min-width:26px;border-radius:5px}
1939
- .ddp-seg .ddp-btn.sel{background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);box-shadow:0 1px 2px rgba(0,0,0,.12)}
1940
1875
  .ddp-sep{width:.5px;height:16px;background:var(--dsw-alias-border-l3);margin:0 2px;flex:none}
1941
1876
  .ddp-kind{position:relative;flex:none}
1942
1877
  .ddp-kind>.ddp-btn.sel{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.12));color:var(--dsw-alias-label-primary)}
@@ -2279,7 +2214,7 @@ window.__ModuleLoader__.load({
2279
2214
  .ddp-sc:hover,.ddp-sc:focus-visible{color:var(--dsw-alias-label-primary)}
2280
2215
  .ddp-sc .pv .ddp-sam{width:calc(100cqw / .32);min-height:calc(100% / .32);transform:scale(.32);transform-origin:0 0;pointer-events:none}
2281
2216
  .ddp-sam{display:flex;flex-direction:column;gap:7px;padding:12px 14px 14px;font-size:11px;line-height:1.45;text-align:left;overflow:hidden;box-sizing:border-box}
2282
- .ddp-sam b{font-weight:600;color:inherit} /* 空白页的 .ddp-empty b 会把字染成界面色 */
2217
+ .ddp-sam b{font-weight:600;color:inherit}
2283
2218
  .ddp-sam .top{display:flex;align-items:center;gap:6px;margin-bottom:3px}
2284
2219
  .ddp-sam .top b{font-size:12px}
2285
2220
  .ddp-sam .lg{width:14px;height:14px;flex:none}
@@ -2518,7 +2453,6 @@ window.__ModuleLoader__.load({
2518
2453
  /* 屏头的小按钮:屏够宽就带字(导出 / 再出两版 / 单看),窄了只剩图标,悬停看说明 */
2519
2454
  .ddp-act .lb{display:none;font-size:11px}
2520
2455
  @container (min-width:300px){.ddp-act .lb{display:inline}.ddp-act{gap:4px}}
2521
- .ddp-tw .row:first-child{border-top:0}
2522
2456
  .ddp-sys .bd{display:flex;flex-direction:column;gap:8px;padding:2px 10px 10px}
2523
2457
  .ddp-sys.bare{flex:1;min-height:0;display:flex;flex-direction:column}
2524
2458
  .ddp-sys>form{display:flex;gap:6px;flex:none;padding:0 10px 10px}
@@ -2907,10 +2841,24 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
2907
2841
  for (const set of strictBy.values()) if (set.has(u)) return true
2908
2842
  return false
2909
2843
  }
2844
+ // 问后台状态的间隔:模型在跑 0.7 秒;平常 1.5 秒;只有标题栏按钮在等(设计台从没打开过)、这个会话也没做过设计:5 秒(#21)。
2845
+ // 设计台一打开就按 1.5 秒,并马上补问一次(见 usePreview)
2846
+ const pollGap = (p) => {
2847
+ const s = p.state
2848
+ if (s && s.turn) return 700
2849
+ if (p.heavy > 0 || (s && (s.target || (Array.isArray(s.screens) && s.screens.length)))) return 1500
2850
+ return 5000
2851
+ }
2852
+ /** 网页单看要不要按画幅缩放(#20):用户在屏名菜单切过(pref = 'fit' / 'fill')听用户的;没切过看这套设计写没写画幅 */
2853
+ const webFitOf = (kind, pref, sized) => kind === 'web' && (pref ? pref === 'fit' : !!sized)
2854
+ const pageHidden = () => { try { return document.visibilityState === 'hidden' } catch { return false } }
2855
+ try {
2856
+ document.addEventListener('visibilitychange', () => { if (!pageHidden()) for (const p of pollers.values()) if (p.refs > 0) { p.stop(); p.start() } })
2857
+ } catch { /* 没有 document(测试) */ }
2910
2858
  function poller(sid) {
2911
2859
  let p = pollers.get(sid)
2912
2860
  if (p) return p
2913
- p = { state: null, subs: new Set(), timer: null, refs: 0, inflight: false, gen: 0 }
2861
+ p = { state: null, subs: new Set(), timer: null, refs: 0, heavy: 0, inflight: false, gen: 0 }
2914
2862
  const tick = async () => {
2915
2863
  p.timer = null
2916
2864
  if (!p.inflight) {
@@ -2932,7 +2880,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
2932
2880
  } catch { /* 下一轮再试 */ }
2933
2881
  p.inflight = false
2934
2882
  }
2935
- if (p.refs > 0) p.timer = setTimeout(tick, p.state && p.state.turn ? 700 : 1500)
2883
+ if (p.refs > 0 && !pageHidden()) p.timer = setTimeout(tick, pollGap(p)) // 窗口在后台:停,回到前台马上补一次(见下面 visibilitychange)
2936
2884
  }
2937
2885
  p.set = (s) => { p.gen++; p.apply(s) }
2938
2886
  p.apply = (s) => {
@@ -2946,17 +2894,20 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
2946
2894
  pollers.set(sid, p)
2947
2895
  return p
2948
2896
  }
2949
- function usePreview(sid) {
2897
+ // light:只是标题栏按钮在等(看要不要弹出右侧栏),没人看设计台时可以问得慢一点
2898
+ function usePreview(sid, light = false) {
2950
2899
  const p = sid ? poller(sid) : null
2951
2900
  const [s, setS] = useState(p ? p.state : null)
2952
2901
  useEffect(() => {
2953
2902
  if (!p) return undefined
2954
2903
  p.subs.add(setS)
2955
2904
  p.refs++
2905
+ if (!light) { p.heavy++; p.stop() } // 设计台打开了:别等原来排的慢的那次,马上问
2956
2906
  p.start()
2957
2907
  setS(p.state)
2958
2908
  return () => {
2959
2909
  p.subs.delete(setS)
2910
+ if (!light) p.heavy--
2960
2911
  if (--p.refs <= 0) p.stop()
2961
2912
  }
2962
2913
  }, [sid])
@@ -4578,6 +4529,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
4578
4529
  const HOLD_MAX = 15000 // 草稿放到一半真文件就落地了:最多再放这么久(一般几秒放完自己说一声)
4579
4530
  const EDIT_GRACE_MS = 3000 // 退出改字后这么久里,页面交上来的最后一处改动还收
4580
4531
  const KIND_SIZE = { web: [1280, 800], app: [390, 844], miniprogram: [375, 812], tablet: [820, 1180], desktop: [1280, 800], poster: [1080, 1350], slides: [1280, 720], email: [640, 960], diagram: [1600, 1000], dshplugin: [1280, 800] }
4532
+ const FIXED = { poster: 1, slides: 1, diagram: 1, dshplugin: 1 } // 画幅是定的(没有「整页」、不按内容加高、市场里只看截图)
4581
4533
  // 外框:pad 边框厚度、top 顶上一条(浏览器栏)、r 外圆角、ir 屏幕圆角、island 灵动岛离顶的距离、capsule 小程序右上角的胶囊、win 桌面软件的窗口按钮
4582
4534
  const FRAME = {
4583
4535
  web: { pad: 0, top: 34, r: 10, ir: 0 },
@@ -7056,7 +7008,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7056
7008
  const n = { name: name || t('exThisName') } // 写出是哪一屏,别只说「这一屏」
7057
7009
  if (FRAMED[kind]) items.push(['frame', I.single, t('exFrame', n)])
7058
7010
  items.push(['raw', I.image, t('exRaw', n)])
7059
- if (kind !== 'poster' && kind !== 'slides' && kind !== 'diagram' && kind !== 'dshplugin') items.push(['long', I.long, t('exLong', n)]) // 海报、幻灯片、图表画幅是定的,没有「整页」
7011
+ if (!FIXED[kind]) items.push(['long', I.long, t('exLong', n)]) // 海报、幻灯片、图表画幅是定的,没有「整页」
7060
7012
  if (count > 1) items.push(['show', I.canvas, t('exShow')])
7061
7013
  items.push(['pdf', I.pdf, t('exPdf')], ['pptx', I.deck, t('exPptx')], ['opts', I.sliders, t('exOpts')])
7062
7014
  return items
@@ -7162,7 +7114,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7162
7114
  }
7163
7115
 
7164
7116
  // 左上屏名 ▾:换屏(画布 / 某一屏)、多尺寸、类型、打开别的页面——「在看什么、怎么看」都在这一个菜单里
7165
- function ScreenMenu({ t, label, title, tip, src, busy, list, cur, canvas, open, setOpen, onPick, onAll, onOther, sizes, kind, onKind, hidden, hiddenText }) {
7117
+ function ScreenMenu({ t, label, title, tip, src, busy, list, cur, canvas, open, setOpen, onPick, onAll, onOther, sizes, fit, kind, onKind, hidden, hiddenText }) {
7166
7118
  const ref = useRef(null)
7167
7119
  useDismiss(open, setOpen, ref)
7168
7120
  const n = list.length
@@ -7181,6 +7133,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7181
7133
  hidden ? h('div', { className: 'nt' }, hiddenText) : null,
7182
7134
  sizes ? h('div', { className: 'sp', role: 'separator' }) : null,
7183
7135
  sizes ? h('button', { className: sizes.on ? 'sel' : '', role: 'menuitemcheckbox', 'aria-checked': !!sizes.on, disabled: !!sizes.off, title: sizes.tip, onClick: close(sizes.run) }, h(I.sizes), h('span', null, t('sizesShort')), sizes.note ? h('em', null, sizes.note) : null) : null,
7136
+ fit ? h('button', { className: fit.on ? 'sel' : '', role: 'menuitemcheckbox', 'aria-checked': !!fit.on, title: t('fitTip'), onClick: close(fit.run) }, h(I.single), h('span', null, t('fitShort')), h('em', null, fit.note)) : null,
7184
7137
  onKind ? h('div', { className: 'hd' }, t('kind')) : null,
7185
7138
  onKind ? h('div', { className: 'ddp-kinds', role: 'group', 'aria-label': t('kind') }, ...KIND_LIST.map((k) => h('button', { key: k, role: 'menuitemradio', 'aria-checked': k === kind, className: k === kind ? 'sel' : '', title: KIND_SIZE[k].join('×'), onClick: close(() => onKind(k)) },
7186
7139
  h(I[k]), h('span', null, t(KIND_KEY[k]))))) : null,
@@ -7419,7 +7372,6 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7419
7372
 
7420
7373
  // ── 设计库 › 市场 ──
7421
7374
  const GALLERY_REPO = 'https://github.com/OrderG-X/dsh-design-gallery'
7422
- const MK_KINDS = ['web', 'app', 'miniprogram', 'tablet', 'desktop', 'poster', 'slides', 'email', 'diagram', 'dshplugin']
7423
7375
  const mkPick = (t, x) => { const o = x || {}; return String((t('lang') === 'en' ? o.en || o.zh : o.zh || o.en) || '') }
7424
7376
  const mkUrl = (e) => e.submission || `${GALLERY_REPO}/tree/main/${e.type === 'system' ? 'systems' : e.type === 'style' ? 'styles' : 'templates'}/${e.id}`
7425
7377
  const mkErr = (t, e) => { const k = String((e && e.message) || e || ''); const m = t('mkErr_' + k); return m && m !== 'mkErr_' + k ? m : k }
@@ -7603,7 +7555,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7603
7555
  .filter((e) => !kind || type !== 'template' || e.kind === kind)
7604
7556
  .filter((e) => { const x = hay(e); return words.every((w) => x.includes(w)) })
7605
7557
  .sort((a, b) => (sort === 'featured' ? (b.featured - a.featured) || time(b.updated) - time(a.updated) : sort === 'new' ? time(b.added) - time(a.added) : time(b.updated) - time(a.updated)))
7606
- const kinds = MK_KINDS.filter((k) => d.designs.some((e) => e.kind === k))
7558
+ const kinds = KIND_LIST.filter((k) => d.designs.some((e) => e.kind === k))
7607
7559
  const card = (e) => {
7608
7560
  const by = e.author && !/^orderg-x$/i.test(e.author.login || '') ? e.author.name || e.author.login : '' // 官方做的不写作者(每张都一样)
7609
7561
  const meta = [e.type === 'template' ? t(KIND_KEY[e.kind] || 'kindWeb') : '', e.screens && e.screens.length ? t('wkScreens', { n: e.screens.length }) : '', t(e.license === 'CC-BY-4.0' ? 'mkUseBY' : 'mkUse0'), by ? '@' + by : ''].filter(Boolean).join(' · ')
@@ -7702,7 +7654,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7702
7654
  isTpl ? h('button', { className: 'ddp-pbtn', disabled: busy, title: t('mkUseTip'), onClick: use }, t('mkUse')) : null,
7703
7655
  e.type === 'system' ? h('button', { className: 'ddp-pbtn', disabled: busy, onClick: install }, t('mkInstall')) : null,
7704
7656
  // 海报、幻灯片、图表是定尺寸的画面、没什么可点的:只看截图(实时看会按原尺寸撑出框)
7705
- !err && e.type !== 'style' && e.kind !== 'poster' && e.kind !== 'slides' && e.kind !== 'diagram' && e.kind !== 'dshplugin' ? h('button', { className: 'ddp-sbtn', disabled: busy, title: t('mkLiveTip'), onClick: () => (live ? setLive(null) : goLive()) }, live ? t('mkShotsBack') : t('mkLive')) : null,
7657
+ !err && e.type !== 'style' && !FIXED[e.kind] ? h('button', { className: 'ddp-sbtn', disabled: busy, title: t('mkLiveTip'), onClick: () => (live ? setLive(null) : goLive()) }, live ? t('mkShotsBack') : t('mkLive')) : null,
7706
7658
  e.type !== 'style' ? h('button', { className: 'ddp-sbtn' + (fav ? ' on' : ''), title: t('mkFavTip'), 'aria-pressed': !!fav, onClick: toggleFav }, fav ? '★ ' + t('mkFaved') : '☆ ' + t('mkFav')) : null),
7707
7659
  h('ul', { className: 'facts' },
7708
7660
  h('li', null, t('mkSafe')),
@@ -7741,7 +7693,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7741
7693
  * over 比画幅大(横向永远会被裁;幻灯片、海报竖向也算);long 长页只截到一部分;dead 点了没反应的链接
7742
7694
  */
7743
7695
  function precheckOf(list, kind, limit) {
7744
- const fixed = kind === 'slides' || kind === 'poster' || kind === 'diagram' || kind === 'dshplugin'
7696
+ const fixed = !!FIXED[kind]
7745
7697
  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 }
7746
7698
  for (const m of list) {
7747
7699
  if (m.failed) { r.fail++; continue }
@@ -7757,7 +7709,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7757
7709
 
7758
7710
  /** 「按内容改画幅」改成多大:'宽x高',不用改或改不了返回 ''。幻灯片、海报按量到的版面,别的只把宽度加上去;竖着堆了好几页的不改高 */
7759
7711
  function fitCanvas(list, kind, size) {
7760
- const fixed = kind === 'slides' || kind === 'poster' || kind === 'diagram' || kind === 'dshplugin'
7712
+ const fixed = !!FIXED[kind]
7761
7713
  let [W, H] = size
7762
7714
  for (const m of list) {
7763
7715
  if (m.failed) continue
@@ -8687,6 +8639,10 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
8687
8639
  const tokens = main.tokens || []
8688
8640
  const kind = (st && st.kind) || meta.kind || 'web'
8689
8641
  const size = sizeOf((st && st.size) || meta.size || autoSize(screens.map((sc) => (infoOf(ik(sc)) || {}).natural), kind), kind)
8642
+ // 网页单看、演示、对比(#20):写了画幅(meta 或 preview_page 的 size)就按画幅整屏缩放,没写就铺满右侧栏;用户在屏名菜单里切过就听用户的
8643
+ const [fitPref, setFitPref] = useState(() => { try { return localStorage.getItem('ddp-web-fit') || '' } catch { return '' } })
8644
+ const webFit = webFitOf(kind, fitPref, !!((st && st.size) || meta.size))
8645
+ const toggleFit = () => { const v = webFit ? 'fill' : 'fit'; setFitPref(v); try { localStorage.setItem('ddp-web-fit', v) } catch { /* 记不住就这次有效 */ } }
8690
8646
  const view = (st && st.view) || (screens.length >= 2 && screens.length <= 12 ? 'canvas' : 'single')
8691
8647
  const canvas = view === 'canvas'
8692
8648
  const writingNew = !!(st && st.writing) && /\.html?$/i.test(st.writing) && !screens.some((s) => s.key === st.writing)
@@ -9273,7 +9229,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
9273
9229
  // 单看时只挂着正在看的那屏;要所有屏(PDF、PPT、拼图、预检)时按画幅大小在背后挂上,用完就撤
9274
9230
  const withFrames = async (fn, only) => {
9275
9231
  if (!only && ((canvas && shown.length <= LIVE_MAX) || shown.length < 2)) return fn(apis.current)
9276
- // 网页单看时铺满右侧栏,和画幅不一样宽,都在背后重挂;别的类型正在看的那屏直接用(滚动位置、打开的弹窗都还在)
9232
+ // 网页单看时铺满右侧栏,和画幅不一样宽,都在背后重挂(开了「按画幅显示」也照这样挂,只是多挂一次、慢一点,结果一样);别的类型正在看的那屏直接用(滚动位置、打开的弹窗都还在)
9277
9233
  // 画布屏多的时候镜头一动画布上的屏就会撤,也都在背后挂
9278
9234
  const stamp = designSeq.current
9279
9235
  const run = async () => {
@@ -9491,7 +9447,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
9491
9447
  const sizeSet = SIZE_SETS[kind] || null
9492
9448
  const inMulti = multi && !!sizeSet && !ver
9493
9449
  // 单页看手机 / 平板时,选择、改字的提示条放在设备上方,给它让出一条(不然压住设备顶边)
9494
- const hintTop = (picking || textEdit) && !canvas && !inMulti && !ver && !demo && kind !== 'web'
9450
+ const hintTop = (picking || textEdit) && !canvas && !inMulti && !ver && !demo && (kind !== 'web' || webFit) // 网页按画幅缩放时也和设备一样让出一条(#20)
9495
9451
  const flows = canvas && !inMulti && !picking && !textEdit ? flowsOf(shown, (sc) => (infoOf(ik(sc)) || {}).links, fileTarget) : []
9496
9452
 
9497
9453
  // ── 设计体检:画布上量所有屏,单页量这一屏;问题标在页面上,列在面板里 ──
@@ -9936,6 +9892,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
9936
9892
  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,
9937
9893
  onPick: pickScreen, onAll: toCanvas, onOther: () => setEditing(true),
9938
9894
  sizes: mark ? null : { on: inMulti, off: !sizeSet || !!ver, tip: sizeSet ? t('sizes') : t('sizesNo'), note: sizeSet ? '' : t('sizesNoShort'), run: () => setMulti(!inMulti) },
9895
+ fit: kind === 'web' && !mark ? { on: webFit, note: size.join('×'), run: toggleFit } : null,
9939
9896
  kind, onKind: mark ? null : (k) => change({ kind: k }) })),
9940
9897
  h('div', { className: 'ddp-isl tr' },
9941
9898
  h('button', { className: 'ddp-btn lab' + (panel ? ' sel' : ''), ...tipA(t('look'), t('dLook')), onClick: () => (panel ? setPanel(false) : openLook()) }, h(I.palette), h('span', { className: 'lb' }, t('look'))),
@@ -10322,9 +10279,10 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
10322
10279
  const cvBody = !demo && (inMulti || (canvas && !(ver && cmp)))
10323
10280
  let body
10324
10281
  let busyGap = false
10282
+ // 单看、演示、对比共用:网页铺满右侧栏(没开「按画幅显示」时),别的按画幅整屏缩放
10283
+ const fill = kind === 'web' && !webFit
10284
+ const [dw, dh] = deviceBox(kind, size)
10325
10285
  if (demo) {
10326
- const fill = kind === 'web'
10327
- const [dw, dh] = deviceBox(kind, size)
10328
10286
  const z = fill ? 1 : Math.max(0.05, Math.min(1, (box.w - 32) / dw, (ah - 16 - 46) / dh))
10329
10287
  const top = demo.layers[demo.layers.length - 1]
10330
10288
  body = h('div', { className: 'ddp-demo' }, ...demo.layers.map((l) => {
@@ -10399,8 +10357,6 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
10399
10357
  const now = screens.find((x) => x.key === k) || screens[0]
10400
10358
  const has = now && ver.screens.includes(now.key)
10401
10359
  const old = now ? { key: now.key, id: `v${ver.n}|${now.key}`, v: ver.n, url: vbase + encodeURIComponent(now.key), label: now.label } : null
10402
- const fill = kind === 'web'
10403
- const [dw, dh] = deviceBox(kind, size)
10404
10360
  // 右边开着版本面板:手机这类有外框的让到面板左边(和单看时一样)
10405
10361
  const aside = !fill && !!(ck || styleEdit || panel || pane || hist || phone) && box.w - 296 >= 240 ? 296 : 0
10406
10362
  const z = fill ? 1 : Math.max(0.05, Math.min(1, (box.w - aside - 32) / dw, (ah - 16 - (ver ? 46 : 0)) / dh))
@@ -10449,8 +10405,6 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
10449
10405
  onOpen: (key) => openByUser(key),
10450
10406
  })
10451
10407
  } else {
10452
- const fill = kind === 'web'
10453
- const [dw, dh] = deviceBox(kind, size)
10454
10408
  // 右边开着面板(体检、调样式、设计规范、换风格):手机这类有外框的让到面板左边(侧栏够宽时),别被挡住
10455
10409
  const sideOn = !!(anUp || ck || styleEdit || panel || pane || hist || phone) && box.w - 296 >= 240
10456
10410
  const aside = !fill && sideOn ? 296 : 0
@@ -10583,7 +10537,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
10583
10537
  function HeaderButton(props) {
10584
10538
  const t = props.t
10585
10539
  const sid = props.sid || props.sessionId
10586
- const [st] = usePreview(sid)
10540
+ const [st] = usePreview(sid, true)
10587
10541
  const seen = useRef(null)
10588
10542
  useEffect(() => {
10589
10543
  if (!st) return
@@ -10701,7 +10655,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
10701
10655
  // 注意:这里是客户端**服务名**(短的),不是包名
10702
10656
  exports.inject = INJECT
10703
10657
  // 测试用
10704
- exports._test = { precheckOf, fitCanvas, layoutOk, fitHOk, autoSize, pulseStep, MarketDetail, dragKind, droppedOf, pickInfo, pickLabel, pickRanges, pickRule, chipOf, chipRanges, makeT, ZH, EN, formatCheck, formatTweaks, markHit, markPath, STYLES, formatStyle, accentUse, autoStyle, styleLook, padInsert, pageOf, pxOf, styleChanges, formatStyleAsk, takesOf, formatCheckTool, poller, frameOf, paletteOf, formatRef, layoutRow, keyOfPath, flowsOf, flowLines, flowMarks, formatPick, whereOf, parseMeta, sizeOf, layoutGrid, fitCam, nearestLive, LIVE_MAX, tokenKind, formatToken, splitTitles, pickColors, hhmm, formatTpl, formatPrep, styleFromTokens, myStyleOf, isZipFile }
10658
+ exports._test = { KIND_LIST, KIND_KEY, KIND_SIZE, META_ALIAS, FIXED, SHOW_COLS, FRAME, ASK_EX, ASK_KINDS, KIND_ICON: I, pollGap, webFitOf, precheckOf, fitCanvas, layoutOk, fitHOk, autoSize, pulseStep, MarketDetail, dragKind, droppedOf, pickInfo, pickLabel, pickRanges, pickRule, chipOf, chipRanges, makeT, ZH, EN, formatCheck, formatTweaks, markHit, markPath, STYLES, formatStyle, accentUse, autoStyle, styleLook, padInsert, pageOf, pxOf, styleChanges, formatStyleAsk, takesOf, formatCheckTool, poller, frameOf, paletteOf, formatRef, layoutRow, keyOfPath, flowsOf, flowLines, flowMarks, formatPick, whereOf, parseMeta, sizeOf, layoutGrid, fitCam, nearestLive, LIVE_MAX, tokenKind, formatToken, splitTitles, pickColors, hhmm, formatTpl, formatPrep, styleFromTokens, myStyleOf, isZipFile }
10705
10659
  return module.exports
10706
10660
  },
10707
10661
  })
package/lib/core.js CHANGED
@@ -35,7 +35,8 @@ const MAX_SCREENS = 60 // 右侧最多显示几屏,再多的收起来并提示
35
35
  const MAX_ROUTES = 300 // 开发服务器的路由先都记着(只为算出收起了几屏);再多就是写飞了
36
36
 
37
37
  // 设计类型:决定右侧用什么画幅显示(网页框、手机、小程序、平板、桌面软件窗口、海报、幻灯片、邮件、图表)
38
- export const KINDS = ['web', 'app', 'miniprogram', 'tablet', 'desktop', 'poster', 'slides', 'email', 'diagram', 'dshplugin']
38
+ import { KINDS } from './kinds.js'
39
+ export { KINDS }
39
40
  const KIND_ALIAS = {
40
41
  website: 'web', site: 'web', page: 'web', landing: 'web', dashboard: 'web',
41
42
  phone: 'app', mobile: 'app', ios: 'app', android: 'app',
@@ -13,6 +13,7 @@
13
13
  import crypto from 'node:crypto'
14
14
  import { tokenize, scanTags, decodeEntities, lineAt, visibleText, rawEnd } from './html.js'
15
15
  import { scanCss, cssTokens, URL_FUNCS } from './css.js'
16
+ import { KINDS, META_ALIAS } from '../kinds.js'
16
17
 
17
18
  export const FORMAT = 1
18
19
  export const LIMITS = {
@@ -38,10 +39,9 @@ export const capsOf = (mode) => (mode === 'share' || mode === 'ci'
38
39
  : { files: LIMITS.localFiles, screens: LIMITS.localScreens, total: LIMITS.localTotal })
39
40
  export const TYPES = ['template', 'system', 'style']
40
41
  export const LICENSES = ['CC0-1.0', 'CC-BY-4.0']
41
- export const KINDS = ['web', 'app', 'miniprogram', 'tablet', 'desktop', 'poster', 'slides', 'email', 'diagram', 'dshplugin']
42
+ export { KINDS }
42
43
  export const STYLE_IDS = ['minimal', 'warm', 'editorial', 'dark', 'playful', 'fresh', 'tech', 'glass', 'soft', 'guochao', 'ink', 'cyber', 'cute', 'retro', 'sale', 'japandi', 'swiss', 'brutal', 'cream', 'sport']
43
44
  export const HEADS = ['SANS', 'SERIF', 'ROUND', 'MONO', 'GROTESK'] // 风格卡的字体只能是这几种系统字体栈
44
- const META_ALIAS = { phone: 'app', mobile: 'app', ios: 'app', android: 'app', mini: 'miniprogram', miniapp: 'miniprogram', weapp: 'miniprogram', wechat: 'miniprogram', 小程序: 'miniprogram', pad: 'tablet', ipad: 'tablet', pc: 'desktop', electron: 'desktop', tauri: 'desktop', mac: 'desktop', macos: 'desktop', windows: 'desktop', win: 'desktop', 桌面: 'desktop', 桌面软件: 'desktop', social: 'poster', image: 'poster', slide: 'slides', deck: 'slides', ppt: 'slides', mail: 'email', mindmap: 'diagram', roadmap: 'diagram', architecture: 'diagram', flowchart: 'diagram', 思维导图: 'diagram', 导图: 'diagram', 路线图: 'diagram', 架构图: 'diagram', 图表: 'diagram', dsh: 'dshplugin', 'dsh-plugin': 'dshplugin', dsh插件: 'dshplugin' }
45
45
 
46
46
  const EXT = { html: 'html', css: 'css', svg: 'svg', png: 'image', jpg: 'image', jpeg: 'image', webp: 'image', gif: 'image', avif: 'image', json: 'json', md: 'md' }
47
47
  const DATA_IMAGE = /^data:image\/(png|jpe?g|webp|gif|avif)(;[a-z0-9=._-]+)*(;base64)?,/i
package/lib/handoff.js CHANGED
@@ -677,7 +677,7 @@ export function localOnly(u) {
677
677
 
678
678
  /* eslint-disable no-undef */
679
679
  /** 在空白页里比两张无损截图:逐像素,每个点三个通道差加起来超过 24 就算不一样 → 差异比例、差得多的几块、拼图 */
680
- async function diffIn(a, b, labels) {
680
+ export async function diffIn(a, b, labels) {
681
681
  const load = (src) => new Promise((res, rej) => { const i = new Image(); i.onload = () => res(i); i.onerror = () => rej(new Error('图片载不出来')); i.src = 'data:image/png;base64,' + src })
682
682
  const [A, B] = await Promise.all([load(a), load(b)])
683
683
  const w = A.width, h = A.height
@@ -693,19 +693,21 @@ async function diffIn(a, b, labels) {
693
693
  const CELL = 16
694
694
  const cw = Math.ceil(w / CELL), ch = Math.ceil(h / CELL)
695
695
  const cells = new Float32Array(cw * ch)
696
- const heat = g.createImageData(w, h)
696
+ // 差异照样逐点算(1px 的线也不能漏);热力图大图按 st×st 一格画(#21:省掉一张全尺寸的图),格子里有一点不一样就标红
697
+ const st = Math.max(1, Math.round(Math.sqrt((w * h) / 1e6)))
698
+ const hw = Math.ceil(w / st), hh = Math.ceil(h / st)
699
+ const heat = g.createImageData(hw, hh)
697
700
  let bad = 0
698
701
  for (let y = 0; y < h; y++) {
702
+ const hy = (y / st) | 0
699
703
  for (let x = 0; x < w; x++) {
700
- const i = (y * w + x) * 4
704
+ const i = (y * w + x) * 4, j = (hy * hw + ((x / st) | 0)) * 4
701
705
  const d = Math.abs(da[i] - db[i]) + Math.abs(da[i + 1] - db[i + 1]) + Math.abs(da[i + 2] - db[i + 2])
702
706
  const hit = d > 24
703
707
  const l = (da[i] * 0.3 + da[i + 1] * 0.59 + da[i + 2] * 0.11) * 0.3 + 175
704
708
  if (hit) { bad++; cells[((y / CELL) | 0) * cw + ((x / CELL) | 0)]++ }
705
- heat.data[i] = hit ? 232 : l
706
- heat.data[i + 1] = hit ? 56 : l
707
- heat.data[i + 2] = hit ? 48 : l
708
- heat.data[i + 3] = 255
709
+ if (hit) { heat.data[j] = 232; heat.data[j + 1] = 56; heat.data[j + 2] = 48; heat.data[j + 3] = 255 }
710
+ else if (y % st === 0 && x % st === 0 && !heat.data[j + 3]) { heat.data[j] = l; heat.data[j + 1] = l; heat.data[j + 2] = l; heat.data[j + 3] = 255 }
709
711
  }
710
712
  }
711
713
  // 差得多的格子连成块,按差的像素数排
@@ -743,8 +745,8 @@ async function diffIn(a, b, labels) {
743
745
  o.fillStyle = '#eef0f3'
744
746
  o.fillRect(0, 0, w * 3 + PAD * 4, h + HEAD + PAD)
745
747
  const hc = document.createElement('canvas')
746
- hc.width = w
747
- hc.height = h
748
+ hc.width = hw
749
+ hc.height = hh
748
750
  hc.getContext('2d').putImageData(heat, 0, 0)
749
751
  const pct = (bad / (w * h)) * 100
750
752
  ;[[A, labels[0]], [B, labels[1]], [hc, labels[2].replace('{pct}', pct.toFixed(1))]].forEach(([img, label], k) => {
@@ -752,7 +754,7 @@ async function diffIn(a, b, labels) {
752
754
  o.fillStyle = '#1f2329'
753
755
  o.font = '600 22px -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif'
754
756
  o.fillText(label, x, 30)
755
- o.drawImage(img, x, HEAD)
757
+ o.drawImage(img, x, HEAD, w, h) // 热力图是取样大小、做出来的截图可能不一样大:都画成设计稿那么大
756
758
  o.strokeStyle = 'rgba(0,0,0,.12)'
757
759
  o.lineWidth = 1
758
760
  o.strokeRect(x - 0.5, HEAD - 0.5, w + 1, h + 1)
@@ -848,8 +850,3 @@ export async function compareScreens(browser, { design, impl, size, at = 'top',
848
850
  } else lines.push('没有成片的差异。')
849
851
  return { pct: r.pct, boxes, jpg: Buffer.from(r.jpg, 'base64'), text: lines.join('\n') }
850
852
  }
851
-
852
- /** 设计目录里的几屏(交接、对比时按文件名找) */
853
- export function screensOf(root) {
854
- return allScreens(root)
855
- }
package/lib/index.js CHANGED
@@ -612,7 +612,7 @@ export const styleTool = {
612
612
  '用户点了风格卡(消息里有〔风格〕)、自己定了具体的风格或配色、或有默认的品牌设计系统时不用调;只说「你定」「帮我推荐一个」「出几个风格挑」算没定,要调。',
613
613
  parameters: specToJsonSchema({
614
614
  subject: { type: 'string', required: true, description: '这次要做什么,直接写用户的原话' },
615
- kind: { type: 'string', enum: ['web', 'app', 'miniprogram', 'tablet', 'desktop', 'poster', 'slides', 'email', 'diagram', 'dshplugin'], description: '设计类型' },
615
+ kind: { type: 'string', enum: KINDS, description: '设计类型' },
616
616
  count: { type: 'number', description: '要几个方向,1–3,默认 1;要先出三个方向时填 3,每个方向一张不同的卡' },
617
617
  }),
618
618
  output: {
package/lib/kinds.js ADDED
@@ -0,0 +1,11 @@
1
+ // 设计类型的唯一一份表(服务端用):加新类型改这里,core / look / gallery/policy 都从这里取。
2
+ // client.js 是单独打包进页面的,有自己的一份,靠 test-client 里的对照测试看住。
3
+
4
+ /** 设计类型和默认画幅(宽, 高) */
5
+ export const KIND_SIZE = { web: [1280, 800], app: [390, 844], miniprogram: [375, 812], tablet: [820, 1180], desktop: [1280, 800], poster: [1080, 1350], slides: [1280, 720], email: [640, 960], diagram: [1600, 1000], dshplugin: [1280, 800] }
6
+
7
+ /** 全部类型(顺序 = 界面里列出的顺序) */
8
+ export const KINDS = Object.keys(KIND_SIZE)
9
+
10
+ /** 页面 <meta name="dsh-design"> 里认的类型别名(比 core 的 parseKind 少,故意不合并) */
11
+ export const META_ALIAS = { phone: 'app', mobile: 'app', ios: 'app', android: 'app', mini: 'miniprogram', miniapp: 'miniprogram', weapp: 'miniprogram', wechat: 'miniprogram', 小程序: 'miniprogram', pad: 'tablet', ipad: 'tablet', pc: 'desktop', electron: 'desktop', tauri: 'desktop', mac: 'desktop', macos: 'desktop', windows: 'desktop', win: 'desktop', 桌面: 'desktop', 桌面软件: 'desktop', social: 'poster', image: 'poster', slide: 'slides', deck: 'slides', ppt: 'slides', mail: 'email', mindmap: 'diagram', roadmap: 'diagram', architecture: 'diagram', flowchart: 'diagram', 思维导图: 'diagram', 导图: 'diagram', 路线图: 'diagram', 架构图: 'diagram', 图表: 'diagram', dsh: 'dshplugin', 'dsh-plugin': 'dshplugin', dsh插件: 'dshplugin' }
package/lib/look.js CHANGED
@@ -8,10 +8,20 @@
8
8
 
9
9
  import fs from 'node:fs'
10
10
  import path from 'node:path'
11
+ import { KIND_SIZE, KINDS as KIND_LIST, META_ALIAS } from './kinds.js'
12
+ export { KIND_SIZE }
13
+
14
+ // 体检一次最多几个页面任务一起跑(#21:12 屏 × 4 尺寸一下全铺开会挤满事件循环;浏览器那边本来也只开 3 个页面)
15
+ const LOOK_PAR = 4
16
+ /** 最多 n 个一起跑,结果按原来的顺序 */
17
+ async function mapLimit(list, n, fn) {
18
+ const out = new Array(list.length)
19
+ let next = 0
20
+ const run = async () => { while (next < list.length) { const i = next++; out[i] = await fn(list[i], i) } }
21
+ await Promise.all(Array.from({ length: Math.min(n, list.length) }, run))
22
+ return out
23
+ }
11
24
 
12
- export const KIND_SIZE = { web: [1280, 800], app: [390, 844], miniprogram: [375, 812], tablet: [820, 1180], desktop: [1280, 800], poster: [1080, 1350], slides: [1280, 720], email: [640, 960], diagram: [1600, 1000], dshplugin: [1280, 800] }
13
- const KIND_LIST = Object.keys(KIND_SIZE)
14
- const META_ALIAS = { phone: 'app', mobile: 'app', ios: 'app', android: 'app', mini: 'miniprogram', miniapp: 'miniprogram', weapp: 'miniprogram', wechat: 'miniprogram', 小程序: 'miniprogram', pad: 'tablet', ipad: 'tablet', pc: 'desktop', electron: 'desktop', tauri: 'desktop', mac: 'desktop', macos: 'desktop', windows: 'desktop', win: 'desktop', 桌面: 'desktop', 桌面软件: 'desktop', social: 'poster', image: 'poster', slide: 'slides', deck: 'slides', ppt: 'slides', mail: 'email', mindmap: 'diagram', roadmap: 'diagram', architecture: 'diagram', flowchart: 'diagram', 思维导图: 'diagram', 导图: 'diagram', 路线图: 'diagram', 架构图: 'diagram', 图表: 'diagram', dsh: 'dshplugin', 'dsh-plugin': 'dshplugin', dsh插件: 'dshplugin' }
15
25
  // 只给宽度时的高:常见真机的屏幕高;别的宽度按这一类默认的宽高比
16
26
  const PHONE_H = { 320: 568, 360: 780, 375: 667, 390: 844, 393: 852, 402: 874, 412: 915, 414: 896, 428: 926, 430: 932, 440: 956 }
17
27
  const TABLET_H = { 744: 1133, 768: 1024, 810: 1080, 820: 1180, 834: 1194, 1024: 1366, 1032: 1376 }
@@ -135,7 +145,7 @@ export async function prepare(page, dark) {
135
145
  /** 没写尺寸的幻灯片 / 海报:开页面量一下,比默认画幅大就按页面实际大小(和右侧栏的画幅一样)。量不到就还是默认 */
136
146
  export async function fitSize(browser, screens, kind, size) {
137
147
  const [w, h] = size
138
- const seen = await Promise.all(screens.map((sc) => browser.withPage({ url: sc.url, w, h }, async (page) => (await prepare(page, false)).info.natural).catch(() => null)))
148
+ const seen = await mapLimit(screens, LOOK_PAR, (sc) => browser.withPage({ url: sc.url, w, h }, async (page) => (await prepare(page, false)).info.natural).catch(() => null))
139
149
  return sizeOf(autoSize(seen, kind), kind) || size
140
150
  }
141
151
 
@@ -163,7 +173,7 @@ export async function measureAll(browser, { screens, sizes, kind, dark, fetcher
163
173
  }
164
174
  return gone.get(url)
165
175
  }
166
- const rows = await Promise.all(jobs.map(async ({ sc, w, h }, i) => {
176
+ const rows = await mapLimit(jobs, LOOK_PAR, async ({ sc, w, h }, i) => {
167
177
  const row = { key: sc.key, label: sc.label || sc.key, w, h, issues: [], metrics: null, error: '' }
168
178
  try {
169
179
  await browser.withPage({ url: sc.url, w, h, dark }, async (page) => {
@@ -193,7 +203,7 @@ export async function measureAll(browser, { screens, sizes, kind, dark, fetcher
193
203
  row.error = String((e && e.message) || e).slice(0, 160)
194
204
  }
195
205
  return row
196
- }))
206
+ })
197
207
  // 规则 → 文件和行号(一次问完)
198
208
  if (locate) {
199
209
  const withRule = rows.flatMap((r) => r.issues.filter((it) => it.rule && it.rule.sel))
@@ -232,7 +242,7 @@ export async function shootAll(browser, { screens, size, at, selector, dark, kin
232
242
  const scale = scaleFor(w, h)
233
243
  const out = []
234
244
  const perScreen = at === 'full' ? Math.max(1, Math.floor(max / Math.max(1, screens.length))) : 1
235
- await Promise.all(screens.map(async (sc, si) => {
245
+ await mapLimit(screens, LOOK_PAR, async (sc, si) => {
236
246
  const shots = []
237
247
  const base = { key: sc.key, label: sc.label || sc.key, w, h }
238
248
  try {
@@ -282,7 +292,7 @@ export async function shootAll(browser, { screens, size, at, selector, dark, kin
282
292
  shots.push({ ...base, at, error: String((e && e.message) || e).slice(0, 160) })
283
293
  }
284
294
  out[si] = shots
285
- }))
295
+ })
286
296
  return out.flat().filter(Boolean)
287
297
  }
288
298
 
package/lib/system.js CHANGED
@@ -533,7 +533,6 @@ function hinted(vars) {
533
533
  return out
534
534
  }
535
535
 
536
- const roundTo = (v, step = 1) => Math.round(v / step) * step
537
536
  const familyOf = (ff) => String(ff || '').split(',')[0].trim().replace(/^["']|["']$/g, '')
538
537
  const isSerif = (ff) => /(^|,)\s*serif\s*$/i.test(String(ff || '')) || /serif|song|ming|georgia|times|garamond|playfair|lora|merriweather|noto serif/i.test(familyOf(ff))
539
538
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-design-studio",
3
- "version": "0.22.0",
3
+ "version": "0.23.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "node --test --test-concurrency=1 test/*.mjs"