dsh-design-studio 1.5.0 → 2.0.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.
Files changed (193) hide show
  1. package/README.en.md +6 -5
  2. package/README.md +7 -6
  3. package/THIRD_PARTY_NOTICES.md +108 -0
  4. package/assets/art/README.md +102 -0
  5. package/assets/art/brand-mark.webp +0 -0
  6. package/assets/art/check-clean.webp +0 -0
  7. package/assets/art/coach-markup.webp +0 -0
  8. package/assets/art/drop-file.webp +0 -0
  9. package/assets/art/empty-components.webp +0 -0
  10. package/assets/art/empty-data.webp +0 -0
  11. package/assets/art/empty-error.webp +0 -0
  12. package/assets/art/empty-frames.webp +0 -0
  13. package/assets/art/empty-history.webp +0 -0
  14. package/assets/art/empty-market.webp +0 -0
  15. package/assets/art/empty-notes.webp +0 -0
  16. package/assets/art/empty-search.webp +0 -0
  17. package/assets/art/empty-tokens.webp +0 -0
  18. package/assets/art/empty-works.webp +0 -0
  19. package/assets/art/guide-icon.webp +0 -0
  20. package/assets/art/kind-app.webp +0 -0
  21. package/assets/art/kind-desktop.webp +0 -0
  22. package/assets/art/kind-diagram.webp +0 -0
  23. package/assets/art/kind-dshplugin.webp +0 -0
  24. package/assets/art/kind-email.webp +0 -0
  25. package/assets/art/kind-embedded.webp +0 -0
  26. package/assets/art/kind-framed.webp +0 -0
  27. package/assets/art/kind-miniprogram.webp +0 -0
  28. package/assets/art/kind-poster.webp +0 -0
  29. package/assets/art/kind-slides.webp +0 -0
  30. package/assets/art/kind-tablet.webp +0 -0
  31. package/assets/art/kind-web.webp +0 -0
  32. package/assets/art/placeholder-inspire-img.webp +0 -0
  33. package/assets/art/wait-creating.webp +0 -0
  34. package/assets/motion/ai-capsule.html +124 -0
  35. package/assets/motion/ai-glow-input.html +112 -0
  36. package/assets/motion/balance-odometer.html +112 -0
  37. package/assets/motion/bottom-sheet.html +149 -0
  38. package/assets/motion/brightness-pill.html +114 -0
  39. package/assets/motion/comet-ring.html +95 -0
  40. package/assets/motion/copy-morph.html +116 -0
  41. package/assets/motion/cube-grid.html +103 -0
  42. package/assets/motion/day-night.html +120 -0
  43. package/assets/motion/dial-knob.html +130 -0
  44. package/assets/motion/dock-magnify.html +118 -0
  45. package/assets/motion/download-ring.html +135 -0
  46. package/assets/motion/expand-card.html +137 -0
  47. package/assets/motion/flip-card.html +100 -0
  48. package/assets/motion/hold-pay.html +137 -0
  49. package/assets/motion/holo-card.html +130 -0
  50. package/assets/motion/keycap.html +92 -0
  51. package/assets/motion/like-jelly.html +88 -0
  52. package/assets/motion/liquid-progress.html +113 -0
  53. package/assets/motion/liquid-segment.html +127 -0
  54. package/assets/motion/live-capsule.html +144 -0
  55. package/assets/motion/marker-highlight.html +94 -0
  56. package/assets/motion/marquee-logos.html +110 -0
  57. package/assets/motion/otp-code.html +111 -0
  58. package/assets/motion/password-eye.html +136 -0
  59. package/assets/motion/ruler-slider.html +140 -0
  60. package/assets/motion/search-expand.html +81 -0
  61. package/assets/motion/send-fly.html +121 -0
  62. package/assets/motion/skeleton-shine.html +124 -0
  63. package/assets/motion/star-rate.html +98 -0
  64. package/assets/motion/success-check.html +114 -0
  65. package/assets/motion/suggest-chips.html +134 -0
  66. package/assets/motion/swipe-row.html +126 -0
  67. package/assets/motion/tabbar-bounce.html +92 -0
  68. package/assets/motion/tactile-controls.html +89 -0
  69. package/assets/motion/text-scramble.html +173 -0
  70. package/assets/motion/toast-stack.html +115 -0
  71. package/assets/motion/token-stream.html +106 -0
  72. package/assets/motion/voice-orb.html +144 -0
  73. package/assets/showcase/alley-noodles-1.webp +0 -0
  74. package/assets/showcase/alley-noodles-2.webp +0 -0
  75. package/assets/showcase/alley-noodles-3.webp +0 -0
  76. package/assets/showcase/autumn-sale-1.webp +0 -0
  77. package/assets/showcase/bold-folio-1.webp +0 -0
  78. package/assets/showcase/bold-folio-2.webp +0 -0
  79. package/assets/showcase/book-club-1.webp +0 -0
  80. package/assets/showcase/book-club-2.webp +0 -0
  81. package/assets/showcase/book-club-3.webp +0 -0
  82. package/assets/showcase/flower-order-1.webp +0 -0
  83. package/assets/showcase/little-painter-1.webp +0 -0
  84. package/assets/showcase/little-painter-2.webp +0 -0
  85. package/assets/showcase/moon-fair-1.webp +0 -0
  86. package/assets/showcase/nail-booking-1.webp +0 -0
  87. package/assets/showcase/nail-booking-2.webp +0 -0
  88. package/assets/showcase/nail-booking-3.webp +0 -0
  89. package/assets/showcase/night-run-1.webp +0 -0
  90. package/assets/showcase/paw-diary-1.webp +0 -0
  91. package/assets/showcase/paw-diary-2.webp +0 -0
  92. package/assets/showcase/paw-diary-3.webp +0 -0
  93. package/assets/showcase/pixel-planet-1.webp +0 -0
  94. package/assets/showcase/pixel-planet-2.webp +0 -0
  95. package/assets/showcase/pixel-planet-3.webp +0 -0
  96. package/assets/showcase/pocket-ledger-1.webp +0 -0
  97. package/assets/showcase/pocket-ledger-2.webp +0 -0
  98. package/assets/showcase/shiftloom-1.webp +0 -0
  99. package/assets/showcase/shiftloom-2.webp +0 -0
  100. package/assets/showcase/slow-breath-1.webp +0 -0
  101. package/assets/showcase/slow-breath-2.webp +0 -0
  102. package/assets/showcase/slow-breath-3.webp +0 -0
  103. package/assets/showcase/slow-trip-1.webp +0 -0
  104. package/assets/showcase/slow-trip-2.webp +0 -0
  105. package/assets/showcase/slow-trip-3.webp +0 -0
  106. package/assets/showcase/slow-weekly-1.webp +0 -0
  107. package/assets/showcase/stay-confirm-1.webp +0 -0
  108. package/assets/showcase/stove-recipes-1.webp +0 -0
  109. package/assets/showcase/stove-recipes-2.webp +0 -0
  110. package/assets/showcase/strobewatch-1.webp +0 -0
  111. package/assets/showcase/strobewatch-2.webp +0 -0
  112. package/assets/showcase/tapeworks-1.webp +0 -0
  113. package/assets/showcase/tapeworks-2.webp +0 -0
  114. package/assets/showcase/tea-brand-pitch-1.webp +0 -0
  115. package/assets/showcase/tea-brand-pitch-2.webp +0 -0
  116. package/assets/showcase/tea-brand-pitch-3.webp +0 -0
  117. package/assets/showcase/time-bookshop-1.webp +0 -0
  118. package/assets/showcase/time-bookshop-2.webp +0 -0
  119. package/assets/showcase/water-journey-1.webp +0 -0
  120. package/assets/showcase/water-journey-2.webp +0 -0
  121. package/assets/showcase/water-journey-3.webp +0 -0
  122. package/assets/showcase/weekend-go-1.webp +0 -0
  123. package/assets/showcase/weekend-go-2.webp +0 -0
  124. package/assets/showcase/weekend-go-3.webp +0 -0
  125. package/assets/showcase/winter-soup-1.webp +0 -0
  126. package/assets/showcase/year-review-1.webp +0 -0
  127. package/assets/showcase/year-review-2.webp +0 -0
  128. package/assets/showcase/year-review-3.webp +0 -0
  129. package/lib/browser.js +3 -1
  130. package/lib/bundle.js +8 -3
  131. package/lib/canvthumb.js +9 -6
  132. package/lib/client.js +7427 -2624
  133. package/lib/components.js +4 -2
  134. package/lib/core.js +762 -132
  135. package/lib/design-page-settings.js +48 -0
  136. package/lib/design-scope.js +36 -0
  137. package/lib/design-transactions.js +259 -0
  138. package/lib/drop-folder.js +25 -0
  139. package/lib/edits.js +125 -8
  140. package/lib/embedded/lvgl_shot.c +133 -0
  141. package/lib/embedded/qml_shot.py +66 -0
  142. package/lib/embedded-shot.js +400 -0
  143. package/lib/embedded-trust.js +76 -0
  144. package/lib/fonts.js +30 -21
  145. package/lib/frames.js +23 -23
  146. package/lib/gallery/css.js +9 -2
  147. package/lib/gallery/market-routes.js +23 -7
  148. package/lib/gallery/pack.js +25 -8
  149. package/lib/gallery/policy.js +6 -4
  150. package/lib/gallery/routes.js +255 -83
  151. package/lib/gallery/submit.js +285 -57
  152. package/lib/gallery/use.js +13 -4
  153. package/lib/handoff-embedded.js +1182 -0
  154. package/lib/handoff.js +212 -71
  155. package/lib/history.js +393 -43
  156. package/lib/htmlpack.js +34 -13
  157. package/lib/impl.js +3 -0
  158. package/lib/index.js +661 -136
  159. package/lib/inspire.js +73 -26
  160. package/lib/kinds.js +11 -2
  161. package/lib/look.js +45 -25
  162. package/lib/mock.js +41 -4
  163. package/lib/motion.js +90 -0
  164. package/lib/page-settings.js +103 -0
  165. package/lib/picker.js +348 -70
  166. package/lib/rules.js +85 -0
  167. package/lib/serve.js +154 -15
  168. package/lib/showcase.json +22 -0
  169. package/lib/styles.js +16 -7
  170. package/lib/system.js +19 -8
  171. package/lib/tool.js +2 -1
  172. package/lib/tweaks.js +146 -9
  173. package/lib/works.js +151 -19
  174. package/locale/auto/en.json +1 -1
  175. package/locale/auto/zh.json +1 -1
  176. package/locale/en.json +1 -1
  177. package/locale/offline/en.json +1 -1
  178. package/locale/offline/zh.json +2 -2
  179. package/locale/zh.json +1 -1
  180. package/package.json +3 -2
  181. package/skills/ui-design/SKILL.md +56 -46
  182. package/skills/ui-design/frames/dsh/frame.json +1 -1
  183. package/skills/ui-design/references/app.md +29 -2
  184. package/skills/ui-design/references/components.md +1 -1
  185. package/skills/ui-design/references/desktop.md +1 -1
  186. package/skills/ui-design/references/dshplugin.md +12 -12
  187. package/skills/ui-design/references/embedded.md +40 -0
  188. package/skills/ui-design/references/frames.md +20 -20
  189. package/skills/ui-design/references/miniprogram.md +2 -2
  190. package/skills/ui-design/references/mock.md +16 -0
  191. package/skills/ui-design/references/poster.md +2 -1
  192. package/skills/ui-design/references/tweaks.md +17 -0
  193. package/skills/ui-design/tokens.css +19 -5
