dsh-design-studio 0.23.0 → 0.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client.js +577 -520
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -8473,6 +8473,512 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
8473
8473
|
|
|
8474
8474
|
// ── 右侧栏标签页 ─────────────────────────────────────────────────────────
|
|
8475
8475
|
|
|
8476
|
+
// ── 导出图片(从预览面板里拆出来的:只用传进来的,不碰面板自己的状态)──────────────
|
|
8477
|
+
// x:这一次画面的值(会话、状态、类型、画幅、几屏…)、几个 ref(各屏接口、背后挂的那批、设计序号)和面板里共用的 apiOf / targetKey
|
|
8478
|
+
// onWarn:预检发现会被裁时打开导出选项
|
|
8479
|
+
function makeExporter(x) {
|
|
8480
|
+
const { sid, st, kind, size, dark, meta, tokens, t, say, canvas, focus, sel, shown, ik, labelOf, infoOf, fileTarget, ver, apis, designNow, designSeq, ghostApis, ghostBatch, ghostQueue, setBackFrames, warned, onWarn, apiOf, targetKey } = x
|
|
8481
|
+
// 截一屏:图片和它的 CSS 尺寸(PDF / PPT 按这个定页面大小)
|
|
8482
|
+
// 这次导出截到的 AI 示意图(文件名去重):每种导出结束的提示里都带一句「上线前换成真实照片」
|
|
8483
|
+
const aiTail = (ai) => (ai && ai.size ? ' · ' + t('xoAi', { n: ai.size }) : '')
|
|
8484
|
+
const captureOf = async (sc, full, map, maxH, ai) => {
|
|
8485
|
+
const api = await apiOf(sc, map)
|
|
8486
|
+
const r = await api.capture({ full: !!full, scale: 2, ...(maxH ? { maxH } : {}) })
|
|
8487
|
+
if (ai && Array.isArray(r.aiPhotos)) for (const x of r.aiPhotos) ai.add(x)
|
|
8488
|
+
return { img: await loadImg(r.png), w: r.w, h: r.h, links: Array.isArray(r.links) ? r.links : [], top: typeof r.top === 'boolean' ? r.top : null, title: String(r.title || '').trim() }
|
|
8489
|
+
}
|
|
8490
|
+
// 导出用的标题:屏多的时候有的屏没在画布上挂过,手上没有它的标题,用截图时页面报的
|
|
8491
|
+
const exportTitle = (sc, r) => (infoOf(ik(sc)) || {}).title || r.title || sc.label
|
|
8492
|
+
|
|
8493
|
+
const saveImage = async (name, blob, ai) => {
|
|
8494
|
+
const png = await blobB64(blob)
|
|
8495
|
+
const r = await post('export', { session: sid, name, png, target: targetKey })
|
|
8496
|
+
const copied = await copyImage(blob)
|
|
8497
|
+
const file = String(r.path || '').split(/[\\/]/).pop()
|
|
8498
|
+
say(t(copied ? 'exportedCopied' : 'exported', { name: file }) + aiTail(ai), { label: t('reveal'), run: () => post('reveal', { path: r.path }).catch(() => {}) })
|
|
8499
|
+
}
|
|
8500
|
+
|
|
8501
|
+
// 单看时只挂着正在看的那屏;要所有屏(PDF、PPT、拼图、预检)时按画幅大小在背后挂上,用完就撤
|
|
8502
|
+
const withFrames = async (fn, only) => {
|
|
8503
|
+
if (!only && ((canvas && shown.length <= LIVE_MAX) || shown.length < 2)) return fn(apis.current)
|
|
8504
|
+
// 网页单看时铺满右侧栏,和画幅不一样宽,都在背后重挂(开了「按画幅显示」也照这样挂,只是多挂一次、慢一点,结果一样);别的类型正在看的那屏直接用(滚动位置、打开的弹窗都还在)
|
|
8505
|
+
// 画布屏多的时候镜头一动画布上的屏就会撤,也都在背后挂
|
|
8506
|
+
const stamp = designSeq.current
|
|
8507
|
+
const run = async () => {
|
|
8508
|
+
if (designSeq.current !== stamp) throw new Error('designChanged') // 排队的时候换了设计
|
|
8509
|
+
// 轮到了才算要挂哪些:排队时前台可能已经换了一屏
|
|
8510
|
+
const list = only || (canvas || kind === 'web' ? shown : shown.filter((sc) => !apis.current.has(ik(sc))))
|
|
8511
|
+
const back = new Set(list.map(ik))
|
|
8512
|
+
const place = new Map(list.map((sc, i) => [ik(sc), i]))
|
|
8513
|
+
// 屏多的时候分批挂:只挂轮到的这一批,别几十个一起跑
|
|
8514
|
+
let at = 0
|
|
8515
|
+
// 每个任务一批新的 iframe:上一批的深浅色、接口都不留(不然拿到上一批「已就绪」的就截了)
|
|
8516
|
+
ghostApis.current.clear()
|
|
8517
|
+
setBackFrames({ list, size, at, dark, batch: ++ghostBatch.current }) // 深浅色跟点导出时的走,和文件名对得上
|
|
8518
|
+
const get = (k) => {
|
|
8519
|
+
const i = place.get(k)
|
|
8520
|
+
if (i !== undefined && (i < at || i >= at + LIVE_MAX)) { at = i; setBackFrames((b) => (b ? { ...b, at: i } : b)) }
|
|
8521
|
+
return (back.has(k) ? ghostApis.current : apis.current).get(k)
|
|
8522
|
+
}
|
|
8523
|
+
try { return await fn({ get }) } finally { setBackFrames(null) }
|
|
8524
|
+
}
|
|
8525
|
+
// 背后挂的屏一次只给一个任务用(预检和导出撞上,会互相把对方要的那批撤掉)
|
|
8526
|
+
const job = ghostQueue.current.then(run, run)
|
|
8527
|
+
ghostQueue.current = job.catch(() => {})
|
|
8528
|
+
return job
|
|
8529
|
+
}
|
|
8530
|
+
const measureAll = async (map) => {
|
|
8531
|
+
const stamp = designSeq.current
|
|
8532
|
+
const list = []
|
|
8533
|
+
for (const sc of shown) {
|
|
8534
|
+
if (designSeq.current !== stamp) break // 设计换了:别再等旧的屏
|
|
8535
|
+
try { const api = await apiOf(sc, map); list.push(await api.measure()) } catch (e) { console.warn('[dsh-design-studio] 量页面失败', sc.key, e); list.push({ failed: true }) }
|
|
8536
|
+
}
|
|
8537
|
+
return list
|
|
8538
|
+
}
|
|
8539
|
+
|
|
8540
|
+
// 图片 / 整套展示图 / PDF / PPT(菜单里的「选项」「打包」「分享」在面板里分流,见 doExport)
|
|
8541
|
+
const exportShots = async (mode, key, opts) => {
|
|
8542
|
+
say(t('exporting'))
|
|
8543
|
+
const design = designNow.current
|
|
8544
|
+
const stamp = designSeq.current
|
|
8545
|
+
const gone = () => designSeq.current !== stamp
|
|
8546
|
+
const aiShot = new Set() // 这次导出截到的 AI 示意图(每次导出各记各的,连着导出不串)
|
|
8547
|
+
try {
|
|
8548
|
+
const prefix = ver ? `v${ver.n}-` : ''
|
|
8549
|
+
const suffix = dark ? '-dark' : ''
|
|
8550
|
+
if (mode === 'pdf' || mode === 'pptx') {
|
|
8551
|
+
// 每屏一页。PDF 里网页、邮件放整页长图(页面多高就多高);PPT 一张幻灯片一个画面。选项面板里可以改
|
|
8552
|
+
const fit = (opts && opts.fit) || ''
|
|
8553
|
+
const long = fit === 'page' || fit === 'height' || (!fit && mode === 'pdf' && (kind === 'web' || kind === 'email'))
|
|
8554
|
+
const maxH = fit === 'height' ? Number(opts.fitH) || 0 : 0
|
|
8555
|
+
let deadN = 0
|
|
8556
|
+
await withFrames(async (map) => {
|
|
8557
|
+
// 从菜单直接点:先量一遍,有内容会被裁就先给看清单(同样的结果只拦一次)
|
|
8558
|
+
if (!opts) {
|
|
8559
|
+
const seen = await measureAll(map)
|
|
8560
|
+
const rep = precheckOf(seen, kind, long ? Infinity : 0)
|
|
8561
|
+
deadN = rep.dead
|
|
8562
|
+
const sig = rep.over || rep.long || rep.moved ? [design, shown.map(ik).join(','), size.join('x'), long ? 1 : 0, seen.map((m) => (m.failed ? '-' : `${m.pageW}x${m.pageH}`)).join(',')].join('|') : ''
|
|
8563
|
+
if (sig && warned.current !== sig) {
|
|
8564
|
+
warned.current = sig
|
|
8565
|
+
say(t('xoWarn'))
|
|
8566
|
+
onWarn()
|
|
8567
|
+
return
|
|
8568
|
+
}
|
|
8569
|
+
}
|
|
8570
|
+
const pages = []
|
|
8571
|
+
const keys = []
|
|
8572
|
+
for (const sc of shown) {
|
|
8573
|
+
if (gone()) break
|
|
8574
|
+
try {
|
|
8575
|
+
const r = await captureOf(sc, long, map, maxH, aiShot)
|
|
8576
|
+
const cut = maxH && r.h > maxH
|
|
8577
|
+
pages.push({ jpg: await jpegB64(cut ? cropImg(r.img, r.h, maxH) : r.img), w: r.w, h: cut ? maxH : r.h, title: exportTitle(sc, r), links: r.links })
|
|
8578
|
+
keys.push(sc.key)
|
|
8579
|
+
} catch (e) { console.warn('[dsh-design-studio] 截图失败', sc.key, e) }
|
|
8580
|
+
}
|
|
8581
|
+
if (gone()) { say(t('xoGone')); return }
|
|
8582
|
+
if (!pages.length) throw new Error('no screens')
|
|
8583
|
+
// 原型里的跳转:路径换成第几页,PDF / PPT 里点了能跳过去
|
|
8584
|
+
for (const p of pages) {
|
|
8585
|
+
p.links = p.links.map((l) => ({ x: l.x, y: l.y, w: l.w, h: l.h, to: keys.indexOf(keyOfPath(l.path, fileTarget)) })).filter((l) => l.to >= 0)
|
|
8586
|
+
}
|
|
8587
|
+
const sp = splitTitles(pages.map((x) => x.title))
|
|
8588
|
+
const folder = st && st.target && st.target.kind === 'file' ? String(st.target.file).split(/[\\/]/).slice(-2, -1)[0] : ''
|
|
8589
|
+
const title = sp.brand || folder || st.label || ''
|
|
8590
|
+
const layout = opts ? (opts.layout === 'custom' ? opts.custom.trim() : opts.layout === 'auto' ? '' : opts.layout) : ''
|
|
8591
|
+
const cols = opts && opts.cols === 2 ? 2 : 1
|
|
8592
|
+
const r = await post('doc', { session: sid, format: mode, name: prefix + (title || 'design') + suffix, title, bg: hexOf(pickColors(tokens).bg), pages, layout, cols, target: targetKey })
|
|
8593
|
+
const file = String(r.path || '').split(/[\\/]/).pop()
|
|
8594
|
+
const miss = shown.length - pages.length
|
|
8595
|
+
const sheets = Math.ceil(pages.length / cols)
|
|
8596
|
+
say((miss ? t('exportedDocMiss', { name: file, n: sheets, miss }) : t('exportedDoc', { name: file, n: sheets })) + (deadN ? ' · ' + t('xoDead', { n: deadN }) : '') + aiTail(aiShot), { label: t('reveal'), run: () => post('reveal', { path: r.path }).catch(() => {}) })
|
|
8597
|
+
})
|
|
8598
|
+
return
|
|
8599
|
+
}
|
|
8600
|
+
if (mode === 'show') {
|
|
8601
|
+
const shots = []
|
|
8602
|
+
await withFrames(async (map) => {
|
|
8603
|
+
for (const sc of shown) {
|
|
8604
|
+
if (gone()) break
|
|
8605
|
+
try { const c = await captureOf(sc, false, map, 0, aiShot); shots.push({ img: c.img, top: c.top, title: exportTitle(sc, c) }) } catch (e) { console.warn('[dsh-design-studio] 截图失败', sc.key, e) }
|
|
8606
|
+
}
|
|
8607
|
+
})
|
|
8608
|
+
if (gone()) { say(t('xoGone')); return }
|
|
8609
|
+
if (!shots.length) throw new Error('no screens')
|
|
8610
|
+
const sp = splitTitles(shots.map((x) => x.title))
|
|
8611
|
+
const colors = pickColors(tokens)
|
|
8612
|
+
const blob = await composeShowcase({
|
|
8613
|
+
kind,
|
|
8614
|
+
size,
|
|
8615
|
+
shots: shots.map((x, i) => ({ img: x.img, top: x.top, label: sp.labels[i] || x.title })),
|
|
8616
|
+
os: meta.os,
|
|
8617
|
+
title: sp.brand || (st && st.target && st.target.kind === 'file' ? String(st.target.file).split(/[\\/]/).slice(-2, -1)[0] : st.label) || '',
|
|
8618
|
+
sub: t('showSub', { n: shots.length, kind: t(KIND_KEY[kind]), date: ymd(new Date()) }),
|
|
8619
|
+
bg: colors.bg,
|
|
8620
|
+
accent: colors.accent || ACCENT,
|
|
8621
|
+
mark: t('madeWith'),
|
|
8622
|
+
})
|
|
8623
|
+
await saveImage(prefix + (sp.brand || 'showcase') + suffix, blob, aiShot)
|
|
8624
|
+
return
|
|
8625
|
+
}
|
|
8626
|
+
const k = key || (canvas ? sel || focus : focus)
|
|
8627
|
+
const sc = shown.find((x) => x.key === k) || shown[0]
|
|
8628
|
+
if (!sc) throw new Error('no screen')
|
|
8629
|
+
const base = prefix + sc.key.replace(/\.html?$/i, '') + suffix
|
|
8630
|
+
// 画布屏多的时候这屏可能没挂着(镜头一动也可能撤掉):在背后单独挂一份来截
|
|
8631
|
+
let shot = null
|
|
8632
|
+
if (canvas && shown.length > LIVE_MAX) await withFrames(async (map) => { shot = await captureOf(sc, mode === 'long', map, 0, aiShot) }, [sc])
|
|
8633
|
+
else shot = await captureOf(sc, mode === 'long', undefined, 0, aiShot)
|
|
8634
|
+
if (gone()) { say(t('xoGone')); return }
|
|
8635
|
+
const { img, top } = shot
|
|
8636
|
+
if (mode === 'frame') await saveImage(base, await composeOne(kind, size, img, labelOf(sc), top, meta.os), aiShot)
|
|
8637
|
+
else {
|
|
8638
|
+
const c = document.createElement('canvas')
|
|
8639
|
+
c.width = img.width
|
|
8640
|
+
c.height = img.height
|
|
8641
|
+
c.getContext('2d').drawImage(img, 0, 0)
|
|
8642
|
+
await saveImage(base + (mode === 'long' ? '-full' : mode === 'raw' && FRAMED[kind] ? '-plain' : ''), await canvasBlob(c), aiShot)
|
|
8643
|
+
}
|
|
8644
|
+
} catch (e) {
|
|
8645
|
+
say(e.message === 'designChanged' ? t('xoGone') : t('exportFail', { msg: e.message }))
|
|
8646
|
+
}
|
|
8647
|
+
}
|
|
8648
|
+
return { withFrames, measureAll, exportShots }
|
|
8649
|
+
}
|
|
8650
|
+
|
|
8651
|
+
// ── 画笔标注(从预览面板里拆出来的):台面上看得到的几屏截图拼好、叠上画的,存进 refs/ 交给模型,或者复制
|
|
8652
|
+
// x:这一次画面的值和几个 ref;开关画笔、收掉别的面板留在面板里(toggleMark)
|
|
8653
|
+
function makeMarkup(x) {
|
|
8654
|
+
const { sid, st, stRef, url, shown, ik, apis, stageRef, markRun, markBusy, setMarkBusy, setMark, curScreen, insert, say, t } = x
|
|
8655
|
+
const markFrames = () => {
|
|
8656
|
+
const stage = stageRef.current
|
|
8657
|
+
if (!stage) return []
|
|
8658
|
+
const sr = stage.getBoundingClientRect()
|
|
8659
|
+
const out = []
|
|
8660
|
+
for (const sc of shown) {
|
|
8661
|
+
const api = apis.current.get(ik(sc))
|
|
8662
|
+
const f = api && typeof api.frame === 'function' ? api.frame() : null
|
|
8663
|
+
if (!f) continue
|
|
8664
|
+
const r = f.getBoundingClientRect()
|
|
8665
|
+
if (r.width < 8 || r.height < 8 || r.right <= sr.left || r.left >= sr.right || r.bottom <= sr.top || r.top >= sr.bottom) continue
|
|
8666
|
+
if (typeof f.checkVisibility === 'function' && !f.checkVisibility({ opacityProperty: true, visibilityProperty: true })) continue
|
|
8667
|
+
out.push({ key: ik(sc), sc, api, f, l: r.left - sr.left, t: r.top - sr.top, w: r.width, h: r.height, z: r.width / Math.max(1, f.offsetWidth) })
|
|
8668
|
+
}
|
|
8669
|
+
return out
|
|
8670
|
+
}
|
|
8671
|
+
const MARK_SHOTS = 40
|
|
8672
|
+
// 截到的是哪一页(只用来起名、写进提示):本地文件按文件名;开发服务器按路由(/account);单页应用的 #/account 路由带上
|
|
8673
|
+
const markPageOf = (sc, href) => {
|
|
8674
|
+
let key = pageOf(sc, href).key
|
|
8675
|
+
try {
|
|
8676
|
+
const u = new URL(href)
|
|
8677
|
+
if (u.origin !== new URL(sc.url).origin) return key
|
|
8678
|
+
if (key === sc.key && st && st.target && st.target.kind === 'proxy') key = decodeURIComponent(u.pathname) || sc.key
|
|
8679
|
+
if (/^#!?\//.test(u.hash)) key += decodeURIComponent(u.hash)
|
|
8680
|
+
} catch { /* 地址不对 */ }
|
|
8681
|
+
return key
|
|
8682
|
+
}
|
|
8683
|
+
// 把画的拼成一张图:画到的那几屏按现在的位置截图,叠上画的(交给模型、复制共用)
|
|
8684
|
+
const buildMark = async (list, stage) => {
|
|
8685
|
+
const sr = stage.getBoundingClientRect()
|
|
8686
|
+
const all = markFrames().filter((x) => x.api.ready())
|
|
8687
|
+
const ov = (a, b) => a.l < b.r && a.r > b.l && a.t < b.b && a.b > b.t
|
|
8688
|
+
const boxOf = (x) => ({ l: x.l, t: x.t, r: x.l + x.w, b: x.t + x.h })
|
|
8689
|
+
// 画到的那几屏(一屏都没碰到:画在屏外空白处的,就把看得到的都拼上)
|
|
8690
|
+
const marks = list.map(markBox)
|
|
8691
|
+
let shots = all.filter((x) => marks.some((m) => ov(boxOf(x), m)))
|
|
8692
|
+
if (!shots.length) shots = all
|
|
8693
|
+
// 裁到有东西的那块(画到的屏 + 画的),四周留一点;落在这块里的别的屏也拼上,免得图上空一块
|
|
8694
|
+
const pad = 16
|
|
8695
|
+
const span = (bs) => ({
|
|
8696
|
+
l: Math.max(0, Math.min(...bs.map((b) => b.l)) - pad),
|
|
8697
|
+
t: Math.max(0, Math.min(...bs.map((b) => b.t)) - pad),
|
|
8698
|
+
r: Math.min(sr.width, Math.max(...bs.map((b) => b.r)) + pad),
|
|
8699
|
+
b: Math.min(sr.height, Math.max(...bs.map((b) => b.b)) + pad),
|
|
8700
|
+
})
|
|
8701
|
+
const crop = span([...shots.map(boxOf), ...marks])
|
|
8702
|
+
shots = all.filter((x) => shots.includes(x) || ov(boxOf(x), crop))
|
|
8703
|
+
const { l: cl, t: ct, r: cr, b: cb } = crop
|
|
8704
|
+
if (!(cr - cl >= 1 && cb - ct >= 1)) throw new Error('empty')
|
|
8705
|
+
// 清晰度:至少按屏幕像素;画布缩小着看的,按页面原来的大小截(最多 4 倍),整张不超过 4096
|
|
8706
|
+
const zMin = Math.min(1, ...shots.map((x) => x.z))
|
|
8707
|
+
const k = Math.min(4096 / Math.max(cr - cl, cb - ct), Math.max(Math.min(2, Math.max(1, window.devicePixelRatio || 1)), Math.min(4, 1 / Math.max(0.05, zMin))))
|
|
8708
|
+
const c = document.createElement('canvas')
|
|
8709
|
+
c.width = Math.max(1, Math.round((cr - cl) * k))
|
|
8710
|
+
c.height = Math.max(1, Math.round((cb - ct) * k))
|
|
8711
|
+
const ctx = c.getContext('2d')
|
|
8712
|
+
let bg = ''
|
|
8713
|
+
for (let el = stage; el && !bg; el = el.parentElement) {
|
|
8714
|
+
const v = getComputedStyle(el).backgroundColor
|
|
8715
|
+
if (v && !/^(transparent|rgba\(.*,\s*0\))$/.test(v)) bg = v
|
|
8716
|
+
}
|
|
8717
|
+
ctx.fillStyle = bg || '#f4f4f5'
|
|
8718
|
+
ctx.fillRect(0, 0, c.width, c.height)
|
|
8719
|
+
if (shots.length > MARK_SHOTS) say(t('mkMany', { n: MARK_SHOTS }))
|
|
8720
|
+
const names = []
|
|
8721
|
+
for (const [i, x] of shots.entries()) {
|
|
8722
|
+
const X = (x.l - cl) * k
|
|
8723
|
+
const Y = (x.t - ct) * k
|
|
8724
|
+
// 手机框的圆角:往上找一层裁圆角的
|
|
8725
|
+
let rad = 0
|
|
8726
|
+
for (let el = x.f.parentElement, j = 0; el && el !== stage && j < 4 && !rad; el = el.parentElement, j++) {
|
|
8727
|
+
const cs = getComputedStyle(el)
|
|
8728
|
+
const v = parseFloat(cs.borderTopLeftRadius) || 0
|
|
8729
|
+
if (v && cs.overflow !== 'visible' && el.offsetWidth) rad = v * (el.getBoundingClientRect().width / el.offsetWidth)
|
|
8730
|
+
}
|
|
8731
|
+
ctx.save()
|
|
8732
|
+
ctx.beginPath()
|
|
8733
|
+
if (rad && typeof ctx.roundRect === 'function') ctx.roundRect(X, Y, x.w * k, x.h * k, rad * k)
|
|
8734
|
+
else ctx.rect(X, Y, x.w * k, x.h * k)
|
|
8735
|
+
ctx.clip()
|
|
8736
|
+
let name = x.sc.key
|
|
8737
|
+
try {
|
|
8738
|
+
if (i >= MARK_SHOTS) throw new Error('too many')
|
|
8739
|
+
const cap = await x.api.capture({ full: false, scale: Math.min(3, Math.max(1, x.z * k)) })
|
|
8740
|
+
// 页面里点链接跳到别的页了:按真正截到的那页起名
|
|
8741
|
+
if (cap.href) name = markPageOf(x.sc, cap.href)
|
|
8742
|
+
const img = await loadImg(cap.png)
|
|
8743
|
+
ctx.fillStyle = '#fff'
|
|
8744
|
+
ctx.fillRect(X, Y, x.w * k, x.h * k)
|
|
8745
|
+
ctx.drawImage(img, X, Y, cap.w * x.z * k, cap.h * x.z * k)
|
|
8746
|
+
} catch (e) {
|
|
8747
|
+
// 这一屏截不下来:留个灰块,画的东西还在
|
|
8748
|
+
if (i < MARK_SHOTS) console.warn('[dsh-design-studio] 标注截图失败', x.sc.key, e)
|
|
8749
|
+
ctx.fillStyle = 'rgba(127,127,127,.18)'
|
|
8750
|
+
ctx.fillRect(X, Y, x.w * k, x.h * k)
|
|
8751
|
+
}
|
|
8752
|
+
ctx.restore()
|
|
8753
|
+
if (!names.includes(name)) names.push(name)
|
|
8754
|
+
}
|
|
8755
|
+
for (const s of list) drawMark(ctx, s, k, cl, ct)
|
|
8756
|
+
return { c, names, blob: await canvasBlob(c) }
|
|
8757
|
+
}
|
|
8758
|
+
const sendMark = async (list) => {
|
|
8759
|
+
if (markBusy) return
|
|
8760
|
+
if (!list.length) { say(t('mkEmpty')); return }
|
|
8761
|
+
const stage = stageRef.current
|
|
8762
|
+
if (!stage) return
|
|
8763
|
+
const url0 = url
|
|
8764
|
+
const run0 = markRun.current
|
|
8765
|
+
const stale = () => stRef.current.url !== url0 || markRun.current !== run0
|
|
8766
|
+
const root0 = st && st.target && st.target.kind === 'file' ? st.target.root : null
|
|
8767
|
+
setMarkBusy(true)
|
|
8768
|
+
try {
|
|
8769
|
+
const { c, names, blob } = await buildMark(list, stage)
|
|
8770
|
+
// 拼图的时候换了设计、关了标注:这张图对不上了,别交
|
|
8771
|
+
if (stale()) { if (stRef.current.url !== url0) say(t('mkMoved')); return }
|
|
8772
|
+
if (!names.length && curScreen) names.push(curScreen.key)
|
|
8773
|
+
const stem = String(names[0] || 'page').replace(/\.html?(?=$|#)/i, '').split(/[/#!]+/).filter(Boolean).pop() || 'page'
|
|
8774
|
+
const body = { session: sid, name: `markup-${stem}`, data: await blobB64(blob) }
|
|
8775
|
+
if (root0 !== null) body.root = root0
|
|
8776
|
+
let saved
|
|
8777
|
+
try { saved = await post('ref', body) } catch (e) {
|
|
8778
|
+
if (/moved/.test(e.message)) { say(t('mkMoved')); return }
|
|
8779
|
+
throw e
|
|
8780
|
+
}
|
|
8781
|
+
if (stale()) { if (stRef.current.url !== url0) say(t('mkMoved')); return }
|
|
8782
|
+
keepThumb(saved.path, c)
|
|
8783
|
+
const where = (names.length ? names : [st.label || '']).join(t('sep'))
|
|
8784
|
+
// 写在图上的字也用文字带上:模型看图看漏了、或者用的模型看不了图,也知道要改什么
|
|
8785
|
+
const notes = list.filter((x) => x.t === 'text').map((x) => t('mkQuote', { v: x.v.replace(/\s*\n\s*/g, ' ') })).join(t('sep'))
|
|
8786
|
+
// 插不进输入框:标注层留着(画的还在),提示再点一次;不退回剪贴板
|
|
8787
|
+
if (insert(t('mkAsk', { path: saved.path, where, notes: notes ? t('mkNotes', { notes }) : '' }), 'mkIn', false)) setMark(false)
|
|
8788
|
+
else say(t('mkNoInput'))
|
|
8789
|
+
} catch (e) {
|
|
8790
|
+
say(t('mkFail', { msg: e.message }))
|
|
8791
|
+
} finally {
|
|
8792
|
+
setMarkBusy(false)
|
|
8793
|
+
}
|
|
8794
|
+
}
|
|
8795
|
+
// 复制:同一张图放进剪贴板(issue #6)。点按钮这一下就把「等图拼好」交给剪贴板——拼完再写,
|
|
8796
|
+
// Safari 这类会说不是用户点的、不让写;不认这种写法的再用拼好的图写一次
|
|
8797
|
+
const copyMark = (list) => {
|
|
8798
|
+
if (markBusy) return
|
|
8799
|
+
if (!list.length) { say(t('mkEmpty')); return }
|
|
8800
|
+
const stage = stageRef.current
|
|
8801
|
+
if (!stage) return
|
|
8802
|
+
const url0 = url
|
|
8803
|
+
const run0 = markRun.current
|
|
8804
|
+
const stale = () => stRef.current.url !== url0 || markRun.current !== run0
|
|
8805
|
+
const STALE = 'ddp-mark-stale'
|
|
8806
|
+
setMarkBusy(true)
|
|
8807
|
+
const made = buildMark(list, stage).then((r) => { if (stale()) throw new Error(STALE); return r })
|
|
8808
|
+
const png = made.then((r) => r.blob)
|
|
8809
|
+
png.catch(() => {}) // 结果在下面看
|
|
8810
|
+
let wrote
|
|
8811
|
+
try { wrote = navigator.clipboard.write([new ClipboardItem({ 'image/png': png })]) } catch (e) { wrote = Promise.reject(e) }
|
|
8812
|
+
wrote.catch(() => {})
|
|
8813
|
+
;(async () => {
|
|
8814
|
+
try {
|
|
8815
|
+
const r = await made
|
|
8816
|
+
if (!(await wrote.then(() => true, () => false))) {
|
|
8817
|
+
// 等写的工夫里取消了、换了设计:别再把这张旧图写进去
|
|
8818
|
+
if (stale()) { if (stRef.current.url !== url0) say(t('mkMoved')); return }
|
|
8819
|
+
if (!(await copyImage(r.blob))) { say(t('mkCopyFail')); return }
|
|
8820
|
+
}
|
|
8821
|
+
if (stale()) return
|
|
8822
|
+
say(t('mkCopied'))
|
|
8823
|
+
setMark(false)
|
|
8824
|
+
} catch (e) {
|
|
8825
|
+
if (e && e.message === STALE) { if (stRef.current.url !== url0) say(t('mkMoved')) } else {
|
|
8826
|
+
console.warn('[dsh-design-studio] 标注图复制失败', e)
|
|
8827
|
+
say(t('mkCopyFail'))
|
|
8828
|
+
}
|
|
8829
|
+
} finally {
|
|
8830
|
+
setMarkBusy(false)
|
|
8831
|
+
}
|
|
8832
|
+
})()
|
|
8833
|
+
}
|
|
8834
|
+
return { markFrames, sendMark, copyMark }
|
|
8835
|
+
}
|
|
8836
|
+
|
|
8837
|
+
// ── 设计体检(从预览面板里拆出来的):画布上量所有屏,单页量这一屏;问题标在页面上,列在面板里
|
|
8838
|
+
// x:这一次画面的值和几个 ref;onOpen:开体检面板时收掉别的面板。自动量、check_design 回话的 effect 留在面板里
|
|
8839
|
+
function makeCheck(x) {
|
|
8840
|
+
const { kind, url, st, stRef, canvas, shown, focus, ik, labelOf, apis, apiOf, ck, setCk, ckGen, ckOpen, setCkCount, setReveal, setSel, onOpen, insert, say, t } = x
|
|
8841
|
+
const closeCheck = () => {
|
|
8842
|
+
ckGen.current++
|
|
8843
|
+
ckOpen.current = false
|
|
8844
|
+
if (ck) for (const sc of ck.list || []) { const a = apis.current.get(ik(sc)); if (a) a.checkClear() }
|
|
8845
|
+
setCk(null)
|
|
8846
|
+
}
|
|
8847
|
+
// 画布屏多的时候只量挂着的(别的没有页面可量)
|
|
8848
|
+
const checkList = () => (canvas ? (shown.length > LIVE_MAX ? shown.filter((sc) => apis.current.has(ik(sc))) : shown) : [shown.find((x) => x.key === focus) || { key: focus, url, label: st.label }])
|
|
8849
|
+
// 几屏一起量(各量各的 iframe),一屏卡住不拖累别的
|
|
8850
|
+
const measure = (list, quiet) => Promise.all(list.map(async (sc) => {
|
|
8851
|
+
const row = { key: sc.key, v: sc.v, label: labelOf(sc), url: sc.url, issues: [] }
|
|
8852
|
+
try {
|
|
8853
|
+
const r = await (await apiOf(sc)).check(kind, quiet)
|
|
8854
|
+
row.issues = Array.isArray(r.issues) ? r.issues : []
|
|
8855
|
+
if (r.metrics && typeof r.metrics === 'object') row.metrics = r.metrics
|
|
8856
|
+
} catch (e) { row.error = e.message }
|
|
8857
|
+
return row
|
|
8858
|
+
}))
|
|
8859
|
+
const total = (list) => list.reduce((m, x) => m + x.issues.length, 0)
|
|
8860
|
+
const runCheck = async () => {
|
|
8861
|
+
onOpen()
|
|
8862
|
+
setCk({ running: true, list: [] })
|
|
8863
|
+
const g = ++ckGen.current
|
|
8864
|
+
ckOpen.current = true
|
|
8865
|
+
const out = await measure(checkList(), false)
|
|
8866
|
+
if (g !== ckGen.current) { // 量的时候面板关了 / 又量了一轮:这份结果作废;面板关着的话,这一轮画上的标记也清掉
|
|
8867
|
+
if (!ckOpen.current) for (const sc of out) { const a = apis.current.get(ik(sc)); if (a) a.checkClear() }
|
|
8868
|
+
return out
|
|
8869
|
+
}
|
|
8870
|
+
if (canvas && shown.length > LIVE_MAX) say(t('checkPartial', { n: out.length }))
|
|
8871
|
+
setCk({ running: false, list: out })
|
|
8872
|
+
setCkCount(total(out))
|
|
8873
|
+
// 有问题的第一屏被面板挡着、在画布外面:挪过来
|
|
8874
|
+
const first = out.find((x) => x.issues.length)
|
|
8875
|
+
if (canvas && first) setReveal((r) => ({ key: first.key, n: ((r && r.n) || 0) + 1 }))
|
|
8876
|
+
return out
|
|
8877
|
+
}
|
|
8878
|
+
const focusIssue = (key, i) => {
|
|
8879
|
+
const sc = (ck && ck.list.find((x) => x.key === key)) || null
|
|
8880
|
+
if (!sc) return
|
|
8881
|
+
if (canvas) { setSel(key); setReveal((r) => ({ key, n: ((r && r.n) || 0) + 1 })) }
|
|
8882
|
+
// 屏多的时候这屏可能撤过(重新载入后页面里的体检标记没了):等它挂上,量一遍再定位
|
|
8883
|
+
if (canvas && shown.length > LIVE_MAX) { apiOf(sc).then((api) => api.check(kind, false).then(() => api.checkFocus(i))).catch((e) => console.warn('[dsh-design-studio] 定位问题失败', key, e)); return }
|
|
8884
|
+
const a = apis.current.get(ik(sc))
|
|
8885
|
+
if (a) a.checkFocus(i)
|
|
8886
|
+
}
|
|
8887
|
+
const fixIssues = () => {
|
|
8888
|
+
if (!ck) return
|
|
8889
|
+
insert(formatCheck(t, ck.list, stRef.current), 'insertedSend')
|
|
8890
|
+
closeCheck()
|
|
8891
|
+
}
|
|
8892
|
+
return { closeCheck, checkList, measure, total, runCheck, focusIssue, fixIssues }
|
|
8893
|
+
}
|
|
8894
|
+
|
|
8895
|
+
// ── 调样式(从预览面板里拆出来的):点一个元素,面板里拖滑块先在页面上看效果;写回文件 = 并进它在源码里的 style 属性
|
|
8896
|
+
// x:这一次画面的值;开关调样式、Esc 收起留在面板里
|
|
8897
|
+
function makeStyleEdit(x) {
|
|
8898
|
+
const { sid, stRef, fileTarget, canvas, setSel, sty, setSty, insert, say, t } = x
|
|
8899
|
+
const onStylePick = (sc, p) => {
|
|
8900
|
+
if (canvas) setSel(sc.key)
|
|
8901
|
+
const pg = pageOf(sc, p.href)
|
|
8902
|
+
setSty({ key: pg.key, url: pg.url, name: p.name, selector: p.selector, text: p.text, loc: p.loc, base: p.css || {}, vars: p.vars || {}, rules: p.rules && typeof p.rules === 'object' ? p.rules : {}, gradient: !!p.gradient, layout: !!p.layout, live: {} })
|
|
8903
|
+
}
|
|
8904
|
+
const setStyleProp = (patch) => setSty((c) => (c ? { ...c, live: { ...c.live, ...patch } } : c))
|
|
8905
|
+
// 交给模型:先问服务端那几条规则在源码第几行(本地文件才有;问不到就只写文件名)
|
|
8906
|
+
const askStyle = async () => {
|
|
8907
|
+
const s0 = sty
|
|
8908
|
+
if (!s0) return
|
|
8909
|
+
let located = null
|
|
8910
|
+
const items = [...new Map(Object.keys(s0.live || {}).map((k) => s0.rules && s0.rules[k]).filter((r) => r && r.sel && r.href).map((r) => [`${r.href}|${r.sel}|${r.n}`, r])).values()]
|
|
8911
|
+
if (fileTarget && items.length) {
|
|
8912
|
+
try {
|
|
8913
|
+
const r = await post('locate', { session: sid, items: items.map((x) => ({ href: x.href, sel: x.sel, n: x.n })) })
|
|
8914
|
+
located = new Map(items.map((x, i) => [`${x.href}|${x.sel}|${x.n}`, r && Array.isArray(r.items) ? r.items[i] : null]))
|
|
8915
|
+
} catch { /* 找不到行号就只写文件名 */ }
|
|
8916
|
+
}
|
|
8917
|
+
insert(formatStyleAsk(t, s0, stRef.current, located), 'insertedSend')
|
|
8918
|
+
}
|
|
8919
|
+
const saveStyle = () => {
|
|
8920
|
+
const s0 = sty
|
|
8921
|
+
if (!s0 || !Object.keys(s0.live).length) return
|
|
8922
|
+
if (!fileTarget) return askStyle()
|
|
8923
|
+
const saved = s0.live
|
|
8924
|
+
post('style', { session: sid, key: s0.key, loc: s0.loc, css: saved, name: s0.name }).then((r) => {
|
|
8925
|
+
if (r && r.ok) {
|
|
8926
|
+
say(t('styleSaved', { file: r.file }))
|
|
8927
|
+
// 写进去的算「原样」了;写的时候又拖过的留着
|
|
8928
|
+
setSty((c) => (c && c.key === s0.key && c.selector === s0.selector
|
|
8929
|
+
? { ...c, base: { ...c.base, ...saved }, live: Object.fromEntries(Object.entries(c.live).filter(([k, v]) => saved[k] !== v)) } : c))
|
|
8930
|
+
} else if (r && r.reason === 'busy') say(t('styleBusyTip'))
|
|
8931
|
+
else { say(t('styleMiss')); askStyle() }
|
|
8932
|
+
}, () => askStyle())
|
|
8933
|
+
}
|
|
8934
|
+
return { onStylePick, setStyleProp, askStyle, saveStyle }
|
|
8935
|
+
}
|
|
8936
|
+
|
|
8937
|
+
// ── 演示跳屏(从预览面板里拆出来的):点页面里的按钮跳到别的屏,前进从右边滑进来、返回从左边
|
|
8938
|
+
// x:setDemo、demoSeq(层的编号)、fileTarget(把链接路径换成哪一屏);开始演示、Esc 收起留在面板里
|
|
8939
|
+
function makeDemoNav(x) {
|
|
8940
|
+
const { setDemo, demoSeq, fileTarget } = x
|
|
8941
|
+
const demoGo = (path) => demoTo(keyOfPath(path, fileTarget))
|
|
8942
|
+
const demoTo = (key) => {
|
|
8943
|
+
setDemo((d) => {
|
|
8944
|
+
if (!d) return d
|
|
8945
|
+
const top = d.stack[d.stack.length - 1]
|
|
8946
|
+
if (key === top) return d
|
|
8947
|
+
const back = d.stack.length > 1 && d.stack[d.stack.length - 2] === key
|
|
8948
|
+
const stack = back ? d.stack.slice(0, -1) : [...d.stack, key].slice(-30)
|
|
8949
|
+
const last = d.layers[d.layers.length - 1]
|
|
8950
|
+
return { stack, layers: [last, { id: ++demoSeq.current, key, dir: back ? -1 : 1, shown: false }] }
|
|
8951
|
+
})
|
|
8952
|
+
}
|
|
8953
|
+
const demoRestart = () => setDemo((d) => {
|
|
8954
|
+
if (!d || d.stack.length < 2) return d
|
|
8955
|
+
const last = d.layers[d.layers.length - 1]
|
|
8956
|
+
return { stack: [d.stack[0]], layers: [last, { id: ++demoSeq.current, key: d.stack[0], dir: -1, shown: false }] }
|
|
8957
|
+
})
|
|
8958
|
+
const demoBack = () => setDemo((d) => {
|
|
8959
|
+
if (!d || d.stack.length < 2) return d
|
|
8960
|
+
const stack = d.stack.slice(0, -1)
|
|
8961
|
+
const last = d.layers[d.layers.length - 1]
|
|
8962
|
+
return { stack, layers: [last, { id: ++demoSeq.current, key: stack[stack.length - 1], dir: -1, shown: false }] }
|
|
8963
|
+
})
|
|
8964
|
+
const demoShown = (id) => {
|
|
8965
|
+
setDemo((d) => (d ? { ...d, layers: d.layers.map((l) => (l.id === id ? { ...l, shown: true } : l)) } : d))
|
|
8966
|
+
setTimeout(() => setDemo((d) => (d && d.layers.length > 1 && d.layers[d.layers.length - 1].id === id ? { ...d, layers: [d.layers[d.layers.length - 1]] } : d)), 480)
|
|
8967
|
+
}
|
|
8968
|
+
// 页面自己用脚本跳了(没走我们拦下的链接):只改记下的是哪一屏,不重载
|
|
8969
|
+
const demoHref = (id, href) => {
|
|
8970
|
+
let key = ''
|
|
8971
|
+
try { key = keyOfPath(decodeURIComponent(new URL(href).pathname), fileTarget) } catch { return }
|
|
8972
|
+
setDemo((d) => {
|
|
8973
|
+
if (!d) return d
|
|
8974
|
+
const last = d.layers[d.layers.length - 1]
|
|
8975
|
+
if (last.id !== id || last.key === key) return d
|
|
8976
|
+
return { stack: [...d.stack.slice(0, -1), key], layers: d.layers.map((l) => (l.id === id ? { ...l, key } : l)) }
|
|
8977
|
+
})
|
|
8978
|
+
}
|
|
8979
|
+
return { demoGo, demoTo, demoRestart, demoBack, demoShown, demoHref }
|
|
8980
|
+
}
|
|
8981
|
+
|
|
8476
8982
|
function PreviewTab(props) {
|
|
8477
8983
|
const t = props.t
|
|
8478
8984
|
const sid = props.sid || props.sessionId
|
|
@@ -8999,57 +9505,24 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
8999
9505
|
post('edit', { session: sid, key: pageOf(sc, d.href).key, before: d.before, after: d.after, nth: d.nth })
|
|
9000
9506
|
.then((r) => (r && r.ok ? say(t('textSaved', { file: r.file })) : askText(sc, d)), () => askText(sc, d))
|
|
9001
9507
|
}
|
|
9002
|
-
|
|
9003
|
-
// 模型在干活时不能改字(它可能正整份重写文件,改了会被盖掉)
|
|
9004
|
-
useEffect(() => { if (ver || demo || busy) setTextEdit(false) }, [!!ver, !!demo, busy])
|
|
9005
|
-
|
|
9006
|
-
// ── 调样式:点一个元素,面板里拖滑块先在页面上看效果;写回文件 = 并进它在源码里的 style 属性 ──
|
|
9007
|
-
const toggleStyle = () => {
|
|
9008
|
-
if (styleEdit) { setStyleEdit(false); return }
|
|
9009
|
-
setPicking(false)
|
|
9010
|
-
setTextEdit(false)
|
|
9011
|
-
setPanel(false)
|
|
9012
|
-
setHist(false)
|
|
9013
|
-
setPhone(false)
|
|
9014
|
-
closeCheck()
|
|
9015
|
-
setStyleEdit(true)
|
|
9016
|
-
}
|
|
9017
|
-
useEffect(() => { if (!styleEdit) setSty(null) }, [styleEdit])
|
|
9018
|
-
const onStylePick = (sc, p) => {
|
|
9019
|
-
if (canvas) setSel(sc.key)
|
|
9020
|
-
const pg = pageOf(sc, p.href)
|
|
9021
|
-
setSty({ key: pg.key, url: pg.url, name: p.name, selector: p.selector, text: p.text, loc: p.loc, base: p.css || {}, vars: p.vars || {}, rules: p.rules && typeof p.rules === 'object' ? p.rules : {}, gradient: !!p.gradient, layout: !!p.layout, live: {} })
|
|
9022
|
-
}
|
|
9023
|
-
const setStyleProp = (patch) => setSty((c) => (c ? { ...c, live: { ...c.live, ...patch } } : c))
|
|
9024
|
-
// 交给模型:先问服务端那几条规则在源码第几行(本地文件才有;问不到就只写文件名)
|
|
9025
|
-
const askStyle = async () => {
|
|
9026
|
-
const s0 = sty
|
|
9027
|
-
if (!s0) return
|
|
9028
|
-
let located = null
|
|
9029
|
-
const items = [...new Map(Object.keys(s0.live || {}).map((k) => s0.rules && s0.rules[k]).filter((r) => r && r.sel && r.href).map((r) => [`${r.href}|${r.sel}|${r.n}`, r])).values()]
|
|
9030
|
-
if (fileTarget && items.length) {
|
|
9031
|
-
try {
|
|
9032
|
-
const r = await post('locate', { session: sid, items: items.map((x) => ({ href: x.href, sel: x.sel, n: x.n })) })
|
|
9033
|
-
located = new Map(items.map((x, i) => [`${x.href}|${x.sel}|${x.n}`, r && Array.isArray(r.items) ? r.items[i] : null]))
|
|
9034
|
-
} catch { /* 找不到行号就只写文件名 */ }
|
|
9035
|
-
}
|
|
9036
|
-
insert(formatStyleAsk(t, s0, stRef.current, located), 'insertedSend')
|
|
9037
|
-
}
|
|
9038
|
-
const saveStyle = () => {
|
|
9039
|
-
const s0 = sty
|
|
9040
|
-
if (!s0 || !Object.keys(s0.live).length) return
|
|
9041
|
-
if (!fileTarget) return askStyle()
|
|
9042
|
-
const saved = s0.live
|
|
9043
|
-
post('style', { session: sid, key: s0.key, loc: s0.loc, css: saved, name: s0.name }).then((r) => {
|
|
9044
|
-
if (r && r.ok) {
|
|
9045
|
-
say(t('styleSaved', { file: r.file }))
|
|
9046
|
-
// 写进去的算「原样」了;写的时候又拖过的留着
|
|
9047
|
-
setSty((c) => (c && c.key === s0.key && c.selector === s0.selector
|
|
9048
|
-
? { ...c, base: { ...c.base, ...saved }, live: Object.fromEntries(Object.entries(c.live).filter(([k, v]) => saved[k] !== v)) } : c))
|
|
9049
|
-
} else if (r && r.reason === 'busy') say(t('styleBusyTip'))
|
|
9050
|
-
else { say(t('styleMiss')); askStyle() }
|
|
9051
|
-
}, () => askStyle())
|
|
9508
|
+
|
|
9509
|
+
// 模型在干活时不能改字(它可能正整份重写文件,改了会被盖掉)
|
|
9510
|
+
useEffect(() => { if (ver || demo || busy) setTextEdit(false) }, [!!ver, !!demo, busy])
|
|
9511
|
+
|
|
9512
|
+
// ── 调样式:点一个元素,面板里拖滑块先在页面上看效果;写回文件 = 并进它在源码里的 style 属性 ──
|
|
9513
|
+
const toggleStyle = () => {
|
|
9514
|
+
if (styleEdit) { setStyleEdit(false); return }
|
|
9515
|
+
setPicking(false)
|
|
9516
|
+
setTextEdit(false)
|
|
9517
|
+
setPanel(false)
|
|
9518
|
+
setHist(false)
|
|
9519
|
+
setPhone(false)
|
|
9520
|
+
closeCheck()
|
|
9521
|
+
setStyleEdit(true)
|
|
9052
9522
|
}
|
|
9523
|
+
useEffect(() => { if (!styleEdit) setSty(null) }, [styleEdit])
|
|
9524
|
+
// 调样式:选中、预览、交给模型、写回(makeStyleEdit)
|
|
9525
|
+
const { onStylePick, setStyleProp, askStyle, saveStyle } = makeStyleEdit({ sid, stRef, fileTarget, canvas, setSel, sty, setSty, insert, say, t })
|
|
9053
9526
|
useEffect(() => {
|
|
9054
9527
|
if (!styleEdit) return undefined
|
|
9055
9528
|
const onKey = (e) => { if (e.key === 'Escape' && !overlayUp()) setStyleEdit(false) }
|
|
@@ -9092,44 +9565,8 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
9092
9565
|
const inf = infoOf(key)
|
|
9093
9566
|
if (inf && !(inf.links || []).length) say(t('demoNone'))
|
|
9094
9567
|
}
|
|
9095
|
-
|
|
9096
|
-
const demoTo = (
|
|
9097
|
-
setDemo((d) => {
|
|
9098
|
-
if (!d) return d
|
|
9099
|
-
const top = d.stack[d.stack.length - 1]
|
|
9100
|
-
if (key === top) return d
|
|
9101
|
-
const back = d.stack.length > 1 && d.stack[d.stack.length - 2] === key
|
|
9102
|
-
const stack = back ? d.stack.slice(0, -1) : [...d.stack, key].slice(-30)
|
|
9103
|
-
const last = d.layers[d.layers.length - 1]
|
|
9104
|
-
return { stack, layers: [last, { id: ++demoSeq.current, key, dir: back ? -1 : 1, shown: false }] }
|
|
9105
|
-
})
|
|
9106
|
-
}
|
|
9107
|
-
const demoRestart = () => setDemo((d) => {
|
|
9108
|
-
if (!d || d.stack.length < 2) return d
|
|
9109
|
-
const last = d.layers[d.layers.length - 1]
|
|
9110
|
-
return { stack: [d.stack[0]], layers: [last, { id: ++demoSeq.current, key: d.stack[0], dir: -1, shown: false }] }
|
|
9111
|
-
})
|
|
9112
|
-
const demoBack = () => setDemo((d) => {
|
|
9113
|
-
if (!d || d.stack.length < 2) return d
|
|
9114
|
-
const stack = d.stack.slice(0, -1)
|
|
9115
|
-
const last = d.layers[d.layers.length - 1]
|
|
9116
|
-
return { stack, layers: [last, { id: ++demoSeq.current, key: stack[stack.length - 1], dir: -1, shown: false }] }
|
|
9117
|
-
})
|
|
9118
|
-
const demoShown = (id) => {
|
|
9119
|
-
setDemo((d) => (d ? { ...d, layers: d.layers.map((l) => (l.id === id ? { ...l, shown: true } : l)) } : d))
|
|
9120
|
-
setTimeout(() => setDemo((d) => (d && d.layers.length > 1 && d.layers[d.layers.length - 1].id === id ? { ...d, layers: [d.layers[d.layers.length - 1]] } : d)), 480)
|
|
9121
|
-
}
|
|
9122
|
-
// 页面自己用脚本跳了(没走我们拦下的链接):只改记下的是哪一屏,不重载
|
|
9123
|
-
const demoHref = (id, href) => {
|
|
9124
|
-
let key = ''
|
|
9125
|
-
try { key = keyOfPath(decodeURIComponent(new URL(href).pathname), fileTarget) } catch { return }
|
|
9126
|
-
setDemo((d) => {
|
|
9127
|
-
if (!d) return d
|
|
9128
|
-
const last = d.layers[d.layers.length - 1]
|
|
9129
|
-
if (last.id !== id || last.key === key) return d
|
|
9130
|
-
return { stack: [...d.stack.slice(0, -1), key], layers: d.layers.map((l) => (l.id === id ? { ...l, key } : l)) }
|
|
9131
|
-
})
|
|
9132
|
-
}
|
|
9568
|
+
// 演示里跳屏、返回、从头来(makeDemoNav)
|
|
9569
|
+
const { demoGo, demoTo, demoRestart, demoBack, demoShown, demoHref } = makeDemoNav({ setDemo, demoSeq, fileTarget })
|
|
9133
9570
|
useEffect(() => {
|
|
9134
9571
|
if (!demo) return undefined
|
|
9135
9572
|
const onKey = (e) => { if (e.key === 'Escape' && !overlayUp()) setDemo(null) }
|
|
@@ -9182,199 +9619,38 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
9182
9619
|
}))
|
|
9183
9620
|
|
|
9184
9621
|
// 画布上屏太多、离镜头远的:先不挂 iframe,放一张后台截的缩略图(issue #17),截不到就是「挪近就加载」。
|
|
9185
|
-
// 本地文件的设计才有图(开发服务器的页面不在后台另开);看旧版本时也没有。目录里一有改动地址就变,没变的那几屏服务端直接给缓存。
|
|
9186
|
-
// 地址带上目录:换了设计服务端就不给(晚到的回包也不会把上一套的图挂到这套上);换设计 / 画幅 / 深浅色时整个 Snap 重来,不留旧图
|
|
9187
|
-
const snapId = fileTarget && sid ? `session=${encodeURIComponent(sid)}&root=${encodeURIComponent(curRoot)}&w=${size[0]}&h=${size[1]}&dark=${dark ? 1 : 0}` : ''
|
|
9188
|
-
const snapQ = snapId ? `${snapId}&r=${(st && st.changedAt) || 0}&t=${encodeURIComponent((st && st.trust) || '')}&lw=${encodeURIComponent((st && st.watch) || '')}` : ''
|
|
9189
|
-
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 },
|
|
9190
|
-
h('div', { className: 'ddp-scr' + (dark ? ' dk' : '') },
|
|
9191
|
-
h('div', { className: 'ddp-away', style: { fontSize: 13 / Math.max(0.25, z || 1) } }, t('canvasAsleep')),
|
|
9192
|
-
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))
|
|
9193
|
-
|
|
9194
|
-
//
|
|
9195
|
-
|
|
9196
|
-
|
|
9197
|
-
|
|
9198
|
-
|
|
9199
|
-
|
|
9200
|
-
|
|
9201
|
-
await new Promise((r) => setTimeout(r, 150))
|
|
9202
|
-
api = map.get(ik(sc))
|
|
9203
|
-
}
|
|
9204
|
-
if (!api) throw new Error('not loaded')
|
|
9205
|
-
return api
|
|
9206
|
-
}
|
|
9207
|
-
// 这次导出截到的 AI 示意图(文件名去重):每种导出结束的提示里都带一句「上线前换成真实照片」
|
|
9208
|
-
const aiTail = (ai) => (ai && ai.size ? ' · ' + t('xoAi', { n: ai.size }) : '')
|
|
9209
|
-
const captureOf = async (sc, full, map, maxH, ai) => {
|
|
9210
|
-
const api = await apiOf(sc, map)
|
|
9211
|
-
const r = await api.capture({ full: !!full, scale: 2, ...(maxH ? { maxH } : {}) })
|
|
9212
|
-
if (ai && Array.isArray(r.aiPhotos)) for (const x of r.aiPhotos) ai.add(x)
|
|
9213
|
-
return { img: await loadImg(r.png), w: r.w, h: r.h, links: Array.isArray(r.links) ? r.links : [], top: typeof r.top === 'boolean' ? r.top : null, title: String(r.title || '').trim() }
|
|
9214
|
-
}
|
|
9215
|
-
// 导出用的标题:屏多的时候有的屏没在画布上挂过,手上没有它的标题,用截图时页面报的
|
|
9216
|
-
const exportTitle = (sc, r) => (infoOf(ik(sc)) || {}).title || r.title || sc.label
|
|
9217
|
-
|
|
9218
|
-
const targetKey = st && st.target ? (st.target.kind === 'file' ? `file|${st.target.root}` : `proxy|${st.target.port}`) : ''
|
|
9219
|
-
const saveImage = async (name, blob, ai) => {
|
|
9220
|
-
const png = await blobB64(blob)
|
|
9221
|
-
const r = await post('export', { session: sid, name, png, target: targetKey })
|
|
9222
|
-
const copied = await copyImage(blob)
|
|
9223
|
-
const file = String(r.path || '').split(/[\\/]/).pop()
|
|
9224
|
-
say(t(copied ? 'exportedCopied' : 'exported', { name: file }) + aiTail(ai), { label: t('reveal'), run: () => post('reveal', { path: r.path }).catch(() => {}) })
|
|
9225
|
-
}
|
|
9226
|
-
|
|
9227
|
-
const designId = JSON.stringify([sid, targetKey, ver ? ver.n : 0])
|
|
9228
|
-
if (designNow.current !== designId) { designNow.current = designId; designSeq.current++ }
|
|
9229
|
-
// 单看时只挂着正在看的那屏;要所有屏(PDF、PPT、拼图、预检)时按画幅大小在背后挂上,用完就撤
|
|
9230
|
-
const withFrames = async (fn, only) => {
|
|
9231
|
-
if (!only && ((canvas && shown.length <= LIVE_MAX) || shown.length < 2)) return fn(apis.current)
|
|
9232
|
-
// 网页单看时铺满右侧栏,和画幅不一样宽,都在背后重挂(开了「按画幅显示」也照这样挂,只是多挂一次、慢一点,结果一样);别的类型正在看的那屏直接用(滚动位置、打开的弹窗都还在)
|
|
9233
|
-
// 画布屏多的时候镜头一动画布上的屏就会撤,也都在背后挂
|
|
9234
|
-
const stamp = designSeq.current
|
|
9235
|
-
const run = async () => {
|
|
9236
|
-
if (designSeq.current !== stamp) throw new Error('designChanged') // 排队的时候换了设计
|
|
9237
|
-
// 轮到了才算要挂哪些:排队时前台可能已经换了一屏
|
|
9238
|
-
const list = only || (canvas || kind === 'web' ? shown : shown.filter((sc) => !apis.current.has(ik(sc))))
|
|
9239
|
-
const back = new Set(list.map(ik))
|
|
9240
|
-
const place = new Map(list.map((sc, i) => [ik(sc), i]))
|
|
9241
|
-
// 屏多的时候分批挂:只挂轮到的这一批,别几十个一起跑
|
|
9242
|
-
let at = 0
|
|
9243
|
-
// 每个任务一批新的 iframe:上一批的深浅色、接口都不留(不然拿到上一批「已就绪」的就截了)
|
|
9244
|
-
ghostApis.current.clear()
|
|
9245
|
-
setBackFrames({ list, size, at, dark, batch: ++ghostBatch.current }) // 深浅色跟点导出时的走,和文件名对得上
|
|
9246
|
-
const get = (k) => {
|
|
9247
|
-
const i = place.get(k)
|
|
9248
|
-
if (i !== undefined && (i < at || i >= at + LIVE_MAX)) { at = i; setBackFrames((b) => (b ? { ...b, at: i } : b)) }
|
|
9249
|
-
return (back.has(k) ? ghostApis.current : apis.current).get(k)
|
|
9250
|
-
}
|
|
9251
|
-
try { return await fn({ get }) } finally { setBackFrames(null) }
|
|
9252
|
-
}
|
|
9253
|
-
// 背后挂的屏一次只给一个任务用(预检和导出撞上,会互相把对方要的那批撤掉)
|
|
9254
|
-
const job = ghostQueue.current.then(run, run)
|
|
9255
|
-
ghostQueue.current = job.catch(() => {})
|
|
9256
|
-
return job
|
|
9257
|
-
}
|
|
9258
|
-
const measureAll = async (map) => {
|
|
9259
|
-
const stamp = designSeq.current
|
|
9260
|
-
const list = []
|
|
9261
|
-
for (const sc of shown) {
|
|
9262
|
-
if (designSeq.current !== stamp) break // 设计换了:别再等旧的屏
|
|
9263
|
-
try { const api = await apiOf(sc, map); list.push(await api.measure()) } catch (e) { console.warn('[dsh-design-studio] 量页面失败', sc.key, e); list.push({ failed: true }) }
|
|
9264
|
-
}
|
|
9265
|
-
return list
|
|
9266
|
-
}
|
|
9267
|
-
|
|
9268
|
-
const doExport = async (mode, key, opts) => {
|
|
9269
|
-
setExMenu(false)
|
|
9270
|
-
if (mode === 'opts') { if (pane !== 'export') openPane('export'); return }
|
|
9271
|
-
if (mode === 'zip') return openPack(fileTarget ? st.target.root : '')
|
|
9272
|
-
if (mode === 'share') return openShare(fileTarget ? st.target.root : '')
|
|
9273
|
-
say(t('exporting'))
|
|
9274
|
-
const design = designNow.current
|
|
9275
|
-
const stamp = designSeq.current
|
|
9276
|
-
const gone = () => designSeq.current !== stamp
|
|
9277
|
-
const aiShot = new Set() // 这次导出截到的 AI 示意图(每次导出各记各的,连着导出不串)
|
|
9278
|
-
try {
|
|
9279
|
-
const prefix = ver ? `v${ver.n}-` : ''
|
|
9280
|
-
const suffix = dark ? '-dark' : ''
|
|
9281
|
-
if (mode === 'pdf' || mode === 'pptx') {
|
|
9282
|
-
// 每屏一页。PDF 里网页、邮件放整页长图(页面多高就多高);PPT 一张幻灯片一个画面。选项面板里可以改
|
|
9283
|
-
const fit = (opts && opts.fit) || ''
|
|
9284
|
-
const long = fit === 'page' || fit === 'height' || (!fit && mode === 'pdf' && (kind === 'web' || kind === 'email'))
|
|
9285
|
-
const maxH = fit === 'height' ? Number(opts.fitH) || 0 : 0
|
|
9286
|
-
let deadN = 0
|
|
9287
|
-
await withFrames(async (map) => {
|
|
9288
|
-
// 从菜单直接点:先量一遍,有内容会被裁就先给看清单(同样的结果只拦一次)
|
|
9289
|
-
if (!opts) {
|
|
9290
|
-
const seen = await measureAll(map)
|
|
9291
|
-
const rep = precheckOf(seen, kind, long ? Infinity : 0)
|
|
9292
|
-
deadN = rep.dead
|
|
9293
|
-
const sig = rep.over || rep.long || rep.moved ? [design, shown.map(ik).join(','), size.join('x'), long ? 1 : 0, seen.map((m) => (m.failed ? '-' : `${m.pageW}x${m.pageH}`)).join(',')].join('|') : ''
|
|
9294
|
-
if (sig && warned.current !== sig) {
|
|
9295
|
-
warned.current = sig
|
|
9296
|
-
say(t('xoWarn'))
|
|
9297
|
-
if (pane !== 'export') openPane('export')
|
|
9298
|
-
return
|
|
9299
|
-
}
|
|
9300
|
-
}
|
|
9301
|
-
const pages = []
|
|
9302
|
-
const keys = []
|
|
9303
|
-
for (const sc of shown) {
|
|
9304
|
-
if (gone()) break
|
|
9305
|
-
try {
|
|
9306
|
-
const r = await captureOf(sc, long, map, maxH, aiShot)
|
|
9307
|
-
const cut = maxH && r.h > maxH
|
|
9308
|
-
pages.push({ jpg: await jpegB64(cut ? cropImg(r.img, r.h, maxH) : r.img), w: r.w, h: cut ? maxH : r.h, title: exportTitle(sc, r), links: r.links })
|
|
9309
|
-
keys.push(sc.key)
|
|
9310
|
-
} catch (e) { console.warn('[dsh-design-studio] 截图失败', sc.key, e) }
|
|
9311
|
-
}
|
|
9312
|
-
if (gone()) { say(t('xoGone')); return }
|
|
9313
|
-
if (!pages.length) throw new Error('no screens')
|
|
9314
|
-
// 原型里的跳转:路径换成第几页,PDF / PPT 里点了能跳过去
|
|
9315
|
-
for (const p of pages) {
|
|
9316
|
-
p.links = p.links.map((l) => ({ x: l.x, y: l.y, w: l.w, h: l.h, to: keys.indexOf(keyOfPath(l.path, fileTarget)) })).filter((l) => l.to >= 0)
|
|
9317
|
-
}
|
|
9318
|
-
const sp = splitTitles(pages.map((x) => x.title))
|
|
9319
|
-
const folder = st && st.target && st.target.kind === 'file' ? String(st.target.file).split(/[\\/]/).slice(-2, -1)[0] : ''
|
|
9320
|
-
const title = sp.brand || folder || st.label || ''
|
|
9321
|
-
const layout = opts ? (opts.layout === 'custom' ? opts.custom.trim() : opts.layout === 'auto' ? '' : opts.layout) : ''
|
|
9322
|
-
const cols = opts && opts.cols === 2 ? 2 : 1
|
|
9323
|
-
const r = await post('doc', { session: sid, format: mode, name: prefix + (title || 'design') + suffix, title, bg: hexOf(pickColors(tokens).bg), pages, layout, cols, target: targetKey })
|
|
9324
|
-
const file = String(r.path || '').split(/[\\/]/).pop()
|
|
9325
|
-
const miss = shown.length - pages.length
|
|
9326
|
-
const sheets = Math.ceil(pages.length / cols)
|
|
9327
|
-
say((miss ? t('exportedDocMiss', { name: file, n: sheets, miss }) : t('exportedDoc', { name: file, n: sheets })) + (deadN ? ' · ' + t('xoDead', { n: deadN }) : '') + aiTail(aiShot), { label: t('reveal'), run: () => post('reveal', { path: r.path }).catch(() => {}) })
|
|
9328
|
-
})
|
|
9329
|
-
return
|
|
9330
|
-
}
|
|
9331
|
-
if (mode === 'show') {
|
|
9332
|
-
const shots = []
|
|
9333
|
-
await withFrames(async (map) => {
|
|
9334
|
-
for (const sc of shown) {
|
|
9335
|
-
if (gone()) break
|
|
9336
|
-
try { const c = await captureOf(sc, false, map, 0, aiShot); shots.push({ img: c.img, top: c.top, title: exportTitle(sc, c) }) } catch (e) { console.warn('[dsh-design-studio] 截图失败', sc.key, e) }
|
|
9337
|
-
}
|
|
9338
|
-
})
|
|
9339
|
-
if (gone()) { say(t('xoGone')); return }
|
|
9340
|
-
if (!shots.length) throw new Error('no screens')
|
|
9341
|
-
const sp = splitTitles(shots.map((x) => x.title))
|
|
9342
|
-
const colors = pickColors(tokens)
|
|
9343
|
-
const blob = await composeShowcase({
|
|
9344
|
-
kind,
|
|
9345
|
-
size,
|
|
9346
|
-
shots: shots.map((x, i) => ({ img: x.img, top: x.top, label: sp.labels[i] || x.title })),
|
|
9347
|
-
os: meta.os,
|
|
9348
|
-
title: sp.brand || (st && st.target && st.target.kind === 'file' ? String(st.target.file).split(/[\\/]/).slice(-2, -1)[0] : st.label) || '',
|
|
9349
|
-
sub: t('showSub', { n: shots.length, kind: t(KIND_KEY[kind]), date: ymd(new Date()) }),
|
|
9350
|
-
bg: colors.bg,
|
|
9351
|
-
accent: colors.accent || ACCENT,
|
|
9352
|
-
mark: t('madeWith'),
|
|
9353
|
-
})
|
|
9354
|
-
await saveImage(prefix + (sp.brand || 'showcase') + suffix, blob, aiShot)
|
|
9355
|
-
return
|
|
9356
|
-
}
|
|
9357
|
-
const k = key || (canvas ? sel || focus : focus)
|
|
9358
|
-
const sc = shown.find((x) => x.key === k) || shown[0]
|
|
9359
|
-
if (!sc) throw new Error('no screen')
|
|
9360
|
-
const base = prefix + sc.key.replace(/\.html?$/i, '') + suffix
|
|
9361
|
-
// 画布屏多的时候这屏可能没挂着(镜头一动也可能撤掉):在背后单独挂一份来截
|
|
9362
|
-
let shot = null
|
|
9363
|
-
if (canvas && shown.length > LIVE_MAX) await withFrames(async (map) => { shot = await captureOf(sc, mode === 'long', map, 0, aiShot) }, [sc])
|
|
9364
|
-
else shot = await captureOf(sc, mode === 'long', undefined, 0, aiShot)
|
|
9365
|
-
if (gone()) { say(t('xoGone')); return }
|
|
9366
|
-
const { img, top } = shot
|
|
9367
|
-
if (mode === 'frame') await saveImage(base, await composeOne(kind, size, img, labelOf(sc), top, meta.os), aiShot)
|
|
9368
|
-
else {
|
|
9369
|
-
const c = document.createElement('canvas')
|
|
9370
|
-
c.width = img.width
|
|
9371
|
-
c.height = img.height
|
|
9372
|
-
c.getContext('2d').drawImage(img, 0, 0)
|
|
9373
|
-
await saveImage(base + (mode === 'long' ? '-full' : mode === 'raw' && FRAMED[kind] ? '-plain' : ''), await canvasBlob(c), aiShot)
|
|
9374
|
-
}
|
|
9375
|
-
} catch (e) {
|
|
9376
|
-
say(e.message === 'designChanged' ? t('xoGone') : t('exportFail', { msg: e.message }))
|
|
9622
|
+
// 本地文件的设计才有图(开发服务器的页面不在后台另开);看旧版本时也没有。目录里一有改动地址就变,没变的那几屏服务端直接给缓存。
|
|
9623
|
+
// 地址带上目录:换了设计服务端就不给(晚到的回包也不会把上一套的图挂到这套上);换设计 / 画幅 / 深浅色时整个 Snap 重来,不留旧图
|
|
9624
|
+
const snapId = fileTarget && sid ? `session=${encodeURIComponent(sid)}&root=${encodeURIComponent(curRoot)}&w=${size[0]}&h=${size[1]}&dark=${dark ? 1 : 0}` : ''
|
|
9625
|
+
const snapQ = snapId ? `${snapId}&r=${(st && st.changedAt) || 0}&t=${encodeURIComponent((st && st.trust) || '')}&lw=${encodeURIComponent((st && st.watch) || '')}` : ''
|
|
9626
|
+
const sleepScreen = (sc, z) => h(Device, { kind, w: size[0], h: size[1], fill: false, label: labelOf(sc), top: tops[ik(sc)], os: meta.os },
|
|
9627
|
+
h('div', { className: 'ddp-scr' + (dark ? ' dk' : '') },
|
|
9628
|
+
h('div', { className: 'ddp-away', style: { fontSize: 13 / Math.max(0.25, z || 1) } }, t('canvasAsleep')),
|
|
9629
|
+
snapQ && !sc.v ? h(Snap, { key: snapId + '&key=' + sc.key, src: `${API}scrthumb?${snapQ}&key=${encodeURIComponent(sc.key)}`, blind: /^off/.test((st && st.watch) || ''), onTitle: (title) => snapTitled(sc.key, title) }) : null))
|
|
9630
|
+
|
|
9631
|
+
// 那一屏的接口(截图、体检、业务标注都用);刚载入的等它就绪
|
|
9632
|
+
const apiOf = async (sc, map = apis.current) => {
|
|
9633
|
+
const tries = map === apis.current ? 40 : 120 // 背后现挂的要等它载完
|
|
9634
|
+
let api = map.get(ik(sc))
|
|
9635
|
+
for (let i = 0; i < tries && !(api && api.ready()); i++) {
|
|
9636
|
+
await new Promise((r) => setTimeout(r, 150))
|
|
9637
|
+
api = map.get(ik(sc))
|
|
9377
9638
|
}
|
|
9639
|
+
if (!api) throw new Error('not loaded')
|
|
9640
|
+
return api
|
|
9641
|
+
}
|
|
9642
|
+
const targetKey = st && st.target ? (st.target.kind === 'file' ? `file|${st.target.root}` : `proxy|${st.target.port}`) : ''
|
|
9643
|
+
// ── 导出图片(makeExporter)──
|
|
9644
|
+
const { withFrames, measureAll, exportShots } = makeExporter({ apiOf, targetKey, sid, st, kind, size, dark, meta, tokens, t, say, canvas, focus, sel, shown, ik, labelOf, infoOf, fileTarget, ver, apis, designNow, designSeq, ghostApis, ghostBatch, ghostQueue, setBackFrames, warned,
|
|
9645
|
+
onWarn: () => { if (pane !== 'export') openPane('export') } })
|
|
9646
|
+
const designId = JSON.stringify([sid, targetKey, ver ? ver.n : 0])
|
|
9647
|
+
if (designNow.current !== designId) { designNow.current = designId; designSeq.current++ }
|
|
9648
|
+
const doExport = async (mode, key, opts) => {
|
|
9649
|
+
setExMenu(false)
|
|
9650
|
+
if (mode === 'opts') { if (pane !== 'export') openPane('export'); return }
|
|
9651
|
+
if (mode === 'zip') return openPack(fileTarget ? st.target.root : '')
|
|
9652
|
+
if (mode === 'share') return openShare(fileTarget ? st.target.root : '')
|
|
9653
|
+
return exportShots(mode, key, opts)
|
|
9378
9654
|
}
|
|
9379
9655
|
|
|
9380
9656
|
const doRestore = () => {
|
|
@@ -9451,52 +9727,9 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
9451
9727
|
const flows = canvas && !inMulti && !picking && !textEdit ? flowsOf(shown, (sc) => (infoOf(ik(sc)) || {}).links, fileTarget) : []
|
|
9452
9728
|
|
|
9453
9729
|
// ── 设计体检:画布上量所有屏,单页量这一屏;问题标在页面上,列在面板里 ──
|
|
9454
|
-
|
|
9455
|
-
|
|
9456
|
-
|
|
9457
|
-
if (ck) for (const sc of ck.list || []) { const a = apis.current.get(ik(sc)); if (a) a.checkClear() }
|
|
9458
|
-
setCk(null)
|
|
9459
|
-
}
|
|
9460
|
-
// 画布屏多的时候只量挂着的(别的没有页面可量)
|
|
9461
|
-
const checkList = () => (canvas ? (shown.length > LIVE_MAX ? shown.filter((sc) => apis.current.has(ik(sc))) : shown) : [shown.find((x) => x.key === focus) || { key: focus, url, label: st.label }])
|
|
9462
|
-
// 几屏一起量(各量各的 iframe),一屏卡住不拖累别的
|
|
9463
|
-
const measure = (list, quiet) => Promise.all(list.map(async (sc) => {
|
|
9464
|
-
const row = { key: sc.key, v: sc.v, label: labelOf(sc), url: sc.url, issues: [] }
|
|
9465
|
-
try {
|
|
9466
|
-
const r = await (await apiOf(sc)).check(kind, quiet)
|
|
9467
|
-
row.issues = Array.isArray(r.issues) ? r.issues : []
|
|
9468
|
-
if (r.metrics && typeof r.metrics === 'object') row.metrics = r.metrics
|
|
9469
|
-
} catch (e) { row.error = e.message }
|
|
9470
|
-
return row
|
|
9471
|
-
}))
|
|
9472
|
-
const total = (list) => list.reduce((m, x) => m + x.issues.length, 0)
|
|
9473
|
-
const runCheck = async () => {
|
|
9474
|
-
setPanel(false); setHist(false); setPhone(false); setAn(false)
|
|
9475
|
-
setCk({ running: true, list: [] })
|
|
9476
|
-
const g = ++ckGen.current
|
|
9477
|
-
ckOpen.current = true
|
|
9478
|
-
const out = await measure(checkList(), false)
|
|
9479
|
-
if (g !== ckGen.current) { // 量的时候面板关了 / 又量了一轮:这份结果作废;面板关着的话,这一轮画上的标记也清掉
|
|
9480
|
-
if (!ckOpen.current) for (const sc of out) { const a = apis.current.get(ik(sc)); if (a) a.checkClear() }
|
|
9481
|
-
return out
|
|
9482
|
-
}
|
|
9483
|
-
if (canvas && shown.length > LIVE_MAX) say(t('checkPartial', { n: out.length }))
|
|
9484
|
-
setCk({ running: false, list: out })
|
|
9485
|
-
setCkCount(total(out))
|
|
9486
|
-
// 有问题的第一屏被面板挡着、在画布外面:挪过来
|
|
9487
|
-
const first = out.find((x) => x.issues.length)
|
|
9488
|
-
if (canvas && first) setReveal((r) => ({ key: first.key, n: ((r && r.n) || 0) + 1 }))
|
|
9489
|
-
return out
|
|
9490
|
-
}
|
|
9491
|
-
const focusIssue = (key, i) => {
|
|
9492
|
-
const sc = (ck && ck.list.find((x) => x.key === key)) || null
|
|
9493
|
-
if (!sc) return
|
|
9494
|
-
if (canvas) { setSel(key); setReveal((r) => ({ key, n: ((r && r.n) || 0) + 1 })) }
|
|
9495
|
-
// 屏多的时候这屏可能撤过(重新载入后页面里的体检标记没了):等它挂上,量一遍再定位
|
|
9496
|
-
if (canvas && shown.length > LIVE_MAX) { apiOf(sc).then((api) => api.check(kind, false).then(() => api.checkFocus(i))).catch((e) => console.warn('[dsh-design-studio] 定位问题失败', key, e)); return }
|
|
9497
|
-
const a = apis.current.get(ik(sc))
|
|
9498
|
-
if (a) a.checkFocus(i)
|
|
9499
|
-
}
|
|
9730
|
+
// 设计体检:量、开面板、定位、交给模型(makeCheck)
|
|
9731
|
+
const { closeCheck, checkList, measure, total, runCheck, focusIssue, fixIssues } = makeCheck({ kind, url, st, stRef, canvas, shown, focus, ik, labelOf, apis, apiOf, ck, setCk, ckGen, ckOpen, setCkCount, setReveal, setSel, insert, say, t,
|
|
9732
|
+
onOpen: () => { setPanel(false); setHist(false); setPhone(false); setAn(false) } })
|
|
9500
9733
|
// 打开一套设计、模型又干完一轮(turns 变了):面板开着就再查一次(改没改好一眼看到);关着就悄悄量一下,问题数标在按钮上。
|
|
9501
9734
|
// 模型干着活时不量;等一会儿再量:刚写完的屏还在刷新、播生成动画
|
|
9502
9735
|
const autoCk = useRef(null)
|
|
@@ -9537,13 +9770,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
9537
9770
|
}, 1500)
|
|
9538
9771
|
return () => clearTimeout(timer)
|
|
9539
9772
|
}, [ckReq])
|
|
9540
|
-
const fixIssues = () => {
|
|
9541
|
-
if (!ck) return
|
|
9542
|
-
insert(formatCheck(t, ck.list, stRef.current), 'insertedSend')
|
|
9543
|
-
closeCheck()
|
|
9544
|
-
}
|
|
9545
9773
|
const checkOff = !url || !!ver || !!demo || inMulti
|
|
9546
|
-
|
|
9547
9774
|
// ── 业务标注(插件页的试验开关开着才有 st.annotations 这个键):面板和体检、版本共用右边那个位置;点选、改字、调样式、画笔时编号收起,退出后回来 ──
|
|
9548
9775
|
useEffect(() => { setAnStates({}) }, [anFile ? anFile.sig : '']) // 文件变了(模型改过选择器):别的屏的旧结果作废,等页面重新报
|
|
9549
9776
|
const toggleAn = () => {
|
|
@@ -9599,185 +9826,8 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
9599
9826
|
// 换了设计、看旧版本、演示:画的东西对不上了,收掉
|
|
9600
9827
|
useEffect(() => { markRun.current++; setMark(false) }, [url, markOff])
|
|
9601
9828
|
// 台面上现在看得到的每一屏:页面 iframe 的位置(台面坐标,画布缩放过的也对),一点没露出来的不要
|
|
9602
|
-
|
|
9603
|
-
|
|
9604
|
-
if (!stage) return []
|
|
9605
|
-
const sr = stage.getBoundingClientRect()
|
|
9606
|
-
const out = []
|
|
9607
|
-
for (const sc of shown) {
|
|
9608
|
-
const api = apis.current.get(ik(sc))
|
|
9609
|
-
const f = api && typeof api.frame === 'function' ? api.frame() : null
|
|
9610
|
-
if (!f) continue
|
|
9611
|
-
const r = f.getBoundingClientRect()
|
|
9612
|
-
if (r.width < 8 || r.height < 8 || r.right <= sr.left || r.left >= sr.right || r.bottom <= sr.top || r.top >= sr.bottom) continue
|
|
9613
|
-
if (typeof f.checkVisibility === 'function' && !f.checkVisibility({ opacityProperty: true, visibilityProperty: true })) continue
|
|
9614
|
-
out.push({ key: ik(sc), sc, api, f, l: r.left - sr.left, t: r.top - sr.top, w: r.width, h: r.height, z: r.width / Math.max(1, f.offsetWidth) })
|
|
9615
|
-
}
|
|
9616
|
-
return out
|
|
9617
|
-
}
|
|
9618
|
-
const MARK_SHOTS = 40
|
|
9619
|
-
// 截到的是哪一页(只用来起名、写进提示):本地文件按文件名;开发服务器按路由(/account);单页应用的 #/account 路由带上
|
|
9620
|
-
const markPageOf = (sc, href) => {
|
|
9621
|
-
let key = pageOf(sc, href).key
|
|
9622
|
-
try {
|
|
9623
|
-
const u = new URL(href)
|
|
9624
|
-
if (u.origin !== new URL(sc.url).origin) return key
|
|
9625
|
-
if (key === sc.key && st && st.target && st.target.kind === 'proxy') key = decodeURIComponent(u.pathname) || sc.key
|
|
9626
|
-
if (/^#!?\//.test(u.hash)) key += decodeURIComponent(u.hash)
|
|
9627
|
-
} catch { /* 地址不对 */ }
|
|
9628
|
-
return key
|
|
9629
|
-
}
|
|
9630
|
-
// 把画的拼成一张图:画到的那几屏按现在的位置截图,叠上画的(交给模型、复制共用)
|
|
9631
|
-
const buildMark = async (list, stage) => {
|
|
9632
|
-
const sr = stage.getBoundingClientRect()
|
|
9633
|
-
const all = markFrames().filter((x) => x.api.ready())
|
|
9634
|
-
const ov = (a, b) => a.l < b.r && a.r > b.l && a.t < b.b && a.b > b.t
|
|
9635
|
-
const boxOf = (x) => ({ l: x.l, t: x.t, r: x.l + x.w, b: x.t + x.h })
|
|
9636
|
-
// 画到的那几屏(一屏都没碰到:画在屏外空白处的,就把看得到的都拼上)
|
|
9637
|
-
const marks = list.map(markBox)
|
|
9638
|
-
let shots = all.filter((x) => marks.some((m) => ov(boxOf(x), m)))
|
|
9639
|
-
if (!shots.length) shots = all
|
|
9640
|
-
// 裁到有东西的那块(画到的屏 + 画的),四周留一点;落在这块里的别的屏也拼上,免得图上空一块
|
|
9641
|
-
const pad = 16
|
|
9642
|
-
const span = (bs) => ({
|
|
9643
|
-
l: Math.max(0, Math.min(...bs.map((b) => b.l)) - pad),
|
|
9644
|
-
t: Math.max(0, Math.min(...bs.map((b) => b.t)) - pad),
|
|
9645
|
-
r: Math.min(sr.width, Math.max(...bs.map((b) => b.r)) + pad),
|
|
9646
|
-
b: Math.min(sr.height, Math.max(...bs.map((b) => b.b)) + pad),
|
|
9647
|
-
})
|
|
9648
|
-
const crop = span([...shots.map(boxOf), ...marks])
|
|
9649
|
-
shots = all.filter((x) => shots.includes(x) || ov(boxOf(x), crop))
|
|
9650
|
-
const { l: cl, t: ct, r: cr, b: cb } = crop
|
|
9651
|
-
if (!(cr - cl >= 1 && cb - ct >= 1)) throw new Error('empty')
|
|
9652
|
-
// 清晰度:至少按屏幕像素;画布缩小着看的,按页面原来的大小截(最多 4 倍),整张不超过 4096
|
|
9653
|
-
const zMin = Math.min(1, ...shots.map((x) => x.z))
|
|
9654
|
-
const k = Math.min(4096 / Math.max(cr - cl, cb - ct), Math.max(Math.min(2, Math.max(1, window.devicePixelRatio || 1)), Math.min(4, 1 / Math.max(0.05, zMin))))
|
|
9655
|
-
const c = document.createElement('canvas')
|
|
9656
|
-
c.width = Math.max(1, Math.round((cr - cl) * k))
|
|
9657
|
-
c.height = Math.max(1, Math.round((cb - ct) * k))
|
|
9658
|
-
const ctx = c.getContext('2d')
|
|
9659
|
-
let bg = ''
|
|
9660
|
-
for (let el = stage; el && !bg; el = el.parentElement) {
|
|
9661
|
-
const v = getComputedStyle(el).backgroundColor
|
|
9662
|
-
if (v && !/^(transparent|rgba\(.*,\s*0\))$/.test(v)) bg = v
|
|
9663
|
-
}
|
|
9664
|
-
ctx.fillStyle = bg || '#f4f4f5'
|
|
9665
|
-
ctx.fillRect(0, 0, c.width, c.height)
|
|
9666
|
-
if (shots.length > MARK_SHOTS) say(t('mkMany', { n: MARK_SHOTS }))
|
|
9667
|
-
const names = []
|
|
9668
|
-
for (const [i, x] of shots.entries()) {
|
|
9669
|
-
const X = (x.l - cl) * k
|
|
9670
|
-
const Y = (x.t - ct) * k
|
|
9671
|
-
// 手机框的圆角:往上找一层裁圆角的
|
|
9672
|
-
let rad = 0
|
|
9673
|
-
for (let el = x.f.parentElement, j = 0; el && el !== stage && j < 4 && !rad; el = el.parentElement, j++) {
|
|
9674
|
-
const cs = getComputedStyle(el)
|
|
9675
|
-
const v = parseFloat(cs.borderTopLeftRadius) || 0
|
|
9676
|
-
if (v && cs.overflow !== 'visible' && el.offsetWidth) rad = v * (el.getBoundingClientRect().width / el.offsetWidth)
|
|
9677
|
-
}
|
|
9678
|
-
ctx.save()
|
|
9679
|
-
ctx.beginPath()
|
|
9680
|
-
if (rad && typeof ctx.roundRect === 'function') ctx.roundRect(X, Y, x.w * k, x.h * k, rad * k)
|
|
9681
|
-
else ctx.rect(X, Y, x.w * k, x.h * k)
|
|
9682
|
-
ctx.clip()
|
|
9683
|
-
let name = x.sc.key
|
|
9684
|
-
try {
|
|
9685
|
-
if (i >= MARK_SHOTS) throw new Error('too many')
|
|
9686
|
-
const cap = await x.api.capture({ full: false, scale: Math.min(3, Math.max(1, x.z * k)) })
|
|
9687
|
-
// 页面里点链接跳到别的页了:按真正截到的那页起名
|
|
9688
|
-
if (cap.href) name = markPageOf(x.sc, cap.href)
|
|
9689
|
-
const img = await loadImg(cap.png)
|
|
9690
|
-
ctx.fillStyle = '#fff'
|
|
9691
|
-
ctx.fillRect(X, Y, x.w * k, x.h * k)
|
|
9692
|
-
ctx.drawImage(img, X, Y, cap.w * x.z * k, cap.h * x.z * k)
|
|
9693
|
-
} catch (e) {
|
|
9694
|
-
// 这一屏截不下来:留个灰块,画的东西还在
|
|
9695
|
-
if (i < MARK_SHOTS) console.warn('[dsh-design-studio] 标注截图失败', x.sc.key, e)
|
|
9696
|
-
ctx.fillStyle = 'rgba(127,127,127,.18)'
|
|
9697
|
-
ctx.fillRect(X, Y, x.w * k, x.h * k)
|
|
9698
|
-
}
|
|
9699
|
-
ctx.restore()
|
|
9700
|
-
if (!names.includes(name)) names.push(name)
|
|
9701
|
-
}
|
|
9702
|
-
for (const s of list) drawMark(ctx, s, k, cl, ct)
|
|
9703
|
-
return { c, names, blob: await canvasBlob(c) }
|
|
9704
|
-
}
|
|
9705
|
-
const sendMark = async (list) => {
|
|
9706
|
-
if (markBusy) return
|
|
9707
|
-
if (!list.length) { say(t('mkEmpty')); return }
|
|
9708
|
-
const stage = stageRef.current
|
|
9709
|
-
if (!stage) return
|
|
9710
|
-
const url0 = url
|
|
9711
|
-
const run0 = markRun.current
|
|
9712
|
-
const stale = () => stRef.current.url !== url0 || markRun.current !== run0
|
|
9713
|
-
const root0 = st && st.target && st.target.kind === 'file' ? st.target.root : null
|
|
9714
|
-
setMarkBusy(true)
|
|
9715
|
-
try {
|
|
9716
|
-
const { c, names, blob } = await buildMark(list, stage)
|
|
9717
|
-
// 拼图的时候换了设计、关了标注:这张图对不上了,别交
|
|
9718
|
-
if (stale()) { if (stRef.current.url !== url0) say(t('mkMoved')); return }
|
|
9719
|
-
if (!names.length && curScreen) names.push(curScreen.key)
|
|
9720
|
-
const stem = String(names[0] || 'page').replace(/\.html?(?=$|#)/i, '').split(/[/#!]+/).filter(Boolean).pop() || 'page'
|
|
9721
|
-
const body = { session: sid, name: `markup-${stem}`, data: await blobB64(blob) }
|
|
9722
|
-
if (root0 !== null) body.root = root0
|
|
9723
|
-
let saved
|
|
9724
|
-
try { saved = await post('ref', body) } catch (e) {
|
|
9725
|
-
if (/moved/.test(e.message)) { say(t('mkMoved')); return }
|
|
9726
|
-
throw e
|
|
9727
|
-
}
|
|
9728
|
-
if (stale()) { if (stRef.current.url !== url0) say(t('mkMoved')); return }
|
|
9729
|
-
keepThumb(saved.path, c)
|
|
9730
|
-
const where = (names.length ? names : [st.label || '']).join(t('sep'))
|
|
9731
|
-
// 写在图上的字也用文字带上:模型看图看漏了、或者用的模型看不了图,也知道要改什么
|
|
9732
|
-
const notes = list.filter((x) => x.t === 'text').map((x) => t('mkQuote', { v: x.v.replace(/\s*\n\s*/g, ' ') })).join(t('sep'))
|
|
9733
|
-
// 插不进输入框:标注层留着(画的还在),提示再点一次;不退回剪贴板
|
|
9734
|
-
if (insert(t('mkAsk', { path: saved.path, where, notes: notes ? t('mkNotes', { notes }) : '' }), 'mkIn', false)) setMark(false)
|
|
9735
|
-
else say(t('mkNoInput'))
|
|
9736
|
-
} catch (e) {
|
|
9737
|
-
say(t('mkFail', { msg: e.message }))
|
|
9738
|
-
} finally {
|
|
9739
|
-
setMarkBusy(false)
|
|
9740
|
-
}
|
|
9741
|
-
}
|
|
9742
|
-
// 复制:同一张图放进剪贴板(issue #6)。点按钮这一下就把「等图拼好」交给剪贴板——拼完再写,
|
|
9743
|
-
// Safari 这类会说不是用户点的、不让写;不认这种写法的再用拼好的图写一次
|
|
9744
|
-
const copyMark = (list) => {
|
|
9745
|
-
if (markBusy) return
|
|
9746
|
-
if (!list.length) { say(t('mkEmpty')); return }
|
|
9747
|
-
const stage = stageRef.current
|
|
9748
|
-
if (!stage) return
|
|
9749
|
-
const url0 = url
|
|
9750
|
-
const run0 = markRun.current
|
|
9751
|
-
const stale = () => stRef.current.url !== url0 || markRun.current !== run0
|
|
9752
|
-
const STALE = 'ddp-mark-stale'
|
|
9753
|
-
setMarkBusy(true)
|
|
9754
|
-
const made = buildMark(list, stage).then((r) => { if (stale()) throw new Error(STALE); return r })
|
|
9755
|
-
const png = made.then((r) => r.blob)
|
|
9756
|
-
png.catch(() => {}) // 结果在下面看
|
|
9757
|
-
let wrote
|
|
9758
|
-
try { wrote = navigator.clipboard.write([new ClipboardItem({ 'image/png': png })]) } catch (e) { wrote = Promise.reject(e) }
|
|
9759
|
-
wrote.catch(() => {})
|
|
9760
|
-
;(async () => {
|
|
9761
|
-
try {
|
|
9762
|
-
const r = await made
|
|
9763
|
-
if (!(await wrote.then(() => true, () => false))) {
|
|
9764
|
-
// 等写的工夫里取消了、换了设计:别再把这张旧图写进去
|
|
9765
|
-
if (stale()) { if (stRef.current.url !== url0) say(t('mkMoved')); return }
|
|
9766
|
-
if (!(await copyImage(r.blob))) { say(t('mkCopyFail')); return }
|
|
9767
|
-
}
|
|
9768
|
-
if (stale()) return
|
|
9769
|
-
say(t('mkCopied'))
|
|
9770
|
-
setMark(false)
|
|
9771
|
-
} catch (e) {
|
|
9772
|
-
if (e && e.message === STALE) { if (stRef.current.url !== url0) say(t('mkMoved')) } else {
|
|
9773
|
-
console.warn('[dsh-design-studio] 标注图复制失败', e)
|
|
9774
|
-
say(t('mkCopyFail'))
|
|
9775
|
-
}
|
|
9776
|
-
} finally {
|
|
9777
|
-
setMarkBusy(false)
|
|
9778
|
-
}
|
|
9779
|
-
})()
|
|
9780
|
-
}
|
|
9829
|
+
// 画笔标注:拼图、交给模型、复制(makeMarkup)
|
|
9830
|
+
const { markFrames, sendMark, copyMark } = makeMarkup({ sid, st, stRef, url, shown, ik, apis, stageRef, markRun, markBusy, setMarkBusy, setMark, curScreen, insert, say, t })
|
|
9781
9831
|
useEffect(() => { if (styleOff) setStyleEdit(false) }, [styleOff])
|
|
9782
9832
|
autoCk.current = { ck, off: checkOff, run: runCheck, list: checkList, measure }
|
|
9783
9833
|
// 屏数超过上限:不声不响地少几屏,用户会以为没生成
|
|
@@ -10358,14 +10408,18 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
10358
10408
|
const has = now && ver.screens.includes(now.key)
|
|
10359
10409
|
const old = now ? { key: now.key, id: `v${ver.n}|${now.key}`, v: ver.n, url: vbase + encodeURIComponent(now.key), label: now.label } : null
|
|
10360
10410
|
// 右边开着版本面板:手机这类有外框的让到面板左边(和单看时一样)
|
|
10361
|
-
const
|
|
10362
|
-
|
|
10411
|
+
const cmpSide = !!(ck || styleEdit || panel || pane || hist || phone) && box.w - 296 >= 240
|
|
10412
|
+
// 网页铺满时也让(#22):按铺满时的大小定住(上面有版本横幅,少 46),整体缩到面板左边,不重排
|
|
10413
|
+
const cmpLock = fill && cmpSide ? { w: box.w, h: ah - 46 } : null
|
|
10414
|
+
const aside = cmpSide && (!fill || cmpLock) ? 296 : 0
|
|
10415
|
+
const flat = fill && !cmpLock
|
|
10416
|
+
const z = cmpLock ? Math.max(0.05, Math.min(1, (box.w - aside - 32) / cmpLock.w)) : fill ? 1 : Math.max(0.05, Math.min(1, (box.w - aside - 32) / dw, (ah - 16 - (ver ? 46 : 0)) / dh))
|
|
10363
10417
|
// 两边的小标签不跟着画面缩小(缩了看不清);手机、平板躲开状态栏
|
|
10364
10418
|
const tagAt = (side) => ({ top: kind === 'app' || kind === 'miniprogram' || kind === 'tablet' ? 60 : 10, transform: `scale(${1 / z})`, transformOrigin: 'top ' + side })
|
|
10365
10419
|
const screenOf = (sc) => h(Screen, { t, remote, onPageDrag: pageDrag, src: sc.url, label: labelOf(sc), busy: false, born: false, picking: false, dark, zoom: z, reloadSeq,
|
|
10366
10420
|
apis: apis.current, apiKey: 'cmp|' + ik(sc), onMeta: (m, title, toks, dk) => remember(ik(sc), m, title, toks, dk), onTop: (dk) => setTop(ik(sc), dk) })
|
|
10367
10421
|
body = h('div', { className: 'ddp-single', style: aside ? { right: aside } : undefined },
|
|
10368
|
-
h('div', { className: 'ddp-fit' + (
|
|
10422
|
+
h('div', { className: 'ddp-fit' + (flat ? ' fill' : ''), style: flat ? undefined : { width: cmpLock ? cmpLock.w : dw, height: cmpLock ? cmpLock.h : dh, transform: `translate(-50%, -50%) scale(${z})` } },
|
|
10369
10423
|
// 胶囊那块露的是哪一边(把手拖过胶囊中间就是左边那一版),胶囊就跟哪一边的顶栏
|
|
10370
10424
|
now ? h(Device, { kind, w: size[0], h: size[1], fill, label: labelOf(now), top: tops[ik(has && (cx / 100) * size[0] > size[0] - CAP.right - CAP.w / 2 ? old : now)], os: meta.os },
|
|
10371
10425
|
h('div', { className: 'ddp-cmp' + (cmpDrag ? ' drag' : ''), ref: cmpRef },
|
|
@@ -10407,22 +10461,25 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
10407
10461
|
} else {
|
|
10408
10462
|
// 右边开着面板(体检、调样式、设计规范、换风格):手机这类有外框的让到面板左边(侧栏够宽时),别被挡住
|
|
10409
10463
|
const sideOn = !!(anUp || ck || styleEdit || panel || pane || hist || phone) && box.w - 296 >= 240
|
|
10410
|
-
|
|
10464
|
+
// 网页铺满时右边开着面板(业务标注、体检、调样式…,#22):按现在的大小定住、整体缩到面板左边,不重排,右边的内容也不被挡
|
|
10465
|
+
// 高度按铺满时真有的那么高:上面挂着横幅(看旧版本)时少 46,和下面 .ddp-body 的 vb 一样算
|
|
10466
|
+
const sideLock = fill && sideOn && !mark ? { w: box.w, h: ah - (ver || demo || hintTop ? 46 : 0) } : null
|
|
10467
|
+
const aside = sideOn && (!fill || sideLock) ? 296 : 0
|
|
10411
10468
|
// 生成中:右侧栏窄(或开着面板)时状态条在上排浮块下面,手机这类给它让一条;宽的时候它在上排中间,不用让。网页不让(一让就重排)
|
|
10412
10469
|
busyGap = busy && !fill && (anOn || box.w < 860 || sideOn)
|
|
10413
10470
|
// 画笔标注开着:网页按开标注时的大小定住(侧栏拉窄了就整体缩小,不重排),画的才对得上
|
|
10414
|
-
const lock = fill && mark && markSize ? markSize :
|
|
10415
|
-
const z = lock ? Math.max(0.05, Math.min(1, box.w / lock.w, ah / lock.h)) : fill ? 1 : Math.max(0.05, Math.min(1, (box.w - aside - 32) / dw, (ah - 16 - (ver || hintTop || busyGap ? 46 : 0)) / dh))
|
|
10471
|
+
const lock = fill && mark && markSize ? markSize : sideLock
|
|
10472
|
+
const z = sideLock ? Math.max(0.05, Math.min(1, (box.w - aside - 32) / sideLock.w)) : lock ? Math.max(0.05, Math.min(1, box.w / lock.w, ah / lock.h)) : fill ? 1 : Math.max(0.05, Math.min(1, (box.w - aside - 32) / dw, (ah - 16 - (ver || hintTop || busyGap ? 46 : 0)) / dh))
|
|
10416
10473
|
const one = ver ? shown.find((x) => x.key === focus) || shown[0] || { key: focus, url, label: st.label } : { key: focus, url, label: st.label }
|
|
10417
10474
|
// 单屏时模型在写新的一屏:先看着它写(没在选、改字、调样式、标注的时候),写完换过去
|
|
10418
|
-
const watch = dr && !ver && !demo && !picking && !textEdit && !styleEdit && !mark && !
|
|
10475
|
+
const watch = dr && !ver && !demo && !picking && !textEdit && !styleEdit && !mark && !peekR.current
|
|
10419
10476
|
if (watch) singleDraftR.current = dr.key || '*' // 还不知道是哪屏:名字到了再说
|
|
10420
10477
|
body = h('div', { className: 'ddp-single', style: aside ? { right: aside } : undefined },
|
|
10421
10478
|
h('div', { className: 'ddp-fit' + (fill && !lock ? ' fill' : ''), style: fill && !lock ? undefined : { width: lock ? lock.w : dw, height: lock ? lock.h : dh, transform: `translate(-50%, -50%) scale(${z})` } },
|
|
10422
10479
|
watch
|
|
10423
10480
|
? h(Device, { key: 'draft', kind, w: size[0], h: size[1], fill, label: '', os: meta.os },
|
|
10424
10481
|
h(GhostDraw, { key: 'gd', t, kind, pulse }),
|
|
10425
|
-
h(DraftFrame, { key: 'df', url: dr.url, z: fill ? 1 : z, lang: t('lang'), onEnd: draftEnd }))
|
|
10482
|
+
h(DraftFrame, { key: 'df', url: dr.url, z: fill && !lock ? 1 : z, lang: t('lang'), onEnd: draftEnd }))
|
|
10426
10483
|
: renderScreen(one, z, fill)))
|
|
10427
10484
|
}
|
|
10428
10485
|
|
|
@@ -10655,7 +10712,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
10655
10712
|
// 注意:这里是客户端**服务名**(短的),不是包名
|
|
10656
10713
|
exports.inject = INJECT
|
|
10657
10714
|
// 测试用
|
|
10658
|
-
exports._test = { KIND_LIST, KIND_KEY, KIND_SIZE, META_ALIAS, FIXED, SHOW_COLS, FRAME, ASK_EX, ASK_KINDS, KIND_ICON: I, pollGap, webFitOf, precheckOf, fitCanvas, layoutOk, fitHOk, autoSize, pulseStep, MarketDetail, dragKind, droppedOf, pickInfo, pickLabel, pickRanges, pickRule, chipOf, chipRanges, makeT, ZH, EN, formatCheck, formatTweaks, markHit, markPath, STYLES, formatStyle, accentUse, autoStyle, styleLook, padInsert, pageOf, pxOf, styleChanges, formatStyleAsk, takesOf, formatCheckTool, poller, frameOf, paletteOf, formatRef, layoutRow, keyOfPath, flowsOf, flowLines, flowMarks, formatPick, whereOf, parseMeta, sizeOf, layoutGrid, fitCam, nearestLive, LIVE_MAX, tokenKind, formatToken, splitTitles, pickColors, hhmm, formatTpl, formatPrep, styleFromTokens, myStyleOf, isZipFile }
|
|
10715
|
+
exports._test = { makeDemoNav, KIND_LIST, KIND_KEY, KIND_SIZE, META_ALIAS, FIXED, SHOW_COLS, FRAME, ASK_EX, ASK_KINDS, KIND_ICON: I, pollGap, webFitOf, precheckOf, fitCanvas, layoutOk, fitHOk, autoSize, pulseStep, MarketDetail, dragKind, droppedOf, pickInfo, pickLabel, pickRanges, pickRule, chipOf, chipRanges, makeT, ZH, EN, formatCheck, formatTweaks, markHit, markPath, STYLES, formatStyle, accentUse, autoStyle, styleLook, padInsert, pageOf, pxOf, styleChanges, formatStyleAsk, takesOf, formatCheckTool, poller, frameOf, paletteOf, formatRef, layoutRow, keyOfPath, flowsOf, flowLines, flowMarks, formatPick, whereOf, parseMeta, sizeOf, layoutGrid, fitCam, nearestLive, LIVE_MAX, tokenKind, formatToken, splitTitles, pickColors, hhmm, formatTpl, formatPrep, styleFromTokens, myStyleOf, isZipFile }
|
|
10659
10716
|
return module.exports
|
|
10660
10717
|
},
|
|
10661
10718
|
})
|