dsh-design-studio 0.22.0 → 0.23.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/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
@@ -8521,6 +8473,512 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
8521
8473
 
8522
8474
  // ── 右侧栏标签页 ─────────────────────────────────────────────────────────
8523
8475
 
8476
+ // ── 导出图片(从预览面板里拆出来的:只用传进来的,不碰面板自己的状态)──────────────
8477
+ // x:这一次画面的值(会话、状态、类型、画幅、几屏…)、几个 ref(各屏接口、背后挂的那批、设计序号)和面板里共用的 apiOf / targetKey
8478
+ // onWarn:预检发现会被裁时打开导出选项
8479
+ function makeExporter(x) {
8480
+ const { sid, st, kind, size, dark, meta, tokens, t, say, canvas, focus, sel, shown, ik, labelOf, infoOf, fileTarget, ver, apis, designNow, designSeq, ghostApis, ghostBatch, ghostQueue, setBackFrames, warned, onWarn, apiOf, targetKey } = x
8481
+ // 截一屏:图片和它的 CSS 尺寸(PDF / PPT 按这个定页面大小)
8482
+ // 这次导出截到的 AI 示意图(文件名去重):每种导出结束的提示里都带一句「上线前换成真实照片」
8483
+ const aiTail = (ai) => (ai && ai.size ? ' · ' + t('xoAi', { n: ai.size }) : '')
8484
+ const captureOf = async (sc, full, map, maxH, ai) => {
8485
+ const api = await apiOf(sc, map)
8486
+ const r = await api.capture({ full: !!full, scale: 2, ...(maxH ? { maxH } : {}) })
8487
+ if (ai && Array.isArray(r.aiPhotos)) for (const x of r.aiPhotos) ai.add(x)
8488
+ 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() }
8489
+ }
8490
+ // 导出用的标题:屏多的时候有的屏没在画布上挂过,手上没有它的标题,用截图时页面报的
8491
+ const exportTitle = (sc, r) => (infoOf(ik(sc)) || {}).title || r.title || sc.label
8492
+
8493
+ const saveImage = async (name, blob, ai) => {
8494
+ const png = await blobB64(blob)
8495
+ const r = await post('export', { session: sid, name, png, target: targetKey })
8496
+ const copied = await copyImage(blob)
8497
+ const file = String(r.path || '').split(/[\\/]/).pop()
8498
+ say(t(copied ? 'exportedCopied' : 'exported', { name: file }) + aiTail(ai), { label: t('reveal'), run: () => post('reveal', { path: r.path }).catch(() => {}) })
8499
+ }
8500
+
8501
+ // 单看时只挂着正在看的那屏;要所有屏(PDF、PPT、拼图、预检)时按画幅大小在背后挂上,用完就撤
8502
+ const withFrames = async (fn, only) => {
8503
+ if (!only && ((canvas && shown.length <= LIVE_MAX) || shown.length < 2)) return fn(apis.current)
8504
+ // 网页单看时铺满右侧栏,和画幅不一样宽,都在背后重挂(开了「按画幅显示」也照这样挂,只是多挂一次、慢一点,结果一样);别的类型正在看的那屏直接用(滚动位置、打开的弹窗都还在)
8505
+ // 画布屏多的时候镜头一动画布上的屏就会撤,也都在背后挂
8506
+ const stamp = designSeq.current
8507
+ const run = async () => {
8508
+ if (designSeq.current !== stamp) throw new Error('designChanged') // 排队的时候换了设计
8509
+ // 轮到了才算要挂哪些:排队时前台可能已经换了一屏
8510
+ const list = only || (canvas || kind === 'web' ? shown : shown.filter((sc) => !apis.current.has(ik(sc))))
8511
+ const back = new Set(list.map(ik))
8512
+ const place = new Map(list.map((sc, i) => [ik(sc), i]))
8513
+ // 屏多的时候分批挂:只挂轮到的这一批,别几十个一起跑
8514
+ let at = 0
8515
+ // 每个任务一批新的 iframe:上一批的深浅色、接口都不留(不然拿到上一批「已就绪」的就截了)
8516
+ ghostApis.current.clear()
8517
+ setBackFrames({ list, size, at, dark, batch: ++ghostBatch.current }) // 深浅色跟点导出时的走,和文件名对得上
8518
+ const get = (k) => {
8519
+ const i = place.get(k)
8520
+ if (i !== undefined && (i < at || i >= at + LIVE_MAX)) { at = i; setBackFrames((b) => (b ? { ...b, at: i } : b)) }
8521
+ return (back.has(k) ? ghostApis.current : apis.current).get(k)
8522
+ }
8523
+ try { return await fn({ get }) } finally { setBackFrames(null) }
8524
+ }
8525
+ // 背后挂的屏一次只给一个任务用(预检和导出撞上,会互相把对方要的那批撤掉)
8526
+ const job = ghostQueue.current.then(run, run)
8527
+ ghostQueue.current = job.catch(() => {})
8528
+ return job
8529
+ }
8530
+ const measureAll = async (map) => {
8531
+ const stamp = designSeq.current
8532
+ const list = []
8533
+ for (const sc of shown) {
8534
+ if (designSeq.current !== stamp) break // 设计换了:别再等旧的屏
8535
+ try { const api = await apiOf(sc, map); list.push(await api.measure()) } catch (e) { console.warn('[dsh-design-studio] 量页面失败', sc.key, e); list.push({ failed: true }) }
8536
+ }
8537
+ return list
8538
+ }
8539
+
8540
+ // 图片 / 整套展示图 / PDF / PPT(菜单里的「选项」「打包」「分享」在面板里分流,见 doExport)
8541
+ const exportShots = async (mode, key, opts) => {
8542
+ say(t('exporting'))
8543
+ const design = designNow.current
8544
+ const stamp = designSeq.current
8545
+ const gone = () => designSeq.current !== stamp
8546
+ const aiShot = new Set() // 这次导出截到的 AI 示意图(每次导出各记各的,连着导出不串)
8547
+ try {
8548
+ const prefix = ver ? `v${ver.n}-` : ''
8549
+ const suffix = dark ? '-dark' : ''
8550
+ if (mode === 'pdf' || mode === 'pptx') {
8551
+ // 每屏一页。PDF 里网页、邮件放整页长图(页面多高就多高);PPT 一张幻灯片一个画面。选项面板里可以改
8552
+ const fit = (opts && opts.fit) || ''
8553
+ const long = fit === 'page' || fit === 'height' || (!fit && mode === 'pdf' && (kind === 'web' || kind === 'email'))
8554
+ const maxH = fit === 'height' ? Number(opts.fitH) || 0 : 0
8555
+ let deadN = 0
8556
+ await withFrames(async (map) => {
8557
+ // 从菜单直接点:先量一遍,有内容会被裁就先给看清单(同样的结果只拦一次)
8558
+ if (!opts) {
8559
+ const seen = await measureAll(map)
8560
+ const rep = precheckOf(seen, kind, long ? Infinity : 0)
8561
+ deadN = rep.dead
8562
+ 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('|') : ''
8563
+ if (sig && warned.current !== sig) {
8564
+ warned.current = sig
8565
+ say(t('xoWarn'))
8566
+ onWarn()
8567
+ return
8568
+ }
8569
+ }
8570
+ const pages = []
8571
+ const keys = []
8572
+ for (const sc of shown) {
8573
+ if (gone()) break
8574
+ try {
8575
+ const r = await captureOf(sc, long, map, maxH, aiShot)
8576
+ const cut = maxH && r.h > maxH
8577
+ 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 })
8578
+ keys.push(sc.key)
8579
+ } catch (e) { console.warn('[dsh-design-studio] 截图失败', sc.key, e) }
8580
+ }
8581
+ if (gone()) { say(t('xoGone')); return }
8582
+ if (!pages.length) throw new Error('no screens')
8583
+ // 原型里的跳转:路径换成第几页,PDF / PPT 里点了能跳过去
8584
+ for (const p of pages) {
8585
+ p.links = p.links.map((l) => ({ x: l.x, y: l.y, w: l.w, h: l.h, to: keys.indexOf(keyOfPath(l.path, fileTarget)) })).filter((l) => l.to >= 0)
8586
+ }
8587
+ const sp = splitTitles(pages.map((x) => x.title))
8588
+ const folder = st && st.target && st.target.kind === 'file' ? String(st.target.file).split(/[\\/]/).slice(-2, -1)[0] : ''
8589
+ const title = sp.brand || folder || st.label || ''
8590
+ const layout = opts ? (opts.layout === 'custom' ? opts.custom.trim() : opts.layout === 'auto' ? '' : opts.layout) : ''
8591
+ const cols = opts && opts.cols === 2 ? 2 : 1
8592
+ const r = await post('doc', { session: sid, format: mode, name: prefix + (title || 'design') + suffix, title, bg: hexOf(pickColors(tokens).bg), pages, layout, cols, target: targetKey })
8593
+ const file = String(r.path || '').split(/[\\/]/).pop()
8594
+ const miss = shown.length - pages.length
8595
+ const sheets = Math.ceil(pages.length / cols)
8596
+ 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(() => {}) })
8597
+ })
8598
+ return
8599
+ }
8600
+ if (mode === 'show') {
8601
+ const shots = []
8602
+ await withFrames(async (map) => {
8603
+ for (const sc of shown) {
8604
+ if (gone()) break
8605
+ 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) }
8606
+ }
8607
+ })
8608
+ if (gone()) { say(t('xoGone')); return }
8609
+ if (!shots.length) throw new Error('no screens')
8610
+ const sp = splitTitles(shots.map((x) => x.title))
8611
+ const colors = pickColors(tokens)
8612
+ const blob = await composeShowcase({
8613
+ kind,
8614
+ size,
8615
+ shots: shots.map((x, i) => ({ img: x.img, top: x.top, label: sp.labels[i] || x.title })),
8616
+ os: meta.os,
8617
+ title: sp.brand || (st && st.target && st.target.kind === 'file' ? String(st.target.file).split(/[\\/]/).slice(-2, -1)[0] : st.label) || '',
8618
+ sub: t('showSub', { n: shots.length, kind: t(KIND_KEY[kind]), date: ymd(new Date()) }),
8619
+ bg: colors.bg,
8620
+ accent: colors.accent || ACCENT,
8621
+ mark: t('madeWith'),
8622
+ })
8623
+ await saveImage(prefix + (sp.brand || 'showcase') + suffix, blob, aiShot)
8624
+ return
8625
+ }
8626
+ const k = key || (canvas ? sel || focus : focus)
8627
+ const sc = shown.find((x) => x.key === k) || shown[0]
8628
+ if (!sc) throw new Error('no screen')
8629
+ const base = prefix + sc.key.replace(/\.html?$/i, '') + suffix
8630
+ // 画布屏多的时候这屏可能没挂着(镜头一动也可能撤掉):在背后单独挂一份来截
8631
+ let shot = null
8632
+ if (canvas && shown.length > LIVE_MAX) await withFrames(async (map) => { shot = await captureOf(sc, mode === 'long', map, 0, aiShot) }, [sc])
8633
+ else shot = await captureOf(sc, mode === 'long', undefined, 0, aiShot)
8634
+ if (gone()) { say(t('xoGone')); return }
8635
+ const { img, top } = shot
8636
+ if (mode === 'frame') await saveImage(base, await composeOne(kind, size, img, labelOf(sc), top, meta.os), aiShot)
8637
+ else {
8638
+ const c = document.createElement('canvas')
8639
+ c.width = img.width
8640
+ c.height = img.height
8641
+ c.getContext('2d').drawImage(img, 0, 0)
8642
+ await saveImage(base + (mode === 'long' ? '-full' : mode === 'raw' && FRAMED[kind] ? '-plain' : ''), await canvasBlob(c), aiShot)
8643
+ }
8644
+ } catch (e) {
8645
+ say(e.message === 'designChanged' ? t('xoGone') : t('exportFail', { msg: e.message }))
8646
+ }
8647
+ }
8648
+ return { withFrames, measureAll, exportShots }
8649
+ }
8650
+
8651
+ // ── 画笔标注(从预览面板里拆出来的):台面上看得到的几屏截图拼好、叠上画的,存进 refs/ 交给模型,或者复制
8652
+ // x:这一次画面的值和几个 ref;开关画笔、收掉别的面板留在面板里(toggleMark)
8653
+ function makeMarkup(x) {
8654
+ const { sid, st, stRef, url, shown, ik, apis, stageRef, markRun, markBusy, setMarkBusy, setMark, curScreen, insert, say, t } = x
8655
+ const markFrames = () => {
8656
+ const stage = stageRef.current
8657
+ if (!stage) return []
8658
+ const sr = stage.getBoundingClientRect()
8659
+ const out = []
8660
+ for (const sc of shown) {
8661
+ const api = apis.current.get(ik(sc))
8662
+ const f = api && typeof api.frame === 'function' ? api.frame() : null
8663
+ if (!f) continue
8664
+ const r = f.getBoundingClientRect()
8665
+ if (r.width < 8 || r.height < 8 || r.right <= sr.left || r.left >= sr.right || r.bottom <= sr.top || r.top >= sr.bottom) continue
8666
+ if (typeof f.checkVisibility === 'function' && !f.checkVisibility({ opacityProperty: true, visibilityProperty: true })) continue
8667
+ out.push({ key: ik(sc), sc, api, f, l: r.left - sr.left, t: r.top - sr.top, w: r.width, h: r.height, z: r.width / Math.max(1, f.offsetWidth) })
8668
+ }
8669
+ return out
8670
+ }
8671
+ const MARK_SHOTS = 40
8672
+ // 截到的是哪一页(只用来起名、写进提示):本地文件按文件名;开发服务器按路由(/account);单页应用的 #/account 路由带上
8673
+ const markPageOf = (sc, href) => {
8674
+ let key = pageOf(sc, href).key
8675
+ try {
8676
+ const u = new URL(href)
8677
+ if (u.origin !== new URL(sc.url).origin) return key
8678
+ if (key === sc.key && st && st.target && st.target.kind === 'proxy') key = decodeURIComponent(u.pathname) || sc.key
8679
+ if (/^#!?\//.test(u.hash)) key += decodeURIComponent(u.hash)
8680
+ } catch { /* 地址不对 */ }
8681
+ return key
8682
+ }
8683
+ // 把画的拼成一张图:画到的那几屏按现在的位置截图,叠上画的(交给模型、复制共用)
8684
+ const buildMark = async (list, stage) => {
8685
+ const sr = stage.getBoundingClientRect()
8686
+ const all = markFrames().filter((x) => x.api.ready())
8687
+ const ov = (a, b) => a.l < b.r && a.r > b.l && a.t < b.b && a.b > b.t
8688
+ const boxOf = (x) => ({ l: x.l, t: x.t, r: x.l + x.w, b: x.t + x.h })
8689
+ // 画到的那几屏(一屏都没碰到:画在屏外空白处的,就把看得到的都拼上)
8690
+ const marks = list.map(markBox)
8691
+ let shots = all.filter((x) => marks.some((m) => ov(boxOf(x), m)))
8692
+ if (!shots.length) shots = all
8693
+ // 裁到有东西的那块(画到的屏 + 画的),四周留一点;落在这块里的别的屏也拼上,免得图上空一块
8694
+ const pad = 16
8695
+ const span = (bs) => ({
8696
+ l: Math.max(0, Math.min(...bs.map((b) => b.l)) - pad),
8697
+ t: Math.max(0, Math.min(...bs.map((b) => b.t)) - pad),
8698
+ r: Math.min(sr.width, Math.max(...bs.map((b) => b.r)) + pad),
8699
+ b: Math.min(sr.height, Math.max(...bs.map((b) => b.b)) + pad),
8700
+ })
8701
+ const crop = span([...shots.map(boxOf), ...marks])
8702
+ shots = all.filter((x) => shots.includes(x) || ov(boxOf(x), crop))
8703
+ const { l: cl, t: ct, r: cr, b: cb } = crop
8704
+ if (!(cr - cl >= 1 && cb - ct >= 1)) throw new Error('empty')
8705
+ // 清晰度:至少按屏幕像素;画布缩小着看的,按页面原来的大小截(最多 4 倍),整张不超过 4096
8706
+ const zMin = Math.min(1, ...shots.map((x) => x.z))
8707
+ const k = Math.min(4096 / Math.max(cr - cl, cb - ct), Math.max(Math.min(2, Math.max(1, window.devicePixelRatio || 1)), Math.min(4, 1 / Math.max(0.05, zMin))))
8708
+ const c = document.createElement('canvas')
8709
+ c.width = Math.max(1, Math.round((cr - cl) * k))
8710
+ c.height = Math.max(1, Math.round((cb - ct) * k))
8711
+ const ctx = c.getContext('2d')
8712
+ let bg = ''
8713
+ for (let el = stage; el && !bg; el = el.parentElement) {
8714
+ const v = getComputedStyle(el).backgroundColor
8715
+ if (v && !/^(transparent|rgba\(.*,\s*0\))$/.test(v)) bg = v
8716
+ }
8717
+ ctx.fillStyle = bg || '#f4f4f5'
8718
+ ctx.fillRect(0, 0, c.width, c.height)
8719
+ if (shots.length > MARK_SHOTS) say(t('mkMany', { n: MARK_SHOTS }))
8720
+ const names = []
8721
+ for (const [i, x] of shots.entries()) {
8722
+ const X = (x.l - cl) * k
8723
+ const Y = (x.t - ct) * k
8724
+ // 手机框的圆角:往上找一层裁圆角的
8725
+ let rad = 0
8726
+ for (let el = x.f.parentElement, j = 0; el && el !== stage && j < 4 && !rad; el = el.parentElement, j++) {
8727
+ const cs = getComputedStyle(el)
8728
+ const v = parseFloat(cs.borderTopLeftRadius) || 0
8729
+ if (v && cs.overflow !== 'visible' && el.offsetWidth) rad = v * (el.getBoundingClientRect().width / el.offsetWidth)
8730
+ }
8731
+ ctx.save()
8732
+ ctx.beginPath()
8733
+ if (rad && typeof ctx.roundRect === 'function') ctx.roundRect(X, Y, x.w * k, x.h * k, rad * k)
8734
+ else ctx.rect(X, Y, x.w * k, x.h * k)
8735
+ ctx.clip()
8736
+ let name = x.sc.key
8737
+ try {
8738
+ if (i >= MARK_SHOTS) throw new Error('too many')
8739
+ const cap = await x.api.capture({ full: false, scale: Math.min(3, Math.max(1, x.z * k)) })
8740
+ // 页面里点链接跳到别的页了:按真正截到的那页起名
8741
+ if (cap.href) name = markPageOf(x.sc, cap.href)
8742
+ const img = await loadImg(cap.png)
8743
+ ctx.fillStyle = '#fff'
8744
+ ctx.fillRect(X, Y, x.w * k, x.h * k)
8745
+ ctx.drawImage(img, X, Y, cap.w * x.z * k, cap.h * x.z * k)
8746
+ } catch (e) {
8747
+ // 这一屏截不下来:留个灰块,画的东西还在
8748
+ if (i < MARK_SHOTS) console.warn('[dsh-design-studio] 标注截图失败', x.sc.key, e)
8749
+ ctx.fillStyle = 'rgba(127,127,127,.18)'
8750
+ ctx.fillRect(X, Y, x.w * k, x.h * k)
8751
+ }
8752
+ ctx.restore()
8753
+ if (!names.includes(name)) names.push(name)
8754
+ }
8755
+ for (const s of list) drawMark(ctx, s, k, cl, ct)
8756
+ return { c, names, blob: await canvasBlob(c) }
8757
+ }
8758
+ const sendMark = async (list) => {
8759
+ if (markBusy) return
8760
+ if (!list.length) { say(t('mkEmpty')); return }
8761
+ const stage = stageRef.current
8762
+ if (!stage) return
8763
+ const url0 = url
8764
+ const run0 = markRun.current
8765
+ const stale = () => stRef.current.url !== url0 || markRun.current !== run0
8766
+ const root0 = st && st.target && st.target.kind === 'file' ? st.target.root : null
8767
+ setMarkBusy(true)
8768
+ try {
8769
+ const { c, names, blob } = await buildMark(list, stage)
8770
+ // 拼图的时候换了设计、关了标注:这张图对不上了,别交
8771
+ if (stale()) { if (stRef.current.url !== url0) say(t('mkMoved')); return }
8772
+ if (!names.length && curScreen) names.push(curScreen.key)
8773
+ const stem = String(names[0] || 'page').replace(/\.html?(?=$|#)/i, '').split(/[/#!]+/).filter(Boolean).pop() || 'page'
8774
+ const body = { session: sid, name: `markup-${stem}`, data: await blobB64(blob) }
8775
+ if (root0 !== null) body.root = root0
8776
+ let saved
8777
+ try { saved = await post('ref', body) } catch (e) {
8778
+ if (/moved/.test(e.message)) { say(t('mkMoved')); return }
8779
+ throw e
8780
+ }
8781
+ if (stale()) { if (stRef.current.url !== url0) say(t('mkMoved')); return }
8782
+ keepThumb(saved.path, c)
8783
+ const where = (names.length ? names : [st.label || '']).join(t('sep'))
8784
+ // 写在图上的字也用文字带上:模型看图看漏了、或者用的模型看不了图,也知道要改什么
8785
+ const notes = list.filter((x) => x.t === 'text').map((x) => t('mkQuote', { v: x.v.replace(/\s*\n\s*/g, ' ') })).join(t('sep'))
8786
+ // 插不进输入框:标注层留着(画的还在),提示再点一次;不退回剪贴板
8787
+ if (insert(t('mkAsk', { path: saved.path, where, notes: notes ? t('mkNotes', { notes }) : '' }), 'mkIn', false)) setMark(false)
8788
+ else say(t('mkNoInput'))
8789
+ } catch (e) {
8790
+ say(t('mkFail', { msg: e.message }))
8791
+ } finally {
8792
+ setMarkBusy(false)
8793
+ }
8794
+ }
8795
+ // 复制:同一张图放进剪贴板(issue #6)。点按钮这一下就把「等图拼好」交给剪贴板——拼完再写,
8796
+ // Safari 这类会说不是用户点的、不让写;不认这种写法的再用拼好的图写一次
8797
+ const copyMark = (list) => {
8798
+ if (markBusy) return
8799
+ if (!list.length) { say(t('mkEmpty')); return }
8800
+ const stage = stageRef.current
8801
+ if (!stage) return
8802
+ const url0 = url
8803
+ const run0 = markRun.current
8804
+ const stale = () => stRef.current.url !== url0 || markRun.current !== run0
8805
+ const STALE = 'ddp-mark-stale'
8806
+ setMarkBusy(true)
8807
+ const made = buildMark(list, stage).then((r) => { if (stale()) throw new Error(STALE); return r })
8808
+ const png = made.then((r) => r.blob)
8809
+ png.catch(() => {}) // 结果在下面看
8810
+ let wrote
8811
+ try { wrote = navigator.clipboard.write([new ClipboardItem({ 'image/png': png })]) } catch (e) { wrote = Promise.reject(e) }
8812
+ wrote.catch(() => {})
8813
+ ;(async () => {
8814
+ try {
8815
+ const r = await made
8816
+ if (!(await wrote.then(() => true, () => false))) {
8817
+ // 等写的工夫里取消了、换了设计:别再把这张旧图写进去
8818
+ if (stale()) { if (stRef.current.url !== url0) say(t('mkMoved')); return }
8819
+ if (!(await copyImage(r.blob))) { say(t('mkCopyFail')); return }
8820
+ }
8821
+ if (stale()) return
8822
+ say(t('mkCopied'))
8823
+ setMark(false)
8824
+ } catch (e) {
8825
+ if (e && e.message === STALE) { if (stRef.current.url !== url0) say(t('mkMoved')) } else {
8826
+ console.warn('[dsh-design-studio] 标注图复制失败', e)
8827
+ say(t('mkCopyFail'))
8828
+ }
8829
+ } finally {
8830
+ setMarkBusy(false)
8831
+ }
8832
+ })()
8833
+ }
8834
+ return { markFrames, sendMark, copyMark }
8835
+ }
8836
+
8837
+ // ── 设计体检(从预览面板里拆出来的):画布上量所有屏,单页量这一屏;问题标在页面上,列在面板里
8838
+ // x:这一次画面的值和几个 ref;onOpen:开体检面板时收掉别的面板。自动量、check_design 回话的 effect 留在面板里
8839
+ function makeCheck(x) {
8840
+ const { kind, url, st, stRef, canvas, shown, focus, ik, labelOf, apis, apiOf, ck, setCk, ckGen, ckOpen, setCkCount, setReveal, setSel, onOpen, insert, say, t } = x
8841
+ const closeCheck = () => {
8842
+ ckGen.current++
8843
+ ckOpen.current = false
8844
+ if (ck) for (const sc of ck.list || []) { const a = apis.current.get(ik(sc)); if (a) a.checkClear() }
8845
+ setCk(null)
8846
+ }
8847
+ // 画布屏多的时候只量挂着的(别的没有页面可量)
8848
+ const checkList = () => (canvas ? (shown.length > LIVE_MAX ? shown.filter((sc) => apis.current.has(ik(sc))) : shown) : [shown.find((x) => x.key === focus) || { key: focus, url, label: st.label }])
8849
+ // 几屏一起量(各量各的 iframe),一屏卡住不拖累别的
8850
+ const measure = (list, quiet) => Promise.all(list.map(async (sc) => {
8851
+ const row = { key: sc.key, v: sc.v, label: labelOf(sc), url: sc.url, issues: [] }
8852
+ try {
8853
+ const r = await (await apiOf(sc)).check(kind, quiet)
8854
+ row.issues = Array.isArray(r.issues) ? r.issues : []
8855
+ if (r.metrics && typeof r.metrics === 'object') row.metrics = r.metrics
8856
+ } catch (e) { row.error = e.message }
8857
+ return row
8858
+ }))
8859
+ const total = (list) => list.reduce((m, x) => m + x.issues.length, 0)
8860
+ const runCheck = async () => {
8861
+ onOpen()
8862
+ setCk({ running: true, list: [] })
8863
+ const g = ++ckGen.current
8864
+ ckOpen.current = true
8865
+ const out = await measure(checkList(), false)
8866
+ if (g !== ckGen.current) { // 量的时候面板关了 / 又量了一轮:这份结果作废;面板关着的话,这一轮画上的标记也清掉
8867
+ if (!ckOpen.current) for (const sc of out) { const a = apis.current.get(ik(sc)); if (a) a.checkClear() }
8868
+ return out
8869
+ }
8870
+ if (canvas && shown.length > LIVE_MAX) say(t('checkPartial', { n: out.length }))
8871
+ setCk({ running: false, list: out })
8872
+ setCkCount(total(out))
8873
+ // 有问题的第一屏被面板挡着、在画布外面:挪过来
8874
+ const first = out.find((x) => x.issues.length)
8875
+ if (canvas && first) setReveal((r) => ({ key: first.key, n: ((r && r.n) || 0) + 1 }))
8876
+ return out
8877
+ }
8878
+ const focusIssue = (key, i) => {
8879
+ const sc = (ck && ck.list.find((x) => x.key === key)) || null
8880
+ if (!sc) return
8881
+ if (canvas) { setSel(key); setReveal((r) => ({ key, n: ((r && r.n) || 0) + 1 })) }
8882
+ // 屏多的时候这屏可能撤过(重新载入后页面里的体检标记没了):等它挂上,量一遍再定位
8883
+ if (canvas && shown.length > LIVE_MAX) { apiOf(sc).then((api) => api.check(kind, false).then(() => api.checkFocus(i))).catch((e) => console.warn('[dsh-design-studio] 定位问题失败', key, e)); return }
8884
+ const a = apis.current.get(ik(sc))
8885
+ if (a) a.checkFocus(i)
8886
+ }
8887
+ const fixIssues = () => {
8888
+ if (!ck) return
8889
+ insert(formatCheck(t, ck.list, stRef.current), 'insertedSend')
8890
+ closeCheck()
8891
+ }
8892
+ return { closeCheck, checkList, measure, total, runCheck, focusIssue, fixIssues }
8893
+ }
8894
+
8895
+ // ── 调样式(从预览面板里拆出来的):点一个元素,面板里拖滑块先在页面上看效果;写回文件 = 并进它在源码里的 style 属性
8896
+ // x:这一次画面的值;开关调样式、Esc 收起留在面板里
8897
+ function makeStyleEdit(x) {
8898
+ const { sid, stRef, fileTarget, canvas, setSel, sty, setSty, insert, say, t } = x
8899
+ const onStylePick = (sc, p) => {
8900
+ if (canvas) setSel(sc.key)
8901
+ const pg = pageOf(sc, p.href)
8902
+ setSty({ key: pg.key, url: pg.url, name: p.name, selector: p.selector, text: p.text, loc: p.loc, base: p.css || {}, vars: p.vars || {}, rules: p.rules && typeof p.rules === 'object' ? p.rules : {}, gradient: !!p.gradient, layout: !!p.layout, live: {} })
8903
+ }
8904
+ const setStyleProp = (patch) => setSty((c) => (c ? { ...c, live: { ...c.live, ...patch } } : c))
8905
+ // 交给模型:先问服务端那几条规则在源码第几行(本地文件才有;问不到就只写文件名)
8906
+ const askStyle = async () => {
8907
+ const s0 = sty
8908
+ if (!s0) return
8909
+ let located = null
8910
+ const items = [...new Map(Object.keys(s0.live || {}).map((k) => s0.rules && s0.rules[k]).filter((r) => r && r.sel && r.href).map((r) => [`${r.href}|${r.sel}|${r.n}`, r])).values()]
8911
+ if (fileTarget && items.length) {
8912
+ try {
8913
+ const r = await post('locate', { session: sid, items: items.map((x) => ({ href: x.href, sel: x.sel, n: x.n })) })
8914
+ located = new Map(items.map((x, i) => [`${x.href}|${x.sel}|${x.n}`, r && Array.isArray(r.items) ? r.items[i] : null]))
8915
+ } catch { /* 找不到行号就只写文件名 */ }
8916
+ }
8917
+ insert(formatStyleAsk(t, s0, stRef.current, located), 'insertedSend')
8918
+ }
8919
+ const saveStyle = () => {
8920
+ const s0 = sty
8921
+ if (!s0 || !Object.keys(s0.live).length) return
8922
+ if (!fileTarget) return askStyle()
8923
+ const saved = s0.live
8924
+ post('style', { session: sid, key: s0.key, loc: s0.loc, css: saved, name: s0.name }).then((r) => {
8925
+ if (r && r.ok) {
8926
+ say(t('styleSaved', { file: r.file }))
8927
+ // 写进去的算「原样」了;写的时候又拖过的留着
8928
+ setSty((c) => (c && c.key === s0.key && c.selector === s0.selector
8929
+ ? { ...c, base: { ...c.base, ...saved }, live: Object.fromEntries(Object.entries(c.live).filter(([k, v]) => saved[k] !== v)) } : c))
8930
+ } else if (r && r.reason === 'busy') say(t('styleBusyTip'))
8931
+ else { say(t('styleMiss')); askStyle() }
8932
+ }, () => askStyle())
8933
+ }
8934
+ return { onStylePick, setStyleProp, askStyle, saveStyle }
8935
+ }
8936
+
8937
+ // ── 演示跳屏(从预览面板里拆出来的):点页面里的按钮跳到别的屏,前进从右边滑进来、返回从左边
8938
+ // x:setDemo、demoSeq(层的编号)、fileTarget(把链接路径换成哪一屏);开始演示、Esc 收起留在面板里
8939
+ function makeDemoNav(x) {
8940
+ const { setDemo, demoSeq, fileTarget } = x
8941
+ const demoGo = (path) => demoTo(keyOfPath(path, fileTarget))
8942
+ const demoTo = (key) => {
8943
+ setDemo((d) => {
8944
+ if (!d) return d
8945
+ const top = d.stack[d.stack.length - 1]
8946
+ if (key === top) return d
8947
+ const back = d.stack.length > 1 && d.stack[d.stack.length - 2] === key
8948
+ const stack = back ? d.stack.slice(0, -1) : [...d.stack, key].slice(-30)
8949
+ const last = d.layers[d.layers.length - 1]
8950
+ return { stack, layers: [last, { id: ++demoSeq.current, key, dir: back ? -1 : 1, shown: false }] }
8951
+ })
8952
+ }
8953
+ const demoRestart = () => setDemo((d) => {
8954
+ if (!d || d.stack.length < 2) return d
8955
+ const last = d.layers[d.layers.length - 1]
8956
+ return { stack: [d.stack[0]], layers: [last, { id: ++demoSeq.current, key: d.stack[0], dir: -1, shown: false }] }
8957
+ })
8958
+ const demoBack = () => setDemo((d) => {
8959
+ if (!d || d.stack.length < 2) return d
8960
+ const stack = d.stack.slice(0, -1)
8961
+ const last = d.layers[d.layers.length - 1]
8962
+ return { stack, layers: [last, { id: ++demoSeq.current, key: stack[stack.length - 1], dir: -1, shown: false }] }
8963
+ })
8964
+ const demoShown = (id) => {
8965
+ setDemo((d) => (d ? { ...d, layers: d.layers.map((l) => (l.id === id ? { ...l, shown: true } : l)) } : d))
8966
+ setTimeout(() => setDemo((d) => (d && d.layers.length > 1 && d.layers[d.layers.length - 1].id === id ? { ...d, layers: [d.layers[d.layers.length - 1]] } : d)), 480)
8967
+ }
8968
+ // 页面自己用脚本跳了(没走我们拦下的链接):只改记下的是哪一屏,不重载
8969
+ const demoHref = (id, href) => {
8970
+ let key = ''
8971
+ try { key = keyOfPath(decodeURIComponent(new URL(href).pathname), fileTarget) } catch { return }
8972
+ setDemo((d) => {
8973
+ if (!d) return d
8974
+ const last = d.layers[d.layers.length - 1]
8975
+ if (last.id !== id || last.key === key) return d
8976
+ return { stack: [...d.stack.slice(0, -1), key], layers: d.layers.map((l) => (l.id === id ? { ...l, key } : l)) }
8977
+ })
8978
+ }
8979
+ return { demoGo, demoTo, demoRestart, demoBack, demoShown, demoHref }
8980
+ }
8981
+
8524
8982
  function PreviewTab(props) {
8525
8983
  const t = props.t
8526
8984
  const sid = props.sid || props.sessionId
@@ -8687,6 +9145,10 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
8687
9145
  const tokens = main.tokens || []
8688
9146
  const kind = (st && st.kind) || meta.kind || 'web'
8689
9147
  const size = sizeOf((st && st.size) || meta.size || autoSize(screens.map((sc) => (infoOf(ik(sc)) || {}).natural), kind), kind)
9148
+ // 网页单看、演示、对比(#20):写了画幅(meta 或 preview_page 的 size)就按画幅整屏缩放,没写就铺满右侧栏;用户在屏名菜单里切过就听用户的
9149
+ const [fitPref, setFitPref] = useState(() => { try { return localStorage.getItem('ddp-web-fit') || '' } catch { return '' } })
9150
+ const webFit = webFitOf(kind, fitPref, !!((st && st.size) || meta.size))
9151
+ const toggleFit = () => { const v = webFit ? 'fill' : 'fit'; setFitPref(v); try { localStorage.setItem('ddp-web-fit', v) } catch { /* 记不住就这次有效 */ } }
8690
9152
  const view = (st && st.view) || (screens.length >= 2 && screens.length <= 12 ? 'canvas' : 'single')
8691
9153
  const canvas = view === 'canvas'
8692
9154
  const writingNew = !!(st && st.writing) && /\.html?$/i.test(st.writing) && !screens.some((s) => s.key === st.writing)
@@ -9040,60 +9502,27 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
9040
9502
 
9041
9503
  const onEdited = (sc, d) => {
9042
9504
  if (!fileTarget) return askText(sc, d)
9043
- post('edit', { session: sid, key: pageOf(sc, d.href).key, before: d.before, after: d.after, nth: d.nth })
9044
- .then((r) => (r && r.ok ? say(t('textSaved', { file: r.file })) : askText(sc, d)), () => askText(sc, d))
9045
- }
9046
-
9047
- // 模型在干活时不能改字(它可能正整份重写文件,改了会被盖掉)
9048
- useEffect(() => { if (ver || demo || busy) setTextEdit(false) }, [!!ver, !!demo, busy])
9049
-
9050
- // ── 调样式:点一个元素,面板里拖滑块先在页面上看效果;写回文件 = 并进它在源码里的 style 属性 ──
9051
- const toggleStyle = () => {
9052
- if (styleEdit) { setStyleEdit(false); return }
9053
- setPicking(false)
9054
- setTextEdit(false)
9055
- setPanel(false)
9056
- setHist(false)
9057
- setPhone(false)
9058
- closeCheck()
9059
- setStyleEdit(true)
9060
- }
9061
- useEffect(() => { if (!styleEdit) setSty(null) }, [styleEdit])
9062
- const onStylePick = (sc, p) => {
9063
- if (canvas) setSel(sc.key)
9064
- const pg = pageOf(sc, p.href)
9065
- setSty({ key: pg.key, url: pg.url, name: p.name, selector: p.selector, text: p.text, loc: p.loc, base: p.css || {}, vars: p.vars || {}, rules: p.rules && typeof p.rules === 'object' ? p.rules : {}, gradient: !!p.gradient, layout: !!p.layout, live: {} })
9066
- }
9067
- const setStyleProp = (patch) => setSty((c) => (c ? { ...c, live: { ...c.live, ...patch } } : c))
9068
- // 交给模型:先问服务端那几条规则在源码第几行(本地文件才有;问不到就只写文件名)
9069
- const askStyle = async () => {
9070
- const s0 = sty
9071
- if (!s0) return
9072
- let located = null
9073
- const items = [...new Map(Object.keys(s0.live || {}).map((k) => s0.rules && s0.rules[k]).filter((r) => r && r.sel && r.href).map((r) => [`${r.href}|${r.sel}|${r.n}`, r])).values()]
9074
- if (fileTarget && items.length) {
9075
- try {
9076
- const r = await post('locate', { session: sid, items: items.map((x) => ({ href: x.href, sel: x.sel, n: x.n })) })
9077
- located = new Map(items.map((x, i) => [`${x.href}|${x.sel}|${x.n}`, r && Array.isArray(r.items) ? r.items[i] : null]))
9078
- } catch { /* 找不到行号就只写文件名 */ }
9079
- }
9080
- insert(formatStyleAsk(t, s0, stRef.current, located), 'insertedSend')
9505
+ post('edit', { session: sid, key: pageOf(sc, d.href).key, before: d.before, after: d.after, nth: d.nth })
9506
+ .then((r) => (r && r.ok ? say(t('textSaved', { file: r.file })) : askText(sc, d)), () => askText(sc, d))
9081
9507
  }
9082
- const saveStyle = () => {
9083
- const s0 = sty
9084
- if (!s0 || !Object.keys(s0.live).length) return
9085
- if (!fileTarget) return askStyle()
9086
- const saved = s0.live
9087
- post('style', { session: sid, key: s0.key, loc: s0.loc, css: saved, name: s0.name }).then((r) => {
9088
- if (r && r.ok) {
9089
- say(t('styleSaved', { file: r.file }))
9090
- // 写进去的算「原样」了;写的时候又拖过的留着
9091
- setSty((c) => (c && c.key === s0.key && c.selector === s0.selector
9092
- ? { ...c, base: { ...c.base, ...saved }, live: Object.fromEntries(Object.entries(c.live).filter(([k, v]) => saved[k] !== v)) } : c))
9093
- } else if (r && r.reason === 'busy') say(t('styleBusyTip'))
9094
- else { say(t('styleMiss')); askStyle() }
9095
- }, () => askStyle())
9508
+
9509
+ // 模型在干活时不能改字(它可能正整份重写文件,改了会被盖掉)
9510
+ useEffect(() => { if (ver || demo || busy) setTextEdit(false) }, [!!ver, !!demo, busy])
9511
+
9512
+ // ── 调样式:点一个元素,面板里拖滑块先在页面上看效果;写回文件 = 并进它在源码里的 style 属性 ──
9513
+ const toggleStyle = () => {
9514
+ if (styleEdit) { setStyleEdit(false); return }
9515
+ setPicking(false)
9516
+ setTextEdit(false)
9517
+ setPanel(false)
9518
+ setHist(false)
9519
+ setPhone(false)
9520
+ closeCheck()
9521
+ setStyleEdit(true)
9096
9522
  }
9523
+ useEffect(() => { if (!styleEdit) setSty(null) }, [styleEdit])
9524
+ // 调样式:选中、预览、交给模型、写回(makeStyleEdit)
9525
+ const { onStylePick, setStyleProp, askStyle, saveStyle } = makeStyleEdit({ sid, stRef, fileTarget, canvas, setSel, sty, setSty, insert, say, t })
9097
9526
  useEffect(() => {
9098
9527
  if (!styleEdit) return undefined
9099
9528
  const onKey = (e) => { if (e.key === 'Escape' && !overlayUp()) setStyleEdit(false) }
@@ -9136,44 +9565,8 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
9136
9565
  const inf = infoOf(key)
9137
9566
  if (inf && !(inf.links || []).length) say(t('demoNone'))
9138
9567
  }
9139
- const demoGo = (path) => demoTo(keyOfPath(path, fileTarget))
9140
- const demoTo = (key) => {
9141
- setDemo((d) => {
9142
- if (!d) return d
9143
- const top = d.stack[d.stack.length - 1]
9144
- if (key === top) return d
9145
- const back = d.stack.length > 1 && d.stack[d.stack.length - 2] === key
9146
- const stack = back ? d.stack.slice(0, -1) : [...d.stack, key].slice(-30)
9147
- const last = d.layers[d.layers.length - 1]
9148
- return { stack, layers: [last, { id: ++demoSeq.current, key, dir: back ? -1 : 1, shown: false }] }
9149
- })
9150
- }
9151
- const demoRestart = () => setDemo((d) => {
9152
- if (!d || d.stack.length < 2) return d
9153
- const last = d.layers[d.layers.length - 1]
9154
- return { stack: [d.stack[0]], layers: [last, { id: ++demoSeq.current, key: d.stack[0], dir: -1, shown: false }] }
9155
- })
9156
- const demoBack = () => setDemo((d) => {
9157
- if (!d || d.stack.length < 2) return d
9158
- const stack = d.stack.slice(0, -1)
9159
- const last = d.layers[d.layers.length - 1]
9160
- return { stack, layers: [last, { id: ++demoSeq.current, key: stack[stack.length - 1], dir: -1, shown: false }] }
9161
- })
9162
- const demoShown = (id) => {
9163
- setDemo((d) => (d ? { ...d, layers: d.layers.map((l) => (l.id === id ? { ...l, shown: true } : l)) } : d))
9164
- setTimeout(() => setDemo((d) => (d && d.layers.length > 1 && d.layers[d.layers.length - 1].id === id ? { ...d, layers: [d.layers[d.layers.length - 1]] } : d)), 480)
9165
- }
9166
- // 页面自己用脚本跳了(没走我们拦下的链接):只改记下的是哪一屏,不重载
9167
- const demoHref = (id, href) => {
9168
- let key = ''
9169
- try { key = keyOfPath(decodeURIComponent(new URL(href).pathname), fileTarget) } catch { return }
9170
- setDemo((d) => {
9171
- if (!d) return d
9172
- const last = d.layers[d.layers.length - 1]
9173
- if (last.id !== id || last.key === key) return d
9174
- return { stack: [...d.stack.slice(0, -1), key], layers: d.layers.map((l) => (l.id === id ? { ...l, key } : l)) }
9175
- })
9176
- }
9568
+ // 演示里跳屏、返回、从头来(makeDemoNav)
9569
+ const { demoGo, demoTo, demoRestart, demoBack, demoShown, demoHref } = makeDemoNav({ setDemo, demoSeq, fileTarget })
9177
9570
  useEffect(() => {
9178
9571
  if (!demo) return undefined
9179
9572
  const onKey = (e) => { if (e.key === 'Escape' && !overlayUp()) setDemo(null) }
@@ -9227,198 +9620,37 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
9227
9620
 
9228
9621
  // 画布上屏太多、离镜头远的:先不挂 iframe,放一张后台截的缩略图(issue #17),截不到就是「挪近就加载」。
9229
9622
  // 本地文件的设计才有图(开发服务器的页面不在后台另开);看旧版本时也没有。目录里一有改动地址就变,没变的那几屏服务端直接给缓存。
9230
- // 地址带上目录:换了设计服务端就不给(晚到的回包也不会把上一套的图挂到这套上);换设计 / 画幅 / 深浅色时整个 Snap 重来,不留旧图
9231
- const snapId = fileTarget && sid ? `session=${encodeURIComponent(sid)}&root=${encodeURIComponent(curRoot)}&w=${size[0]}&h=${size[1]}&dark=${dark ? 1 : 0}` : ''
9232
- const snapQ = snapId ? `${snapId}&r=${(st && st.changedAt) || 0}&t=${encodeURIComponent((st && st.trust) || '')}&lw=${encodeURIComponent((st && st.watch) || '')}` : ''
9233
- const sleepScreen = (sc, z) => h(Device, { kind, w: size[0], h: size[1], fill: false, label: labelOf(sc), top: tops[ik(sc)], os: meta.os },
9234
- h('div', { className: 'ddp-scr' + (dark ? ' dk' : '') },
9235
- h('div', { className: 'ddp-away', style: { fontSize: 13 / Math.max(0.25, z || 1) } }, t('canvasAsleep')),
9236
- snapQ && !sc.v ? h(Snap, { key: snapId + '&key=' + sc.key, src: `${API}scrthumb?${snapQ}&key=${encodeURIComponent(sc.key)}`, blind: /^off/.test((st && st.watch) || ''), onTitle: (title) => snapTitled(sc.key, title) }) : null))
9237
-
9238
- // ── 导出图片 ──
9239
- // 截一屏:图片和它的 CSS 尺寸(PDF / PPT 按这个定页面大小)
9240
- // 那一屏的接口(截图、体检);刚载入的等它就绪
9241
- const apiOf = async (sc, map = apis.current) => {
9242
- const tries = map === apis.current ? 40 : 120 // 背后现挂的要等它载完
9243
- let api = map.get(ik(sc))
9244
- for (let i = 0; i < tries && !(api && api.ready()); i++) {
9245
- await new Promise((r) => setTimeout(r, 150))
9246
- api = map.get(ik(sc))
9247
- }
9248
- if (!api) throw new Error('not loaded')
9249
- return api
9250
- }
9251
- // 这次导出截到的 AI 示意图(文件名去重):每种导出结束的提示里都带一句「上线前换成真实照片」
9252
- const aiTail = (ai) => (ai && ai.size ? ' · ' + t('xoAi', { n: ai.size }) : '')
9253
- const captureOf = async (sc, full, map, maxH, ai) => {
9254
- const api = await apiOf(sc, map)
9255
- const r = await api.capture({ full: !!full, scale: 2, ...(maxH ? { maxH } : {}) })
9256
- if (ai && Array.isArray(r.aiPhotos)) for (const x of r.aiPhotos) ai.add(x)
9257
- 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() }
9258
- }
9259
- // 导出用的标题:屏多的时候有的屏没在画布上挂过,手上没有它的标题,用截图时页面报的
9260
- const exportTitle = (sc, r) => (infoOf(ik(sc)) || {}).title || r.title || sc.label
9261
-
9262
- const targetKey = st && st.target ? (st.target.kind === 'file' ? `file|${st.target.root}` : `proxy|${st.target.port}`) : ''
9263
- const saveImage = async (name, blob, ai) => {
9264
- const png = await blobB64(blob)
9265
- const r = await post('export', { session: sid, name, png, target: targetKey })
9266
- const copied = await copyImage(blob)
9267
- const file = String(r.path || '').split(/[\\/]/).pop()
9268
- say(t(copied ? 'exportedCopied' : 'exported', { name: file }) + aiTail(ai), { label: t('reveal'), run: () => post('reveal', { path: r.path }).catch(() => {}) })
9269
- }
9270
-
9271
- const designId = JSON.stringify([sid, targetKey, ver ? ver.n : 0])
9272
- if (designNow.current !== designId) { designNow.current = designId; designSeq.current++ }
9273
- // 单看时只挂着正在看的那屏;要所有屏(PDF、PPT、拼图、预检)时按画幅大小在背后挂上,用完就撤
9274
- const withFrames = async (fn, only) => {
9275
- if (!only && ((canvas && shown.length <= LIVE_MAX) || shown.length < 2)) return fn(apis.current)
9276
- // 网页单看时铺满右侧栏,和画幅不一样宽,都在背后重挂;别的类型正在看的那屏直接用(滚动位置、打开的弹窗都还在)
9277
- // 画布屏多的时候镜头一动画布上的屏就会撤,也都在背后挂
9278
- const stamp = designSeq.current
9279
- const run = async () => {
9280
- if (designSeq.current !== stamp) throw new Error('designChanged') // 排队的时候换了设计
9281
- // 轮到了才算要挂哪些:排队时前台可能已经换了一屏
9282
- const list = only || (canvas || kind === 'web' ? shown : shown.filter((sc) => !apis.current.has(ik(sc))))
9283
- const back = new Set(list.map(ik))
9284
- const place = new Map(list.map((sc, i) => [ik(sc), i]))
9285
- // 屏多的时候分批挂:只挂轮到的这一批,别几十个一起跑
9286
- let at = 0
9287
- // 每个任务一批新的 iframe:上一批的深浅色、接口都不留(不然拿到上一批「已就绪」的就截了)
9288
- ghostApis.current.clear()
9289
- setBackFrames({ list, size, at, dark, batch: ++ghostBatch.current }) // 深浅色跟点导出时的走,和文件名对得上
9290
- const get = (k) => {
9291
- const i = place.get(k)
9292
- if (i !== undefined && (i < at || i >= at + LIVE_MAX)) { at = i; setBackFrames((b) => (b ? { ...b, at: i } : b)) }
9293
- return (back.has(k) ? ghostApis.current : apis.current).get(k)
9294
- }
9295
- try { return await fn({ get }) } finally { setBackFrames(null) }
9296
- }
9297
- // 背后挂的屏一次只给一个任务用(预检和导出撞上,会互相把对方要的那批撤掉)
9298
- const job = ghostQueue.current.then(run, run)
9299
- ghostQueue.current = job.catch(() => {})
9300
- return job
9301
- }
9302
- const measureAll = async (map) => {
9303
- const stamp = designSeq.current
9304
- const list = []
9305
- for (const sc of shown) {
9306
- if (designSeq.current !== stamp) break // 设计换了:别再等旧的屏
9307
- try { const api = await apiOf(sc, map); list.push(await api.measure()) } catch (e) { console.warn('[dsh-design-studio] 量页面失败', sc.key, e); list.push({ failed: true }) }
9308
- }
9309
- return list
9310
- }
9311
-
9312
- const doExport = async (mode, key, opts) => {
9313
- setExMenu(false)
9314
- if (mode === 'opts') { if (pane !== 'export') openPane('export'); return }
9315
- if (mode === 'zip') return openPack(fileTarget ? st.target.root : '')
9316
- if (mode === 'share') return openShare(fileTarget ? st.target.root : '')
9317
- say(t('exporting'))
9318
- const design = designNow.current
9319
- const stamp = designSeq.current
9320
- const gone = () => designSeq.current !== stamp
9321
- const aiShot = new Set() // 这次导出截到的 AI 示意图(每次导出各记各的,连着导出不串)
9322
- try {
9323
- const prefix = ver ? `v${ver.n}-` : ''
9324
- const suffix = dark ? '-dark' : ''
9325
- if (mode === 'pdf' || mode === 'pptx') {
9326
- // 每屏一页。PDF 里网页、邮件放整页长图(页面多高就多高);PPT 一张幻灯片一个画面。选项面板里可以改
9327
- const fit = (opts && opts.fit) || ''
9328
- const long = fit === 'page' || fit === 'height' || (!fit && mode === 'pdf' && (kind === 'web' || kind === 'email'))
9329
- const maxH = fit === 'height' ? Number(opts.fitH) || 0 : 0
9330
- let deadN = 0
9331
- await withFrames(async (map) => {
9332
- // 从菜单直接点:先量一遍,有内容会被裁就先给看清单(同样的结果只拦一次)
9333
- if (!opts) {
9334
- const seen = await measureAll(map)
9335
- const rep = precheckOf(seen, kind, long ? Infinity : 0)
9336
- deadN = rep.dead
9337
- 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('|') : ''
9338
- if (sig && warned.current !== sig) {
9339
- warned.current = sig
9340
- say(t('xoWarn'))
9341
- if (pane !== 'export') openPane('export')
9342
- return
9343
- }
9344
- }
9345
- const pages = []
9346
- const keys = []
9347
- for (const sc of shown) {
9348
- if (gone()) break
9349
- try {
9350
- const r = await captureOf(sc, long, map, maxH, aiShot)
9351
- const cut = maxH && r.h > maxH
9352
- 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 })
9353
- keys.push(sc.key)
9354
- } catch (e) { console.warn('[dsh-design-studio] 截图失败', sc.key, e) }
9355
- }
9356
- if (gone()) { say(t('xoGone')); return }
9357
- if (!pages.length) throw new Error('no screens')
9358
- // 原型里的跳转:路径换成第几页,PDF / PPT 里点了能跳过去
9359
- for (const p of pages) {
9360
- p.links = p.links.map((l) => ({ x: l.x, y: l.y, w: l.w, h: l.h, to: keys.indexOf(keyOfPath(l.path, fileTarget)) })).filter((l) => l.to >= 0)
9361
- }
9362
- const sp = splitTitles(pages.map((x) => x.title))
9363
- const folder = st && st.target && st.target.kind === 'file' ? String(st.target.file).split(/[\\/]/).slice(-2, -1)[0] : ''
9364
- const title = sp.brand || folder || st.label || ''
9365
- const layout = opts ? (opts.layout === 'custom' ? opts.custom.trim() : opts.layout === 'auto' ? '' : opts.layout) : ''
9366
- const cols = opts && opts.cols === 2 ? 2 : 1
9367
- const r = await post('doc', { session: sid, format: mode, name: prefix + (title || 'design') + suffix, title, bg: hexOf(pickColors(tokens).bg), pages, layout, cols, target: targetKey })
9368
- const file = String(r.path || '').split(/[\\/]/).pop()
9369
- const miss = shown.length - pages.length
9370
- const sheets = Math.ceil(pages.length / cols)
9371
- 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(() => {}) })
9372
- })
9373
- return
9374
- }
9375
- if (mode === 'show') {
9376
- const shots = []
9377
- await withFrames(async (map) => {
9378
- for (const sc of shown) {
9379
- if (gone()) break
9380
- 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) }
9381
- }
9382
- })
9383
- if (gone()) { say(t('xoGone')); return }
9384
- if (!shots.length) throw new Error('no screens')
9385
- const sp = splitTitles(shots.map((x) => x.title))
9386
- const colors = pickColors(tokens)
9387
- const blob = await composeShowcase({
9388
- kind,
9389
- size,
9390
- shots: shots.map((x, i) => ({ img: x.img, top: x.top, label: sp.labels[i] || x.title })),
9391
- os: meta.os,
9392
- title: sp.brand || (st && st.target && st.target.kind === 'file' ? String(st.target.file).split(/[\\/]/).slice(-2, -1)[0] : st.label) || '',
9393
- sub: t('showSub', { n: shots.length, kind: t(KIND_KEY[kind]), date: ymd(new Date()) }),
9394
- bg: colors.bg,
9395
- accent: colors.accent || ACCENT,
9396
- mark: t('madeWith'),
9397
- })
9398
- await saveImage(prefix + (sp.brand || 'showcase') + suffix, blob, aiShot)
9399
- return
9400
- }
9401
- const k = key || (canvas ? sel || focus : focus)
9402
- const sc = shown.find((x) => x.key === k) || shown[0]
9403
- if (!sc) throw new Error('no screen')
9404
- const base = prefix + sc.key.replace(/\.html?$/i, '') + suffix
9405
- // 画布屏多的时候这屏可能没挂着(镜头一动也可能撤掉):在背后单独挂一份来截
9406
- let shot = null
9407
- if (canvas && shown.length > LIVE_MAX) await withFrames(async (map) => { shot = await captureOf(sc, mode === 'long', map, 0, aiShot) }, [sc])
9408
- else shot = await captureOf(sc, mode === 'long', undefined, 0, aiShot)
9409
- if (gone()) { say(t('xoGone')); return }
9410
- const { img, top } = shot
9411
- if (mode === 'frame') await saveImage(base, await composeOne(kind, size, img, labelOf(sc), top, meta.os), aiShot)
9412
- else {
9413
- const c = document.createElement('canvas')
9414
- c.width = img.width
9415
- c.height = img.height
9416
- c.getContext('2d').drawImage(img, 0, 0)
9417
- await saveImage(base + (mode === 'long' ? '-full' : mode === 'raw' && FRAMED[kind] ? '-plain' : ''), await canvasBlob(c), aiShot)
9418
- }
9419
- } catch (e) {
9420
- say(e.message === 'designChanged' ? t('xoGone') : t('exportFail', { msg: e.message }))
9623
+ // 地址带上目录:换了设计服务端就不给(晚到的回包也不会把上一套的图挂到这套上);换设计 / 画幅 / 深浅色时整个 Snap 重来,不留旧图
9624
+ const snapId = fileTarget && sid ? `session=${encodeURIComponent(sid)}&root=${encodeURIComponent(curRoot)}&w=${size[0]}&h=${size[1]}&dark=${dark ? 1 : 0}` : ''
9625
+ const snapQ = snapId ? `${snapId}&r=${(st && st.changedAt) || 0}&t=${encodeURIComponent((st && st.trust) || '')}&lw=${encodeURIComponent((st && st.watch) || '')}` : ''
9626
+ const sleepScreen = (sc, z) => h(Device, { kind, w: size[0], h: size[1], fill: false, label: labelOf(sc), top: tops[ik(sc)], os: meta.os },
9627
+ h('div', { className: 'ddp-scr' + (dark ? ' dk' : '') },
9628
+ h('div', { className: 'ddp-away', style: { fontSize: 13 / Math.max(0.25, z || 1) } }, t('canvasAsleep')),
9629
+ snapQ && !sc.v ? h(Snap, { key: snapId + '&key=' + sc.key, src: `${API}scrthumb?${snapQ}&key=${encodeURIComponent(sc.key)}`, blind: /^off/.test((st && st.watch) || ''), onTitle: (title) => snapTitled(sc.key, title) }) : null))
9630
+
9631
+ // 那一屏的接口(截图、体检、业务标注都用);刚载入的等它就绪
9632
+ const apiOf = async (sc, map = apis.current) => {
9633
+ const tries = map === apis.current ? 40 : 120 // 背后现挂的要等它载完
9634
+ let api = map.get(ik(sc))
9635
+ for (let i = 0; i < tries && !(api && api.ready()); i++) {
9636
+ await new Promise((r) => setTimeout(r, 150))
9637
+ api = map.get(ik(sc))
9421
9638
  }
9639
+ if (!api) throw new Error('not loaded')
9640
+ return api
9641
+ }
9642
+ const targetKey = st && st.target ? (st.target.kind === 'file' ? `file|${st.target.root}` : `proxy|${st.target.port}`) : ''
9643
+ // ── 导出图片(makeExporter)──
9644
+ const { withFrames, measureAll, exportShots } = makeExporter({ apiOf, targetKey, sid, st, kind, size, dark, meta, tokens, t, say, canvas, focus, sel, shown, ik, labelOf, infoOf, fileTarget, ver, apis, designNow, designSeq, ghostApis, ghostBatch, ghostQueue, setBackFrames, warned,
9645
+ onWarn: () => { if (pane !== 'export') openPane('export') } })
9646
+ const designId = JSON.stringify([sid, targetKey, ver ? ver.n : 0])
9647
+ if (designNow.current !== designId) { designNow.current = designId; designSeq.current++ }
9648
+ const doExport = async (mode, key, opts) => {
9649
+ setExMenu(false)
9650
+ if (mode === 'opts') { if (pane !== 'export') openPane('export'); return }
9651
+ if (mode === 'zip') return openPack(fileTarget ? st.target.root : '')
9652
+ if (mode === 'share') return openShare(fileTarget ? st.target.root : '')
9653
+ return exportShots(mode, key, opts)
9422
9654
  }
9423
9655
 
9424
9656
  const doRestore = () => {
@@ -9491,56 +9723,13 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
9491
9723
  const sizeSet = SIZE_SETS[kind] || null
9492
9724
  const inMulti = multi && !!sizeSet && !ver
9493
9725
  // 单页看手机 / 平板时,选择、改字的提示条放在设备上方,给它让出一条(不然压住设备顶边)
9494
- const hintTop = (picking || textEdit) && !canvas && !inMulti && !ver && !demo && kind !== 'web'
9726
+ const hintTop = (picking || textEdit) && !canvas && !inMulti && !ver && !demo && (kind !== 'web' || webFit) // 网页按画幅缩放时也和设备一样让出一条(#20)
9495
9727
  const flows = canvas && !inMulti && !picking && !textEdit ? flowsOf(shown, (sc) => (infoOf(ik(sc)) || {}).links, fileTarget) : []
9496
9728
 
9497
9729
  // ── 设计体检:画布上量所有屏,单页量这一屏;问题标在页面上,列在面板里 ──
9498
- const closeCheck = () => {
9499
- ckGen.current++
9500
- ckOpen.current = false
9501
- if (ck) for (const sc of ck.list || []) { const a = apis.current.get(ik(sc)); if (a) a.checkClear() }
9502
- setCk(null)
9503
- }
9504
- // 画布屏多的时候只量挂着的(别的没有页面可量)
9505
- const checkList = () => (canvas ? (shown.length > LIVE_MAX ? shown.filter((sc) => apis.current.has(ik(sc))) : shown) : [shown.find((x) => x.key === focus) || { key: focus, url, label: st.label }])
9506
- // 几屏一起量(各量各的 iframe),一屏卡住不拖累别的
9507
- const measure = (list, quiet) => Promise.all(list.map(async (sc) => {
9508
- const row = { key: sc.key, v: sc.v, label: labelOf(sc), url: sc.url, issues: [] }
9509
- try {
9510
- const r = await (await apiOf(sc)).check(kind, quiet)
9511
- row.issues = Array.isArray(r.issues) ? r.issues : []
9512
- if (r.metrics && typeof r.metrics === 'object') row.metrics = r.metrics
9513
- } catch (e) { row.error = e.message }
9514
- return row
9515
- }))
9516
- const total = (list) => list.reduce((m, x) => m + x.issues.length, 0)
9517
- const runCheck = async () => {
9518
- setPanel(false); setHist(false); setPhone(false); setAn(false)
9519
- setCk({ running: true, list: [] })
9520
- const g = ++ckGen.current
9521
- ckOpen.current = true
9522
- const out = await measure(checkList(), false)
9523
- if (g !== ckGen.current) { // 量的时候面板关了 / 又量了一轮:这份结果作废;面板关着的话,这一轮画上的标记也清掉
9524
- if (!ckOpen.current) for (const sc of out) { const a = apis.current.get(ik(sc)); if (a) a.checkClear() }
9525
- return out
9526
- }
9527
- if (canvas && shown.length > LIVE_MAX) say(t('checkPartial', { n: out.length }))
9528
- setCk({ running: false, list: out })
9529
- setCkCount(total(out))
9530
- // 有问题的第一屏被面板挡着、在画布外面:挪过来
9531
- const first = out.find((x) => x.issues.length)
9532
- if (canvas && first) setReveal((r) => ({ key: first.key, n: ((r && r.n) || 0) + 1 }))
9533
- return out
9534
- }
9535
- const focusIssue = (key, i) => {
9536
- const sc = (ck && ck.list.find((x) => x.key === key)) || null
9537
- if (!sc) return
9538
- if (canvas) { setSel(key); setReveal((r) => ({ key, n: ((r && r.n) || 0) + 1 })) }
9539
- // 屏多的时候这屏可能撤过(重新载入后页面里的体检标记没了):等它挂上,量一遍再定位
9540
- if (canvas && shown.length > LIVE_MAX) { apiOf(sc).then((api) => api.check(kind, false).then(() => api.checkFocus(i))).catch((e) => console.warn('[dsh-design-studio] 定位问题失败', key, e)); return }
9541
- const a = apis.current.get(ik(sc))
9542
- if (a) a.checkFocus(i)
9543
- }
9730
+ // 设计体检:量、开面板、定位、交给模型(makeCheck)
9731
+ const { closeCheck, checkList, measure, total, runCheck, focusIssue, fixIssues } = makeCheck({ kind, url, st, stRef, canvas, shown, focus, ik, labelOf, apis, apiOf, ck, setCk, ckGen, ckOpen, setCkCount, setReveal, setSel, insert, say, t,
9732
+ onOpen: () => { setPanel(false); setHist(false); setPhone(false); setAn(false) } })
9544
9733
  // 打开一套设计、模型又干完一轮(turns 变了):面板开着就再查一次(改没改好一眼看到);关着就悄悄量一下,问题数标在按钮上。
9545
9734
  // 模型干着活时不量;等一会儿再量:刚写完的屏还在刷新、播生成动画
9546
9735
  const autoCk = useRef(null)
@@ -9581,13 +9770,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
9581
9770
  }, 1500)
9582
9771
  return () => clearTimeout(timer)
9583
9772
  }, [ckReq])