package/lib/picker.js CHANGED
@@ -19,6 +19,7 @@
19
19
  if (window.__dshDesignPicker) return
20
20
  window.__dshDesignPicker = true
21
21
 
22
+ let uiLang = /^en\b/i.test(navigator.language) ? 'en' : 'zh'
22
23
  const cfg = window.__DSH_DESIGN__ || {}
23
24
  // 只和 DSH 说话:外层的源得是服务端给的那几个(桌面版 dsh-app://app、DSH 网页端)。
24
25
  // 别的网站把预览嵌进去:当没有外层(不发消息、也不听它的),页面照常显示
@@ -41,6 +42,7 @@
41
42
  const STRICT = !!cfg.strict || !!(document.currentScript && document.currentScript.getAttribute('data-strict') === '1')
42
43
  const SEED_KEY = '__dsh_design_seed__'
43
44
  // 远程看(右侧栏把这一屏打包放进沙盒 iframe 的 srcdoc,location 是 about:srcdoc):这一屏原本的地址由右侧栏给
45
+ const editSig = cfg.sig || document.currentScript?.getAttribute('data-edit-sig') || ''
44
46
  const HERE = cfg.remote && typeof cfg.href === 'string' ? cfg.href : ''
45
47
  const here = () => HERE || location.href
46
48
  const hereUrl = () => { try { return new URL(here()) } catch { return location } }
@@ -105,17 +107,30 @@
105
107
  if (took || pageTakes(e)) { took = false; return }
106
108
  e.preventDefault()
107
109
  const files = []
108
- for (const x of [...(dt.items || [])].slice(0, 20)) {
110
+ for (const x of [...(dt.items || [])]) {
109
111
  if (x.kind !== 'file') continue
110
112
  // 文件夹只有 entry 分得出来,得在 drop 里同步取
111
- let dir = false
112
- try { const en = typeof x.webkitGetAsEntry === 'function' ? x.webkitGetAsEntry() : null; dir = !!(en && en.isDirectory) } catch { dir = false }
113
- let f = null
114
- try { f = x.getAsFile() } catch { f = null }
115
- if (f) files.push({ f, dir })
113
+ let entry
114
+ try { entry = x.webkitGetAsEntry?.() } catch { /* regular file */ }
115
+ const f = x.getAsFile()
116
+ if (f || entry?.isDirectory) files.push({ f: f || new File([], entry.name), dir: !!entry?.isDirectory, entry })
117
+ }
118
+ // Desktop opens the original path. Read directory contents only if a web client requests them.
119
+ for (const origin of parentOrigins) {
120
+ const ports = []
121
+ const payload = files.map(({ f, dir, entry }) => {
122
+ if (!dir) return { f }
123
+ const { port1, port2 } = new MessageChannel()
124
+ port1.onmessage = async () => {
125
+ try { port1.postMessage({ files: await window.__DSH_READ_FOLDER__(entry) }) }
126
+ catch (err) { port1.postMessage({ error: String(err.message || err) }) }
127
+ finally { port1.close() }
128
+ }
129
+ ports.push(port2)
130
+ return { f, dir, port: port2 }
131
+ })
132
+ parentWin?.postMessage({ dshDesign: 1, type: 'dropIn', files: payload }, origin, ports)
116
133
  }
117
- // File 能直接跟着消息过去(桌面版照样拿得到它的真实路径)
118
- post({ type: 'dropIn', files })
119
134
  }
120
135
  // 页面在 window 上挂的整页上传常常比这里晚注册(type=module 的脚本、框架挂载后):每次事件在捕获阶段把上面两个摘下来重挂,
121
136
  // 排到 window 冒泡监听的最后,页面的处理(不管什么时候挂的)都先跑完,才看它接没接。
@@ -326,7 +341,7 @@
326
341
  host = document.createElement('dsh-design-picker')
327
342
  host.style.setProperty('--k', K)
328
343
  const root = host.attachShadow({ mode: 'closed' })
