MCPcopy Index your code
hub / github.com/Comfy-Org/litegraph.js

github.com/Comfy-Org/litegraph.js @v0.17.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.17.2 ↗ · + Follow
1,395 symbols 3,378 edges 135 files 452 documented · 32%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

@ComfyOrg/litegraph

This is the litegraph version used in ComfyUI_frontend.

It is a fork of the original litegraph.js. Some APIs may by unchanged, however it is largely incompatible with the original.

Some early highlights:

Install

npm i @comfyorg/litegraph

litegraph.js

A TypeScript library to create graphs in the browser similar to Unreal Blueprints.

Description of the original litegraph.js

A library in Javascript to create graphs in the browser similar to Unreal Blueprints. Nodes can be programmed easily and it includes an editor to construct and tests the graphs.

It can be integrated easily in any existing web applications and graphs can be run without the need of the editor.

Node Graph

Features

  • Renders on Canvas2D (zoom in/out and panning, easy to render complex interfaces, can be used inside a WebGLTexture)
  • Easy to use editor (searchbox, keyboard shortcuts, multiple selection, context menu, ...)
  • Optimized to support hundreds of nodes per graph (on editor but also on execution)
  • Customizable theme (colors, shapes, background)
  • Callbacks to personalize every action/drawing/event of nodes
  • Graphs can be executed in NodeJS
  • Highly customizable nodes (color, shape, widgets, custom rendering)
  • Easy to integrate in any JS application (one single file, no dependencies)
  • Typescript support

Installation

You can install it using npm

npm install @comfyorg/litegraph

How to code a new Node type

Here is an example of how to build a node that sums two inputs:

import { LiteGraph, LGraphNode } from "./litegraph"

class MyAddNode extends LGraphNode {
  // Name to show
  title = "Sum"

  constructor() {
    this.addInput("A", "number")
    this.addInput("B", "number")
    this.addOutput("A+B", "number")
    this.properties.precision = 1
  }

  // Function to call when the node is executed
  onExecute() {
    var A = this.getInputData(0)
    if (A === undefined) A = 0
    var B = this.getInputData(1)
    if (B === undefined) B = 0
    this.setOutputData(0, A + B)
  }
}

// Register the node type
LiteGraph.registerNodeType("basic/sum", MyAddNode)

Server side

It also works server-side using NodeJS although some nodes do not work in server (audio, graphics, input, etc).

import { LiteGraph, LGraph } from "./litegraph.js"

const graph = new LGraph()

const firstNode = LiteGraph.createNode("basic/sum")
graph.add(firstNode)

const secondNode = LiteGraph.createNode("basic/sum")
graph.add(secondNode)

firstNode.connect(0, secondNode, 1)

graph.start()

Projects using it

ComfyUI

ComfyUI default workflow

Projects using the original litegraph.js

Click to expand

webglstudio.org

WebGLStudio

MOI Elephant

MOI Elephant

Mynodes

MyNodes

Feedback

Please open an issue on the GitHub repo.

Development

Litegraph has no runtime dependencies. The build tooling has been tested on Node.JS 20.18.x

Releasing

Use GitHub actions to release normal versions.

  1. Run the Release a New Version action, selecting the version incrment type
  2. Merge the resultion PR
  3. A GitHub release is automatically published on merge

Pre-release

The action directly translates Version increment type to the npm version command. Pre-release ID (suffix) is the option for the --preid argument.

e.g. Use prerelease increment type to automatically bump the patch version and create a pre-release version. Subsequent runs of prerelease will update the prerelease version only. Use patch when ready to remove the pre-release suffix.

Contributors

You can find the current list of contributors on GitHub.

Contributors (pre-fork)

  • atlasan
  • kriffe
  • rappestad
  • InventivetalentDev
  • NateScarlet
  • coderofsalvation
  • ilyabesk
  • gausszhou

Extension points exported contracts — how you extend this code

RenderLink (Interface)
(no doc) [12 implementers]
src/canvas/RenderLink.ts
Positionable (Interface)
(no doc) [5 implementers]
src/interfaces.ts
NodeLike (Interface)
(no doc) [4 implementers]
src/types/NodeLike.ts
BaseLGraph (Interface)
(no doc) [3 implementers]
src/LGraph.ts
DirtyFixtures (Interface)
These fixtures alter global state, and are difficult to reset. Relies on a single test per-file to reset state.
test/testExtensions.ts
ICloseable (Interface)
(no doc) [2 implementers]
src/LGraphCanvas.ts
CustomEventDispatcher (Interface)
(no doc) [2 implementers]
src/infrastructure/CustomEventTarget.ts
TestContext (Interface)
(no doc)
test/LinkConnector.integration.test.ts

Core symbols most depended-on inside this repo

add
called by 189
src/LGraph.ts
createTestSubgraph
called by 161
test/subgraph/fixtures/subgraphHelpers.ts
get
called by 115
src/MapProxyHandler.ts
createTestSubgraphNode
called by 113
test/subgraph/fixtures/subgraphHelpers.ts
addEventListener
called by 113
src/infrastructure/CustomEventTarget.ts
addInput
called by 112
src/LGraphNode.ts
getNodeById
called by 84
src/interfaces.ts
addOutput
called by 77
src/LGraphNode.ts

Shape

Method 939
Function 179
Interface 151
Class 111
Enum 15

Languages

TypeScript100%

Modules by API surface

src/LGraphCanvas.ts187 symbols
src/LGraphNode.ts163 symbols
src/LGraph.ts75 symbols
src/Reroute.ts55 symbols
src/interfaces.ts53 symbols
src/infrastructure/Rectangle.ts51 symbols
src/canvas/LinkConnector.ts34 symbols
src/LLink.ts30 symbols
src/LiteGraphGlobal.ts29 symbols
src/LGraphGroup.ts27 symbols
src/subgraph/SubgraphNode.ts23 symbols
src/subgraph/SubgraphIONodeBase.ts22 symbols

For agents

$ claude mcp add litegraph.js \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact