diff --git a/web/character_loader.js b/web/character_loader.js index a0fc074..c78e9d1 100644 --- a/web/character_loader.js +++ b/web/character_loader.js @@ -1,6 +1,7 @@ import { API_ROOT, COLORS, EMPTY_VALUE } from "./constants.js"; import { findWidget, + flashButton, registerNode, setWidgetValue, waitForWidgets, @@ -66,30 +67,6 @@ const loadFileIntoWidgets = async (file, node) => { // --- Buttons --- -const flashButton = (node, index, flashLabel) => { - const buttonRowWidget = node.widgets?.find( - (w) => w.name === "action_buttons", - ); - if (!buttonRowWidget) return; - const btn = buttonRowWidget.buttons[index]; - - // Cancel previous timer if existing - if (btn._flashTimer) clearTimeout(btn._flashTimer); - - // Save original if not flashing - if (!btn._originalLabel) btn._originalLabel = btn.label; - - btn.label = flashLabel; - if (node.graph) node.graph.setDirtyCanvas(true, true); - - btn._flashTimer = setTimeout(() => { - btn.label = btn._originalLabel; - btn._originalLabel = null; - btn._flashTimer = null; - if (node.graph) node.graph.setDirtyCanvas(true, true); - }, 1500); -}; - const handleNew = async (node, characterFileWidget) => { const name = prompt("New character file name (e.g. characters/Alice):"); if (!name?.trim()) return; diff --git a/web/style_loader.js b/web/style_loader.js index faa4547..e5c01b4 100644 --- a/web/style_loader.js +++ b/web/style_loader.js @@ -1,6 +1,7 @@ import { API_ROOT, COLORS, EMPTY_VALUE } from "./constants.js"; import { findWidget, + flashButton, registerNode, setWidgetValue, waitForWidgets, @@ -265,30 +266,6 @@ const loadFileIntoWidgets = async ( // --- Buttons --- -const flashButton = (node, index, flashLabel) => { - const buttonRowWidget = node.widgets.find( - (w) => w.name === "action_buttons", - ); - if (!buttonRowWidget) return; - const btn = buttonRowWidget.buttons[index]; - - // Cancel previous timer if existing - if (btn._flashTimer) clearTimeout(btn._flashTimer); - - // Save original if not flashing - if (!btn._originalLabel) btn._originalLabel = btn.label; - - btn.label = flashLabel; - if (node.graph) node.graph.setDirtyCanvas(true, true); - - btn._flashTimer = setTimeout(() => { - btn.label = btn._originalLabel; - btn._originalLabel = null; - btn._flashTimer = null; - if (node.graph) node.graph.setDirtyCanvas(true, true); - }, 1500); -}; - const handleNew = async (node, styleFileWidget, addButtonWidget) => { const name = prompt("New style file name (e.g. anime/illustrious):"); if (!name?.trim()) return; diff --git a/web/utils.js b/web/utils.js index e4a7be6..2f7e463 100644 --- a/web/utils.js +++ b/web/utils.js @@ -380,3 +380,29 @@ export const waitForWidgets = (node, callback) => { }; requestAnimationFrame(tryAttach); }; + +// --- Buttons --- + +export const flashButton = (node, index, flashLabel) => { + const buttonRowWidget = node.widgets.find( + (w) => w.name === "action_buttons", + ); + if (!buttonRowWidget) return; + const btn = buttonRowWidget.buttons[index]; + + // Cancel previous timer if existing + if (btn._flashTimer) clearTimeout(btn._flashTimer); + + // Save original if not flashing + if (!btn._originalLabel) btn._originalLabel = btn.label; + + btn.label = flashLabel; + if (node.graph) node.graph.setDirtyCanvas(true, true); + + btn._flashTimer = setTimeout(() => { + btn.label = btn._originalLabel; + btn._originalLabel = null; + btn._flashTimer = null; + if (node.graph) node.graph.setDirtyCanvas(true, true); + }, 1500); +};