329
- root.innerHTML = `<style>${STYLE}</style><div class="layer"></div><div class="box"></div><div class="tag"></div><div class="hint">点选一个元素,或拖出一块区域 · Esc 取消</div>`
344
+ root.innerHTML = `<style>${STYLE}</style><div class="layer"></div><div class="box"></div><div class="tag"></div><div class="hint">${uiLang === 'en' ? 'Click an element or drag a region. Esc cancels.' : '点选一个元素或拖出一块区域,Esc 取消'}</div>`
330
345
  ui = {
331
346
  layer: root.querySelector('.layer'),
332
347
  box: root.querySelector('.box'),
@@ -432,7 +447,7 @@
432
447
  rip(e.clientX, e.clientY)
433
448
  styleSelect(el)
434
449
  const cel = usesComps() && el.closest ? el.closest('[data-dsh-c]') : null
435
- post({ type: 'stylePick', payload: { ...styleInfo(el), href: here(), ...(usesComps() ? { comp: cel ? String(cel.getAttribute('data-dsh-c') || '').slice(0, 64) || true : true } : {}) } })
450
+ post({ type: 'stylePick', payload: { ...baseInfo(el), href: here(), ...(usesComps() ? { comp: cel ? String(cel.getAttribute('data-dsh-c') || '').slice(0, 64) || true : true } : {}) } })
436
451
  return
437
452
  }
438
453
  let payload
@@ -453,23 +468,31 @@
453
468
  place(el.getBoundingClientRect(), 'done')
454
469
  pin(null, el, nameOf(el))
455
470
  }
456
- stop(false)
457
- post({ type: 'picked', payload: { ...payload, href: here(), title: document.title, viewport: { w: innerWidth, h: innerHeight } } })
471
+ post({ type: 'picked', context:pickContext, payload: { ...payload, sourceSig:editSig, href: here(), title: document.title, viewport: { w: innerWidth, h: innerHeight } } })
458
472
  }
459
473
 
