diff --git a/__init__.py b/__init__.py index 3647136..b943bbe 100644 --- a/__init__.py +++ b/__init__.py @@ -13,6 +13,7 @@ js_dest_path = os.path.join(comfy_path, "web", "extensions", "SDPromptReader") os.makedirs(js_dest_path, exist_ok=True) files_to_copy = [ + "utils.js", "promptDisplay.js", "parameterDisplay.js", "seedGen.js", diff --git a/js/extractorDisplay.js b/js/extractorDisplay.js index 4e87693..9b9d3e3 100644 --- a/js/extractorDisplay.js +++ b/js/extractorDisplay.js @@ -1,14 +1,6 @@ import {app} from "../../scripts/app.js"; import {ComfyWidgets} from "../../scripts/widgets.js"; - -// Create a read-only string widget -function createWidget(app, node, widgetName, type) { - const widget = ComfyWidgets[type](node, widgetName, ["STRING", {multiline: true}], app).widget; - widget.inputEl.readOnly = true; - widget.inputEl.style.textAlign = "center"; - widget.inputEl.style.fontSize = "0.75rem"; - return widget; -} +import {createTextWidget} from "./utils.js" app.registerExtension({ name: "sd_prompt_reader.extractorDisplay", @@ -20,7 +12,8 @@ app.registerExtension({ const result = onNodeCreated?.apply(this, arguments); // Create widgets - const value_display = createWidget(app, this, "value_display", "STRING"); + const styles = {textAlign: "center", fontSize: "0.75rem"} + const value_display = createTextWidget(app, this, "value_display", styles); }; // Update widgets diff --git a/js/loaderDisplay.js b/js/loaderDisplay.js index fe77f22..71f58b1 100644 --- a/js/loaderDisplay.js +++ b/js/loaderDisplay.js @@ -1,13 +1,6 @@ import {app} from "../../scripts/app.js"; import {ComfyWidgets} from "../../scripts/widgets.js"; - -// Create a read-only string widget with opacity set -function createWidget(app, node, widgetName) { - const widget = ComfyWidgets["STRING"](node, widgetName, ["STRING", {multiline: true}], app).widget; - widget.inputEl.readOnly = true; - widget.inputEl.style.opacity = 0.7; - return widget; -} +import {createTextWidget} from "./utils.js" // Displays file list on the node app.registerExtension({ @@ -20,7 +13,8 @@ app.registerExtension({ const result = onNodeCreated?.apply(this, arguments); // Create prompt and setting widgets - const fileList = createWidget(app, this, "fileList"); + const styles = {opacity: 0.7} + const fileList =createTextWidget(app, this, "fileList", styles); return result; }; diff --git a/js/parameterDisplay.js b/js/parameterDisplay.js index fd715da..4563e29 100644 --- a/js/parameterDisplay.js +++ b/js/parameterDisplay.js @@ -1,14 +1,6 @@ import {app} from "../../scripts/app.js"; import {ComfyWidgets} from "../../scripts/widgets.js"; - -// Create a read-only string widget -function createWidget(app, node, widgetName, type) { - const widget = ComfyWidgets[type](node, widgetName, ["STRING", {multiline: true}], app).widget; - widget.inputEl.readOnly = true; - widget.inputEl.style.textAlign = "center"; - widget.inputEl.style.fontSize = "0.75rem"; - return widget; -} +import {createTextWidget} from "./utils.js" app.registerExtension({ name: "sd_prompt_reader.parameterDisplay", @@ -20,8 +12,9 @@ app.registerExtension({ const result = onNodeCreated?.apply(this, arguments); // Create widgets - const steps_display = createWidget(app, this, "steps_display", "STRING"); - const aspect_ratio_display = createWidget(app, this, "aspect_ratio_display", "STRING"); + const styles = {textAlign: "center", fontSize: "0.75rem"} + const steps_display = createTextWidget(app, this, "steps_display", styles); + const aspect_ratio_display = createTextWidget(app, this, "aspect_ratio_display", styles); // Resize the node const nodeWidth = this.size[0]; diff --git a/js/promptDisplay.js b/js/promptDisplay.js index 15c670f..26aa561 100644 --- a/js/promptDisplay.js +++ b/js/promptDisplay.js @@ -1,13 +1,6 @@ import {app} from "../../scripts/app.js"; import {ComfyWidgets} from "../../scripts/widgets.js"; - -// Create a read-only string widget with opacity set -function createWidget(app, node, widgetName) { - const widget = ComfyWidgets["STRING"](node, widgetName, ["STRING", {multiline: true}], app).widget; - widget.inputEl.readOnly = true; - widget.inputEl.style.opacity = 0.7; - return widget; -} +import {createTextWidget} from "./utils.js" // Displays prompt and setting on the node app.registerExtension({ @@ -20,9 +13,10 @@ app.registerExtension({ const result = onNodeCreated?.apply(this, arguments); // Create prompt and setting widgets - const positive = createWidget(app, this, "positive"); - const negative = createWidget(app, this, "negative"); - const setting = createWidget(app, this, "setting"); + const styles = {opacity: 0.7} + const positive = createTextWidget(app, this, "positive", styles); + const negative = createTextWidget(app, this, "negative", styles); + const setting = createTextWidget(app, this, "setting", styles); // Resize the node const nodeWidth = this.size[0]; const nodeHeight = this.size[1]; diff --git a/js/utils.js b/js/utils.js new file mode 100644 index 0000000..e509b4b --- /dev/null +++ b/js/utils.js @@ -0,0 +1,10 @@ +import {app} from "../../scripts/app.js"; +import {ComfyWidgets} from "../../scripts/widgets.js"; + +// Create a read-only string widget +export function createTextWidget(app, node, widgetName, styles = {}) { + const widget = ComfyWidgets["STRING"](node, widgetName, ["STRING", {multiline: true}], app).widget; + widget.inputEl.readOnly = true; + Object.assign(widget.inputEl.style, styles); + return widget; +}