Fix circular dependency (#219)

* Fix circular dependency - LGraphCanvas static init

* Remove dependency workaround
This commit is contained in:
filtered
2024-10-26 11:17:31 +11:00
committed by GitHub
parent 86fb5339e8
commit 955daac9e6
3 changed files with 27 additions and 34 deletions

View File

@@ -8,7 +8,6 @@ import type { LLink } from "./LLink"
import type { LGraphGroup } from "./LGraphGroup"
import type { LGraph } from "./LGraph"
import type { ContextMenu } from "./ContextMenu"
import { LiteGraphGlobal } from "./LiteGraphGlobal"
import { isInsideRectangle, distance, overlapBounding, isPointInRectangle } from "./measure"
import { drawSlot, LabelPosition } from "./draw"
import { DragAndScale } from "./DragAndScale"
@@ -106,12 +105,8 @@ export class LGraphCanvas {
static DEFAULT_BACKGROUND_IMAGE = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII="
// TODO: Remove workaround - this should be instance-based, regardless. "-1" formerly pointed to LiteGraph.EVENT_LINK_COLOR.
static link_type_colors: Record<string, string> = {
"-1": LiteGraphGlobal.DEFAULT_EVENT_LINK_COLOR,
number: "#AAA",
node: "#DCA"
}
/** Initialised from LiteGraphGlobal static block to avoid circular dependency. */
static link_type_colors: Record<string, string>
static gradients = {} //cache of gradients
static search_limit = -1
@@ -5060,8 +5055,6 @@ export class LGraphCanvas {
//choose color
if (!color && link) {
// TODO: Remove ts-ignore when typescript LLink PR goes in.
// @ts-ignore Already resolved in parallel PR.
color = link.color || LGraphCanvas.link_type_colors[link.type]
}
color ||= this.default_link_color

View File

@@ -1,10 +1,10 @@
import type { LGraph } from "./LGraph"
import type { LLink } from "./LLink"
import type { LGraphGroup } from "./LGraphGroup"
import type { DragAndScale } from "./DragAndScale"
import type { LGraphCanvas } from "./LGraphCanvas"
import type { ContextMenu } from "./ContextMenu"
import type { CurveEditor } from "./CurveEditor"
import { LGraph } from "./LGraph"
import { LLink } from "./LLink"
import { LGraphGroup } from "./LGraphGroup"
import { DragAndScale } from "./DragAndScale"
import { LGraphCanvas } from "./LGraphCanvas"
import { ContextMenu } from "./ContextMenu"
import { CurveEditor } from "./CurveEditor"
import { LGraphEventMode, LinkDirection, LinkRenderType, NodeSlotType, RenderShape, TitleMode } from "./types/globalEnums"
import { LiteGraph } from "./litegraph"
import { LGraphNode } from "./LGraphNode"
@@ -166,18 +166,28 @@ export class LiteGraphGlobal {
// Whether to highlight the bounding box of selected groups
highlight_selected_group = false
LGraph: typeof LGraph
LLink: typeof LLink
LGraphNode: typeof LGraphNode
LGraphGroup: typeof LGraphGroup
DragAndScale: typeof DragAndScale
LGraphCanvas: typeof LGraphCanvas
ContextMenu: typeof ContextMenu
CurveEditor: typeof CurveEditor
// TODO: Remove legacy accessors
LGraph = LGraph
LLink = LLink
LGraphNode = LGraphNode
LGraphGroup = LGraphGroup
DragAndScale = DragAndScale
LGraphCanvas = LGraphCanvas
ContextMenu = ContextMenu
CurveEditor = CurveEditor
onNodeTypeRegistered?(type: string, base_class: typeof LGraphNode): void
onNodeTypeReplaced?(type: string, base_class: typeof LGraphNode, prev: unknown): void
// Avoid circular dependency from original single-module
static {
LGraphCanvas.link_type_colors = {
"-1": LiteGraphGlobal.DEFAULT_EVENT_LINK_COLOR,
number: "#AAA",
node: "#DCA"
}
}
constructor() {
//timer that works everywhere
if (typeof performance != "undefined") {

View File

@@ -23,16 +23,6 @@ export { IWidget }
export { LGraphBadge, BadgePosition }
export { SlotShape, LabelPosition, SlotDirection, SlotType }
// TODO: Remove legacy accessors
LiteGraph.LGraph = LGraph
LiteGraph.LLink = LLink
LiteGraph.LGraphNode = LGraphNode
LiteGraph.LGraphGroup = LGraphGroup
LiteGraph.DragAndScale = DragAndScale
LiteGraph.LGraphCanvas = LGraphCanvas
LiteGraph.ContextMenu = ContextMenu
LiteGraph.CurveEditor = CurveEditor
export function clamp(v: number, a: number, b: number): number {
return a > v ? a : b < v ? b : v
};