dsh-design-studio 0.14.0 → 0.15.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 +291 -39
- package/lib/core.js +39 -17
- package/lib/gallery/pack.js +2 -2
- package/lib/gallery/policy.js +14 -6
- package/lib/gallery/routes.js +2 -2
- package/lib/handoff.js +2 -2
- package/lib/index.js +2 -1
- package/lib/tweaks.js +3 -3
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -32,7 +32,7 @@ window.__ModuleLoader__.load({
|
|
|
32
32
|
return module.exports
|
|
33
33
|
}
|
|
34
34
|
const h = react.createElement
|
|
35
|
-
const { useState, useEffect, useRef, useCallback } = react
|
|
35
|
+
const { useState, useEffect, useRef, useCallback, useMemo } = react
|
|
36
36
|
|
|
37
37
|
const NS = 'dsh-design-studio'
|
|
38
38
|
const TAB_ID = 'dsh-design-studio'
|
|
@@ -523,6 +523,9 @@ window.__ModuleLoader__.load({
|
|
|
523
523
|
screensHd: '屏幕',
|
|
524
524
|
screensAll: '全部 {n} 屏',
|
|
525
525
|
screensN: '{name} · {n} 屏',
|
|
526
|
+
screensHidden: '还有 {n} 屏没显示(最多显示 {max} 屏,最新的优先)',
|
|
527
|
+
canvasAsleep: '挪近就加载',
|
|
528
|
+
checkPartial: '屏太多,这次只体检了画布上加载着的 {n} 屏',
|
|
526
529
|
openOther: '打开别的页面…',
|
|
527
530
|
phoneOnTip: '手机预览开着',
|
|
528
531
|
lookSet: '整套',
|
|
@@ -1324,6 +1327,9 @@ window.__ModuleLoader__.load({
|
|
|
1324
1327
|
screensHd: 'Screens',
|
|
1325
1328
|
screensAll: 'All {n}',
|
|
1326
1329
|
screensN: '{name} · {n} screens',
|
|
1330
|
+
screensHidden: '{n} more not shown (up to {max} screens, newest first)',
|
|
1331
|
+
canvasAsleep: 'Move closer to load',
|
|
1332
|
+
checkPartial: 'Too many screens: checked only the {n} loaded on the canvas',
|
|
1327
1333
|
openOther: 'Open another page…',
|
|
1328
1334
|
phoneOnTip: 'Phone preview is on',
|
|
1329
1335
|
lookSet: 'Overall',
|
|
@@ -1768,6 +1774,8 @@ window.__ModuleLoader__.load({
|
|
|
1768
1774
|
.ddp-menu{position:absolute;right:0;top:33px;min-width:196px;padding:5px;border-radius:11px;background:var(--dsw-alias-bg-layer-1);
|
|
1769
1775
|
box-shadow:0 12px 32px rgba(0,0,0,.24),0 0 0 .5px var(--dsw-alias-border-l3);animation:ddp-in .16s ${EASE}}
|
|
1770
1776
|
.ddp-menu .hd{padding:5px 9px 4px;color:var(--dsw-alias-label-tertiary);font-size:11px}
|
|
1777
|
+
.ddp-menu .nt{padding:5px 9px 4px;color:var(--dsw-alias-label-tertiary);font-size:11px;line-height:1.5}
|
|
1778
|
+
.ddp-addr em.hid{flex:none;font-style:normal;font-size:11px;color:var(--dsw-alias-label-tertiary)}
|
|
1771
1779
|
.ddp-menu a{display:flex;align-items:center;gap:9px;height:30px;padding:0 9px;border-radius:7px;color:var(--dsw-alias-label-primary);text-decoration:none}
|
|
1772
1780
|
.ddp-menu a:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.12))}
|
|
1773
1781
|
.ddp-menu a svg{width:15px;height:15px;flex:none;color:var(--dsw-alias-label-secondary)}
|
|
@@ -1824,6 +1832,7 @@ window.__ModuleLoader__.load({
|
|
|
1824
1832
|
.ddp-world{position:absolute;left:0;top:0;transform-origin:0 0;will-change:transform}
|
|
1825
1833
|
.ddp-world.anim{transition:transform .45s ${EASE}}
|
|
1826
1834
|
.ddp-cell{position:absolute;transition:left .45s ${EASE},top .45s ${EASE};animation:ddp-cell .5s ${EASE}}
|
|
1835
|
+
.ddp-canvas.heavy .ddp-cell{transition:none;will-change:translate,scale}
|
|
1827
1836
|
@keyframes ddp-cell{from{opacity:0;scale:.94}}
|
|
1828
1837
|
.ddp-cell.sel>.ddp-dev{outline:calc(2px / var(--z)) solid ${ACCENT};outline-offset:calc(5px / var(--z))}
|
|
1829
1838
|
.ddp-shield{position:absolute;inset:0;z-index:6;cursor:default}
|
|
@@ -4415,6 +4424,15 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
4415
4424
|
const LAB = 34 // 每屏上面标题占的高度(屏幕像素,不跟着缩放)
|
|
4416
4425
|
const GAP = 18 // 两屏之间最少隔开的屏幕像素
|
|
4417
4426
|
const clampZ = (z) => Math.max(ZMIN, Math.min(ZMAX, z))
|
|
4427
|
+
const HEAVY_N = 12 // 超过这么多屏,画布按「重」的来:拖宽度时只挪镜头、列数变了才重排,换行动画走合成层(不然所有 iframe 每一帧都按新比例重绘,整个窗口跟着闪)
|
|
4428
|
+
const LIVE_MAX = 24 // 同时跑几个 iframe。超过这么多屏,画布只挂镜头附近的(选中的那屏总在),导出时分批挂
|
|
4429
|
+
/** 该挂着的几屏:离镜头中心最近的 max 屏,选中的那屏排最前。cx、cy 是镜头中心在画布上的坐标 */
|
|
4430
|
+
function nearestLive(ids, pos, dw, dh, cx, cy, selId, max, prev) {
|
|
4431
|
+
// 挂着的优先留着:镜头稍微挪一点,边上那几屏别来回撤了又载
|
|
4432
|
+
const rows = ids.map((id, i) => ({ id, d: id === selId ? -1 : ((pos[i].x + dw / 2 - cx) ** 2 + (pos[i].y + dh / 2 - cy) ** 2) * (prev && prev.has(id) ? 0.5 : 1) }))
|
|
4433
|
+
rows.sort((a, b) => a.d - b.d)
|
|
4434
|
+
return new Set(rows.slice(0, max).map((x) => x.id))
|
|
4435
|
+
}
|
|
4418
4436
|
|
|
4419
4437
|
/**
|
|
4420
4438
|
* n 屏排成网格:试每种列数,挑缩进舞台后最大的那种。
|
|
@@ -6632,7 +6650,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
6632
6650
|
}
|
|
6633
6651
|
|
|
6634
6652
|
// 左上屏名 ▾:换屏(画布 / 某一屏)、多尺寸、类型、打开别的页面——「在看什么、怎么看」都在这一个菜单里
|
|
6635
|
-
function ScreenMenu({ t, label, title, tip, src, busy, list, cur, canvas, open, setOpen, onPick, onAll, onOther, sizes, kind, onKind }) {
|
|
6653
|
+
function ScreenMenu({ t, label, title, tip, src, busy, list, cur, canvas, open, setOpen, onPick, onAll, onOther, sizes, kind, onKind, hidden, hiddenText }) {
|
|
6636
6654
|
const ref = useRef(null)
|
|
6637
6655
|
useDismiss(open, setOpen, ref)
|
|
6638
6656
|
const n = list.length
|
|
@@ -6641,12 +6659,14 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
6641
6659
|
h('button', { className: 'ddp-addr' + (open ? ' sel' : ''), ...(tip ? tipA(tip[0], tip[1]) : { title: title || t('screensT') }), 'data-src': src || undefined, 'aria-haspopup': 'menu', 'aria-expanded': open, onClick: () => setOpen(!open) },
|
|
6642
6660
|
h('i', { className: 'ddp-dot' + (busy ? ' wait' : '') }),
|
|
6643
6661
|
(() => { const m = /^(.+?)( · [^·]+)$/.exec(label || ''); return m ? h('span', { className: 'lb2' }, h('b', null, m[1]), h('em', null, m[2])) : h('span', null, label) })(),
|
|
6662
|
+
hidden ? h('em', { className: 'hid', title: hiddenText }, '+' + hidden) : null,
|
|
6644
6663
|
h(I.caret)),
|
|
6645
6664
|
open ? h('div', { className: 'ddp-menu l', role: 'menu' },
|
|
6646
6665
|
h('div', { className: 'hd' }, n > 1 ? t('screensHd') : t('screensT')),
|
|
6647
6666
|
h('button', { className: canvas && !(sizes && sizes.on) ? 'sel' : '', role: 'menuitemradio', 'aria-checked': canvas, onClick: close(onAll) }, h(I.canvas), h('span', null, t('canvasShort')), n > 1 ? h('em', null, t('screensAll', { n })) : null),
|
|
6648
6667
|
h('div', { className: 'ls' }, ...list.map((x) => h('button', { key: x.key, className: !canvas && !(sizes && sizes.on) && x.key === cur ? 'sel' : '', role: 'menuitemradio', 'aria-checked': !canvas && x.key === cur, title: x.key, onClick: close(() => onPick(x.key)) },
|
|
6649
6668
|
h(I.single), h('span', null, x.label)))),
|
|
6669
|
+
hidden ? h('div', { className: 'nt' }, hiddenText) : null,
|
|
6650
6670
|
sizes ? h('div', { className: 'sp', role: 'separator' }) : null,
|
|
6651
6671
|
sizes ? h('button', { className: sizes.on ? 'sel' : '', role: 'menuitemcheckbox', 'aria-checked': !!sizes.on, disabled: !!sizes.off, title: sizes.tip, onClick: close(sizes.run) }, h(I.sizes), h('span', null, t('sizesShort')), sizes.note ? h('em', null, sizes.note) : null) : null,
|
|
6652
6672
|
onKind ? h('div', { className: 'hd' }, t('kind')) : null,
|
|
@@ -7434,6 +7454,21 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
7434
7454
|
issues.more ? h('p', null, t('pkMore', { n: issues.more })) : null)))
|
|
7435
7455
|
}
|
|
7436
7456
|
|
|
7457
|
+
const GHOST_CELL = '__ghost'
|
|
7458
|
+
const cellsOf = (world) => [...world.children].filter((el) => el.dataset && el.dataset.cell)
|
|
7459
|
+
const labOf = (cell) => cell.querySelector(':scope > .ddp-lab')
|
|
7460
|
+
// 换行前记下画面现在的样子(正在滑的也算):每格的屏幕位置、标题的反向缩放、底纹点阵
|
|
7461
|
+
function snapStage(stage, world) {
|
|
7462
|
+
const bg = getComputedStyle(stage)
|
|
7463
|
+
return {
|
|
7464
|
+
bg: { backgroundSize: bg.backgroundSize, backgroundPosition: bg.backgroundPosition },
|
|
7465
|
+
cells: new Map(cellsOf(world).map((el) => {
|
|
7466
|
+
const lab = labOf(el)
|
|
7467
|
+
return [el.dataset.cell, { rect: el.getBoundingClientRect(), lab: lab ? getComputedStyle(lab).transform : '' }]
|
|
7468
|
+
})),
|
|
7469
|
+
}
|
|
7470
|
+
}
|
|
7471
|
+
|
|
7437
7472
|
function Canvas(props) {
|
|
7438
7473
|
const { t, screens, kind, size, ghost, picking, sel, labelOf } = props
|
|
7439
7474
|
const ref = useRef(null)
|
|
@@ -7443,12 +7478,17 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
7443
7478
|
const [drag, setDrag] = useState(false)
|
|
7444
7479
|
const [zoomMenu, setZoomMenu] = useState(false)
|
|
7445
7480
|
const auto = useRef(true)
|
|
7481
|
+
const liveCam = useRef(null) // 拖宽度时直接写到画布上的镜头,React 的 cam 还没追上;平移、缩放要从画面上的这个算
|
|
7446
7482
|
const camRef = useRef(cam)
|
|
7447
|
-
camRef.current = cam
|
|
7483
|
+
camRef.current = liveCam.current || cam
|
|
7448
7484
|
const lastTap = useRef({ key: '', at: 0 })
|
|
7449
7485
|
const f = FRAME[kind] || FRAME.web
|
|
7450
7486
|
const [dw, dh] = deviceBox(kind, size)
|
|
7451
7487
|
const n = screens.length + (ghost ? 1 : 0)
|
|
7488
|
+
const heavy = !props.items && screens.length > HEAVY_N
|
|
7489
|
+
const heavyRef = useRef(heavy)
|
|
7490
|
+
heavyRef.current = heavy
|
|
7491
|
+
const worldRef = useRef(null)
|
|
7452
7492
|
// 多尺寸:每块自己的类型和大小(items[i] = { kind, size })
|
|
7453
7493
|
const items = props.items || null
|
|
7454
7494
|
const boxes = items ? items.map((it) => deviceBox(it.kind, it.size)) : null
|
|
@@ -7461,24 +7501,177 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
7461
7501
|
const vw = box.w - ins
|
|
7462
7502
|
const layoutKey = L ? [n, L.cols, dw, dh, box.w, box.h, rt, bh, ins, boxes ? boxes.join(';') : ''].join('|') : ''
|
|
7463
7503
|
const fitAt = () => { const c = fitCam(L, vw, bh); return { ...c, y: c.y + rt } }
|
|
7504
|
+
// 屏多时拖宽度:新镜头直接写到画布上,不走 React,也不动 --z,这样既跟手又不让 iframe 每帧重绘。
|
|
7505
|
+
// 列数变了(或者松手了)才真重排:先记下每格现在在屏幕上的样子,镜头和格子一次换好,再从记下的样子滑过去,中间没有哪一帧会跳。返回有没有真重排
|
|
7506
|
+
const followRef = useRef(null)
|
|
7507
|
+
const flipFirst = useRef(null)
|
|
7508
|
+
const unpinRef = useRef(false)
|
|
7509
|
+
followRef.current = (w, h, final) => {
|
|
7510
|
+
const sh = Math.max(0, h - rt - (props.bottom || 0))
|
|
7511
|
+
const world = worldRef.current
|
|
7512
|
+
if (!L || !world || !(w > 0) || !(sh > 0)) { setBox({ w, h }); return false }
|
|
7513
|
+
const next = layoutGrid(n, dw, dh, w, sh)
|
|
7514
|
+
const sw = w - (props.inset && w - props.inset >= 240 ? props.inset : 0)
|
|
7515
|
+
if (final || next.cols !== L.cols) {
|
|
7516
|
+
if (w === box.w && h === box.h) {
|
|
7517
|
+
if (liveCam.current && !auto.current) setCam(liveCam.current)
|
|
7518
|
+
else if (liveCam.current) { liveCam.current = null; camRef.current = cam }
|
|
7519
|
+
return false
|
|
7520
|
+
}
|
|
7521
|
+
flipFirst.current = snapStage(ref.current, world)
|
|
7522
|
+
if (auto.current) { const c = fitCam(next, sw, sh); setCam({ ...c, y: c.y + rt }) }
|
|
7523
|
+
else if (liveCam.current) setCam(liveCam.current)
|
|
7524
|
+
setBox({ w, h })
|
|
7525
|
+
return true
|
|
7526
|
+
}
|
|
7527
|
+
if (auto.current) {
|
|
7528
|
+
const c = fitCam({ ...L, z: next.z }, sw, sh)
|
|
7529
|
+
liveCam.current = camRef.current = { ...c, y: c.y + rt }
|
|
7530
|
+
world.style.transform = `translate(${c.x}px, ${c.y + rt}px) scale(${c.z})`
|
|
7531
|
+
}
|
|
7532
|
+
return false
|
|
7533
|
+
}
|
|
7534
|
+
// 屏多的时候只挂镜头附近的,别的先放占位。镜头停下来才换,拖动时不闪、不反复重载
|
|
7535
|
+
const cull = !!props.sleep && !!L && screens.length > LIVE_MAX
|
|
7536
|
+
const [live, setLive] = useState(null)
|
|
7537
|
+
const liveIds = cull ? screens.map((x) => x.id || x.key) : []
|
|
7538
|
+
const liveSig = liveIds.join('|')
|
|
7539
|
+
useEffect(() => {
|
|
7540
|
+
if (!cull || !cam) { if (live) setLive(null); return undefined }
|
|
7541
|
+
const run = () => {
|
|
7542
|
+
const c = camRef.current
|
|
7543
|
+
const selIdx = screens.findIndex((x) => x.key === props.sel)
|
|
7544
|
+
setLive((prev) => {
|
|
7545
|
+
// 「适合画布」时所有屏都在画面里,光是重排就别换加载着的屏,换了会闪
|
|
7546
|
+
const selId = selIdx < 0 ? '' : liveIds[selIdx]
|
|
7547
|
+
if (prev && auto.current && prev.size === Math.min(LIVE_MAX, liveIds.length) && (!selId || prev.has(selId)) && [...prev].every((id) => liveIds.includes(id))) return prev
|
|
7548
|
+
const next = nearestLive(liveIds, L.pos, dw, dh, (vw / 2 - c.x) / c.z, (rt + bh / 2 - c.y) / c.z, selIdx < 0 ? '' : liveIds[selIdx], LIVE_MAX, prev)
|
|
7549
|
+
return prev && prev.size === next.size && [...next].every((id) => prev.has(id)) ? prev : next
|
|
7550
|
+
})
|
|
7551
|
+
}
|
|
7552
|
+
if (!live) { run(); return undefined }
|
|
7553
|
+
const timer = setTimeout(run, 160)
|
|
7554
|
+
return () => clearTimeout(timer)
|
|
7555
|
+
}, [cull, cam, layoutKey, liveSig, props.sel])
|
|
7464
7556
|
|
|
7465
7557
|
useEffect(() => {
|
|
7466
7558
|
const el = ref.current
|
|
7467
7559
|
if (!el) return undefined
|
|
7468
|
-
const
|
|
7469
|
-
|
|
7560
|
+
const apply = () => setBox({ w: el.clientWidth, h: el.clientHeight })
|
|
7561
|
+
let timer = 0
|
|
7562
|
+
const pin = (v) => { if (worldRef.current) worldRef.current.style.transition = v }
|
|
7563
|
+
const settle = () => { if (followRef.current(el.clientWidth, el.clientHeight, true)) unpinRef.current = true; else pin('') }
|
|
7564
|
+
const measure = () => {
|
|
7565
|
+
clearTimeout(timer)
|
|
7566
|
+
if (!heavyRef.current) { pin(''); apply(); return }
|
|
7567
|
+
pin('none') // 拖动时镜头不做过渡:每帧重开过渡正是闪的来源之一
|
|
7568
|
+
followRef.current(el.clientWidth, el.clientHeight, false)
|
|
7569
|
+
timer = setTimeout(settle, 160)
|
|
7570
|
+
}
|
|
7571
|
+
apply()
|
|
7470
7572
|
if (typeof ResizeObserver === 'undefined') return undefined
|
|
7471
7573
|
const ro = new ResizeObserver(measure)
|
|
7472
7574
|
ro.observe(el)
|
|
7473
|
-
return () => ro.disconnect()
|
|
7575
|
+
return () => { clearTimeout(timer); ro.disconnect() }
|
|
7474
7576
|
}, [])
|
|
7475
7577
|
|
|
7578
|
+
// 屏多时的换行动画:格子先到新位置,再用 translate 从旧位置滑过来,全程走合成层,不用每帧重新排版 30 个格子
|
|
7579
|
+
const flipFrom = useRef(null)
|
|
7580
|
+
const flipUntil = useRef(0)
|
|
7581
|
+
const SLIDE = { id: 'ddp-flip', duration: 450, easing: EASE }
|
|
7582
|
+
const stopFlip = (el) => { for (const old of el.getAnimations()) if (old.id === 'ddp-flip') old.cancel() }
|
|
7583
|
+
// first 是镜头和格子换之前的样子,这里量换完的样子,差多少就从那儿滑回来。先量完再统一开动画,别读写交错
|
|
7584
|
+
function playFlip(world, first) {
|
|
7585
|
+
flipUntil.current = performance.now() + 450
|
|
7586
|
+
const list = cellsOf(world)
|
|
7587
|
+
for (const el of [...list, ...list.map(labOf), ref.current]) if (el) stopFlip(el)
|
|
7588
|
+
const jobs = []
|
|
7589
|
+
for (const el of list) {
|
|
7590
|
+
const f = first.cells.get(el.dataset.cell)
|
|
7591
|
+
if (!f) continue
|
|
7592
|
+
const l = el.getBoundingClientRect()
|
|
7593
|
+
if (!l.width || !el.offsetWidth) continue
|
|
7594
|
+
const k = l.width / el.offsetWidth
|
|
7595
|
+
const dx = (f.rect.left + f.rect.width / 2 - l.left - l.width / 2) / k
|
|
7596
|
+
const dy = (f.rect.top + f.rect.height / 2 - l.top - l.height / 2) / k
|
|
7597
|
+
const s = f.rect.width / l.width
|
|
7598
|
+
if (Math.abs(dx) < 0.5 && Math.abs(dy) < 0.5 && Math.abs(s - 1) < 0.001) continue
|
|
7599
|
+
jobs.push([el, { translate: `${dx}px ${dy}px`, scale: String(s) }, f.lab])
|
|
7600
|
+
}
|
|
7601
|
+
for (const [el, from, labFrom] of jobs) {
|
|
7602
|
+
el.animate([from, { translate: '0 0', scale: '1' }], SLIDE)
|
|
7603
|
+
const lab = labOf(el)
|
|
7604
|
+
if (lab && labFrom && labFrom !== 'none') lab.animate([{ transform: labFrom }, { transform: lab.style.transform }], SLIDE)
|
|
7605
|
+
}
|
|
7606
|
+
ref.current.animate([first.bg, { backgroundSize: ref.current.style.backgroundSize, backgroundPosition: ref.current.style.backgroundPosition }], SLIDE)
|
|
7607
|
+
// 选中屏的连线画在新位置,等格子落定再淡出来,别在半路错位
|
|
7608
|
+
const lines = world.querySelector(':scope > .ddp-flows')
|
|
7609
|
+
if (lines) lines.animate([{ opacity: 0 }, { opacity: 0, offset: 0.7 }, { opacity: 1 }], { duration: 450 })
|
|
7610
|
+
}
|
|
7611
|
+
react.useLayoutEffect(() => {
|
|
7612
|
+
if (!L) return
|
|
7613
|
+
const now = new Map(screens.map((sc, i) => [String(sc.id || sc.key), L.pos[i]]))
|
|
7614
|
+
if (ghost) now.set(GHOST_CELL, L.pos[n - 1])
|
|
7615
|
+
const was = flipFrom.current
|
|
7616
|
+
flipFrom.current = now
|
|
7617
|
+
const first = flipFirst.current
|
|
7618
|
+
flipFirst.current = null
|
|
7619
|
+
const world = worldRef.current
|
|
7620
|
+
if (world && heavy && !reduced()) {
|
|
7621
|
+
if (first) playFlip(world, first)
|
|
7622
|
+
else if (was) {
|
|
7623
|
+
// 别的原因重排(加屏、删屏):镜头有自己的过渡,格子只补世界坐标里的差;上一段没滑完就从当前看到的样子接着滑
|
|
7624
|
+
for (const el of cellsOf(world)) {
|
|
7625
|
+
const a = was.get(el.dataset.cell)
|
|
7626
|
+
const b = now.get(el.dataset.cell)
|
|
7627
|
+
if (!a || !b || (a.x === b.x && a.y === b.y)) continue
|
|
7628
|
+
const cs = getComputedStyle(el)
|
|
7629
|
+
const [ox, oy] = cs.translate && cs.translate !== 'none' ? cs.translate.split(' ').map(parseFloat) : [0, 0]
|
|
7630
|
+
const sc0 = cs.scale && cs.scale !== 'none' ? cs.scale.split(' ')[0] : '1'
|
|
7631
|
+
stopFlip(el)
|
|
7632
|
+
el.animate([{ translate: `${a.x - b.x + (ox || 0)}px ${a.y - b.y + (oy || 0)}px`, scale: sc0 }, { translate: '0 0', scale: '1' }], SLIDE)
|
|
7633
|
+
}
|
|
7634
|
+
}
|
|
7635
|
+
}
|
|
7636
|
+
if (unpinRef.current) { unpinRef.current = false; if (world) world.style.transition = '' }
|
|
7637
|
+
}, [layoutKey])
|
|
7638
|
+
|
|
7639
|
+
// 镜头一提交,画面就以它为准:拖宽度时直接写过 DOM,React 看值没变可能不重写,这里显式写一次
|
|
7640
|
+
react.useLayoutEffect(() => {
|
|
7641
|
+
liveCam.current = null
|
|
7642
|
+
camRef.current = cam
|
|
7643
|
+
const world = worldRef.current
|
|
7644
|
+
if (!world || !cam) return
|
|
7645
|
+
world.style.transform = `translate(${cam.x}px, ${cam.y}px) scale(${cam.z})`
|
|
7646
|
+
// 标题还在往旧倍率滑的时候镜头又变了:从当前看到的样子改滑向新倍率,别滑完再跳一下
|
|
7647
|
+
if (heavy && performance.now() < flipUntil.current) {
|
|
7648
|
+
for (const el of cellsOf(world)) {
|
|
7649
|
+
const lab = labOf(el)
|
|
7650
|
+
const run = lab && lab.getAnimations().find((x) => x.id === 'ddp-flip')
|
|
7651
|
+
if (!run || run.effect.getKeyframes().at(-1).transform === lab.style.transform) continue
|
|
7652
|
+
const from = getComputedStyle(lab).transform
|
|
7653
|
+
stopFlip(lab)
|
|
7654
|
+
lab.animate([{ transform: from }, { transform: lab.style.transform }], SLIDE)
|
|
7655
|
+
flipUntil.current = performance.now() + 450
|
|
7656
|
+
}
|
|
7657
|
+
}
|
|
7658
|
+
const first = flipFirst.current
|
|
7659
|
+
if (!first) return
|
|
7660
|
+
flipFirst.current = null
|
|
7661
|
+
if (heavy && !reduced()) playFlip(world, first)
|
|
7662
|
+
}, [cam])
|
|
7663
|
+
|
|
7476
7664
|
// 屏数 / 类型 / 舞台大小变了:用户没自己动过镜头就重新摆好
|
|
7477
7665
|
useEffect(() => {
|
|
7478
7666
|
if (!L) return
|
|
7479
7667
|
if (auto.current || !camRef.current) {
|
|
7480
|
-
|
|
7481
|
-
|
|
7668
|
+
const world = worldRef.current
|
|
7669
|
+
const to = fitAt()
|
|
7670
|
+
const c = camRef.current
|
|
7671
|
+
// 拖着宽度的时候屏数变了:镜头这时不走过渡,和换行一样先记下画面再滑过去
|
|
7672
|
+
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)
|
|
7673
|
+
setAnim(!!c)
|
|
7674
|
+
setCam(to)
|
|
7482
7675
|
} else if (ins && props.sel) showKey(props.sel) // 自己挪过镜头:只把选中的那屏挪出来,别被面板挡着
|
|
7483
7676
|
}, [layoutKey])
|
|
7484
7677
|
|
|
@@ -7582,30 +7775,34 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
7582
7775
|
while (grid < 12) grid *= 2
|
|
7583
7776
|
while (grid > 48) grid /= 2
|
|
7584
7777
|
const lab = (key, body, w = dw) => h('div', { className: 'ddp-lab', 'data-key': key, style: { width: w * z, transform: `scale(${1 / z})` } }, ...body)
|
|
7585
|
-
|
|
7586
|
-
|
|
7778
|
+
// 只是挪镜头(props、缩放都没变):别重建每一屏,省得所有 iframe 跟着过一遍 React
|
|
7779
|
+
const cells = useMemo(() => {
|
|
7780
|
+
const out = []
|
|
7781
|
+
if (!cam || !L) return out
|
|
7587
7782
|
screens.forEach((sc, i) => {
|
|
7588
7783
|
const on = sel === sc.key
|
|
7589
7784
|
const [cw, ch] = boxes ? boxes[i] : [dw, dh]
|
|
7590
7785
|
const fr = items ? FRAME[items[i].kind] || FRAME.web : f
|
|
7591
|
-
|
|
7786
|
+
out.push(h('div', {
|
|
7592
7787
|
key: sc.id || sc.key,
|
|
7788
|
+
'data-cell': String(sc.id || sc.key),
|
|
7593
7789
|
className: 'ddp-cell' + (on ? ' sel' : ''),
|
|
7594
7790
|
style: { left: L.pos[i].x, top: L.pos[i].y, width: cw, height: ch },
|
|
7595
7791
|
},
|
|
7596
7792
|
lab(sc.key, [props.tag ? props.tag(sc) : null, h('span', { key: 's' }, labelOf(sc)), !picking && props.badge ? props.badge(sc) : null, !picking && props.actions ? h('span', { key: 'a', className: 'ddp-act' }, ...props.actions(sc)) : null], cw),
|
|
7597
|
-
props.render(sc, z, i),
|
|
7793
|
+
cull && !(live && live.has(sc.id || sc.key)) ? props.sleep(sc, z) : props.render(sc, z, i),
|
|
7598
7794
|
picking ? null : h('div', { className: 'ddp-shield', 'data-key': sc.key, title: items ? '' : t('openScreen'), style: { borderRadius: fr.r } })))
|
|
7599
7795
|
})
|
|
7600
7796
|
if (ghost) {
|
|
7601
7797
|
const p = L.pos[n - 1]
|
|
7602
|
-
|
|
7798
|
+
out.push(h('div', { key: '__ghost', 'data-cell': GHOST_CELL, className: 'ddp-cell ghost', style: { left: p.x, top: p.y, width: dw, height: dh } },
|
|
7603
7799
|
lab('', [h('i', { key: 'i', className: 'sp' }), h('span', { key: 's' }, t('generating'))]),
|
|
7604
7800
|
h(Device, { kind, w: size[0], h: size[1], label: '' },
|
|
7605
7801
|
h(GhostDraw, { key: 'gd', t, kind, pulse: props.pulse || 0 }),
|
|
7606
7802
|
props.draft ? h(DraftFrame, { key: 'df', url: props.draft, z, lang: t('lang'), onEnd: props.onDraftEnd }) : null)))
|
|
7607
7803
|
}
|
|
7608
|
-
|
|
7804
|
+
return out
|
|
7805
|
+
}, [props, z, live, layoutKey, !!cam])
|
|
7609
7806
|
let flowSvg = null
|
|
7610
7807
|
if (cam && L && props.flows && props.flows.length && !picking) {
|
|
7611
7808
|
// 只画选中那屏通向哪(不画哪些通向它),底栏、返回这种每屏都有的导航只描框
|
|
@@ -7616,12 +7813,13 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
7616
7813
|
}
|
|
7617
7814
|
}
|
|
7618
7815
|
return h('div', {
|
|
7619
|
-
className: 'ddp-canvas' + (drag ? ' drag' : ''),
|
|
7816
|
+
className: 'ddp-canvas' + (drag ? ' drag' : '') + (heavy ? ' heavy' : ''),
|
|
7620
7817
|
ref,
|
|
7621
7818
|
onPointerDown,
|
|
7622
7819
|
style: cam ? { backgroundSize: `${grid}px ${grid}px`, backgroundPosition: `${cam.x}px ${cam.y}px` } : undefined,
|
|
7623
7820
|
},
|
|
7624
7821
|
cam && L ? h('div', {
|
|
7822
|
+
ref: worldRef,
|
|
7625
7823
|
className: 'ddp-world' + (anim ? ' anim' : ''),
|
|
7626
7824
|
style: { transform: `translate(${cam.x}px, ${cam.y}px) scale(${z})`, '--z': z },
|
|
7627
7825
|
}, ...cells, flowSvg) : null,
|
|
@@ -7632,7 +7830,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
7632
7830
|
['', I.minus, t('zoomOut'), false, z <= ZMIN, () => center(1 / 1.25)],
|
|
7633
7831
|
'sep',
|
|
7634
7832
|
['', I.fit, t('fit'), false, false, fit],
|
|
7635
|
-
['', I.single, t('zoomReal'), Math.abs(z - 1) < 0.005, false, () => center(1 / z)],
|
|
7833
|
+
['', I.single, t('zoomReal'), Math.abs(z - 1) < 0.005, false, () => center(1 / camRef.current.z)],
|
|
7636
7834
|
] })))
|
|
7637
7835
|
}
|
|
7638
7836
|
|
|
@@ -7727,7 +7925,8 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
7727
7925
|
const [tw, setTw] = useState({}) // 拖过的滑块:id → 值(还没写进文件)
|
|
7728
7926
|
const apis = useRef(new Map()) // 屏 → 截图用的接口
|
|
7729
7927
|
const ghostApis = useRef(new Map()) // 单看时导出:在背后临时挂上的各屏
|
|
7730
|
-
const
|
|
7928
|
+
const ghostQueue = useRef(Promise.resolve())
|
|
7929
|
+
const ghostBatch = useRef(0)
|
|
7731
7930
|
const [backFrames, setBackFrames] = useState(null) // { list, size }:开始时的那些屏,途中换设计也不跟着变
|
|
7732
7931
|
const designNow = useRef('') // 现在开着哪套设计
|
|
7733
7932
|
const designSeq = useRef(0) // 换一次设计加一:导出途中换过(换回来也算)就不存了
|
|
@@ -7756,6 +7955,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
7756
7955
|
const draftedR = useRef(new Map()) // 边写边看过的屏 → 什么时候:真文件出来时不再播一遍生成动画
|
|
7757
7956
|
const pulseR = useRef({ key: '', lines: 0, n: 0 }) // 模型真有动静就加一(占位里的鼠标按它动)
|
|
7758
7957
|
const singleDraftR = useRef('') // 单屏里正在看着写的那屏:写完换过去看它
|
|
7958
|
+
const peekR = useRef('') // 这轮生成里用户自己点开的那屏:就给他看这屏,别拿在写的草稿盖住,写完也别把他带走
|
|
7759
7959
|
const playR = useRef({ url: '', key: '', hold: 0, end: false, meta: '', lump: false }) // 在放的草稿(见下面 dr)
|
|
7760
7960
|
const M = marks.current
|
|
7761
7961
|
if (M.site !== site) {
|
|
@@ -8007,8 +8207,15 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
8007
8207
|
if (!patch.focus && poll && poll.state) poll.set({ ...poll.state, ...patch })
|
|
8008
8208
|
post('view', { session: sid, ...patch }).then((s) => poll && poll.set(s), (e) => say(t('openFailed', { msg: e.message })))
|
|
8009
8209
|
}
|
|
8210
|
+
// 用户自己点开一屏(双击、菜单、单看按钮)
|
|
8211
|
+
const openByUser = (key) => {
|
|
8212
|
+
singleDraftR.current = ''
|
|
8213
|
+
peekR.current = key || focus
|
|
8214
|
+
change(key ? { view: 'single', focus: key } : { view: 'single' })
|
|
8215
|
+
}
|
|
8010
8216
|
// 单屏里看着写完的那屏:真文件出来了就换过去看它(不然写完一闪又回到原来那屏)
|
|
8011
8217
|
useEffect(() => {
|
|
8218
|
+
if (!busy && !dr) peekR.current = ''
|
|
8012
8219
|
let k = singleDraftR.current
|
|
8013
8220
|
if (k === '*' && sd && sd.key) k = singleDraftR.current = sd.key
|
|
8014
8221
|
if (!k || dr) return
|
|
@@ -8260,8 +8467,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
8260
8467
|
useEffect(() => { setDemo(null) }, [site])
|
|
8261
8468
|
|
|
8262
8469
|
const openSingle = () => {
|
|
8263
|
-
|
|
8264
|
-
else change({ view: 'single' })
|
|
8470
|
+
openByUser(sel && sel !== focus && screens.some((s) => s.key === sel) ? sel : '')
|
|
8265
8471
|
}
|
|
8266
8472
|
|
|
8267
8473
|
const renderScreen = (sc, z, fill) => h(Device, { kind, w: size[0], h: size[1], fill, label: labelOf(sc), top: tops[ik(sc)], os: meta.os },
|
|
@@ -8295,6 +8501,10 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
8295
8501
|
onBuilt: (title) => onBuilt(sc, title),
|
|
8296
8502
|
}))
|
|
8297
8503
|
|
|
8504
|
+
// 画布上屏太多、离镜头远的:先不挂 iframe,放个占位
|
|
8505
|
+
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 },
|
|
8506
|
+
h('div', { className: 'ddp-scr' + (dark ? ' dk' : '') }, h('div', { className: 'ddp-away', style: { fontSize: 13 / Math.max(0.25, z || 1) } }, t('canvasAsleep'))))
|
|
8507
|
+
|
|
8298
8508
|
// ── 导出图片 ──
|
|
8299
8509
|
// 截一屏:图片和它的 CSS 尺寸(PDF / PPT 按这个定页面大小)
|
|
8300
8510
|
// 那一屏的接口(截图、体检);刚载入的等它就绪
|
|
@@ -8311,8 +8521,10 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
8311
8521
|
const captureOf = async (sc, full, map, maxH) => {
|
|
8312
8522
|
const api = await apiOf(sc, map)
|
|
8313
8523
|
const r = await api.capture({ full: !!full, scale: 2, ...(maxH ? { maxH } : {}) })
|
|
8314
|
-
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 }
|
|
8524
|
+
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() }
|
|
8315
8525
|
}
|
|
8526
|
+
// 导出用的标题:屏多的时候有的屏没在画布上挂过,手上没有它的标题,用截图时页面报的
|
|
8527
|
+
const exportTitle = (sc, r) => (infoOf(ik(sc)) || {}).title || r.title || sc.label
|
|
8316
8528
|
|
|
8317
8529
|
const targetKey = st && st.target ? (st.target.kind === 'file' ? `file|${st.target.root}` : `proxy|${st.target.port}`) : ''
|
|
8318
8530
|
const saveImage = async (name, blob) => {
|
|
@@ -8326,18 +8538,39 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
8326
8538
|
const designId = JSON.stringify([sid, targetKey, ver ? ver.n : 0])
|
|
8327
8539
|
if (designNow.current !== designId) { designNow.current = designId; designSeq.current++ }
|
|
8328
8540
|
// 单看时只挂着正在看的那屏;要所有屏(PDF、PPT、拼图、预检)时按画幅大小在背后挂上,用完就撤
|
|
8329
|
-
const withFrames = async (fn) => {
|
|
8330
|
-
if (canvas || shown.length < 2) return fn(apis.current)
|
|
8541
|
+
const withFrames = async (fn, only) => {
|
|
8542
|
+
if (!only && ((canvas && shown.length <= LIVE_MAX) || shown.length < 2)) return fn(apis.current)
|
|
8331
8543
|
// 网页单看时铺满右侧栏,和画幅不一样宽,都在背后重挂;别的类型正在看的那屏直接用(滚动位置、打开的弹窗都还在)
|
|
8332
|
-
|
|
8333
|
-
const
|
|
8334
|
-
|
|
8335
|
-
|
|
8336
|
-
|
|
8544
|
+
// 画布屏多的时候镜头一动画布上的屏就会撤,也都在背后挂
|
|
8545
|
+
const stamp = designSeq.current
|
|
8546
|
+
const run = async () => {
|
|
8547
|
+
if (designSeq.current !== stamp) throw new Error('designChanged') // 排队的时候换了设计
|
|
8548
|
+
// 轮到了才算要挂哪些:排队时前台可能已经换了一屏
|
|
8549
|
+
const list = only || (canvas || kind === 'web' ? shown : shown.filter((sc) => !apis.current.has(ik(sc))))
|
|
8550
|
+
const back = new Set(list.map(ik))
|
|
8551
|
+
const place = new Map(list.map((sc, i) => [ik(sc), i]))
|
|
8552
|
+
// 屏多的时候分批挂:只挂轮到的这一批,别几十个一起跑
|
|
8553
|
+
let at = 0
|
|
8554
|
+
// 每个任务一批新的 iframe:上一批的深浅色、接口都不留(不然拿到上一批「已就绪」的就截了)
|
|
8555
|
+
ghostApis.current.clear()
|
|
8556
|
+
setBackFrames({ list, size, at, dark, batch: ++ghostBatch.current }) // 深浅色跟点导出时的走,和文件名对得上
|
|
8557
|
+
const get = (k) => {
|
|
8558
|
+
const i = place.get(k)
|
|
8559
|
+
if (i !== undefined && (i < at || i >= at + LIVE_MAX)) { at = i; setBackFrames((b) => (b ? { ...b, at: i } : b)) }
|
|
8560
|
+
return (back.has(k) ? ghostApis.current : apis.current).get(k)
|
|
8561
|
+
}
|
|
8562
|
+
try { return await fn({ get }) } finally { setBackFrames(null) }
|
|
8563
|
+
}
|
|
8564
|
+
// 背后挂的屏一次只给一个任务用(预检和导出撞上,会互相把对方要的那批撤掉)
|
|
8565
|
+
const job = ghostQueue.current.then(run, run)
|
|
8566
|
+
ghostQueue.current = job.catch(() => {})
|
|
8567
|
+
return job
|
|
8337
8568
|
}
|
|
8338
8569
|
const measureAll = async (map) => {
|
|
8570
|
+
const stamp = designSeq.current
|
|
8339
8571
|
const list = []
|
|
8340
8572
|
for (const sc of shown) {
|
|
8573
|
+
if (designSeq.current !== stamp) break // 设计换了:别再等旧的屏
|
|
8341
8574
|
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 }) }
|
|
8342
8575
|
}
|
|
8343
8576
|
return list
|
|
@@ -8382,7 +8615,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
8382
8615
|
try {
|
|
8383
8616
|
const r = await captureOf(sc, long, map, maxH)
|
|
8384
8617
|
const cut = maxH && r.h > maxH
|
|
8385
|
-
pages.push({ jpg: await jpegB64(cut ? cropImg(r.img, r.h, maxH) : r.img), w: r.w, h: cut ? maxH : r.h, title:
|
|
8618
|
+
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 })
|
|
8386
8619
|
keys.push(sc.key)
|
|
8387
8620
|
} catch (e) { console.warn('[dsh-design-studio] 截图失败', sc.key, e) }
|
|
8388
8621
|
}
|
|
@@ -8410,7 +8643,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
8410
8643
|
await withFrames(async (map) => {
|
|
8411
8644
|
for (const sc of shown) {
|
|
8412
8645
|
if (gone()) break
|
|
8413
|
-
try { const c = await captureOf(sc, false, map); shots.push({ img: c.img, top: c.top, title:
|
|
8646
|
+
try { const c = await captureOf(sc, false, map); shots.push({ img: c.img, top: c.top, title: exportTitle(sc, c) }) } catch (e) { console.warn('[dsh-design-studio] 截图失败', sc.key, e) }
|
|
8414
8647
|
}
|
|
8415
8648
|
})
|
|
8416
8649
|
if (gone()) { say(t('xoGone')); return }
|
|
@@ -8435,7 +8668,12 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
8435
8668
|
const sc = shown.find((x) => x.key === k) || shown[0]
|
|
8436
8669
|
if (!sc) throw new Error('no screen')
|
|
8437
8670
|
const base = prefix + sc.key.replace(/\.html?$/i, '') + suffix
|
|
8438
|
-
|
|
8671
|
+
// 画布屏多的时候这屏可能没挂着(镜头一动也可能撤掉):在背后单独挂一份来截
|
|
8672
|
+
let shot = null
|
|
8673
|
+
if (canvas && shown.length > LIVE_MAX) await withFrames(async (map) => { shot = await captureOf(sc, mode === 'long', map) }, [sc])
|
|
8674
|
+
else shot = await captureOf(sc, mode === 'long')
|
|
8675
|
+
if (gone()) { say(t('xoGone')); return }
|
|
8676
|
+
const { img, top } = shot
|
|
8439
8677
|
if (mode === 'frame') await saveImage(base, await composeOne(kind, size, img, labelOf(sc), top, meta.os))
|
|
8440
8678
|
else {
|
|
8441
8679
|
const c = document.createElement('canvas')
|
|
@@ -8488,7 +8726,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
8488
8726
|
const actions = (sc) => [
|
|
8489
8727
|
h('button', { key: 'x', className: 'ddp-btn', title: t('exThis'), onClick: () => doExport(FRAMED[kind] ? 'frame' : 'raw', sc.key) }, h(I.download), h('span', { className: 'lb' }, t('actX'))),
|
|
8490
8728
|
sc.v ? null : h('button', { key: 'v', className: 'ddp-btn', title: t('variants'), onClick: () => askVariants(sc) }, h(I.sparkle), h('span', { className: 'lb' }, t('actV'))),
|
|
8491
|
-
h('button', { key: 'o', className: 'ddp-btn', title: t('openScreen'), onClick: () =>
|
|
8729
|
+
h('button', { key: 'o', className: 'ddp-btn', title: t('openScreen'), onClick: () => openByUser(sc.key) }, h(I.single), h('span', { className: 'lb' }, t('actO'))),
|
|
8492
8730
|
]
|
|
8493
8731
|
|
|
8494
8732
|
// 对比:拖中间的把手
|
|
@@ -8526,7 +8764,8 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
8526
8764
|
if (ck) for (const sc of ck.list || []) { const a = apis.current.get(ik(sc)); if (a) a.checkClear() }
|
|
8527
8765
|
setCk(null)
|
|
8528
8766
|
}
|
|
8529
|
-
|
|
8767
|
+
// 画布屏多的时候只量挂着的(别的没有页面可量)
|
|
8768
|
+
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 }])
|
|
8530
8769
|
// 几屏一起量(各量各的 iframe),一屏卡住不拖累别的
|
|
8531
8770
|
const measure = (list, quiet) => Promise.all(list.map(async (sc) => {
|
|
8532
8771
|
const row = { key: sc.key, v: sc.v, label: labelOf(sc), url: sc.url, issues: [] }
|
|
@@ -8542,6 +8781,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
8542
8781
|
setPanel(false); setHist(false); setPhone(false)
|
|
8543
8782
|
setCk({ running: true, list: [] })
|
|
8544
8783
|
const out = await measure(checkList(), false)
|
|
8784
|
+
if (canvas && shown.length > LIVE_MAX) say(t('checkPartial', { n: out.length }))
|
|
8545
8785
|
setCk({ running: false, list: out })
|
|
8546
8786
|
setCkCount(total(out))
|
|
8547
8787
|
// 有问题的第一屏被面板挡着、在画布外面:挪过来
|
|
@@ -8553,6 +8793,8 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
8553
8793
|
const sc = (ck && ck.list.find((x) => x.key === key)) || null
|
|
8554
8794
|
if (!sc) return
|
|
8555
8795
|
if (canvas) { setSel(key); setReveal((r) => ({ key, n: ((r && r.n) || 0) + 1 })) }
|
|
8796
|
+
// 屏多的时候这屏可能撤过(重新载入后页面里的体检标记没了):等它挂上,量一遍再定位
|
|
8797
|
+
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 }
|
|
8556
8798
|
const a = apis.current.get(ik(sc))
|
|
8557
8799
|
if (a) a.checkFocus(i)
|
|
8558
8800
|
}
|
|
@@ -8806,6 +9048,15 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
8806
9048
|
}
|
|
8807
9049
|
useEffect(() => { if (styleOff) setStyleEdit(false) }, [styleOff])
|
|
8808
9050
|
autoCk.current = { ck, off: checkOff, run: runCheck, list: checkList, measure }
|
|
9051
|
+
// 屏数超过上限:不声不响地少几屏,用户会以为没生成
|
|
9052
|
+
const hiddenN = (st && st.hidden) || 0
|
|
9053
|
+
const hiddenText = hiddenN ? t('screensHidden', { n: hiddenN, max: st.maxScreens }) : ''
|
|
9054
|
+
const hiddenSaid = useRef('')
|
|
9055
|
+
useEffect(() => {
|
|
9056
|
+
const sig = hiddenN ? `${targetKey}|${hiddenN}` : ''
|
|
9057
|
+
if (sig && sig !== hiddenSaid.current) say(hiddenText)
|
|
9058
|
+
hiddenSaid.current = sig
|
|
9059
|
+
}, [hiddenN, targetKey])
|
|
8809
9060
|
useEffect(() => { if (checkOff && ck) closeCheck() }, [checkOff])
|
|
8810
9061
|
|
|
8811
9062
|
const toggleDemo = () => (demo ? setDemo(null) : startDemo())
|
|
@@ -8885,7 +9136,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
8885
9136
|
setMulti(false)
|
|
8886
9137
|
if (demo) setDemo(null)
|
|
8887
9138
|
setSel(key)
|
|
8888
|
-
if (canvas || key !== focus)
|
|
9139
|
+
if (canvas || key !== focus || dr) openByUser(key)
|
|
8889
9140
|
}
|
|
8890
9141
|
// 导出菜单写出是哪一屏(和 doExport 取同一屏)
|
|
8891
9142
|
const exSc = shown.find((x) => x.key === (canvas ? sel || focus : focus)) || shown[0]
|
|
@@ -8902,7 +9153,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
8902
9153
|
h('div', { className: 'ddp-isl tl' },
|
|
8903
9154
|
h('button', { className: 'ddp-btn lab' + (homeAt === 'on' ? ' sel' : ''), ...tipA(t('homeBtn'), t('dHome'), homeAt === 'on' ? 'Esc' : ''), 'aria-pressed': homeAt === 'on', onClick: () => (homeAt === 'on' ? homeClose() : homeOpen()) }, h(I.home), h('span', { className: 'lb' }, t('homeBtn'))),
|
|
8904
9155
|
h('span', { className: 'ddp-sep' }),
|
|
8905
|
-
h(ScreenMenu, { t, label: scrLabel, tip: [scrLabel || stLabel, t('dScreen')], src: stLabel, busy, list: screens.map((x) => { const L = takeTag(x); return { key: x.key, label: dropBrand(shortOf(x)) + (L ? ' · ' + L : '') } }), cur: curKey, canvas: canvas && !inMulti && !demo, open: scrMenu, setOpen: setScrMenu,
|
|
9156
|
+
h(ScreenMenu, { t, hidden: hiddenN, hiddenText, label: scrLabel, tip: [scrLabel || stLabel, t('dScreen')], src: stLabel, busy, list: screens.map((x) => { const L = takeTag(x); return { key: x.key, label: dropBrand(shortOf(x)) + (L ? ' · ' + L : '') } }), cur: curKey, canvas: canvas && !inMulti && !demo, open: scrMenu, setOpen: setScrMenu,
|
|
8906
9157
|
onPick: pickScreen, onAll: () => { setMulti(false); if (demo) setDemo(null); change({ view: 'canvas' }) }, onOther: () => setEditing(true),
|
|
8907
9158
|
sizes: mark ? null : { on: inMulti, off: !sizeSet || !!ver, tip: sizeSet ? t('sizes') : t('sizesNo'), note: sizeSet ? '' : t('sizesNoShort'), run: () => setMulti(!inMulti) },
|
|
8908
9159
|
kind, onKind: mark ? null : (k) => change({ kind: k }) })),
|
|
@@ -9052,8 +9303,8 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
9052
9303
|
toast ? h('div', { className: 'ddp-toast low' }, h('span', null, toast.text)) : null) : null
|
|
9053
9304
|
// 开着设计时点「首页」:首页叠在画布上(设计库再叠在它上面)
|
|
9054
9305
|
// 单看时导出:所有屏按画幅大小挂在背后(看不见、点不到,放在视口里是因为视口外的 iframe 浏览器会停掉它的绘制)
|
|
9055
|
-
const ghostLayer = backFrames ? h('div', { className: 'ddp-ghost', 'aria-hidden': true }, ...backFrames.list.map((sc) => h('div', { key: ik(sc), className: 'ddp-vp', style: { left: 0, top: 0, width: backFrames.size[0], height: backFrames.size[1] } },
|
|
9056
|
-
h(Screen, { t, remote, src: sc.url, label: labelOf(sc), dark, apis: ghostApis.current, apiKey: ik(sc), quietPick: true, zoom: 1, reloadSeq, tweak: sc.v ? null : tweak, styleSel: sty && sty.key === sc.key ? sty.selector : '', styleCss: sty && sty.key === sc.key ? sty.live : null })))) : null
|
|
9306
|
+
const ghostLayer = backFrames ? h('div', { className: 'ddp-ghost', 'aria-hidden': true }, ...backFrames.list.slice(backFrames.at || 0, (backFrames.at || 0) + LIVE_MAX).map((sc) => h('div', { key: backFrames.batch + '|' + ik(sc), className: 'ddp-vp', style: { left: 0, top: 0, width: backFrames.size[0], height: backFrames.size[1] } },
|
|
9307
|
+
h(Screen, { t, remote, src: sc.url, label: labelOf(sc), dark: backFrames.dark, apis: ghostApis.current, apiKey: ik(sc), quietPick: true, zoom: 1, reloadSeq, tweak: sc.v ? null : tweak, styleEdit: styleEdit && !sc.v, styleSel: sty && sty.key === sc.key ? sty.selector : '', styleCss: sty && sty.key === sc.key ? sty.live : null })))) : null
|
|
9057
9308
|
const root = (...kids) => h('div', rootProps, ...kids, url && homeAt ? homeView(true) : null, libLayer, dropLayer, fileInput, pageFileInput, ghostLayer)
|
|
9058
9309
|
|
|
9059
9310
|
// ── 设计库:打成 zip、拖进来的设计包、存成我的风格 ──
|
|
@@ -9404,9 +9655,10 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
9404
9655
|
reveal,
|
|
9405
9656
|
inset: ck || styleEdit || panel || pane || hist || phone ? 296 : 0, // 右边的面板 276 宽,离边 10
|
|
9406
9657
|
render: (sc, z) => renderScreen(sc, z, false),
|
|
9658
|
+
sleep: sleepScreen,
|
|
9407
9659
|
flows,
|
|
9408
9660
|
onSelect: setSel,
|
|
9409
|
-
onOpen: (key) =>
|
|
9661
|
+
onOpen: (key) => openByUser(key),
|
|
9410
9662
|
})
|
|
9411
9663
|
} else {
|
|
9412
9664
|
const fill = kind === 'web'
|
|
@@ -9421,7 +9673,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
9421
9673
|
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))
|
|
9422
9674
|
const one = ver ? shown.find((x) => x.key === focus) || shown[0] || { key: focus, url, label: st.label } : { key: focus, url, label: st.label }
|
|
9423
9675
|
// 单屏时模型在写新的一屏:先看着它写(没在选、改字、调样式、标注的时候),写完换过去
|
|
9424
|
-
const watch = dr && !ver && !demo && !picking && !textEdit && !styleEdit && !mark && !lock
|
|
9676
|
+
const watch = dr && !ver && !demo && !picking && !textEdit && !styleEdit && !mark && !lock && !peekR.current
|
|
9425
9677
|
if (watch) singleDraftR.current = dr.key || '*' // 还不知道是哪屏:名字到了再说
|
|
9426
9678
|
body = h('div', { className: 'ddp-single', style: aside ? { right: aside } : undefined },
|
|
9427
9679
|
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})` } },
|
|
@@ -9648,7 +9900,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
9648
9900
|
// 注意:这里是客户端**服务名**(短的),不是包名
|
|
9649
9901
|
exports.inject = INJECT
|
|
9650
9902
|
// 测试用
|
|
9651
|
-
exports._test = { 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, tokenKind, formatToken, splitTitles, pickColors, hhmm, formatTpl, formatPrep, styleFromTokens, myStyleOf, isZipFile }
|
|
9903
|
+
exports._test = { 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 }
|
|
9652
9904
|
return module.exports
|
|
9653
9905
|
},
|
|
9654
9906
|
})
|
package/lib/core.js
CHANGED
|
@@ -31,7 +31,8 @@ const SHELL_TOOL = /^(bash|shell|sh|zsh|powershell|pwsh|exec|run_command|termina
|
|
|
31
31
|
// 放到后台跑的命令(DSH:bash 带 run_in_background,或前台超时转后台)回一个 job id,输出要用 job_output 去读
|
|
32
32
|
const JOB_READ_TOOL = /^(job_output|bash_output|read_job|job_read)$/i
|
|
33
33
|
const BG_JOB = /\bbackground job\s+`?([\w.:-]{3,})/i
|
|
34
|
-
const MAX_SCREENS = 24
|
|
34
|
+
const MAX_SCREENS = 60 // 右侧最多显示几屏,再多的收起来并提示(画布同时只挂 24 屏,见 client.js 的 LIVE_MAX)
|
|
35
|
+
const MAX_ROUTES = 300 // 开发服务器的路由先都记着(只为算出收起了几屏);再多就是写飞了
|
|
35
36
|
|
|
36
37
|
// 设计类型:决定右侧用什么画幅显示(网页框、手机、小程序、平板、桌面软件窗口、海报、幻灯片、邮件)
|
|
37
38
|
export const KINDS = ['web', 'app', 'miniprogram', 'tablet', 'desktop', 'poster', 'slides', 'email']
|
|
@@ -64,8 +65,20 @@ export function parseSize(input) {
|
|
|
64
65
|
return `${w}x${h}`
|
|
65
66
|
}
|
|
66
67
|
|
|
67
|
-
/**
|
|
68
|
-
export function listScreens(root) {
|
|
68
|
+
/** 右侧显示的几屏:超过上限时留最新生成的,最早的先收起来。keep:正打开的那屏,不在里面也留着(挤掉最早的一屏) */
|
|
69
|
+
export function listScreens(root, keep = '') {
|
|
70
|
+
const kept = screensByBirth(root).slice(-MAX_SCREENS)
|
|
71
|
+
if (keep && !kept.includes(keep)) { if (kept.length >= MAX_SCREENS) kept.shift(); kept.push(keep) }
|
|
72
|
+
return inManifestOrder(root, kept)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** 目录里所有的屏。按文件名找、改全套的时候用这个,别漏掉收起来的 */
|
|
76
|
+
export function allScreens(root) {
|
|
77
|
+
return inManifestOrder(root, screensByBirth(root))
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** 顶层的 HTML 文件,按创建时间(= 模型生成的顺序)排 */
|
|
81
|
+
function screensByBirth(root) {
|
|
69
82
|
let dirents
|
|
70
83
|
try { dirents = fs.readdirSync(root, { withFileTypes: true }) } catch { return [] }
|
|
71
84
|
const out = []
|
|
@@ -80,14 +93,16 @@ export function listScreens(root) {
|
|
|
80
93
|
out.push({ name: d.name, born })
|
|
81
94
|
}
|
|
82
95
|
out.sort((a, b) => a.born - b.born || a.name.localeCompare(b.name))
|
|
83
|
-
|
|
96
|
+
return out.map((x) => x.name)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** 有设计清单(design.json,从设计库来的模板 / 分享过的设计):按清单里的顺序排,清单外的(模型后加的)按创建时间排在后面 */
|
|
100
|
+
function inManifestOrder(root, names) {
|
|
84
101
|
const order = manifestOrder(root)
|
|
85
|
-
if (order.length)
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
return out.slice(0, MAX_SCREENS).map((x) => x.name)
|
|
102
|
+
if (!order.length) return names
|
|
103
|
+
const rank = new Map(order.map((f, i) => [f.toLowerCase(), i]))
|
|
104
|
+
const listed = names.filter((x) => rank.has(x.toLowerCase())).sort((a, b) => rank.get(a.toLowerCase()) - rank.get(b.toLowerCase()))
|
|
105
|
+
return [...listed, ...names.filter((x) => !rank.has(x.toLowerCase()))]
|
|
91
106
|
}
|
|
92
107
|
|
|
93
108
|
/** design.json 里 screens 的文件名(读不了、写错了都当没有) */
|
|
@@ -113,7 +128,7 @@ function normRoutes(list) {
|
|
|
113
128
|
if (m) s = m[3] || '/'
|
|
114
129
|
if (!s.startsWith('/')) s = '/' + s
|
|
115
130
|
if (!out.includes(s)) out.push(s)
|
|
116
|
-
if (out.length >=
|
|
131
|
+
if (out.length >= MAX_ROUTES) break
|
|
117
132
|
}
|
|
118
133
|
return out.length ? out : null
|
|
119
134
|
}
|
|
@@ -161,7 +176,7 @@ export function parseTarget(input, cwd = os.homedir()) {
|
|
|
161
176
|
if (st.isDirectory()) {
|
|
162
177
|
// 有 index.html 开它;没有就开最先做的那屏(设计目录一屏一个文件,画布上会把同目录的几屏都排出来)
|
|
163
178
|
const index = path.join(p, 'index.html')
|
|
164
|
-
const first = fs.existsSync(index) ? 'index.html' :
|
|
179
|
+
const first = fs.existsSync(index) ? 'index.html' : allScreens(p)[0]
|
|
165
180
|
if (!first) {
|
|
166
181
|
try { fs.readdirSync(p) } catch (e) { throw new Error(`读不了这个文件夹(${e.code === 'EACCES' || e.code === 'EPERM' ? '没有权限' : e.code || e.message}):${p}`) }
|
|
167
182
|
throw new Error(`这个文件夹里没有 HTML 文件:${p}`)
|
|
@@ -638,19 +653,24 @@ export function createTracker({ open, drafts = null, skipPorts = () => new Set()
|
|
|
638
653
|
|
|
639
654
|
function refreshScreens(st) {
|
|
640
655
|
const t = st.target
|
|
656
|
+
st.hidden = 0
|
|
641
657
|
if (!t) { st.screens = []; return }
|
|
642
658
|
if (t.kind === 'file') {
|
|
643
|
-
const
|
|
659
|
+
const all = allScreens(t.root)
|
|
644
660
|
const me = path.basename(t.file)
|
|
645
|
-
|
|
661
|
+
const found = listScreens(t.root, me)
|
|
646
662
|
// 已经排好的几屏位置不动:编辑器改文件常是写临时文件再换名,创建时间会变,按它重排画布会乱跳
|
|
647
663
|
const list = st.screens.filter((k) => found.includes(k))
|
|
648
664
|
for (const k of found) if (!list.includes(k)) placeScreen(list, k)
|
|
649
|
-
st.screens = list
|
|
665
|
+
st.screens = list
|
|
666
|
+
st.hidden = Math.max(0, all.length + (all.includes(me) ? 0 : 1) - list.length)
|
|
650
667
|
} else {
|
|
651
668
|
const list = st.routes ? [...st.routes] : []
|
|
652
669
|
if (!list.includes(t.path)) list.unshift(t.path)
|
|
653
|
-
|
|
670
|
+
const kept = list.slice(0, MAX_SCREENS)
|
|
671
|
+
if (!kept.includes(t.path)) kept[MAX_SCREENS - 1] = t.path // 正看的这个路由始终在
|
|
672
|
+
st.screens = kept
|
|
673
|
+
st.hidden = list.length - kept.length
|
|
654
674
|
}
|
|
655
675
|
}
|
|
656
676
|
|
|
@@ -705,7 +725,7 @@ export function createTracker({ open, drafts = null, skipPorts = () => new Set()
|
|
|
705
725
|
const t = st.target
|
|
706
726
|
const key = String(focus)
|
|
707
727
|
if (t.kind === 'file') {
|
|
708
|
-
if (!
|
|
728
|
+
if (!allScreens(t.root).includes(key) && key !== path.basename(t.file)) throw new Error(`没有这一屏:${key}`)
|
|
709
729
|
await setTarget(id, { kind: 'file', file: path.join(t.root, key), root: t.root }, { source: st.source, popup: false })
|
|
710
730
|
} else {
|
|
711
731
|
if (!key.startsWith('/')) throw new Error(`路由要以 / 开头:${key}`)
|
|
@@ -1165,6 +1185,8 @@ export function createTracker({ open, drafts = null, skipPorts = () => new Set()
|
|
|
1165
1185
|
origin,
|
|
1166
1186
|
vrev: st.vrev,
|
|
1167
1187
|
focus: file ? path.basename(target.file) : target.path,
|
|
1188
|
+
hidden: st.hidden || 0, // 超过上限收起来的屏数
|
|
1189
|
+
maxScreens: MAX_SCREENS,
|
|
1168
1190
|
screens: st.screens.map((key) => ({
|
|
1169
1191
|
key,
|
|
1170
1192
|
url: file ? `${origin}/${encodeURIComponent(key)}` : origin + key,
|
package/lib/gallery/pack.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
import fs from 'node:fs'
|
|
12
12
|
import path from 'node:path'
|
|
13
|
-
import { checkPack, normalizeHtml, titleOf, metaKind, message, LIMITS, FORMAT, pctBytes, imageInfo } from './policy.js'
|
|
13
|
+
import { checkPack, normalizeHtml, titleOf, metaKind, message, LIMITS, capsOf, FORMAT, pctBytes, imageInfo } from './policy.js'
|
|
14
14
|
import { writeZip } from './zip.js'
|
|
15
15
|
|
|
16
16
|
const PACK_EXT = /\.(html|css|svg|png|jpe?g|webp|gif|avif|json|md)$/i
|
|
@@ -237,7 +237,7 @@ export function packDesign(root, { screens, version = '', license = '', author =
|
|
|
237
237
|
const { files: picked, skipped, tooBig } = collectDesign(root)
|
|
238
238
|
const notes = []
|
|
239
239
|
const errors = []
|
|
240
|
-
if (tooBig) errors.push({ code: 'count', n: '2000+', max:
|
|
240
|
+
if (tooBig) errors.push({ code: 'count', n: '2000+', max: capsOf(mode).files, sev: 'error' })
|
|
241
241
|
const screenSet = new Set(screens.map((s) => s.toLowerCase()))
|
|
242
242
|
let existing = null
|
|
243
243
|
const files = []
|
package/lib/gallery/policy.js
CHANGED
|
@@ -16,8 +16,11 @@ import { scanCss, cssTokens, URL_FUNCS } from './css.js'
|
|
|
16
16
|
|
|
17
17
|
export const FORMAT = 1
|
|
18
18
|
export const LIMITS = {
|
|
19
|
-
files: 60, //
|
|
20
|
-
screens: 24, //
|
|
19
|
+
files: 60, // 市场里一套最多几个文件(分享、审核)
|
|
20
|
+
screens: 24, // 市场里一套最多几屏(分享、审核)
|
|
21
|
+
localFiles: 200, // 自己打 zip、导入 zip 的上限(屏数和工作台一样)
|
|
22
|
+
localScreens: 60,
|
|
23
|
+
localTotal: 5 * 1024 * 1024,
|
|
21
24
|
depth: 3, // 目录最多几层
|
|
22
25
|
html: 200 * 1024,
|
|
23
26
|
css: 200 * 1024,
|
|
@@ -29,6 +32,10 @@ export const LIMITS = {
|
|
|
29
32
|
total: 2 * 1024 * 1024,
|
|
30
33
|
name: 64, // 文件名长度
|
|
31
34
|
}
|
|
35
|
+
/** 这个模式下的数量上限:进市场的(share / ci)严,只在自己手上的(zip / install)宽 */
|
|
36
|
+
export const capsOf = (mode) => (mode === 'share' || mode === 'ci'
|
|
37
|
+
? { files: LIMITS.files, screens: LIMITS.screens, total: LIMITS.total }
|
|
38
|
+
: { files: LIMITS.localFiles, screens: LIMITS.localScreens, total: LIMITS.localTotal })
|
|
32
39
|
export const TYPES = ['template', 'system', 'style']
|
|
33
40
|
export const LICENSES = ['CC0-1.0', 'CC-BY-4.0']
|
|
34
41
|
export const KINDS = ['web', 'app', 'miniprogram', 'tablet', 'desktop', 'poster', 'slides', 'email']
|
|
@@ -1247,7 +1254,7 @@ export function checkManifest(m, { mode = 'install', vocab = null } = {}) {
|
|
|
1247
1254
|
if (m.size !== undefined && !/^\d{3,4}x\d{3,4}$/.test(String(m.size))) bad('size', '写成 1080x1920 这样')
|
|
1248
1255
|
if (m.os !== undefined && !['mac', 'windows'].includes(m.os)) bad('os', '只能是 mac / windows')
|
|
1249
1256
|
if (!Array.isArray(m.screens) || !m.screens.length) bad('screens', '至少一屏')
|
|
1250
|
-
else if (m.screens.length >
|
|
1257
|
+
else if (m.screens.length > capsOf(mode).screens) bad('screens', `最多 ${capsOf(mode).screens} 屏`)
|
|
1251
1258
|
else {
|
|
1252
1259
|
const seen = new Set()
|
|
1253
1260
|
m.screens.forEach((s, i) => {
|
|
@@ -1269,7 +1276,7 @@ export function checkManifest(m, { mode = 'install', vocab = null } = {}) {
|
|
|
1269
1276
|
if (m.lang !== undefined && !['zh', 'en', 'both'].includes(m.lang)) bad('lang', '只能是 zh / en / both')
|
|
1270
1277
|
if (m.dark !== undefined && typeof m.dark !== 'boolean') bad('dark', '要是 true / false')
|
|
1271
1278
|
if (m.assets !== undefined) {
|
|
1272
|
-
if (!Array.isArray(m.assets) || m.assets.length >
|
|
1279
|
+
if (!Array.isArray(m.assets) || m.assets.length > capsOf(mode).files) bad('assets', '要是列表')
|
|
1273
1280
|
else m.assets.forEach((a, i) => {
|
|
1274
1281
|
if (!isObj(a) || typeof a.path !== 'string' || !cleanPath(a.path)) return bad(`assets[${i}]`, '要有 path(包里的图片)')
|
|
1275
1282
|
if (!['self', 'cc0', 'pd'].includes(a.source)) bad(`assets[${i}].source`, 'self(自己做的)/ cc0 / pd(公有领域)')
|
|
@@ -1372,8 +1379,9 @@ export function checkPack(files, { mode = 'install', vocab = null } = {}) {
|
|
|
1372
1379
|
bytes += size
|
|
1373
1380
|
list.push({ path: p, ext, kind, data: f.data, size })
|
|
1374
1381
|
}
|
|
1375
|
-
|
|
1376
|
-
if (
|
|
1382
|
+
const caps = capsOf(mode)
|
|
1383
|
+
if (list.length > caps.files) err({ code: 'count', n: list.length, max: caps.files })
|
|
1384
|
+
if (bytes > caps.total) err({ code: 'total', n: kb(bytes), max: kb(caps.total) })
|
|
1377
1385
|
|
|
1378
1386
|
const texts = new Map()
|
|
1379
1387
|
for (const f of list) {
|
package/lib/gallery/routes.js
CHANGED
|
@@ -16,7 +16,7 @@ import fs from 'node:fs'
|
|
|
16
16
|
import os from 'node:os'
|
|
17
17
|
import path from 'node:path'
|
|
18
18
|
import { execFile } from 'node:child_process'
|
|
19
|
-
import { listScreens } from '../core.js'
|
|
19
|
+
import { listScreens, allScreens } from '../core.js'
|
|
20
20
|
import { parseMeta, metaOfFile, KIND_SIZE, prepare } from '../look.js'
|
|
21
21
|
import { packDesign, zipOf, splitTitle } from './pack.js'
|
|
22
22
|
import { PERSONAL_CODES } from './policy.js'
|
|
@@ -215,7 +215,7 @@ export function createLibraryRoutes({ admit, readBody, json, tracker, library, i
|
|
|
215
215
|
const snap = body.session ? tracker.snapshot(String(body.session)) : null
|
|
216
216
|
const open = snap && snap.target && snap.target.kind === 'file' && path.resolve(snap.target.root) === dir
|
|
217
217
|
if (!open && !byDir(dir)) return json(res, 404, { error: 'not a design here' })
|
|
218
|
-
const screens =
|
|
218
|
+
const screens = allScreens(dir) // 打包按整套算:屏数超了要明确报,不能悄悄少几屏
|
|
219
219
|
if (!screens.length) return json(res, 400, { error: 'noScreens' })
|
|
220
220
|
const local = localManifest(dir)
|
|
221
221
|
// 分享向导先要一份预填:名字、介绍、授权、分享过没有
|
package/lib/handoff.js
CHANGED
|
@@ -14,7 +14,7 @@ import os from 'node:os'
|
|
|
14
14
|
import path from 'node:path'
|
|
15
15
|
import { pathToFileURL } from 'node:url'
|
|
16
16
|
import { prepare } from './look.js'
|
|
17
|
-
import {
|
|
17
|
+
import { allScreens } from './core.js'
|
|
18
18
|
import { readTweaks, shownValue } from './tweaks.js'
|
|
19
19
|
import { tokensOf } from './system.js'
|
|
20
20
|
|
|
@@ -827,5 +827,5 @@ export async function compareScreens(browser, { design, impl, size, at = 'top',
|
|
|
827
827
|
|
|
828
828
|
/** 设计目录里的几屏(交接、对比时按文件名找) */
|
|
829
829
|
export function screensOf(root) {
|
|
830
|
-
return
|
|
830
|
+
return allScreens(root)
|
|
831
831
|
}
|
package/lib/index.js
CHANGED
|
@@ -169,8 +169,9 @@ export const previewTool = {
|
|
|
169
169
|
const st = await tracker.setTarget(id, target, opts)
|
|
170
170
|
const what = target.kind === 'file' ? target.file : `localhost:${target.port}${target.path}`
|
|
171
171
|
const many = target.kind === 'file' ? '同目录再写别的 HTML 文件,会作为新的一屏并排出现。' : ''
|
|
172
|
+
const over = st.hidden ? `右侧最多显示 ${st.screens.length} 屏,还有 ${st.hidden} 屏没显示。` : ''
|
|
172
173
|
return {
|
|
173
|
-
text: `已在右侧「设计工作台」打开 ${what}。${target.kind === 'file' ? '这个目录里的文件一改就自动刷新。' + many : '开发服务器的热更新照常生效。'}`,
|
|
174
|
+
text: `已在右侧「设计工作台」打开 ${what}。${target.kind === 'file' ? '这个目录里的文件一改就自动刷新。' + many : '开发服务器的热更新照常生效。'}${over}`,
|
|
174
175
|
url: st.url,
|
|
175
176
|
}
|
|
176
177
|
},
|
package/lib/tweaks.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
import fs from 'node:fs'
|
|
17
17
|
import path from 'node:path'
|
|
18
|
-
import {
|
|
18
|
+
import { allScreens } from './core.js'
|
|
19
19
|
import { parseColor, hexOf } from './system.js'
|
|
20
20
|
|
|
21
21
|
export const TWEAKS_FILE = 'tweaks.json'
|
|
@@ -270,7 +270,7 @@ function cssFiles(root, realRoot = '') {
|
|
|
270
270
|
let names = []
|
|
271
271
|
try { names = fs.readdirSync(root) } catch { return [] }
|
|
272
272
|
const css = names.filter((n) => /\.css$/i.test(n) && !n.startsWith('.')).sort((a, b) => (a === 'tokens.css' ? -1 : b === 'tokens.css' ? 1 : a.localeCompare(b)))
|
|
273
|
-
return [...css, ...
|
|
273
|
+
return [...css, ...allScreens(root)].filter((rel) => ownFile(root, realRoot, rel))
|
|
274
274
|
}
|
|
275
275
|
|
|
276
276
|
/** 外观面板里直接改的设计变量:{ '--名字': 值 } → [[名字, 值]](名字、值都要老实:值里不能有 ; { } < 换行) */
|
|
@@ -333,7 +333,7 @@ export function applyTweaks(root, values, vars) {
|
|
|
333
333
|
if (k.var) {
|
|
334
334
|
if (!writeVar(k.var, cssValue(k, v))) { missed.push({ id: k.id, label: k.label }); continue }
|
|
335
335
|
} else {
|
|
336
|
-
for (const rel of
|
|
336
|
+
for (const rel of allScreens(root)) {
|
|
337
337
|
if (!ownFile(root, realRoot, rel)) continue
|
|
338
338
|
const next = setHtmlAttr(read(rel), k.attr, v)
|
|
339
339
|
if (next !== null) texts.set(rel, next)
|