dsh-design-studio 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js CHANGED
@@ -204,7 +204,10 @@ window.__ModuleLoader__.load({
204
204
  exportedDocMiss: '已导出 {name}({n} 页,{miss} 屏没截到)',
205
205
  exportedHtml: '已导出 {name}({n} 屏,发给别人双击就能看)',
206
206
  exportedHtmlMiss: '已导出 {name}({n} 屏,{miss} 屏没读到)',
207
+ exportedHtmlSkip: '。{n} 个文件太大没放进去,演示里会缺({files}):单个文件最多 12 MB、一屏的图和字体加起来最多 48 MB',
207
208
  htmlTooBig: '图片太多,演示包超过 150 MB,没导出。少放几屏再试',
209
+ htmlImgBig: '模拟数据(mock.json)里绑的图太大(单张最多 12 MB、加起来最多 60 MB),放不进演示,没导出。换小一点的图再试',
210
+ htmlMockBig: 'mock.json 太大(超过 1 MB),演示里的数据带不上,没导出。把里面的大段内容(比如图片的 base64)换成图片文件路径再试',
208
211
  htmlNoScreens: '一屏都没读到(文件被挪走或删了?),没导出',
209
212
  xoWarn: '有内容会被裁掉,先看一眼',
210
213
  xoChecking: '正在量页面…',
@@ -301,6 +304,7 @@ window.__ModuleLoader__.load({
301
304
  ck_tight: '离固定栏太近',
302
305
  ck_jserr: '页面脚本报错',
303
306
  ck_missing: '文件没载出来',
307
+ ck_mockmiss: '模拟数据里没这个字段',
304
308
  ck_capsule: '被小程序胶囊挡住',
305
309
  ck_island: '被灵动岛挡住',
306
310
  ck_homebar: '伸进底部横条区',
@@ -331,6 +335,7 @@ window.__ModuleLoader__.load({
331
335
  cd_tight: '离{edgeName} {bar} 只有 {px}px(留 16px 以上)',
332
336
  cd_jserr: '{msg}{at}',
333
337
  cd_missing: '{what} {src} 载不出来(路径写错了,或者文件不在)',
338
+ cd_mockmiss: '用到了 {paths},mock.json 里没有(显示出来是空的)',
334
339
  cd_capsule: '伸进右上角胶囊 {px}px(胶囊是微信画的、盖不住:顶栏右边从 x={x} 起空着)',
335
340
  cd_island: '被灵动岛挡住 {px}px(灵动岛在 y 11–45:状态栏中间空着,内容放到状态栏下面)',
336
341
  cd_homebar: '{bar} 里的字或图标伸进底部横条区 {px}px(底部留 34px:栏加 padding-bottom: 34px,预览里 env(safe-area-inset-bottom) 是 0)',
@@ -775,6 +780,27 @@ window.__ModuleLoader__.load({
775
780
  lookStyle: '换风格',
776
781
  lookBrand: '品牌',
777
782
  lookTokTip: '点一下放进对话,接着说怎么改',
783
+ fpRowTip: '点开换字体:字体库(免费可商用)或电脑自带的',
784
+ fpTitle: '换{name}',
785
+ fpNow: '现在:{v}',
786
+ fpBack: '返回',
787
+ fpLib: '字体库 · 免费可商用',
788
+ fpLibTip: 'SIL 开放字体许可(OFL),个人、商用都免费。中文只带了常用的 6763 个字,生僻字由系统字体补上。存下时字体文件会复制进设计的 dsh-fonts/ 文件夹',
789
+ fpDl: '第一次用要下载字体库({mb} MB),之后不用再下',
790
+ fpOff: '「设计库不联网」开着,字体库下载不了',
791
+ fpNet: '字体库这会儿下载不了,稍后再试',
792
+ fpZh: '中文',
793
+ fpEn: '英文(只有英文和数字,中文用系统字体)',
794
+ fpSys: '电脑自带',
795
+ fpSysTip: '用的是这台电脑装的字体,别人电脑上没有时会换成相近的。商用海报要看字体授权',
796
+ fpAsk: '交给模型',
797
+ fpAskTip: '放进对话,说想要什么感觉,让模型挑',
798
+ fpNone: '这个版本的设计台没带字体库',
799
+ fpLoading: '正在读字体库…',
800
+ lookLibFont: '(字体库的「{name}」:调 use_fonts 放进来,var 填 {var})',
801
+ fontOffSave: '「设计库不联网」开着,字体库的字体放不进设计,没保存',
802
+ fontNetSave: '字体库下载不了,没保存(稍后再试)',
803
+ fontWriteSave: '设计目录的 dsh-fonts/ 写不进去,没保存',
778
804
  lookShape: '形状',
779
805
  lookPal: '配色',
780
806
  lookNoColor: '没有颜色变量。',
@@ -810,7 +836,7 @@ window.__ModuleLoader__.load({
810
836
  tkn_xs: '注释', tkn_sm: '小字', tkn_md: '中号字', tkn_body: '正文', tkn_lg: '大字', tkn_title: '标题', tkn_display: '大标题',
811
837
  tkn_rSm: '小圆角', tkn_rMd: '中圆角', tkn_rLg: '大圆角', tkn_rFull: '全圆', tkn_r: '圆角',
812
838
  tkn_space: '间距', tkn_gutter: '页边距',
813
- tkn_fHead: '标题字体', tkn_fBody: '正文字体', tkn_fMono: '等宽字体',
839
+ tkn_fHead: '标题字体', tkn_fBody: '正文字体', tkn_fMono: '等宽字体', tkn_fArt: '书法字体',
814
840
  tkn_shadow: '阴影', tkn_light: '浅', tkn_dark: '深', tkn_hover: '悬停',
815
841
  sizesNoShort: '固定画幅',
816
842
  working: '模型正在工作',
@@ -1094,6 +1120,36 @@ window.__ModuleLoader__.load({
1094
1120
  anHelp: '模型读完设计,把规则、状态、流程写成一条条标注;点一条,页面上找到它。',
1095
1121
  hpLookSet: '点色块直接改颜色,所有屏一起变,点「保存」才写进文件;字体、形状点一项会放进对话,接着说怎么改。',
1096
1122
  histHelp: '模型每轮改完、你每次手调保存,都会自动存一版:能和现在并排比,也能退回去。',
1123
+ data: '数据',
1124
+ dData: '原型里点出来的数据:随时看、随手改、一键重置',
1125
+ dataHelp: '原型里点出来的变化都记在这,换页、刷新都还在。在这里改,页面马上跟着变;「存成初始数据」写回 mock.json,以后重置就回到这里。',
1126
+ dataWait: '正在读数据…',
1127
+ dataNoneT: '读不到数据',
1128
+ dataNone: '预览页面没开起来;关掉面板再开一次试试',
1129
+ dataBadT: 'mock.json 读不出来',
1130
+ dataFix: '让模型修好',
1131
+ dataFixText: 'mock.json 读不出来({err})。请修好它:要是一个 JSON 对象,原型里用到的字段都留着。',
1132
+ dataN: '改过 {n} 处(和 mock.json 比)',
1133
+ dataSame: '和 mock.json 一样',
1134
+ dataReset: '重置',
1135
+ dataResetTip: '所有屏一起回到 mock.json 里的初始数据',
1136
+ dataResetDone: '数据已重置',
1137
+ dataSave: '存成初始数据',
1138
+ dataSaveTip: '把现在的数据写回 mock.json,以后重置就回到这里',
1139
+ dataSaved: '已存成初始数据',
1140
+ dataNoMock: 'mock.json 不在了,没存',
1141
+ dataChanged: 'mock.json 刚被改过(模型或别的窗口),没存,免得把新的盖掉;面板会换成新的那份',
1142
+ dataBadFile: 'mock.json 读不出来,先让模型修好再存',
1143
+ dataBig: '数据太大存不下(最多 1 MB)',
1144
+ dataFail: '没改成:{msg}',
1145
+ dataNull: '空',
1146
+ dataItems: '{n} 条',
1147
+ dataKeys: '{n} 项',
1148
+ dataMore: '还有 {n} 条没列出来',
1149
+ dataAdd: '加一条',
1150
+ dataAddTip: '照最后一条复制一条',
1151
+ dataDel: '删掉这条',
1152
+ dataChg: '改过',
1097
1153
  styleHelp: '拖滑块时页面上先看效果,还没写进文件;满意了点「保存」,或点「让模型改」交给模型写进样式表。',
1098
1154
  hoHelp: '模型先写一份交接说明,再一屏一屏做;每屏做完自动和设计稿比一次,差多少写在「做完怎么验」里。',
1099
1155
  inPick: '选图片',
@@ -1164,6 +1220,7 @@ window.__ModuleLoader__.load({
1164
1220
  pkNote_form: '{n} 个表单地址',
1165
1221
  pkNote_ping: '{n} 个 ping',
1166
1222
  pkNote_exif: '{n} 张图片的拍摄信息',
1223
+ pkNote_fontLib: '{n} 个文件里字体库的字体(字体不进包,分享出去用系统字体显示)',
1167
1224
  pkFail: '有 {n} 个问题要先改:',
1168
1225
  pkMore: '还有 {n} 个…',
1169
1226
  pkFix: '让模型改',
@@ -1395,7 +1452,10 @@ window.__ModuleLoader__.load({
1395
1452
  exportedDocMiss: 'Exported {name} ({n} pages, {miss} screens could not be captured)',
1396
1453
  exportedHtml: 'Exported {name} ({n} screens; anyone can open it with a double-click)',
1397
1454
  exportedHtmlMiss: 'Exported {name} ({n} screens, {miss} could not be read)',
1455
+ exportedHtmlSkip: '. {n} file(s) were too big to include and will be missing ({files}): 12 MB per file and 48 MB of images and fonts per screen at most',
1398
1456
  htmlTooBig: 'Too many images: the demo would be over 150 MB, so nothing was exported. Try with fewer screens',
1457
+ htmlImgBig: 'An image referenced in the mock data (mock.json) is too big (12 MB each, 60 MB in total at most) to fit in the demo, so nothing was exported. Try a smaller image',
1458
+ htmlMockBig: 'mock.json is too big (over 1 MB) to carry its data into the demo, so nothing was exported. Replace large content (like base64 images) with image file paths and try again',
1399
1459
  htmlNoScreens: 'None of the screens could be read (moved or deleted?), so nothing was exported',
1400
1460
  xoWarn: 'Some content would be cut off. Have a look first',
1401
1461
  xoChecking: 'Measuring pages…',
@@ -1492,6 +1552,7 @@ window.__ModuleLoader__.load({
1492
1552
  ck_tight: 'Too close to a fixed bar',
1493
1553
  ck_jserr: 'Script error',
1494
1554
  ck_missing: 'File failed to load',
1555
+ ck_mockmiss: 'Not in the mock data',
1495
1556
  ck_capsule: 'Under the mini program capsule',
1496
1557
  ck_island: 'Under the Dynamic Island',
1497
1558
  ck_homebar: 'In the home indicator area',
@@ -1522,6 +1583,7 @@ window.__ModuleLoader__.load({
1522
1583
  cd_tight: 'only {px}px from the {edgeName} {bar} (leave 16px or more)',
1523
1584
  cd_jserr: '{msg}{at}',
1524
1585
  cd_missing: '{what} {src} did not load (wrong path, or the file is missing)',
1586
+ cd_mockmiss: 'Uses {paths}, which mock.json does not have (shows up empty)',
1525
1587
  cd_capsule: '{px}px under the top-right capsule (WeChat draws it on top; keep the top bar clear from x={x})',
1526
1588
  cd_island: '{px}px under the Dynamic Island (it sits at y 11–45: keep the middle of the status bar empty and start content below the status bar)',
1527
1589
  cd_homebar: 'text or icons in {bar} reach {px}px into the home indicator area (leave 34px: give the bar padding-bottom: 34px; env(safe-area-inset-bottom) is 0 in the preview)',
@@ -1965,6 +2027,27 @@ window.__ModuleLoader__.load({
1965
2027
  lookStyle: 'Restyle',
1966
2028
  lookBrand: 'Brand',
1967
2029
  lookTokTip: 'Click to add it to the chat, then say how to change it',
2030
+ fpRowTip: 'Change the font: from the font library (free for commercial use) or this computer',
2031
+ fpTitle: 'Change {name}',
2032
+ fpNow: 'Now: {v}',
2033
+ fpBack: 'Back',
2034
+ fpLib: 'Font library · free for commercial use',
2035
+ fpLibTip: 'SIL Open Font License (OFL): free for personal and commercial use. Chinese fonts carry the 6,763 common characters; rare ones fall back to system fonts. Saving copies the font files into the design\'s dsh-fonts/ folder',
2036
+ fpDl: 'The first use downloads the font library ({mb} MB), once',
2037
+ fpOff: '"Design library offline" is on, so the font library cannot be downloaded',
2038
+ fpNet: 'The font library cannot be downloaded right now. Try again later',
2039
+ fpZh: 'Chinese',
2040
+ fpEn: 'Latin (letters and numbers only; Chinese uses system fonts)',
2041
+ fpSys: 'On this computer',
2042
+ fpSysTip: 'Fonts installed on this computer. Computers without them show a similar font. Check the font license for commercial posters',
2043
+ fpAsk: 'Ask the model',
2044
+ fpAskTip: 'Add it to the chat, describe the feel you want and let the model pick',
2045
+ fpNone: 'This version of the studio has no font library',
2046
+ fpLoading: 'Loading the font library…',
2047
+ lookLibFont: ' (font library "{name}": call use_fonts with var {var})',
2048
+ fontOffSave: '"Design library offline" is on, so library fonts cannot be added. Not saved',
2049
+ fontNetSave: 'The font library cannot be downloaded. Not saved (try again later)',
2050
+ fontWriteSave: 'Cannot write the design\'s dsh-fonts/ folder. Not saved',
1968
2051
  lookShape: 'Shape',
1969
2052
  lookPal: 'Colors',
1970
2053
  lookNoColor: 'No color tokens.',
@@ -2000,7 +2083,7 @@ window.__ModuleLoader__.load({
2000
2083
  tkn_xs: 'Caption', tkn_sm: 'Small', tkn_md: 'Medium', tkn_body: 'Body', tkn_lg: 'Large', tkn_title: 'Title', tkn_display: 'Display',
2001
2084
  tkn_rSm: 'Small corners', tkn_rMd: 'Medium corners', tkn_rLg: 'Large corners', tkn_rFull: 'Pill', tkn_r: 'Corners',
2002
2085
  tkn_space: 'Spacing', tkn_gutter: 'Page margin',
2003
- tkn_fHead: 'Heading font', tkn_fBody: 'Body font', tkn_fMono: 'Mono font',
2086
+ tkn_fHead: 'Heading font', tkn_fBody: 'Body font', tkn_fMono: 'Mono font', tkn_fArt: 'Script font',
2004
2087
  tkn_shadow: 'Shadow', tkn_light: 'light', tkn_dark: 'dark', tkn_hover: 'hover',
2005
2088
  sizesNoShort: 'Fixed size',
2006
2089
  working: 'The model is working',
@@ -2283,6 +2366,36 @@ window.__ModuleLoader__.load({
2283
2366
  anHelp: 'The model reads the design and writes its rules, states and flows as notes. Click a note to find it on the page.',
2284
2367
  hpLookSet: 'Click a swatch to change a color; every screen follows, and Save writes it to the file. Click a font or shape item to add it to the chat and say how to change it.',
2285
2368
  histHelp: 'A version is saved after every model turn and every manual save: compare it with now side by side, or go back to it.',
2369
+ data: 'Data',
2370
+ dData: 'The data behind the clickable prototype: view it, edit it, reset it',
2371
+ dataHelp: 'Everything you click in the prototype is kept here and survives page changes and reloads. Edit it here and the pages follow at once; "Save as initial data" writes it back to mock.json, so Reset returns here from then on.',
2372
+ dataWait: 'Reading the data…',
2373
+ dataNoneT: 'Could not read the data',
2374
+ dataNone: 'The preview page did not open; close this panel and open it again',
2375
+ dataBadT: 'mock.json cannot be read',
2376
+ dataFix: 'Ask the model to fix it',
2377
+ dataFixText: 'mock.json cannot be read ({err}). Please fix it: it must be a JSON object, and keep every field the prototype uses.',
2378
+ dataN: '{n} changes (compared with mock.json)',
2379
+ dataSame: 'Same as mock.json',
2380
+ dataReset: 'Reset',
2381
+ dataResetTip: 'Every screen goes back to the initial data in mock.json',
2382
+ dataResetDone: 'Data reset',
2383
+ dataSave: 'Save as initial data',
2384
+ dataSaveTip: 'Write the current data back to mock.json; Reset returns here from then on',
2385
+ dataSaved: 'Saved as initial data',
2386
+ dataNoMock: 'mock.json is gone, so nothing was saved',
2387
+ dataChanged: 'mock.json was just changed (by the model or another window), so nothing was saved to avoid overwriting it; the panel will switch to the new data',
2388
+ dataBadFile: "mock.json can't be read; have the model fix it before saving",
2389
+ dataBig: 'The data is too big to save (1 MB at most)',
2390
+ dataFail: 'Not changed: {msg}',
2391
+ dataNull: 'empty',
2392
+ dataItems: '{n} items',
2393
+ dataKeys: '{n} fields',
2394
+ dataMore: '{n} more not listed',
2395
+ dataAdd: 'Add one',
2396
+ dataAddTip: 'Copy the last item',
2397
+ dataDel: 'Delete this item',
2398
+ dataChg: 'Changed',
2286
2399
  styleHelp: 'Dragging a slider previews the change on the page without touching the file. Click Save when you like it, or Ask the model to write it into the stylesheet.',
2287
2400
  hoHelp: 'The model writes a handoff note first, then builds one screen at a time; each finished screen is compared with the design, and the difference shows under “How it gets checked”.',
2288
2401
  inPick: 'Choose images',
@@ -2353,6 +2466,7 @@ window.__ModuleLoader__.load({
2353
2466
  pkNote_form: '{n} form addresses',
2354
2467
  pkNote_ping: '{n} pings',
2355
2468
  pkNote_exif: 'photo metadata in {n} images',
2469
+ pkNote_fontLib: 'font-library fonts in {n} files (fonts are not packed; the shared copy shows system fonts)',
2356
2470
  pkFail: '{n} things to fix first:',
2357
2471
  pkMore: '{n} more…',
2358
2472
  pkFix: 'Ask the model',
@@ -4299,12 +4413,69 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
4299
4413
  .ddp .dd-tkr>.vl{flex:none;max-width:55%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:12px;color:var(--dd-t3);font-variant-numeric:tabular-nums}
4300
4414
  .ddp .dd-tkr>.shb{width:30px;height:20px;flex:none;border-radius:6px;background:#ececef;display:grid;place-items:center}
4301
4415
  .ddp .dd-tkr>.shb>.sh{width:16px;height:10px;border-radius:3px;background:#fff}
4416
+ .ddp .dd-tkr.on{box-shadow:inset 0 0 0 1.5px var(--dd-acc)}
4417
+ .ddp .dd-tkr.on>.vl{color:var(--dd-acc)}
4418
+ .ddp .dd-tkr>.go{flex:none;display:grid;place-items:center;width:14px;height:14px;margin-right:-4px;color:var(--dd-t3);transform:rotate(180deg)}
4419
+ .ddp .dd-tkr>.go svg{width:14px;height:14px}
4420
+ .ddp .dd-fp{display:flex;flex-direction:column;gap:14px;min-width:0}
4421
+ .ddp .dd-fph{display:flex;align-items:center;gap:10px;flex-wrap:wrap;min-width:0}
4422
+ .ddp .dd-fph>b{font-size:14px;color:var(--dd-t1)}
4423
+ .ddp .dd-fph>.note{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
4424
+ .ddp .dd-fps{display:flex;flex-direction:column;gap:8px;min-width:0}
4425
+ .ddp .dd-fps>h6{display:flex;align-items:center;gap:6px;flex-wrap:wrap;margin:0;font-size:12px;font-weight:600;color:var(--dd-t2)}
4426
+ .ddp .dd-fps>h6>small{font-weight:400;font-size:11.5px;color:var(--dd-t3);letter-spacing:0;text-transform:none}
4427
+ .ddp .dd-fps>em{font-style:normal;font-size:11.5px;color:var(--dd-t3);margin-top:2px}
4428
+ .ddp .dd-fpg{display:grid;grid-template-columns:repeat(auto-fill,minmax(210px,1fr));gap:6px}
4429
+ .ddp .dd-fnt{display:flex;flex-direction:column;align-items:flex-start;justify-content:center;gap:4px;position:relative;min-width:0;min-height:58px;padding:8px 30px 8px 12px;border:0;border-radius:var(--dd-r2);background:var(--dd-f1);box-shadow:inset 0 0 0 1px var(--dd-line);color:var(--dd-t1);font:inherit;text-align:left;cursor:pointer;transition:background-color .15s,box-shadow .15s,transform .12s var(--dd-out)}
4430
+ .ddp .dd-fnt:hover{background:var(--dd-f2);box-shadow:inset 0 0 0 1px var(--dd-line2)}
4431
+ .ddp .dd-fnt:active{transform:scale(.985)}
4432
+ .ddp .dd-fnt:focus-visible{outline:2px solid var(--dd-acc);outline-offset:-2px}
4433
+ .ddp .dd-fnt:disabled{opacity:.5;cursor:default}
4434
+ .ddp .dd-fnt.on{box-shadow:inset 0 0 0 1.5px var(--dd-acc)}
4435
+ .ddp .dd-fnt>.pv{display:flex;align-items:center;height:24px;max-width:100%;min-width:0;color:var(--dd-t1)}
4436
+ .ddp .dd-fnt>.pv svg{height:22px;width:auto;max-width:100%;overflow:visible}
4437
+ .ddp .dd-fnt>.pv path{fill:currentColor}
4438
+ .ddp .dd-fnt>.pv b{font-size:17px;font-weight:500;line-height:24px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
4439
+ .ddp .dd-fnt>.nt{display:flex;align-items:center;gap:6px;max-width:100%;min-width:0;font-size:11.5px;color:var(--dd-t3)}
4440
+ .ddp .dd-fnt>.nt>span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
4441
+ .ddp .dd-fnt>svg{position:absolute;top:50%;right:10px;width:16px;height:16px;margin-top:-8px;color:var(--dd-acc)}
4302
4442
  .ddp .dd-f>.lbl b.on{color:var(--dd-acc)}
4303
4443
  .ddp .dd-sws.wr{flex-wrap:wrap}
4304
4444
  .ddp .ddp-lktw .dd-seg{width:100%}
4305
4445
  .ddp .ddp-lktw .dd-seg>button{height:30px}
4306
4446
  .ddp .ddp-lktw .dd-chips{margin-top:0}
4307
4447
  /* 空着:一圈极光 + 标题 + 一句说明 + 一个按钮 */
4448
+ .ddp .dd-mkbr{position:absolute;width:0;height:0;border:0;visibility:hidden;pointer-events:none}
4449
+ /* 「数据」:一行一个字段,缩进看层级;改过的打个橙点 */
4450
+ .ddp .dd-sheet .dd-in>*>.bd.dd-mk{display:flex;flex-direction:column;gap:1px;padding:6px 8px 12px}
4451
+ .ddp .dd-mkr{display:flex;align-items:center;gap:8px;min-height:34px;padding:0 6px 0 calc(28px + var(--d,0) * 16px);border-radius:9px;animation:dd-ckin .3s var(--dd-out) backwards}
4452
+ .ddp .dd-mkr:hover{background:var(--dd-f1)}
4453
+ .ddp .dd-mkr>.k,.ddp .dd-mkr .fold>.k{flex:0 1 auto;min-width:0;max-width:46%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--dd-t2);font:12px/18px ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
4454
+ .ddp .dd-mkr>.v{flex:1 1 auto;min-width:0;display:flex;justify-content:flex-end;align-items:center}
4455
+ .ddp .dd-mkr .fold{flex:1 1 auto;min-width:0;display:flex;align-items:center;gap:6px;height:30px;margin-left:-20px;padding:0 4px;border:0;background:none;color:inherit;font:inherit;cursor:pointer;text-align:left}
4456
+ .ddp .dd-mkr .fold>svg{width:14px;height:14px;flex:none;color:var(--dd-t3);transition:transform .16s var(--dd-out)}
4457
+ .ddp .dd-mkr.op .fold>svg{transform:rotate(90deg)}
4458
+ .ddp .dd-mkr .fold>.k{max-width:none;color:var(--dd-t1);font-weight:600}
4459
+ .ddp .dd-mkr .ct{flex:0 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--dd-t3);font-size:11.5px}
4460
+ .ddp .dd-mkr input.tx{width:100%;max-width:280px;height:28px;padding:0 9px;border:0;border-radius:8px;background:var(--dd-f1);box-shadow:inset 0 0 0 1px var(--dd-line);color:var(--dd-t1);font:inherit;font-size:12.5px;text-align:right;text-overflow:ellipsis;transition:box-shadow .14s var(--dd-out),background .14s var(--dd-out)}
4461
+ .ddp .dd-mkr input.tx.num{max-width:120px;font-variant-numeric:tabular-nums}
4462
+ .ddp .dd-mkr input.tx:hover{box-shadow:inset 0 0 0 1px var(--dd-line2)}
4463
+ .ddp .dd-mkr input.tx:focus{outline:none;background:var(--dd-s1);box-shadow:inset 0 0 0 1.5px var(--dd-acc);text-align:left}
4464
+ .ddp .dd-mkr .sw{display:inline-flex;align-items:center;height:28px;padding:0 2px;border:0;background:none;cursor:pointer}
4465
+ .ddp .dd-mkr .nul{color:var(--dd-t4);font-style:italic;font-size:12px}
4466
+ .ddp .dd-mkr .chg{width:7px;height:7px;flex:none;border-radius:50%;background:var(--dd-c4);box-shadow:0 0 0 3px color-mix(in srgb,var(--dd-c4) 22%,transparent)}
4467
+ .ddp .dd-mkr>.del{width:24px;height:24px;flex:none;display:grid;place-items:center;padding:0;border:0;border-radius:7px;background:none;color:var(--dd-t3);cursor:pointer;opacity:0;transition:opacity .12s var(--dd-out)}
4468
+ .ddp .dd-mkr>.del svg{width:12px;height:12px}
4469
+ .ddp .dd-mkr:hover>.del,.ddp .dd-mkr>.del:focus-visible{opacity:1}
4470
+ .ddp .dd-mkr>.del:hover{background:var(--dd-err-bg);color:var(--dd-err)}
4471
+ .ddp .dd-mkr.more{color:var(--dd-t3);font-size:11.5px}
4472
+ .ddp .dd-mkr.add{min-height:30px}
4473
+ .ddp .dd-mkr.add .dd-bt{height:26px;padding:0 9px;font-size:12px}
4474
+ .ddp .dd-mkerr{display:flex;flex-wrap:wrap;align-items:center;gap:8px 10px;margin:4px 2px 8px;padding:10px 10px 10px 12px;border-radius:var(--dd-r3);background:var(--dd-err-bg);color:var(--dd-err);font-size:12px;line-height:18px}
4475
+ .ddp .dd-mkerr>svg{width:15px;height:15px;flex:none}
4476
+ .ddp .dd-mkerr>span{flex:1 1 200px;min-width:0;overflow-wrap:anywhere}
4477
+ .ddp .dd-mkerr .dd-bt{height:30px;font-size:12.5px}
4478
+ @media (hover:none){.ddp .dd-mkr>.del{opacity:1}}
4308
4479
  .ddp .dd-emp{display:flex;flex-direction:column;align-items:center;gap:6px;padding:22px 16px 16px;color:var(--dd-t3);font-size:12px;line-height:18px;text-align:center;animation:dd-ckin .4s var(--dd-out) .08s backwards}
4309
4480
  .ddp .dd-emp>b{font-size:14px;font-weight:600;color:var(--dd-t1)}
4310
4481
  .ddp .dd-emp>span{max-width:440px;overflow-wrap:anywhere}
@@ -4594,6 +4765,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
4594
4765
  image: () => svg([h('rect', { key: 1, x: 3.5, y: 4.5, width: 17, height: 15, rx: 2.2 }), h('circle', { key: 2, cx: 9, cy: 10, r: 1.7 }), h('path', { key: 3, d: 'M20 16l-4.5-4.5L7 19.5' })]),
4595
4766
  long: () => svg([h('rect', { key: 1, x: 6.5, y: 2.5, width: 11, height: 19, rx: 2 }), h('path', { key: 2, d: 'M9.5 7h5M9.5 10.5h5M9.5 14h3' })]),
4596
4767
  history: () => svg([h('path', { key: 1, d: 'M3.5 12a8.5 8.5 0 1 0 2.6-6.1' }), h('path', { key: 2, d: 'M3.5 4.5v4h4' }), h('path', { key: 3, d: 'M12 7.5V12l3 2' })]),
4768
+ data: () => svg([h('ellipse', { key: 1, cx: 12, cy: 6, rx: 7, ry: 3 }), h('path', { key: 2, d: 'M5 6v12c0 1.66 3.13 3 7 3s7-1.34 7-3V6' }), h('path', { key: 3, d: 'M5 12c0 1.66 3.13 3 7 3s7-1.34 7-3' })]),
4597
4769
  scan: () => svg([h('path', { key: 1, d: 'M4 8.5V6a2 2 0 0 1 2-2h2.5M15.5 4H18a2 2 0 0 1 2 2v2.5M20 15.5V18a2 2 0 0 1-2 2h-2.5M8.5 20H6a2 2 0 0 1-2-2v-2.5' }),
4598
4770
  h('rect', { key: 2, x: 9, y: 7.5, width: 6, height: 9, rx: 1.3 })]),
4599
4771
  sizes: () => svg([h('rect', { key: 1, x: 2.5, y: 5, width: 12, height: 9.5, rx: 1.4 }), h('path', { key: 2, d: 'M6.5 18h4' }),
@@ -5347,6 +5519,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
5347
5519
  const m = rest(/^$/).join(' ')
5348
5520
  return m ? `${t('tkn_space')} ${m}` : t('tkn_space')
5349
5521
  } else if (kind === 'font') {
5522
+ if (has(/^(brush|calligraphy|script|hand|handwriting)$/)) return t('tkn_fArt')
5350
5523
  if (has(/^(head|heading|display|title|serif|brand)$/)) return t('tkn_fHead')
5351
5524
  if (has(/^(mono|code)$/)) return t('tkn_fMono')
5352
5525
  if (has(/^(body|text|sans|base|ui)$/)) return t('tkn_fBody')
@@ -6528,6 +6701,10 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
6528
6701
  * 单看时页面里点了换状态的链接(#30):顶栏记着的就是要的这个(在页面里去了别的页、又点链接回来,页面显示的不是顶栏那个状态),
6529
6702
  * 顶栏、地址都不会变 → 'reload' 重新载一遍这屏(不然点了没反应);不然 'pick' 交给顶栏换。def:要的是默认状态
6530
6703
  */
6704
+ /** 页面报上来的状态那段里有「#mock」那行:这页的状态跟着模拟数据走(不带状态 = 数据里那个,第一个状态要点名) */
6705
+ function followsMock(raw) {
6706
+ return /^#mock\n/.test(String(raw || ''))
6707
+ }
6531
6708
  function stateGoPlan(src, d) {
6532
6709
  let had = ''
6533
6710
  try { had = new URL(src).searchParams.get('state') || '' } catch { /* 地址不认识:当默认 */ }
@@ -7729,7 +7906,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
7729
7906
  }
7730
7907
  setErrs((m) => (JSON.stringify(m[id] || null) === JSON.stringify(fail) ? m : { ...m, [id]: fail }))
7731
7908
  if (p.dark) postTo(id, { type: 'theme', dark: true })
7732
- if (p.tweak) postTo(id, { type: 'tweak', vars: p.tweak.vars, attrs: p.tweak.attrs })
7909
+ if (p.tweak) postTo(id, { type: 'tweak', vars: p.tweak.vars, attrs: p.tweak.attrs, fonts: p.tweak.fonts || [] })
7733
7910
  try { if (d.href) L.pageOf.set(id, keyOfPath(decodeURIComponent(new URL(d.href).pathname), true)) } catch { /* 地址不认识:当没跳 */ }
7734
7911
  {
7735
7912
  const list = annotsOf(p, id)
@@ -7815,7 +7992,8 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
7815
7992
  if (isCur && p.picking && p.onPicked) p.onPicked(d.payload)
7816
7993
  break
7817
7994
  case 'stateGo': { // 单看时点了同一页换状态的链接(#30)
7818
- if (!isCur || !p.onStateGo || typeof d.state !== 'string' || !STATE_RE.test(d.state)) break
7995
+ // clear:状态跟着模拟数据走的页里点了不带状态的链接 → 去掉点名的状态(回到跟着数据)
7996
+ if (!isCur || !p.onStateGo || typeof d.state !== 'string' || !(STATE_RE.test(d.state) || (d.state === '' && d.clear === true))) break
7819
7997
  // 链接带的锚点(?state=paid#receipt):换好状态的那一帧载的时候带上(只认这一下,过会儿就不算了)
7820
7998
  L.hashNext = typeof d.hash === 'string' && /^#[^\s#]{1,200}$/.test(d.hash) ? { hash: d.hash, at: Date.now() } : null
7821
7999
  if (stateGoPlan(p.src, d) === 'reload') { L.at = ''; load(null, true) } else p.onStateGo(d.state)
@@ -7884,7 +8062,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
7884
8062
  useEffect(() => { if (cur) postTo(cur, { type: 'demo', on: !!props.demo }) }, [!!props.demo])
7885
8063
  // 调节滑块:拖的时候改页面上的 CSS 变量 / <html> 属性(新载的一帧在 ready 时套上)
7886
8064
  const twSig = JSON.stringify(props.tweak || null)
7887
- useEffect(() => { if (cur) postTo(cur, { type: 'tweak', vars: (props.tweak || {}).vars || {}, attrs: (props.tweak || {}).attrs || {} }) }, [twSig])
8065
+ useEffect(() => { if (cur) postTo(cur, { type: 'tweak', vars: (props.tweak || {}).vars || {}, attrs: (props.tweak || {}).attrs || {}, fonts: (props.tweak || {}).fonts || [] }) }, [twSig])
7888
8066
  // 业务标注:编号画在页面里(新载的一帧在 ready 时再发一次);点选、改字这些模式下 annots 是 null,编号收起
7889
8067
  const anSig = JSON.stringify(props.annots || null)
7890
8068
  useEffect(() => { if (cur) postTo(cur, { type: 'annots', list: annotsOf(props, cur) || [], sel: props.annotSel || '' }) }, [anSig, props.annotVer])
@@ -8795,6 +8973,143 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
8795
8973
  return /^-?[\d.]+px$/.test(s) ? s.slice(0, -2) : s
8796
8974
  }
8797
8975
 
8976
+ // ── 字体库(#31)─────────────────────────────────────────────────────────
8977
+
8978
+ let LIB_FONTS = [] // 字体库列表(发给页面试字体时要知道 id、字重;变量那行显示中文名)
8979
+ let libFontsP = null
8980
+ /** 读一次字体库列表(名字、说明、字体栈、预览图形);读完 onDone 让面板重画 */
8981
+ function loadLibFonts() {
8982
+ if (!libFontsP) libFontsP = getJson('fonts').then((d) => { LIB_FONTS = Array.isArray(d.fonts) ? d.fonts : []; return d }, (e) => { libFontsP = null; throw e })
8983
+ return libFontsP
8984
+ }
8985
+ const firstFam = (stack) => { const m = /^\s*(?:"([^"]*)"|'([^']*)'|([^,]*))/.exec(String(stack || '')); return m ? (m[1] ?? m[2] ?? m[3] ?? '').trim() : '' }
8986
+ const libOfStack = (v) => { const fam = firstFam(v).toLowerCase(); return (fam && LIB_FONTS.find((f) => f.family.toLowerCase() === fam)) || null }
8987
+ /** 面板里改的变量用到了哪些字体库的字体 → 发给页面,先从预览服务器加载着看(还没存进设计) */
8988
+ function tweakFontsOf(tv) {
8989
+ const out = []
8990
+ for (const v of Object.values(tv || {})) {
8991
+ const f = libOfStack(v)
8992
+ if (f && !out.some((x) => x.id === f.id)) out.push({ id: f.id, family: f.family, weights: f.weights })
8993
+ }
8994
+ return out
8995
+ }
8996
+ // 电脑自带的:Mac / Windows 成对写(同一种字,两边名字不一样),装了其中一个就列出来
8997
+ const SYS_FONTS = [
8998
+ { k: 'pingfang', zh: '苹方 / 微软雅黑', en: 'PingFang / Microsoft YaHei', nzh: '系统默认的黑体', nen: 'The default Chinese sans', stack: '"PingFang SC", "Microsoft YaHei", system-ui, sans-serif', test: ['PingFang SC', 'Microsoft YaHei'] },
8999
+ { k: 'heiti', zh: '黑体', en: 'Heiti', nzh: '老派一点的黑体', nen: 'Classic Chinese sans', stack: '"Heiti SC", "SimHei", sans-serif', test: ['Heiti SC', 'SimHei', 'STHeiti'] },
9000
+ { k: 'songti', zh: '宋体', en: 'Songti', nzh: '书卷气的宋体', nen: 'Bookish Chinese serif', stack: '"Songti SC", "SimSun", serif', test: ['Songti SC', 'SimSun', 'STSong'] },
9001
+ { k: 'kaiti', zh: '楷体', en: 'Kaiti', nzh: '手写感的楷体', nen: 'Brush-like regular script', stack: '"Kaiti SC", "KaiTi", "STKaiti", serif', test: ['Kaiti SC', 'KaiTi', 'STKaiti'] },
9002
+ { k: 'fangsong', zh: '仿宋', en: 'Fangsong', nzh: '公文、古籍感', nen: 'Official documents, classics', stack: '"STFangsong", "FangSong", serif', test: ['STFangsong', 'FangSong'] },
9003
+ { k: 'yuanti', zh: '圆体', en: 'Yuanti', nzh: '圆润亲和', nen: 'Rounded and friendly', stack: '"Yuanti SC", "SF Pro Rounded", sans-serif', test: ['Yuanti SC'] },
9004
+ { k: 'harmony', zh: 'HarmonyOS Sans', en: 'HarmonyOS Sans', nzh: '华为的黑体', nen: 'Huawei sans', stack: '"HarmonyOS Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif', test: ['HarmonyOS Sans SC'] },
9005
+ { k: 'misans', zh: 'MiSans', en: 'MiSans', nzh: '小米的黑体', nen: 'Xiaomi sans', stack: '"MiSans", "PingFang SC", "Microsoft YaHei", sans-serif', test: ['MiSans'] },
9006
+ { k: 'helvetica', zh: 'Helvetica / Arial', en: 'Helvetica / Arial', nzh: '经典无衬线', nen: 'Classic sans', stack: '"Helvetica Neue", Helvetica, Arial, "PingFang SC", "Microsoft YaHei", sans-serif', test: ['Helvetica Neue', 'Arial'] },
9007
+ { k: 'avenir', zh: 'Avenir Next', en: 'Avenir Next', nzh: '几何感无衬线', nen: 'Geometric sans', stack: '"Avenir Next", Avenir, "PingFang SC", "Microsoft YaHei", sans-serif', test: ['Avenir Next'] },
9008
+ { k: 'georgia', zh: 'Georgia', en: 'Georgia', nzh: '耐看的衬线', nen: 'Readable serif', stack: 'Georgia, "Songti SC", "SimSun", serif', test: ['Georgia'] },
9009
+ { k: 'times', zh: 'Times New Roman', en: 'Times New Roman', nzh: '报纸衬线', nen: 'Newspaper serif', stack: '"Times New Roman", Times, "Songti SC", "SimSun", serif', test: ['Times New Roman'] },
9010
+ { k: 'mono', zh: 'Menlo / Consolas', en: 'Menlo / Consolas', nzh: '等宽,代码、数据', nen: 'Monospace for code and data', stack: '"SF Mono", Menlo, Consolas, monospace', test: ['Menlo', 'Consolas', 'SF Mono'] },
9011
+ ]
9012
+ let sysSeen = null
9013
+ /** 这台电脑装了哪些(量一串字的宽度:装了的和后备字体量出来不一样);量不了就都列出来 */
9014
+ function sysInstalled() {
9015
+ if (sysSeen) return sysSeen
9016
+ const out = new Set()
9017
+ try {
9018
+ const c = document.createElement('canvas').getContext('2d')
9019
+ const s = 'mmmmmmmmmmlli1WAaQ@#'
9020
+ const w = (f) => { c.font = `48px ${f}`; return c.measureText(s).width }
9021
+ const bm = w('monospace')
9022
+ const bs = w('serif')
9023
+ for (const x of SYS_FONTS) if (x.test.some((n) => w(`"${n}", monospace`) !== bm || w(`"${n}", serif`) !== bs)) out.add(x.k)
9024
+ } catch { for (const x of SYS_FONTS) out.add(x.k) }
9025
+ sysSeen = out
9026
+ return out
9027
+ }
9028
+ /** 变量那行右边显示的字体名:字体库 / 电脑自带认得出的给中文名,别的给第一个名字 */
9029
+ function fontShort(t, v) {
9030
+ const en = t('lang') === 'en'
9031
+ const lf = libOfStack(v)
9032
+ if (lf) return en ? lf.en : lf.zh
9033
+ const fam = firstFam(v).toLowerCase()
9034
+ const sf = fam && SYS_FONTS.find((x) => firstFam(x.stack).toLowerCase() === fam)
9035
+ return sf ? (en ? sf.en : sf.zh) : tokenShort('font', v)
9036
+ }
9037
+
9038
+ /** 换字体(#31):字体库(预览是名字画成的图形,不用先下载)+ 电脑自带的;点一下页面马上换,「保存」才写进文件 */
9039
+ function FontPicker({ t, label, value, onPick, onBack, onAsk }) {
9040
+ const en = t('lang') === 'en'
9041
+ const [data, setData] = useState(null)
9042
+ const [err, setErr] = useState('')
9043
+ const [busy, setBusy] = useState('')
9044
+ const alive = useRef(true)
9045
+ useEffect(() => {
9046
+ alive.current = true
9047
+ loadLibFonts().then((d) => { if (alive.current) setData(d) }, (e) => { if (alive.current) setErr(t('failed', { msg: e.message })) })
9048
+ return () => { alive.current = false }
9049
+ }, [])
9050
+ const cur = firstFam(value).toLowerCase()
9051
+ const sys = sysInstalled()
9052
+ const pickLib = async (f) => {
9053
+ if (busy) return
9054
+ setErr('')
9055
+ if (!(data && data.ready)) {
9056
+ setBusy(f.id)
9057
+ let r
9058
+ try {
9059
+ r = await post('fonts', {})
9060
+ } catch (e) {
9061
+ r = { err: e }
9062
+ }
9063
+ if (r.ok && libFontsP) libFontsP = libFontsP.then((d) => ({ ...d, ready: true }))
9064
+ // 下载期间关了面板、换了设计:这次选择作废(不落到别的设计上)
9065
+ if (!alive.current) return
9066
+ setBusy('')
9067
+ if (r.err) return setErr(t('failed', { msg: r.err.message }))
9068
+ if (!r.ok) return setErr(t(r.reason === 'off' ? 'fpOff' : 'fpNet'))
9069
+ setData((d) => ({ ...d, ready: true }))
9070
+ }
9071
+ onPick(f.stack)
9072
+ }
9073
+ const libRow = (f) => {
9074
+ const on = cur === f.family.toLowerCase()
9075
+ const pv = f.pv
9076
+ const nm = en ? f.en : f.zh
9077
+ return h('button', { key: f.id, type: 'button', className: 'dd-fnt' + (on ? ' on' : ''), 'aria-pressed': on, 'aria-label': `${nm} · ${en ? f.nen : f.nzh}`, disabled: !!busy && busy !== f.id, onClick: () => pickLib(f) },
9078
+ h('span', { className: 'pv', 'aria-hidden': 'true' }, pv && pv.d ? h('svg', { viewBox: `0 0 ${pv.w} ${pv.h}`, preserveAspectRatio: 'xMinYMid meet' }, h('path', { d: pv.d })) : h('b', null, nm)),
9079
+ h('span', { className: 'nt' }, busy === f.id ? h('i', { className: 'dd-spin' }) : null, h('span', null, en ? f.nen : f.nzh)),
9080
+ on ? h(I.check) : null)
9081
+ }
9082
+ const sysRow = (x) => {
9083
+ const on = cur === firstFam(x.stack).toLowerCase()
9084
+ return h('button', { key: x.k, type: 'button', className: 'dd-fnt sys' + (on ? ' on' : ''), 'aria-pressed': on, disabled: !!busy, onClick: () => onPick(x.stack) },
9085
+ h('span', { className: 'pv' }, h('b', { style: { fontFamily: x.stack } }, en ? x.en : x.zh)),
9086
+ h('span', { className: 'nt' }, h('span', null, en ? x.nen : x.nzh)),
9087
+ on ? h(I.check) : null)
9088
+ }
9089
+ const fonts = (data && data.fonts) || []
9090
+ const zh = fonts.filter((f) => f.lang === 'zh')
9091
+ const lat = fonts.filter((f) => f.lang !== 'zh')
9092
+ const sysL = SYS_FONTS.filter((x) => sys.has(x.k))
9093
+ return h('div', { className: 'bd dd-fp', key: 'fp' },
9094
+ h('div', { className: 'dd-fph' },
9095
+ h('button', { type: 'button', className: 'dd-bt ghost', onClick: onBack }, h(I.back), t('fpBack')),
9096
+ h('b', null, t('fpTitle', { name: label })),
9097
+ h('span', { className: 'note' }, t('fpNow', { v: fontShort(t, value) })),
9098
+ h('button', { type: 'button', className: 'dd-bt ghost ask', ...tipA(t('fpAsk'), t('fpAskTip')), onClick: onAsk }, h(I.spark), t('fpAsk'))),
9099
+ err ? h('p', { className: 'note err' }, err) : null,
9100
+ !data && !err ? h('div', { className: 'dd-ckwait' }, h('i', { className: 'dd-spin' }), h('span', null, t('fpLoading'))) : null,
9101
+ data && data.none ? h('p', { className: 'note' }, t('fpNone')) : null,
9102
+ fonts.length ? h('section', { className: 'dd-fps' },
9103
+ h('h6', null, t('fpLib'), h(Help, { t, text: t('fpLibTip') }), data.ready ? null : h('small', null, t('fpDl', { mb: Math.round((data.size || 0) / 1024 / 1024) }))),
9104
+ zh.length ? h('em', null, t('fpZh')) : null,
9105
+ zh.length ? h('div', { className: 'dd-fpg' }, ...zh.map(libRow)) : null,
9106
+ lat.length ? h('em', null, t('fpEn')) : null,
9107
+ lat.length ? h('div', { className: 'dd-fpg' }, ...lat.map(libRow)) : null) : null,
9108
+ sysL.length ? h('section', { className: 'dd-fps' },
9109
+ h('h6', null, t('fpSys'), h(Help, { t, text: t('fpSysTip') })),
9110
+ h('div', { className: 'dd-fpg' }, ...sysL.map(sysRow))) : null)
9111
+ }
9112
+
8798
9113
  /**
8799
9114
  * 外观面板(1.0):四页——
8800
9115
  * 整套:三列 配色(点色块直接改)/ 字体 / 形状(点一项放进对话);滑块:三列 整体 / 颜色 / 质感(模型给这套设计做的);
@@ -8802,7 +9117,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
8802
9117
  * 换风格:推荐 / 全部 / 我的风格 + 一排风格卡,点一张选中、再点看原大样板,底栏「换成这个风格」。
8803
9118
  * 品牌:两列 从网站或项目提一套 | 已有几套(设为默认、套用到当前设计)。
8804
9119
  */
8805
- function LookPanel({ t, head, tab, tokens, tv, onTv, onTokAsk, onTokMake, tw, live, onTw, onTwMake, write, onReset, onAsk, onSave, onPickStyle, onRef, onSaveStyle, rec, brand }) {
9120
+ function LookPanel({ t, head, tab, scope = '', tokens, tv, onTv, onTokAsk, onTokMake, tw, live, onTw, onTwMake, write, onReset, onAsk, onSave, onPickStyle, onRef, onSaveStyle, rec, brand }) {
8806
9121
  const en = t('lang') === 'en'
8807
9122
  const groups = {}
8808
9123
  for (const tok of tokens) (groups[tokenKind(tok)] = groups[tokenKind(tok)] || []).push(tok)
@@ -8815,6 +9130,11 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
8815
9130
  const [grp, setGrp] = useState('rec')
8816
9131
  const [sel, setSel] = useState(null)
8817
9132
  const [view, setView] = useState(-1)
9133
+ const [fp, setFp] = useState('') // 正在换哪个字体变量(#31)
9134
+ const [, setLibTick] = useState(0)
9135
+ useEffect(() => { if (tab !== 'set') setFp('') }, [tab])
9136
+ // 字体变量那行要显示字体库的中文名:开面板时读一次列表
9137
+ useEffect(() => { if (tab === 'set' && !LIB_FONTS.length) loadLibFonts().then(() => setLibTick((n) => n + 1), () => {}) }, [tab])
8818
9138
  // 进原大样板:焦点给样板(← → 翻、Esc 回去);回卡片:焦点回到选中的那张
8819
9139
  const root = useRef(null)
8820
9140
  const seen = useRef(false)
@@ -8900,8 +9220,28 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
8900
9220
  h('button', { className: 'dd-bt pri', onClick: onTokMake }, h(I.sparkle), t('tokensAsk')))), foot)
8901
9221
  }
8902
9222
  const colors = groups.color || []
9223
+ const fpTok = fp && tokens.find((x) => x.name === fp)
9224
+ if (fpTok) {
9225
+ return box(h(FontPicker, {
9226
+ key: 'fp:' + scope + '\n' + fpTok.name, // 换了一套设计就是另一个(下载慢、回来晚的那次选择不会落到新设计上)
9227
+ t,
9228
+ label: names.get(fpTok.name),
9229
+ value: hasOwn(tv, fpTok.name) ? tv[fpTok.name] : fpTok.value,
9230
+ onPick: (v) => onTv(fpTok.name, v),
9231
+ onBack: () => setFp(''),
9232
+ onAsk: () => { setFp(''); onTokAsk(fpTok) },
9233
+ }), foot)
9234
+ }
8903
9235
  const tokRow = (tok) => {
8904
9236
  const k = tokenKind(tok)
9237
+ if (k === 'font') {
9238
+ const ch = hasOwn(tv, tok.name)
9239
+ const v = ch ? tv[tok.name] : tok.value
9240
+ return h('button', { key: tok.name, className: 'dd-tkr fnt' + (ch ? ' on' : ''), title: `${tok.name}: ${v}\n${t('fpRowTip')}`, onClick: () => setFp(tok.name) },
9241
+ h('span', { className: 'nm', style: libOfStack(v) ? null : { fontFamily: v } }, names.get(tok.name)),
9242
+ h('span', { className: 'vl' }, fontShort(t, v)),
9243
+ h('span', { className: 'go', 'aria-hidden': 'true' }, h(I.back)))
9244
+ }
8905
9245
  const st = k === 'font' ? { fontFamily: tok.value } : k === 'size' ? { fontSize: Math.max(11, Math.min(17, pxOf(tok.value, tokens) || 13)) + 'px', fontWeight: (pxOf(tok.value, tokens) || 0) >= 20 ? 600 : 400 } : null
8906
9246
  const short = tokenShort(k, tok.value)
8907
9247
  return h('button', { key: tok.name, className: 'dd-tkr', title: `${tok.name}: ${tok.value}\n${t('lookTokTip')}`, onClick: () => onTokAsk(tok) },
@@ -9383,7 +9723,8 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
9383
9723
  let out = Object.keys(live).length ? formatTweaks(t, list, live) : ''
9384
9724
  const rows = Object.entries(tv).map(([name, v]) => {
9385
9725
  const tok = tokens.find((x) => x.name === name)
9386
- return `- ${name}(${tok ? tokenLabel(t, tok) : name}):${tok ? tok.value : '?'} → ${v}`
9726
+ const lf = libOfStack(v)
9727
+ return `- ${name}(${tok ? tokenLabel(t, tok) : name}):${tok ? tok.value : '?'} → ${v}${lf ? t('lookLibFont', { name: t('lang') === 'en' ? lf.en : lf.zh, var: name }) : ''}`
9387
9728
  })
9388
9729
  if (rows.length) out += t('lookAskHead') + '\n' + rows.join('\n') + '\n' + t('lookAskTail') + '\n'
9389
9730
  return out
@@ -10398,7 +10739,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
10398
10739
  // 几百屏的设计(#29):只列前 12 个名字
10399
10740
  return t('pubScreens', { n: list.length, names: list.slice(0, 12).join(t('sep')) + (list.length > 12 ? t('pubMoreNames') : '') })
10400
10741
  })()
10401
- const errText = (r) => (r.error === 'tooBig' ? t('pubTooBig') : r.error === 'noScreens' ? t('pubNoScreens') : t('pubFail', { msg: r.message || r.error || '' }))
10742
+ const errText = (r) => (r.error === 'tooBig' ? t('pubTooBig') : r.error === 'imgTooBig' ? t('htmlImgBig') : r.error === 'mockTooBig' ? t('htmlMockBig') : r.error === 'noScreens' ? t('pubNoScreens') : t('pubFail', { msg: r.message || r.error || '' }))
10402
10743
  // 接口拒了(点生成的那一刻换了设计、或者现在看的不是本地文件):别说成「没连上 Cloudflare」
10403
10744
  const errMsg = (m) => (m === 'designChanged' || m === 'not-file' ? t('pubGone') : t('pubFail', { msg: m }))
10404
10745
  const ended = (r) => (r.ended === 'expired' ? t('pubEndExpired') : r.ended === 'dropped' ? t('pubEndDropped') : r.ended === 'moved' ? t('pubEndMoved') : '')
@@ -10433,7 +10774,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
10433
10774
  h('button', { type: 'button', className: 'dd-bt pri', onClick: () => onCopy(res.url) }, h(I.copy), t('phoneCopy')),
10434
10775
  h('button', { type: 'button', className: 'dd-bt danger', onClick: stop }, h(I.stopSq), t('pubStop'))),
10435
10776
  res.state === 'reconnecting' ? h('p', { className: 'fine warn' }, t('pubReconnectingFine')) : null,
10436
- res.broken ? h('p', { className: 'fine warn' }, t('pubBroken', { why: res.broken === 'tooBig' ? t('pubTooBig') : res.broken === 'noScreens' ? t('pubNoScreens') : res.broken })) : null,
10777
+ res.broken ? h('p', { className: 'fine warn' }, t('pubBroken', { why: res.broken === 'tooBig' ? t('pubTooBig') : res.broken === 'imgTooBig' ? t('htmlImgBig') : res.broken === 'mockTooBig' ? t('htmlMockBig') : res.broken === 'noScreens' ? t('pubNoScreens') : res.broken })) : null,
10437
10778
  res.screens && res.screens.length ? h('p', { className: 'fine' }, t('pubShared', { n: res.screens.length, names: res.screens.join(t('sep')) })) : null),
10438
10779
  notes(['pubHow', 'pubLive', 'pubWarn']))
10439
10780
  } else if (res.dl && !res.dl.done && !res.tool) {
@@ -10552,6 +10893,120 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
10552
10893
  : h('div', { className: 'bd' }, emptyBox(I.history, t('histEmptyT'), t('histEmpty'))))
10553
10894
  }
10554
10895
 
10896
+ /**
10897
+ * 「数据」(#30 模拟数据):设计目录里有 mock.json 才有。面板里藏一个预览地址上的小页(/__dsh_design__/mock.html)当桥:
10898
+ * 它和各屏读写同一份数据(同一个地址的 localStorage),这里改了各屏马上跟着变,各屏点出来的变化也马上显示在这
10899
+ */
10900
+ const MOCK_SHOW = 200 // 一层最多列多少
10901
+ const mkSame = (a, b) => { try { return JSON.stringify(a) === JSON.stringify(b) } catch { return false } }
10902
+ const mkAt = (o, keys) => { let v = o; for (const k of keys) { if (v == null || typeof v !== 'object') return undefined; v = v[k] } return v }
10903
+ /** 叶子上不一样的有几处(和 mock.json 比) */
10904
+ function mkDiff(a, b) {
10905
+ if (mkSame(a, b)) return 0
10906
+ if (!a || !b || typeof a !== 'object' || typeof b !== 'object' || Array.isArray(a) !== Array.isArray(b)) return 1
10907
+ let n = 0
10908
+ for (const k of new Set([...Object.keys(a), ...Object.keys(b)])) n += mkDiff(a[k], b[k])
10909
+ return n
10910
+ }
10911
+ /** 列表里一条(对象)收着时旁边写什么:头一个文字 / 数字字段 */
10912
+ const mkPeek = (v) => { for (const x of Object.values(v || {})) if (typeof x === 'string' ? x.trim() : typeof x === 'number') return String(x).slice(0, 40); return '' }
10913
+ function DataPanel({ t, head, origin, fp, err, write, onFix, onSave, onSay }) {
10914
+ const fr = useRef(null)
10915
+ const [snap, setSnap] = useState(null) // 桥报上来的:{ data, initial, err }
10916
+ const [dead, setDead] = useState(false)
10917
+ const [fold, setFold] = useState(() => new Map()) // 路径 → 开 / 收(点过的才记)
10918
+ const got = useRef(false)
10919
+ useEffect(() => {
10920
+ got.current = false
10921
+ setSnap(null)
10922
+ setDead(false)
10923
+ const on = (e) => {
10924
+ const d = e.data
10925
+ if (!fr.current || e.source !== fr.current.contentWindow || e.origin !== origin || !d || d.ddpMock !== 1) return
10926
+ if (d.type === 'data') {
10927
+ got.current = true
10928
+ setDead(false)
10929
+ setSnap({ data: d.data && typeof d.data === 'object' ? d.data : {}, initial: d.initial && typeof d.initial === 'object' ? d.initial : {}, err: String(d.err || ''), fp: String(d.fp || '') })
10930
+ } else if (d.type === 'fail') onSay(t('dataFail', { msg: String(d.msg || '') }))
10931
+ }
10932
+ addEventListener('message', on)
10933
+ const tm = setTimeout(() => { if (!got.current) setDead(true) }, 8000)
10934
+ return () => { removeEventListener('message', on); clearTimeout(tm) }
10935
+ }, [origin, fp])
10936
+ const send = (m) => { const w = fr.current && fr.current.contentWindow; if (w) try { w.postMessage({ ddpMock: 1, ...m }, origin) } catch { /* 桥不在了 */ } }
10937
+ const setAt = (keys, value) => send({ type: 'set', keys, value })
10938
+ const bridge = h('iframe', { key: 'br:' + fp, ref: fr, className: 'dd-mkbr', src: `${origin}/__dsh_design__/mock.html?fp=${encodeURIComponent(fp || '')}`, title: 'mock', 'aria-hidden': true, tabIndex: -1, onLoad: () => send({ type: 'get' }) })
10939
+ const bad = (snap && snap.err) || err
10940
+ const errBox = bad ? h('div', { className: 'dd-mkerr', key: 'err' }, h(I.warn), h('span', null, h('b', null, t('dataBadT')), ' · ', bad), h('button', { className: 'dd-bt', onClick: () => onFix(bad) }, h(I.sparkle), t('dataFix'))) : null
10941
+ const n = snap ? mkDiff(snap.data, snap.initial) : 0
10942
+ const foot = h('footer', { className: 'dd-sf' },
10943
+ h('span', { className: 'note' }, snap ? (n ? t('dataN', { n }) : t('dataSame')) : ''),
10944
+ h('button', { className: 'dd-bt ghost', disabled: !n, ...tipA(t('dataReset'), t('dataResetTip')), onClick: () => { send({ type: 'reset' }); onSay(t('dataResetDone')) } }, h(I.refresh), t('dataReset')),
10945
+ h('button', { className: 'dd-bt pri go', disabled: !n || !write.ok || !!bad, ...tipA(t('dataSave'), bad ? t('dataBadFile') : write.ok ? t('dataSaveTip') : write.tip), onClick: () => snap && !bad && onSave(snap.data, snap.fp) }, t('dataSave')))
10946
+ const box = (body) => h('div', { className: 'ddp-tokens ddp-data', onPointerDown: (e) => e.stopPropagation() }, head, body, foot, bridge)
10947
+ if (!snap) {
10948
+ return box(h('div', { className: 'bd', key: 'w' }, errBox, dead
10949
+ ? emptyBox(I.data, t('dataNoneT'), t('dataNone'))
10950
+ : h('div', { className: 'dd-ckwait' }, h('i', { className: 'dd-spin' }), h('span', null, t('dataWait')))))
10951
+ }
10952
+ // 开着还是收着:点过的照点的;没点过的,最上一层开着,别的小的(不在列表里)开着
10953
+ const isOpen = (path, d, size, inArr) => (fold.has(path) ? fold.get(path) : d === 0 || (!inArr && d <= 2 && size <= 6))
10954
+ const toggle = (path, on) => setFold((m) => new Map(m).set(path, on))
10955
+ const editor = (keys, v) => {
10956
+ const nm = keys.join('.')
10957
+ if (typeof v === 'boolean') return h('button', { className: 'sw', role: 'switch', 'aria-checked': v, 'aria-label': nm, onClick: () => setAt(keys, !v) }, swOf(v))
10958
+ if (v === null) return h('span', { className: 'nul' }, t('dataNull'))
10959
+ const num = typeof v === 'number'
10960
+ const back = (el) => { el.value = String(v) }
10961
+ return h('input', {
10962
+ key: 'in:' + JSON.stringify(v),
10963
+ className: 'tx' + (num ? ' num' : ''),
10964
+ defaultValue: String(v),
10965
+ inputMode: num ? 'decimal' : undefined,
10966
+ spellCheck: false,
10967
+ 'aria-label': nm,
10968
+ onKeyDown: (e) => {
10969
+ if (e.nativeEvent.isComposing || e.keyCode === 229) return
10970
+ if (e.key === 'Enter') e.currentTarget.blur()
10971
+ else if (isEsc(e)) { e.stopPropagation(); back(e.currentTarget); e.currentTarget.blur() }
10972
+ },
10973
+ onBlur: (e) => {
10974
+ const s = e.currentTarget.value
10975
+ if (s === String(v)) return
10976
+ if (!num) return setAt(keys, s)
10977
+ const x = Number(s.trim())
10978
+ if (!s.trim() || !Number.isFinite(x)) return back(e.currentTarget)
10979
+ setAt(keys, x)
10980
+ },
10981
+ })
10982
+ }
10983
+ const rows = []
10984
+ const walk = (keys, label, v, d, inArr) => {
10985
+ const path = keys.join('\u0001')
10986
+ const chg = !mkSame(v, mkAt(snap.initial, keys))
10987
+ const dot = chg ? h('i', { className: 'chg', title: t('dataChg'), 'aria-label': t('dataChg') }) : null
10988
+ const del = inArr ? h('button', { className: 'del', ...tipA(t('dataDel')), onClick: () => { const up = keys.slice(0, -1); const a = mkAt(snap.data, up); if (Array.isArray(a)) setAt(up, a.filter((_, i) => String(i) !== keys[keys.length - 1])) } }, h(I.close)) : null
10989
+ const style = { '--d': d }
10990
+ if (v && typeof v === 'object') {
10991
+ const arr = Array.isArray(v)
10992
+ const ks = arr ? v.map((_, i) => String(i)) : Object.keys(v)
10993
+ const op = isOpen(path, d, ks.length, inArr)
10994
+ const peek = inArr && !arr && !op ? mkPeek(v) : ''
10995
+ rows.push(h('div', { key: path, className: 'dd-mkr grp' + (op ? ' op' : ''), style },
10996
+ h('button', { className: 'fold', 'aria-expanded': op, onClick: () => toggle(path, !op) }, h(I.chev), h('span', { className: 'k' }, label), dot, h('span', { className: 'ct' }, peek || t(arr ? 'dataItems' : 'dataKeys', { n: ks.length }))),
10997
+ del))
10998
+ if (!op) return
10999
+ for (const k of ks.slice(0, MOCK_SHOW)) walk([...keys, k], arr ? '#' + (Number(k) + 1) : k, v[k], d + 1, arr)
11000
+ if (ks.length > MOCK_SHOW) rows.push(h('div', { key: path + '\u0002more', className: 'dd-mkr more', style: { '--d': d + 1 } }, t('dataMore', { n: ks.length - MOCK_SHOW })))
11001
+ if (arr && v.length) rows.push(h('div', { key: path + '\u0002add', className: 'dd-mkr add', style: { '--d': d + 1 } }, h('button', { className: 'dd-bt ghost', ...tipA(t('dataAdd'), t('dataAddTip')), onClick: () => setAt(keys, [...v, JSON.parse(JSON.stringify(v[v.length - 1]))]) }, h(I.plus), t('dataAdd'))))
11002
+ return
11003
+ }
11004
+ rows.push(h('div', { key: path, className: 'dd-mkr', style }, h('span', { className: 'k', title: keys.join('.') }, label), dot, h('span', { className: 'v' }, editor(keys, v)), del))
11005
+ }
11006
+ for (const k of Object.keys(snap.data)) walk([k], k, snap.data[k], 0, false)
11007
+ return box(h('div', { className: 'bd dd-mk', key: 'tree' }, errBox, ...rows))
11008
+ }
11009
+
10555
11010
  /**
10556
11011
  * 画布:几屏排成网格,能拖、能缩放(触控板双指滑 = 平移,捏合 / ⌘ 滚轮 = 缩放)。
10557
11012
  * 平时每屏上盖一层「挡板」:点一下选中,双击只看这一屏;选取时拿掉挡板,直接在页面里点。
@@ -12145,7 +12600,8 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
12145
12600
  for (const sc of list) {
12146
12601
  const ss = sc.v ? [] : statesFor(sc.key) || []
12147
12602
  if (ss.length < 2) { out.push(sc); continue }
12148
- ss.forEach((s, i) => out.push({ ...sc, url: withState(sc.url, i ? s.name : ''), xs: s.name, xsLabel: s.label, xsFirst: i === 0 }))
12603
+ // 第一个状态也写明(状态跟着模拟数据走的屏,不写就是数据里那个状态,会和后面某张重复)
12604
+ ss.forEach((s, i) => out.push({ ...sc, url: withState(sc.url, s.name), xs: s.name, xsLabel: s.label, xsFirst: i === 0 }))
12149
12605
  }
12150
12606
  return out
12151
12607
  }
@@ -12235,7 +12691,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
12235
12691
  const toDefault = (sc) => {
12236
12692
  if (!sc.state || sc.v || !statesFor) return sc
12237
12693
  const ss = statesFor(sc.key) || []
12238
- return ss.length >= 2 ? { ...sc, url: withState(sc.url, ''), state: '', xs: ss[0].name, xsLabel: ss[0].label, xsFirst: true } : sc
12694
+ return ss.length >= 2 ? { ...sc, url: withState(sc.url, ss[0].name), state: '', xs: ss[0].name, xsLabel: ss[0].label, xsFirst: true } : sc
12239
12695
  }
12240
12696
  const precheck = (tok, def) => {
12241
12697
  const pool = def ? every.map(toDefault) : every
@@ -12412,11 +12868,12 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
12412
12868
  const r = await post('htmlpack', { session: sid, ...b, name: (ver ? `v${ver.n}-` : '') + (b.title || 'design') + (dark ? '-dark' : '') })
12413
12869
  const file = String(r.path || '').split(/[\\/]/).pop()
12414
12870
  const miss = Array.isArray(r.missing) ? r.missing.length : 0
12415
- say((miss ? t('exportedHtmlMiss', { name: file, n: r.count, miss }) : t('exportedHtml', { name: file, n: r.count })) + cutTail() + (r.ai ? ' · ' + t('xoAi', { n: r.ai }) : ''), { label: t('reveal'), run: () => post('reveal', { path: r.path }).catch(() => {}) })
12871
+ const skip = Array.isArray(r.skipped) ? r.skipped : []
12872
+ say((miss ? t('exportedHtmlMiss', { name: file, n: r.count, miss }) : t('exportedHtml', { name: file, n: r.count })) + (skip.length ? t('exportedHtmlSkip', { n: r.skippedN || skip.length, files: skip.slice(0, 3).map((x) => String(x).split('/').pop()).join('、') + ((r.skippedN || skip.length) > 3 ? '…' : '') }) : '') + cutTail() + (r.ai ? ' · ' + t('xoAi', { n: r.ai }) : ''), { label: t('reveal'), run: () => post('reveal', { path: r.path }).catch(() => {}) })
12416
12873
  } catch (e) {
12417
12874
  const m = String((e && e.message) || '')
12418
12875
  if (m === 'designChanged' || m === 'not-file') sayErr(t('xoGone'))
12419
- else if (m === 'tooBig' || m === 'noScreens') sayErr(t(m === 'tooBig' ? 'htmlTooBig' : 'htmlNoScreens'))
12876
+ else if (m === 'tooBig' || m === 'noScreens' || m === 'imgTooBig' || m === 'mockTooBig') sayErr(t(m === 'tooBig' ? 'htmlTooBig' : m === 'imgTooBig' ? 'htmlImgBig' : m === 'mockTooBig' ? 'htmlMockBig' : 'htmlNoScreens'))
12420
12877
  else sayErr(t('exportFail', { msg: m }), { label: t('retry'), run: () => exportHtml() })
12421
12878
  }
12422
12879
  }
@@ -12868,14 +13325,14 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
12868
13325
  const u = new URL(href)
12869
13326
  key = keyOfPath(decodeURIComponent(u.pathname), fileTarget)
12870
13327
  given = u.searchParams.get('state') || ''
12871
- state = STATE_RE.test(given) && dec.includes(given) && given !== dec[0] ? given : ''
13328
+ state = STATE_RE.test(given) && dec.includes(given) && (given !== dec[0] || followsMock(raw)) ? given : ''
12872
13329
  } catch { return }
12873
13330
  setDemo((d) => {
12874
13331
  if (!d) return d
12875
13332
  const last = d.layers[d.layers.length - 1]
12876
13333
  // 还是这一层载的那个地址(跨页链接带的 ?state= 那页没写,地址里照样有):没跳,别改记下的、别再载一遍
12877
13334
  // 没写状态的页(老页面自己拿 ?state= 当参数)自己换了参数:也不算换屏,别动这一层(一动地址就变、重载,参数丢了)
12878
- if (last.id !== id || (last.key === key && (!dec.length || (last.state || '') === given || norm(last, dec[0] || defOf(key)) === state))) return d
13335
+ if (last.id !== id || (last.key === key && (!dec.length || (last.state || '') === given || norm(last, followsMock(raw) ? '' : dec[0] || defOf(key)) === state))) return d
12879
13336
  return { stack: [...d.stack.slice(0, -1), { key, state }], layers: d.layers.map((l) => (l.id === id ? { ...l, key, state, hash: l.key === key ? l.hash : '' } : l)) }
12880
13337
  })
12881
13338
  }
@@ -13076,15 +13533,16 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
13076
13533
  const tg = st && st.target
13077
13534
  const site = tg ? (tg.kind === 'file' ? 'file:' + String(tg.file || '').replace(/[\\/][^\\/]*$/, '') : 'proxy:' + tg.port) : origin
13078
13535
  const busy = !!(st && st.turn)
13079
- // 一页多状态(#30):这屏写了哪几个状态(页面报上来的)、现在看哪个;选了不是默认的那屏,地址带上 ?state=
13536
+ // 一页多状态(#30):这屏写了哪几个状态(页面报上来的)、现在看哪个;点名选了的(第一个也算)地址带上 ?state=——
13537
+ // 状态跟着模拟数据走的页,不带就是数据里那个,选「第一个」不带就切不回去
13080
13538
  const statesOf = (key) => parseStates((info[site + '|' + key] || {}).states)
13081
13539
  const stateFor = (key) => {
13082
13540
  const s = stSel[site + '|' + key]
13083
- return s && statesOf(key).some((x, i) => i > 0 && x.name === s) ? s : ''
13541
+ return s && statesOf(key).some((x) => x.name === s) ? s : ''
13084
13542
  }
13085
13543
  const pickState = (key, name) => {
13086
13544
  const list = statesOf(key)
13087
- const v = list.length && name !== list[0].name ? name : ''
13545
+ const v = list.some((x) => x.name === name) ? name : ''
13088
13546
  setStSel((m) => ((m[site + '|' + key] || '') === v ? m : { ...m, [site + '|' + key]: v }))
13089
13547
  }
13090
13548
  const screens = ((st && st.screens) || []).map((sc) => { const s = stateFor(sc.key); return s ? { ...sc, url: withState(sc.url, s), state: s } : sc })
@@ -13344,7 +13802,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
13344
13802
  const twGen = useRef(0) // 换一次设计加一:晚到的保存回包认得出是上一套的
13345
13803
  useEffect(() => { twGen.current++; setTw({}); setTv({}) }, [site])
13346
13804
  // 拖的滑块 + 外观面板里直接改的颜色:一起发给页面先看效果
13347
- const tweak = Object.keys(tw).length || Object.keys(tv).length ? (() => { const m = tweakMsg(tlist, tw); return { vars: { ...m.vars, ...tv }, attrs: m.attrs } })() : null
13805
+ const tweak = Object.keys(tw).length || Object.keys(tv).length ? (() => { const m = tweakMsg(tlist, tw); return { vars: { ...m.vars, ...tv }, attrs: m.attrs, fonts: tweakFontsOf(tv) } })() : null
13348
13806
  // 业务标注:开关开着才有 st.annotations 这个键(null = 还没有文件)
13349
13807
  const anOn = !!st && Object.prototype.hasOwnProperty.call(st, 'annotations')
13350
13808
  const anFile = anOn ? st.annotations : null
@@ -13727,7 +14185,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
13727
14185
  if (inf && !(inf.links || []).length) say(t('demoNone'))
13728
14186
  }
13729
14187
  // 演示里跳屏、返回、从头来(makeDemoNav)
13730
- const { demoGo, demoTo, demoRestart, demoBack, demoShown, demoHref } = makeDemoNav({ setDemo, demoSeq, fileTarget, defOf: (key) => { const ss = statesOf(key); return ss.length ? ss[0].name : '' } })
14188
+ const { demoGo, demoTo, demoRestart, demoBack, demoShown, demoHref } = makeDemoNav({ setDemo, demoSeq, fileTarget, defOf: (key) => { const ss = statesOf(key); return ss.length && !followsMock((info[site + '|' + key] || {}).states) ? ss[0].name : '' } })
13731
14189
  const { implLoad, implRecompare } = makeImpl({ sid, setImpl, setImplRun, say, t })
13732
14190
  // 和做出来的比:在比哪一屏(看旧版本时不比)、那屏记着的地址和上次的分数
13733
14191
  const implSc = impl && !ver ? screens.find((x) => x.key === impl.key) || null : null
@@ -14218,6 +14676,19 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
14218
14676
  // 右边同一时间只开一个面板:别的开了,这几个关掉;开这几个时别的关掉
14219
14677
  const oldOpen = !!(panel || hist || phone || pubP || ck || styleEdit)
14220
14678
  useEffect(() => { if (oldOpen) setPane('') }, [oldOpen])
14679
+ // 「数据」(模拟数据):本地文件的设计、目录里有 mock.json 才有;从别的设备打开的 DSH 够不着电脑上的预览地址,不给;
14680
+ // 看旧版本时不给(旧版本的屏用的是自己那份数据,面板改的是现在的)
14681
+ const mockOn = !!(fileTarget && st && st.mock && url && !away(url) && !ver)
14682
+ useEffect(() => { if (pane === 'data' && !mockOn) setPane('') }, [pane, mockOn])
14683
+ const saveMockData = async (data, fp) => {
14684
+ try {
14685
+ const r = await post('mocksave', { session: sid, root: st && st.target ? st.target.root : '', data, fp: fp || '' })
14686
+ if (!r.ok) return say(r.reason === 'busy' ? t('styleBusyTip') : r.reason === 'moved' ? t('twMoved') : r.reason === 'big' ? t('dataBig') : r.reason === 'no-mock' ? t('dataNoMock') : r.reason === 'changed' ? t('dataChanged') : r.reason === 'bad-file' ? t('dataBadFile') : t('twNoWrite'))
14687
+ showFlash(t('dataSaved'))
14688
+ } catch (e) {
14689
+ sayErr(t('failed', { msg: e.message }))
14690
+ }
14691
+ }
14221
14692
  const openPane = (p) => {
14222
14693
  const next = pane === p ? '' : p
14223
14694
  if (next) { setPanel(false); setHist(false); setPhone(false); setPubP(false); closeCheck(); setStyleEdit(false); setAn(false) }
@@ -14235,7 +14706,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
14235
14706
  const sentTv = tv
14236
14707
  const gen = twGen.current
14237
14708
  const r = await post('tweak', { session: sid, root: st && st.target ? st.target.root : '', values: sentTw, vars: sentTv })
14238
- if (!r.ok) return say(r.reason === 'busy' ? t('styleBusyTip') : r.reason === 'moved' ? t('twMoved') : t('twNoWrite'))
14709
+ if (!r.ok) return say(r.reason === 'busy' ? t('styleBusyTip') : r.reason === 'moved' ? t('twMoved') : r.reason === 'font-off' ? t('fontOffSave') : r.reason === 'font-net' ? t('fontNetSave') : r.reason === 'font-write' ? t('fontWriteSave') : t('twNoWrite'))
14239
14710
  if (r.missed && r.missed.length) sayErr(t('twMissed', { names: r.missed.map((x) => { const tok = String(x.id).startsWith('--') && tokens.find((k) => k.name === x.id); return tok ? tokenLabel(t, tok) : x.label }).join(t('sep')) }))
14240
14711
  else showFlash(t('twSaved', { n: r.changed.length }))
14241
14712
  // 写进去的(设计变量、滑块):放掉,页面重新读文件就是新值了(滑块和配色管同一个颜色时以配色为准,滑块的旧值也得放掉);
@@ -14293,7 +14764,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
14293
14764
  const packOther = !!packDir && !(fileTarget && st && st.target && packDir === st.target.root)
14294
14765
  const shareTab = phone ? 'phone' : pubP ? 'pub' : pane === 'pack' && !packOther ? 'demo' : pane === 'share' && !packOther ? 'submit' : ''
14295
14766
  const sheet = styleEdit ? 'style' : panel ? 'look' : ck || anUp ? 'check' : hist ? 'ver' : shareTab ? 'share'
14296
- : pane === 'export' ? 'export' : pane === 'handoff' ? 'code' : pane === 'pack' ? 'pack' : pane === 'share' ? 'submit' : pane === 'zip' && zipIssues ? 'zip' : ''
14767
+ : pane === 'export' ? 'export' : pane === 'handoff' ? 'code' : pane === 'pack' ? 'pack' : pane === 'share' ? 'submit' : pane === 'zip' && zipIssues ? 'zip' : pane === 'data' && mockOn ? 'data' : ''
14297
14768
  const closeShare = () => { setPhone(false); setPubP(false); if (pane === 'pack' || pane === 'share') setPane('') }
14298
14769
  // 标题栏「分享」:开着手机看 / 公网链接时直接到那一页
14299
14770
  const toggleShare = () => (sheet === 'share' ? closeShare() : pubOn && fileTarget ? togglePub() : togglePhone())
@@ -14306,7 +14777,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
14306
14777
  const tool = (cls, on, desc, off, run, Icon, label, extra, k) => h('button', { className: 'ddp-tool' + (cls ? ' ' + cls : '') + (on ? ' on' : ''), ...tipA(label, desc, on ? 'Esc' : k || ''), 'aria-pressed': !!on, disabled: !!off, onClick: run }, h(Icon), h('span', null, label), extra || null)
14307
14778
  const badgeOf = (n) => (n ? h('span', { className: 'bdg' }, n > 99 ? '99+' : String(n)) : null)
14308
14779
  // 灵动条放得下多少:全宽 → 藏快捷键 → 「说一句」收成图标 → 工具也只剩图标(两边小块挪到上面一行)
14309
- const nTools = 7
14780
+ const nTools = mockOn ? 8 : 7
14310
14781
  const islW = (cmd, tw) => 12 + cmd + 4 + nTools * tw + 11
14311
14782
  const dwKey = (m) => t('askSay') + '|' + m + (busy && capAway ? '|run' : '')
14312
14783
  const dwOf = (m, est) => dockW.current[dwKey(m)] || est
@@ -14424,6 +14895,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
14424
14895
  tool('', mark, t('dMark'), markOff, toggleMark, I.pen, t('markShort'), null, 'P'),
14425
14896
  h('span', { className: 'dd-vs' }),
14426
14897
  tool('dm', !!demo, t('dPlay'), !url || !!ver, toggleDemo, I.play, t('demoShort'), null, 'R'),
14898
+ mockOn ? tool('', pane === 'data', t('dData'), false, () => openPane('data'), I.data, t('data')) : null,
14427
14899
  tool('', !!panel, t('dLook'), false, () => (panel ? setPanel(false) : openLook()), I.palette, t('look'), null, 'L'),
14428
14900
  tool('', !!ck || anUp, ckCount && !ck ? t('dCheckN', { n: ckCount }) : t('dCheck'), checkOff, () => (ck ? closeCheck() : anUp ? toggleAn() : runCheck()), I.shield, t('checkShort'), !ck && !anUp && !checkOff ? badgeOf(ckCount) : null, 'C')),
14429
14901
  implSc ? null : h('button', { key: 'ver', className: 'ddp-isl dd-mini' + (verIco ? ' ico' : '') + (hist ? ' on' : ''), ...tipA(t('history'), t('dHistory')), 'aria-pressed': hist, disabled: !fileTarget, onClick: toggleHist }, h(I.history), h('span', null, t('history'))),
@@ -14698,9 +15170,16 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
14698
15170
  t,
14699
15171
  head: hd({ icon: I.palette, title: t('look'), help: t({ tw: 'lookTwHint', style: 'stPickHint', brand: 'sysTip' }[lookTab] || 'hpLookSet'), tabs: [['set', t('lookSet')], ['tw', t('lookTw')], ['style', t('lookStyle')], ['brand', t('lookBrand')]], tab: lookTab, onTab: setLookTab }),
14700
15172
  tab: lookTab,
15173
+ scope: targetKey,
14701
15174
  tokens,
14702
15175
  tv,
14703
- onTv: (name, v) => setTv((c) => ({ ...c, [name]: v })),
15176
+ onTv: (name, v) => setTv((c) => {
15177
+ const tok = tokens.find((x) => x.name === name)
15178
+ // 和文件里一样就不算改——除非选的是字体库的字体、页面里却还没有它的 @font-face(旧设计本来就写着 "Noto Serif SC" 当后备):存下时才会放进来
15179
+ const pending = !!libOfStack(v) && !(tok && tok.face)
15180
+ if (tok && String(tok.value).trim() === String(v).trim() && !pending) { if (!hasOwn(c, name)) return c; const out = { ...c }; delete out[name]; return out }
15181
+ return { ...c, [name]: v }
15182
+ }),
14704
15183
  onTokAsk: (tok) => insert(formatToken(tok, stRef.current)),
14705
15184
  onTokMake: () => insert(t('tokensAskText') + '\n', 'insertedSend'),
14706
15185
  tw: tweaks,
@@ -14798,6 +15277,19 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
14798
15277
  }
14799
15278
  if (sheet === 'submit') return h(SharePanel, { t, head: hd({ icon: I.share, title: t('subT') }), sid, root: sheetRoot, brand: '', onFix: fixPack, onSay: say, onClose: () => setPane('') })
14800
15279
  if (sheet === 'pack') return h(PackPanel, { t, head: hd({ icon: I.box, title: t('pkTitle'), help: t('pkTip') }), sid, root: sheetRoot, onFix: fixPack, onSay: say, onClose: () => setPane('') })
15280
+ if (sheet === 'data') {
15281
+ return h(DataPanel, {
15282
+ t,
15283
+ head: hd({ icon: I.data, title: t('data'), help: t('dataHelp'), sub: 'mock.json' }),
15284
+ origin,
15285
+ fp: st.mock.fp,
15286
+ err: st.mock.err,
15287
+ write: busy ? { ok: false, tip: t('styleBusyTip') } : { ok: true },
15288
+ onFix: (err) => insert(t('dataFixText', { err }) + '\n', 'insertedSend'),
15289
+ onSave: saveMockData,
15290
+ onSay: say,
15291
+ })
15292
+ }
14801
15293
  if (sheet === 'zip') return h(ZipIssues, { t, head: hd({ icon: I.box, title: t('zipNotOpened') }), issues: zipIssues, onClose: () => { setPane(''); setZipIssues(null) } })
14802
15294
  if (sheet === 'export') {
14803
15295
  const imgModes = exportItems(t, kind, shown.length, exName).filter(([m]) => m !== 'pdf' && m !== 'pptx' && m !== 'opts')
@@ -14810,7 +15302,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
14810
15302
  }
14811
15303
  return null
14812
15304
  }
14813
- const SHEET_T = { style: 'style', look: 'look', check: 'check', ver: 'history', share: 'shareT', submit: 'subT', pack: 'pkTitle', zip: 'zipNotOpened', export: 'exportT', code: 'handoff' }
15305
+ const SHEET_T = { style: 'style', look: 'look', check: 'check', ver: 'history', share: 'shareT', submit: 'subT', pack: 'pkTitle', zip: 'zipNotOpened', export: 'exportT', code: 'handoff', data: 'data' }
14814
15306
  // 壳一直在(换面板时只换里面,淡出淡入);关的时候整张落下 / 滑走
14815
15307
  const sheetEl = (home) => h(Presence, { key: 'sheet', on: !!sheet, ms: 300 }, sheet ? h('div', {
14816
15308
  className: 'dd-sheet' + (box.w > 1000 ? ' wide' : '') + (home ? ' home' : ''),
@@ -14856,6 +15348,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
14856
15348
  add('mark', I.pen, t('markShort'), toggleMark, { key: 'P', on: mark, off: markOff, kw: kwOf('markShort') })
14857
15349
  add('demo', I.play, t('demoShort'), () => { if (implSc) implClose(); toggleDemo() }, { key: 'R', on: !!demo, off: noUrl || !!ver, top: true, kw: kwOf('demoShort') })
14858
15350
  add('look', I.palette, t('look'), () => (panel ? setPanel(false) : openLook()), { key: 'L', on: !!panel, top: true, kw: kwOf('look', 'lookSet') })
15351
+ if (mockOn) add('data', I.data, t('data'), () => openPane('data'), { on: pane === 'data', kw: kwOf('data', 'dataReset') + ' mock json' })
14859
15352
  add('look-style', I.palette, t('look') + ' · ' + t('lookStyle'), () => openLook('style'), { kw: kwOf('lookStyle') })
14860
15353
  add('look-brand', I.palette, t('look') + ' · ' + t('lookBrand'), () => openLook('brand'), { kw: kwOf('lookBrand') })
14861
15354
  add('check', I.shield, t('checkShort'), () => (ck ? closeCheck() : runCheck()), { key: 'C', on: !!ck, off: checkOff, top: true, note: ckCount && !ck ? String(ckCount) : '', kw: kwOf('checkShort') })
@@ -15054,7 +15547,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
15054
15547
  // 一页多状态(#30):这一屏的每个状态并排(第一个是默认);点选、改字照常,发给模型时说明是哪个状态
15055
15548
  const base = screens.find((x) => x.key === stAll) || { key: stAll, url: urlOfKey(stAll), label: stAll.replace(/\.html?$/i, '') }
15056
15549
  const list = statesOf(stAll)
15057
- const fake = list.map((x, i) => ({ key: 'st' + i, id: 'st:' + x.name + '|' + base.key, url: withState(base.url, i ? x.name : ''), label: x.label }))
15550
+ const fake = list.map((x, i) => ({ key: 'st' + i, id: 'st:' + x.name + '|' + base.key, url: withState(base.url, x.name), label: x.label }))
15058
15551
  body = h(Canvas, {
15059
15552
  key: 'stall',
15060
15553
  t,