dsh-design-studio 1.1.0 → 1.2.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/README.en.md CHANGED
@@ -43,6 +43,7 @@ If DSH can't reach the npm registry, it falls back to a mirror in China. To upda
43
43
  - **Open what you have:** home + › Open HTML… picks an HTML file, or drop an HTML file or folder onto the sidebar (desktop app); you can also type a path or a dev-server port.
44
44
  - **Design check:** one click finds overflowing text, low contrast, small tap targets and tiny text, marked right on the page. In Design mode the model also checks its own work and fixes what it finds.
45
45
  - **Clickable prototypes:** back arrows marked `data-back` go back to wherever you came from; the different looks of one page (empty list, with data, paid) are states in one file instead of extra screens, switchable next to the screen name on the canvas, and checked and exported state by state. The design check also points out a shared part that is styled differently on different screens (#30).
46
+ - **Mock data:** ask for a prototype whose clicks really change things and survive page changes, and the model writes `mock.json` as the data source and binds the pages to it: "Accept offer" switches the whole app to its on-site stage, clocking in updates the time, and it all stays across pages and reloads; a global stage or role changes every page at once. **Data** in the bottom bar opens the data as a tree: edit any value, reset it, or save it as the initial data. The HTML demo carries the data too, with a Reset data button (#30).
46
47
  - **Versions and compare:** every turn is saved; drag a slider to compare, and go back to any version.
47
48
  - **Export and share:** Export makes showcase images, PDF and PowerPoint (links between screens still work), and designs with hundreds of screens export in full (up to 1000). Share has a clickable HTML demo that opens with a double-click (device frame included, ready to send to a client), a temporary public link (beta; opens in WeChat or any browser, closes after 2 hours), and a QR code to see it on your phone at real size. Slides and posters larger than the default canvas now use the page's real size. You can also set it by adding `WIDTHxHEIGHT` after the type, for example `<meta name="dsh-design" content="slides 1440x810">`. Export options let you pick the page size (16:9, 4:3, A3 landscape or custom), what each page shows (one screen, full page or a set height) and two screens per page. If anything would be cut off, you get a checklist first, with a one-click fix that fits the canvas to the content.
48
49
  - **Diagrams:** mind maps, technical route charts (the kind in grant proposals and theses), product roadmaps and system architecture diagrams. Lines, branches and arrows are laid out for you and re-flow when you change text or add nodes; colors follow the design style, and a high-resolution PNG or PDF export drops straight into Word or PowerPoint. For grant-proposal and final-report frameworks, the model first lists how the parts relate (which problem maps to which task) for you to confirm, then draws labelled arrows between the blocks, in a bold 3D-gradient "proposal" style by default or after a reference image you give it.
package/README.md CHANGED
@@ -43,6 +43,7 @@
43
43
  - **打开已有的页面**:首页输入框左边的「+」→「打开 HTML…」选一个,或把 HTML 文件 / 文件夹拖进右侧栏就能预览(桌面版);也能输路径或开发服务器端口。
44
44
  - **设计体检**:一键查文字溢出、对比度不够、按钮太小、字太小,问题直接标在页面上;模型做完也会自己查一遍再改。
45
45
  - **点得动的原型**:返回按钮写上 `data-back` 就「从哪来回哪去」;同一个页面的几种样子(空列表 / 有数据 / 已付款)写成状态,不用另做一屏,画布上屏名旁边就能切,体检、导出每个状态都算;共用部件在各屏写得不一样时,体检会提醒(#30)。
46
+ - **模拟数据**:说「点了要真的变、换页还在」,模型会写一份 `mock.json` 当数据源,页面绑在上面——点「接受 Offer」整个 App 切到在项、打卡后时间变了,换页、刷新都还在;阶段、角色这种全局的东西一处改所有页一起变。底部「数据」打开就是一棵数据树:随手改、一键重置、存成初始数据;HTML 演示也带着数据和「重置数据」按钮(#30)。
46
47
  - **版本和对比**:每轮自动存一版,左右拖动对比,随时回到任意一版。
47
48
  - **导出和分享**:标题栏「导出」出展示图、PDF、PPT(屏和屏之间的跳转照样能点),几百屏的设计也全部导出(最多 1000 屏);「分享」里有双击就能开的 HTML 演示(带外壳、点得动,发给客户直接看)、临时公网链接(实验,微信里点开就能看,2 小时自动关),扫码在手机上按真机尺寸看。页面比默认画幅大的幻灯片、海报,画幅自动跟页面走;也可以在类型后面跟 `宽x高` 指定,比如 `<meta name="dsh-design" content="slides 1440x810">`。导出选项里可以选版面(16:9、4:3、A3 横向、自定义)、每页取景(一屏、整页、指定高度)和每页拼 2 屏;有内容会被裁时,导出前先给一张清单,可以一键按内容改画幅。
48
49
  - **图表**:思维导图、技术路线图(申报书、开题报告那种)、产品路线图、系统架构图。连线、分叉、箭头自动排好,改字、加节点自己重排;配色跟着设计风格走,导出高清 PNG 或 PDF 贴进 Word / PPT。申报书、结题报告的框架图先帮你理清「哪个问题对应哪项内容」请你确认再画,版块之间画出带关系词的箭头;默认是立体渐变的「申报书炫酷样式」,也能照你给的参考图画。
package/lib/browser.js CHANGED
@@ -223,7 +223,7 @@ export function createBrowser({ bin = findBrowser(), log = () => {}, idleMs = ID
223
223
  * allow(网址):给了就只让它说行的页面载入(主页面、iframe,连跳转、脚本改地址都算),别的拦下,记在 page.blocked
224
224
  * offline:断网渲染(设计库的检查):所有请求(样式、图片、字体、接口 …)只放行和页面同源的,别的一律拦下,记在 page.blocked
225
225
  */
226
- async function withPage({ url, w, h, scale = 1, dark = false, allow = null, offline = false, linger = idleMs }, fn) {
226
+ async function withPage({ url, w, h, scale = 1, dark = false, allow = null, offline = false, linger = idleMs, store = false }, fn) {
227
227
  if (dead) throw new Error('browser closed')
228
228
  if (open >= MAX_PAGES) await new Promise((r) => queue.push(r))
229
229
  if (dead) throw new Error('browser closed')
@@ -254,6 +254,9 @@ export function createBrowser({ bin = findBrowser(), log = () => {}, idleMs = ID
254
254
  await c('Fetch.enable', { patterns: offline ? [{ urlPattern: '*', requestStage: 'Request' }] : [{ urlPattern: '*', resourceType: 'Document', requestStage: 'Request' }] })
255
255
  }
256
256
  await c('Page.enable')
257
+ // 告诉页面这是无头浏览器在量 / 截图(设计台的模拟数据只放内存、不存:同一个浏览器里开的几屏互不串,量的都是初始数据)。
258
+ // store:要像真人那样存(测整套演示跨屏保留时)
259
+ if (!store) await c('Page.addScriptToEvaluateOnNewDocument', { source: 'window.__dshHeadless=1' }).catch(() => {})
257
260
  // 和右侧栏里一样按桌面方式排版(mobile: false):页面宽就是 w,不看 <meta viewport>
258
261
  await c('Emulation.setDeviceMetricsOverride', { width: w, height: h, deviceScaleFactor: scale, mobile: false })
259
262
  await c('Emulation.setEmulatedMedia', { features: [{ name: 'prefers-color-scheme', value: dark ? 'dark' : 'light' }, { name: 'prefers-reduced-motion', value: 'reduce' }] })
package/lib/bundle.js CHANGED
@@ -32,6 +32,52 @@ function join(base, ref) {
32
32
  }
33
33
 
34
34
  const escAttr = (s) => String(s).replace(/&/g, '&amp;').replace(/"/g, '&quot;')
35
+
36
+ const DATA_IMG = /\.(png|jpe?g|gif|webp|avif|bmp|ico|svg)$/i
37
+ /**
38
+ * 模拟数据(#30)里写的本地图片(「avatar": "img/me.png",页面用 data-mock-attr 绑到 src):打成单个文件时要换成 data: 地址,
39
+ * 不然演示里是坏图。数据本身不改(同一个字段拿来显示文件名还是文件名):回 { f: 真实路径 → data: 地址, r: 数据里写的那串 → 真实路径 },
40
+ * 运行时设 src / href 这类地址时查表。地址从设计目录根算;读不到的不进表(预览里本来也是坏的)。
41
+ * 同一张图(img/a.jpg、./img/a.jpg 写法不同也算)只放一份、只算一次大小。
42
+ * over:有这个文件、但太大换不下的放进这里(调用方据此报错,不能悄悄留个坏图);
43
+ * isBig(rel):read 给了 null 是因为文件太大(不是没有)——这种也算换不下
44
+ */
45
+ export function dataAssets(data, read, max = 8 * 1024 * 1024, over = null, isBig = null) {
46
+ let left = max
47
+ let nodes = 0
48
+ const done = new Map() // 相对路径 → data: 地址(换不下 / 没有:'')
49
+ const f = {}
50
+ const r = {}
51
+ const one = (s) => {
52
+ if (Object.prototype.hasOwnProperty.call(r, s)) return
53
+ const ref = localRef(s)
54
+ if (!ref || !DATA_IMG.test(ref)) return
55
+ const rel = join('_', ref)
56
+ if (rel.startsWith('..')) return
57
+ if (!done.has(rel)) {
58
+ let buf = null
59
+ try { buf = read(rel) } catch { buf = null }
60
+ let d = ''
61
+ if (buf && buf.length * 1.4 < left) {
62
+ const ext = path.posix.extname(rel).toLowerCase()
63
+ const t = (MIME[ext] || (ext === '.bmp' ? 'image/bmp' : 'application/octet-stream')).replace(/;.*/, '')
64
+ d = `data:${t};base64,${buf.toString('base64')}`
65
+ left -= d.length
66
+ } else if (over && (buf || (isBig && isBig(rel)))) over.push(rel)
67
+ done.set(rel, d)
68
+ }
69
+ const d = done.get(rel)
70
+ if (d) { f[rel] = d; r[s] = rel }
71
+ }
72
+ const walk = (v, depth) => {
73
+ if (++nodes > 20000 || depth > 40) return
74
+ if (typeof v === 'string') { if (v.length < 600) one(v); return }
75
+ if (Array.isArray(v)) { for (const x of v) walk(x, depth + 1); return }
76
+ if (v && typeof v === 'object') for (const k of Object.keys(v)) walk(v[k], depth + 1)
77
+ }
78
+ walk(data, 0)
79
+ return { f, r }
80
+ }
35
81
  const escScript = (s) => String(s).replace(/<\/(script)/gi, '<\\/$1').replace(/<!--/g, '<\\!--')
36
82
  /** 属性值里的实体解回来(只管引号和 &,style 里用得到的就这些) */
37
83
  const unAttr = (s) => String(s).replace(/&(quot|#0*34|#x0*22);/gi, '"').replace(/&(apos|#0*39|#x0*27);/gi, "'").replace(/&amp;/gi, '&')
package/lib/client.js CHANGED
@@ -205,6 +205,8 @@ window.__ModuleLoader__.load({
205
205
  exportedHtml: '已导出 {name}({n} 屏,发给别人双击就能看)',
206
206
  exportedHtmlMiss: '已导出 {name}({n} 屏,{miss} 屏没读到)',
207
207
  htmlTooBig: '图片太多,演示包超过 150 MB,没导出。少放几屏再试',
208
+ htmlImgBig: '模拟数据(mock.json)里绑的图太大(单张最多 12 MB、加起来最多 60 MB),放不进演示,没导出。换小一点的图再试',
209
+ htmlMockBig: 'mock.json 太大(超过 1 MB),演示里的数据带不上,没导出。把里面的大段内容(比如图片的 base64)换成图片文件路径再试',
208
210
  htmlNoScreens: '一屏都没读到(文件被挪走或删了?),没导出',
209
211
  xoWarn: '有内容会被裁掉,先看一眼',
210
212
  xoChecking: '正在量页面…',
@@ -301,6 +303,7 @@ window.__ModuleLoader__.load({
301
303
  ck_tight: '离固定栏太近',
302
304
  ck_jserr: '页面脚本报错',
303
305
  ck_missing: '文件没载出来',
306
+ ck_mockmiss: '模拟数据里没这个字段',
304
307
  ck_capsule: '被小程序胶囊挡住',
305
308
  ck_island: '被灵动岛挡住',
306
309
  ck_homebar: '伸进底部横条区',
@@ -331,6 +334,7 @@ window.__ModuleLoader__.load({
331
334
  cd_tight: '离{edgeName} {bar} 只有 {px}px(留 16px 以上)',
332
335
  cd_jserr: '{msg}{at}',
333
336
  cd_missing: '{what} {src} 载不出来(路径写错了,或者文件不在)',
337
+ cd_mockmiss: '用到了 {paths},mock.json 里没有(显示出来是空的)',
334
338
  cd_capsule: '伸进右上角胶囊 {px}px(胶囊是微信画的、盖不住:顶栏右边从 x={x} 起空着)',
335
339
  cd_island: '被灵动岛挡住 {px}px(灵动岛在 y 11–45:状态栏中间空着,内容放到状态栏下面)',
336
340
  cd_homebar: '{bar} 里的字或图标伸进底部横条区 {px}px(底部留 34px:栏加 padding-bottom: 34px,预览里 env(safe-area-inset-bottom) 是 0)',
@@ -1094,6 +1098,36 @@ window.__ModuleLoader__.load({
1094
1098
  anHelp: '模型读完设计,把规则、状态、流程写成一条条标注;点一条,页面上找到它。',
1095
1099
  hpLookSet: '点色块直接改颜色,所有屏一起变,点「保存」才写进文件;字体、形状点一项会放进对话,接着说怎么改。',
1096
1100
  histHelp: '模型每轮改完、你每次手调保存,都会自动存一版:能和现在并排比,也能退回去。',
1101
+ data: '数据',
1102
+ dData: '原型里点出来的数据:随时看、随手改、一键重置',
1103
+ dataHelp: '原型里点出来的变化都记在这,换页、刷新都还在。在这里改,页面马上跟着变;「存成初始数据」写回 mock.json,以后重置就回到这里。',
1104
+ dataWait: '正在读数据…',
1105
+ dataNoneT: '读不到数据',
1106
+ dataNone: '预览页面没开起来;关掉面板再开一次试试',
1107
+ dataBadT: 'mock.json 读不出来',
1108
+ dataFix: '让模型修好',
1109
+ dataFixText: 'mock.json 读不出来({err})。请修好它:要是一个 JSON 对象,原型里用到的字段都留着。',
1110
+ dataN: '改过 {n} 处(和 mock.json 比)',
1111
+ dataSame: '和 mock.json 一样',
1112
+ dataReset: '重置',
1113
+ dataResetTip: '所有屏一起回到 mock.json 里的初始数据',
1114
+ dataResetDone: '数据已重置',
1115
+ dataSave: '存成初始数据',
1116
+ dataSaveTip: '把现在的数据写回 mock.json,以后重置就回到这里',
1117
+ dataSaved: '已存成初始数据',
1118
+ dataNoMock: 'mock.json 不在了,没存',
1119
+ dataChanged: 'mock.json 刚被改过(模型或别的窗口),没存,免得把新的盖掉;面板会换成新的那份',
1120
+ dataBadFile: 'mock.json 读不出来,先让模型修好再存',
1121
+ dataBig: '数据太大存不下(最多 1 MB)',
1122
+ dataFail: '没改成:{msg}',
1123
+ dataNull: '空',
1124
+ dataItems: '{n} 条',
1125
+ dataKeys: '{n} 项',
1126
+ dataMore: '还有 {n} 条没列出来',
1127
+ dataAdd: '加一条',
1128
+ dataAddTip: '照最后一条复制一条',
1129
+ dataDel: '删掉这条',
1130
+ dataChg: '改过',
1097
1131
  styleHelp: '拖滑块时页面上先看效果,还没写进文件;满意了点「保存」,或点「让模型改」交给模型写进样式表。',
1098
1132
  hoHelp: '模型先写一份交接说明,再一屏一屏做;每屏做完自动和设计稿比一次,差多少写在「做完怎么验」里。',
1099
1133
  inPick: '选图片',
@@ -1396,6 +1430,8 @@ window.__ModuleLoader__.load({
1396
1430
  exportedHtml: 'Exported {name} ({n} screens; anyone can open it with a double-click)',
1397
1431
  exportedHtmlMiss: 'Exported {name} ({n} screens, {miss} could not be read)',
1398
1432
  htmlTooBig: 'Too many images: the demo would be over 150 MB, so nothing was exported. Try with fewer screens',
1433
+ 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',
1434
+ 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
1435
  htmlNoScreens: 'None of the screens could be read (moved or deleted?), so nothing was exported',
1400
1436
  xoWarn: 'Some content would be cut off. Have a look first',
1401
1437
  xoChecking: 'Measuring pages…',
@@ -1492,6 +1528,7 @@ window.__ModuleLoader__.load({
1492
1528
  ck_tight: 'Too close to a fixed bar',
1493
1529
  ck_jserr: 'Script error',
1494
1530
  ck_missing: 'File failed to load',
1531
+ ck_mockmiss: 'Not in the mock data',
1495
1532
  ck_capsule: 'Under the mini program capsule',
1496
1533
  ck_island: 'Under the Dynamic Island',
1497
1534
  ck_homebar: 'In the home indicator area',
@@ -1522,6 +1559,7 @@ window.__ModuleLoader__.load({
1522
1559
  cd_tight: 'only {px}px from the {edgeName} {bar} (leave 16px or more)',
1523
1560
  cd_jserr: '{msg}{at}',
1524
1561
  cd_missing: '{what} {src} did not load (wrong path, or the file is missing)',
1562
+ cd_mockmiss: 'Uses {paths}, which mock.json does not have (shows up empty)',
1525
1563
  cd_capsule: '{px}px under the top-right capsule (WeChat draws it on top; keep the top bar clear from x={x})',
1526
1564
  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
1565
  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)',
@@ -2283,6 +2321,36 @@ window.__ModuleLoader__.load({
2283
2321
  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
2322
  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
2323
  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.',
2324
+ data: 'Data',
2325
+ dData: 'The data behind the clickable prototype: view it, edit it, reset it',
2326
+ 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.',
2327
+ dataWait: 'Reading the data…',
2328
+ dataNoneT: 'Could not read the data',
2329
+ dataNone: 'The preview page did not open; close this panel and open it again',
2330
+ dataBadT: 'mock.json cannot be read',
2331
+ dataFix: 'Ask the model to fix it',
2332
+ dataFixText: 'mock.json cannot be read ({err}). Please fix it: it must be a JSON object, and keep every field the prototype uses.',
2333
+ dataN: '{n} changes (compared with mock.json)',
2334
+ dataSame: 'Same as mock.json',
2335
+ dataReset: 'Reset',
2336
+ dataResetTip: 'Every screen goes back to the initial data in mock.json',
2337
+ dataResetDone: 'Data reset',
2338
+ dataSave: 'Save as initial data',
2339
+ dataSaveTip: 'Write the current data back to mock.json; Reset returns here from then on',
2340
+ dataSaved: 'Saved as initial data',
2341
+ dataNoMock: 'mock.json is gone, so nothing was saved',
2342
+ 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',
2343
+ dataBadFile: "mock.json can't be read; have the model fix it before saving",
2344
+ dataBig: 'The data is too big to save (1 MB at most)',
2345
+ dataFail: 'Not changed: {msg}',
2346
+ dataNull: 'empty',
2347
+ dataItems: '{n} items',
2348
+ dataKeys: '{n} fields',
2349
+ dataMore: '{n} more not listed',
2350
+ dataAdd: 'Add one',
2351
+ dataAddTip: 'Copy the last item',
2352
+ dataDel: 'Delete this item',
2353
+ dataChg: 'Changed',
2286
2354
  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
2355
  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
2356
  inPick: 'Choose images',
@@ -4305,6 +4373,37 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
4305
4373
  .ddp .ddp-lktw .dd-seg>button{height:30px}
4306
4374
  .ddp .ddp-lktw .dd-chips{margin-top:0}
4307
4375
  /* 空着:一圈极光 + 标题 + 一句说明 + 一个按钮 */
4376
+ .ddp .dd-mkbr{position:absolute;width:0;height:0;border:0;visibility:hidden;pointer-events:none}
4377
+ /* 「数据」:一行一个字段,缩进看层级;改过的打个橙点 */
4378
+ .ddp .dd-sheet .dd-in>*>.bd.dd-mk{display:flex;flex-direction:column;gap:1px;padding:6px 8px 12px}
4379
+ .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}
4380
+ .ddp .dd-mkr:hover{background:var(--dd-f1)}
4381
+ .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}
4382
+ .ddp .dd-mkr>.v{flex:1 1 auto;min-width:0;display:flex;justify-content:flex-end;align-items:center}
4383
+ .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}
4384
+ .ddp .dd-mkr .fold>svg{width:14px;height:14px;flex:none;color:var(--dd-t3);transition:transform .16s var(--dd-out)}
4385
+ .ddp .dd-mkr.op .fold>svg{transform:rotate(90deg)}
4386
+ .ddp .dd-mkr .fold>.k{max-width:none;color:var(--dd-t1);font-weight:600}
4387
+ .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}
4388
+ .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)}
4389
+ .ddp .dd-mkr input.tx.num{max-width:120px;font-variant-numeric:tabular-nums}
4390
+ .ddp .dd-mkr input.tx:hover{box-shadow:inset 0 0 0 1px var(--dd-line2)}
4391
+ .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}
4392
+ .ddp .dd-mkr .sw{display:inline-flex;align-items:center;height:28px;padding:0 2px;border:0;background:none;cursor:pointer}
4393
+ .ddp .dd-mkr .nul{color:var(--dd-t4);font-style:italic;font-size:12px}
4394
+ .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)}
4395
+ .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)}
4396
+ .ddp .dd-mkr>.del svg{width:12px;height:12px}
4397
+ .ddp .dd-mkr:hover>.del,.ddp .dd-mkr>.del:focus-visible{opacity:1}
4398
+ .ddp .dd-mkr>.del:hover{background:var(--dd-err-bg);color:var(--dd-err)}
4399
+ .ddp .dd-mkr.more{color:var(--dd-t3);font-size:11.5px}
4400
+ .ddp .dd-mkr.add{min-height:30px}
4401
+ .ddp .dd-mkr.add .dd-bt{height:26px;padding:0 9px;font-size:12px}
4402
+ .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}
4403
+ .ddp .dd-mkerr>svg{width:15px;height:15px;flex:none}
4404
+ .ddp .dd-mkerr>span{flex:1 1 200px;min-width:0;overflow-wrap:anywhere}
4405
+ .ddp .dd-mkerr .dd-bt{height:30px;font-size:12.5px}
4406
+ @media (hover:none){.ddp .dd-mkr>.del{opacity:1}}
4308
4407
  .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
4408
  .ddp .dd-emp>b{font-size:14px;font-weight:600;color:var(--dd-t1)}
4310
4409
  .ddp .dd-emp>span{max-width:440px;overflow-wrap:anywhere}
@@ -4594,6 +4693,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
4594
4693
  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
4694
  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
4695
  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' })]),
4696
+ 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
4697
  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
4698
  h('rect', { key: 2, x: 9, y: 7.5, width: 6, height: 9, rx: 1.3 })]),
4599
4699
  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' }),
@@ -6528,6 +6628,10 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
6528
6628
  * 单看时页面里点了换状态的链接(#30):顶栏记着的就是要的这个(在页面里去了别的页、又点链接回来,页面显示的不是顶栏那个状态),
6529
6629
  * 顶栏、地址都不会变 → 'reload' 重新载一遍这屏(不然点了没反应);不然 'pick' 交给顶栏换。def:要的是默认状态
6530
6630
  */
6631
+ /** 页面报上来的状态那段里有「#mock」那行:这页的状态跟着模拟数据走(不带状态 = 数据里那个,第一个状态要点名) */
6632
+ function followsMock(raw) {
6633
+ return /^#mock\n/.test(String(raw || ''))
6634
+ }
6531
6635
  function stateGoPlan(src, d) {
6532
6636
  let had = ''
6533
6637
  try { had = new URL(src).searchParams.get('state') || '' } catch { /* 地址不认识:当默认 */ }
@@ -7815,7 +7919,8 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
7815
7919
  if (isCur && p.picking && p.onPicked) p.onPicked(d.payload)
7816
7920
  break
7817
7921
  case 'stateGo': { // 单看时点了同一页换状态的链接(#30)
7818
- if (!isCur || !p.onStateGo || typeof d.state !== 'string' || !STATE_RE.test(d.state)) break
7922
+ // clear:状态跟着模拟数据走的页里点了不带状态的链接 → 去掉点名的状态(回到跟着数据)
7923
+ if (!isCur || !p.onStateGo || typeof d.state !== 'string' || !(STATE_RE.test(d.state) || (d.state === '' && d.clear === true))) break
7819
7924
  // 链接带的锚点(?state=paid#receipt):换好状态的那一帧载的时候带上(只认这一下,过会儿就不算了)
7820
7925
  L.hashNext = typeof d.hash === 'string' && /^#[^\s#]{1,200}$/.test(d.hash) ? { hash: d.hash, at: Date.now() } : null
7821
7926
  if (stateGoPlan(p.src, d) === 'reload') { L.at = ''; load(null, true) } else p.onStateGo(d.state)
@@ -10398,7 +10503,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
10398
10503
  // 几百屏的设计(#29):只列前 12 个名字
10399
10504
  return t('pubScreens', { n: list.length, names: list.slice(0, 12).join(t('sep')) + (list.length > 12 ? t('pubMoreNames') : '') })
10400
10505
  })()
10401
- const errText = (r) => (r.error === 'tooBig' ? t('pubTooBig') : r.error === 'noScreens' ? t('pubNoScreens') : t('pubFail', { msg: r.message || r.error || '' }))
10506
+ 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
10507
  // 接口拒了(点生成的那一刻换了设计、或者现在看的不是本地文件):别说成「没连上 Cloudflare」
10403
10508
  const errMsg = (m) => (m === 'designChanged' || m === 'not-file' ? t('pubGone') : t('pubFail', { msg: m }))
10404
10509
  const ended = (r) => (r.ended === 'expired' ? t('pubEndExpired') : r.ended === 'dropped' ? t('pubEndDropped') : r.ended === 'moved' ? t('pubEndMoved') : '')
@@ -10433,7 +10538,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
10433
10538
  h('button', { type: 'button', className: 'dd-bt pri', onClick: () => onCopy(res.url) }, h(I.copy), t('phoneCopy')),
10434
10539
  h('button', { type: 'button', className: 'dd-bt danger', onClick: stop }, h(I.stopSq), t('pubStop'))),
10435
10540
  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,
10541
+ 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
10542
  res.screens && res.screens.length ? h('p', { className: 'fine' }, t('pubShared', { n: res.screens.length, names: res.screens.join(t('sep')) })) : null),
10438
10543
  notes(['pubHow', 'pubLive', 'pubWarn']))
10439
10544
  } else if (res.dl && !res.dl.done && !res.tool) {
@@ -10552,6 +10657,120 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
10552
10657
  : h('div', { className: 'bd' }, emptyBox(I.history, t('histEmptyT'), t('histEmpty'))))
10553
10658
  }
10554
10659
 
10660
+ /**
10661
+ * 「数据」(#30 模拟数据):设计目录里有 mock.json 才有。面板里藏一个预览地址上的小页(/__dsh_design__/mock.html)当桥:
10662
+ * 它和各屏读写同一份数据(同一个地址的 localStorage),这里改了各屏马上跟着变,各屏点出来的变化也马上显示在这
10663
+ */
10664
+ const MOCK_SHOW = 200 // 一层最多列多少
10665
+ const mkSame = (a, b) => { try { return JSON.stringify(a) === JSON.stringify(b) } catch { return false } }
10666
+ 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 }
10667
+ /** 叶子上不一样的有几处(和 mock.json 比) */
10668
+ function mkDiff(a, b) {
10669
+ if (mkSame(a, b)) return 0
10670
+ if (!a || !b || typeof a !== 'object' || typeof b !== 'object' || Array.isArray(a) !== Array.isArray(b)) return 1
10671
+ let n = 0
10672
+ for (const k of new Set([...Object.keys(a), ...Object.keys(b)])) n += mkDiff(a[k], b[k])
10673
+ return n
10674
+ }
10675
+ /** 列表里一条(对象)收着时旁边写什么:头一个文字 / 数字字段 */
10676
+ 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 '' }
10677
+ function DataPanel({ t, head, origin, fp, err, write, onFix, onSave, onSay }) {
10678
+ const fr = useRef(null)
10679
+ const [snap, setSnap] = useState(null) // 桥报上来的:{ data, initial, err }
10680
+ const [dead, setDead] = useState(false)
10681
+ const [fold, setFold] = useState(() => new Map()) // 路径 → 开 / 收(点过的才记)
10682
+ const got = useRef(false)
10683
+ useEffect(() => {
10684
+ got.current = false
10685
+ setSnap(null)
10686
+ setDead(false)
10687
+ const on = (e) => {
10688
+ const d = e.data
10689
+ if (!fr.current || e.source !== fr.current.contentWindow || e.origin !== origin || !d || d.ddpMock !== 1) return
10690
+ if (d.type === 'data') {
10691
+ got.current = true
10692
+ setDead(false)
10693
+ 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 || '') })
10694
+ } else if (d.type === 'fail') onSay(t('dataFail', { msg: String(d.msg || '') }))
10695
+ }
10696
+ addEventListener('message', on)
10697
+ const tm = setTimeout(() => { if (!got.current) setDead(true) }, 8000)
10698
+ return () => { removeEventListener('message', on); clearTimeout(tm) }
10699
+ }, [origin, fp])
10700
+ const send = (m) => { const w = fr.current && fr.current.contentWindow; if (w) try { w.postMessage({ ddpMock: 1, ...m }, origin) } catch { /* 桥不在了 */ } }
10701
+ const setAt = (keys, value) => send({ type: 'set', keys, value })
10702
+ 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' }) })
10703
+ const bad = (snap && snap.err) || err
10704
+ 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
10705
+ const n = snap ? mkDiff(snap.data, snap.initial) : 0
10706
+ const foot = h('footer', { className: 'dd-sf' },
10707
+ h('span', { className: 'note' }, snap ? (n ? t('dataN', { n }) : t('dataSame')) : ''),
10708
+ 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')),
10709
+ 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')))
10710
+ const box = (body) => h('div', { className: 'ddp-tokens ddp-data', onPointerDown: (e) => e.stopPropagation() }, head, body, foot, bridge)
10711
+ if (!snap) {
10712
+ return box(h('div', { className: 'bd', key: 'w' }, errBox, dead
10713
+ ? emptyBox(I.data, t('dataNoneT'), t('dataNone'))
10714
+ : h('div', { className: 'dd-ckwait' }, h('i', { className: 'dd-spin' }), h('span', null, t('dataWait')))))
10715
+ }
10716
+ // 开着还是收着:点过的照点的;没点过的,最上一层开着,别的小的(不在列表里)开着
10717
+ const isOpen = (path, d, size, inArr) => (fold.has(path) ? fold.get(path) : d === 0 || (!inArr && d <= 2 && size <= 6))
10718
+ const toggle = (path, on) => setFold((m) => new Map(m).set(path, on))
10719
+ const editor = (keys, v) => {
10720
+ const nm = keys.join('.')
10721
+ if (typeof v === 'boolean') return h('button', { className: 'sw', role: 'switch', 'aria-checked': v, 'aria-label': nm, onClick: () => setAt(keys, !v) }, swOf(v))
10722
+ if (v === null) return h('span', { className: 'nul' }, t('dataNull'))
10723
+ const num = typeof v === 'number'
10724
+ const back = (el) => { el.value = String(v) }
10725
+ return h('input', {
10726
+ key: 'in:' + JSON.stringify(v),
10727
+ className: 'tx' + (num ? ' num' : ''),
10728
+ defaultValue: String(v),
10729
+ inputMode: num ? 'decimal' : undefined,
10730
+ spellCheck: false,
10731
+ 'aria-label': nm,
10732
+ onKeyDown: (e) => {
10733
+ if (e.nativeEvent.isComposing || e.keyCode === 229) return
10734
+ if (e.key === 'Enter') e.currentTarget.blur()
10735
+ else if (isEsc(e)) { e.stopPropagation(); back(e.currentTarget); e.currentTarget.blur() }
10736
+ },
10737
+ onBlur: (e) => {
10738
+ const s = e.currentTarget.value
10739
+ if (s === String(v)) return
10740
+ if (!num) return setAt(keys, s)
10741
+ const x = Number(s.trim())
10742
+ if (!s.trim() || !Number.isFinite(x)) return back(e.currentTarget)
10743
+ setAt(keys, x)
10744
+ },
10745
+ })
10746
+ }
10747
+ const rows = []
10748
+ const walk = (keys, label, v, d, inArr) => {
10749
+ const path = keys.join('\u0001')
10750
+ const chg = !mkSame(v, mkAt(snap.initial, keys))
10751
+ const dot = chg ? h('i', { className: 'chg', title: t('dataChg'), 'aria-label': t('dataChg') }) : null
10752
+ 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
10753
+ const style = { '--d': d }
10754
+ if (v && typeof v === 'object') {
10755
+ const arr = Array.isArray(v)
10756
+ const ks = arr ? v.map((_, i) => String(i)) : Object.keys(v)
10757
+ const op = isOpen(path, d, ks.length, inArr)
10758
+ const peek = inArr && !arr && !op ? mkPeek(v) : ''
10759
+ rows.push(h('div', { key: path, className: 'dd-mkr grp' + (op ? ' op' : ''), style },
10760
+ 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 }))),
10761
+ del))
10762
+ if (!op) return
10763
+ for (const k of ks.slice(0, MOCK_SHOW)) walk([...keys, k], arr ? '#' + (Number(k) + 1) : k, v[k], d + 1, arr)
10764
+ 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 })))
10765
+ 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'))))
10766
+ return
10767
+ }
10768
+ 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))
10769
+ }
10770
+ for (const k of Object.keys(snap.data)) walk([k], k, snap.data[k], 0, false)
10771
+ return box(h('div', { className: 'bd dd-mk', key: 'tree' }, errBox, ...rows))
10772
+ }
10773
+
10555
10774
  /**
10556
10775
  * 画布:几屏排成网格,能拖、能缩放(触控板双指滑 = 平移,捏合 / ⌘ 滚轮 = 缩放)。
10557
10776
  * 平时每屏上盖一层「挡板」:点一下选中,双击只看这一屏;选取时拿掉挡板,直接在页面里点。
@@ -12145,7 +12364,8 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
12145
12364
  for (const sc of list) {
12146
12365
  const ss = sc.v ? [] : statesFor(sc.key) || []
12147
12366
  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 }))
12367
+ // 第一个状态也写明(状态跟着模拟数据走的屏,不写就是数据里那个状态,会和后面某张重复)
12368
+ ss.forEach((s, i) => out.push({ ...sc, url: withState(sc.url, s.name), xs: s.name, xsLabel: s.label, xsFirst: i === 0 }))
12149
12369
  }
12150
12370
  return out
12151
12371
  }
@@ -12235,7 +12455,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
12235
12455
  const toDefault = (sc) => {
12236
12456
  if (!sc.state || sc.v || !statesFor) return sc
12237
12457
  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
12458
+ 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
12459
  }
12240
12460
  const precheck = (tok, def) => {
12241
12461
  const pool = def ? every.map(toDefault) : every
@@ -12416,7 +12636,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
12416
12636
  } catch (e) {
12417
12637
  const m = String((e && e.message) || '')
12418
12638
  if (m === 'designChanged' || m === 'not-file') sayErr(t('xoGone'))
12419
- else if (m === 'tooBig' || m === 'noScreens') sayErr(t(m === 'tooBig' ? 'htmlTooBig' : 'htmlNoScreens'))
12639
+ else if (m === 'tooBig' || m === 'noScreens' || m === 'imgTooBig' || m === 'mockTooBig') sayErr(t(m === 'tooBig' ? 'htmlTooBig' : m === 'imgTooBig' ? 'htmlImgBig' : m === 'mockTooBig' ? 'htmlMockBig' : 'htmlNoScreens'))
12420
12640
  else sayErr(t('exportFail', { msg: m }), { label: t('retry'), run: () => exportHtml() })
12421
12641
  }
12422
12642
  }
@@ -12868,14 +13088,14 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
12868
13088
  const u = new URL(href)
12869
13089
  key = keyOfPath(decodeURIComponent(u.pathname), fileTarget)
12870
13090
  given = u.searchParams.get('state') || ''
12871
- state = STATE_RE.test(given) && dec.includes(given) && given !== dec[0] ? given : ''
13091
+ state = STATE_RE.test(given) && dec.includes(given) && (given !== dec[0] || followsMock(raw)) ? given : ''
12872
13092
  } catch { return }
12873
13093
  setDemo((d) => {
12874
13094
  if (!d) return d
12875
13095
  const last = d.layers[d.layers.length - 1]
12876
13096
  // 还是这一层载的那个地址(跨页链接带的 ?state= 那页没写,地址里照样有):没跳,别改记下的、别再载一遍
12877
13097
  // 没写状态的页(老页面自己拿 ?state= 当参数)自己换了参数:也不算换屏,别动这一层(一动地址就变、重载,参数丢了)
12878
- if (last.id !== id || (last.key === key && (!dec.length || (last.state || '') === given || norm(last, dec[0] || defOf(key)) === state))) return d
13098
+ if (last.id !== id || (last.key === key && (!dec.length || (last.state || '') === given || norm(last, followsMock(raw) ? '' : dec[0] || defOf(key)) === state))) return d
12879
13099
  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
13100
  })
12881
13101
  }
@@ -13076,15 +13296,16 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
13076
13296
  const tg = st && st.target
13077
13297
  const site = tg ? (tg.kind === 'file' ? 'file:' + String(tg.file || '').replace(/[\\/][^\\/]*$/, '') : 'proxy:' + tg.port) : origin
13078
13298
  const busy = !!(st && st.turn)
13079
- // 一页多状态(#30):这屏写了哪几个状态(页面报上来的)、现在看哪个;选了不是默认的那屏,地址带上 ?state=
13299
+ // 一页多状态(#30):这屏写了哪几个状态(页面报上来的)、现在看哪个;点名选了的(第一个也算)地址带上 ?state=——
13300
+ // 状态跟着模拟数据走的页,不带就是数据里那个,选「第一个」不带就切不回去
13080
13301
  const statesOf = (key) => parseStates((info[site + '|' + key] || {}).states)
13081
13302
  const stateFor = (key) => {
13082
13303
  const s = stSel[site + '|' + key]
13083
- return s && statesOf(key).some((x, i) => i > 0 && x.name === s) ? s : ''
13304
+ return s && statesOf(key).some((x) => x.name === s) ? s : ''
13084
13305
  }
13085
13306
  const pickState = (key, name) => {
13086
13307
  const list = statesOf(key)
13087
- const v = list.length && name !== list[0].name ? name : ''
13308
+ const v = list.some((x) => x.name === name) ? name : ''
13088
13309
  setStSel((m) => ((m[site + '|' + key] || '') === v ? m : { ...m, [site + '|' + key]: v }))
13089
13310
  }
13090
13311
  const screens = ((st && st.screens) || []).map((sc) => { const s = stateFor(sc.key); return s ? { ...sc, url: withState(sc.url, s), state: s } : sc })
@@ -13727,7 +13948,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
13727
13948
  if (inf && !(inf.links || []).length) say(t('demoNone'))
13728
13949
  }
13729
13950
  // 演示里跳屏、返回、从头来(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 : '' } })
13951
+ 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
13952
  const { implLoad, implRecompare } = makeImpl({ sid, setImpl, setImplRun, say, t })
13732
13953
  // 和做出来的比:在比哪一屏(看旧版本时不比)、那屏记着的地址和上次的分数
13733
13954
  const implSc = impl && !ver ? screens.find((x) => x.key === impl.key) || null : null
@@ -14218,6 +14439,19 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
14218
14439
  // 右边同一时间只开一个面板:别的开了,这几个关掉;开这几个时别的关掉
14219
14440
  const oldOpen = !!(panel || hist || phone || pubP || ck || styleEdit)
14220
14441
  useEffect(() => { if (oldOpen) setPane('') }, [oldOpen])
14442
+ // 「数据」(模拟数据):本地文件的设计、目录里有 mock.json 才有;从别的设备打开的 DSH 够不着电脑上的预览地址,不给;
14443
+ // 看旧版本时不给(旧版本的屏用的是自己那份数据,面板改的是现在的)
14444
+ const mockOn = !!(fileTarget && st && st.mock && url && !away(url) && !ver)
14445
+ useEffect(() => { if (pane === 'data' && !mockOn) setPane('') }, [pane, mockOn])
14446
+ const saveMockData = async (data, fp) => {
14447
+ try {
14448
+ const r = await post('mocksave', { session: sid, root: st && st.target ? st.target.root : '', data, fp: fp || '' })
14449
+ 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'))
14450
+ showFlash(t('dataSaved'))
14451
+ } catch (e) {
14452
+ sayErr(t('failed', { msg: e.message }))
14453
+ }
14454
+ }
14221
14455
  const openPane = (p) => {
14222
14456
  const next = pane === p ? '' : p
14223
14457
  if (next) { setPanel(false); setHist(false); setPhone(false); setPubP(false); closeCheck(); setStyleEdit(false); setAn(false) }
@@ -14293,7 +14527,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
14293
14527
  const packOther = !!packDir && !(fileTarget && st && st.target && packDir === st.target.root)
14294
14528
  const shareTab = phone ? 'phone' : pubP ? 'pub' : pane === 'pack' && !packOther ? 'demo' : pane === 'share' && !packOther ? 'submit' : ''
14295
14529
  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' : ''
14530
+ : pane === 'export' ? 'export' : pane === 'handoff' ? 'code' : pane === 'pack' ? 'pack' : pane === 'share' ? 'submit' : pane === 'zip' && zipIssues ? 'zip' : pane === 'data' && mockOn ? 'data' : ''
14297
14531
  const closeShare = () => { setPhone(false); setPubP(false); if (pane === 'pack' || pane === 'share') setPane('') }
14298
14532
  // 标题栏「分享」:开着手机看 / 公网链接时直接到那一页
14299
14533
  const toggleShare = () => (sheet === 'share' ? closeShare() : pubOn && fileTarget ? togglePub() : togglePhone())
@@ -14306,7 +14540,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
14306
14540
  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
14541
  const badgeOf = (n) => (n ? h('span', { className: 'bdg' }, n > 99 ? '99+' : String(n)) : null)
14308
14542
  // 灵动条放得下多少:全宽 → 藏快捷键 → 「说一句」收成图标 → 工具也只剩图标(两边小块挪到上面一行)
14309
- const nTools = 7
14543
+ const nTools = mockOn ? 8 : 7
14310
14544
  const islW = (cmd, tw) => 12 + cmd + 4 + nTools * tw + 11
14311
14545
  const dwKey = (m) => t('askSay') + '|' + m + (busy && capAway ? '|run' : '')
14312
14546
  const dwOf = (m, est) => dockW.current[dwKey(m)] || est
@@ -14424,6 +14658,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
14424
14658
  tool('', mark, t('dMark'), markOff, toggleMark, I.pen, t('markShort'), null, 'P'),
14425
14659
  h('span', { className: 'dd-vs' }),
14426
14660
  tool('dm', !!demo, t('dPlay'), !url || !!ver, toggleDemo, I.play, t('demoShort'), null, 'R'),
14661
+ mockOn ? tool('', pane === 'data', t('dData'), false, () => openPane('data'), I.data, t('data')) : null,
14427
14662
  tool('', !!panel, t('dLook'), false, () => (panel ? setPanel(false) : openLook()), I.palette, t('look'), null, 'L'),
14428
14663
  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
14664
  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'))),
@@ -14798,6 +15033,19 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
14798
15033
  }
14799
15034
  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
15035
  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('') })
15036
+ if (sheet === 'data') {
15037
+ return h(DataPanel, {
15038
+ t,
15039
+ head: hd({ icon: I.data, title: t('data'), help: t('dataHelp'), sub: 'mock.json' }),
15040
+ origin,
15041
+ fp: st.mock.fp,
15042
+ err: st.mock.err,
15043
+ write: busy ? { ok: false, tip: t('styleBusyTip') } : { ok: true },
15044
+ onFix: (err) => insert(t('dataFixText', { err }) + '\n', 'insertedSend'),
15045
+ onSave: saveMockData,
15046
+ onSay: say,
15047
+ })
15048
+ }
14801
15049
  if (sheet === 'zip') return h(ZipIssues, { t, head: hd({ icon: I.box, title: t('zipNotOpened') }), issues: zipIssues, onClose: () => { setPane(''); setZipIssues(null) } })
14802
15050
  if (sheet === 'export') {
14803
15051
  const imgModes = exportItems(t, kind, shown.length, exName).filter(([m]) => m !== 'pdf' && m !== 'pptx' && m !== 'opts')
@@ -14810,7 +15058,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
14810
15058
  }
14811
15059
  return null
14812
15060
  }
14813
- const SHEET_T = { style: 'style', look: 'look', check: 'check', ver: 'history', share: 'shareT', submit: 'subT', pack: 'pkTitle', zip: 'zipNotOpened', export: 'exportT', code: 'handoff' }
15061
+ 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
15062
  // 壳一直在(换面板时只换里面,淡出淡入);关的时候整张落下 / 滑走
14815
15063
  const sheetEl = (home) => h(Presence, { key: 'sheet', on: !!sheet, ms: 300 }, sheet ? h('div', {
14816
15064
  className: 'dd-sheet' + (box.w > 1000 ? ' wide' : '') + (home ? ' home' : ''),
@@ -14856,6 +15104,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
14856
15104
  add('mark', I.pen, t('markShort'), toggleMark, { key: 'P', on: mark, off: markOff, kw: kwOf('markShort') })
14857
15105
  add('demo', I.play, t('demoShort'), () => { if (implSc) implClose(); toggleDemo() }, { key: 'R', on: !!demo, off: noUrl || !!ver, top: true, kw: kwOf('demoShort') })
14858
15106
  add('look', I.palette, t('look'), () => (panel ? setPanel(false) : openLook()), { key: 'L', on: !!panel, top: true, kw: kwOf('look', 'lookSet') })
15107
+ if (mockOn) add('data', I.data, t('data'), () => openPane('data'), { on: pane === 'data', kw: kwOf('data', 'dataReset') + ' mock json' })
14859
15108
  add('look-style', I.palette, t('look') + ' · ' + t('lookStyle'), () => openLook('style'), { kw: kwOf('lookStyle') })
14860
15109
  add('look-brand', I.palette, t('look') + ' · ' + t('lookBrand'), () => openLook('brand'), { kw: kwOf('lookBrand') })
14861
15110
  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 +15303,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
15054
15303
  // 一页多状态(#30):这一屏的每个状态并排(第一个是默认);点选、改字照常,发给模型时说明是哪个状态
15055
15304
  const base = screens.find((x) => x.key === stAll) || { key: stAll, url: urlOfKey(stAll), label: stAll.replace(/\.html?$/i, '') }
15056
15305
  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 }))
15306
+ 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
15307
  body = h(Canvas, {
15059
15308
  key: 'stall',
15060
15309
  t,