From 81a0e50b2dd39d38bc1c19217128bce08a9d1077 Mon Sep 17 00:00:00 2001 From: Jony <951565127@qq.com> Date: Mon, 9 Nov 2026 10:49:28 +0800 Subject: [PATCH] Split batch clear buttons for source and target images --- tests/test_o1key_image_generator_frontend.mjs | 37 +++++++++-- web/js/o1keyImageGenerator.js | 62 ++++++++++++------- 2 files changed, 72 insertions(+), 27 deletions(-) diff --git a/tests/test_o1key_image_generator_frontend.mjs b/tests/test_o1key_image_generator_frontend.mjs index 2d230e9..e39f3d0 100644 --- a/tests/test_o1key_image_generator_frontend.mjs +++ b/tests/test_o1key_image_generator_frontend.mjs @@ -337,9 +337,10 @@ const renderReferenceRole = vm.runInContext("renderReferenceRole", context); const editReference = vm.runInContext("editReference", context); const replaceReference = vm.runInContext("replaceReference", context); const updateBatchReferenceHint = vm.runInContext("updateBatchReferenceHint", context); -const clearAllReferences = vm.runInContext("clearAllReferences", context); +const clearReferenceRole = vm.runInContext("clearReferenceRole", context); const syncClearReferenceButtons = vm.runInContext("syncClearReferenceButtons", context); const referenceListsAreEmpty = vm.runInContext("referenceListsAreEmpty", context); +const referenceRoleIsEmpty = vm.runInContext("referenceRoleIsEmpty", context); const setWidgetValue = vm.runInContext("setWidgetValue", context); const updateBatchSummary = vm.runInContext("updateBatchSummary", context); const initializeSaveSlots = vm.runInContext("initializeSaveSlots", context); @@ -516,10 +517,12 @@ function createRecoveryNodes(batchId, generatorId, saveNodeId) { assert.equal(modelActions.className, "o1ig-asset-actions"); assert.equal(modelActions.children[0], node._o1igClearModelReferences); assert.equal(modelActions.children[1], node._o1igModelCanvasPick); - assert.equal(node._o1igClearModelReferences.children[0].textContent, "清空"); + assert.equal(node._o1igClearModelReferences.children[0].textContent, "清空目标图"); assert.equal(node._o1igClearModelReferences.disabled, true); + assert.equal(node._o1igClearReferences.children[0].textContent, "清空素材图"); node._o1igBatchToggle.dispatch("click"); assert.equal(node._o1igBatchEnabled, false); + assert.equal(node._o1igClearReferences.children[0].textContent, "清空参考图"); const promptWidget = widgets.find(widget => widget.name === "prompt"); const computeSize = promptWidget.computeSize; promptWidget.options = {};promptWidget.hidden = false; @@ -3141,8 +3144,10 @@ function createRecoveryNodes(batchId, generatorId, saveNodeId) { }; buildPanel(clearNode); assert.equal(referenceListsAreEmpty(clearNode), true); - assert.equal(clearAllReferences(clearNode), false, "No-op when already empty"); + assert.equal(referenceRoleIsEmpty(clearNode, "references"), true); + assert.equal(clearReferenceRole(clearNode, "references"), false, "No-op when already empty"); assert.equal(clearNode._o1igClearReferences.disabled, true); + assert.equal(clearNode._o1igClearReferences.children[0].textContent, "清空参考图"); clearNode._o1igReferences = [ { name: "a.png", subfolder: "", type: "input" }, @@ -3153,11 +3158,10 @@ function createRecoveryNodes(batchId, generatorId, saveNodeId) { setWidgetValue(clearNode, "蒙版清单", JSON.stringify(clearNode._o1igMask)); syncClearReferenceButtons(clearNode); assert.equal(clearNode._o1igClearReferences.disabled, false); - assert.equal(clearAllReferences(clearNode), true); + assert.equal(clearReferenceRole(clearNode, "references"), true); assert.deepEqual(JSON.parse(JSON.stringify(clearNode._o1igReferences)), []); assert.deepEqual(JSON.parse(JSON.stringify(clearNode._o1igModelReferences)), []); assert.equal(widgets.find((widget) => widget.name === "参考图清单").value, "[]"); - assert.equal(widgets.find((widget) => widget.name === "模特图清单").value, "[]"); assert.deepEqual( JSON.parse(JSON.stringify(clearNode._o1igMask)), { name: "mask.png", subfolder: "", type: "input" }, @@ -3176,7 +3180,24 @@ function createRecoveryNodes(batchId, generatorId, saveNodeId) { syncClearReferenceButtons(clearNode); assert.equal(clearNode._o1igClearReferences.disabled, false); assert.equal(clearNode._o1igClearModelReferences.disabled, false); + assert.equal(clearNode._o1igClearReferences.children[0].textContent, "清空素材图"); + assert.equal(clearNode._o1igClearModelReferences.children[0].textContent, "清空目标图"); + assert.equal(clearNode._o1igClearReferences.title, "清空全部素材图"); + assert.equal(clearNode._o1igClearModelReferences.title, "清空全部目标图"); + clearNode._o1igClearModelReferences.dispatch("click"); + assert.deepEqual( + JSON.parse(JSON.stringify(clearNode._o1igReferences)), + [{ name: "outfit.png", subfolder: "", type: "input" }], + "Clearing 目标图 must not touch 素材图", + ); + assert.deepEqual(JSON.parse(JSON.stringify(clearNode._o1igModelReferences)), []); + assert.equal(widgets.find((widget) => widget.name === "参考图清单").value, JSON.stringify([{ name: "outfit.png", subfolder: "", type: "input" }])); + assert.equal(widgets.find((widget) => widget.name === "模特图清单").value, "[]"); + assert.equal(clearNode._o1igClearReferences.disabled, false); + assert.equal(clearNode._o1igClearModelReferences.disabled, true); + + clearNode._o1igClearReferences.dispatch("click"); assert.deepEqual(JSON.parse(JSON.stringify(clearNode._o1igReferences)), []); assert.deepEqual(JSON.parse(JSON.stringify(clearNode._o1igModelReferences)), []); assert.equal(widgets.find((widget) => widget.name === "参考图清单").value, "[]"); @@ -3274,8 +3295,12 @@ assert.match(source, /\.o1ig-thumb\{[\s\S]*?flex:0 0 102px;height:102px/); assert.match(source, /\.o1ig-thumb img\{[\s\S]*?object-fit:contain;background:var\(--o1ig-surface\)/); assert.match(source, /referenceActions\.append\(clearReferences, canvasPick\)/); assert.match(source, /modelActions\.append\(clearModelReferences, modelCanvasPick\)/); -assert.match(source, /function clearAllReferences\(node\)/); +assert.match(source, /function clearReferenceRole\(node, role = "references"\)/); assert.match(source, /textContent = "清空参考图"/); +assert.match(source, /textContent = "清空目标图"/); +assert.match(source, /batch \? "清空素材图" : "清空参考图"/); +assert.match(source, /clearReferenceRole\(node, "references"\)/); +assert.match(source, /clearReferenceRole\(node, "models"\)/); assert.match(source, /\.o1ig-clear-refs\{/); assert.doesNotMatch(source, /o1ig-add[\s\S]{0,400}?addLabel\.textContent = "上传"/, "头部不再有上传按钮"); assert.match(source, /upload\.addEventListener\("click", \(\) => requestReferenceUpload\(node, role\)\)/); diff --git a/web/js/o1keyImageGenerator.js b/web/js/o1keyImageGenerator.js index c937d90..3b85ea9 100644 --- a/web/js/o1keyImageGenerator.js +++ b/web/js/o1keyImageGenerator.js @@ -2299,37 +2299,57 @@ function renderReferences(node) { syncClearReferenceButtons(node); } -function referenceListsAreEmpty(node) { +function referenceRoleIsEmpty(node, role = "references") { + if (role === "models") { + return !( + (node?._o1igModelReferences?.length || 0) + || (node?._o1igModelPending?.length || 0) + ); + } return !( (node?._o1igReferences?.length || 0) || (node?._o1igPending?.length || 0) - || (node?._o1igModelReferences?.length || 0) - || (node?._o1igModelPending?.length || 0) ); } +function referenceListsAreEmpty(node) { + return referenceRoleIsEmpty(node, "references") && referenceRoleIsEmpty(node, "models"); +} + function syncClearReferenceButtons(node) { - const empty = referenceListsAreEmpty(node); + const batch = Boolean(node?._o1igBatchEnabled); if (node?._o1igClearReferences) { + const empty = referenceRoleIsEmpty(node, "references"); + const label = batch ? "清空素材图" : "清空参考图"; node._o1igClearReferences.disabled = empty; - node._o1igClearReferences.title = empty ? "暂无参考图可清空" : "清空全部参考图与目标图"; + const span = node._o1igClearReferences.children?.[0]; + if (span) span.textContent = label; + node._o1igClearReferences.title = empty + ? (batch ? "暂无素材图可清空" : "暂无参考图可清空") + : (batch ? "清空全部素材图" : "清空全部参考图"); } if (node?._o1igClearModelReferences) { + const empty = referenceRoleIsEmpty(node, "models"); node._o1igClearModelReferences.disabled = empty; - node._o1igClearModelReferences.title = empty ? "暂无图片可清空" : "清空全部素材图与目标图"; + const span = node._o1igClearModelReferences.children?.[0]; + if (span) span.textContent = "清空目标图"; + node._o1igClearModelReferences.title = empty ? "暂无目标图可清空" : "清空全部目标图"; } } -/** Clear every reference image list the panel uses for generation (batch + non-batch). */ -function clearAllReferences(node) { - if (!node || referenceListsAreEmpty(node)) return false; - node._o1igReferences = []; - node._o1igPending = []; - node._o1igModelReferences = []; - node._o1igModelPending = []; - // Follow single-tile remove: mask stays on its own control. - setWidgetValue(node, "参考图清单", "[]"); - setWidgetValue(node, "模特图清单", "[]"); +/** Clear one reference role list (素材/参考图 or 目标图). Mask stays untouched. */ +function clearReferenceRole(node, role = "references") { + if (!node || referenceRoleIsEmpty(node, role)) return false; + if (role === "models") { + node._o1igModelReferences = []; + node._o1igModelPending = []; + setWidgetValue(node, "模特图清单", "[]"); + } else { + node._o1igReferences = []; + node._o1igPending = []; + // Follow single-tile remove: mask stays on its own control. + setWidgetValue(node, "参考图清单", "[]"); + } renderReferences(node); return true; } @@ -5008,11 +5028,11 @@ function buildPanel(node) { const clearReferences = document.createElement("button"); clearReferences.type = "button"; clearReferences.className = "o1ig-clear-refs"; - clearReferences.title = "清空全部参考图与目标图"; + clearReferences.title = "清空全部参考图"; const clearReferencesLabel = document.createElement("span"); clearReferencesLabel.textContent = "清空参考图"; clearReferences.append(clearReferencesLabel); - clearReferences.addEventListener("click", () => clearAllReferences(node)); + clearReferences.addEventListener("click", () => clearReferenceRole(node, "references")); referenceActions.className = "o1ig-asset-actions"; referenceActions.append(clearReferences, canvasPick); referenceHeader.append(referenceMeta, referenceActions); @@ -5060,11 +5080,11 @@ function buildPanel(node) { const clearModelReferences = document.createElement("button"); clearModelReferences.type = "button"; clearModelReferences.className = "o1ig-clear-refs"; - clearModelReferences.title = "清空全部素材图与目标图"; + clearModelReferences.title = "清空全部目标图"; const clearModelReferencesLabel = document.createElement("span"); - clearModelReferencesLabel.textContent = "清空"; + clearModelReferencesLabel.textContent = "清空目标图"; clearModelReferences.append(clearModelReferencesLabel); - clearModelReferences.addEventListener("click", () => clearAllReferences(node)); + clearModelReferences.addEventListener("click", () => clearReferenceRole(node, "models")); modelActions.className = "o1ig-asset-actions"; modelActions.append(clearModelReferences, modelCanvasPick); modelHeader.append(modelMeta, modelActions);