dsh-design-studio 0.17.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js CHANGED
@@ -854,7 +854,7 @@ window.__ModuleLoader__.load({
854
854
  exShare: '分享到设计市场',
855
855
  shTitle: '分享到设计市场',
856
856
  shGh: '投稿要有 GitHub 账号',
857
- shTip: '交上去的东西是公开的:别人能看、能拿去用。先查一遍,过了打成 zip,再到 GitHub 上交。',
857
+ shTip: '交上去的东西是公开的:别人能看、能拿去用。先查一遍,过了就能投。',
858
858
  shName: '名字',
859
859
  shDesc: '一句话介绍',
860
860
  shDescPh: '比如:街角茶饮店的三屏点单 App',
@@ -867,12 +867,39 @@ window.__ModuleLoader__.load({
867
867
  shChecking: '在查…',
868
868
  shOk: '查过了,打好了:{name}(在「下载」里)',
869
869
  shSteps: '还差三步:',
870
- shStep1: '点下面「打开投稿页」(先登录 GitHub)',
870
+ shStep1: '点「打开投稿页」(先登录 GitHub)',
871
871
  shStep2: '把这个 zip 拖进「设计包」那一栏',
872
872
  shStep3: '勾上四个确认,点「Submit new issue」',
873
873
  shOpen: '打开投稿页',
874
874
  shAfter: '几分钟后机器人会在那条 issue 里回复结果;上架后「我的作品」里这套会显示「已上架」。投稿记号:{ref}',
875
875
  shAgain: '改好了,再查一遍',
876
+ shGhWhy: '连一次 GitHub,以后点一下就能投:插件替你把 zip 放进你自己的 GitHub 仓库、开好投稿 issue。',
877
+ shGhConnect: '连上 GitHub',
878
+ shGhCode: '到 GitHub 输这个码:',
879
+ shGhCopy: '复制',
880
+ shGhOpen: '打开 GitHub 输码',
881
+ shGhCancel: '取消',
882
+ shGhWaiting: '输完点「Authorize」,这里会自动接着走。',
883
+ shGhAs: '用 GitHub 账号 {login} 投稿',
884
+ shGhLogout: '断开',
885
+ shGhErr_denied: '你在 GitHub 上点了拒绝。想投的话再连一次。',
886
+ shGhErr_expired: '码过期了,再连一次。',
887
+ shGhErr_net: '连不上 GitHub,等会儿再试,或者用网页表单交。',
888
+ shGhErr_noApp: '这个版本还不能一键投稿,用网页表单交。',
889
+ shGhErr_device: 'GitHub 没连上,再试一次,或者用网页表单交。',
890
+ shSubmit: '一键投稿',
891
+ shSubmittingShort: '在投…',
892
+ shSubmitting: '在投…第一次会在你的 GitHub 里建一个副本放 zip,要一两分钟。',
893
+ shSubmitted: '交上去了:机器人几分钟内会在投稿 issue 里回复检查结果。',
894
+ shSubmittedLink: '看投稿进度',
895
+ shManual: '不想连 GitHub?用网页表单交',
896
+ shSubErr_auth: 'GitHub 授权失效了,重新连一次。',
897
+ shSubErr_net: '连不上 GitHub,等会儿再试,或者用网页表单交。',
898
+ shSubErr_big: '包太大(超过 8MB),投不上去:删掉用不到的大图再查一遍。',
899
+ shSubErr_notShared: '找不到刚打好的包了,再点一次「检查并投稿」。',
900
+ shSubErr_busy: '正在投,稍等。',
901
+ shSubErr_who: '现在连着的 GitHub 账号换成了 {msg}(别的窗口里换的)。没投,确认用这个账号的话再点一次。',
902
+ shSubErr_api: 'GitHub 没接住({msg}):再试一次,或者用网页表单交。',
876
903
  wkShare: '分享到设计市场',
877
904
  wkListed: '已上架 · 去市场看',
878
905
  wkShared: '分享过 · 还没上架',
@@ -1692,7 +1719,7 @@ window.__ModuleLoader__.load({
1692
1719
  exShare: 'Share to the gallery',
1693
1720
  shTitle: 'Share to the gallery',
1694
1721
  shGh: 'You need a GitHub account to submit',
1695
- shTip: 'What you share is public: anyone can see and reuse it. It is checked first, saved as a zip, then you submit it on GitHub.',
1722
+ shTip: 'What you share is public: anyone can see and reuse it. It is checked first; once it passes you can submit it.',
1696
1723
  shName: 'Name',
1697
1724
  shDesc: 'One-line description',
1698
1725
  shDescPh: 'e.g. A three-screen ordering app for a corner tea shop',
@@ -1705,12 +1732,39 @@ window.__ModuleLoader__.load({
1705
1732
  shChecking: 'Checking…',
1706
1733
  shOk: 'Checked and saved: {name} (in Downloads)',
1707
1734
  shSteps: 'Three more steps:',
1708
- shStep1: 'Click “Open the submission page” below (sign in to GitHub first)',
1735
+ shStep1: 'Click “Open the submission page” (sign in to GitHub first)',
1709
1736
  shStep2: 'Drag this zip into the “Design pack” box',
1710
1737
  shStep3: 'Tick the four boxes and click “Submit new issue”',
1711
1738
  shOpen: 'Open the submission page',
1712
1739
  shAfter: 'A bot replies on that issue within minutes; once it is listed, My work shows “Listed”. Submission ref: {ref}',
1713
1740
  shAgain: 'Fixed, check again',
1741
+ shGhWhy: 'Connect GitHub once and submitting is one click: the plugin puts the zip in your own GitHub repository and opens the submission issue for you.',
1742
+ shGhConnect: 'Connect GitHub',
1743
+ shGhCode: 'Enter this code on GitHub:',
1744
+ shGhCopy: 'Copy',
1745
+ shGhOpen: 'Open GitHub to enter the code',
1746
+ shGhCancel: 'Cancel',
1747
+ shGhWaiting: 'After entering it, click “Authorize”; this continues by itself.',
1748
+ shGhAs: 'Submitting as GitHub user {login}',
1749
+ shGhLogout: 'Disconnect',
1750
+ shGhErr_denied: 'You declined on GitHub. Connect again if you want to submit.',
1751
+ shGhErr_expired: 'The code expired. Connect again.',
1752
+ shGhErr_net: 'Could not reach GitHub. Try again later, or use the web form.',
1753
+ shGhErr_noApp: 'One-click submission is not available in this version; use the web form.',
1754
+ shGhErr_device: 'Could not connect GitHub. Try again, or use the web form.',
1755
+ shSubmit: 'Submit',
1756
+ shSubmittingShort: 'Submitting…',
1757
+ shSubmitting: 'Submitting… The first time, a copy of the gallery is made in your GitHub to hold the zip; this takes a minute or two.',
1758
+ shSubmitted: 'Submitted: a bot replies on the submission issue with the check results within minutes.',
1759
+ shSubmittedLink: 'See progress',
1760
+ shManual: 'Rather not connect GitHub? Use the web form',
1761
+ shSubErr_auth: 'GitHub access expired. Connect again.',
1762
+ shSubErr_net: 'Could not reach GitHub. Try again later, or use the web form.',
1763
+ shSubErr_big: 'The pack is too big (over 8 MB): remove large images you do not use and check again.',
1764
+ shSubErr_notShared: 'The pack just made is gone; click “Check and submit” again.',
1765
+ shSubErr_busy: 'Already submitting, one moment.',
1766
+ shSubErr_who: 'The connected GitHub account changed to {msg} (in another window). Nothing was sent; click again to submit with this account.',
1767
+ shSubErr_api: 'GitHub did not accept it ({msg}): try again, or use the web form.',
1714
1768
  wkShare: 'Share to the gallery',
1715
1769
  wkListed: 'Listed · view in gallery',
1716
1770
  wkShared: 'Shared · not listed yet',
@@ -1859,6 +1913,9 @@ window.__ModuleLoader__.load({
1859
1913
  .ddp-stage{position:relative;flex:1;min-height:0;overflow:hidden;background:var(--dsw-alias-bg-layer-2)}
1860
1914
  .ddp-scr{position:absolute;inset:0;overflow:hidden}
1861
1915
  .ddp-away{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;padding:24px;text-align:center;font-size:13px;line-height:1.6;color:var(--dsw-alias-text-secondary,#888);background:var(--dsw-alias-bg-layer-1)}
1916
+ /* 睡着的屏的缩略图:盖在「挪近就加载」上面,载到了才淡出来 */
1917
+ .ddp-snap{position:absolute;left:0;top:0;width:100%;height:100%;object-fit:cover;object-position:left top;opacity:0;transition:opacity .25s;pointer-events:none;user-select:none;-webkit-user-drag:none}
1918
+ .ddp-snap.on{opacity:1}
1862
1919
  .ddp-frame{position:absolute;left:0;top:0;width:100%;height:100%;border:0;background:#fff;opacity:0;z-index:0;pointer-events:none}
1863
1920
  .ddp-frame.old{opacity:1;z-index:1}
1864
1921
  .ddp-frame.cur{opacity:1;z-index:2;pointer-events:auto;transition:opacity .32s ease}
@@ -1900,10 +1957,13 @@ window.__ModuleLoader__.load({
1900
1957
  .ddp-canvas{position:absolute;inset:0;overflow:hidden;cursor:grab;touch-action:none;user-select:none;-webkit-user-select:none;
1901
1958
  background-color:var(--dsw-alias-bg-layer-2);background-image:radial-gradient(circle,rgba(127,127,127,.3) 1px,transparent 1.4px)}
1902
1959
  .ddp-canvas.drag{cursor:grabbing}
1903
- .ddp-world{position:absolute;left:0;top:0;transform-origin:0 0;will-change:transform}
1960
+ /* 画布和格子都不写 will-change:带着它浏览器会一直按放大过时的清晰度留着整片画布,缩小看几十屏时显存爆掉,
1961
+ 画布和底色画不出来,后面的对话透上来(issue #18)。不带它,停下就按当前大小重画;镜头过渡、换行滑动浏览器自己会临时走合成层 */
1962
+ .ddp-world{position:absolute;left:0;top:0;transform-origin:0 0}
1904
1963
  .ddp-world.anim{transition:transform .45s ${EASE}}
1905
- .ddp-cell{position:absolute;transition:left .45s ${EASE},top .45s ${EASE};animation:ddp-cell .5s ${EASE}}
1906
- .ddp-canvas.heavy .ddp-cell{transition:none;will-change:translate,scale}
1964
+ /* 每格自成一层:极小缩放时标题伸进上一排,别被上一屏的挡板截走点击。
1965
+ 换位置不用 left/top 过渡:一律由画布里的 translate 动画从旧样子滑过来,两套动画差一帧开始就会在第一帧猛跳一下 */
1966
+ .ddp-cell{position:absolute;isolation:isolate;animation:ddp-cell .5s ${EASE}}
1907
1967
  @keyframes ddp-cell{from{opacity:0;scale:.94}}
1908
1968
  .ddp-cell.sel>.ddp-dev{outline:calc(2px / var(--z)) solid ${ACCENT};outline-offset:calc(5px / var(--z))}
1909
1969
  .ddp-shield{position:absolute;inset:0;z-index:6;cursor:default}
@@ -2645,6 +2705,9 @@ window.__ModuleLoader__.load({
2645
2705
  .ddp-share .steps{margin:10px 6px 0;line-height:1.6}
2646
2706
  .ddp-share .steps p{margin:0}
2647
2707
  .ddp-share .steps ol{margin:4px 0 6px;padding-left:20px}
2708
+ .ddp-share .steps.gh1{display:flex;flex-direction:column;gap:6px}
2709
+ .ddp-share .steps .code b{font:600 20px/1.3 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;letter-spacing:2px;color:var(--dsw-alias-label-primary);user-select:all}
2710
+ .ddp-share .steps .lk{padding:0}
2648
2711
  .ddp-share footer a.go{display:flex;flex:1;align-items:center;justify-content:center;height:30px;padding:0 10px;border-radius:8px;font:inherit;text-decoration:none}
2649
2712
  .ddp-share footer a.go:hover{opacity:.88}
2650
2713
  .ddp-pack .okbox{display:flex;flex-direction:column;align-items:flex-start;gap:6px;margin:10px 4px 0;padding:10px;border-radius:10px;background:color-mix(in srgb,#16a34a 11%,transparent);color:var(--dsw-alias-label-primary);line-height:1.5}
@@ -4544,7 +4607,6 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
4544
4607
  const LAB = 34 // 每屏上面标题占的高度(屏幕像素,不跟着缩放)
4545
4608
  const GAP = 18 // 两屏之间最少隔开的屏幕像素
4546
4609
  const clampZ = (z) => Math.max(ZMIN, Math.min(ZMAX, z))
4547
- const HEAVY_N = 12 // 超过这么多屏,画布按「重」的来:拖宽度时只挪镜头、列数变了才重排,换行动画走合成层(不然所有 iframe 每一帧都按新比例重绘,整个窗口跟着闪)
4548
4610
  const LIVE_MAX = 24 // 同时跑几个 iframe。超过这么多屏,画布只挂镜头附近的(选中的那屏总在),导出时分批挂
4549
4611
  /** 该挂着的几屏:离镜头中心最近的 max 屏,选中的那屏排最前。cx、cy 是镜头中心在画布上的坐标 */
4550
4612
  function nearestLive(ids, pos, dw, dh, cx, cy, selId, max, prev) {
@@ -5253,8 +5315,8 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
5253
5315
  // 远程看(本地文件的预览):服务端把这一屏连同样式、图片打成一份 HTML,放进沙盒 iframe 的 srcdoc
5254
5316
  const remOf = (p) => (p.remote && away(p.src) ? p.remote : null)
5255
5317
  const OLD_VER = /^__dsh_design__\/v\/(\d+)\/(.*)$/
5256
- /** 这一屏(预览服务器上的地址)打包后的取法 */
5257
- function bundleOf(href, sid) {
5318
+ /** 这一屏(预览服务器上的地址)打包后的取法。fresh:要求服务端别复用缓存、重新打包 */
5319
+ function bundleOf(href, sid, fresh) {
5258
5320
  let p
5259
5321
  try { p = new URL(href).pathname } catch { return '' }
5260
5322
  try { p = decodeURIComponent(p) } catch { /* 原样 */ }
@@ -5263,7 +5325,80 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
5263
5325
  const m = OLD_VER.exec(p)
5264
5326
  if (m) { v = m[1]; p = m[2] }
5265
5327
  if (!p || p.endsWith('/')) p += 'index.html'
5266
- return `${API}bundle?${new URLSearchParams({ session: sid, key: p, v, parent: location.origin })}`
5328
+ const q = { session: sid, key: p, v, parent: location.origin }
5329
+ if (fresh) q.fresh = '1'
5330
+ return `${API}bundle?${new URLSearchParams(q)}`
5331
+ }
5332
+
5333
+ /**
5334
+ * 打包结果留一份,几处共用:画布 ↔ 单页来回切、多尺寸三档同一屏、关掉侧栏再打开、来回看版本。
5335
+ * 一屏就是几十上百 KB(有图是几 MB),重复走一趟往返不划算。
5336
+ * 认「目录里最后一次改动的时间」(state 的 changedAt)和「哪些算别人做的」的指纹(state 的 trust,所有会话共用:
5337
+ * 退回旧版时信任可能变了、文件却没动):对不上就当没有,重新取。
5338
+ */
5339
+ const bundleMemo = new Map() // memoKeyOf → { at, html, deps, strict, bytes }
5340
+
5341
+ /**
5342
+ * 留着的打包结果按什么分:哪套设计(目录)、哪个预览服务器、哪一屏哪一版。
5343
+ * 不含 fresh:强刷只管这次走不走网络,取回来的照样盖掉同一个条目
5344
+ */
5345
+ function memoKeyOf(href, r) {
5346
+ let o = ''
5347
+ try { o = new URL(href).origin } catch { return '' }
5348
+ const u = bundleOf(href, r.sid, false)
5349
+ return u ? `${r.root || ''}|${o}|${u}` : ''
5350
+ }
5351
+ let bundleMemoBytes = 0
5352
+ // 上限按「字符串长度」算,而 JS 里中文占两个字节:16M 字符最坏也就 32MB 左右,
5353
+ // 够画布一屏加来回切;再大手机上容易被 iOS Safari 当内存压力杀掉标签页
5354
+ const BUNDLE_MEMO_BYTES = 16 * 1024 * 1024
5355
+ const BUNDLE_MEMO_MAX = 12
5356
+
5357
+ function memoDrop(url) {
5358
+ const e = bundleMemo.get(url)
5359
+ if (!e) return
5360
+ bundleMemoBytes -= e.bytes
5361
+ bundleMemo.delete(url)
5362
+ }
5363
+
5364
+ // 回包能不能写进来:每发一次请求、每次作废都记一个递增的号。作废(强刷、退回旧版)之前发出去的请求,
5365
+ // 回得再晚也不许写——画布和单页、多尺寸三档同时挂着同一屏,旧请求晚到会把强刷刚换上的新内容盖回去
5366
+ let memoTick = 0
5367
+ let memoFloorAll = 0
5368
+ const memoFloor = new Map() // 键 → 这个键最近一次作废时的号
5369
+ const memoTicket = () => ++memoTick
5370
+ function memoInvalidate(key) {
5371
+ memoDrop(key)
5372
+ memoFloor.set(key, ++memoTick)
5373
+ }
5374
+ /** 全部作废(退回旧版:信任可能变了,状态还没轮询到) */
5375
+ function memoReset() {
5376
+ for (const k of [...bundleMemo.keys()]) memoDrop(k)
5377
+ memoFloorAll = ++memoTick
5378
+ }
5379
+ const memoFresh = (key, ticket) => ticket > memoFloorAll && ticket > (memoFloor.get(key) || 0)
5380
+ // 键 → 在途强刷的票号。它回来之前又发出去的普通请求,可能先到服务端、拿到强刷要换掉的那份旧包,回得还更晚:不许写
5381
+ const memoForcing = new Map()
5382
+
5383
+ function memoGet(url, at) {
5384
+ const e = bundleMemo.get(url)
5385
+ if (!e || e.at !== at) return null
5386
+ bundleMemo.delete(url) // 挪到队尾,当 LRU 用
5387
+ bundleMemo.set(url, e)
5388
+ return e
5389
+ }
5390
+
5391
+ function memoPut(url, at, html, deps, strict) {
5392
+ memoDrop(url)
5393
+ const bytes = html.length
5394
+ if (bytes > BUNDLE_MEMO_BYTES) return
5395
+ bundleMemo.set(url, { at, html, deps, strict, bytes })
5396
+ bundleMemoBytes += bytes
5397
+ while (bundleMemo.size > BUNDLE_MEMO_MAX || bundleMemoBytes > BUNDLE_MEMO_BYTES) {
5398
+ const oldest = bundleMemo.keys().next()
5399
+ if (oldest.done) break
5400
+ memoDrop(oldest.value)
5401
+ }
5267
5402
  }
5268
5403
 
5269
5404
  function Screen(props) {
@@ -5314,7 +5449,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
5314
5449
  checkClear: () => { if (curRef.current) postTo(curRef.current, { type: 'checkClear' }) },
5315
5450
  annotFocus: (id) => { if (curRef.current) postTo(curRef.current, { type: 'annotFocus', id }) },
5316
5451
  annotPage: () => life.current.pageOf.get(curRef.current) || '', // 这一帧实际显示的屏(设计里的链接能带走)
5317
- annotHome: (id) => { if (P.current.annotGo) P.current.annotGo.current = id; life.current.at = ''; load(null) }, // 走开了:重新载回这一屏,载好再定位
5452
+ annotHome: (id) => { if (P.current.annotGo) P.current.annotGo.current = id; life.current.at = ''; load(null, true) }, // 走开了:重新载回这一屏,载好再定位
5318
5453
  annotHit: (x, y) => { if (curRef.current) postTo(curRef.current, { type: 'annotHit', x, y }) },
5319
5454
  unpin: () => { if (curRef.current) postTo(curRef.current, { type: 'unpin' }) }, // 去掉「已选」虚线框
5320
5455
  holdScroll: () => { if (curRef.current) postTo(curRef.current, { type: 'holdScroll' }) }, // 用户要在这个位置上画:闪改动别再滚回去
@@ -5344,35 +5479,87 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
5344
5479
  }
5345
5480
  }
5346
5481
 
5347
- // 在后台载一帧新的;正在载就记一笔,等它换上来再载
5348
- const load = (seed) => {
5482
+ // 在后台载一帧新的;正在载就记一笔,等它换上来再载。
5483
+ // force:目录里刚改过(或用户点了刷新)一定要重取;不传就先用留着的打包结果,省一趟往返。
5484
+ const load = (seed, force) => {
5349
5485
  const L = life.current
5350
5486
  if (L.loading) { L.again = true; return }
5351
5487
  const id = L.next++
5352
5488
  L.loading = id
5353
5489
  if (seed) L.seedOf.set(id, seed)
5490
+ clearTimeout(L.retry) // 这次就是最新的一次:之前排着的重试不用了
5354
5491
  const r = remOf(P.current)
5355
5492
  if (r) {
5493
+ if (force) clearTimeout(L.snapTimer) // 这次就是强取:刷新排着的兜底不用再取一次
5356
5494
  const gen = L.gen
5357
- fetch(bundleOf(L.at || P.current.src, r.sid), { credentials: 'same-origin', cache: 'no-store' })
5495
+ // 重试只排一个(新的加载、换页、卸载、信任变了都会取消它)
5496
+ const retry = (ms) => { clearTimeout(L.retry); L.retry = setTimeout(() => { if (L.gen === gen) load(null, true) }, ms) }
5497
+ const href = L.at || P.current.src
5498
+ // 还不知道信任指纹(老状态、刚打开)就不用也不存
5499
+ const mk = r.trust ? memoKeyOf(href, r) : ''
5500
+ const at = `${r.at || 0}:${r.trust}`
5501
+ // 同一屏有强刷还在途:这次也强取。普通请求可能先到服务端、拿到强刷要换掉的那份旧包
5502
+ const forced = !!force || (!!mk && memoForcing.has(mk))
5503
+ const url = bundleOf(href, r.sid, forced)
5504
+ if (forced && mk) memoInvalidate(mk) // 要真的重取:留着的那份不再信,取不回来也别再拿它顶
5505
+ const had = forced || !mk ? null : memoGet(mk, at)
5506
+ const ticket = memoTicket()
5507
+ let settleTimer = null
5508
+ let expired = false
5509
+ const settle = () => { clearTimeout(settleTimer); if (memoForcing.get(mk) === ticket) memoForcing.delete(mk) }
5510
+ if (forced && mk) {
5511
+ memoForcing.set(mk, ticket)
5512
+ // 挂死的请求别一直占着「在途强刷」的标记;过了这个点它的回包再到也不许写缓存(期间别的请求可能已经写了更新的)
5513
+ settleTimer = setTimeout(() => { expired = true; settle() }, 60000)
5514
+ }
5515
+ let origin0 = ''
5516
+ try { origin0 = new URL(href).origin } catch { /* 键已经是空的 */ }
5517
+ if (had) {
5518
+ L.deps = had.deps
5519
+ L.fails = 0
5520
+ setFailed(false)
5521
+ setFrames((fs) => [...fs, { id, doc: had.html, strict: !!had.strict }])
5522
+ return
5523
+ }
5524
+ // no-cache:每次都问一句「还是那份吗」,没变就 304,body 不用再传(远程访问省的就是这个)
5525
+ fetch(url, { credentials: 'same-origin', cache: 'no-cache' })
5358
5526
  .then((res) => res.json().then((d) => {
5359
5527
  if (!res.ok || !d || typeof d.html !== 'string') throw new Error((d && d.error) || `HTTP ${res.status}`)
5360
5528
  return d
5361
5529
  }))
5362
5530
  .then((d) => {
5531
+ settle()
5363
5532
  if (L.gen !== gen || L.loading !== id) return
5533
+ // 请求发出后「哪些算别人做的」变了(这一屏可能从此要加硬规矩):这份不显示也不存,按现在的信任重取。
5534
+ // 回来的不是请求时的目标(服务端打包的是它那时的目标:会话换了目录、预览服务器换了端口):同样不要,
5535
+ // 过一会儿重取(状态轮询追上后换页 effect 也会重载);几回都对不上就当没取回来
5536
+ const now = remOf(P.current)
5537
+ const same = d.root === r.root && d.origin === origin0
5538
+ const moved = !now || now.trust !== r.trust
5539
+ if (moved || !same) {
5540
+ L.loading = 0
5541
+ L.again = false
5542
+ if (moved) { retry(0); return }
5543
+ L.stale = (L.stale || 0) + 1
5544
+ if (L.stale <= 3) retry(300 * L.stale)
5545
+ else if (!curRef.current) setFailed(true)
5546
+ return
5547
+ }
5548
+ L.stale = 0
5364
5549
  L.deps = Array.isArray(d.deps) ? d.deps : null
5365
5550
  L.fails = 0
5366
5551
  setFailed(false)
5552
+ if (mk && !expired && memoFresh(mk, ticket)) memoPut(mk, at, d.html, L.deps, !!d.strict)
5367
5553
  setFrames((fs) => [...fs, { id, doc: d.html, strict: !!d.strict }])
5368
5554
  })
5369
5555
  .catch(() => {
5556
+ settle()
5370
5557
  if (L.gen !== gen || L.loading !== id) return
5371
5558
  L.loading = 0
5372
5559
  if (!curRef.current) setFailed(true)
5373
5560
  // 没取回来:那次改动还没显示出来,过一会儿再试(最多三回),别等下一次改动
5374
5561
  L.fails = (L.fails || 0) + 1
5375
- if (L.again || L.fails <= 3) { L.again = false; setTimeout(() => { if (L.gen === gen) load(null) }, 1500 * Math.min(L.fails, 3)) }
5562
+ if (L.again || L.fails <= 3) { L.again = false; retry(1500 * Math.min(L.fails, 3)) }
5376
5563
  })
5377
5564
  return
5378
5565
  }
@@ -5441,9 +5628,53 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
5441
5628
  setCur(0)
5442
5629
  setFrames([])
5443
5630
  setFailed(false)
5444
- if (src) setTimeout(() => load(null), 0)
5631
+ L.stale = 0
5632
+ clearTimeout(L.first)
5633
+ clearTimeout(L.snapTimer) // 上一页等着的刷新、重试别落到这一页
5634
+ clearTimeout(L.retry)
5635
+ const g = L.gen
5636
+ if (src) L.first = setTimeout(() => { if (L.gen === g) load(null) }, 0)
5445
5637
  }, [src, !!rem])
5446
5638
 
5639
+ // 卸载:还没回来的请求、等着的刷新都作废(别在没人看的时候再去取、再写缓存)
5640
+ useEffect(() => () => {
5641
+ const L = life.current
5642
+ L.gen++
5643
+ clearTimeout(L.snapTimer)
5644
+ clearTimeout(L.first)
5645
+ clearTimeout(L.retry)
5646
+ }, [])
5647
+
5648
+ // 远程看:「哪些算别人做的」变了(别的会话退回了旧版、装了设计)——文件没动,但这一屏可能从此要加硬规矩,重取一次
5649
+ const trust = rem ? rem.trust || '' : ''
5650
+ const trustSeen = useRef(trust)
5651
+ useEffect(() => {
5652
+ const was = trustSeen.current
5653
+ if (trust) trustSeen.current = trust
5654
+ if (!trust || trust === was) return
5655
+ // 在途的请求、已经加进来还没换上的帧,都是按旧信任打的包:作废(回包会被拒收)、撤掉,再按新信任重取。
5656
+ // 正在显示的那帧:加了规矩的留到新的一帧换上来(别闪一下空白,重取有 400ms 兜底,不靠页面回话);
5657
+ // 没加规矩的立刻撤下(它里面的脚本别再跑),空着等新的一帧,取不回来就显示「没取回来」
5658
+ const L = life.current
5659
+ L.gen++
5660
+ L.loading = 0
5661
+ L.again = false
5662
+ L.fails = 0 // 新一轮按新信任取:重试次数从头算
5663
+ L.stale = 0
5664
+ clearTimeout(L.snapTimer)
5665
+ clearTimeout(L.retry)
5666
+ const shown = frames.find((f) => f.id === curRef.current)
5667
+ if (shown && typeof shown.doc === 'string' && shown.strict) {
5668
+ setFrames((fs) => fs.filter((f) => f.id <= curRef.current))
5669
+ refresh()
5670
+ return
5671
+ }
5672
+ curRef.current = 0
5673
+ setCur(0)
5674
+ setFrames([])
5675
+ load(null, true)
5676
+ }, [trust])
5677
+
5447
5678
  // 页面发来的消息(几屏共用一个源,按 iframe 认是不是自己的)
5448
5679
  useEffect(() => {
5449
5680
  const on = (e) => {
@@ -5518,10 +5749,10 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
5518
5749
  if (isCur && p.onTop) p.onTop(!!d.dark)
5519
5750
  break
5520
5751
  case 'changed':
5521
- if (isCur) { L.file = d.file || L.file; load(d.seed) }
5752
+ if (isCur) { L.file = d.file || L.file; load(d.seed, true) }
5522
5753
  break
5523
5754
  case 'snap':
5524
- if (isCur) { clearTimeout(L.snapTimer); load(d.seed) }
5755
+ if (isCur) { clearTimeout(L.snapTimer); load(d.seed, true) }
5525
5756
  break
5526
5757
  case 'bye':
5527
5758
  if (isCur) L.seeds.set(id, d.seed)
@@ -5594,18 +5825,21 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
5594
5825
  if (cur) postTo(cur, { type: 'edit', on: !!props.textEdit, hint: false })
5595
5826
  }, [!!props.textEdit])
5596
5827
 
5597
- // 刷新:先问当前这帧要滚动位置和指纹,问不到就直接载
5828
+ // 刷新:先问当前这帧要滚动位置和指纹,问不到就直接载(这里是「真的重取」,不吃留着的打包结果)
5598
5829
  const refresh = () => {
5599
5830
  const L = life.current
5600
- if (!curRef.current) { load(null); return }
5831
+ if (!curRef.current) { load(null, true); return }
5601
5832
  clearTimeout(L.snapTimer)
5602
- L.snapTimer = setTimeout(() => load(null), 400)
5833
+ L.snapTimer = setTimeout(() => load(null, true), 400)
5603
5834
  postTo(curRef.current, { type: 'snapshot' })
5604
5835
  }
5605
5836
  const seq = useRef(props.reloadSeq)
5606
5837
  useEffect(() => {
5607
5838
  if (seq.current === props.reloadSeq) return
5608
5839
  seq.current = props.reloadSeq
5840
+ const L = life.current
5841
+ L.fails = 0 // 用户点的刷新:重试次数从头算
5842
+ L.stale = 0
5609
5843
  refresh()
5610
5844
  }, [props.reloadSeq])
5611
5845
 
@@ -7603,34 +7837,132 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7603
7837
  const [agree, setAgree] = useState({})
7604
7838
  const [res, setRes] = useState(null)
7605
7839
  const [busy, setBusy] = useState(false)
7840
+ const packSeq = useRef(0) // 每次查、每次换作品都加一:晚到的回包对不上就不认(不然 B 的面板会拿到 A 的包去投)
7841
+ const edited = useRef({}) // 用户自己改过的栏:预填回来不覆盖
7606
7842
  useEffect(() => {
7843
+ // 换了作品:上一套填的名字、介绍、授权和四个确认都不带过来,等这一套的预填
7844
+ packSeq.current++
7845
+ edited.current = {}
7846
+ setBusy(false)
7607
7847
  setRes(null)
7608
7848
  setInfo(null)
7849
+ setTitle('')
7850
+ setDesc('')
7851
+ setLic('CC0-1.0')
7852
+ setAgree({})
7609
7853
  if (!root) return undefined
7610
7854
  let on = true
7855
+ const my = packSeq.current
7611
7856
  post('pack', { session: sid, dir: root, info: true, lang: L }).then((d) => {
7612
- if (!on) return
7857
+ if (!on || packSeq.current !== my) return // 预填晚到、用户已经点了检查:不改正在查的表单
7613
7858
  setInfo(d)
7614
- setTitle(d.title && d.title !== baseName(root) ? d.title : brand || d.title || '')
7615
- setDesc(d.description || '')
7616
- setLic(d.license === 'CC-BY-4.0' ? 'CC-BY-4.0' : 'CC0-1.0')
7617
- }, (e) => { if (on) setInfo({ error: e.message }) })
7859
+ if (!edited.current.title) setTitle(d.title && d.title !== baseName(root) ? d.title : brand || d.title || '')
7860
+ if (!edited.current.desc) setDesc(d.description || '')
7861
+ if (!edited.current.lic) setLic(d.license === 'CC-BY-4.0' ? 'CC-BY-4.0' : 'CC0-1.0')
7862
+ }, (e) => { if (on && packSeq.current === my) setInfo({ error: e.message }) })
7618
7863
  return () => { on = false }
7619
7864
  }, [root])
7620
- const ready = !!root && !!title.trim() && !!desc.trim() && SHARE_AGREE.every(([k]) => agree[k])
7865
+ // 预填回来之前不能查(不然用的是没对上这一套的表单)
7866
+ const ready = !!root && !!info && !!title.trim() && !!desc.trim() && SHARE_AGREE.every(([k]) => agree[k])
7621
7867
  const go = async () => {
7868
+ const my = ++packSeq.current
7622
7869
  setBusy(true)
7623
7870
  setRes(null)
7624
- try { setRes(await post('pack', { session: sid, dir: root, share: true, title: title.trim(), description: desc.trim(), license: lic, agree, lang: L })) } catch (e) { setRes({ error: e.message }) } finally { setBusy(false) }
7871
+ setLost(false)
7872
+ let r
7873
+ try { r = await post('pack', { session: sid, dir: root, share: true, title: title.trim(), description: desc.trim(), license: lic, agree, lang: L }) } catch (e) { r = { error: e.message } }
7874
+ if (packSeq.current !== my) return
7875
+ setRes(r)
7876
+ setBusy(false)
7625
7877
  }
7626
7878
  const formUrl = (r) => {
7627
- const q = new URLSearchParams({ template: 'submit-design.yml', title: `投稿 / Submission: ${r.share.title || title.trim()} · ${r.share.ref}`, license: FORM_LIC[lic] })
7879
+ const q = new URLSearchParams({ template: 'submit-design.yml', title: `投稿 / Submission: ${r.share.title || title.trim()} · ${r.share.ref}`, license: FORM_LIC[r.share.license] || FORM_LIC[lic] })
7628
7880
  if (r.share.slug) q.set('slug', r.share.slug)
7629
7881
  return `${GALLERY_REPO}/issues/new?${q}`
7630
7882
  }
7631
7883
  const aiN = (res && res.aiPhotos) || 0
7632
7884
  const fixed = res && res.notes ? Object.entries(res.notes.reduce((m, n) => { m[n.code] = (m[n.code] || 0) + 1; return m }, {})).map(([k, n]) => t('pkNote_' + k, { n })).join(t('sep')) : ''
7633
7885
  const done = res && res.ok && res.share
7886
+ // 一键投稿:连 GitHub(设备授权,输个码)→ 插件替你放 zip、开投稿 issue;不想连的走网页表单
7887
+ const [gh, setGh] = useState(null)
7888
+ const [ghBusy, setGhBusy] = useState(false)
7889
+ const [sub, setSub] = useState(null) // { busy } / { url } / { error, msg }
7890
+ const [manual, setManual] = useState(false)
7891
+ const [lost, setLost] = useState(false) // 打好的包找不到了(插件重启过、zip 被删了):回到表单重新查
7892
+ const resNow = useRef(res) // 投稿回来时核对:还是投的那个包(中间换了作品、重新查过就不认这次的回包)
7893
+ resNow.current = res
7894
+ useEffect(() => { setSub(null); setManual(false) }, [res])
7895
+ const ghSeq = useRef(0) // 连、取消、断开、投稿发现授权失效都加一:之前发出去还没回来的查状态作废(不然断开后又显示连着)
7896
+ useEffect(() => {
7897
+ if (!done) return undefined
7898
+ let on = true
7899
+ const my = ghSeq.current
7900
+ getJson('ghauth').then((s) => { if (on && ghSeq.current === my) setGh(s) }, () => { if (on && ghSeq.current === my) setGh({ ready: false }) })
7901
+ return () => { on = false }
7902
+ }, [done])
7903
+ const waiting = !!(gh && gh.flow && !gh.flow.error && !gh.login)
7904
+ useEffect(() => {
7905
+ if (!waiting) return undefined
7906
+ let on = true
7907
+ const id = setInterval(() => {
7908
+ const my = ghSeq.current
7909
+ getJson('ghauth').then((s) => { if (on && ghSeq.current === my) setGh(s) }, () => {})
7910
+ }, 2500)
7911
+ return () => { on = false; clearInterval(id) }
7912
+ }, [waiting])
7913
+ const ghOp = async (op) => {
7914
+ const my = ++ghSeq.current
7915
+ setGhBusy(true)
7916
+ try {
7917
+ const s = await post('ghauth', { op })
7918
+ if (ghSeq.current === my) setGh(s)
7919
+ } catch (e) {
7920
+ if (ghSeq.current === my) setGh((g) => ({ ...(g || {}), ready: true, login: '', flow: { error: e.message } }))
7921
+ } finally { setGhBusy(false) }
7922
+ }
7923
+ const submit = async () => {
7924
+ const mine = res
7925
+ const still = () => resNow.current === mine
7926
+ setSub({ busy: true })
7927
+ try {
7928
+ const r = await fetch(API + 'submit', { method: 'POST', credentials: 'same-origin', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ path: mine.path, login: (gh && gh.login) || '' }) })
7929
+ const d = await r.json().catch(() => ({}))
7930
+ if (!still()) return
7931
+ if (r.ok && d.url) setSub({ url: d.url })
7932
+ else if (d.error === 'notShared') { setLost(true); setRes(null) }
7933
+ else {
7934
+ setSub({ error: d.error || 'net', msg: d.msg || '' })
7935
+ if (d.error === 'auth') { ghSeq.current++; setGh((g) => ({ ...(g || {}), login: '', flow: null })) }
7936
+ // 别的窗口换了账号:面板换成现在连着的那个,用户看清楚再点
7937
+ if (d.error === 'who') { ghSeq.current++; setGh((g) => ({ ...(g || {}), login: d.msg || '', flow: null })) }
7938
+ }
7939
+ } catch { if (still()) setSub({ error: 'net' }) }
7940
+ }
7941
+ const ghErr = (code) => t(['denied', 'expired', 'net', 'noApp'].includes(code) ? 'shGhErr_' + code : 'shGhErr_device')
7942
+ const subErr = (s) => t(['auth', 'net', 'big', 'notShared', 'busy', 'who'].includes(s.error) ? 'shSubErr_' + s.error : 'shSubErr_api', { msg: s.msg || s.error })
7943
+ const canOne = !!(gh && gh.ready)
7944
+ const steps = h('div', { className: 'steps' },
7945
+ h('p', null, t('shSteps')),
7946
+ h('ol', null, h('li', null, t('shStep1')), h('li', null, t('shStep2')), h('li', null, t('shStep3'))),
7947
+ h('a', { className: 'lk', href: done ? formUrl(res) : '#', target: '_blank', rel: 'noopener noreferrer' }, t('shOpen')))
7948
+ const oneClick = !done || !canOne ? null : sub && sub.url
7949
+ ? h('div', { className: 'okbox' }, h('div', null, h(I.check), h('span', null, t('shSubmitted'))), h('a', { className: 'lk', href: sub.url, target: '_blank', rel: 'noopener noreferrer' }, t('shSubmittedLink')))
7950
+ : h('div', { className: 'steps gh1' },
7951
+ gh.login
7952
+ ? h('p', null, t('shGhAs', { login: gh.login }), ' ', h('button', { className: 'lk', disabled: !!(sub && sub.busy), onClick: () => ghOp('logout') }, t('shGhLogout')))
7953
+ : waiting
7954
+ ? [
7955
+ h('p', { key: 'c' }, t('shGhCode')),
7956
+ h('p', { key: 'v', className: 'code' }, h('b', null, gh.flow.code), ' ', h('button', { className: 'lk', onClick: () => { try { navigator.clipboard.writeText(gh.flow.code).catch(() => {}) } catch { /* 能选中自己复制 */ } } }, t('shGhCopy'))),
7957
+ h('p', { key: 'o' }, h('a', { className: 'lk', href: gh.flow.uri, target: '_blank', rel: 'noopener noreferrer' }, t('shGhOpen')), ' · ', h('button', { className: 'lk', onClick: () => ghOp('cancel') }, t('shGhCancel'))),
7958
+ h('p', { key: 'w', className: 'note' }, t('shGhWaiting')),
7959
+ ]
7960
+ : [
7961
+ h('p', { key: 'y' }, t('shGhWhy')),
7962
+ gh.flow && gh.flow.error ? h('p', { key: 'e', className: 'note' }, ghErr(gh.flow.error)) : null,
7963
+ ],
7964
+ sub && sub.busy ? h('p', { className: 'note' }, t('shSubmitting')) : null,
7965
+ sub && sub.error ? h('p', { className: 'note' }, subErr(sub)) : null)
7634
7966
  return h('div', { className: 'ddp-tokens ddp-pack ddp-share', onPointerDown: (e) => e.stopPropagation() },
7635
7967
  h('header', null, h(I.share), h('b', null, t('shTitle')), h('button', { className: 'ddp-btn', title: '×', onClick: onClose }, h(I.close))),
7636
7968
  h('p', { className: 'tip gh' }, h(I.info), h('span', null, t('shGh'))),
@@ -7640,25 +7972,27 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7640
7972
  info && info.error ? h('div', { className: 'none' }, info.error === 'noScreens' ? t('pkNoDesign') : t('libFail', { msg: info.error })) : null,
7641
7973
  done ? null : [
7642
7974
  h('h4', { key: 'n' }, t('shName')),
7643
- h('input', { key: 'ni', className: 'who', value: title, maxLength: 24, 'aria-label': t('shName'), onChange: (e) => setTitle(e.target.value) }),
7975
+ h('input', { key: 'ni', className: 'who', value: title, maxLength: 24, disabled: busy, 'aria-label': t('shName'), onChange: (e) => { edited.current.title = true; setTitle(e.target.value) } }),
7644
7976
  h('h4', { key: 'd' }, t('shDesc')),
7645
- h('input', { key: 'di', className: 'who', value: desc, maxLength: 120, placeholder: t('shDescPh'), 'aria-label': t('shDesc'), onChange: (e) => setDesc(e.target.value) }),
7977
+ h('input', { key: 'di', className: 'who', value: desc, maxLength: 120, disabled: busy, placeholder: t('shDescPh'), 'aria-label': t('shDesc'), onChange: (e) => { edited.current.desc = true; setDesc(e.target.value) } }),
7646
7978
  h('h4', { key: 'l' }, t('pkLicense')),
7647
7979
  h('div', { key: 'li', className: 'lic' }, ...[['CC0-1.0', 'pkCC0'], ['CC-BY-4.0', 'pkBY']].map(([k, label]) => h('label', { key: k, className: lic === k ? 'on' : '' },
7648
- h('input', { type: 'radio', name: 'ddp-shlic', checked: lic === k, onChange: () => setLic(k) }), h('span', null, t(label))))),
7980
+ h('input', { type: 'radio', name: 'ddp-shlic', checked: lic === k, disabled: busy, onChange: () => { edited.current.lic = true; setLic(k) } }), h('span', null, t(label))))),
7649
7981
  lic === 'CC-BY-4.0' ? h('p', { key: 'by', className: 'note' }, t('shBYNote')) : null,
7650
7982
  h('div', { key: 'ag', className: 'agree' }, ...SHARE_AGREE.map(([k, label]) => h('label', { key: k },
7651
- h('input', { type: 'checkbox', checked: !!agree[k], onChange: (e) => setAgree((a) => ({ ...a, [k]: e.target.checked })) }), h('span', null, t(label))))),
7983
+ h('input', { type: 'checkbox', checked: !!agree[k], disabled: busy, onChange: (e) => setAgree((a) => ({ ...a, [k]: e.target.checked })) }), h('span', null, t(label))))),
7652
7984
  ],
7653
7985
  busy ? h('div', { className: 'none' }, t('shChecking')) : null,
7986
+ lost && !res && !busy ? h('p', { className: 'note' }, t('shSubErr_notShared')) : null,
7654
7987
  res && res.error ? h('div', { className: 'none' }, res.error === 'noScreens' ? t('pkNoDesign') : t('libFail', { msg: res.error })) : null,
7655
7988
  done ? h('div', { className: 'okbox' },
7656
7989
  h('div', null, h(I.check), h('span', null, t('shOk', { name: baseName(res.path) }))),
7657
7990
  h('button', { className: 'lk', onClick: () => post('reveal', { path: res.path }).catch(() => {}) }, t('pkReveal'))) : null,
7658
- done ? h('div', { className: 'steps' },
7659
- h('p', null, t('shSteps')),
7660
- h('ol', null, h('li', null, t('shStep1')), h('li', null, t('shStep2')), h('li', null, t('shStep3'))),
7661
- h('p', { className: 'note' }, t('shAfter', { ref: res.share.ref }))) : null,
7991
+ done && res.share.license ? h('p', { className: 'note' }, h('b', null, t('pkLicense')), ' ', t(res.share.license === 'CC-BY-4.0' ? 'pkBY' : 'pkCC0')) : null,
7992
+ oneClick,
7993
+ done && (!canOne || manual) && !(sub && sub.url) ? steps : null,
7994
+ done && canOne && !manual && !(sub && sub.url) ? h('button', { className: 'lk', onClick: () => setManual(true) }, t('shManual')) : null,
7995
+ done ? h('p', { className: 'note' }, t('shAfter', { ref: res.share.ref })) : null,
7662
7996
  res && res.ok === false ? h('div', { className: 'errs' },
7663
7997
  h('p', null, t('pkFail', { n: res.errors.length + (res.more || 0) })),
7664
7998
  h('ol', null, ...res.errors.slice(0, 30).map((e, i) => h('li', { key: i }, e.msg))),
@@ -7669,9 +8003,14 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7669
8003
  res.flags.length > 8 || res.flagsMore ? h('p', null, t('pkMore', { n: res.flags.length - 8 + (res.flagsMore || 0) })) : null) : null),
7670
8004
  h('footer', { className: 'row' },
7671
8005
  res && res.ok === false ? h('button', { onClick: () => onFix(res.errors) }, h('span', null, t('pkFix'))) : null,
7672
- done
7673
- ? h('a', { className: 'go', href: formUrl(res), target: '_blank', rel: 'noopener noreferrer' }, h('span', null, t('shOpen')))
7674
- : h('button', { className: 'go', disabled: busy || !ready, onClick: go }, h('span', null, t(res && res.ok === false ? 'shAgain' : 'shGo')))))
8006
+ !done
8007
+ ? h('button', { className: 'go', disabled: busy || !ready, onClick: go }, h('span', null, t(res && res.ok === false ? 'shAgain' : 'shGo')))
8008
+ : !gh ? null
8009
+ : !canOne ? h('a', { className: 'go', href: formUrl(res), target: '_blank', rel: 'noopener noreferrer' }, h('span', null, t('shOpen')))
8010
+ : sub && sub.url ? null
8011
+ : gh.login ? h('button', { className: 'go', disabled: !!(sub && sub.busy), onClick: submit }, h('span', null, t(sub && sub.busy ? 'shSubmittingShort' : 'shSubmit')))
8012
+ : waiting ? null
8013
+ : h('button', { className: 'go', disabled: ghBusy, onClick: () => ghOp('start') }, h('span', null, t('shGhConnect')))))
7675
8014
  }
7676
8015
 
7677
8016
  /** 拖进来的设计包没过检查:说清哪几条 */
@@ -7699,6 +8038,62 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7699
8038
  }
7700
8039
  }
7701
8040
 
8041
+ /**
8042
+ * 睡着的屏的缩略图(issue #17):用 fetch 取,顺手从响应头拿到页面标题(onTitle);
8043
+ * 屏醒了、不显示了就取消请求(服务端排着队的那张也就不截了)。地址变了先留着旧图,新图到了再换(还是同一张就不换)
8044
+ */
8045
+ function Snap({ src, onTitle, blind }) {
8046
+ const [url, setUrl] = useState('')
8047
+ const cur = useRef('')
8048
+ const shown = useRef('') // 现在显示的是服务端的哪张
8049
+ const titleTo = useRef(onTitle)
8050
+ titleTo.current = onTitle
8051
+ useEffect(() => {
8052
+ if (!src) return undefined
8053
+ const ac = new AbortController()
8054
+ let tries = 0
8055
+ let timer = 0
8056
+ // 目录没在监听(改了不会通知、地址不会变):隔这么久自己再要,直到服务端说在监听了。
8057
+ // 页面状态已经说没在监听(blind)的,一开始就按这个节奏,免得头几下没要到就断了
8058
+ let poll = blind ? 10_000 : 0
8059
+ const later = (ms) => { clearTimeout(timer); if (!ac.signal.aborted) timer = setTimeout(go, ms) }
8060
+ // 没要到(503:浏览器忙不过来、会话刚恢复预览还没起来…;断网;图传了一半断了):过一会儿再要两次,还不行就按定时再要的节奏接着要
8061
+ const fail = () => {
8062
+ if (ac.signal.aborted) return
8063
+ if (tries < 2) later(++tries * 2500)
8064
+ else if (poll) later(poll)
8065
+ }
8066
+ const done = (title) => {
8067
+ tries = 0
8068
+ if (poll) later(poll)
8069
+ try { if (titleTo.current) titleTo.current(title) } catch { /* 无所谓 */ } // 空的也报:标题删了就回到文件名
8070
+ }
8071
+ const go = () => fetch(src, { credentials: 'same-origin', cache: 'no-store', signal: ac.signal }).then(async (r) => {
8072
+ if (ac.signal.aborted) return
8073
+ if (r.status >= 500) return fail()
8074
+ if (!r.ok) return
8075
+ poll = (Number(r.headers.get('X-Dsh-Recheck')) || 0) * 1000
8076
+ let title = ''
8077
+ try { title = decodeURIComponent(r.headers.get('X-Dsh-Title') || '') } catch { title = '' }
8078
+ const name = r.headers.get('X-Dsh-Thumb') || ''
8079
+ if (name && name === shown.current) { try { r.body && r.body.cancel() } catch { /* 无所谓 */ } return done(title) }
8080
+ const blob = await r.blob()
8081
+ if (ac.signal.aborted) return
8082
+ if (!blob.size) return fail()
8083
+ shown.current = name
8084
+ const old = cur.current
8085
+ cur.current = URL.createObjectURL(blob)
8086
+ setUrl(cur.current)
8087
+ if (old) setTimeout(() => URL.revokeObjectURL(old), 1000)
8088
+ done(title)
8089
+ }).catch(fail)
8090
+ go()
8091
+ return () => { ac.abort(); clearTimeout(timer) }
8092
+ }, [src])
8093
+ useEffect(() => () => { if (cur.current) URL.revokeObjectURL(cur.current) }, [])
8094
+ return url ? h('img', { className: 'ddp-snap', src: url, alt: '', draggable: false, decoding: 'async', onLoad: (e) => e.currentTarget.classList.add('on') }) : null
8095
+ }
8096
+
7702
8097
  function Canvas(props) {
7703
8098
  const { t, screens, kind, size, ghost, picking, sel, labelOf } = props
7704
8099
  const ref = useRef(null)
@@ -7715,10 +8110,12 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7715
8110
  const f = FRAME[kind] || FRAME.web
7716
8111
  const [dw, dh] = deviceBox(kind, size)
7717
8112
  const n = screens.length + (ghost ? 1 : 0)
7718
- const heavy = !props.items && screens.length > HEAVY_N
7719
- const heavyRef = useRef(heavy)
7720
- heavyRef.current = heavy
7721
8113
  const worldRef = useRef(null)
8114
+ // 画面上现在的倍率(镜头提交、拖宽度直接写画布时更新)
8115
+ const shownZ = useRef(0)
8116
+ // 镜头换到倍率 nz 时做不做过渡:只有平移做,倍率一变就直接到位(屏多屏少都一样)。
8117
+ // 缩放过渡途中浏览器会按很大的清晰度画整片画布,几屏就能把显存吃满,缺块、后面的对话透上来(issue #18)
8118
+ const glides = (nz) => nz === shownZ.current
7722
8119
  // 多尺寸:每块自己的类型和大小(items[i] = { kind, size })
7723
8120
  const items = props.items || null
7724
8121
  const boxes = items ? items.map((it) => deviceBox(it.kind, it.size)) : null
@@ -7731,8 +8128,9 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7731
8128
  const vw = box.w - ins
7732
8129
  const layoutKey = L ? [n, L.cols, dw, dh, box.w, box.h, rt, bh, ins, boxes ? boxes.join(';') : ''].join('|') : ''
7733
8130
  const fitAt = () => { const c = fitCam(L, vw, bh); return { ...c, y: c.y + rt } }
7734
- // 屏多时拖宽度:新镜头直接写到画布上,不走 React,也不动 --z,这样既跟手又不让 iframe 每帧重绘。
7735
- // 列数变了(或者松手了)才真重排:先记下每格现在在屏幕上的样子,镜头和格子一次换好,再从记下的样子滑过去,中间没有哪一帧会跳。返回有没有真重排
8131
+ // 拖宽度(屏多屏少都一样):新镜头直接写到画布上,不走 React,也不动 --z,这样既跟手又不让 iframe 每帧重绘。
8132
+ // 列数变了(或者松手了)才真重排:先记下每格现在在屏幕上的样子,镜头和格子一次换好,再从记下的样子滑过去,中间没有哪一帧会跳。返回有没有真重排。
8133
+ // 屏少时以前每帧都重排、每帧重开滑动,画面停住还缺块透底(issue #18)
7736
8134
  const followRef = useRef(null)
7737
8135
  const flipFirst = useRef(null)
7738
8136
  const unpinRef = useRef(false)
@@ -7740,7 +8138,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7740
8138
  const sh = Math.max(0, h - rt - (props.bottom || 0))
7741
8139
  const world = worldRef.current
7742
8140
  if (!L || !world || !(w > 0) || !(sh > 0)) { setBox({ w, h }); return false }
7743
- const next = layoutGrid(n, dw, dh, w, sh)
8141
+ const next = boxes ? layoutRow(boxes, w, sh) : layoutGrid(n, dw, dh, w, sh)
7744
8142
  const sw = w - (props.inset && w - props.inset >= 240 ? props.inset : 0)
7745
8143
  if (final || next.cols !== L.cols) {
7746
8144
  if (w === box.w && h === box.h) {
@@ -7757,6 +8155,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7757
8155
  if (auto.current) {
7758
8156
  const c = fitCam({ ...L, z: next.z }, sw, sh)
7759
8157
  liveCam.current = camRef.current = { ...c, y: c.y + rt }
8158
+ shownZ.current = c.z
7760
8159
  world.style.transform = `translate(${c.x}px, ${c.y + rt}px) scale(${c.z})`
7761
8160
  }
7762
8161
  return false
@@ -7793,7 +8192,6 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7793
8192
  const settle = () => { if (followRef.current(el.clientWidth, el.clientHeight, true)) unpinRef.current = true; else pin('') }
7794
8193
  const measure = () => {
7795
8194
  clearTimeout(timer)
7796
- if (!heavyRef.current) { pin(''); apply(); return }
7797
8195
  pin('none') // 拖动时镜头不做过渡:每帧重开过渡正是闪的来源之一
7798
8196
  followRef.current(el.clientWidth, el.clientHeight, false)
7799
8197
  timer = setTimeout(settle, 160)
@@ -7805,7 +8203,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7805
8203
  return () => { clearTimeout(timer); ro.disconnect() }
7806
8204
  }, [])
7807
8205
 
7808
- // 屏多时的换行动画:格子先到新位置,再用 translate 从旧位置滑过来,全程走合成层,不用每帧重新排版 30 个格子
8206
+ // 换行动画:格子先到新位置,再用 translate 从旧位置滑过来,全程走合成层,不用每帧重新排版所有格子
7809
8207
  const flipFrom = useRef(null)
7810
8208
  const flipUntil = useRef(0)
7811
8209
  const SLIDE = { id: 'ddp-flip', duration: 450, easing: EASE }
@@ -7847,7 +8245,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7847
8245
  const first = flipFirst.current
7848
8246
  flipFirst.current = null
7849
8247
  const world = worldRef.current
7850
- if (world && heavy && !reduced()) {
8248
+ if (world && !reduced()) {
7851
8249
  if (first) playFlip(world, first)
7852
8250
  else if (was) {
7853
8251
  // 别的原因重排(加屏、删屏):镜头有自己的过渡,格子只补世界坐标里的差;上一段没滑完就从当前看到的样子接着滑
@@ -7872,9 +8270,10 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7872
8270
  camRef.current = cam
7873
8271
  const world = worldRef.current
7874
8272
  if (!world || !cam) return
8273
+ shownZ.current = cam.z
7875
8274
  world.style.transform = `translate(${cam.x}px, ${cam.y}px) scale(${cam.z})`
7876
8275
  // 标题还在往旧倍率滑的时候镜头又变了:从当前看到的样子改滑向新倍率,别滑完再跳一下
7877
- if (heavy && performance.now() < flipUntil.current) {
8276
+ if (performance.now() < flipUntil.current) {
7878
8277
  for (const el of cellsOf(world)) {
7879
8278
  const lab = labOf(el)
7880
8279
  const run = lab && lab.getAnimations().find((x) => x.id === 'ddp-flip')
@@ -7888,7 +8287,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7888
8287
  const first = flipFirst.current
7889
8288
  if (!first) return
7890
8289
  flipFirst.current = null
7891
- if (heavy && !reduced()) playFlip(world, first)
8290
+ if (!reduced()) playFlip(world, first)
7892
8291
  }, [cam])
7893
8292
 
7894
8293
  // 屏数 / 类型 / 舞台大小变了:用户没自己动过镜头就重新摆好
@@ -7898,8 +8297,8 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7898
8297
  const world = worldRef.current
7899
8298
  const to = fitAt()
7900
8299
  const c = camRef.current
7901
- // 拖着宽度的时候屏数变了:镜头这时不走过渡,和换行一样先记下画面再滑过去
7902
- if (heavy && world && c && world.style.transition === 'none' && (c.x !== to.x || c.y !== to.y || c.z !== to.z)) flipFirst.current = snapStage(ref.current, world)
8300
+ // 镜头这回不走过渡(拖着宽度、或者倍率变了直接到位):和换行一样先记下画面,镜头和格子一起从记下的样子滑过去,别先跳再滑
8301
+ if (world && c && (world.style.transition === 'none' || !glides(to.z)) && (c.x !== to.x || c.y !== to.y || c.z !== to.z)) flipFirst.current = snapStage(ref.current, world)
7903
8302
  setAnim(!!c)
7904
8303
  setCam(to)
7905
8304
  } else if (ins && props.sel) showKey(props.sel) // 自己挪过镜头:只把选中的那屏挪出来,别被面板挡着
@@ -8044,14 +8443,14 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
8044
8443
  }
8045
8444
  }
8046
8445
  return h('div', {
8047
- className: 'ddp-canvas' + (drag ? ' drag' : '') + (heavy ? ' heavy' : ''),
8446
+ className: 'ddp-canvas' + (drag ? ' drag' : ''),
8048
8447
  ref,
8049
8448
  onPointerDown,
8050
8449
  style: cam ? { backgroundSize: `${grid}px ${grid}px`, backgroundPosition: `${cam.x}px ${cam.y}px` } : undefined,
8051
8450
  },
8052
8451
  cam && L ? h('div', {
8053
8452
  ref: worldRef,
8054
- className: 'ddp-world' + (anim ? ' anim' : ''),
8453
+ className: 'ddp-world' + (anim && cam && glides(cam.z) ? ' anim' : ''),
8055
8454
  style: { transform: `translate(${cam.x}px, ${cam.y}px) scale(${z})`, '--z': z },
8056
8455
  }, ...cells, flowSvg) : null,
8057
8456
  // 右下缩放:「43% ▾」,点开是放大 / 缩小 / 适合画布 / 实际大小
@@ -8275,7 +8674,16 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
8275
8674
  const id = setTimeout(() => setTick((n) => n + 1), Math.max(0, M.lastNew + GHOST_MS - Date.now()) + 50)
8276
8675
  return () => clearTimeout(id)
8277
8676
  }, [fresh, writingNew, M.lastNew])
8278
- const labelOf = (sc) => (infoOf(ik(sc)) || {}).title || sc.label
8677
+ // 睡着的屏:标题用缩略图截的时候页面报的(只当显示用,别的都不看它)。它总比右侧栏上回载这屏时记的新
8678
+ // (睡着以后改了名也对;空的也记,标题删了就回到文件名);屏醒了载上来(remember)就清掉,听页面的
8679
+ const [snapTitles, setSnapTitles] = useState({})
8680
+ const snapSite = (tg && tg.kind === 'file' && tg.root) || site // 按目录记:同一套设计里换着看别的文件不丢
8681
+ const snapTitled = (key, title) => setSnapTitles((cur) => (cur[snapSite + '|' + key] === title ? cur : { ...cur, [snapSite + '|' + key]: title }))
8682
+ const labelOf = (sc) => {
8683
+ const snapT = sc.v ? undefined : snapTitles[snapSite + '|' + sc.key]
8684
+ if (snapT !== undefined) return snapT || sc.label
8685
+ return (infoOf(ik(sc)) || {}).title || sc.label
8686
+ }
8279
8687
  // 状态条上那句:在等你回答 / 正在做第几屏 / 正在改哪屏 / 按调的工具说 / 没调工具就是在想
8280
8688
  const busyPhase = () => {
8281
8689
  if (!st) return { text: t('working') }
@@ -8310,7 +8718,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
8310
8718
  const curRoot = fileTarget ? st.target.root : ''
8311
8719
  useEffect(() => { setPackDir('') }, [curRoot]) // 换了设计:打包面板跟着现在这套
8312
8720
  // 远程看(手机走外网等):本地文件的预览由服务端打包传过来(见 Screen),目录里改了哪些文件也一起带过去
8313
- const remote = fileTarget && sid ? { sid, at: st.changedAt || 0, files: st.changedFiles || [], changes: st.changes || [] } : null
8721
+ const remote = fileTarget && sid ? { sid, root: curRoot, at: st.changedAt || 0, trust: st.trust || '', files: st.changedFiles || [], changes: st.changes || [] } : null
8314
8722
 
8315
8723
  // 调节滑块:tweaks.json 改了(写回了、模型改了)就把和文件一样的值放掉;换了设计全放掉
8316
8724
  const tweaks = (fileTarget && st.tweaks) || null
@@ -8435,6 +8843,8 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
8435
8843
  const remember = (key, m, title, toks, dk, links, nat) => {
8436
8844
  if (pane === 'export') setLoadTick((n) => n + 1)
8437
8845
  const k = site + '|' + key
8846
+ const sk = snapSite + '|' + key
8847
+ if (!/^v\d+\|/.test(key)) setSnapTitles((cur) => { if (!(sk in cur)) return cur; const next = { ...cur }; delete next[sk]; return next })
8438
8848
  const sig = JSON.stringify([toks || [], links || []])
8439
8849
  setInfo((cur) => {
8440
8850
  const natural = nat === 0 ? null : nat || (cur[k] && cur[k].natural) || null // 画幅放大后页面正好撑满、报空:还按上回量的;0 是这页不再是一整块:清掉
@@ -8760,9 +9170,15 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
8760
9170
  onBuilt: (title) => onBuilt(sc, title),
8761
9171
  }))
8762
9172
 
8763
- // 画布上屏太多、离镜头远的:先不挂 iframe,放个占位
9173
+ // 画布上屏太多、离镜头远的:先不挂 iframe,放一张后台截的缩略图(issue #17),截不到就是「挪近就加载」。
9174
+ // 本地文件的设计才有图(开发服务器的页面不在后台另开);看旧版本时也没有。目录里一有改动地址就变,没变的那几屏服务端直接给缓存。
9175
+ // 地址带上目录:换了设计服务端就不给(晚到的回包也不会把上一套的图挂到这套上);换设计 / 画幅 / 深浅色时整个 Snap 重来,不留旧图
9176
+ const snapId = fileTarget && sid ? `session=${encodeURIComponent(sid)}&root=${encodeURIComponent(curRoot)}&w=${size[0]}&h=${size[1]}&dark=${dark ? 1 : 0}` : ''
9177
+ const snapQ = snapId ? `${snapId}&r=${(st && st.changedAt) || 0}&t=${encodeURIComponent((st && st.trust) || '')}&lw=${encodeURIComponent((st && st.watch) || '')}` : ''
8764
9178
  const sleepScreen = (sc, z) => h(Device, { kind, w: size[0], h: size[1], fill: false, label: labelOf(sc), top: tops[ik(sc)], os: meta.os },
8765
- h('div', { className: 'ddp-scr' + (dark ? ' dk' : '') }, h('div', { className: 'ddp-away', style: { fontSize: 13 / Math.max(0.25, z || 1) } }, t('canvasAsleep'))))
9179
+ h('div', { className: 'ddp-scr' + (dark ? ' dk' : '') },
9180
+ h('div', { className: 'ddp-away', style: { fontSize: 13 / Math.max(0.25, z || 1) } }, t('canvasAsleep')),
9181
+ snapQ && !sc.v ? h(Snap, { key: snapId + '&key=' + sc.key, src: `${API}scrthumb?${snapQ}&key=${encodeURIComponent(sc.key)}`, blind: /^off/.test((st && st.watch) || ''), onTitle: (title) => snapTitled(sc.key, title) }) : null))
8766
9182
 
8767
9183
  // ── 导出图片 ──
8768
9184
  // 截一屏:图片和它的 CSS 尺寸(PDF / PPT 按这个定页面大小)
@@ -8954,6 +9370,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
8954
9370
  if (!ver) return
8955
9371
  const n = ver.n
8956
9372
  post('restore', { session: sid, n }).then((d) => {
9373
+ memoReset() // 退回来的页面可能从此按别人做的预览(信任变了、文件没动),状态还没轮询到:留着的打包结果全不用
8957
9374
  setVersions(Array.isArray(d.versions) ? d.versions : [])
8958
9375
  setVer(null)
8959
9376
  setCmp(false)