Skip to content

Commit

Permalink
Use npm package @ComfyOrg/litegraph (#89)
Browse files Browse the repository at this point in the history
* Use npm to manage litegraph

* Fix merge issues caused by BetaUI change

* Switch to @comfyorg/litegraph

* Fix various import

* Fix css apply order bug

* Fix package lock

* Update litegraph

* Update litegraph

* Update browsertest expectations

* Update test expectations [skip ci]

* Fix default view screenshot

---------

Co-authored-by: github-actions <github-actions@github.com>
  • Loading branch information
huchenlei and github-actions authored Jul 6, 2024
1 parent 27c5bc1 commit d6b2d5f
Show file tree
Hide file tree
Showing 63 changed files with 514 additions and 18,024 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ Front-end of [ComfyUI](https://github.com/comfyanonymous/ComfyUI) modernized. Th
- Added a shim layer to be backward compatible with the existing extension system. https://github.com/huchenlei/ComfyUI_frontend/pull/15
- Front-end dev server.
- Zod schema for input validation on ComfyUI workflow.
- Make litegraph a npm dependency.

### What to be done

- Make litegraph a npm dependency.
- Replace the existing ComfyUI front-end impl.
- Turn on `strict` on `tsconfig.json`.
- Introduce react to start managing part of the UI.
Expand Down
2 changes: 2 additions & 0 deletions browser_tests/ComfyPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export class ComfyPage {

async resetView() {
await this.resetViewButton.click();
// Avoid "Reset View" button highlight.
await this.page.mouse.move(10, 10);
await this.nextFrame();
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 2 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@
font-family: 'Roboto Mono', 'Noto Color Emoji';
}
</style> -->
<link rel="stylesheet" type="text/css" href="/lib/litegraph.css" />
<link rel="stylesheet" type="text/css" href="/style.css" />
<link rel="stylesheet" type="text/css" href="/user.css" />
<link rel="stylesheet" type="text/css" href="/materialdesignicons.min.css" />
<script type="text/javascript" src="/lib/litegraph.core.js"></script>
<script type="text/javascript" src="/lib/litegraph.extensions.js" defer></script>
<script type="module">
console.log("ComfyUI Front-end version:", __COMFYUI_FRONTEND_VERSION__);
import { app } from "./src/scripts/app";
Expand All @@ -27,6 +21,8 @@
window.graph = app.graph;
})();
</script>
<link rel="stylesheet" type="text/css" href="/user.css" />
<link rel="stylesheet" type="text/css" href="/materialdesignicons.min.css" />
</head>
<body class="litegraph">
<div id="comfy-user-selection" class="comfy-user-selection" style="display: none;">
Expand Down
1,229 changes: 399 additions & 830 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"zip-dir": "^2.0.0"
},
"dependencies": {
"@comfyorg/litegraph": "^0.7.20",
"dotenv": "^16.4.5",
"zod": "^3.23.8",
"zod-validation-error": "^3.3.0"
Expand All @@ -47,4 +48,4 @@
"git add"
]
}
}
}
2 changes: 0 additions & 2 deletions public/style.css → src/assets/css/style.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@import url("scripts/ui/menu/menu.css");

