├── .gitignore ├── config.yaml ├── .gitattributes ├── directory_paths.py ├── js ├── queue.js ├── dialog.js ├── nodeMenu.js └── nestedNode.js ├── uninstall.py ├── nested_node.py ├── README.md ├── __init__.py └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | /nested_nodes 2 | *.pyc 3 | *.ipynb -------------------------------------------------------------------------------- /config.yaml: -------------------------------------------------------------------------------- 1 | nested_nodes_path: ./nested_nodes -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /directory_paths.py: -------------------------------------------------------------------------------- 1 | import os 2 | import folder_paths 3 | 4 | comfy_path = os.path.dirname(folder_paths.__file__) 5 | ext_path = os.path.dirname(os.path.realpath(__file__)) 6 | repo_name = os.path.basename(ext_path) 7 | default_nested_nodes_path = os.path.join(ext_path, "nested_nodes") 8 | js_extensions_path = os.path.join(comfy_path, "web", "extensions") 9 | config_path = os.path.join(ext_path, "config.yaml") 10 | js_extensions_repo_path = os.path.join(js_extensions_path, repo_name) -------------------------------------------------------------------------------- /js/queue.js: -------------------------------------------------------------------------------- 1 | export class Queue { 2 | // Basic queue implementation for now 3 | 4 | constructor(init_items=[]) { 5 | this._queue = init_items; 6 | } 7 | 8 | enqueue(item) { 9 | this._queue.push(item); 10 | } 11 | 12 | dequeue() { 13 | return this._queue.shift(); 14 | } 15 | 16 | peek() { 17 | return this._queue[0]; 18 | } 19 | 20 | get length() { 21 | return this._queue.length; 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /uninstall.py: -------------------------------------------------------------------------------- 1 | import os 2 | from directory_paths import js_extensions_repo_path, repo_name 3 | 4 | print(f"Uninstalling extra files installed by {repo_name}...") 5 | 6 | # Remove files from the extensions folder 7 | for file_name in os.listdir(js_extensions_repo_path): 8 | if file_name.endswith(".js"): 9 | file_path = os.path.join(js_extensions_repo_path, file_name) 10 | os.remove(file_path) 11 | 12 | # Remove the extensions folder 13 | os.rmdir(js_extensions_repo_path) 14 | 15 | print(f"You can now delete the {repo_name} folder in ComfyUI/custom_nodes/") 16 | -------------------------------------------------------------------------------- /nested_node.py: -------------------------------------------------------------------------------- 1 | # Not used, maybe in the future 2 | 3 | import nodes 4 | 5 | def createNestedNodeClass(node_def): 6 | # Create a new class with the node name 7 | node_name = node_def["name"] 8 | 9 | # Inputs 10 | @classmethod 11 | def INPUT_TYPES(s): 12 | return node_def["inputs"] 13 | 14 | # Entry point 15 | nested_workflow = node_def["description"]["nestedNodes"] 16 | def execute_nested_node(self, **kwargs): 17 | for node in self.nested_workflow: 18 | nodes.NODE_CLASS_MAPPINGS[node["type"]].execute(node, **kwargs) 19 | 20 | node_class = type(node_name, (object,), { 21 | "INPUT_TYPES": INPUT_TYPES, 22 | "RETURN_TYPES": node_def["output"], 23 | "CATEGORY": "Nested Nodes", 24 | "FUNCTION": "execute_nested_node", 25 | "execute_nested_node": execute_nested_node, 26 | # instance variables 27 | "nested_workflow": nested_workflow, 28 | }) 29 | 30 | return node_class 31 | -------------------------------------------------------------------------------- /js/dialog.js: -------------------------------------------------------------------------------- 1 | import { $el } from "../../scripts/ui.js"; 2 | 3 | export class ComfirmDialog { 4 | constructor() { 5 | this.element = $el("div.comfy-modal", { parent: document.body }, [ 6 | $el("div.comfy-modal-content", [$el("p", { $: (p) => (this.textElement = p) }), this.createButtons()]), 7 | ]); 8 | this.element.style.color = "var(--input-text)"; 9 | } 10 | 11 | createButtons() { 12 | this.yesButton = $el("button", { 13 | type: "button", 14 | textContent: "Yes", 15 | onclick: () => this.close(), 16 | }); 17 | this.noButton = $el("button", { 18 | type: "button", 19 | textContent: "No", 20 | onclick: () => this.close(), 21 | }); 22 | return $el("div", [this.yesButton, this.noButton]); 23 | } 24 | 25 | close() { 26 | this.element.style.display = "none"; 27 | } 28 | 29 | show(html, onYes, onNo) { 30 | if (typeof html === "string") { 31 | this.textElement.innerHTML = html; 32 | } else { 33 | this.textElement.replaceChildren(html); 34 | } 35 | this.element.style.display = "flex"; 36 | 37 | this.element.querySelector("button:nth-child(1)").onclick = () => { 38 | this.close(); 39 | onYes(); 40 | } 41 | this.element.querySelector("button:nth-child(2)").onclick = () => { 42 | this.close(); 43 | onNo(); 44 | } 45 | this.yesButton.focus(); 46 | } 47 | } 48 | 49 | export function showWidgetDialog(pos, prompt, onEnter, onCancel) { 50 | if (!onEnter) { 51 | onEnter = () => { }; 52 | } 53 | if (!onCancel) { 54 | onCancel = () => { }; 55 | } 56 | const htmlElement = `${prompt}` 57 | let dialog = app.canvas.createDialog( 58 | htmlElement, 59 | { position: pos } 60 | ); 61 | let input = dialog.querySelector("input"); 62 | input.focus(); 63 | const cancel = () => { 64 | onCancel(); 65 | dialog.close(); 66 | }; 67 | const enter = () => { 68 | onEnter(input); 69 | dialog.close(); 70 | }; 71 | input.addEventListener("keydown", function (e) { 72 | if (e.keyCode == 27) { // ESC 73 | cancel(); 74 | } else if (e.keyCode == 13) { // ENTER 75 | enter(); 76 | } else if (e.keyCode != 13) { 77 | dialog.modified(); 78 | return; 79 | } 80 | e.preventDefault(); 81 | e.stopPropagation(); 82 | }); 83 | let button = dialog.querySelector("button"); 84 | button.addEventListener("click", enter); 85 | } 86 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Archived (1/11/2024) 2 | An identical feature now exists in ComfyUI. Additionally, this extension is largely broken with the recent versions of the codebase, so please use the built-in feature for group nodes. 3 | 4 | Original Description Below 5 | --- 6 | # ComfyUI_NestedNodeBuilder 7 | Adds a feature for the default interface in [ComfyUI](https://github.com/comfyanonymous/ComfyUI) that allows for nesting of other nodes for better organization and simplification of repetitive patterns in workflows. 8 | 9 | ## Disclaimer 10 | This is a prototype and will likely have many problems. This will probably be obsolete once [subgraphs](https://github.com/comfyanonymous/ComfyUI/pull/724) are implemented within ComfyUI. To be safe, save your workflow before nesting any nodes. How nested nodes are saved are subject to change and saved nodes may become unusable in the future. 11 | 12 | ## Installation 13 | Enter the following command from the commandline starting in ComfyUI/custom_nodes/ 14 | ``` 15 | git clone https://github.com/ssitu/ComfyUI_NestedNodeBuilder 16 | ``` 17 | 18 | ## Usage 19 | 20 | ### Demo: 21 | ![NestedNodeBuilderDemo](https://github.com/ssitu/ComfyUI_NestedNodeBuilder/assets/57548627/f88fc1dc-ec64-4a48-b989-2857de088b67) 22 | 23 | ### Instructions: 24 |
25 | 1. Selecting the nodes to nest 26 | Select multiple nodes by using Ctrl/Shift + left/right click on the desired nodes to nest. 27 | You can also use Ctrl + left click + drag to highlight nodes. 28 |
29 |
30 | 2. Nesting the selected nodes 31 | After making a selection, right click on any of the selected nodes and select Nest Selected Nodes and choose a name that won't conflict with any other existing node. The selected nodes will be replaced with a new node that contains the selected nodes. You can also unnest the new node by right clicking on the node and clicking Unnest. The selected nodes may also be converted to an already existing nested node using the Convert selected to Nested Node: <name> option that appears if the selected nodes have a similar structure. 32 |
33 |
34 | 3. Creating a nested node from the node menu 35 | Nested nodes are saved and can be created again from the node menu that appears when you right click on the canvas under the Nested Nodes category. 36 |
37 |
38 | 4. Where are nested nodes saved? 39 | You can find them under ComfyUI/custom_nodes/ComfyUI_NestedNodeBuilder/nested_nodes/. This directory can be changed by editing the nested_nodes_path entry in the config.yaml. The nested nodes are stored as .json files. The names of the nested nodes may be changed by editing their .json files. The changes made to the directory are registered after refreshing the web UI. 40 |
41 | 42 |
43 |

How it works

44 | The nodes that are nested are stored in the properties of the nested node. Before the prompt is calculated, the nested node is replaced with the nodes that it stored. After the prompt is calculated, the nodes are nested again. Depending on performance, this may cause a quick flash of what the workflow looks like after the nodes are unnested when queueing a prompt. This seemed to be the approach that was the least intrusive on the ComfyUI codebase. 45 |
46 | 47 | ## Known Problems 48 | - Nested nodes cannot be nested themselves. 49 | - When converting a seed widget to input and connecting it to a primitive node, the prompt will ignore the control_after_generate widget of the primitive node and yield to the underlying control_after_generate widget of the respective node. Can be solved by changing the values to "fixed" before nesting. 50 | - Can't really nest output nodes such as preview image and save image nodes. It works, but it won't display the image. 51 | 52 | Feel free to open an issue if you find any other problems. 53 | 54 | ## Credits 55 | Inspired by [this repo by ltdrdata](https://github.com/ltdrdata/ComfyUI-Workflow-Component), check it out if you want something more robust and flexible. 56 | -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- 1 | import yaml 2 | import shutil 3 | import json 4 | import os 5 | import sys 6 | import server 7 | from server import web 8 | 9 | try: 10 | dir_path = os.path.dirname(os.path.abspath(__file__)) 11 | sys.path.append(dir_path) 12 | from directory_paths import ext_path, default_nested_nodes_path, config_path, js_extensions_repo_path 13 | except ImportError as e: 14 | print(f"[NestedNodeBuilder] Error importing directory_paths.py: {e}") 15 | 16 | 17 | # Config keys 18 | config_nested_nodes_path = "nested_nodes_path" 19 | 20 | # Load config 21 | config = {} 22 | with open(config_path, 'r') as config_file: 23 | try: 24 | config = yaml.safe_load(config_file) 25 | except yaml.YAMLError as yaml_e: 26 | print("[NestedNodeBuilder] Error loading NestedNodeBuilder config:", yaml_e) 27 | 28 | 29 | def load_nested_node_defs(): 30 | defs_list = [] 31 | if config_nested_nodes_path not in config: 32 | print( 33 | f'[NestedNodeBuilder] missing entry "{config_nested_nodes_path}" in config.yaml, \ 34 | using default path "{default_nested_nodes_path}".' 35 | ) 36 | nested_nodes_path = config.get(config_nested_nodes_path, default_nested_nodes_path) 37 | if not os.path.isabs(nested_nodes_path): 38 | nested_nodes_path = os.path.join(ext_path, nested_nodes_path) 39 | if not os.path.exists(nested_nodes_path): 40 | os.makedirs(nested_nodes_path) 41 | 42 | # Load each json file in the nested_nodes_path and add it to the defs list 43 | for file_name in os.listdir(nested_nodes_path): 44 | if file_name.endswith(".json"): 45 | file_path = os.path.join(nested_nodes_path, file_name) 46 | with open(file_path, 'r') as json_file: 47 | try: 48 | node_def = json.load(json_file) 49 | except json.JSONDecodeError as json_e: 50 | print(f"[NestedNodeBuilder] Error loading {file_name}:", json_e) 51 | continue 52 | if "name" not in node_def: 53 | print("[NestedNodeBuilder] missing property \"name\" in node definition:", file_name) 54 | continue 55 | defs_list.append(node_def) 56 | defs = {} 57 | for node_def in defs_list: 58 | key = node_def["name"] 59 | defs[key] = node_def 60 | 61 | # Add the nested node defs 62 | # import nodes 63 | # from .nested_nodes import createNestedNodeClass 64 | # for node_def in defs_list: 65 | # nodes.NODE_CLASS_MAPPINGS[node_def["name"]] = createNestedNodeClass(node_def) 66 | # nodes.NODE_DISPLAY_NAME_MAPPINGS[node_def["name"]] = node_def["display_name"] 67 | 68 | return defs 69 | 70 | 71 | def save_nested_def(node_def): 72 | if config_nested_nodes_path not in config: 73 | print( 74 | f'[NestedNodeBuilder] missing entry "{config_nested_nodes_path}" in config.yaml, \ 75 | using default path "{default_nested_nodes_path}".' 76 | ) 77 | nested_nodes_path = config.get(config_nested_nodes_path, default_nested_nodes_path) 78 | if not os.path.isabs(nested_nodes_path): 79 | nested_nodes_path = os.path.join(ext_path, nested_nodes_path) 80 | if not os.path.exists(nested_nodes_path): 81 | os.makedirs(nested_nodes_path) 82 | file_name = node_def["name"] + ".json" 83 | file_path = os.path.join(nested_nodes_path, file_name) 84 | # Raise error if file already exists 85 | # if os.path.exists(file_path): 86 | # raise FileExistsError(f"[NestedNodeBuilder] {file_name} already exists.") 87 | with open(file_path, 'w') as json_file: 88 | json.dump(node_def, json_file, indent=4) 89 | 90 | 91 | def place_js(): 92 | src = os.path.join(ext_path, "js") 93 | dst = js_extensions_repo_path 94 | shutil.copytree(src, dst, dirs_exist_ok=True) 95 | 96 | 97 | @server.PromptServer.instance.routes.get('/nested_node_builder/nested_defs') 98 | async def server_add_def_route(request): 99 | nested_node_defs = load_nested_node_defs() 100 | return web.json_response(nested_node_defs) 101 | 102 | 103 | @server.PromptServer.instance.routes.post('/nested_node_builder/nested_defs') 104 | async def server_add_def_route(request): 105 | nested_def = await request.json() 106 | save_nested_def(nested_def) 107 | return web.Response(text="ok") 108 | 109 | # 110 | # Setup 111 | # 112 | WEB_DIRECTORY = "./js" 113 | skip_js_copy = hasattr(server.PromptServer.instance, "supports") and "custom_nodes_from_web" in server.PromptServer.instance.supports 114 | if not skip_js_copy: 115 | print("[NestedNodeBuilder] Installed ComfyUI version doesn't support in-place web extension loading. Copying files to web directory...") 116 | place_js() 117 | # This is required so that the extension is displayed as imported successfully 118 | NODE_CLASS_MAPPINGS = {} 119 | __all__ = ["NODE_CLASS_MAPPINGS", "WEB_DIRECTORY"] -------------------------------------------------------------------------------- /js/nodeMenu.js: -------------------------------------------------------------------------------- 1 | import { app } from "../../scripts/app.js"; 2 | import { api } from "../../scripts/api.js"; 3 | import { NestedNode, serializeWorkflow } from "./nestedNode.js"; 4 | import { ComfirmDialog, showWidgetDialog } from "./dialog.js"; 5 | import { Queue } from "./queue.js"; 6 | 7 | export let nodeDefs = {}; 8 | 9 | export const ext = { 10 | name: "SS.NestedNodeBuilder", 11 | nestedDef: {}, 12 | nestedNodeDefs: {}, 13 | comfirmationDialog: new ComfirmDialog(), 14 | nestedPromptQueue: new Queue([null]), 15 | 16 | async setup(app) { 17 | // Extend app.queuePrompt behavior 18 | const originalAppQueuePrompt = app.queuePrompt; 19 | app.queuePrompt = async function (number, batchsize) { 20 | // Save the current workflow 21 | const nestedWorkflow = JSON.parse(JSON.stringify(app.graph.serialize())); 22 | 23 | // Unnest all nested nodes 24 | const nestedNodesUnnested = {}; 25 | const nestedNodes = {}; 26 | const connectedInputNodes = {}; 27 | const nodes = app.graph._nodes; 28 | for (const i in nodes) { 29 | const node = nodes[i]; 30 | if (node.properties.nestedData) { 31 | node.beforeQueuePrompt(); 32 | nestedNodes[node.id] = node; 33 | connectedInputNodes[node.id] = node.getConnectedInputNodes(); 34 | } 35 | } 36 | // Unnest the nodes 37 | for (const nestedNodeId in nestedNodes) { 38 | const node = nestedNodes[nestedNodeId]; 39 | const unnestedNodes = node.unnest(); 40 | nestedNodesUnnested[node.id] = unnestedNodes; 41 | } 42 | 43 | // Replace the unnested workflow with the nested workflow 44 | const originalApiQueuePrompt = api.queuePrompt; 45 | api.queuePrompt = async function (number, promptData) { 46 | const unnestedWorkflow = promptData.workflow; 47 | promptData.workflow = nestedWorkflow; 48 | const result = await originalApiQueuePrompt.apply(this, arguments); 49 | promptData.workflow = unnestedWorkflow; 50 | return result; 51 | } 52 | 53 | // Call the original function 54 | await originalAppQueuePrompt.call(this, number, batchsize); 55 | 56 | // Restore the original api.queuePrompt 57 | api.queuePrompt = originalApiQueuePrompt; 58 | 59 | // Renest all nested nodes 60 | for (const nestedId in nestedNodesUnnested) { 61 | const unnestedNodes = nestedNodesUnnested[nestedId]; 62 | const node = nestedNodes[nestedId]; 63 | 64 | // Readd the node to the graph 65 | app.graph.add(node); 66 | 67 | // Renest the node using the unnested nodes 68 | node.nestWorkflow(unnestedNodes); 69 | 70 | // Reconnect missing links 71 | const inputNodes = connectedInputNodes[nestedId]; 72 | const currentConnectedInputNodes = node.getConnectedInputNodes(); 73 | let currentIdx = 0; 74 | for (const inputIdx in inputNodes) { 75 | const inputData = inputNodes[inputIdx]; 76 | const currentInputData = currentConnectedInputNodes[currentIdx]; 77 | if (inputData.node.id === currentInputData?.node.id) { 78 | // Increment the current index 79 | currentIdx++; 80 | continue; 81 | } // Otherwise, the link is missing 82 | // Reconnect the link 83 | const srcSlot = inputData.srcSlot; 84 | const dstSlot = inputData.dstSlot; 85 | inputData.node.connect(srcSlot, node, dstSlot); 86 | } 87 | 88 | // Readd widget elements to the canvas 89 | for (const widget of node.widgets ?? []) { 90 | if (widget.inputEl) { 91 | document.body.appendChild(widget.inputEl); 92 | } 93 | } 94 | 95 | // Call resize listeners to fix overhanging widgets 96 | node.setSize(node.size); 97 | } 98 | 99 | // 100 | // Add the pre-unnested workflow to the queue 101 | // 102 | // Create a mapping of unnested node ids to the encapsulating nested node id 103 | const unnestedToNestedIds = {}; 104 | for (const nestedId in nestedNodesUnnested) { 105 | const unnestedNodes = nestedNodesUnnested[nestedId]; 106 | for (const unnestedNode of unnestedNodes) { 107 | unnestedToNestedIds[unnestedNode.id] = nestedId; 108 | } 109 | } 110 | console.log("[NestedNodeBuilder] unnestedToNestedIds:", unnestedToNestedIds) 111 | // Add the mapping to the queue 112 | ext.nestedPromptQueue.enqueue(unnestedToNestedIds); 113 | } 114 | 115 | // Redirect the executing event to the nested node if the executing node is nested 116 | api.addEventListener("executing", ({ detail }) => { 117 | const unnestedToNestedIds = ext.nestedPromptQueue.peek(); 118 | if (unnestedToNestedIds?.[detail]) { 119 | app.runningNodeId = unnestedToNestedIds[detail]; 120 | } 121 | }); 122 | 123 | // Remove the last prompt from the queue 124 | api.addEventListener("execution_start", ({ detail }) => { 125 | this.nestedPromptQueue.dequeue(); 126 | }); 127 | 128 | }, 129 | 130 | /** 131 | * Called before the app registers nodes from definitions. 132 | * Used to add nested node definitions. 133 | * @param defs The node definitions. 134 | * @param app The app. 135 | * @returns {Promise} 136 | */ 137 | async addCustomNodeDefs(defs, app) { 138 | // Save definitions for reference 139 | nodeDefs = defs; 140 | // Grab nested node definitions 141 | const resp = await api.fetchApi("/nested_node_builder/nested_defs") 142 | const nestedNodeDefs = await resp.json(); 143 | // Merge nested node definitions 144 | Object.assign(this.nestedNodeDefs, nestedNodeDefs); 145 | // Add nested node definitions if they exist 146 | Object.assign(defs, this.nestedNodeDefs); 147 | 148 | 149 | }, 150 | 151 | /** 152 | * Called after inputs, outputs, widgets, menus are added to the node given the node definition. 153 | * Used to add methods to nested nodes. 154 | * @param nodeType The ComfyNode object to be registered with LiteGraph. 155 | * @param nodeData The node definition. 156 | * @param app The app. 157 | * @returns {Promise} 158 | */ 159 | async beforeRegisterNodeDef(nodeType, nodeData, app) { 160 | // Return if the node is not a nested node 161 | if (!(nodeData.name in this.nestedNodeDefs)) { 162 | return; 163 | } 164 | 165 | // Add Nested Node methods to the node ComfyNode 166 | Object.defineProperties(nodeType.prototype, Object.getOwnPropertyDescriptors(NestedNode.prototype)); 167 | 168 | // Add the nested node data to the node properties 169 | const onNodeCreated = nodeType.prototype.onNodeCreated; 170 | nodeType.prototype.onNodeCreated = function () { 171 | const result = onNodeCreated?.apply(this, arguments); 172 | this.addProperty("nestedData", nodeData.description, "object"); 173 | return result; 174 | } 175 | }, 176 | 177 | /** 178 | * Called when loading a graph from a JSON file or pasted into the app. 179 | * @param node The node that was loaded. 180 | * @param app The app. 181 | */ 182 | loadedGraphNode(node, app) { 183 | // Return if the node is not a nested node 184 | if (!node.properties.nestedData) return; 185 | 186 | // Return if a nested node definition with the same name already exists 187 | if (this.nestedNodeDefs[node.type]) return; 188 | 189 | // Use the serialized workflow to create a nested node definition 190 | const nestedDef = this.createNestedDef(node.properties.nestedData.nestedNodes, node.type); 191 | 192 | // If the definition already exists, then the node will be loaded with the existing definition 193 | if (Object.values(this.nestedNodeDefs).some(def => def.name === nestedDef.name)) return; 194 | 195 | // 196 | // When the nested node is loaded but missing def, it can still work. 197 | // Might remove this in the future. 198 | // 199 | console.log("[NestedNodeBuilder] def for nested node not found, adding temporary def:", nestedDef); 200 | 201 | // Add the def 202 | this.nestedNodeDefs[nestedDef.name] = nestedDef; 203 | // Reload the graph 204 | LiteGraph.registered_node_types = {}; 205 | app.registerNodes().then(() => { 206 | // Reload the graph data 207 | app.loadGraphData(app.graph.serialize()); 208 | }, (error) => { 209 | console.log("Error registering nodes:", error); 210 | }); 211 | }, 212 | 213 | /** 214 | * Called when a node is created. Used to add menu options to nodes. 215 | * @param node The node that was created. 216 | * @param app The app. 217 | */ 218 | nodeCreated(node, app) { 219 | // Save the original options 220 | const getBaseMenuOptions = node.getExtraMenuOptions; 221 | // Add new options 222 | node.getExtraMenuOptions = function (_, options) { 223 | // Call the original function for the default menu options 224 | getBaseMenuOptions.call(this, _, options); 225 | 226 | // Add new menu options for this extension 227 | options.push({ 228 | content: "Nest Selected Nodes", callback: () => { 229 | ext.onMenuNestSelectedNodes(); 230 | } 231 | }); 232 | 233 | // Add a menu option to nest the selected nodes if there is a nested node definition with the same structure 234 | const selectedNodes = app.canvas.selected_nodes; 235 | const serializedWorkflow = serializeWorkflow(selectedNodes); 236 | for (const defName in ext.nestedNodeDefs) { 237 | const def = ext.nestedNodeDefs[defName]; 238 | if (isStructurallyEqual(def.description.nestedNodes, serializedWorkflow)) { 239 | options.push({ 240 | content: `Convert selected to Nested Node: ${defName}`, callback: () => { 241 | ext.nestSelectedNodes(selectedNodes, defName); 242 | } 243 | }); 244 | } 245 | } 246 | 247 | // Nested Node specific options 248 | if (this.properties.nestedData) { 249 | // Add a menu option to unnest the node 250 | options.push({ 251 | content: "Unnest", callback: () => { 252 | this.unnest(); 253 | } 254 | }); 255 | } 256 | 257 | // End with a separator 258 | options.push(null); 259 | }; 260 | }, 261 | 262 | createNestedDef(serializedWorkflow, uniqueName) { 263 | // Replace spaces with underscores for the type 264 | const uniqueType = uniqueName.replace(/\s/g, "_"); 265 | let nestedDef = { 266 | name: uniqueType, 267 | display_name: uniqueName, 268 | category: "Nested Nodes", 269 | description: { 270 | nestedNodes: serializedWorkflow 271 | }, 272 | input: {}, 273 | output: [], 274 | output_is_list: [], 275 | output_name: [], 276 | }; 277 | // Create a mapping of links 278 | const linksMapping = mapLinksToNodes(serializedWorkflow); 279 | // Inherit inputs and outputs for each node 280 | for (const id in serializedWorkflow) { 281 | const node = serializedWorkflow[id]; 282 | const nodeDef = nodeDefs[node.type]; 283 | inheritInputs(node, nodeDef, nestedDef, linksMapping); 284 | inheritOutputs(node, nodeDef, nestedDef, linksMapping); 285 | } 286 | return nestedDef; 287 | }, 288 | 289 | createNestSelectedDialog(selectedNodes) { 290 | const pos = [window.innerWidth / 3, 2 * window.innerHeight / 3]; 291 | const enterName = (input) => { 292 | // Check if the name already exists in the defs 293 | const name = input.value; 294 | if (name in this.nestedNodeDefs) { 295 | this.comfirmationDialog.show( 296 | `The name "${name}" is already used for a nested node. Do you want to overwrite it?`, 297 | () => { 298 | // Overwrite the nested node 299 | this.nestSelectedNodes(selectedNodes, name); 300 | }, 301 | () => { 302 | // Do not overwrite the nested node 303 | return; 304 | } 305 | ); 306 | } else { 307 | // Successfully entered a valid name 308 | this.nestSelectedNodes(selectedNodes, name); 309 | } 310 | } 311 | showWidgetDialog(pos, "Name for nested node:", enterName); 312 | }, 313 | 314 | onMenuNestSelectedNodes() { 315 | // Use the selected nodes for the nested node 316 | const selectedNodes = app.canvas.selected_nodes; 317 | 318 | // Prompt user to enter name for the node type 319 | this.createNestSelectedDialog(selectedNodes); 320 | }, 321 | 322 | nestSelectedNodes(selectedNodes, uniqueName) { 323 | // Add a custom definition for the nested node 324 | const nestedDef = this.createNestedDef(serializeWorkflow(selectedNodes), uniqueName); 325 | 326 | // Add the def, this will be added to defs in addCustomNodeDefs 327 | this.nestedNodeDefs[nestedDef.name] = nestedDef; 328 | 329 | // Download the nested node definition 330 | saveDef(nestedDef).then( 331 | (successful) => { 332 | // Register nodes again to add the nested node definition 333 | LiteGraph.registered_node_types = {}; 334 | app.registerNodes().then(() => { 335 | // Create the nested node 336 | const nestedNode = LiteGraph.createNode(nestedDef.name); 337 | app.graph.add(nestedNode); 338 | nestedNode.nestWorkflow(selectedNodes); 339 | 340 | // Add new node to selection 341 | app.canvas.selectNode(nestedNode, true); 342 | }, (error) => { 343 | console.log("Error registering nodes:", error); 344 | }); 345 | }, 346 | (error) => { 347 | app.ui.dialog.show(`Was unable to save the nested node. Check the browser console for more details.`); 348 | console.log("Error saving nested node:", error); 349 | } 350 | ); 351 | }, 352 | 353 | mapLinks(selectedNodes) { 354 | const serializedWorkflow = serializeWorkflow(selectedNodes); 355 | return mapLinksToNodes(serializedWorkflow); 356 | } 357 | 358 | }; 359 | 360 | app.registerExtension(ext); 361 | 362 | async function saveDef(nestedDef) { 363 | // Save by sending to server 364 | const request = { 365 | method: "POST", 366 | headers: { 367 | "Content-Type": "application/json", 368 | }, 369 | body: JSON.stringify(nestedDef) 370 | }; 371 | console.log("[NestedNodeBuilder] Saving nested node def:", nestedDef); 372 | const response = await api.fetchApi("/nested_node_builder/nested_defs", request); 373 | return response.status === 200; 374 | } 375 | 376 | export function mapLinksToNodes(serializedWorkflow) { 377 | // Mapping 378 | const links = {}; 379 | // Iterate over nodes and add links to mapping 380 | for (const node of serializedWorkflow) { 381 | // Add the destination node id for each link 382 | for (const inputIdx in node.inputs ?? []) { 383 | const input = node.inputs[inputIdx]; 384 | // input.link is either null or a link id 385 | if (input.link === null) { 386 | continue; 387 | } 388 | // Add the link entry if it doesn't exist 389 | if (links[input.link] === undefined) { 390 | links[input.link] = {}; 391 | } 392 | // Set the destination node id 393 | links[input.link].dstId = node.id; 394 | // Set the destination slot 395 | links[input.link].dstSlot = Number(inputIdx); 396 | } 397 | // Add the source node id for each link 398 | for (const outputIdx in node.outputs ?? []) { 399 | const output = node.outputs[outputIdx]; 400 | // For each link, add the source node id 401 | for (const link of output.links ?? []) { 402 | // Add the link entry if it doesn't exist 403 | if (links[link] === undefined) { 404 | links[link] = {}; 405 | } 406 | // Set the source node id 407 | links[link].srcId = node.id; 408 | // Set the source slot 409 | links[link].srcSlot = Number(outputIdx); 410 | } 411 | } 412 | } 413 | return links; 414 | } 415 | 416 | function inheritInputs(node, nodeDef, nestedDef, linkMapping) { 417 | // For each input from nodeDef, add it to the nestedDef if the input is connected 418 | // to a node outside the serialized workflow 419 | let linkInputIdx = 0; 420 | for (const inputType in (nodeDef?.input) ?? []) { // inputType is required, optional, hidden, etc. 421 | // Optional inputs will be added to required inputs to keep inputs order the same as the node order 422 | const nestedInputType = inputType === "optional" ? "required" : inputType; 423 | if (!(nestedInputType in nestedDef.input)) { 424 | nestedDef.input[nestedInputType] = {}; 425 | } 426 | for (const inputName in nodeDef.input[inputType]) { 427 | // Change the input name if it already exists 428 | let uniqueInputName = inputName + "_1"; 429 | let i = 2; 430 | while (uniqueInputName in nestedDef.input[nestedInputType]) { 431 | uniqueInputName = inputName + "_" + i; 432 | i++; 433 | } 434 | const isRemainingWidgets = node.inputs === undefined || linkInputIdx >= node.inputs.length; 435 | if (isRemainingWidgets || inputName !== node.inputs[linkInputIdx].name) { 436 | // This input is a widget, add by default 437 | nestedDef.input[nestedInputType][uniqueInputName] = nodeDef.input[inputType][inputName]; 438 | continue; 439 | } 440 | 441 | // Add the input if it is not connected to a node within the serialized workflow 442 | if (!isInputInternal(node, linkInputIdx, linkMapping)) { 443 | nestedDef.input[nestedInputType][uniqueInputName] = nodeDef.input[inputType][inputName]; 444 | } 445 | linkInputIdx++; 446 | } 447 | } 448 | } 449 | 450 | export function isInputInternal(node, inputIdx, linkMapping) { 451 | // Keep input if no link 452 | const link = node.inputs[inputIdx].link; 453 | if (link === null) { 454 | return false; 455 | } 456 | // Keep input if link is connected to a node outside the nested workflow 457 | const entry = linkMapping[link]; 458 | if (entry.srcId === undefined) { 459 | // This input is connected to a node outside the nested workflow 460 | return false; 461 | } 462 | return true; 463 | } 464 | 465 | export function isOutputInternal(node, outputIdx, linkMapping) { 466 | // Keep output if no links 467 | const links = node.outputs[outputIdx].links; 468 | if (links === null || links.length === 0) { 469 | return false; 470 | } 471 | // Keep output if any link is connected to a node outside the nested workflow 472 | for (const link of links) { 473 | const entry = linkMapping[link]; 474 | if (entry.dstId === undefined) { 475 | // This output is connected to a node outside the nested workflow 476 | return false; 477 | } 478 | } 479 | return true; 480 | } 481 | 482 | function inheritOutputs(node, nodeDef, nestedDef, linksMapping) { 483 | // Somewhat similar to inheritInputs. 484 | // Outputs do not have a type, and they can connect to multiple nodes. 485 | // Inputs were either a link or a widget. 486 | // Only keep outputs that connect to nodes outside the nested workflow. 487 | for (const outputIdx in (nodeDef?.output) ?? []) { 488 | if (isOutputInternal(node, outputIdx, linksMapping)) { 489 | continue; 490 | } 491 | const defOutput = nodeDef.output[outputIdx]; 492 | const defOutputName = nodeDef.output_name[outputIdx]; 493 | const defOutputIsList = nodeDef.output_is_list[outputIdx]; 494 | nestedDef.output.push(defOutput); 495 | nestedDef.output_name.push(defOutputName); 496 | nestedDef.output_is_list.push(defOutputIsList); 497 | } 498 | } 499 | 500 | export function isStructurallyEqual(nestedWorkflow1, nestedWorkflow2) { 501 | // Number of nodes must be the equal 502 | if (nestedWorkflow1.length !== nestedWorkflow2.length) { 503 | return false; 504 | } 505 | // Workflow is structurally equal if the numbers of each type of node is equal 506 | // and they are linked in the same way. 507 | 508 | // Number of each type of node must be equal 509 | const nodeTypeCount1 = {}; 510 | const nodeTypeCount2 = {}; 511 | for (const i in nestedWorkflow1) { 512 | const node1 = nestedWorkflow1[i]; 513 | if (nodeTypeCount1[node1.type] === undefined) { 514 | nodeTypeCount1[node1.type] = 0; 515 | } 516 | nodeTypeCount1[node1.type]++; 517 | 518 | const node2 = nestedWorkflow2[i]; 519 | if (nodeTypeCount2[node2.type] === undefined) { 520 | nodeTypeCount2[node2.type] = 0; 521 | } 522 | nodeTypeCount2[node2.type]++; 523 | } 524 | // Verify counts 525 | for (const type in nodeTypeCount1) { 526 | if (nodeTypeCount1[type] !== nodeTypeCount2[type]) { 527 | return false; 528 | } 529 | } 530 | 531 | // Check if the links are the same 532 | const linksMapping1 = mapLinksToNodes(nestedWorkflow1); 533 | const linksMapping2 = mapLinksToNodes(nestedWorkflow2); 534 | 535 | // Remove links that are not within the nested workflow 536 | for (const link in linksMapping1) { 537 | const entry = linksMapping1[link]; 538 | if (entry.srcId === undefined || entry.dstId === undefined) { 539 | delete linksMapping1[link]; 540 | } 541 | } 542 | for (const link in linksMapping2) { 543 | const entry = linksMapping2[link]; 544 | if (entry.srcId === undefined || entry.dstId === undefined) { 545 | delete linksMapping2[link]; 546 | } 547 | } 548 | 549 | // Get a mapping of ids to types 550 | const idToType1 = {}; 551 | const idToType2 = {}; 552 | for (const i in nestedWorkflow1) { 553 | const node1 = nestedWorkflow1[i]; 554 | idToType1[node1.id] = node1.type; 555 | const node2 = nestedWorkflow2[i]; 556 | idToType2[node2.id] = node2.type; 557 | } 558 | 559 | // Replace the ids with the type 560 | for (const link in linksMapping1) { 561 | const entry = linksMapping1[link]; 562 | entry.srcId = idToType1[entry.srcId]; 563 | entry.dstId = idToType1[entry.dstId]; 564 | } 565 | for (const link in linksMapping2) { 566 | const entry = linksMapping2[link]; 567 | entry.srcId = idToType2[entry.srcId]; 568 | entry.dstId = idToType2[entry.dstId]; 569 | } 570 | 571 | // Check if the links are the same 572 | for (const link1 in linksMapping1) { 573 | // Iterate over the links in the 2nd mapping and find a match 574 | let foundMatch = false; 575 | for (const link2 in linksMapping2) { 576 | const entry1 = linksMapping1[link1]; 577 | const entry2 = linksMapping2[link2]; 578 | if (entry1.srcId === entry2.srcId && entry1.dstId === entry2.dstId) { 579 | // Found a match, remove the entry from the 2nd mapping 580 | delete linksMapping2[link2]; 581 | foundMatch = true; 582 | break; 583 | } 584 | } 585 | if (!foundMatch) { 586 | return false; 587 | } 588 | } 589 | return true; 590 | } -------------------------------------------------------------------------------- /js/nestedNode.js: -------------------------------------------------------------------------------- 1 | import { app } from "../../scripts/app.js"; 2 | import { mapLinksToNodes, isOutputInternal, isInputInternal, nodeDefs } from "./nodeMenu.js"; 3 | 4 | // Node that allows you to convert a set of nodes into a single node 5 | export const nestedNodeType = "NestedNode"; 6 | export const nestedNodeTitle = "Nested Node"; 7 | 8 | // Identifier used to prevent the user from changing input back to widget (if the widget is used as an input that is internal to the nested node). 9 | const HIDDEN_CONVERTED_TYPE = "hidden-converted-widget"; 10 | // Identifier used to distinguish converted widgets from ones inherited from nodes within the nested node (Prevent widgetInputs.js from removing the converted input on load). 11 | const INHERITED_CONVERTED_TYPE = "inherited-converted-widget"; 12 | 13 | 14 | export function serializeWorkflow(workflow) { 15 | let nodes = []; 16 | for (const id in workflow) { 17 | const node = workflow[id]; 18 | let serialized = LiteGraph.cloneObject(node.serialize()); 19 | 20 | // Add widgets to the serialization 21 | serialized.serializedWidgets = []; 22 | for (const widgetIdx in node.widgets) { 23 | const { ...widget } = node.widgets[widgetIdx]; 24 | // Remove possible circular reference (text boxes have a reference to the parent) 25 | delete widget.parent; 26 | serialized.serializedWidgets.push(LiteGraph.cloneObject(widget)); 27 | } 28 | 29 | nodes.push(serialized); 30 | } 31 | return nodes; 32 | } 33 | 34 | export function arrToIdMap(serialiedWorkflow) { 35 | const result = {}; 36 | for (const node of serialiedWorkflow) { 37 | result[node.id] = node; 38 | } 39 | return result; 40 | } 41 | 42 | export function cleanLinks(serializedWorkflow) { 43 | // Remove links that are not connections between nodes within the workflow 44 | const linksMapping = mapLinksToNodes(serializedWorkflow); 45 | const result = structuredClone(serializedWorkflow); 46 | for (const node of result) { 47 | for (const input of node.inputs ?? []) { // Some nodes don't have inputs 48 | const entry = linksMapping[input.link]; 49 | const isLinkWithinWorkflow = entry && entry.srcId && entry.dstId; 50 | if (!isLinkWithinWorkflow) { 51 | // Remove link 52 | input.link = null; 53 | } 54 | } 55 | for (const output of node.outputs ?? []) { 56 | for (const link of output.links ?? []) { 57 | const entry = linksMapping[link]; 58 | const isLinkWithinWorkflow = entry && entry.srcId && entry.dstId; 59 | if (!isLinkWithinWorkflow) { 60 | // Remove link, should be unique 61 | output.links.splice(output.links.indexOf(link), 1); 62 | } 63 | } 64 | } 65 | } 66 | return result; 67 | } 68 | 69 | function averagePos(nodes) { 70 | let x = 0; 71 | let y = 0; 72 | let count = 0; 73 | for (const i in nodes) { 74 | const node = nodes[i]; 75 | x += node.pos[0]; 76 | y += node.pos[1]; 77 | count++; 78 | } 79 | x /= count; 80 | y /= count; 81 | return [x, y]; 82 | } 83 | 84 | export function getRerouteName(rerouteNode) { 85 | const input = rerouteNode.inputs[0]; 86 | const output = rerouteNode.outputs[0]; 87 | return input.label || output.label || output.type; 88 | } 89 | 90 | export class NestedNode { 91 | 92 | get nestedNodes() { 93 | return this.properties.nestedData.nestedNodes; 94 | } 95 | 96 | nestedNodeSetup() { 97 | // Called every time a nested node is loaded 98 | console.log("[NestedNodeBuilder] Nested node setup") 99 | this.addWidgetListeners(); 100 | this.nestedNodeIdMapping = arrToIdMap(this.nestedNodes); 101 | this.linksMapping = mapLinksToNodes(this.nestedNodes); 102 | 103 | this.inheritRerouteNodeInputs(); 104 | this.inheritRerouteNodeOutputs(); 105 | this.inheritFrontendWidgets(); 106 | this.inheritConvertedWidgets(); 107 | this.inheritPrimitiveWidgets(); 108 | this.widgetMapping = this.createWidgetMapping(); 109 | 110 | this.renameInputs(); 111 | this.resizeNestedNode(); 112 | this.inheritWidgetValues(); 113 | 114 | 115 | // Prevent widgetInputs.js from changing the widget type 116 | const origOnConfigure = this.onConfigure; 117 | this.onConfigure = function () { 118 | const widgets = []; 119 | for (const input of this.inputs ?? []) { 120 | // If input is from a widget, then save it and remove it from the input 121 | if (input.isInherited || (input.isReroute && input.widget)) { 122 | widgets.push(input.widget); 123 | input.widget = undefined; 124 | } else { // Otherwise, add a null entry to keep the indices the same 125 | widgets.push(null); 126 | } 127 | } 128 | // Let widgetInputs.js do its thing 129 | const r = origOnConfigure ? origOnConfigure.apply(this, arguments) : undefined; 130 | // Restore the widgets 131 | for (let i = 0; i < (this.inputs ?? []).length; i++) { 132 | if (widgets[i]) { 133 | this.inputs[i].widget = widgets[i]; 134 | } 135 | } 136 | return r; 137 | }; 138 | } 139 | 140 | onAdded() { 141 | if (!this.isSetup) { 142 | this.nestedNodeSetup(); 143 | this.isSetup = true; 144 | } 145 | } 146 | 147 | // Nest the workflow within this node 148 | nestWorkflow(workflow) { 149 | // Called when user makes a nested node 150 | console.log("[NestedNodeBuilder] Nesting workflow") 151 | // Node setup 152 | this.properties.nestedData = { nestedNodes: serializeWorkflow(workflow) }; 153 | this.linksMapping = mapLinksToNodes(this.nestedNodes); 154 | this.placeNestedNode(workflow); 155 | this.inheritLinks(); 156 | this.inheritWidgetValues(); 157 | this.removeNestedNodes(workflow); 158 | } 159 | 160 | // Remove the nodes that are being nested 161 | removeNestedNodes(workflow) { 162 | for (const id in workflow) { 163 | const node = workflow[id]; 164 | app.graph.remove(node); 165 | } 166 | } 167 | 168 | // Set the location of the nested node 169 | placeNestedNode(workflow) { 170 | this.pos = averagePos(workflow) 171 | } 172 | 173 | // Resize the nested node 174 | resizeNestedNode() { 175 | this.size = this.computeSize(); 176 | this.size[0] *= 1.5; 177 | } 178 | 179 | renameInputs() { 180 | // Undo the unique name suffixes 181 | 182 | // Inputs 183 | for (const input of this.inputs ?? []) { 184 | input.name = input.name.replace(/_\d+$/, ''); 185 | } 186 | // Widgets 187 | for (const widget of this.widgets ?? []) { 188 | widget.name = widget.name.replace(/_\d+$/, ''); 189 | } 190 | } 191 | 192 | inheritWidgetValues() { 193 | // Inherit the widget values of the serialized workflow 194 | const serialized = this.nestedNodes; 195 | const widgetMapping = this.widgetMapping; 196 | for (const widgetIdx in widgetMapping) { 197 | const widget = this.widgets[widgetIdx]; 198 | const { nodeIdx, widgetIdx: widgetIdx2 } = widgetMapping[widgetIdx]; 199 | const node = serialized[nodeIdx]; 200 | widget.value = node.widgets_values[widgetIdx2]; 201 | } 202 | } 203 | 204 | createInputMappings() { 205 | // Map nodes inside the nesting to the starting index of their inputs in the nesting and the end index of the start of the next node's inputs 206 | // key: node id, value: { startIdx, endIdx } 207 | const serialized = this.nestedNodes; 208 | const linksMapping = this.linksMapping; 209 | const result = {}; 210 | let inputIdx = 0; 211 | for (const i in serialized) { 212 | const node = serialized[i]; 213 | const nodeInputs = node.inputs ?? []; 214 | let numInternalInputs = 0; 215 | for (let inputIdx = 0; inputIdx < nodeInputs.length; inputIdx++) { 216 | if (isInputInternal(node, inputIdx, linksMapping)) { 217 | numInternalInputs++; 218 | } 219 | } 220 | result[node.id] = { startIdx: inputIdx, endIdx: inputIdx + nodeInputs.length - numInternalInputs }; 221 | inputIdx += nodeInputs.length - numInternalInputs; 222 | } 223 | return result; 224 | } 225 | 226 | inheritRerouteNodeInputs() { 227 | // Inherit the inputs of reroute nodes, since they are not added 228 | // to the node definition so they must be added manually. 229 | 230 | let inputIdx = 0; 231 | const serialized = this.nestedNodes; 232 | const linksMapping = this.linksMapping; 233 | for (const node of serialized) { 234 | if (node.type === "Reroute" && !this.inputs?.[inputIdx]?.isReroute && !isInputInternal(node, 0, linksMapping)) { 235 | // Allow the use of titles on reroute nodes for custom input names 236 | const rerouteType = node.outputs[0].type; 237 | const inputName = getRerouteName(node); 238 | const newInput = this.insertInput(inputName, rerouteType, inputIdx); 239 | newInput.isReroute = true; 240 | newInput.widget = node?.inputs?.[0]?.widget; 241 | } 242 | for (let i = 0; i < (node.inputs ?? []).length; i++) { 243 | const isConvertedWidget = !!node.inputs[i].widget; 244 | if (!isInputInternal(node, i, linksMapping) && !isConvertedWidget) inputIdx++; 245 | } 246 | } 247 | } 248 | 249 | inheritRerouteNodeOutputs() { 250 | // Inherit the outputs of reroute nodes 251 | 252 | let outputIdx = 0; 253 | const serialized = this.nestedNodes; 254 | const linksMapping = this.linksMapping; 255 | for (const node of serialized) { 256 | if (node.type === "Reroute" && !this.outputs?.[outputIdx]?.isReroute && !isOutputInternal(node, 0, linksMapping)) { 257 | const rerouteType = node.outputs[0].type; 258 | const outputName = getRerouteName(node); 259 | const newOutput = this.insertOutput(outputName, rerouteType, outputIdx); 260 | newOutput.isReroute = true; 261 | } 262 | for (let i = 0; i < (node.outputs ?? []).length; i++) { 263 | if (!isOutputInternal(node, i, linksMapping)) outputIdx++; 264 | } 265 | } 266 | } 267 | 268 | inheritFrontendWidgets() { 269 | // Inherit the frontend widgets of the serialized workflow, which shows up after the specific node's construction 270 | const serialized = this.nestedNodes; 271 | let nestedWidgetIdx = 0; 272 | for (const i in serialized) { 273 | const node = serialized[i]; 274 | // Skip primitive nodes, deal with them in another method 275 | if (node.type === "PrimitiveNode") { 276 | continue; 277 | } 278 | const tempNode = LiteGraph.createNode(node.type); 279 | if (!tempNode) { 280 | console.log("[NestedNodeBuilder] Node not found", node.type); 281 | continue; 282 | } 283 | const nodeDef = nodeDefs[node.type]; 284 | const widgets = node?.serializedWidgets ?? []; 285 | for (const widgetIdx in widgets) { 286 | const widget = widgets[widgetIdx]; 287 | const tempWidget = tempNode?.widgets?.[widgetIdx]; 288 | const isWidgetInDef = nodeDef?.input?.required?.[widget.name] || nodeDef?.input?.optional?.[widget.name]; 289 | if (!isWidgetInDef && tempWidget) { 290 | // This widget is a frontend widget 291 | this.widgets.splice(nestedWidgetIdx, 0, tempWidget); 292 | // Check if this is a linked widget 293 | const parentWidgetIdx = node.serializedWidgets?.findIndex(w => w?.linkedWidgets?.map(v => v.name)?.includes(widget.name)); 294 | if (parentWidgetIdx !== undefined && parentWidgetIdx !== -1) { 295 | // This is a linked widget, find the corresponding widget in the nesting 296 | const start = nestedWidgetIdx - widgetIdx; 297 | const nestedParentWidgetIdx = start + parentWidgetIdx; 298 | const nestedParentWidget = this.widgets[nestedParentWidgetIdx]; 299 | // Link the widgets 300 | nestedParentWidget.linkedWidgets = nestedParentWidget.linkedWidgets ?? []; 301 | nestedParentWidget.linkedWidgets.push(tempWidget); 302 | } 303 | 304 | // If the widget is linked and supposed to be converted, then hide it 305 | if (widget.type.startsWith(CONVERTED_TYPE + ":")) { 306 | const parentWidgetName = widget.type.split(":")[1]; 307 | hideWidget(this, tempWidget, ":" + parentWidgetName); 308 | } 309 | } 310 | 311 | nestedWidgetIdx++; 312 | } 313 | } 314 | } 315 | 316 | inheritConvertedWidgets() { 317 | let nestedWidgetIdx = 0; 318 | for (const nodeIdx in this.nestedNodes) { 319 | const node = this.nestedNodes[nodeIdx]; 320 | const convertedInputs = {}; 321 | // Skip primitive nodes, deal with them in another method 322 | if (node.type === "PrimitiveNode") { 323 | continue; 324 | } 325 | for (const widgetIdx in node.serializedWidgets) { 326 | const widget = node.serializedWidgets[widgetIdx]; 327 | const config = getConfig(nodeDefs[node.type], widget); 328 | const nestedWidget = this?.widgets?.[nestedWidgetIdx]; 329 | if (!nestedWidget) { 330 | nestedWidgetIdx++; 331 | continue; 332 | } 333 | // Skip widgets that have already been converted (Prevent duplicate inputs when cloning the node) 334 | if (nestedWidget.type === CONVERTED_TYPE || nestedWidget.type === HIDDEN_CONVERTED_TYPE || nestedWidget.type === INHERITED_CONVERTED_TYPE) { 335 | nestedWidgetIdx++; 336 | continue; 337 | } 338 | if (widget.type === CONVERTED_TYPE) { 339 | convertToInput(this, nestedWidget, config); 340 | // Find index of the input of the node in the nesting that maps to the converted widget input 341 | const inputIdx = node.inputs.findIndex(input => input.name === widget.name); 342 | if (isInputInternal(node, inputIdx, this.linksMapping)) { 343 | // Input from converted widget is internal, so remove it and completely hide the widget 344 | this.inputs.pop(); 345 | nestedWidget.type = HIDDEN_CONVERTED_TYPE; 346 | } else { 347 | // Input from converted widget is external, so keep it and mark it as inherited 348 | nestedWidget.type = INHERITED_CONVERTED_TYPE; 349 | this.inputs.at(-1).isInherited = true; 350 | // Remove the converted input and store for later 351 | const convertedInput = this.inputs.pop(); 352 | convertedInputs[node.inputs[inputIdx].name] = convertedInput; 353 | } 354 | } 355 | nestedWidgetIdx++; 356 | } 357 | // Add the converted inputs back in the correct order 358 | const startIdx = node?.inputs?.findIndex(input => input?.widget); 359 | if (startIdx !== undefined && startIdx !== -1) { 360 | for (let i = startIdx; i < node.inputs.length; i++) { 361 | const input = node.inputs[i]; 362 | const convertedInput = convertedInputs[input.name]; 363 | if (convertedInput) { 364 | const nestedInputIdx = this.getNestedInputSlot(node.id, i); 365 | this.inputs.splice(nestedInputIdx, 0, convertedInput); 366 | } 367 | } 368 | } 369 | } 370 | } 371 | 372 | inheritPrimitiveWidgets() { 373 | const serialized = this.nestedNodes; 374 | const linksMapping = this.linksMapping; 375 | let widgetIdx = 0; 376 | for (const i in serialized) { 377 | const node = serialized[i]; 378 | // Create a temporary node to get access to primitive node widgets 379 | const tempNode = LiteGraph.createNode(node.type); 380 | if (tempNode !== null && tempNode.type == "PrimitiveNode" && node.outputs[0].links) { 381 | const tempGraph = new LiteGraph.LGraph(); 382 | tempGraph.add(tempNode); 383 | const linkId = node.outputs[0].links[0]; 384 | const entry = linksMapping[linkId]; 385 | const dst = this.nestedNodeIdMapping[entry.dstId]; 386 | const dstNode = LiteGraph.createNode(dst.type); 387 | tempGraph.add(dstNode); 388 | dstNode.configure(dst); 389 | tempNode.configure(node); 390 | // Using the first widget for now, since that is the one with the actual value 391 | const widget = tempNode.widgets[0]; 392 | delete widget.callback 393 | widget.name = tempNode.title 394 | this.widgets.splice(widgetIdx, 0, widget); 395 | widgetIdx++; 396 | } else { 397 | widgetIdx += (node.widgets_values ?? []).length; 398 | } 399 | } 400 | } 401 | 402 | createWidgetMapping() { 403 | // Map nested widget index to serialized node index and widget index 404 | const serialized = this.nestedNodes; 405 | const widgetMapping = {}; 406 | let widgetIdx = 0; 407 | for (const i in serialized) { 408 | const node = serialized[i]; 409 | for (const j in node.widgets_values) { 410 | const nestedWidget = this.widgets?.[widgetIdx]; 411 | if (!nestedWidget) break; 412 | if (node.type === "PrimitiveNode") { 413 | widgetMapping[widgetIdx] = { nodeIdx: i, widgetIdx: j }; 414 | widgetIdx++; 415 | // Skip the rest of the widgets of the primitive node, only care about the value widget 416 | break; 417 | } 418 | widgetMapping[widgetIdx] = { nodeIdx: i, widgetIdx: j }; 419 | widgetIdx++; 420 | 421 | } 422 | } 423 | return widgetMapping; 424 | } 425 | 426 | updateSerializedWorkflow() { 427 | // Update the serialized workflow with the current values of the widgets 428 | const mapping = this.widgetMapping; 429 | const serialized = this.nestedNodes; 430 | for (const widgetIdx in mapping) { 431 | const widget = this.widgets[widgetIdx]; 432 | const { nodeIdx, widgetIdx: widgetIdx2 } = mapping[widgetIdx]; 433 | const node = serialized[nodeIdx]; 434 | node.widgets_values[widgetIdx2] = widget.value; 435 | } 436 | } 437 | 438 | // Add listeners to the widgets 439 | addWidgetListeners() { 440 | for (const widget of this.widgets ?? []) { 441 | if (widget.inputEl) { 442 | widget.inputEl.addEventListener("change", (e) => { 443 | this.onWidgetChanged(widget.name, widget.value, widget.value, widget); 444 | }); 445 | } 446 | } 447 | } 448 | 449 | // Update node on property change 450 | onPropertyChanged(name, value) { 451 | if (name === "serializedWorkflow") { 452 | this.inheritWidgetValues(); 453 | } 454 | } 455 | 456 | onWidgetChanged(name, value, old_value, widget) { 457 | this.updateSerializedWorkflow(); 458 | } 459 | 460 | beforeQueuePrompt() { 461 | this.updateSerializedWorkflow(); 462 | } 463 | 464 | insertInput(name, type, index) { 465 | // Instead of appending to the end, insert at the given index, 466 | // pushing the rest of the inputs towards the end. 467 | 468 | // Add the new input 469 | this.addInput(name, type); 470 | const input = this.inputs.pop(); 471 | this.inputs.splice(index, 0, input); 472 | return input; 473 | } 474 | 475 | insertOutput(name, type, index) { 476 | // Similar to insertInput 477 | 478 | // Add the new output 479 | this.addOutput(name, type); 480 | const output = this.outputs.pop(); 481 | this.outputs.splice(index, 0, output); 482 | return output; 483 | } 484 | 485 | // Inherit the links of its serialized workflow, 486 | // must be before the nodes that are being nested are removed from the graph 487 | inheritLinks() { 488 | const linksMapping = this.linksMapping; 489 | for (const linkId in linksMapping) { 490 | const entry = linksMapping[linkId]; 491 | if (entry.srcId && entry.dstId) { // Link between nodes within the nested workflow 492 | continue; 493 | } 494 | const link = app.graph.links[linkId]; 495 | if (entry.dstId) { // Input connected from outside 496 | // This will be the new target node 497 | const src = app.graph.getNodeById(link.origin_id); 498 | const dstSlot = this.getNestedInputSlot(entry.dstId, entry.dstSlot); 499 | src.connect(link.origin_slot, this, dstSlot); 500 | } 501 | else if (entry.srcId) { // Output connected to outside 502 | // This will be the new origin node 503 | const dst = app.graph.getNodeById(link?.target_id); 504 | const srcSlot = this.getNestedOutputSlot(entry.srcId, entry.srcSlot); 505 | this.connect(srcSlot, dst, link?.target_slot); 506 | } 507 | } 508 | } 509 | 510 | getNestedInputSlot(internalNodeId, internalSlotId) { 511 | // Converts a node slot that was nested into a slot of the resulting nested node. 512 | const serialized = this.nestedNodes; 513 | const linksMapping = this.linksMapping; 514 | let slotIdx = 0; 515 | for (const i in serialized) { 516 | const node = serialized[i]; 517 | const nodeInputs = node.inputs ?? []; 518 | for (let inputIdx = 0; inputIdx < nodeInputs.length; inputIdx++) { 519 | const isCorrectSlot = node.id === internalNodeId && inputIdx === internalSlotId; 520 | if (isCorrectSlot) { 521 | return slotIdx; 522 | } 523 | if (!isInputInternal(node, inputIdx, linksMapping)) { 524 | slotIdx++; 525 | } 526 | } 527 | } 528 | return null; 529 | } 530 | 531 | getNestedOutputSlot(internalNodeId, internalSlotId) { 532 | // Converts a node slot that was nested into a slot of the resulting nested node 533 | const serialized = this.nestedNodes; 534 | let slotIdx = 0; 535 | 536 | const linksMapping = this.linksMapping; 537 | for (const i in serialized) { 538 | const node = serialized[i]; 539 | if (node.id === internalNodeId) { 540 | let numInternalOutputs = 0; 541 | // The slot internalSlotId should be non-internal if it is included in the nested node 542 | for (let j = 0; j < internalSlotId; j++) { 543 | if (isOutputInternal(node, j, linksMapping)) { 544 | numInternalOutputs++; 545 | } 546 | } 547 | return slotIdx + internalSlotId - numInternalOutputs; 548 | } 549 | let numNonInternalOutputs = 0; 550 | for (const j in node.outputs) { 551 | if (!isOutputInternal(node, j, linksMapping)) { 552 | numNonInternalOutputs++; 553 | } 554 | } 555 | slotIdx += numNonInternalOutputs; 556 | } 557 | return null; 558 | } 559 | 560 | unnest() { 561 | const serializedWorkflow = this.nestedNodes; 562 | this.linksMapping = mapLinksToNodes(serializedWorkflow); 563 | const linksMapping = this.linksMapping; 564 | // Add the nodes inside the nested node 565 | const nestedNodes = []; 566 | const internalOutputList = []; 567 | const internalInputList = []; 568 | const avgPos = averagePos(serializedWorkflow); 569 | const serializedToNodeMapping = {}; 570 | for (const idx in serializedWorkflow) { 571 | const serializedNode = serializedWorkflow[idx]; 572 | let node = LiteGraph.createNode(serializedNode.type); 573 | let rerouteInputLink = null; 574 | let rerouteOutputLinks = null; 575 | if (node) { 576 | // Fix for Primitive nodes, which check for the existence of the graph 577 | node.graph = app.graph; 578 | // Fix for Reroute nodes, which executes code if it has a link, but the link wouldn't be valid here. 579 | if (node.type === "Reroute") { 580 | rerouteInputLink = serializedNode.inputs[0].link; 581 | if (serializedNode.outputs[0].links) { 582 | rerouteOutputLinks = serializedNode.outputs[0].links.slice(); 583 | } 584 | serializedNode.inputs[0].link = null; 585 | serializedNode.outputs[0].links = []; 586 | } 587 | } else { 588 | // Create an empty missing node, use same code as LiteGraph 589 | node = new LiteGraph.LGraphNode(); 590 | node.last_serialization = serializedNode; 591 | node.has_errors = true; 592 | } 593 | // Configure the node 594 | node.configure(serializedNode); 595 | // Restore links from Reroute node fix 596 | if (node.type === "Reroute") { 597 | serializedNode.inputs[0].link = rerouteInputLink; 598 | if (rerouteOutputLinks) { 599 | serializedNode.outputs[0].links = rerouteOutputLinks; 600 | } 601 | } 602 | 603 | const dx = serializedNode.pos[0] - avgPos[0]; 604 | const dy = serializedNode.pos[1] - avgPos[1]; 605 | node.pos = [this.pos[0] + dx, this.pos[1] + dy]; 606 | 607 | const isInputsInternal = []; 608 | for (let i = 0; i < (serializedNode.inputs ?? []).length; i++) { 609 | isInputsInternal.push(isInputInternal(serializedNode, i, linksMapping)); 610 | } 611 | internalInputList.push(isInputsInternal); 612 | 613 | const isOutputsInternal = []; 614 | for (const i in serializedNode.outputs) { 615 | const output = serializedNode.outputs[i]; 616 | let isInternal = true; 617 | if (!output.links || output.links.length === 0) { 618 | isInternal = false; 619 | } 620 | for (const link of output.links ?? []) { 621 | const entry = linksMapping[link]; 622 | if (!(entry.srcId && entry.dstId)) { 623 | isInternal = false; 624 | break; 625 | } 626 | } 627 | isOutputsInternal.push(isInternal); 628 | } 629 | internalOutputList.push(isOutputsInternal); 630 | 631 | // Clear links 632 | for (const i in node.inputs) { 633 | node.inputs[i].link = null; 634 | } 635 | for (const i in node.outputs) { 636 | node.outputs[i].links = []; 637 | } 638 | 639 | app.graph.add(node); 640 | nestedNodes.push(node); 641 | serializedToNodeMapping[serializedNode.id] = node; 642 | } 643 | 644 | 645 | // Link the nodes inside the nested node 646 | for (const link in linksMapping) { 647 | const entry = linksMapping[link]; 648 | if (entry && entry.srcId && entry.dstId) { 649 | const src = serializedToNodeMapping[entry.srcId]; 650 | const dst = serializedToNodeMapping[entry.dstId]; 651 | src.connect(entry.srcSlot, dst, entry.dstSlot); 652 | } 653 | } 654 | 655 | // Link nodes in the workflow to the nodes nested by the nested node 656 | let nestedInputSlot = 0; 657 | let nestedOutputSlot = 0; 658 | // Assuming that the order of inputs and outputs of each node of the nested workflow 659 | // is in the same order as the inputs and outputs of the nested node 660 | for (const i in nestedNodes) { 661 | const node = nestedNodes[i]; 662 | for (let inputSlot = 0; inputSlot < (node.inputs ?? []).length; inputSlot++) { 663 | // Out of bounds, rest of the inputs are not connected to the outside 664 | if (nestedInputSlot >= (this.inputs ?? []).length) { 665 | break; 666 | } 667 | // If the input is only connected internally, then skip 668 | if (internalInputList[i][inputSlot]) { 669 | continue; 670 | } 671 | // If types don't match, then skip this input 672 | // Must take into account reroute node wildcard inputs 673 | let isRerouteMatching = false; 674 | if (node.type === "Reroute") { 675 | const rerouteType = node.__outputType; // Property that reroutes have 676 | isRerouteMatching = rerouteType === this.inputs[nestedInputSlot].type; 677 | isRerouteMatching = isRerouteMatching || rerouteType === undefined; // Unconnected Reroute 678 | } 679 | const dstName = node.type === "Reroute" ? getRerouteName(node) : node.title; 680 | let matchingTypes = node.inputs[inputSlot].type === this.inputs[nestedInputSlot].type; 681 | matchingTypes ||= isRerouteMatching; 682 | if (!matchingTypes) { 683 | continue; 684 | } 685 | const link = this.getInputLink(nestedInputSlot); 686 | if (link) { // Just in case 687 | const originNode = app.graph.getNodeById(link.origin_id); 688 | const srcName = originNode.type === "Reroute" ? getRerouteName(originNode) : originNode.title; 689 | originNode.connect(link.origin_slot, node, inputSlot); 690 | } 691 | nestedInputSlot++; 692 | } 693 | // Links the outputs of the nested node to the nodes outside the nested node 694 | for (let outputSlot = 0; outputSlot < (node.outputs ?? []).length; outputSlot++) { 695 | // Out of bounds, rest of the outputs are not connected to the outside 696 | if (nestedOutputSlot >= (this.outputs ?? []).length) { 697 | break; 698 | } 699 | // If types don't match, then skip this output 700 | // Allow wildcard matches for reroute nodes 701 | const isWildcardMatching = node.outputs[outputSlot].type === "*" || this.outputs[nestedOutputSlot].type === "*"; 702 | if (!isWildcardMatching && node.outputs[outputSlot].type !== this.outputs[nestedOutputSlot].type) { 703 | continue; 704 | } 705 | // If the output is only connected internally, then skip this output 706 | if (internalOutputList[i][outputSlot]) { 707 | continue; 708 | } 709 | 710 | const links = this.getOutputInfo(nestedOutputSlot).links; 711 | const toConnect = []; // To avoid invalidating the iterator 712 | for (const linkId of links ?? []) { 713 | const link = app.graph.links[linkId]; 714 | if (link) { 715 | const targetNode = app.graph.getNodeById(link.target_id); 716 | toConnect.push({ node: targetNode, slot: link.target_slot }); 717 | } 718 | } 719 | for (const { node: targetNode, slot: targetSlot } of toConnect) { 720 | node.connect(outputSlot, targetNode, targetSlot); 721 | } 722 | nestedOutputSlot++; 723 | } 724 | } 725 | 726 | // Remove the nested node 727 | app.graph.remove(graph.getNodeById(this.id)); 728 | 729 | // Add the nodes to selection 730 | for (const node of nestedNodes) { 731 | app.canvas.selectNode(node, true); 732 | } 733 | 734 | return nestedNodes; 735 | } 736 | 737 | getConnectedInputNodes() { 738 | const result = []; 739 | for (let inputSlot = 0; inputSlot < (this.inputs ?? []).length; inputSlot++) { 740 | const link = this.getInputLink(inputSlot); 741 | if (link) { 742 | const originNode = app.graph.getNodeById(link.origin_id); 743 | const data = { 744 | node: originNode, 745 | srcSlot: link.origin_slot, 746 | dstSlot: inputSlot, 747 | }; 748 | result.push(data); 749 | } 750 | } 751 | return result; 752 | } 753 | } 754 | 755 | // 756 | // Copied from ./web/extensions/core/widgetInputs.js 757 | // 758 | const CONVERTED_TYPE = "converted-widget"; 759 | const VALID_TYPES = ["STRING", "combo", "number"]; 760 | 761 | export function isConvertableWidget(widget, config) { 762 | return VALID_TYPES.includes(widget.type) || VALID_TYPES.includes(config[0]); 763 | } 764 | 765 | function hideWidget(node, widget, suffix = "") { 766 | widget.origType = widget.type; 767 | widget.origComputeSize = widget.computeSize; 768 | widget.origSerializeValue = widget.serializeValue; 769 | widget.computeSize = () => [0, -4]; // -4 is due to the gap litegraph adds between widgets automatically 770 | widget.type = CONVERTED_TYPE + suffix; 771 | widget.serializeValue = () => { 772 | // Prevent serializing the widget if we have no input linked 773 | const { link } = node.inputs.find((i) => i.widget?.name === widget.name); 774 | if (link == null) { 775 | return undefined; 776 | } 777 | return widget.origSerializeValue ? widget.origSerializeValue() : widget.value; 778 | }; 779 | 780 | // Hide any linked widgets, e.g. seed+seedControl 781 | if (widget.linkedWidgets) { 782 | for (const w of widget.linkedWidgets) { 783 | hideWidget(node, w, ":" + widget.name); 784 | } 785 | } 786 | } 787 | 788 | function convertToInput(node, widget, config) { 789 | hideWidget(node, widget); 790 | const { linkType } = getWidgetType(config); 791 | 792 | // Add input and store widget config for creating on primitive node 793 | const sz = node.size; 794 | node.addInput(widget.name, linkType, { 795 | widget: { name: widget.name, config }, 796 | }); 797 | 798 | // Restore original size but grow if needed 799 | node.setSize([Math.max(sz[0], node.size[0]), Math.max(sz[1], node.size[1])]); 800 | } 801 | 802 | function getWidgetType(config) { 803 | // Special handling for COMBO so we restrict links based on the entries 804 | let type = config[0]; 805 | let linkType = type; 806 | if (type instanceof Array) { 807 | type = "COMBO"; 808 | linkType = linkType.join(","); 809 | } 810 | return { type, linkType }; 811 | } 812 | 813 | function getConfig(nodeData, widget) { 814 | const originalName = widget.name.replace(/_\d+$/, ''); 815 | return nodeData?.input?.required[originalName] || nodeData?.input?.optional?.[originalName] || [widget.type, widget.options || {}]; 816 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------