460
474
  function onKey(e) {
461
- if (e.key === 'Escape' && picking) {
475
+ if (picking && ['Enter',' '].includes(e.key)) return blockActivation(e)
476
+ if (e.key === 'Escape' && picking && !e.isComposing && e.keyCode !== 229) {
462
477
  e.preventDefault()
463
478
  stop(true)
464
479
  }
465
480
  }
466
481
 
467
- function start(hint = true) {
482
+ function blockActivation(e) {
483
+ if (!picking) return
484
+ e.preventDefault()
485
+ e.stopImmediatePropagation()
486
+ }
487
+ let pickContext
488
+ function start(hint = true, context) {
489
+ pickContext = context
468
490
  if (picking) return
469
491
  picking = true
470
492
  if (!styleOn) unpin()
471
493
  mount(hint)
472
494
  addEventListener('keydown', onKey, true)
495
+ for (const event of ['click','submit','auxclick']) addEventListener(event, blockActivation, true)
473
496
  }
474
497
 
475
498
  /** cancelled: 用户按了 Esc / 外面点了取消;false 时留一下选中框再收 */
@@ -477,6 +500,7 @@
477
500
  if (!picking) return
478
501
  picking = false
479
502
  removeEventListener('keydown', onKey, true)
503
+ for (const event of ['click','submit','auxclick']) removeEventListener(event, blockActivation, true)
480
504
  if (cancelled) {
481
505
  unmount()
482
506
  post({ type: 'cancelled', style: styleOn }) // style:调样式里按了 Esc(右侧栏退出调样式)
@@ -595,10 +619,10 @@
595
619
  @keyframes pin-in{from{opacity:0;transform:scale(1.12)}}
596
620
  .ck{position:absolute;pointer-events:none;border:calc(2px * var(--k, 1)) solid #f59e0b;border-radius:4px;background:rgba(245,158,11,.08)}
597
621
  .ck.hi{border-color:#e5484d;background:rgba(229,72,77,.08)}
598
- .ck b{position:absolute;left:calc(-9px * var(--k, 1));top:calc(-9px * var(--k, 1));min-width:18px;height:18px;padding:0 4px;box-sizing:border-box;border-radius:9px;
599
- background:#f59e0b;color:#fff;font:700 11px/18px -apple-system,BlinkMacSystemFont,system-ui,sans-serif;text-align:center;
600
- transform:scale(var(--k, 1));transform-origin:0 0;box-shadow:0 2px 6px rgba(0,0,0,.25)}
601
- .ck.hi b{background:#e5484d}
622
+ .ck>i{position:absolute;left:calc(-9px * var(--k, 1));top:calc(-9px * var(--k, 1));display:flex;gap:3px;transform:scale(var(--k, 1));transform-origin:0 0} /* 同一个元素有几条问题:序号并排,不叠在一起 */
623
+ .ck b{display:block;min-width:18px;height:18px;padding:0 4px;box-sizing:border-box;border-radius:9px;
624
+ background:#f59e0b;color:#fff;font:700 11px/18px -apple-system,BlinkMacSystemFont,system-ui,sans-serif;text-align:center;box-shadow:0 2px 6px rgba(0,0,0,.25)}
625
+ .ck b.hi{background:#e5484d}
602
626
  .ck.on{animation:ck-on 1.2s ease-out}
603
627
  .ck.on b{animation:ck-pop .7s cubic-bezier(.2,.8,.2,1)}
604
628
  @keyframes ck-pop{25%,75%{scale:1.3}50%{scale:1}}
@@ -698,7 +722,7 @@
698
722
  b.style.animationDelay = i * 80 + 'ms'
699
723
  if (i === 0) {
700
724
  const t = document.createElement('span')
701
- t.textContent = els.length > 1 ? `已更新 · ${els.length} 处` : '已更新'
725
+ t.textContent = uiLang === 'en' ? `Updated ${els.length} ${els.length === 1 ? 'item' : 'items'}` : `已更新 ${els.length} 处`
702
726
  b.append(t)
703
727
  }
704
728
  root.append(b)
@@ -1030,7 +1054,7 @@
1030
1054
  const b = document.createElement('div')
1031
1055
  b.className = 'pin'
1032
1056
  const t = document.createElement('span')
1033
- t.textContent = '已选 · ' + text
1057
+ t.textContent = uiLang === 'en' ? `Selected “${text}”` : `已选「${text}」`
1034
1058
  b.append(t)
1035
1059
  root.append(b)
1036
1060
  pinned = { node: b, el, rect }
@@ -1325,13 +1349,13 @@
1325
1349
  const meta = document.querySelector('meta[name="dsh-design"]')
1326
1350
  const err = document.querySelector('meta[name="dsh-error"]') // 预览服务器给的出错页(文件没了 / 开发服务器连不上)
1327
1351
  post({
1328
- type: 'ready',
1352
+ type: 'ready', sourceSig:editSig,
1329
1353
  title: document.title,
1330
1354
  err: err ? String(err.getAttribute('content') || 'missing').slice(0, 20) : '',
1331
1355
  href: here(),
1332
1356
  meta: meta ? String(meta.getAttribute('content') || '').slice(0, 80) : '',
1333
1357
  ...statesNow(),
1334
- tokens: tokensOf(),
1358
+ tokens: firstTokens(),
1335
1359
  links: firstLinks(),
1336
1360
  dark: hasDark(),
1337
1361
  natural: naturalSize(),
@@ -1363,8 +1387,11 @@
1363
1387
  }
1364
1388
 
1365
1389
  function tokensOf() {
1366
- const out = []
1367
- const seen = new Set()
1390
+ // 同一个变量几处都写了:记页面上真正生效的那条(:root 压过 html、!important 压过普通、一样时后写的赢),
1391
+ // href / alias / noTry 都按它——试穿换风格只写那一份。先把所有声明收齐再比,加载顺序怎样都一样
1392
+ const best = new Map() // 变量 → { k, href, raw, noTry }
1393
+ const order = [] // 顶层写过的变量(按第一次出现),只在 @media 里写的不报
1394
+ const top = new Set()
1368
1395
  const cs = getComputedStyle(document.documentElement)
1369
1396
  let faces = null
1370
1397
  // 字体变量:打头的字体有没有 @font-face(外观面板据此判断选字体库的同名字体要不要存)
@@ -1374,21 +1401,92 @@
1374
1401
  if (!faces) faces = fontFaces()
1375
1402
  return faces.has((m[1] || m[2]).trim().toLowerCase())
1376
1403
  }
1404
+ const ROOT_SEL = /(^|,)\s*(:root|html)\s*(,|$)/
1405
+ // nested:写在现在生效的 @media / @supports 里(手机宽度下覆盖主色);mixed:和别的选择器写在一起(html, .checkout)。
1406
+ // 生效的是这两种时记 noTry:保存试穿只改得了单写 :root / html 的顶层那条,改了也不是屏幕上这个颜色,试穿不碰它
1407
+ const take = (r, href, nested) => {
1408
+ const sel = r.selectorText || ''
1409
+ if (!ROOT_SEL.test(sel)) return
1410
+ const spec = /(^|,)\s*:root\s*(,|$)/.test(sel) ? 1 : 0
1411
+ const mixed = !sel.split(',').every((x) => /^\s*(:root|html)\s*$/.test(x))
1412
+ for (let i = 0; i < r.style.length; i++) {
1413
+ const name = r.style[i]
1414
+ if (!name.startsWith('--')) continue
1415
+ const raw = r.style.getPropertyValue(name).trim()
1416
+ const k = spec + (r.style.getPropertyPriority(name) === 'important' ? 2 : 0)
1417
+ if (!nested && !top.has(name)) { top.add(name); order.push(name) }
1418
+ const b = best.get(name)
1419
+ if (b && k < b.k) continue
1420
+ best.set(name, { k, href, raw, noTry: nested || mixed })
1421
+ }
1422
+ }
1423
+ // CSS 层里(@import … layer(x)、@layer 块)带 !important 的变量:层里的 !important 压得过层外的,生效的是哪条比不清,
1424
+ // 这几个变量记 noTry(试穿不碰,免得写进没生效的那份文件)。层里的普通声明压不过层外的,不用管
1425
+ const layeredImp = new Set()
1426
+ // 远程预览打包时展开过 @import 的样式表(<style data-imports>):里面的声明原来在哪个文件分不清,按入口文件写会写错地方
1427
+ const blurred = new Set()
1428
+ const isLayer = (r) => typeof CSSLayerBlockRule !== 'undefined' && r instanceof CSSLayerBlockRule
1429
+ const lay = (list, depth) => {
1430
+ if (!list || depth >= 6) return
1431
+ for (const r of list) {
1432
+ if (r.style) {
1433
+ if (!ROOT_SEL.test(r.selectorText || '')) continue
1434
+ for (let i = 0; i < r.style.length; i++) {
1435
+ const name = r.style[i]
1436
+ if (name.startsWith('--') && r.style.getPropertyPriority(name) === 'important') layeredImp.add(name)
1437
+ }
1438
+ continue
1439
+ }
1440
+ try { lay(r.styleSheet ? r.styleSheet.cssRules : r.cssRules, depth + 1) } catch { /* 别的源的读不了 */ }
1441
+ }
1442
+ }
1443
+ const walk = (list, href, nested, depth) => {
1444
+ for (const r of list) {
1445
+ if (r.style) { take(r, href, nested); continue }
1446
+ // @import 进来的样式表:按它自己的地址记(层叠顺序就在 @import 这个位置)。
1447
+ // 放进 CSS 层的(@import … layer(x))和 @layer 块一样不按先后比:层里的普通声明压不过层外的,只记带 !important 的(见 lay)
1448
+ if (r.styleSheet && depth < 4) {
1449
+ if (r.layerName != null) { lay([r], depth); continue }
1450
+ try {
1451
+ const mq = r.media && r.media.mediaText
1452
+ if (!mq || matchMedia(mq).matches) walk(r.styleSheet.cssRules, sheetHref(r.styleSheet), nested, depth + 1)
1453
+ } catch { /* 别的源的读不了 */ }
1454
+ continue
1455
+ }
1456
+ if (!r.cssRules || depth >= 4) continue
1457
+ if (isLayer(r)) { lay(r.cssRules, depth); continue }
1458
+ let on = false
1459
+ try {
1460
+ if (r.media && typeof r.media.mediaText === 'string') on = matchMedia(r.media.mediaText).matches
1461
+ else if (typeof r.conditionText === 'string' && !r.media) on = CSS.supports(r.conditionText)
1462
+ } catch { on = false }
1463
+ if (on) walk(r.cssRules, href, true, depth + 1)
1464
+ }
1465
+ }
1377
1466
  for (const sheet of document.styleSheets) {
1378
1467
  let rules
1379
1468
  try { rules = sheet.cssRules } catch { continue } // 别的源的样式表读不了
1469
+ // 现在不生效的样式表(media="print"、关掉的)不算:试穿存的是屏幕上看到的那份
1470
+ if (sheet.disabled) continue
1471
+ try { const mq = sheet.media && sheet.media.mediaText; if (mq && !matchMedia(mq).matches) continue } catch { /* 认不出的 media 照算 */ }
1380
1472
  const href = sheetHref(sheet)
1381
- for (const r of rules) {
1382
- if (out.length >= MAX_TOKENS) return out
1383
- if (!r.style || !/(^|,)\s*(:root|html)\s*(,|$)/.test(r.selectorText || '')) continue
1384
- for (let i = 0; i < r.style.length && out.length < MAX_TOKENS; i++) {
1385
- const name = r.style[i]
1386
- if (!name.startsWith('--') || seen.has(name)) continue
1387
- seen.add(name)
1388
- const value = (cs.getPropertyValue(name) || r.style.getPropertyValue(name)).trim()
1389
- if (value) out.push({ name, value: clip(value, 160), href, ...(/^\s*["']/.test(value) && face(value) ? { face: true } : null) })
1390
- }
1391
- }
1473
+ try { if (sheet.ownerNode && sheet.ownerNode.hasAttribute('data-imports')) blurred.add(href) } catch { /* 照算 */ }
1474
+ walk(rules, href, false, 0)
1475
+ }
1476
+ const out = []
1477
+ for (const name of order) {
1478
+ if (out.length >= MAX_TOKENS) break
1479
+ const b = best.get(name)
1480
+ const value = (cs.getPropertyValue(name) || b.raw).trim()
1481
+ if (!value) continue
1482
+ out.push({
1483
+ name, value: clip(value, 160), href: b.href,
1484
+ ...(/^\s*["']/.test(value) && face(value) ? { face: true } : null),
1485
+ // alias:写的值里引用了别的变量(--primary: var(--brand)、--shadow: 0 2px 8px var(--c))——试穿换风格时不动它
1486
+ ...(/var\(/i.test(b.raw) ? { alias: true } : null),
1487
+ ...(b.noTry || layeredImp.has(name) || blurred.has(b.href) ? { noTry: true } : null),
1488
+ ...(tweakVars.has(name) ? { tweaked: true } : null), // 正在试穿 / 拖滑块:value 是临时值
1489
+ })
1392
1490
  }
1393
1491
  return out
1394
1492
  }
@@ -1583,7 +1681,7 @@
1583
1681
  name: nameOf(el),
1584
1682
  selector: cssPath(el),
1585
1683
  text: textOf(el),
1586
- loc: { tag, n: same.indexOf(el), total: same.length, id: el.getAttribute('id') || '', cls: [...el.classList] },
1684
+ loc: { sig: editSig, pickedAt: Date.now(), tag, n: same.indexOf(el), total: same.length, id: el.getAttribute('id') || '', cls: [...el.classList] },
1587
1685
  css,
1588
1686
  vars: varsOf(el),
1589
1687
  rules: rulesOf(el),
@@ -1592,6 +1690,26 @@
1592
1690
  }
1593
1691
  }
1594
1692
 
1693
+ /** 读文件里的样子:这个元素正套着调样式的预览时,先撤掉预览再量,量完放回去(关掉过渡,免得量到动画中间的值、放回时闪一下) */
1694
+ function baseInfo(el) {
1695
+ if (!el || el !== styleEl) return styleInfo(el)
1696
+ const cur = el.getAttribute('style')
1697
+ if (cur === styleOrig) return styleInfo(el)
1698
+ const still = () => el.style.setProperty('transition', 'none', 'important')
1699
+ try {
1700
+ styleRevert()
1701
+ still()
1702
+ return styleInfo(el)
1703
+ } finally {
1704
+ if (cur === null) el.removeAttribute('style')
1705
+ else el.setAttribute('style', cur)
1706
+ still()
1707
+ void getComputedStyle(el).fontSize
1708
+ if (cur === null) el.removeAttribute('style')
1709
+ else el.setAttribute('style', cur)
1710
+ }
1711
+ }
1712
+
1595
1713
  function styleRevert() {
1596
1714
  if (!styleEl) return
1597
1715
  if (styleOrig === null) styleEl.removeAttribute('style')
@@ -1632,6 +1750,7 @@
1632
1750
  if (!picking) return
1633
1751
  picking = false
1634
1752
  removeEventListener('keydown', onKey, true)
1753
+ for (const event of ['click','submit','auxclick']) removeEventListener(event, blockActivation, true)
1635
1754
  unmount()
1636
1755
  }
1637
1756
 
@@ -1672,11 +1791,10 @@
1672
1791
  try { Object.defineProperty(window, '__ddpBusy', { value: () => picking || textEdit || styleOn, configurable: true }) } catch { /* 页面占了 */ }
1673
1792
  let editUi = null
1674
1793
  let editing = null // { span, node, before, nth }
1675
- let editLang = 'zh'
1676
- // 正在改的那段字上面的小标签:什么字 · 字号 / 粗细(和右侧栏灵动条上的按键提示一起看)
1794
+ // 正在改的那段字上面的小标签:元素类型和字号(和右侧栏灵动条上的按键提示一起看)
1677
1795
  const ED_TX = {
1678
- zh: { h: '标题', p: '正文', button: '按钮', a: '链接', label: '标签', li: '列表', text: '文字', w7: '粗', w5: '中', w4: '常规' },
1679
- en: { h: 'Heading', p: 'Body', button: 'Button', a: 'Link', label: 'Label', li: 'List', text: 'Text', w7: 'Bold', w5: 'Medium', w4: 'Regular' },
1796
+ zh: { h: '标题', p: '正文', button: '按钮', a: '链接', label: '标签', li: '列表', text: '文字' },
1797
+ en: { h: 'Heading', p: 'Body', button: 'Button', a: 'Link', label: 'Label', li: 'List', text: 'Text' },
1680
1798
  }
1681
1799
 
1682
1800
  function countIn(hay, needle) {
@@ -1733,12 +1851,12 @@ background:linear-gradient(100deg,#a594ff,#5ec8f2 55%,#67e0c3);color:#0b1020;fon
1733
1851
  @media (prefers-reduced-motion:reduce){.tag{animation:none}}
1734
1852
  .hint{position:fixed;left:50%;top:10px;transform:translateX(-50%) scale(var(--k, 1));transform-origin:50% 0;z-index:2147483647;pointer-events:none;padding:6px 12px;border-radius:999px;
1735
1853
  background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-ui,sans-serif;white-space:nowrap;box-shadow:0 4px 16px rgba(0,0,0,.25)}</style>
1736
- <div class="box"></div><div class="tag"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"><path d="M5 6h14M12 6v13"/></svg><span></span></div><div class="hint">点文字直接改 · 回车保存 · Esc 退出</div>`
1854
+ <div class="box"></div><div class="tag"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"><path d="M5 6h14M12 6v13"/></svg><span></span></div><div class="hint">${uiLang === 'en' ? 'Click text to edit. Enter saves, Esc exits.' : '点文字直接改,回车保存,Esc 退出'}</div>`
1737
1855
  editUi = { host: hostEl, box: root.querySelector('.box'), hint: root.querySelector('.hint'), tag: root.querySelector('.tag') }
1738
1856
  // 用了组件的屏(#30):改的字不直接写文件、交给模型改——一进来就说清楚(不管之前看没看过提示)
1739
1857
  // 右侧栏自己有提示条(hint=false)时这里不再挂一条:组件的事由右侧栏那条说(editing 带 comp)
1740
1858
  if (!hint) editUi.hint.style.display = 'none'
1741
- else if (usesComps()) editUi.hint.textContent = editLang === 'en' ? 'This screen uses components · edits go to the model · Esc to stop' : '这屏用了组件 · 改的字会交给模型去改 · Esc 退出'
1859
+ else if (usesComps()) editUi.hint.textContent = uiLang === 'en' ? 'This screen uses components. The model applies your text edits. Esc exits.' : '这屏用了组件,改的字会交给模型去改,Esc 退出'
1742
1860
  document.documentElement.appendChild(hostEl)
1743
1861
  }
1744
1862
 
@@ -1762,12 +1880,11 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
1762
1880
  const tg = editUi.tag
1763
1881
  if (!span || !span.isConnected) { tg.style.display = 'none'; return }
1764
1882
  const el = span.parentElement || span
1765
- const tx = ED_TX[editLang] || ED_TX.zh
1883
+ const tx = ED_TX[uiLang] || ED_TX.zh
1766
1884
  const tn = el.closest('h1,h2,h3,h4,h5,h6,button,a,label,li,p')
1767
1885
  const kind = !tn ? tx.text : /^H\d$/.test(tn.tagName) ? tx.h : tx[tn.tagName.toLowerCase()] || tx.text
1768
1886
  const cs = getComputedStyle(el)
1769
- const w = parseInt(cs.fontWeight, 10) || 400
1770
- tg.querySelector('span').textContent = `${kind} · ${Math.round(parseFloat(cs.fontSize) || 0)} / ${w >= 600 ? tx.w7 : w >= 500 ? tx.w5 : tx.w4}`
1887
+ tg.querySelector('span').textContent = `${kind} ${Math.round(parseFloat(cs.fontSize) || 0)}px`
1771
1888
  const r = span.getBoundingClientRect()
1772
1889
  Object.assign(tg.style, { display: 'flex', left: Math.max(2, r.left - 3) + 'px', top: Math.max(20 * K, r.top - 5) + 'px' })
1773
1890
  }
@@ -1809,6 +1926,9 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
1809
1926
  range.selectNodeContents(span)
1810
1927
  sel.removeAllRanges()
1811
1928
  sel.addRange(range)
1929
+ const comp = usesComps() && span.closest('[data-dsh-c]')
1930
+ editing.source = { sig: editSig, before, nth, href: here(), ...(comp ? { comp: String(comp.getAttribute('data-dsh-c') || '').slice(0, 64) } : {}) }
1931
+ span.addEventListener('input', () => { if (editing?.span === span) post({ type: 'editDraft', ...editing.source, after: normWs(span.innerText) }) })
1812
1932
  span.addEventListener('blur', () => finishEdit(true), { once: true })
1813
1933
  }
1814
1934
 
@@ -1818,13 +1938,11 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
1818
1938
  if (!ed) return
1819
1939
  editing = null
1820
1940
  editTag(null)
1821
- post({ type: 'editing', on: false })
1822
1941
  const after = normWs(ed.span.innerText)
1823
1942
  const text = document.createTextNode(save && after ? ed.raw.replace(ed.raw.trim(), after) : ed.raw)
1824
1943
  if (ed.span.parentNode) ed.span.parentNode.replaceChild(text, ed.span)
1825
- // 字在组件里(#30):带上组件名,交给模型时告诉它该改哪个文件
1826
- const comp = usesComps() && text.parentElement && text.parentElement.closest ? text.parentElement.closest('[data-dsh-c]') : null
1827
- if (save && after && after !== ed.before) post({ type: 'edited', before: ed.before, after, nth: ed.nth, href: here(), ...(comp ? { comp: String(comp.getAttribute('data-dsh-c') || '').slice(0, 64) } : {}) })
1944
+ if (save && after && after !== ed.before) post({ type: 'edited', ...ed.source, after })
1945
+ post({ type: 'editing', on: false })
1828
1946
  }
1829
1947
 
1830
1948
  function onEditKey(e) {
@@ -1838,8 +1956,7 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
1838
1956
  if (e.key === 'Escape') { e.preventDefault(); post({ type: 'editDone' }) }
1839
1957
  }
1840
1958
 
1841
- function setTextEdit(on, hint = true, lang) {
1842
- if (lang) editLang = lang === 'en' ? 'en' : 'zh'
1959
+ function setTextEdit(on, hint = true) {
1843
1960
  if (on === textEdit) return
1844
1961
  if (on && styleOn) setStyleMode(false)
1845
1962
  textEdit = on
@@ -1967,6 +2084,13 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
1967
2084
  // 先报一次,尺寸变了 / 过一会儿再算,位置不一样了就补报(画布连线跟着更新)
1968
2085
  let linkSig = ''
1969
2086
  let linkTimer = 0
2087
+ // 设计变量也一样:画幅变了(拖窄过了断点,手机宽度下的覆盖生效)来源可能跟着变,补报给右侧栏(试穿保存按它写)
2088
+ let tokSig = ''
2089
+ function firstTokens() {
2090
+ const tokens = tokensOf()
2091
+ tokSig = JSON.stringify(tokens.map((tk) => [tk.name, tk.href, tk.alias, tk.noTry]))
2092
+ return tokens
2093
+ }
1970
2094
  function firstLinks() {
1971
2095
  const links = linksOf(true)
1972
2096
  linkSig = JSON.stringify(links)
@@ -1977,9 +2101,14 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
1977
2101
  function resendLinks() {
1978
2102
  const links = linksOf(true)
1979
2103
  const sig = JSON.stringify(links)
1980
- if (sig === linkSig) return
2104
+ const tokens = tokensOf()
2105
+ // 只看来源变没变(值跟着试穿、拖滑块变,不算)
2106
+ const ts = JSON.stringify(tokens.map((tk) => [tk.name, tk.href, tk.alias, tk.noTry]))
2107
+ if (sig === linkSig && ts === tokSig) return
1981
2108
  linkSig = sig
1982
- post({ type: 'links', links })
2109
+ const withTokens = ts !== tokSig
2110
+ tokSig = ts
2111
+ post({ type: 'links', links, ...(withTokens ? { tokens } : {}) })
1983
2112
  }
1984
2113
 
1985
2114
  if (STRICT) {
@@ -2014,6 +2143,17 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
2014
2143
 
2015
2144
  // 演示:点了跳页的地方,不在 iframe 里直接跳,告诉右侧栏换一屏(带过场动画)
2016
2145
  // 远程看也是:沙盒里的页面跳不过去(地址指着电脑本机),由右侧栏打包那一页换上来
2146
+ let interacting = false, historyKeys = false
2147
+ addEventListener('keydown', event => {
2148
+ if (parentWin && historyKeys && !editing && !demo && !event.defaultPrevented && window.__dshForwardHistoryKey?.(event)) event.preventDefault()
2149
+ })
2150
+ function leaveInteraction(event) {
2151
+ if (!interacting || !event.isTrusted || event.key !== 'Escape' || event.defaultPrevented || event.isComposing || event.keyCode === 229 ||
2152
+ event.target.closest?.('input, textarea, select, [contenteditable]:not([contenteditable=false]), dialog[open], [role=dialog]')) return
2153
+ event.preventDefault()
2154
+ post({ type:'leaveInteraction' })
2155
+ }
2156
+ addEventListener('keydown', leaveInteraction)
2017
2157
  let demo = false
2018
2158
  // 单看时点了「同一页换个状态」的链接(#30):不在 iframe 里自己跳,告诉右侧栏换状态(屏名旁的「状态 ▾」跟着变)。
2019
2159
  // 右侧栏说了认这个(init 里 stateNav 是它让这一帧显示的那一页的路径)才拦:别的看法(对比、多尺寸)照常让页面自己跳;
@@ -2130,7 +2270,7 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
2130
2270
  const c = pending
2131
2271
  pending = null
2132
2272
  if (opts && opts.build) build(opts.lang === 'en' ? 'en' : 'zh')
2133
- else if (c && c.els.length) setTimeout(() => play(c.els), 60)
2273
+ else if (!opts?.quiet && c && c.els.length) setTimeout(() => play(c.els), 60)
2134
2274
  watchHmr()
2135
2275
  }
2136
2276
 
@@ -2950,12 +3090,12 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
2950
3090
 
2951
3091
  // ── 设计体检:在画好的页面上实测常见毛病,标在页面上,报给右侧栏(给人看的文字由右侧栏按界面语言拼) ──
2952
3092
  //
2953
- // hscroll 超出屏幕(会横向滚动 / 被切掉) · clipped 文字被截断 · overflow 文字超出框 · overlap 文字叠在一起
2954
- // contrast 对比度不够 · tap 点击区太小 · tiny 字太小 · img 图片没加载出来 · fonts 字号太杂
2955
- // covered 被固定栏压住(滚到底也看不全) · tight 离固定栏太近 · jserr 页面脚本报错 · missing 样式表 / 脚本 / 字体没载出来
3093
+ // hscroll 超出屏幕(会横向滚动 / 被切掉),clipped 文字被截断,overflow 文字超出框,overlap 文字叠在一起
3094
+ // contrast 对比度不够,tap 点击区太小,tiny 字太小,img 图片没加载出来,fonts 字号太杂
3095
+ // covered 被固定栏压住(滚到底也看不全),tight 离固定栏太近,jserr 页面脚本报错,missing 样式表 / 脚本 / 字体没载出来
2956
3096
  // mockmiss 页面用到的字段模拟数据里没有
2957
3097
  // capsule 小程序右上角的胶囊(微信画的,页面盖不住)挡住了字或按钮
2958
- // island 灵动岛挡住了字或按钮 · homebar 底栏里的字、图标伸进底部横条区 · tabbar 标签栏超过 5 项 · navbar 小程序这屏没有导航栏
3098
+ // island 灵动岛挡住了字或按钮,homebar 底栏里的字、图标伸进底部横条区,tabbar 标签栏超过 5 项,navbar 小程序这屏没有导航栏
2959
3099
  // winctl 桌面软件的窗口按钮(Mac 红绿灯 / Windows 右上角三个)挡住了字或按钮
2960
3100
  // 有意为之的不报:省略号(text-overflow: ellipsis)、行数截断(line-clamp)、可以滚动的区域(轮播)、很淡的装饰大字。
2961
3101
 
@@ -3303,6 +3443,47 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
3303
3443
  return false
3304
3444
  }
3305
3445
 
3446
+ /**
3447
+ * 栏上凸出来的那块(底栏中间的「+」圆钮、顶栏垂下来的头像):栏本身没压住、凸出来的压住了也算。
3448
+ * 栏外面的字被它盖住 → covered(要再多留边距);栏里自己的字(「记一笔」)被它盖住 → overlap。
3449
+ */
3450
+ function bumpCheck(add, atoms, bar, edge, covered) {
3451
+ const b = bar.r
3452
+ const bumps = []
3453
+ for (const d of bar.el.querySelectorAll('*')) {
3454
+ if (isOurs(d) || bumps.some((x) => x.el.contains(d))) continue
3455
+ const r = d.getBoundingClientRect()
3456
+ if (r.width < 12 || r.height < 12) continue
3457
+ if ((edge === 'bottom' ? b.top - r.top : r.bottom - b.bottom) < 4) continue
3458
+ if (hiddenChain(d)) continue
3459
+ bumps.push({ el: d, r })
3460
+ }
3461
+ for (const bump of bumps) {
3462
+ const p = bump.r
3463
+ for (const a of atoms) {
3464
+ if (covered.has(a.el) || bump.el.contains(a.el) || a.el.contains(bump.el)) continue
3465
+ const inBar = bar.el.contains(a.el)
3466
+ for (const r of textRects(a.el)) {
3467
+ const l = Math.max(r.l, p.left), rr = Math.min(r.r, p.right)
3468
+ if (rr - l < 2) continue
3469
+ // 栏外的字只看伸出栏的那段(栏本身压住的上面已经查过);栏里的字看和凸块叠着的那段
3470
+ const lo = inBar ? p.top : edge === 'bottom' ? p.top : b.bottom
3471
+ const hi = inBar ? p.bottom : edge === 'bottom' ? b.top : p.bottom
3472
+ const t = Math.max(r.t, lo), bt = Math.min(r.b, hi)
3473
+ if (bt - t < 2) continue
3474
+ const x = (l + rr) / 2, y = (t + bt) / 2
3475
+ if (clippedAt(a.el, x, y)) continue
3476
+ const top = topAt(x, y)
3477
+ if (!top || !bump.el.contains(top) || !barSolid(top, bump.el)) continue
3478
+ covered.add(a.el)
3479
+ if (inBar) add('overlap', a.el, { other: nameOf(bump.el), otherText: ownText(bump.el).slice(0, 40), otherSel: cssPath(bump.el), px: Math.round(bt - t) }, 2)
3480
+ else add('covered', a.el, { px: Math.round(bt - t), edge, bar: `${nameOf(bar.el)} 凸出来的 ${nameOf(bump.el)}` }, 2)
3481
+ break
3482
+ }
3483
+ }
3484
+ }
3485
+ }
3486
+
3306
3487
  function edgeCheck(add, atoms) {
3307
3488
  const areas = scrollAreas()
3308
3489
  const was = areas.map((el) => [el, el.scrollLeft, el.scrollTop])
@@ -3337,6 +3518,7 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
3337
3518
  }
3338
3519
  }
3339
3520
  if (near && near.d >= 0 && near.d < 8 && !covered.has(near.el)) add('tight', near.el, { px: Math.round(near.d), edge, bar: nameOf(bar.el) }, 1)
3521
+ bumpCheck(add, atoms, bar, edge, covered)
3340
3522
  out.push({ edge, name: nameOf(bar.el), pos: bar.pos, h: Math.round(b.height), gap: near ? Math.round(near.d) : null })
3341
3523
  }
3342
3524
  }
@@ -3664,8 +3846,8 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
3664
3846
  if (cr < need - 0.05) add('contrast', el, { ratio: Math.round(cr * 100) / 100, need, fg: hex(fg), bg: hex(bd.color) }, cr < need * 0.75 ? 2 : 1)
3665
3847
  } })
3666
3848
 
3667
- // 5. 点击区太小(App / 小程序 / 平板 44,网页 24;文字中间的链接不算)
3668
- const minTap = kind === 'app' || kind === 'miniprogram' || kind === 'tablet' ? 44 : kind === 'web' || kind === 'email' || kind === 'desktop' || kind === 'dshplugin' || kind === 'framed' ? 24 : 0
3849
+ // 5. 点击区太小(App / 小程序 / 平板 44,网页 24,嵌入式屏幕小屏 36、一般 44;文字中间的链接不算)
3850
+ const minTap = kind === 'embedded' ? (vw <= 480 ? 36 : 44) : kind === 'app' || kind === 'miniprogram' || kind === 'tablet' ? 44 : kind === 'web' || kind === 'email' || kind === 'desktop' || kind === 'dshplugin' || kind === 'framed' ? 24 : 0
3669
3851
  if (minTap) {
3670
3852
  const small = []
3671
3853
  for (const el of body.querySelectorAll(CLICKABLE)) {
@@ -3736,9 +3918,10 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
3736
3918
  if (short || tail <= 2.2) { add('wrap', a.el, { lines: tops.length }, 1); wraps++ }
3737
3919
  }
3738
3920
 
3739
- // 10. 字号太杂(整屏一条)
3921
+ // 10. 字号太杂(整屏一条)。嵌入式屏幕每个字号都要单独转一份字库(占 Flash),最多 4 种
3740
3922
  const used = [...sizes.keys()].sort((x, y) => x - y)
3741
- if (used.length > 7) add('fonts', null, { sizes: used }, 1)
3923
+ const fontMax = kind === 'embedded' ? 4 : 7
3924
+ if (used.length > fontMax) add('fonts', null, { sizes: used, max: fontMax }, 1)
3742
3925
 
3743
3926
  // 11. 固定栏压住内容 / 贴得太近
3744
3927
  const edges = edgeCheck(add, atoms)
@@ -3771,6 +3954,8 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
3771
3954
  if (kind === 'diagram') smallTextCheck(add, vw)
3772
3955
  // 17. DSH 插件:外框被改动(结构、文字、样式和模板对不上)
3773
3956
  frameCheck(add, kind)
3957
+ // 18. 嵌入式屏幕:整屏放不下、板子上画不出来的写法、字体太多
3958
+ if (kind === 'embedded') embeddedCheck(add, atoms)
3774
3959
 
3775
3960
  issues.sort((x, y) => y.sev - x.sev)
3776
3961
  const se0 = se()
@@ -4538,6 +4723,78 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
4538
4723
  }
4539
4724
  }
4540
4725
 
4726
+ /** 一层样式里 LVGL(单片机上的图形库)画不出来、或者要额外打开开关才画得出来的写法 → 代号列表 */
4727
+ function emfxOf(cs) {
4728
+ const out = []
4729
+ const none = (v) => !v || v === 'none'
4730
+ if (!none(cs.backdropFilter) || !none(cs.webkitBackdropFilter)) out.push('backdrop')
4731
+ if (!none(cs.filter)) out.push('filter')
4732
+ if (cs.mixBlendMode && cs.mixBlendMode !== 'normal') out.push('blend')
4733
+ if (!none(cs.textShadow)) out.push('tshadow')
4734
+ if (!none(cs.boxShadow)) {
4735
+ const n = cs.boxShadow.replace(/\([^)]*\)/g, '').split(',').length
4736
+ if (n > 1 || /\binset\b/.test(cs.boxShadow)) out.push('shadow')
4737
+ }
4738
+ const bg = cs.backgroundImage || ''
4739
+ if (/(radial|conic)-gradient\(/.test(bg)) out.push('grad')
4740
+ else {
4741
+ for (const m of bg.matchAll(/linear-gradient\(((?:[^()]|\([^()]*\))*)\)/g)) {
4742
+ const body = m[1]
4743
+ const deg = /^\s*(-?[\d.]+)deg/.exec(body)
4744
+ const corner = /^\s*to\s+(top|bottom)\s+(left|right)|^\s*to\s+(left|right)\s+(top|bottom)/.test(body)
4745
+ const stops = (body.match(/(rgba?|hsla?|color|oklch|oklab|lab|lch)\(|#[0-9a-f]{3,8}\b|\btransparent\b/gi) || []).length
4746
+ if (corner || (deg && Math.abs(parseFloat(deg[1])) % 90 > 0.5) || stops > 2) { out.push('grad'); break }
4747
+ }
4748
+ }
4749
+ if (/^matrix3d/.test(cs.transform || '') || !none(cs.perspective)) out.push('3d')
4750
+ if (!none(cs.clipPath)) out.push('clip')
4751
+ if (!none(cs.maskImage) || !none(cs.webkitMaskImage)) out.push('mask')
4752
+ return out
4753
+ }
4754
+
4755
+ /** 嵌入式屏幕:板子上没有滚动条、画不出模糊这类效果、字库按字体单独转(占 Flash) */
4756
+ function embeddedCheck(add, atoms) {
4757
+ // 整屏放不下:页面能往下滚,或者字 / 按钮跑到屏幕下面去了(html、body 或最外层容器 overflow: hidden 时页面不滚,多出来的直接被裁掉)。
4758
+ // 在能滚的容器(overflow: auto 的长列表)里的不算
4759
+ const vh = innerHeight
4760
+ const de = document.scrollingElement || document.documentElement
4761
+ let bottom = Math.ceil(de.scrollHeight)
4762
+ const inScroller = (el) => {
4763
+ for (let e = el.parentElement; e && e !== document.body && e !== document.documentElement; e = e.parentElement) if (/auto|scroll/.test(getComputedStyle(e).overflowY)) return true
4764
+ return false
4765
+ }
4766
+ for (const a of atoms) {
4767
+ const b = Math.max(...a.rects.map((r) => r.b)) + scrollY
4768
+ if (b > vh + 2 && b > bottom && !inScroller(a.el)) bottom = Math.ceil(b)
4769
+ }
4770
+ for (const el of document.body.querySelectorAll(CLICKABLE)) {
4771
+ if (isOurs(el) || inFrame(el)) continue
4772
+ const r = el.getBoundingClientRect()
4773
+ const b = r.bottom + scrollY
4774
+ if (r.width >= 1 && r.height >= 1 && b > vh + 2 && b > bottom && !hiddenChain(el) && !inScroller(el)) bottom = Math.ceil(b)
4775
+ }
4776
+ if (bottom > vh + 2) add('emfit', null, { h: bottom, vh }, 2)
4777
+ const all = document.body.getElementsByTagName('*')
4778
+ for (let i = 0, seen = 0; i < all.length && seen < 3000; i++) {
4779
+ const el = all[i]
4780
+ if (isOurs(el) || el.closest('dsh-design-picker,dsh-design-fx,dsh-design-edit,script,style,noscript,template,head') || inFrame(el)) continue
4781
+ seen++
4782
+ const cs = getComputedStyle(el)
4783
+ if (cs.display === 'none' || cs.display === 'contents') continue
4784
+ const fx = emfxOf(cs)
4785
+ if (!fx.length) continue
4786
+ const r = el.getBoundingClientRect()
4787
+ if (r.width < 1 || r.height < 1 || hiddenChain(el)) continue
4788
+ add('emfx', el, { fx }, 1)
4789
+ }
4790
+ const fams = new Set()
4791
+ for (const a of atoms) {
4792
+ const f = String(a.cs.fontFamily || '').split(',')[0].replace(/["']/g, '').trim()
4793
+ if (f) fams.add(f)
4794
+ }
4795
+ if (fams.size > 2) add('emfont', null, { n: fams.size, names: [...fams].slice(0, 5).join(' / ') }, 1)
4796
+ }
4797
+
4541
4798
  /** 图表(diagram.css)的结构问题:连线是样式按结构画的,结构写错了线就对不上 */
4542
4799
  function diagramCheck(add, kind, vw) {
4543
4800
  const de = document.scrollingElement || document.documentElement
@@ -5279,13 +5536,21 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
5279
5536
  const { root } = fxRoot()
5280
5537
  issues.forEach((it, i) => {
5281
5538
  if (!it.el) return
5282
- const b = document.createElement('div')
5283
- b.className = 'ck' + (it.sev > 1 ? ' hi' : '')
5539
+ // 同一个元素的几条问题共用一个框,序号并排(不然框叠框、序号压序号,只看得到最后一个)
5540
+ let mk = checkMarks.find((x) => x.el === it.el)
5541
+ if (!mk) {
5542
+ const b = document.createElement('div')
5543
+ b.className = 'ck'
5544
+ b.append(document.createElement('i'))
5545
+ root.append(b)
5546
+ mk = { node: b, el: it.el }
5547
+ checkMarks.push(mk)
5548
+ }
5549
+ if (it.sev > 1) mk.node.classList.add('hi')
5284
5550
  const t = document.createElement('b')
5551
+ if (it.sev > 1) t.className = 'hi'
5285
5552
  t.textContent = String(i + 1)
5286
- b.append(t)
5287
- root.append(b)
5288
- checkMarks.push({ node: b, el: it.el })
5553
+ mk.node.firstChild.append(t)
5289
5554
  })
5290
5555
  placeMarks()
5291
5556
  }
@@ -5801,9 +6066,10 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
5801
6066
  if (!parentWin || e.source !== parentWin || !parentOrigins.includes(e.origin)) return
5802
6067
  const d = e.data
5803
6068
  if (!d || d.dshDesign !== 1) return
5804
- if (d.type === 'pick') start(d.hint !== false)
6069
+ if (d.lang === 'en' || d.lang === 'zh') uiLang = d.lang
6070
+ if (d.type === 'pick') start(d.hint !== false,d.context)
5805
6071
  else if (d.type === 'cancel') { if (!styleOn) stop(true) }
5806
- else if (d.type === 'init') { if (d.relay) relay(); stateNav = typeof d.stateNav === 'string' ? d.stateNav : ''; boot(d.seed || null) }
6072
+ else if (d.type === 'init') { if (d.relay) relay(); historyKeys = d.historyKeys === true; stateNav = typeof d.stateNav === 'string' ? d.stateNav : ''; boot(d.seed || null) }
5807
6073
  else if (d.type === 'files') { relay(); onFiles(String(d.file || ''), Array.isArray(d.files) ? d.files : null) }
5808
6074
  else if (d.type === 'reveal') reveal(d)
5809
6075
  else if (d.type === 'zoom') setK(1 / (Number(d.z) || 1))
@@ -5822,9 +6088,19 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
5822
6088
  else if (d.type === 'annotFocus') { holdScroll(); focusAnnot(String(d.id || '')) }
5823
6089
  else if (d.type === 'annotHit') hitAnnot(Number(d.x), Number(d.y))
5824
6090
  else if (d.type === 'theme') { setDark(d.dark); postTop(); setTimeout(postTop, 400) }
6091
+ else if (d.type === 'interaction') interacting = !!d.on
5825
6092
  else if (d.type === 'demo') demo = !!d.on
5826
- else if (d.type === 'edit') setTextEdit(!!d.on, d.hint !== false, d.lang)
6093
+ else if (d.type === 'edit') setTextEdit(!!d.on, d.hint !== false)
5827
6094
  else if (d.type === 'styleMode') setStyleMode(!!d.on)
6095
+ else if (d.type === 'readStyle' && styleOn) {
6096
+ let el
6097
+ try { el = document.querySelector(d.selector) } catch { /* selection no longer exists */ }
6098
+ const info = el && baseInfo(el)
6099
+ const loc = info?.loc
6100
+ const same = loc && loc.tag === d.loc?.tag && loc.id === d.loc.id &&
6101
+ (loc.id || (loc.n === d.loc.n && loc.total === d.loc.total && loc.cls.join(' ') === (d.loc.cls || []).join(' ')))
6102
+ post({ type: 'styleRefreshed', request: d.request, payload: same ? info : null })
6103
+ }
5828
6104
  else if (d.type === 'styleSel') onStyleSel(d.selector)
5829
6105
  else if (d.type === 'style') { styleApply(d.css); queueTop() }
5830
6106
  else if (d.type === 'tweak') { applyTweak(d.vars, d.attrs, d.fonts); queueTop() }
@@ -5855,6 +6131,8 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
5855
6131
  winctl: (how) => showWinCtl(how),
5856
6132
  /** 调节滑块的值套到页面上(和右侧栏拖的时候一样) */
5857
6133
  tweak: (vars, attrs) => { applyTweak(vars, attrs); return true },
6134
+ /** 页面上的设计变量(和发给右侧栏的一样:每个变量记生效那条声明的出处) */
6135
+ tokens: () => tokensOf(),
5858
6136
  settle: () => settle().then(() => true),
5859
6137
  /** 业务标注定位得到吗(只找,不画):[{ id, how, count }] */
5860
6138
  annots: async (list) => {