:root {
--fg-color: #000;
--bg-color: #fff;
Expand Down
27 changes: 27 additions & 0 deletions src/extensions/core/colorPalette.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { app } from "../../scripts/app";
import { $el } from "../../scripts/ui";
import type { ColorPalettes } from "/types/colorPalette";
import { LGraphCanvas, LiteGraph } from "@comfyorg/litegraph";

// Manage color palettes

Expand Down Expand Up @@ -427,6 +428,32 @@ const els: { select: HTMLSelectElement | null } = {
// const ctxMenu = LiteGraph.ContextMenu;
app.registerExtension({
name: id,
init() {
/**
* Changes the background color of the canvas.
*
* @method updateBackground
* @param {image} String
* @param {clearBackgroundColor} String
*/
// @ts-ignore
LGraphCanvas.prototype.updateBackground = function (
image,
clearBackgroundColor
) {
this._bg_img = new Image();
this._bg_img.name = image;
this._bg_img.src = image;
this._bg_img.onload = () => {
this.draw(true, true);
};
this.background_image = image;

this.clear_background = true;
this.clear_background_color = clearBackgroundColor;
this._pattern = null;
};
},
addCustomNodeDefs(node_defs) {
const sortObjectKeys = (unordered) => {
return Object.keys(unordered)
Expand Down
1 change: 1 addition & 0 deletions src/extensions/core/contextMenuFilter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { LiteGraph, LGraphCanvas } from "@comfyorg/litegraph";
import { app } from "../../scripts/app";

// Adds filtering to combo context menus
Expand Down
3 changes: 2 additions & 1 deletion src/extensions/core/groupNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { app } from "../../scripts/app";
import { api } from "../../scripts/api";
import { mergeIfValid } from "./widgetInputs";
import { ManageGroupDialog } from "./groupNodeManage";
import type { LGraphNode } from "/types/litegraph";
import type { LGraphNode } from "@comfyorg/litegraph";
import { LGraphCanvas, LiteGraph } from "@comfyorg/litegraph";

const GROUP = Symbol();

Expand Down
6 changes: 5 additions & 1 deletion src/extensions/core/groupNodeManage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { DraggableList } from "../../scripts/ui/draggableList";
import { GroupNodeConfig, GroupNodeHandler } from "./groupNode";
import "./groupNodeManage.css";
import { app, type ComfyApp } from "../../scripts/app";
import type { LGraphNode, LGraphNodeConstructor } from "/types/litegraph";
import {
LiteGraph,
type LGraphNode,
type LGraphNodeConstructor,
} from "@comfyorg/litegraph";

const ORDER: symbol = Symbol();

Expand Down
1 change: 1 addition & 0 deletions src/extensions/core/groupOptions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { app } from "../../scripts/app";
import { LGraphCanvas, LiteGraph } from "@comfyorg/litegraph";

function setNodeMode(node, mode) {
node.mode = mode;
Expand Down
1 change: 1 addition & 0 deletions src/extensions/core/invertMenuScrolling.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { LiteGraph } from "@comfyorg/litegraph";
import { app } from "../../scripts/app";

// Inverts the scrolling of context menus
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/core/linkRenderMode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { app } from "../../scripts/app";

import { LiteGraph } from "@comfyorg/litegraph";
const id = "Comfy.LinkRenderMode";
const ext = {
name: id,
Expand Down
1 change: 1 addition & 0 deletions src/extensions/core/nodeTemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { app } from "../../scripts/app";
import { api } from "../../scripts/api";
import { ComfyDialog, $el } from "../../scripts/ui";
import { GroupNodeConfig, GroupNodeHandler } from "./groupNode";
import { LGraphCanvas } from "@comfyorg/litegraph";

// Adds the ability to save and add multiple nodes as a template
// To save:
Expand Down
4 changes: 1 addition & 3 deletions src/extensions/core/noteNode.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { LiteGraph, LGraphCanvas } from "@comfyorg/litegraph";
import { app } from "../../scripts/app";
import { ComfyWidgets } from "../../scripts/widgets";
// Node that add notes to your project
Expand All @@ -8,11 +9,8 @@ app.registerExtension({
class NoteNode {
static category: string;

// @ts-ignore
color = LGraphCanvas.node_colors.yellow.color;
// @ts-ignore
bgcolor = LGraphCanvas.node_colors.yellow.bgcolor;
// @ts-ignore
groupcolor = LGraphCanvas.node_colors.yellow.groupcolor;
properties: { text: string };
serialize_widgets: boolean;
Expand Down
1 change: 1 addition & 0 deletions src/extensions/core/rerouteNode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { app } from "../../scripts/app";
import { mergeIfValid, getWidgetConfig, setWidgetConfig } from "./widgetInputs";
import { LiteGraph, LGraphCanvas } from "@comfyorg/litegraph";

// Node that allows you to redirect connections for cleaner graphs

Expand Down
1 change: 1 addition & 0 deletions src/extensions/core/simpleTouchSupport.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { app } from "../../scripts/app";
import { LGraphCanvas, LiteGraph } from "@comfyorg/litegraph";

let touchZooming;
let touchCount = 0;
Expand Down
1 change: 1 addition & 0 deletions src/extensions/core/slotDefaults.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { app } from "../../scripts/app";
import { ComfyWidgets } from "../../scripts/widgets";
import { LiteGraph } from "@comfyorg/litegraph";
// Adds defaults for quickly adding nodes with middle click on the input/output

app.registerExtension({
Expand Down
13 changes: 12 additions & 1 deletion src/extensions/core/snapToGrid.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { app } from "../../scripts/app";
import {
LGraphCanvas,
LGraphNode,
LGraphGroup,
LiteGraph,
} from "@comfyorg/litegraph";

// Shift + drag/resize to snap to grid

Expand Down Expand Up @@ -77,12 +83,14 @@ app.registerExtension({

let w, h;
if (node.flags.collapsed) {
// @ts-ignore
w = node._collapsed_width;
h = LiteGraph.NODE_TITLE_HEIGHT;
shiftY -= LiteGraph.NODE_TITLE_HEIGHT;
} else {
w = node.size[0];
h = node.size[1];
// @ts-ignore
let titleMode = node.constructor.title_mode;
if (
titleMode !== LiteGraph.TRANSPARENT_TITLE &&
Expand All @@ -105,7 +113,7 @@ app.registerExtension({
* The currently moving, selected group only. Set after the `selected_group` has actually started
* moving.
*/
let selectedAndMovingGroup = null;
let selectedAndMovingGroup: LGraphGroup | null = null;

/**
* Handles moving a group; tracking when a group has been moved (to show the ghost in `drawGroups`
Expand Down Expand Up @@ -154,13 +162,16 @@ app.registerExtension({
LGraphCanvas.prototype.drawGroups = function (canvas, ctx) {
if (this.selected_group && app.shiftDown) {
if (this.selected_group_resizing) {
// @ts-ignore
roundVectorToGrid(this.selected_group.size);
} else if (selectedAndMovingGroup) {
// @ts-ignore
const [x, y] = roundVectorToGrid([...selectedAndMovingGroup.pos]);
const f = ctx.fillStyle;
const s = ctx.strokeStyle;
ctx.fillStyle = "rgba(100, 100, 100, 0.33)";
ctx.strokeStyle = "rgba(100, 100, 100, 0.66)";
// @ts-ignore
ctx.rect(x, y, ...selectedAndMovingGroup.size);
ctx.fill();
ctx.stroke();
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/core/uploadAudio.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { app } from "../../scripts/app";
import { api } from "../../scripts/api";
import type { IWidget } from "/types/litegraph";
import type { IWidget } from "@comfyorg/litegraph";
import type { DOMWidget } from "/scripts/domWidget";
import { ComfyNodeDef } from "/types/apiTypes";

Expand Down
1 change: 1 addition & 0 deletions src/extensions/core/widgetInputs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ComfyWidgets, addValueControlWidgets } from "../../scripts/widgets";
import { app } from "../../scripts/app";
import { applyTextReplacements } from "../../scripts/utils";
import { LiteGraph } from "@comfyorg/litegraph";

const CONVERTED_TYPE = "converted-widget";
const VALID_TYPES = ["STRING", "combo", "number", "BOOLEAN"];
Expand Down
Loading

0 comments on commit d6b2d5f

Please sign in to comment.