9584
- const fixIssues = () => {
9585
- if (!ck) return
9586
- insert(formatCheck(t, ck.list, stRef.current), 'insertedSend')
9587
- closeCheck()
9588
- }
9589
9773
  const checkOff = !url || !!ver || !!demo || inMulti
9590
-
9591
9774
  // ── 业务标注(插件页的试验开关开着才有 st.annotations 这个键):面板和体检、版本共用右边那个位置;点选、改字、调样式、画笔时编号收起,退出后回来 ──
9592
9775
  useEffect(() => { setAnStates({}) }, [anFile ? anFile.sig : '']) // 文件变了(模型改过选择器):别的屏的旧结果作废,等页面重新报
9593
9776
  const toggleAn = () => {
@@ -9643,185 +9826,8 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
9643
9826
  // 换了设计、看旧版本、演示:画的东西对不上了,收掉
9644
9827
  useEffect(() => { markRun.current++; setMark(false) }, [url, markOff])
9645
9828
  // 台面上现在看得到的每一屏:页面 iframe 的位置(台面坐标,画布缩放过的也对),一点没露出来的不要
9646
- const markFrames = () => {
9647
- const stage = stageRef.current
9648
- if (!stage) return []
9649
- const sr = stage.getBoundingClientRect()
9650
- const out = []
9651
- for (const sc of shown) {
9652
- const api = apis.current.get(ik(sc))
9653
- const f = api && typeof api.frame === 'function' ? api.frame() : null
9654
- if (!f) continue
9655
- const r = f.getBoundingClientRect()
9656
- if (r.width < 8 || r.height < 8 || r.right <= sr.left || r.left >= sr.right || r.bottom <= sr.top || r.top >= sr.bottom) continue
9657
- if (typeof f.checkVisibility === 'function' && !f.checkVisibility({ opacityProperty: true, visibilityProperty: true })) continue
9658
- out.push({ key: ik(sc), sc, api, f, l: r.left - sr.left, t: r.top - sr.top, w: r.width, h: r.height, z: r.width / Math.max(1, f.offsetWidth) })
9659
- }
9660
- return out
9661
- }
9662
- const MARK_SHOTS = 40
9663
- // 截到的是哪一页(只用来起名、写进提示):本地文件按文件名;开发服务器按路由(/account);单页应用的 #/account 路由带上
9664
- const markPageOf = (sc, href) => {
9665
- let key = pageOf(sc, href).key
9666
- try {
9667
- const u = new URL(href)
9668
- if (u.origin !== new URL(sc.url).origin) return key
9669
- if (key === sc.key && st && st.target && st.target.kind === 'proxy') key = decodeURIComponent(u.pathname) || sc.key
9670
- if (/^#!?\//.test(u.hash)) key += decodeURIComponent(u.hash)
9671
- } catch { /* 地址不对 */ }
9672
- return key
9673
- }
9674
- // 把画的拼成一张图:画到的那几屏按现在的位置截图,叠上画的(交给模型、复制共用)
9675
- const buildMark = async (list, stage) => {
9676
- const sr = stage.getBoundingClientRect()
9677
- const all = markFrames().filter((x) => x.api.ready())
9678
- const ov = (a, b) => a.l < b.r && a.r > b.l && a.t < b.b && a.b > b.t
9679
- const boxOf = (x) => ({ l: x.l, t: x.t, r: x.l + x.w, b: x.t + x.h })
9680
- // 画到的那几屏(一屏都没碰到:画在屏外空白处的,就把看得到的都拼上)
9681
- const marks = list.map(markBox)
9682
- let shots = all.filter((x) => marks.some((m) => ov(boxOf(x), m)))
9683
- if (!shots.length) shots = all
9684
- // 裁到有东西的那块(画到的屏 + 画的),四周留一点;落在这块里的别的屏也拼上,免得图上空一块
9685
- const pad = 16
9686
- const span = (bs) => ({
9687
- l: Math.max(0, Math.min(...bs.map((b) => b.l)) - pad),
9688
- t: Math.max(0, Math.min(...bs.map((b) => b.t)) - pad),
9689
- r: Math.min(sr.width, Math.max(...bs.map((b) => b.r)) + pad),
9690
- b: Math.min(sr.height, Math.max(...bs.map((b) => b.b)) + pad),
9691
- })
9692
- const crop = span([...shots.map(boxOf), ...marks])
9693
- shots = all.filter((x) => shots.includes(x) || ov(boxOf(x), crop))
9694
- const { l: cl, t: ct, r: cr, b: cb } = crop
9695
- if (!(cr - cl >= 1 && cb - ct >= 1)) throw new Error('empty')
9696
- // 清晰度:至少按屏幕像素;画布缩小着看的,按页面原来的大小截(最多 4 倍),整张不超过 4096
9697
- const zMin = Math.min(1, ...shots.map((x) => x.z))
9698
- const k = Math.min(4096 / Math.max(cr - cl, cb - ct), Math.max(Math.min(2, Math.max(1, window.devicePixelRatio || 1)), Math.min(4, 1 / Math.max(0.05, zMin))))
9699
- const c = document.createElement('canvas')
9700
- c.width = Math.max(1, Math.round((cr - cl) * k))
9701
- c.height = Math.max(1, Math.round((cb - ct) * k))
9702
- const ctx = c.getContext('2d')
9703
- let bg = ''
9704
- for (let el = stage; el && !bg; el = el.parentElement) {
9705
- const v = getComputedStyle(el).backgroundColor
9706
- if (v && !/^(transparent|rgba\(.*,\s*0\))$/.test(v)) bg = v
9707
- }
9708
- ctx.fillStyle = bg || '#f4f4f5'
9709
- ctx.fillRect(0, 0, c.width, c.height)
9710
- if (shots.length > MARK_SHOTS) say(t('mkMany', { n: MARK_SHOTS }))
9711
- const names = []
9712
- for (const [i, x] of shots.entries()) {
9713
- const X = (x.l - cl) * k
9714
- const Y = (x.t - ct) * k
9715
- // 手机框的圆角:往上找一层裁圆角的
9716
- let rad = 0
9717
- for (let el = x.f.parentElement, j = 0; el && el !== stage && j < 4 && !rad; el = el.parentElement, j++) {
9718
- const cs = getComputedStyle(el)
9719
- const v = parseFloat(cs.borderTopLeftRadius) || 0
9720
- if (v && cs.overflow !== 'visible' && el.offsetWidth) rad = v * (el.getBoundingClientRect().width / el.offsetWidth)
9721
- }
9722
- ctx.save()
9723
- ctx.beginPath()
9724
- if (rad && typeof ctx.roundRect === 'function') ctx.roundRect(X, Y, x.w * k, x.h * k, rad * k)
9725
- else ctx.rect(X, Y, x.w * k, x.h * k)
9726
- ctx.clip()
9727
- let name = x.sc.key
9728
- try {
9729
- if (i >= MARK_SHOTS) throw new Error('too many')
9730
- const cap = await x.api.capture({ full: false, scale: Math.min(3, Math.max(1, x.z * k)) })
9731
- // 页面里点链接跳到别的页了:按真正截到的那页起名
9732
- if (cap.href) name = markPageOf(x.sc, cap.href)
9733
- const img = await loadImg(cap.png)
9734
- ctx.fillStyle = '#fff'
9735
- ctx.fillRect(X, Y, x.w * k, x.h * k)
9736
- ctx.drawImage(img, X, Y, cap.w * x.z * k, cap.h * x.z * k)
9737
- } catch (e) {
9738
- // 这一屏截不下来:留个灰块,画的东西还在
9739
- if (i < MARK_SHOTS) console.warn('[dsh-design-studio] 标注截图失败', x.sc.key, e)
9740
- ctx.fillStyle = 'rgba(127,127,127,.18)'
9741
- ctx.fillRect(X, Y, x.w * k, x.h * k)
9742
- }
9743
- ctx.restore()
9744
- if (!names.includes(name)) names.push(name)
9745
- }
9746
- for (const s of list) drawMark(ctx, s, k, cl, ct)
9747
- return { c, names, blob: await canvasBlob(c) }
9748
- }
9749
- const sendMark = async (list) => {
9750
- if (markBusy) return
9751
- if (!list.length) { say(t('mkEmpty')); return }
9752
- const stage = stageRef.current
9753
- if (!stage) return
9754
- const url0 = url
9755
- const run0 = markRun.current
9756
- const stale = () => stRef.current.url !== url0 || markRun.current !== run0
9757
- const root0 = st && st.target && st.target.kind === 'file' ? st.target.root : null
9758
- setMarkBusy(true)
9759
- try {
9760
- const { c, names, blob } = await buildMark(list, stage)
9761
- // 拼图的时候换了设计、关了标注:这张图对不上了,别交
9762
- if (stale()) { if (stRef.current.url !== url0) say(t('mkMoved')); return }
9763
- if (!names.length && curScreen) names.push(curScreen.key)
9764
- const stem = String(names[0] || 'page').replace(/\.html?(?=$|#)/i, '').split(/[/#!]+/).filter(Boolean).pop() || 'page'
9765
- const body = { session: sid, name: `markup-${stem}`, data: await blobB64(blob) }
9766
- if (root0 !== null) body.root = root0
9767
- let saved
9768
- try { saved = await post('ref', body) } catch (e) {
9769
- if (/moved/.test(e.message)) { say(t('mkMoved')); return }
9770
- throw e
9771
- }
9772
- if (stale()) { if (stRef.current.url !== url0) say(t('mkMoved')); return }
9773
- keepThumb(saved.path, c)
9774
- const where = (names.length ? names : [st.label || '']).join(t('sep'))
9775
- // 写在图上的字也用文字带上:模型看图看漏了、或者用的模型看不了图,也知道要改什么
9776
- const notes = list.filter((x) => x.t === 'text').map((x) => t('mkQuote', { v: x.v.replace(/\s*\n\s*/g, ' ') })).join(t('sep'))
9777
- // 插不进输入框:标注层留着(画的还在),提示再点一次;不退回剪贴板
9778
- if (insert(t('mkAsk', { path: saved.path, where, notes: notes ? t('mkNotes', { notes }) : '' }), 'mkIn', false)) setMark(false)
9779
- else say(t('mkNoInput'))
9780
- } catch (e) {
9781
- say(t('mkFail', { msg: e.message }))
9782
- } finally {
9783
- setMarkBusy(false)
9784
- }
9785
- }
9786
- // 复制:同一张图放进剪贴板(issue #6)。点按钮这一下就把「等图拼好」交给剪贴板——拼完再写,
9787
- // Safari 这类会说不是用户点的、不让写;不认这种写法的再用拼好的图写一次
9788
- const copyMark = (list) => {
9789
- if (markBusy) return
9790
- if (!list.length) { say(t('mkEmpty')); return }
9791
- const stage = stageRef.current
9792
- if (!stage) return
9793
- const url0 = url
9794
- const run0 = markRun.current
9795
- const stale = () => stRef.current.url !== url0 || markRun.current !== run0
9796
- const STALE = 'ddp-mark-stale'
9797
- setMarkBusy(true)
9798
- const made = buildMark(list, stage).then((r) => { if (stale()) throw new Error(STALE); return r })
9799
- const png = made.then((r) => r.blob)
9800
- png.catch(() => {}) // 结果在下面看
9801
- let wrote
9802
- try { wrote = navigator.clipboard.write([new ClipboardItem({ 'image/png': png })]) } catch (e) { wrote = Promise.reject(e) }
9803
- wrote.catch(() => {})
9804
- ;(async () => {
9805
- try {
9806
- const r = await made
9807
- if (!(await wrote.then(() => true, () => false))) {
9808
- // 等写的工夫里取消了、换了设计:别再把这张旧图写进去
9809
- if (stale()) { if (stRef.current.url !== url0) say(t('mkMoved')); return }
9810
- if (!(await copyImage(r.blob))) { say(t('mkCopyFail')); return }
9811
- }
9812
- if (stale()) return
9813
- say(t('mkCopied'))
9814
- setMark(false)
9815
- } catch (e) {
9816
- if (e && e.message === STALE) { if (stRef.current.url !== url0) say(t('mkMoved')) } else {
9817
- console.warn('[dsh-design-studio] 标注图复制失败', e)
9818
- say(t('mkCopyFail'))
9819
- }
9820
- } finally {
9821
- setMarkBusy(false)
9822
- }
9823
- })()
9824
- }
9829
+ // 画笔标注:拼图、交给模型、复制(makeMarkup)
9830
+ const { markFrames, sendMark, copyMark } = makeMarkup({ sid, st, stRef, url, shown, ik, apis, stageRef, markRun, markBusy, setMarkBusy, setMark, curScreen, insert, say, t })
9825
9831
  useEffect(() => { if (styleOff) setStyleEdit(false) }, [styleOff])
9826
9832
  autoCk.current = { ck, off: checkOff, run: runCheck, list: checkList, measure }
9827
9833
  // 屏数超过上限:不声不响地少几屏,用户会以为没生成
@@ -9936,6 +9942,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
9936
9942
  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
9943
  onPick: pickScreen, onAll: toCanvas, onOther: () => setEditing(true),
9938
9944
  sizes: mark ? null : { on: inMulti, off: !sizeSet || !!ver, tip: sizeSet ? t('sizes') : t('sizesNo'), note: sizeSet ? '' : t('sizesNoShort'), run: () => setMulti(!inMulti) },
9945
+ fit: kind === 'web' && !mark ? { on: webFit, note: size.join('×'), run: toggleFit } : null,
9939
9946
  kind, onKind: mark ? null : (k) => change({ kind: k }) })),
9940
9947
  h('div', { className: 'ddp-isl tr' },
9941
9948
  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 +10329,10 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
10322
10329
  const cvBody = !demo && (inMulti || (canvas && !(ver && cmp)))
10323
10330
  let body
10324
10331
  let busyGap = false
10332
+ // 单看、演示、对比共用:网页铺满右侧栏(没开「按画幅显示」时),别的按画幅整屏缩放
10333
+ const fill = kind === 'web' && !webFit
10334
+ const [dw, dh] = deviceBox(kind, size)
10325
10335
  if (demo) {
10326
- const fill = kind === 'web'
10327
- const [dw, dh] = deviceBox(kind, size)
10328
10336
  const z = fill ? 1 : Math.max(0.05, Math.min(1, (box.w - 32) / dw, (ah - 16 - 46) / dh))
10329
10337
  const top = demo.layers[demo.layers.length - 1]
10330
10338
  body = h('div', { className: 'ddp-demo' }, ...demo.layers.map((l) => {
@@ -10399,17 +10407,19 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
10399
10407
  const now = screens.find((x) => x.key === k) || screens[0]
10400
10408
  const has = now && ver.screens.includes(now.key)
10401
10409
  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
10410
  // 右边开着版本面板:手机这类有外框的让到面板左边(和单看时一样)
10405
- const aside = !fill && !!(ck || styleEdit || panel || pane || hist || phone) && box.w - 296 >= 240 ? 296 : 0
10406
- const z = fill ? 1 : Math.max(0.05, Math.min(1, (box.w - aside - 32) / dw, (ah - 16 - (ver ? 46 : 0)) / dh))
10411
+ const cmpSide = !!(ck || styleEdit || panel || pane || hist || phone) && box.w - 296 >= 240
10412
+ // 网页铺满时也让(#22):按铺满时的大小定住(上面有版本横幅,少 46),整体缩到面板左边,不重排
10413
+ const cmpLock = fill && cmpSide ? { w: box.w, h: ah - 46 } : null
10414
+ const aside = cmpSide && (!fill || cmpLock) ? 296 : 0
10415
+ const flat = fill && !cmpLock
10416
+ const z = cmpLock ? Math.max(0.05, Math.min(1, (box.w - aside - 32) / cmpLock.w)) : fill ? 1 : Math.max(0.05, Math.min(1, (box.w - aside - 32) / dw, (ah - 16 - (ver ? 46 : 0)) / dh))
10407
10417
  // 两边的小标签不跟着画面缩小(缩了看不清);手机、平板躲开状态栏
10408
10418
  const tagAt = (side) => ({ top: kind === 'app' || kind === 'miniprogram' || kind === 'tablet' ? 60 : 10, transform: `scale(${1 / z})`, transformOrigin: 'top ' + side })
10409
10419
  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,
10410
10420
  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) })
10411
10421
  body = h('div', { className: 'ddp-single', style: aside ? { right: aside } : undefined },
10412
- h('div', { className: 'ddp-fit' + (fill ? ' fill' : ''), style: fill ? undefined : { width: dw, height: dh, transform: `translate(-50%, -50%) scale(${z})` } },
10422
+ h('div', { className: 'ddp-fit' + (flat ? ' fill' : ''), style: flat ? undefined : { width: cmpLock ? cmpLock.w : dw, height: cmpLock ? cmpLock.h : dh, transform: `translate(-50%, -50%) scale(${z})` } },
10413
10423
  // 胶囊那块露的是哪一边(把手拖过胶囊中间就是左边那一版),胶囊就跟哪一边的顶栏
10414
10424
  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 },
10415
10425
  h('div', { className: 'ddp-cmp' + (cmpDrag ? ' drag' : ''), ref: cmpRef },
@@ -10449,26 +10459,27 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
10449
10459
  onOpen: (key) => openByUser(key),
10450
10460
  })
10451
10461
  } else {
10452
- const fill = kind === 'web'
10453
- const [dw, dh] = deviceBox(kind, size)
10454
10462
  // 右边开着面板(体检、调样式、设计规范、换风格):手机这类有外框的让到面板左边(侧栏够宽时),别被挡住
10455
10463
  const sideOn = !!(anUp || ck || styleEdit || panel || pane || hist || phone) && box.w - 296 >= 240
10456
- const aside = !fill && sideOn ? 296 : 0
10464
+ // 网页铺满时右边开着面板(业务标注、体检、调样式…,#22):按现在的大小定住、整体缩到面板左边,不重排,右边的内容也不被挡
10465
+ // 高度按铺满时真有的那么高:上面挂着横幅(看旧版本)时少 46,和下面 .ddp-body 的 vb 一样算
10466
+ const sideLock = fill && sideOn && !mark ? { w: box.w, h: ah - (ver || demo || hintTop ? 46 : 0) } : null
10467
+ const aside = sideOn && (!fill || sideLock) ? 296 : 0
10457
10468
  // 生成中:右侧栏窄(或开着面板)时状态条在上排浮块下面,手机这类给它让一条;宽的时候它在上排中间,不用让。网页不让(一让就重排)
10458
10469
  busyGap = busy && !fill && (anOn || box.w < 860 || sideOn)
10459
10470
  // 画笔标注开着:网页按开标注时的大小定住(侧栏拉窄了就整体缩小,不重排),画的才对得上
10460
- const lock = fill && mark && markSize ? markSize : null
10461
- const z = lock ? Math.max(0.05, Math.min(1, box.w / lock.w, ah / lock.h)) : fill ? 1 : Math.max(0.05, Math.min(1, (box.w - aside - 32) / dw, (ah - 16 - (ver || hintTop || busyGap ? 46 : 0)) / dh))
10471
+ const lock = fill && mark && markSize ? markSize : sideLock
10472
+ const z = sideLock ? Math.max(0.05, Math.min(1, (box.w - aside - 32) / sideLock.w)) : lock ? Math.max(0.05, Math.min(1, box.w / lock.w, ah / lock.h)) : fill ? 1 : Math.max(0.05, Math.min(1, (box.w - aside - 32) / dw, (ah - 16 - (ver || hintTop || busyGap ? 46 : 0)) / dh))
10462
10473
  const one = ver ? shown.find((x) => x.key === focus) || shown[0] || { key: focus, url, label: st.label } : { key: focus, url, label: st.label }
10463
10474
  // 单屏时模型在写新的一屏:先看着它写(没在选、改字、调样式、标注的时候),写完换过去
10464
- const watch = dr && !ver && !demo && !picking && !textEdit && !styleEdit && !mark && !lock && !peekR.current
10475
+ const watch = dr && !ver && !demo && !picking && !textEdit && !styleEdit && !mark && !peekR.current
10465
10476
  if (watch) singleDraftR.current = dr.key || '*' // 还不知道是哪屏:名字到了再说
10466
10477
  body = h('div', { className: 'ddp-single', style: aside ? { right: aside } : undefined },
10467
10478
  h('div', { className: 'ddp-fit' + (fill && !lock ? ' fill' : ''), style: fill && !lock ? undefined : { width: lock ? lock.w : dw, height: lock ? lock.h : dh, transform: `translate(-50%, -50%) scale(${z})` } },
10468
10479
  watch
10469
10480
  ? h(Device, { key: 'draft', kind, w: size[0], h: size[1], fill, label: '', os: meta.os },
10470
10481
  h(GhostDraw, { key: 'gd', t, kind, pulse }),
10471
- h(DraftFrame, { key: 'df', url: dr.url, z: fill ? 1 : z, lang: t('lang'), onEnd: draftEnd }))
10482
+ h(DraftFrame, { key: 'df', url: dr.url, z: fill && !lock ? 1 : z, lang: t('lang'), onEnd: draftEnd }))
10472
10483
  : renderScreen(one, z, fill)))
10473
10484
  }
10474
10485
 
@@ -10583,7 +10594,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
10583
10594
  function HeaderButton(props) {
10584
10595
  const t = props.t
10585
10596
  const sid = props.sid || props.sessionId
10586
- const [st] = usePreview(sid)
10597
+ const [st] = usePreview(sid, true)
10587
10598
  const seen = useRef(null)
10588
10599
  useEffect(() => {
10589
10600
  if (!st) return
@@ -10701,7 +10712,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
10701
10712
  // 注意:这里是客户端**服务名**(短的),不是包名
10702
10713
  exports.inject = INJECT
10703
10714
  // 测试用
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 }
10715
+ exports._test = { makeDemoNav, 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
10716
  return module.exports
10706
10717
  },
10707
10718
  })