@ninkch/dsh-infinite-canvas 0.19.17 → 0.19.18
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/client.js +448 -36
- package/docs/UI-RULES.md +2 -0
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -1163,6 +1163,17 @@ function revealCanvasInRight() {
|
|
|
1163
1163
|
'updateSrcChina': '中国大陆镜像源',
|
|
1164
1164
|
'updateSrcNow': '当前源',
|
|
1165
1165
|
'updateSrcSet': '更新源已切换',
|
|
1166
|
+
'assetsSelAllPage': '全选本页',
|
|
1167
|
+
'assetsAddToCanvas': '添加到画布',
|
|
1168
|
+
'assetsClearSel': '清除选择',
|
|
1169
|
+
'assetsOnlyAudio': '所选均为音频资产,无法生成画布节点',
|
|
1170
|
+
'assetsAudioSkip': '{n} 个音频资产已跳过',
|
|
1171
|
+
'assetsAdded': '已添加 {n} 个资产节点',
|
|
1172
|
+
'assetsBatchDelWarn': '将从资产库删除所选资产;画布上引用它们的节点会解绑:',
|
|
1173
|
+
'assetsDeletedN': '已删除 {n} 个资产',
|
|
1174
|
+
'assetsTotalCount': '共 {n} 项',
|
|
1175
|
+
'assetClickHint': '单击选择 / 双击直接添加到画布',
|
|
1176
|
+
'assetsRelinked': '已自动回链 {n} 个节点的资产引用',
|
|
1166
1177
|
'dataRootLabel': '数据根目录',
|
|
1167
1178
|
'dataRootPlaceholder': '如 D:\\canvas-data',
|
|
1168
1179
|
'dataRootHint': '资产与视频按项目落盘到该目录(不再占用 C 盘 IndexedDB)。留空 = 浏览器 IndexedDB。',
|
|
@@ -2099,6 +2110,17 @@ function revealCanvasInRight() {
|
|
|
2099
2110
|
'updateSrcChina': 'China mainland mirror',
|
|
2100
2111
|
'updateSrcNow': 'Active source',
|
|
2101
2112
|
'updateSrcSet': 'Update source changed',
|
|
2113
|
+
'assetsSelAllPage': 'Select page',
|
|
2114
|
+
'assetsAddToCanvas': 'Add to canvas',
|
|
2115
|
+
'assetsClearSel': 'Clear selection',
|
|
2116
|
+
'assetsOnlyAudio': 'Only audio assets selected — nothing to place on canvas',
|
|
2117
|
+
'assetsAudioSkip': '{n} audio assets skipped',
|
|
2118
|
+
'assetsAdded': '{n} asset nodes added',
|
|
2119
|
+
'assetsBatchDelWarn': 'Selected assets will be deleted from the library; canvas nodes referencing them will be unbound:',
|
|
2120
|
+
'assetsDeletedN': '{n} assets deleted',
|
|
2121
|
+
'assetsTotalCount': '{n} items',
|
|
2122
|
+
'assetClickHint': 'Click to select / double-click to add to canvas',
|
|
2123
|
+
'assetsRelinked': 'Relinked {n} nodes to their assets',
|
|
2102
2124
|
'dataRootLabel': 'Data root',
|
|
2103
2125
|
'dataRootPlaceholder': 'e.g. D:\\canvas-data',
|
|
2104
2126
|
'dataRootHint': 'Assets and videos are stored per project under this folder (no more C: IndexedDB). Empty = browser IndexedDB.',
|
|
@@ -2710,7 +2732,31 @@ body[data-ds-dark-theme] .dshic-studio-modal{border-color:var(--dsw-alias-border
|
|
|
2710
2732
|
.dshic-modal-assets{display:flex;flex-direction:column;gap:10px;}
|
|
2711
2733
|
.dshic-modal-assets .dshic-asset-grid{grid-template-columns:repeat(auto-fill,minmax(158px,1fr));gap:10px;}
|
|
2712
2734
|
.dshic-modal-assets .dshic-asset-thumb{height:112px;}
|
|
2713
|
-
|
|
2735
|
+
/* ── 资产页工具栏(项目下拉下一行):同步/导入/全选/批量操作 + 分页同排 ──
|
|
2736
|
+
按钮统一「透明底 + 1px 线框 + 文字」(UI-RULES:禁止灰底色块);hover 只加深边框不加底色。
|
|
2737
|
+
窄窗口 flex-wrap 换行,分页 margin-left:auto 始终靠右。 */
|
|
2738
|
+
.dshic-asset-toolbar{display:flex;align-items:center;gap:8px;flex-wrap:wrap;row-gap:6px;}
|
|
2739
|
+
.dshic-asset-toolbar-main{display:flex;align-items:center;gap:8px;flex-wrap:wrap;row-gap:6px;min-width:0;}
|
|
2740
|
+
.dshic-asset-batch{display:flex;align-items:center;gap:8px;flex-wrap:wrap;row-gap:6px;}
|
|
2741
|
+
.dshic-toolbtn{display:inline-flex;align-items:center;gap:4px;height:26px;padding:0 10px;border-radius:7px;
|
|
2742
|
+
border:1px solid var(--dsw-alias-border-l2);background:transparent;color:var(--dsw-alias-label-primary);
|
|
2743
|
+
font:inherit;font-size:12px;line-height:1;white-space:nowrap;flex:none;cursor:pointer;}
|
|
2744
|
+
.dshic-toolbtn:hover:not(:disabled){border-color:var(--dsw-alias-label-secondary);}
|
|
2745
|
+
.dshic-toolbtn:disabled{opacity:.45;cursor:default;}
|
|
2746
|
+
.dshic-toolbtn.is-danger{color:var(--dsw-alias-state-error-primary);border-color:var(--dsw-alias-state-error-primary);}
|
|
2747
|
+
.dshic-toolbtn.is-icon{width:26px;padding:0;justify-content:center;font-size:14px;}
|
|
2748
|
+
.dshic-asset-selall{display:inline-flex;align-items:center;gap:4px;font-size:12px;
|
|
2749
|
+
color:var(--dsw-alias-label-secondary);cursor:pointer;flex:none;}
|
|
2750
|
+
.dshic-asset-audiohint{font-size:11px;color:var(--dsw-alias-label-secondary);opacity:.75;}
|
|
2751
|
+
.dshic-asset-pager{display:flex;align-items:center;gap:6px;margin-left:auto;flex:none;
|
|
2752
|
+
font-size:11.5px;color:var(--dsw-alias-label-secondary);}
|
|
2753
|
+
.dshic-asset-pagebox{display:inline-flex;align-items:center;gap:4px;}
|
|
2754
|
+
.dshic-asset-pageinput{width:44px;height:26px;text-align:center;font:inherit;font-size:12px;padding:0 4px;
|
|
2755
|
+
border:1px solid var(--dsw-alias-border-l2);border-radius:7px;background:transparent;
|
|
2756
|
+
color:var(--dsw-alias-label-primary);box-sizing:border-box;}
|
|
2757
|
+
.dshic-asset-pageinput:focus{outline:none;border-color:var(--dsw-alias-brand-primary);box-shadow:var(--dshic-shadow-sel);}
|
|
2758
|
+
.dshic-asset-pagetotal,.dshic-asset-pagecount{font-variant-numeric:tabular-nums;white-space:nowrap;}
|
|
2759
|
+
.dshic-asset-pagecount{opacity:.75;}
|
|
2714
2760
|
/* 设定集条目:行 + 已绑定资产缩略图 */
|
|
2715
2761
|
.dshic-bible-item{display:flex;flex-direction:column;gap:4px;padding:5px 0;border-bottom:1px dashed var(--dsw-alias-border-l1);}
|
|
2716
2762
|
.dshic-bible-thumbs{display:flex;gap:5px;flex-wrap:wrap;padding-left:4px;}
|
|
@@ -2913,6 +2959,9 @@ body[data-ds-dark-theme] .dshic-inline-input{border-color:var(--dsw-alias-border
|
|
|
2913
2959
|
.dshic-asset{position:relative;border:1px solid var(--dsw-alias-border-l1);border-radius:9px;overflow:hidden;cursor:pointer;
|
|
2914
2960
|
background:var(--dsw-alias-bg-layer-2);}
|
|
2915
2961
|
.dshic-asset:hover{border-color:var(--dsw-alias-brand-primary);}
|
|
2962
|
+
/* 批量选择:复选框常驻左上角;选中卡片描边 */
|
|
2963
|
+
.dshic-asset-check{position:absolute;left:6px;top:6px;z-index:2;width:15px;height:15px;cursor:pointer;accent-color:var(--dsw-alias-brand-primary);}
|
|
2964
|
+
.dshic-asset.is-checked{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:-2px;}
|
|
2916
2965
|
.dshic-asset-thumb{width:100%;height:86px;object-fit:cover;display:block;background:var(--dsw-alias-bg-layer-2);}
|
|
2917
2966
|
.dshic-asset-meta{display:flex;align-items:center;gap:4px;padding:3px 6px;font-size:10px;color:var(--dsw-alias-label-secondary);flex-wrap:wrap;}
|
|
2918
2967
|
.dshic-asset-actions{position:absolute;top:4px;right:4px;display:flex;gap:3px;opacity:0;transition:opacity .12s;}
|
|
@@ -3641,6 +3690,7 @@ body[data-ds-dark-theme] .dshic-pick-item.is-on{background:color-mix(in srgb,var
|
|
|
3641
3690
|
V.x = s.graph.view.x; V.y = s.graph.view.y; V.scale = s.graph.view.scale;
|
|
3642
3691
|
applyViewToDom();
|
|
3643
3692
|
});
|
|
3693
|
+
scheduleRepair(); // 载入/切画布后自愈被误置空的资产引用(幂等,每画布一次)
|
|
3644
3694
|
history.stack = [];
|
|
3645
3695
|
history.idx = -1;
|
|
3646
3696
|
pushHistory();
|
|
@@ -6059,9 +6109,63 @@ function queueThumb(assetId) {
|
|
|
6059
6109
|
if (!r.ok && (r.status === 401 || r.status === 403) && authFallback && Object.keys(authFallback).length) {
|
|
6060
6110
|
r = await fetchViaProxy(url, { method: 'GET', headers: authFallback, timeoutMs: 300000, label: '下载视频' });
|
|
6061
6111
|
}
|
|
6062
|
-
if (!r.ok)
|
|
6112
|
+
if (!r.ok) {
|
|
6113
|
+
const e = new Error('下载视频失败 HTTP ' + r.status);
|
|
6114
|
+
e.status = r.status; // 供下载重试判定区分「缓存未就绪(502/404…)」与「鉴权/请求错误(401/400)」
|
|
6115
|
+
throw e;
|
|
6116
|
+
}
|
|
6063
6117
|
return r.blob;
|
|
6064
6118
|
}
|
|
6119
|
+
/** 下载重试判定(纯函数):厂商任务成功后 CDN 缓存尚未铺开时,首次 GET 常见
|
|
6120
|
+
* 502/503/504/404/403/429/408;这些都可重试。401(鉴权)与 400/405(请求格式)
|
|
6121
|
+
* 是配置错误,绝不重试——否则会把真实错误拖满整个重试窗口。 */
|
|
6122
|
+
function retryableDownloadError(err) {
|
|
6123
|
+
const st = Number(err && err.status) || 0;
|
|
6124
|
+
if (!st) return true; // 无 HTTP 状态 = 网络抖动/代理超时(fetchViaProxy 直接抛错)
|
|
6125
|
+
return st === 403 || st === 404 || st === 408 || st === 409 || st === 425 || st === 429 || st >= 500;
|
|
6126
|
+
}
|
|
6127
|
+
/** 三宝:succeeded 后等 CDN 缓存铺开的下载重试窗口(实测 2–3 分钟,最迟 5 分钟;留 10 分钟余量)。
|
|
6128
|
+
* 生成成功只有一次下载机会 → 单次 502 不能让整次生成作废。 */
|
|
6129
|
+
const SANBAO_DOWNLOAD_RETRY_MS = 10 * 60 * 1000;
|
|
6130
|
+
const SANBAO_DOWNLOAD_RETRY_STEP_MS = 10 * 1000;
|
|
6131
|
+
/** 带窗口的下载重试(三宝等「任务成功 ≠ 文件可下载」的厂商):
|
|
6132
|
+
* · 仅在可重试错误上循环(见 retryableDownloadError),鉴权/请求错误立即抛;
|
|
6133
|
+
* · 每次重试前可用 refreshUrl 拿最新签名地址(旧地址可能已过期);
|
|
6134
|
+
* · 到达窗口上限后抛明确错误(带最后 HTTP 状态),绝不再无限等;
|
|
6135
|
+
* · 中断(用户停止)优先于重试;download/sleep/now 可注入供回归(不真等 10 分钟)。 */
|
|
6136
|
+
async function downloadVideoWithRetry(url, headers, opts) {
|
|
6137
|
+
const o = opts || {};
|
|
6138
|
+
const windowMs = o.windowMs == null ? SANBAO_DOWNLOAD_RETRY_MS : Math.max(0, Number(o.windowMs) || 0);
|
|
6139
|
+
const stepMs = o.stepMs == null ? SANBAO_DOWNLOAD_RETRY_STEP_MS : Math.max(0, Number(o.stepMs) || 0);
|
|
6140
|
+
const dl = typeof o.download === 'function' ? o.download : downloadVideo;
|
|
6141
|
+
const wait = typeof o.sleep === 'function' ? o.sleep : sleep;
|
|
6142
|
+
const now = typeof o.now === 'function' ? o.now : Date.now;
|
|
6143
|
+
const isAborted = typeof o.isAborted === 'function' ? o.isAborted : genAborted;
|
|
6144
|
+
const deadline = now() + windowMs;
|
|
6145
|
+
for (let attempt = 1; ; attempt++) {
|
|
6146
|
+
if (isAborted && isAborted()) throw new Error(T('stoppedNote'));
|
|
6147
|
+
try {
|
|
6148
|
+
return await dl(url, headers || {}, o.authFallback);
|
|
6149
|
+
} catch (e) {
|
|
6150
|
+
if (!retryableDownloadError(e)) throw e;
|
|
6151
|
+
if (now() >= deadline) {
|
|
6152
|
+
const err = new Error((o.label ? o.label + ' ' : '') + '视频已生成,但 '
|
|
6153
|
+
+ Math.round(windowMs / 60000) + ' 分钟内仍无法下载(最后错误:' + ((e && e.message) || e) + ')');
|
|
6154
|
+
err.status = e && e.status;
|
|
6155
|
+
err.downloadTimeout = true;
|
|
6156
|
+
throw err;
|
|
6157
|
+
}
|
|
6158
|
+
if (typeof o.onRetry === 'function') { try { o.onRetry(e, attempt); } catch { /* 诊断失败不影响重试 */ } }
|
|
6159
|
+
if (typeof o.refreshUrl === 'function') {
|
|
6160
|
+
try {
|
|
6161
|
+
const fresh = await o.refreshUrl();
|
|
6162
|
+
if (fresh) url = fresh;
|
|
6163
|
+
} catch { /* 刷新地址失败:沿用旧地址继续重试 */ }
|
|
6164
|
+
}
|
|
6165
|
+
await wait(stepMs);
|
|
6166
|
+
}
|
|
6167
|
+
}
|
|
6168
|
+
}
|
|
6065
6169
|
/** 跨镜衔接标注(短剧分镜链式生成的行业标准做法):图1=上一镜尾帧(仅用于衔接),
|
|
6066
6170
|
* 图2..N=实体参考图(名称与 o.refNames 对齐)。Seedance 的 first_frame 与 reference_image 互斥,
|
|
6067
6171
|
* 尾帧+参考图同连时尾帧降级为第一张衔接参考图,靠顺序+标注控制用途。 */
|
|
@@ -6629,14 +6733,41 @@ function queueThumb(assetId) {
|
|
|
6629
6733
|
let j1 = null; try { j1 = JSON.parse(r1.text); } catch { throw new Error('Sanbao 响应非 JSON:' + r1.text.slice(0, 200)); }
|
|
6630
6734
|
const tid = sanbaoTaskIdOf(j1);
|
|
6631
6735
|
if (!tid) throw new Error('Sanbao 响应中没有任务 id:' + r1.text.slice(0, 200));
|
|
6632
|
-
|
|
6736
|
+
const taskUrl = base + '/openapi/v1/videos/' + encodeURIComponent(tid);
|
|
6737
|
+
if (o.onTask) { try { o.onTask(tid, taskUrl); } catch { /* 持久化失败不影响生成 */ } }
|
|
6738
|
+
const queryTask = async (label) => {
|
|
6739
|
+
const r = await fetchViaProxy(taskUrl, { method: 'GET', headers: { Authorization: 'Bearer ' + (s.apiKey || '') }, timeoutMs: 60000, label });
|
|
6740
|
+
if (!r || !r.ok) return null;
|
|
6741
|
+
try { return JSON.parse(r.text); } catch { return null; }
|
|
6742
|
+
};
|
|
6633
6743
|
const url = await vendorPoll('Sanbao', 8000, async () => {
|
|
6634
|
-
const
|
|
6635
|
-
|
|
6636
|
-
let j = null; try { j = JSON.parse(r.text); } catch { return { state: 'wait' }; }
|
|
6637
|
-
return sanbaoPollState(j);
|
|
6744
|
+
const j = await queryTask('Sanbao 查询');
|
|
6745
|
+
return j ? sanbaoPollState(j) : { state: 'wait' };
|
|
6638
6746
|
});
|
|
6639
|
-
|
|
6747
|
+
// 三宝 succeeded 只代表转码完成:CDN 缓存尚未铺开时首次 GET 会 502(实测 2–3 分钟,最迟 5 分钟)。
|
|
6748
|
+
// 任务已成功、钱已花 → 给 10 分钟重试窗口,每次重试前刷新签名地址;鉴权/请求错误仍立即失败。
|
|
6749
|
+
try {
|
|
6750
|
+
return await downloadVideoWithRetry(url, {}, {
|
|
6751
|
+
windowMs: SANBAO_DOWNLOAD_RETRY_MS,
|
|
6752
|
+
stepMs: SANBAO_DOWNLOAD_RETRY_STEP_MS,
|
|
6753
|
+
refreshUrl: async () => {
|
|
6754
|
+
const j = await queryTask('Sanbao 缓存查询');
|
|
6755
|
+
if (!j) return '';
|
|
6756
|
+
const st = sanbaoPollState(j);
|
|
6757
|
+
return st.state === 'done' ? st.url : '';
|
|
6758
|
+
},
|
|
6759
|
+
onRetry: (e, n) => {
|
|
6760
|
+
try {
|
|
6761
|
+
console.info('[IC] sanbao download not ready (' + ((e && e.message) || e) + ') — retry '
|
|
6762
|
+
+ n + '/' + Math.ceil(SANBAO_DOWNLOAD_RETRY_MS / SANBAO_DOWNLOAD_RETRY_STEP_MS));
|
|
6763
|
+
} catch { /* 诊断失败不影响重试 */ }
|
|
6764
|
+
},
|
|
6765
|
+
});
|
|
6766
|
+
} catch (e) {
|
|
6767
|
+
const err = new Error('三宝视频下载失败(任务 ' + tid + '):' + ((e && e.message) || e));
|
|
6768
|
+
err.status = e && e.status;
|
|
6769
|
+
throw err;
|
|
6770
|
+
}
|
|
6640
6771
|
},
|
|
6641
6772
|
// —— MiniMax 海螺:异步 task_id + query 接口 ——
|
|
6642
6773
|
async minimax(prompt, frameBlob, s, o) {
|
|
@@ -8188,8 +8319,22 @@ function queueThumb(assetId) {
|
|
|
8188
8319
|
const LS_DOCSYNC = 'dsh-ic:docsync:';
|
|
8189
8320
|
/** Host 侧改动了项目文档(Agent 建节点/连线/写内容/补设定集)→ 拉回并合并到本地画布。
|
|
8190
8321
|
* canvasId 非空 = 该画布文档(多画布);缺省 = 项目默认画布。 */
|
|
8191
|
-
|
|
8192
|
-
|
|
8322
|
+
/** 媒体节点指针空值保护(纯函数供回归):Host 副本把 assetId/lastAssetId 清成 null 时,
|
|
8323
|
+
* 本地有值则保留——null 不是有效写入(没人会"有意"清空指针),而这类 null 恰是
|
|
8324
|
+
* 「历史清理误判 / 跨机空库」污染后的形态;真删资产时展示层有缺失态兜底,保留指针永远可恢复。
|
|
8325
|
+
* Host 的非空值仍以 Host 为准(Agent 写入是有意的)。 */
|
|
8326
|
+
function protectMediaPointer(hostNode, localNode) {
|
|
8327
|
+
if (!hostNode || !hostNode.data || !localNode || !localNode.data) return hostNode;
|
|
8328
|
+
const t = normalizeNodeType(hostNode.type);
|
|
8329
|
+
if (t !== 'image' && t !== 'video') return hostNode;
|
|
8330
|
+
const local = localNode.data;
|
|
8331
|
+
const data = { ...hostNode.data };
|
|
8332
|
+
let changed = false;
|
|
8333
|
+
if (!data.assetId && local.assetId) { data.assetId = local.assetId; changed = true; }
|
|
8334
|
+
if (!data.lastAssetId && local.lastAssetId) { data.lastAssetId = local.lastAssetId; changed = true; }
|
|
8335
|
+
return changed ? { ...hostNode, data } : hostNode;
|
|
8336
|
+
}
|
|
8337
|
+
function mergeHostDoc(pid, full, canvasId) { if (!full) return;
|
|
8193
8338
|
const cid = full.canvasId || canvasId || DEFAULT_CANVAS_ID;
|
|
8194
8339
|
// Host 侧(对话 Agent)可能写入了旧类型节点:先把整份文档归一,再做合并(类型迁移与旧项目兼容)
|
|
8195
8340
|
normalizeGraphDoc(full);
|
|
@@ -8213,7 +8358,7 @@ function queueThumb(assetId) {
|
|
|
8213
8358
|
// (否则刚生成完的分镜会被一次过期合并清空,客户端再推回去就永久丢失)
|
|
8214
8359
|
if (cur && cur.type === 'storyboard' && Array.isArray(cur.data && cur.data.shots) && cur.data.shots.length
|
|
8215
8360
|
&& !(n && n.data && Array.isArray(n.data.shots) && n.data.shots.length)) continue;
|
|
8216
|
-
nodes[nid] = n; // Host
|
|
8361
|
+
nodes[nid] = protectMediaPointer(n, cur); // Host 为准,但媒体指针不允许被 Host 的 null 清空(回链被覆盖事故)
|
|
8217
8362
|
}
|
|
8218
8363
|
const deadEdges = new Set([...(local.edgeTombstones || []), ...(full.edgeTombstones || []), ...((live && live.edgeTombstones) || [])]);
|
|
8219
8364
|
const edges = (live && live.edges) ? [...live.edges] : [...(local.edges || [])];
|
|
@@ -8243,6 +8388,7 @@ function queueThumb(assetId) {
|
|
|
8243
8388
|
}
|
|
8244
8389
|
}
|
|
8245
8390
|
if (isActiveCanvas) update((s) => { s.graph = { nodes, edges: keep, view: s.graph.view, tombstones: tombOut, edgeTombstones: local.edgeTombstones || [] }; s.assetsTick++; });
|
|
8391
|
+
if (isActiveCanvas) scheduleRepair(); // 启动同步落图后自愈被误置空的资产引用
|
|
8246
8392
|
}
|
|
8247
8393
|
async function hostSyncTick() {
|
|
8248
8394
|
if (hostSyncStopped) return;
|
|
@@ -9471,6 +9617,46 @@ function queueThumb(assetId) {
|
|
|
9471
9617
|
return { x, y };
|
|
9472
9618
|
}
|
|
9473
9619
|
|
|
9620
|
+
/** 资产批量导入落点(纯函数供回归):在现有节点最右侧之外按列铺开,一列 ≤5 个。
|
|
9621
|
+
* existingRects:现有节点矩形 [{x,y,w,h}];items:[{w,h}](按导入顺序,仅计可成节点的资产)。
|
|
9622
|
+
* 返回 [{x,y,w,h}]:列内自上而下堆叠、放不下碰撞则顺延,列间 GAP_COL,彼此与现有节点零重叠。 */
|
|
9623
|
+
function layoutBatchColumns(existingRects, items, opts) {
|
|
9624
|
+
const o = opts || {};
|
|
9625
|
+
const GAP_X = Number(o.gapX) || 80; // 与现有节点最右界的水平间距
|
|
9626
|
+
const GAP_COL = Number(o.gapCol) || 60; // 列间距
|
|
9627
|
+
const GAP_Y = Number(o.gapY) || 40; // 行间距
|
|
9628
|
+
const PER_COL = Number(o.perCol) || 5; // 一列上限
|
|
9629
|
+
const rects = (existingRects || []).filter((r) => r && Number.isFinite(Number(r.x)));
|
|
9630
|
+
const baseX = rects.length
|
|
9631
|
+
? Math.round(Math.max(...rects.map((r) => (Number(r.x) || 0) + (Number(r.w) || 0))) + GAP_X)
|
|
9632
|
+
: 80;
|
|
9633
|
+
const baseY = Math.round(Number(o.y0) || 40);
|
|
9634
|
+
const placed = [];
|
|
9635
|
+
const hit = (x, y, w, h) => rects.find((r) => (Number(r.x) || 0) < x + w + 28 && (Number(r.x) || 0) + (Number(r.w) || 0) + 28 > x
|
|
9636
|
+
&& (Number(r.y) || 0) < y + h + 28 && (Number(r.y) || 0) + (Number(r.h) || 0) + 28 > y)
|
|
9637
|
+
|| placed.find((p) => p.x < x + w + 28 && p.x + p.w + 28 > x && p.y < y + h + 28 && p.y + p.h + 28 > y);
|
|
9638
|
+
const out = [];
|
|
9639
|
+
let colX = baseX;
|
|
9640
|
+
let colY = baseY;
|
|
9641
|
+
let colW = 0;
|
|
9642
|
+
let inCol = 0;
|
|
9643
|
+
for (const it of items || []) {
|
|
9644
|
+
const w = Math.max(1, Number(it && it.w) || 360);
|
|
9645
|
+
const h = Math.max(1, Number(it && it.h) || 220);
|
|
9646
|
+
if (inCol >= PER_COL) { colX = colX + colW + GAP_COL; colY = baseY; colW = 0; inCol = 0; }
|
|
9647
|
+
let y = colY;
|
|
9648
|
+
let blocker = hit(colX, y, w, h);
|
|
9649
|
+
let guard = 0;
|
|
9650
|
+
while (blocker && guard++ < 80) { y = (Number(blocker.y) || 0) + (Number(blocker.h) || 0) + 28; blocker = hit(colX, y, w, h); }
|
|
9651
|
+
out.push({ x: Math.round(colX), y: Math.round(y), w, h });
|
|
9652
|
+
placed.push({ x: colX, y, w, h });
|
|
9653
|
+
colW = Math.max(colW, w);
|
|
9654
|
+
colY = y + h + GAP_Y;
|
|
9655
|
+
inCol++;
|
|
9656
|
+
}
|
|
9657
|
+
return out;
|
|
9658
|
+
}
|
|
9659
|
+
|
|
9474
9660
|
function addNodeAt(type, pos) {
|
|
9475
9661
|
// 代码级强控制:建点坐标由布局引擎决定(一类型一列 + 碰撞下移),不信任调用者的自由坐标。
|
|
9476
9662
|
// 媒体节点外框按比例(与 Host nextNodePos 同口径),其余 360×360。
|
|
@@ -9507,6 +9693,84 @@ function queueThumb(assetId) {
|
|
|
9507
9693
|
pushHistory();
|
|
9508
9694
|
flushSave(); // 删除立即推送(不等 450ms 防抖):同步把 Host 上的节点删掉,压缩"拉回复活"的时间窗
|
|
9509
9695
|
}
|
|
9696
|
+
/** 历史条死条目裁剪(纯函数供回归):返回去死后的新数组,无死时原样返回(调用方按引用判变化)。
|
|
9697
|
+
* 【契约】只裁 history——绝不产生「清空当前 assetId」的语义(旧版清理曾把 assetId 置空落盘,
|
|
9698
|
+
* 刷新/跨机误判时造成生成节点预览全部丢失)。 */
|
|
9699
|
+
function pruneDeadHistory(history, aliveIds) {
|
|
9700
|
+
const hasDead = (history || []).some((x) => !aliveIds.has(x.assetId));
|
|
9701
|
+
if (!hasDead) return history;
|
|
9702
|
+
return (history || []).filter((x) => aliveIds.has(x.assetId));
|
|
9703
|
+
}
|
|
9704
|
+
/** 资产回链候选挑选(纯函数供回归):跳过已被其他节点引用的资产,取 createdAt 最新的一条;
|
|
9705
|
+
* 无可用候选返回 null(宁缺勿错)。 */
|
|
9706
|
+
function repairPickAsset(candidates, usedIds) {
|
|
9707
|
+
const pool = (candidates || []).filter((c) => c && c.id && !(usedIds && usedIds.has(c.id)));
|
|
9708
|
+
if (!pool.length) return null;
|
|
9709
|
+
let best = null;
|
|
9710
|
+
for (const c of pool) {
|
|
9711
|
+
if (!best || (Number(c.createdAt) || 0) >= (Number(best.createdAt) || 0)) best = c;
|
|
9712
|
+
}
|
|
9713
|
+
return best;
|
|
9714
|
+
}
|
|
9715
|
+
/** 资产回链计划(纯函数供回归):孤儿节点(done 无 assetId)按 nodeLabel 逐字匹配资产,
|
|
9716
|
+
* 跳过已被其他节点引用的候选,每节点取 createdAt 最新的一条;无可用候选 → 不产生修复项。 */
|
|
9717
|
+
function repairPlan(orphanNodes, recs, usedIdsIn) {
|
|
9718
|
+
const usedIds = new Set(usedIdsIn || []);
|
|
9719
|
+
const byLabel = new Map();
|
|
9720
|
+
for (const rec of recs || []) {
|
|
9721
|
+
if (rec.kind !== 'image' && rec.kind !== 'video') continue;
|
|
9722
|
+
const lb = String(rec.nodeLabel || '').trim();
|
|
9723
|
+
if (!lb) continue;
|
|
9724
|
+
if (!byLabel.has(lb)) byLabel.set(lb, []);
|
|
9725
|
+
byLabel.get(lb).push(rec);
|
|
9726
|
+
}
|
|
9727
|
+
const fixes = [];
|
|
9728
|
+
for (const nd of orphanNodes || []) {
|
|
9729
|
+
const pick = repairPickAsset(byLabel.get(String(nd.data.label || '').trim()), usedIds);
|
|
9730
|
+
if (!pick) continue;
|
|
9731
|
+
fixes.push({ id: nd.id, assetId: pick.id });
|
|
9732
|
+
usedIds.add(pick.id);
|
|
9733
|
+
}
|
|
9734
|
+
return fixes;
|
|
9735
|
+
}
|
|
9736
|
+
// 修复:旧版清理在 store 未就绪(刷新竞态)/跨机打开(本地库无资产行)时会误把 assetId
|
|
9737
|
+
// 置空并落盘 → 生成节点预览全部丢失(资产文件与资产库都还在,只有指针没了)。
|
|
9738
|
+
// 每次载入项目/切画布后跑一次:按 nodeLabel 与节点 label 逐字唯一匹配回链最新资产(幂等)。
|
|
9739
|
+
let repairDoneFor = '';
|
|
9740
|
+
let repairTimer = null;
|
|
9741
|
+
function scheduleRepair() {
|
|
9742
|
+
if (repairTimer) clearTimeout(repairTimer);
|
|
9743
|
+
repairTimer = setTimeout(() => { repairTimer = null; repairMissingAssetLinks().catch(() => { /* 静默 */ }); }, 1500);
|
|
9744
|
+
}
|
|
9745
|
+
async function repairMissingAssetLinks() {
|
|
9746
|
+
if (!S.store || !S.activeId) return;
|
|
9747
|
+
const nodes = Object.values(S.graph.nodes).filter((nd) => (nd.type === 'image' || nd.type === 'video')
|
|
9748
|
+
&& nd.data && nd.data.status === 'done' && !nd.data.assetId && String(nd.data.label || '').trim());
|
|
9749
|
+
// 图未加载 / 服务端暂时拉不到清单 → 不记账直接返回(下次调度重试);
|
|
9750
|
+
// 记账必须在"真正完成一次有效检查"之后,否则启动竞态会把每画布一次的额度烧掉
|
|
9751
|
+
if (!nodes.length) return;
|
|
9752
|
+
const recs = await idbByProject(S.activeId).catch(() => []);
|
|
9753
|
+
if (!recs.length) {
|
|
9754
|
+
try { console.info('[IC] asset-relink: orphans=' + nodes.length + ' recs=0(assetsList 未返回)'); } catch { /* 忽略 */ }
|
|
9755
|
+
return;
|
|
9756
|
+
}
|
|
9757
|
+
const key = S.activeId + '/' + activeCanvasId();
|
|
9758
|
+
if (repairDoneFor === key) return;
|
|
9759
|
+
repairDoneFor = key;
|
|
9760
|
+
const usedIds = new Set(Object.values(S.graph.nodes).map((nd) => nd.data && nd.data.assetId).filter(Boolean));
|
|
9761
|
+
const fixes = repairPlan(nodes, recs, usedIds);
|
|
9762
|
+
try { console.info('[IC] asset-relink: orphans=' + nodes.length + ' recs=' + recs.length + ' fixes=' + fixes.length); } catch { /* 忽略 */ }
|
|
9763
|
+
if (!fixes.length) return;
|
|
9764
|
+
update((s) => {
|
|
9765
|
+
for (const f of fixes) {
|
|
9766
|
+
const nd = s.graph.nodes[f.id];
|
|
9767
|
+
if (nd && nd.data && !nd.data.assetId) nd.data.assetId = f.assetId;
|
|
9768
|
+
}
|
|
9769
|
+
s.assetsTick++;
|
|
9770
|
+
});
|
|
9771
|
+
flushSave();
|
|
9772
|
+
toast(T('assetsRelinked').replace('{n}', String(fixes.length)));
|
|
9773
|
+
}
|
|
9510
9774
|
function duplicateSelection() {
|
|
9511
9775
|
const clones = [];
|
|
9512
9776
|
update((s) => {
|
|
@@ -12448,14 +12712,18 @@ function queueThumb(assetId) {
|
|
|
12448
12712
|
return () => { cancelled = true; };
|
|
12449
12713
|
}, [kind, n.data.assetId, n.data.label, S.assetsTick]);
|
|
12450
12714
|
// 历史条自愈:已被删除的资产(渲染成 … 的幽灵格)自动从节点 history 剔除;
|
|
12451
|
-
//
|
|
12715
|
+
// 【卫语句】store 未就绪绝不清理——sqlite 资产不在 IDB,误走 IDB 分支会把活资产
|
|
12716
|
+
// 全部判死并置空 assetId(刷新竞态曾造成生成节点预览全部丢失,见 0.19.18 修复记录)。
|
|
12717
|
+
// 【契约】清理只裁 history,绝不回写 data.assetId——当前资产指针是用户数据,
|
|
12718
|
+
// 资产真被删时展示层已有缺失态兜底,节点仍可重生成/重连。
|
|
12452
12719
|
useEffect(() => {
|
|
12453
12720
|
const histList = n.data.history || [];
|
|
12454
12721
|
if (!histList.length) return;
|
|
12722
|
+
if (!S.store) return;
|
|
12455
12723
|
let ok = true;
|
|
12456
12724
|
(async () => {
|
|
12457
12725
|
let alive = null;
|
|
12458
|
-
if (S.store) {
|
|
12726
|
+
if (S.store === 'sqlite') {
|
|
12459
12727
|
const r = await hostRpc('assetsGet', { ids: histList.map((x) => x.assetId) }).catch(() => null);
|
|
12460
12728
|
if (!r) return;
|
|
12461
12729
|
alive = new Set((r.items || []).map((x) => x.id));
|
|
@@ -12464,15 +12732,12 @@ function queueThumb(assetId) {
|
|
|
12464
12732
|
alive = new Set(histList.filter((_, i) => recs[i]).map((x) => x.assetId));
|
|
12465
12733
|
}
|
|
12466
12734
|
if (!ok) return;
|
|
12467
|
-
const
|
|
12468
|
-
if (
|
|
12735
|
+
const next = pruneDeadHistory(n.data.history, alive);
|
|
12736
|
+
if (next === n.data.history) return;
|
|
12469
12737
|
update((s) => {
|
|
12470
12738
|
const nd = s.graph.nodes[n.id];
|
|
12471
12739
|
if (!nd || !Array.isArray(nd.data.history)) return;
|
|
12472
|
-
const next = nd.data.history.filter((x) => !dead.includes(x.assetId));
|
|
12473
|
-
if (next.length === nd.data.history.length) return;
|
|
12474
12740
|
nd.data.history = next;
|
|
12475
|
-
if (nd.data.assetId && dead.includes(nd.data.assetId)) nd.data.assetId = next.length ? next[next.length - 1].assetId : null;
|
|
12476
12741
|
});
|
|
12477
12742
|
})();
|
|
12478
12743
|
return () => { ok = false; };
|
|
@@ -17760,6 +18025,16 @@ const DIRECTOR_KEY_HELP = [
|
|
|
17760
18025
|
* 搜索/分类/项目筛选与分页都在客户端做;卡片 = AssetCard(缩略图或视频首帧 + 名称 + 分类 + 时间,
|
|
17761
18026
|
* 预览/下载/添加到画布 全部保留)。右侧面板不再有资产页签。 */
|
|
17762
18027
|
const ASSET_PAGE_SIZE = 24;
|
|
18028
|
+
/** 资产分页跳转(纯函数):页码输入 → 0-based 页。
|
|
18029
|
+
* 非数字/空/小数 → null(保持当前页);越界夹取到 1..pageCount。 */
|
|
18030
|
+
function assetsPageIndex(raw, pageCount) {
|
|
18031
|
+
const t = String(raw == null ? '' : raw).trim();
|
|
18032
|
+
if (!/^\d+$/.test(t)) return null;
|
|
18033
|
+
const n = parseInt(t, 10);
|
|
18034
|
+
if (!Number.isFinite(n)) return null;
|
|
18035
|
+
const pc = Math.max(1, Number(pageCount) || 1);
|
|
18036
|
+
return Math.min(Math.max(1, n), pc) - 1;
|
|
18037
|
+
}
|
|
17763
18038
|
function AssetsTab({ variant } = {}) {
|
|
17764
18039
|
void variant;
|
|
17765
18040
|
const [assets, setAssets] = useState([]);
|
|
@@ -17778,13 +18053,16 @@ const DIRECTOR_KEY_HELP = [
|
|
|
17778
18053
|
const [craftFor, setCraftFor] = useState(null);
|
|
17779
18054
|
const [delTarget, setDelTarget] = useState(null); // 待确认删除的资产(确认框见 DeleteAssetModal)
|
|
17780
18055
|
const [assetName, setAssetName] = useState(''); // 删除确认框的输入内容
|
|
18056
|
+
const [selIds, setSelIds] = useState(() => new Set()); // 批量选择(资产 id):选中后一键按列导入画布 / 批量删除
|
|
18057
|
+
const [batchDel, setBatchDel] = useState(false); // 批量删除确认框
|
|
18058
|
+
const [pageDraft, setPageDraft] = useState(null); // 页码输入草稿(null = 显示当前页)
|
|
17781
18059
|
const fileRef = useRef(null);
|
|
17782
18060
|
// 搜索防抖:资产多时避免每个按键都过一遍全量过滤
|
|
17783
18061
|
useEffect(() => {
|
|
17784
18062
|
const t = setTimeout(() => setQDeb(search), 300);
|
|
17785
18063
|
return () => clearTimeout(t);
|
|
17786
18064
|
}, [search]);
|
|
17787
|
-
useEffect(() => { setPage(0); }, [filter, qDeb, scope]);
|
|
18065
|
+
useEffect(() => { setPage(0); setPageDraft(null); }, [filter, qDeb, scope]);
|
|
17788
18066
|
useEffect(() => {
|
|
17789
18067
|
probeCraft();
|
|
17790
18068
|
let ok = true;
|
|
@@ -17880,6 +18158,52 @@ const DIRECTOR_KEY_HELP = [
|
|
|
17880
18158
|
});
|
|
17881
18159
|
bumpView();
|
|
17882
18160
|
};
|
|
18161
|
+
// ---------- 批量选择:一键按列导入画布 / 批量删除 ----------
|
|
18162
|
+
// 落点由 layoutBatchColumns 决定(现有节点最右侧之外按列铺开,一列 ≤5,零重叠),
|
|
18163
|
+
// 音频资产不成节点(与单个添加同一口径),导入时跳过并提示数量。
|
|
18164
|
+
const selList = assets.filter((a) => selIds.has(a.id));
|
|
18165
|
+
const addableList = selList.filter((a) => a.kind !== 'audio');
|
|
18166
|
+
const audioN = selList.length - addableList.length;
|
|
18167
|
+
const allPageSel = () => shown.length > 0 && shown.every((a) => selIds.has(a.id));
|
|
18168
|
+
const toggleSel = (a) => setSelIds((prev) => { const n = new Set(prev); if (n.has(a.id)) n.delete(a.id); else n.add(a.id); return n; });
|
|
18169
|
+
const selectAllPage = () => setSelIds((prev) => {
|
|
18170
|
+
const n = new Set(prev);
|
|
18171
|
+
if (allPageSel()) shown.forEach((a) => n.delete(a.id));
|
|
18172
|
+
else shown.forEach((a) => n.add(a.id));
|
|
18173
|
+
return n;
|
|
18174
|
+
});
|
|
18175
|
+
const clearSel = () => setSelIds(new Set());
|
|
18176
|
+
const addSelectedToCanvas = () => {
|
|
18177
|
+
if (!addableList.length) { toast(T('assetsOnlyAudio')); return; }
|
|
18178
|
+
// 检测画布现有节点位置:批量落点在其最右侧之外按列铺开,绝不与现有节点重叠
|
|
18179
|
+
const rects = Object.values(S.graph.nodes)
|
|
18180
|
+
.filter((nd) => nd.type !== 'group' && !(nd.data && nd.data.hidden))
|
|
18181
|
+
.map((nd) => ({ x: Number(nd.x) || 0, y: Number(nd.y) || 0, w: Number(nd.w) || 280, h: Number(nd.h) || 160 }));
|
|
18182
|
+
const items = addableList.map((a) => (a.kind === 'text' ? { w: 360, h: 220 } : nodeSizeForRatio('16:9', { hasFooter: false })));
|
|
18183
|
+
const pts = layoutBatchColumns(rects, items);
|
|
18184
|
+
const newIds = [];
|
|
18185
|
+
update((s) => {
|
|
18186
|
+
addableList.forEach((a, k) => {
|
|
18187
|
+
const nd = newNode(a.kind === 'text' ? 'text' : a.kind, pts[k]);
|
|
18188
|
+
if (a.kind === 'text') nd.data.text = a.text || '';
|
|
18189
|
+
else { nd.data.assetId = a.id; nd.data.status = 'done'; }
|
|
18190
|
+
s.graph.nodes[nd.id] = nd;
|
|
18191
|
+
newIds.push(nd.id);
|
|
18192
|
+
});
|
|
18193
|
+
s.sel = new Set(newIds); s.selEdge = null;
|
|
18194
|
+
});
|
|
18195
|
+
pushHistory();
|
|
18196
|
+
flushSave();
|
|
18197
|
+
setSelIds(new Set());
|
|
18198
|
+
toast(T('assetsAdded').replace('{n}', String(addable.length)) + (audioN ? ',' + T('assetsAudioSkip').replace('{n}', String(audioN)) : ''));
|
|
18199
|
+
};
|
|
18200
|
+
const delSelected = async () => {
|
|
18201
|
+
const list = selList.slice();
|
|
18202
|
+
setBatchDel(false);
|
|
18203
|
+
for (const a of list) { try { await del(a); } catch { /* 单个失败继续其余 */ } }
|
|
18204
|
+
setSelIds(new Set());
|
|
18205
|
+
toast(T('assetsDeletedN').replace('{n}', String(list.length)));
|
|
18206
|
+
};
|
|
17883
18207
|
// 资产重命名:服务端写回(SQL/JSON 各自落库)+ 刷新名称缓存(@引用与连线名称都吃这份缓存)
|
|
17884
18208
|
const rename = async (a, name) => {
|
|
17885
18209
|
if (S.store) {
|
|
@@ -17922,6 +18246,19 @@ const DIRECTOR_KEY_HELP = [
|
|
|
17922
18246
|
const pageCount = Math.max(1, Math.ceil(filtered.length / ASSET_PAGE_SIZE));
|
|
17923
18247
|
const pageSafe = Math.min(Math.max(0, page), pageCount - 1);
|
|
17924
18248
|
const shown = filtered.slice(pageSafe * ASSET_PAGE_SIZE, pageSafe * ASSET_PAGE_SIZE + ASSET_PAGE_SIZE);
|
|
18249
|
+
/** 提交页码输入:回车/失焦;非法文本保持当前页,越界夹取(UI-RULES 第 15 条口径)。 */
|
|
18250
|
+
const commitPageJump = () => {
|
|
18251
|
+
const idx = assetsPageIndex(pageDraft, pageCount);
|
|
18252
|
+
if (idx != null) setPage(idx);
|
|
18253
|
+
setPageDraft(null);
|
|
18254
|
+
};
|
|
18255
|
+
/** 翻页:输入框有草稿时先以草稿为基准(避免 blur 提交与按钮翻页互相覆盖)。 */
|
|
18256
|
+
const goPage = (delta) => {
|
|
18257
|
+
const idx = pageDraft != null ? assetsPageIndex(pageDraft, pageCount) : null;
|
|
18258
|
+
const base = idx != null ? idx : pageSafe;
|
|
18259
|
+
setPage(Math.min(Math.max(0, base + delta), pageCount - 1));
|
|
18260
|
+
setPageDraft(null);
|
|
18261
|
+
};
|
|
17925
18262
|
return [
|
|
17926
18263
|
h('div', { key: 'chips', className: 'dshic-chips' },
|
|
17927
18264
|
[{ id: 'all', label: T('catAll') }].concat(CATEGORIES.map((c) => ({ id: c, label: catLabel(c) }))).map((c) =>
|
|
@@ -17943,8 +18280,61 @@ const DIRECTOR_KEY_HELP = [
|
|
|
17943
18280
|
.concat(S.projects.map((p) => ({ value: p.id, label: p.name }))),
|
|
17944
18281
|
onChange: (v) => setScope(v),
|
|
17945
18282
|
}),
|
|
17946
|
-
|
|
17947
|
-
|
|
18283
|
+
// 工具栏(项目下一行):所有操作按钮 + 分页集中在一行,窄窗口自动换行、分页始终靠右。
|
|
18284
|
+
// 按钮统一「透明底 + 1px 线框 + 文字」(UI-RULES:禁止灰底色块)。
|
|
18285
|
+
h('div', { key: 'toolbar', className: 'dshic-asset-toolbar', 'data-role': 'assets-toolbar' },
|
|
18286
|
+
h('div', { className: 'dshic-asset-toolbar-main' },
|
|
18287
|
+
h('button', {
|
|
18288
|
+
type: 'button', className: 'dshic-toolbtn', 'data-action': 'assets-sync-all',
|
|
18289
|
+
disabled: !craftOkCached(), title: craftOkCached() ? T('craftSyncAll') : T('craftUnreachable'),
|
|
18290
|
+
onClick: syncAll, onPointerDown: (e) => e.stopPropagation(),
|
|
18291
|
+
}, Ic('upload', 11), T('craftSyncAll')),
|
|
18292
|
+
h('button', {
|
|
18293
|
+
type: 'button', className: 'dshic-toolbtn', 'data-action': 'assets-import',
|
|
18294
|
+
onClick: () => { if (fileRef.current) fileRef.current.click(); },
|
|
18295
|
+
}, Ic('upload', 11), T('import')),
|
|
18296
|
+
h('label', { className: 'dshic-asset-selall', onPointerDown: (e) => e.stopPropagation() },
|
|
18297
|
+
h('input', { type: 'checkbox', checked: allPageSel(), disabled: !shown.length, onChange: selectAllPage }),
|
|
18298
|
+
T('assetsSelAllPage')),
|
|
18299
|
+
// 批量操作:选中 >0 时出现,与导入同一行(不另占一行)
|
|
18300
|
+
selIds.size
|
|
18301
|
+
? h('div', { key: 'batchbar', className: 'dshic-asset-batch', 'data-role': 'assets-batch-bar' },
|
|
18302
|
+
h('button', { type: 'button', className: 'dshic-toolbtn', 'data-action': 'assets-add-selected', disabled: !addableList.length, onClick: addSelectedToCanvas, onPointerDown: (e) => e.stopPropagation() }, Ic('expandAll', 11), T('assetsAddToCanvas') + '(' + addableList.length + ')'),
|
|
18303
|
+
h('button', { type: 'button', className: 'dshic-toolbtn is-danger', 'data-action': 'assets-batch-delete', onClick: () => setBatchDel(true), onPointerDown: (e) => e.stopPropagation() }, T('doDelete') + '(' + selIds.size + ')'),
|
|
18304
|
+
h('button', { type: 'button', className: 'dshic-toolbtn', 'data-action': 'assets-clear-sel', onClick: clearSel, onPointerDown: (e) => e.stopPropagation() }, T('assetsClearSel')),
|
|
18305
|
+
audioN ? h('span', { className: 'dshic-asset-audiohint' }, T('assetsAudioSkip').replace('{n}', String(audioN))) : null,
|
|
18306
|
+
)
|
|
18307
|
+
: null,
|
|
18308
|
+
),
|
|
18309
|
+
// 分页(客户端分页):‹ [页码输入] / N › + 总数;Enter/失焦跳转,Esc 取消,越界夹取
|
|
18310
|
+
h('div', { key: 'pager', className: 'dshic-asset-pager', 'data-role': 'assets-pager' },
|
|
18311
|
+
h('button', {
|
|
18312
|
+
type: 'button', className: 'dshic-toolbtn is-icon', 'data-action': 'assets-page-prev', title: T('pagePrev'),
|
|
18313
|
+
disabled: pageSafe <= 0, onClick: () => goPage(-1), onPointerDown: (e) => e.stopPropagation(),
|
|
18314
|
+
}, '‹'),
|
|
18315
|
+
h('div', { className: 'dshic-asset-pagebox' },
|
|
18316
|
+
h('input', {
|
|
18317
|
+
className: 'dshic-asset-pageinput', type: 'text', inputMode: 'numeric',
|
|
18318
|
+
'data-role': 'assets-page-input', 'aria-label': T('pageNumber'),
|
|
18319
|
+
value: pageDraft != null ? pageDraft : String(pageSafe + 1),
|
|
18320
|
+
onPointerDown: (e) => e.stopPropagation(),
|
|
18321
|
+
onClick: (e) => e.stopPropagation(),
|
|
18322
|
+
onChange: (e) => setPageDraft(e.target.value),
|
|
18323
|
+
onBlur: commitPageJump,
|
|
18324
|
+
onKeyDown: (e) => {
|
|
18325
|
+
if (e.key === 'Enter') { e.preventDefault(); e.stopPropagation(); commitPageJump(); }
|
|
18326
|
+
else if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); setPageDraft(null); }
|
|
18327
|
+
},
|
|
18328
|
+
}),
|
|
18329
|
+
h('span', { className: 'dshic-asset-pagetotal', 'data-role': 'assets-page-total' }, '/ ' + pageCount),
|
|
18330
|
+
),
|
|
18331
|
+
h('button', {
|
|
18332
|
+
type: 'button', className: 'dshic-toolbtn is-icon', 'data-action': 'assets-page-next', title: T('pageNext'),
|
|
18333
|
+
disabled: pageSafe >= pageCount - 1, onClick: () => goPage(1), onPointerDown: (e) => e.stopPropagation(),
|
|
18334
|
+
}, '›'),
|
|
18335
|
+
h('span', { className: 'dshic-asset-pagecount', 'data-role': 'assets-page-info' }, T('assetsTotalCount').replace('{n}', String(filtered.length))),
|
|
18336
|
+
),
|
|
18337
|
+
),
|
|
17948
18338
|
h('input', { key: 'file', ref: fileRef, type: 'file', accept: 'image/*,video/*', multiple: true, style: { display: 'none' }, onChange: onImport }),
|
|
17949
18339
|
loading && !assets.length
|
|
17950
18340
|
? h('div', { key: 'loading', className: 'dshic-hint' }, T('aiRunning'))
|
|
@@ -17955,25 +18345,25 @@ const DIRECTOR_KEY_HELP = [
|
|
|
17955
18345
|
key: a.id, a, onAdd: addNodeFor, onDel: (x) => setDelTarget(x), onCat: changeCategory,
|
|
17956
18346
|
onRename: rename, onMove: moveAsset,
|
|
17957
18347
|
projectName: projectName(a.projectId),
|
|
18348
|
+
checked: selIds.has(a.id), onToggleSel: toggleSel,
|
|
17958
18349
|
})),
|
|
17959
18350
|
),
|
|
17960
|
-
// 分页(客户端分页:资产数据源已是全量 assetsForPicker)
|
|
17961
|
-
h('div', { key: 'pager', className: 'dshic-asset-pager' },
|
|
17962
|
-
h('button', {
|
|
17963
|
-
type: 'button', className: 'dshic-mini is-ghost', 'data-action': 'assets-page-prev',
|
|
17964
|
-
disabled: pageSafe <= 0, onClick: () => setPage(pageSafe - 1), onPointerDown: (e) => e.stopPropagation(),
|
|
17965
|
-
}, '‹ ' + T('pagePrev')),
|
|
17966
|
-
h('span', { 'data-role': 'assets-page-info' }, (pageSafe + 1) + ' / ' + pageCount + ' · ' + filtered.length + ' / ' + assets.length),
|
|
17967
|
-
h('button', {
|
|
17968
|
-
type: 'button', className: 'dshic-mini is-ghost', 'data-action': 'assets-page-next',
|
|
17969
|
-
disabled: pageSafe >= pageCount - 1, onClick: () => setPage(pageSafe + 1), onPointerDown: (e) => e.stopPropagation(),
|
|
17970
|
-
}, T('pageNext') + ' ›'),
|
|
17971
|
-
),
|
|
17972
18351
|
delTarget ? h(DeleteAssetModal, {
|
|
17973
18352
|
key: 'delasset', target: delTarget, name: assetName, setName: setAssetName,
|
|
17974
18353
|
onCancel: () => { setDelTarget(null); setAssetName(''); },
|
|
17975
18354
|
onConfirm: async () => { const t = delTarget; setDelTarget(null); setAssetName(''); await del(t); },
|
|
17976
18355
|
}) : null,
|
|
18356
|
+
batchDel ? h('div', { className: 'dshic-modal-overlay', onPointerDown: (e) => { if (e.target === e.currentTarget) setBatchDel(false); } },
|
|
18357
|
+
h('div', { className: 'dshic-modal' },
|
|
18358
|
+
h('div', { className: 'dshic-modal-title' }, T('delAssetTitle') + ' × ' + selIds.size),
|
|
18359
|
+
h('div', { className: 'dshic-modal-warn' },
|
|
18360
|
+
T('assetsBatchDelWarn'),
|
|
18361
|
+
h('div', { className: 'dshic-modal-name', style: { marginTop: 4 } },
|
|
18362
|
+
selList.slice(0, 3).map((a) => a.name || '—').join('、') + (selList.length > 3 ? ' …' : ''))),
|
|
18363
|
+
h('div', { className: 'dshic-modal-actions' },
|
|
18364
|
+
h('button', { type: 'button', className: 'dshic-btn dshic-btn-outline', onClick: () => setBatchDel(false) }, T('cancel')),
|
|
18365
|
+
h('button', { type: 'button', className: 'dshic-btn is-danger', onClick: delSelected }, T('doDelete'))),
|
|
18366
|
+
)) : null,
|
|
17977
18367
|
];
|
|
17978
18368
|
}
|
|
17979
18369
|
/** 删除资产确认框:与项目删除同一套交互 —— 名字可选中,手打确认,不做一键填入。 */
|
|
@@ -18009,7 +18399,7 @@ const DIRECTOR_KEY_HELP = [
|
|
|
18009
18399
|
));
|
|
18010
18400
|
}
|
|
18011
18401
|
|
|
18012
|
-
function AssetCard({ a, onAdd, onDel, onCat, onRename, onMove, projectName }) {
|
|
18402
|
+
function AssetCard({ a, checked = false, onToggleSel = () => {}, onAdd, onDel, onCat, onRename, onMove, projectName }) {
|
|
18013
18403
|
const url = useAssetUrl(a.kind === 'text' ? null : a.id);
|
|
18014
18404
|
const [craftFor, setCraftFor] = useState(false);
|
|
18015
18405
|
const [renaming, setRenaming] = useState(false);
|
|
@@ -18034,7 +18424,17 @@ const DIRECTOR_KEY_HELP = [
|
|
|
18034
18424
|
onClick: startRename,
|
|
18035
18425
|
}, Ic('pencil', 11));
|
|
18036
18426
|
const downloadName = (a.name || 'asset') + extForDownload(a.mime, a.name, a.kind);
|
|
18037
|
-
return h('div', {
|
|
18427
|
+
return h('div', {
|
|
18428
|
+
className: cls('dshic-asset', checked && 'is-checked'),
|
|
18429
|
+
onClick: () => onToggleSel(a),
|
|
18430
|
+
onDoubleClick: a.kind === 'audio' ? undefined : () => onAdd(a), // 双击 = 单个直接添加(熟练用户捷径)
|
|
18431
|
+
title: T('assetClickHint'),
|
|
18432
|
+
},
|
|
18433
|
+
// 复选框:批量选择入口(单击卡片也切换选中;图标按钮仍 stopPropagation 不受影响)
|
|
18434
|
+
h('input', { type: 'checkbox', className: 'dshic-asset-check', checked: !!checked,
|
|
18435
|
+
onPointerDown: (e) => e.stopPropagation(),
|
|
18436
|
+
onClick: (e) => { e.stopPropagation(); onToggleSel(a); },
|
|
18437
|
+
onChange: () => {} }),
|
|
18038
18438
|
a.kind === 'text'
|
|
18039
18439
|
? h('div', { className: 'dshic-textcard is-title' },
|
|
18040
18440
|
renaming ? nameInput : h('div', { className: 'dshic-textcard-title', title: a.name || '' }, a.name || T('scriptAssetPrefix')),
|
|
@@ -20181,6 +20581,10 @@ const DIRECTOR_KEY_HELP = [
|
|
|
20181
20581
|
fetchUpdateRegistry();
|
|
20182
20582
|
// 数据根目录(Host 旧版静默降级为 IndexedDB 模式);就绪后把本地遗留 blob 搬进服务端(v1 旧布局由 Host 侧自动迁移)
|
|
20183
20583
|
refreshDataRoot().then(() => migrateLegacyAssets('boot')).catch(() => { /* 静默 */ });
|
|
20584
|
+
// 资产指针自愈:显式调度,不依赖同步回调(普通启动没有文档变更信号,mergeHostDoc 不会触发)。
|
|
20585
|
+
// 2s 主跑 + 10s 兜底重试(图/资产清单加载慢时第二轮补上);scheduleRepair 自带 1.5s 防抖。
|
|
20586
|
+
setTimeout(() => scheduleRepair(), 2000);
|
|
20587
|
+
setTimeout(() => scheduleRepair(), 10000);
|
|
20184
20588
|
// 对话 ↔ 画布同步(启动一次 + 3s 轮询;旧 Host 自动停轮询)
|
|
20185
20589
|
hostSyncTick().then(() => pushAllProjectsToHost());
|
|
20186
20590
|
const hostSyncTimer = setInterval(() => hostSyncTick(), 3000);
|
|
@@ -20337,6 +20741,14 @@ const DIRECTOR_KEY_HELP = [
|
|
|
20337
20741
|
wheelScrollTarget,
|
|
20338
20742
|
// 建点布局强控制(一类型一列 + 碰撞下移):addNodeAt 收口 + 纯函数,供回归测试直接驱动
|
|
20339
20743
|
nextNodePosClient, addNodeAt,
|
|
20744
|
+
// 资产批量导入落点:现有节点最右侧之外按列铺开(一列 ≤5,零重叠),供回归测试直接断言
|
|
20745
|
+
layoutBatchColumns,
|
|
20746
|
+
// 资产页分页跳转(页码输入 → 0-based 页;非法文本 null、越界夹取)
|
|
20747
|
+
assetsPageIndex,
|
|
20748
|
+
// 历史条死条目裁剪 / 资产回链候选挑选与回链计划(纯函数,供回归测试直接断言)
|
|
20749
|
+
pruneDeadHistory, repairPickAsset, repairPlan,
|
|
20750
|
+
// 媒体节点指针空值保护(Host 合并不得用 null 覆盖本地有效 assetId/lastAssetId)
|
|
20751
|
+
protectMediaPointer,
|
|
20340
20752
|
graph: () => JSON.parse(JSON.stringify(S.graph)), // 建点结果断言用(与 SYNC.graph 同口径)
|
|
20341
20753
|
addGraphNodes: (list) => { for (const n of (list || [])) S.graph.nodes[n.id] = n; }, // 测试播种(写入活状态)
|
|
20342
20754
|
// 下拉自定义数值的纯函数:范围夹取 / 整数与小数口径(分镜数、单段上限共用)
|
|
@@ -20384,7 +20796,7 @@ const DIRECTOR_KEY_HELP = [
|
|
|
20384
20796
|
// IC-04:参考图上传三件套的纯函数出口(供 scripts/test-image-upload.mjs 直接断言)
|
|
20385
20797
|
window.__DSH_IC_IMGREF__ = { rawImageDims, sniffImageEncoding, registerReferenceAsset };
|
|
20386
20798
|
// IC-03:视频厂商识别/前缀归一化的纯函数出口(供 scripts/test-vendor-detect.mjs 直接断言)
|
|
20387
|
-
window.__DSH_IC_VENDOR__ = { detectVideoVendor, gatewayPrefixFor, wanEndpoints, vendorBase, VIDEO_REF_CAPS, needsSimpleMediaRetry, buildSimpleMediaRetryBody, wanTaskIdOf, wanStatusOf, wanPollState, buildSanbaoVideoBody, sanbaoTaskIdOf, sanbaoPollState, needsSanbaoMediaRetry, bibleStyleAnchor };
|
|
20799
|
+
window.__DSH_IC_VENDOR__ = { detectVideoVendor, gatewayPrefixFor, wanEndpoints, vendorBase, VIDEO_REF_CAPS, needsSimpleMediaRetry, buildSimpleMediaRetryBody, wanTaskIdOf, wanStatusOf, wanPollState, buildSanbaoVideoBody, sanbaoTaskIdOf, sanbaoPollState, needsSanbaoMediaRetry, retryableDownloadError, downloadVideoWithRetry, SANBAO_DOWNLOAD_RETRY_MS, SANBAO_DOWNLOAD_RETRY_STEP_MS, bibleStyleAnchor };
|
|
20388
20800
|
// 按镜头切段(分段生成本身就是最容易出错的地方):规划器 + 强弱模型分流 + 节点段区间解析
|
|
20389
20801
|
// 供 scripts/test-segment-plan.mjs 直接断言
|
|
20390
20802
|
window.__DSH_IC_SEGMENT__ = { planShotSegments, isCutPoint, segmentNeedsHardFrame, videoSegmentOf, shotContinuityPlan };
|
package/docs/UI-RULES.md
CHANGED
|
@@ -68,6 +68,8 @@
|
|
|
68
68
|
41. **设置页技能增强 = 单一「专家」下拉**:专家 = 一套技能组(`persona` + `skills`);选项**只列本插件专家**(当前仅「通用专家 / General expert」,默认值 `general`),**禁止列举 Harness 全部技能**(artcraft-* / noteboard-* / office-* / diagnose-* 等一律不得出现);旧设置 `skillScript` / `skillStoryboard` 迁移到 `general`,缺字段/非法值回退 `general` 且不报错。
|
|
69
69
|
42. **画布性能**:视频节点空闲时只渲染静态 poster(不挂 `<video>`,播放时才挂、暂停/播完卸载),有 poster 即视为 ready,骨架只允许在首次取 poster 时出现一次;拖动/平移的每一帧**不得** `notify()` 全树、不得遍历全部节点,松手只通知一次;`idbGet` 在 SQLite 模式必须先走服务端,**不得**每次前置查 IndexedDB。
|
|
70
70
|
|
|
71
|
+
43. **资产页工具栏**:所有操作按钮(同步全部资产到磁盘 / 导入图片/视频 / 全选本页 / 添加到画布 / 批量删除 / 清除选择)与分页**集中在项目下拉下一行**,不各自占行;按钮一律**透明底 + 1px 线框 + 文字**(禁止灰色/品牌色块底),删除按钮用红色线框 + 红字;分页为 `‹ [页码输入] / N ›`,回车/失焦跳转、非法文本不改页、越界夹取到 1..N,右侧显示总数;窄窗口自动换行,分页始终靠右。
|
|
72
|
+
|
|
71
73
|
---
|
|
72
74
|
|
|
73
75
|
**自检方式**:改完 UI 后逐条对照本文件;涉及"禁止/不得"的条目,必须在测试里有**反向断言**(例如断言某样式不存在),而不是靠肉眼确认。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ninkch/dsh-infinite-canvas",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.18",
|
|
4
4
|
"description": "无限画布(Infinite Canvas)for DeepSeek Harness:节点式创作工作室(剧本/分镜/生成/成片),内置「媒体创作」预设模式(导演第一视角 + 引导工作坊)。Version-agnostic: reads the live catalog from the installed package at load time.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|