/** * @template {Object} T * @template {keyof T} K * @param {T} target * @param {K} callbackName * @param {T[K]} callback */ export function setCallback(target, callbackName, callback) { const originalCallback = target[callbackName]; target[callbackName] = function (...args) { const r = originalCallback?.apply(this, args); callback?.apply(this, args); return r; }; } /** * Updates a prototype with new properties, preserving existing ones. Intended for use with * beforeRegisterNodeDef(). See dtModelNodes.js for an example * * Accepts functions and property descriptors. Functions already on the prototype will be wrapped * * @param {{prototype: any}} base an object with a prototype to be updated (not the prototype itself) * @param {Record [v, k])); /** * Converts a DrawThings config property name to a ComfyUI property name. * * This function maps specific DrawThings names to corresponding widget names * using a predefined map. If a name is not found in the map, it converts * camelCase names to snake_case by inserting underscores before uppercase * letters and converting all characters to lowercase. * * @param {string} dtName - The DrawThings name to convert. * @returns {string} The corresponding widget name. */ export function getWidgetName(dtName) { if (dtName in propertyMap) return propertyMap[dtName]; return dtName.replace(/([A-Z])/g, "_$1").toLowerCase(); } export function getDTPropertyName(widgetName) { if (widgetName in reversePropertyMap) return reversePropertyMap[widgetName]; return widgetName.replace(/_([a-z])/g, (g) => g[1].toUpperCase()); } export function findWidgetByName(node, name) { return node.widgets.find((w) => w.name === name) }