From d65ca9ad081ac8b64168301324fca8cc264710bc Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Sun, 11 Oct 2026 08:08:02 +0000 Subject: [PATCH 01/16] refactor: remove litegraph helper barrel cycles --- .fallow-baselines/dead-code.json | 16 ++++----- src/lib/litegraph/src/ContextMenu.ts | 6 ++-- src/lib/litegraph/src/DragAndScale.ts | 3 +- src/lib/litegraph/src/Reroute.ts | 4 +-- src/lib/litegraph/src/canvas/linkGeometry.ts | 10 +++--- .../src/subgraph/ExecutableNodeDTO.ts | 11 ++++--- src/lib/litegraph/src/utils/feedback.ts | 6 ++-- src/lib/litegraph/src/utils/linkColors.ts | 8 ++--- src/lib/litegraph/src/widgets/ComboWidget.ts | 6 ++-- src/lib/litegraph/src/widgets/LegacyWidget.ts | 4 +-- .../canvas/litegraph/litegraphLinkAdapter.ts | 4 +-- .../canvas/litegraph/slotCalculations.test.ts | 33 +++++++++---------- .../core/canvas/litegraph/slotCalculations.ts | 30 ++++++++--------- 13 files changed, 70 insertions(+), 71 deletions(-) diff --git a/.fallow-baselines/dead-code.json b/.fallow-baselines/dead-code.json index 65b24e4bcf7..77543917784 100644 --- a/.fallow-baselines/dead-code.json +++ b/.fallow-baselines/dead-code.json @@ -27,25 +27,25 @@ "src/composables/sidebarTabs/useJobHistorySidebarTab.ts->src/stores/workspace/sidebarTabStore.ts", "src/composables/usePaste.ts->src/scripts/app.ts", "src/extensions/core/load3d/Load3dUtils.ts->src/scripts/app.ts", - "src/lib/litegraph/src/ContextMenu.ts->src/lib/litegraph/src/litegraph.ts", - "src/lib/litegraph/src/ContextMenu.ts->src/lib/litegraph/src/LiteGraphGlobal.ts->src/lib/litegraph/src/litegraph.ts", - "src/lib/litegraph/src/DragAndScale.ts->src/lib/litegraph/src/litegraph.ts", - "src/lib/litegraph/src/DragAndScale.ts->src/lib/litegraph/src/LGraphCanvas.ts->src/lib/litegraph/src/litegraph.ts", - "src/lib/litegraph/src/DragAndScale.ts->src/lib/litegraph/src/LiteGraphGlobal.ts->src/lib/litegraph/src/litegraph.ts", + "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphCanvas.ts->src/lib/litegraph/src/litegraph.ts", + "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphGroup.ts->src/lib/litegraph/src/litegraph.ts", + "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/litegraph.ts", "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/litegraph.ts", + "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LiteGraphGlobal.ts->src/lib/litegraph/src/litegraph.ts", + "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/litegraph.ts->src/lib/litegraph/src/subgraph/Subgraph.ts", + "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/litegraph.ts->src/lib/litegraph/src/subgraph/SubgraphInput.ts", + "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/litegraph.ts->src/lib/litegraph/src/subgraph/SubgraphOutput.ts", + "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/litegraph.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", "src/lib/litegraph/src/LGraphCanvas.ts->src/lib/litegraph/src/LGraphGroup.ts", "src/lib/litegraph/src/LGraphCanvas.ts->src/lib/litegraph/src/LGraphNode.ts", "src/lib/litegraph/src/LGraphCanvas.ts->src/lib/litegraph/src/litegraph.ts", "src/lib/litegraph/src/LGraphGroup.ts->src/lib/litegraph/src/litegraph.ts", "src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/litegraph.ts", "src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/utils/collections.ts", - "src/lib/litegraph/src/Reroute.ts->src/lib/litegraph/src/litegraph.ts", "src/lib/litegraph/src/litegraph.ts->src/lib/litegraph/src/node/NodeInputSlot.ts", "src/lib/litegraph/src/litegraph.ts->src/lib/litegraph/src/node/NodeOutputSlot.ts", - "src/lib/litegraph/src/litegraph.ts->src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts", "src/lib/litegraph/src/litegraph.ts->src/lib/litegraph/src/subgraph/SubgraphNode.ts", "src/lib/litegraph/src/litegraph.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", - "src/lib/litegraph/src/litegraph.ts->src/lib/litegraph/src/widgets/LegacyWidget.ts", "src/lib/litegraph/src/node/NodeInputSlot.ts->src/lib/litegraph/src/node/NodeSlot.ts", "src/platform/cloud/subscription/composables/useSubscriptionDialog.ts->src/services/dialogService.ts", "src/platform/missingMedia/missingMediaStore.ts->src/scripts/app.ts", diff --git a/src/lib/litegraph/src/ContextMenu.ts b/src/lib/litegraph/src/ContextMenu.ts index c2cb9f9e0f9..4f1425788bb 100644 --- a/src/lib/litegraph/src/ContextMenu.ts +++ b/src/lib/litegraph/src/ContextMenu.ts @@ -5,7 +5,7 @@ import type { IContextMenuOptions, IContextMenuValue } from './types/contextMenu' -import { LiteGraph } from './litegraph' +import { litegraph } from './litegraphInstance' const ALLOWED_TAGS = ['span', 'b', 'i', 'em', 'strong'] const ALLOWED_STYLE_PROPS = new Set([ @@ -215,7 +215,7 @@ export class ContextMenu { root.style.left = `${left}px` root.style.top = `${top}px` - if (LiteGraph.context_menu_scaling && options.scale) { + if (litegraph().context_menu_scaling && options.scale) { root.style.transform = `scale(${Math.round(options.scale * 4) * 0.25})` } } @@ -384,7 +384,7 @@ export class ContextMenu { } else if (!ContextMenu.isCursorOverElement(e, this.parentMenu.root)) { ContextMenu.trigger( this.parentMenu.root, - `${LiteGraph.pointerevents_method}leave`, + `${litegraph().pointerevents_method}leave`, e ) } diff --git a/src/lib/litegraph/src/DragAndScale.ts b/src/lib/litegraph/src/DragAndScale.ts index 695a2e70f0c..ec9cb8251f2 100644 --- a/src/lib/litegraph/src/DragAndScale.ts +++ b/src/lib/litegraph/src/DragAndScale.ts @@ -1,7 +1,8 @@ import { readBrowserDpr } from '@/renderer/core/canvas/canvasViewport' import type { Point, ReadOnlyRect, Rect } from './interfaces' -import { EaseFunction, Rectangle } from './litegraph' +import { EaseFunction } from './types/globalEnums' +import { Rectangle } from './infrastructure/Rectangle' export interface DragAndScaleState { /** diff --git a/src/lib/litegraph/src/Reroute.ts b/src/lib/litegraph/src/Reroute.ts index 840aebf9daa..84d4705458b 100644 --- a/src/lib/litegraph/src/Reroute.ts +++ b/src/lib/litegraph/src/Reroute.ts @@ -43,7 +43,7 @@ import type { } from './interfaces' import type { INodeInputSlot, INodeOutputSlot } from './types/slots' import type { LinkNetwork, ReadonlyLinkNetwork } from './types/linkNetwork' -import { LiteGraph } from './litegraph' +import { litegraph } from './litegraphInstance' import { distance, isPointInRect } from './measure' import type { Serialisable, SerialisableReroute } from './types/serialisation' @@ -472,7 +472,7 @@ export class Reroute snapToGrid(snapTo: number): boolean { if (!snapTo) return false - const offsetY = LiteGraph.NODE_SLOT_HEIGHT * 0.7 + const offsetY = litegraph().NODE_SLOT_HEIGHT * 0.7 const { x, y } = this.storedPosition const snappedX = snapTo * Math.round(x / snapTo) const snappedY = snapTo * Math.round((y - offsetY) / snapTo) + offsetY diff --git a/src/lib/litegraph/src/canvas/linkGeometry.ts b/src/lib/litegraph/src/canvas/linkGeometry.ts index 11bea2b37a5..54c27964a6c 100644 --- a/src/lib/litegraph/src/canvas/linkGeometry.ts +++ b/src/lib/litegraph/src/canvas/linkGeometry.ts @@ -1,7 +1,7 @@ import type { LGraph } from '../LGraph' import type { LLink } from '../LLink' import type { Point } from '../interfaces' -import { LiteGraph } from '../litegraph' +import { litegraph } from '../litegraphInstance' import { inputLinkId } from '../node/slotLinks' import { getSlotPosition } from '@/renderer/core/canvas/litegraph/slotCalculations' @@ -16,7 +16,7 @@ export function getLinkEndpointPositions( return } - const endPos = LiteGraph.vueNodesMode + const endPos = litegraph().vueNodesMode ? getSlotPosition(inputNode, link.target_slot, true) : inputNode.getInputPos(link.target_slot) return [subgraphInput.pos, endPos] @@ -28,7 +28,7 @@ export function getLinkEndpointPositions( return } - const startPos = LiteGraph.vueNodesMode + const startPos = litegraph().vueNodesMode ? getSlotPosition(outputNode, link.origin_slot, false) : outputNode.getOutputPos(link.origin_slot) return [startPos, subgraphOutput.pos] @@ -42,10 +42,10 @@ export function getLinkEndpointPositions( return if (!outputNode || !output) return - const endPos: Point = LiteGraph.vueNodesMode + const endPos: Point = litegraph().vueNodesMode ? getSlotPosition(inputNode, link.target_slot, true) : inputNode.getInputPos(link.target_slot) - const startPos: Point = LiteGraph.vueNodesMode + const startPos: Point = litegraph().vueNodesMode ? getSlotPosition(outputNode, link.origin_slot, false) : outputNode.getOutputPos(link.origin_slot) diff --git a/src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts b/src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts index 11f41ca578e..8e54346a7b6 100644 --- a/src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts +++ b/src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts @@ -9,7 +9,8 @@ import { NullGraphError } from '@/lib/litegraph/src/infrastructure/NullGraphErro import { RecursionError } from '@/lib/litegraph/src/infrastructure/RecursionError' import { SlotIndexError } from '@/lib/litegraph/src/infrastructure/SlotIndexError' import type { ISlotType } from '@/lib/litegraph/src/interfaces' -import { LGraphEventMode, LiteGraph } from '@/lib/litegraph/src/litegraph' +import { LGraphEventMode } from '@/lib/litegraph/src/types/globalEnums' +import { litegraph } from '@/lib/litegraph/src/litegraphInstance' import type { Subgraph } from './Subgraph' import type { SubgraphNode } from './SubgraphNode' @@ -366,8 +367,8 @@ export class ExecutableNodeDTO implements ExecutableLGraphNode { // Prefer input with the same slot ID if ( oppositeInput && - LiteGraph.isValidConnection(oppositeInput.type, outputType) && - LiteGraph.isValidConnection(oppositeInput.type, type) + litegraph().isValidConnection(oppositeInput.type, outputType) && + litegraph().isValidConnection(oppositeInput.type, type) ) { return slot } @@ -379,8 +380,8 @@ export class ExecutableNodeDTO implements ExecutableLGraphNode { // Find first matching slot - prefer exact type return inputs.findIndex( (input) => - LiteGraph.isValidConnection(input.type, outputType) && - LiteGraph.isValidConnection(input.type, type) + litegraph().isValidConnection(input.type, outputType) && + litegraph().isValidConnection(input.type, type) ) } diff --git a/src/lib/litegraph/src/utils/feedback.ts b/src/lib/litegraph/src/utils/feedback.ts index 8215735a439..88e798a903c 100644 --- a/src/lib/litegraph/src/utils/feedback.ts +++ b/src/lib/litegraph/src/utils/feedback.ts @@ -1,4 +1,4 @@ -import { LiteGraph } from '@/lib/litegraph/src/litegraph' +import { litegraph } from '@/lib/litegraph/src/litegraphInstance' /** Guard against unbound allocation. */ const UNIQUE_MESSAGE_LIMIT = 10_000 @@ -11,7 +11,7 @@ const sentWarnings: Set = new Set() * @param source A reference object to include alongside the message, e.g. `this`. */ export function warnDeprecated(message: string, source?: object): void { - if (!LiteGraph.alwaysRepeatWarnings) { + if (!litegraph().alwaysRepeatWarnings) { // Do not repeat if (sentWarnings.has(message)) return @@ -21,7 +21,7 @@ export function warnDeprecated(message: string, source?: object): void { sentWarnings.add(message) } - for (const callback of LiteGraph.onDeprecationWarning) { + for (const callback of litegraph().onDeprecationWarning) { callback(message, source) } } diff --git a/src/lib/litegraph/src/utils/linkColors.ts b/src/lib/litegraph/src/utils/linkColors.ts index e6e966133d6..b2f745d5753 100644 --- a/src/lib/litegraph/src/utils/linkColors.ts +++ b/src/lib/litegraph/src/utils/linkColors.ts @@ -1,5 +1,5 @@ import type { CanvasColour, ISlotType } from '../interfaces' -import { LiteGraph } from '../litegraph' +import { litegraph } from '../litegraphInstance' /** * Resolve the colour used while rendering or previewing a connection of a given slot type. @@ -7,7 +7,7 @@ import { LiteGraph } from '../litegraph' export function resolveConnectingLinkColor( type: ISlotType | undefined ): CanvasColour { - return type === LiteGraph.EVENT - ? LiteGraph.EVENT_LINK_COLOR - : LiteGraph.CONNECTING_LINK_COLOR + return type === litegraph().EVENT + ? litegraph().EVENT_LINK_COLOR + : litegraph().CONNECTING_LINK_COLOR } diff --git a/src/lib/litegraph/src/widgets/ComboWidget.ts b/src/lib/litegraph/src/widgets/ComboWidget.ts index 8d16ea2ba73..613f653cd97 100644 --- a/src/lib/litegraph/src/widgets/ComboWidget.ts +++ b/src/lib/litegraph/src/widgets/ComboWidget.ts @@ -2,7 +2,7 @@ import { clamp } from 'es-toolkit/compat' import type { IContextMenuValue } from '@/lib/litegraph/src/types/contextMenu' import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' -import { LiteGraph } from '@/lib/litegraph/src/litegraph' +import { litegraph } from '@/lib/litegraph/src/litegraphInstance' import type { ComboWidgetValues, IComboWidget, @@ -169,7 +169,7 @@ export class ComboWidget } } } - const menu = new LiteGraph.ContextMenu([], menuOptions) + const menu = new (litegraph().ContextMenu)([], menuOptions) const getOptionLabel = this.options.getOptionLabel for (const value of values_list) { @@ -187,7 +187,7 @@ export class ComboWidget // Show dropdown menu when user clicks on widget label const text_values = values != values_list ? Object.values(values) : values - new LiteGraph.ContextMenu(text_values, { + new (litegraph().ContextMenu)(text_values, { scale: Math.max(1, canvas.ds.scale), event: e, className: 'dark', diff --git a/src/lib/litegraph/src/widgets/LegacyWidget.ts b/src/lib/litegraph/src/widgets/LegacyWidget.ts index 1c48bb3255d..11faf94914f 100644 --- a/src/lib/litegraph/src/widgets/LegacyWidget.ts +++ b/src/lib/litegraph/src/widgets/LegacyWidget.ts @@ -1,5 +1,5 @@ import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' -import { LiteGraph } from '@/lib/litegraph/src/litegraph' +import { litegraph } from '@/lib/litegraph/src/litegraphInstance' import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets' import { BaseWidget } from './BaseWidget' @@ -28,7 +28,7 @@ export class LegacyWidget ctx: CanvasRenderingContext2D, options: DrawWidgetOptions ) { - const H = LiteGraph.NODE_WIDGET_HEIGHT + const H = litegraph().NODE_WIDGET_HEIGHT this.draw?.(ctx, this.node, options.width, this.y, H, !!options.showText) } diff --git a/src/renderer/core/canvas/litegraph/litegraphLinkAdapter.ts b/src/renderer/core/canvas/litegraph/litegraphLinkAdapter.ts index 7ddfc0c7b17..3d0f0d17578 100644 --- a/src/renderer/core/canvas/litegraph/litegraphLinkAdapter.ts +++ b/src/renderer/core/canvas/litegraph/litegraphLinkAdapter.ts @@ -9,7 +9,7 @@ import type { LLink } from '@/lib/litegraph/src/LLink' import type { Reroute } from '@/lib/litegraph/src/Reroute' import type { CanvasColour, Point } from '@/lib/litegraph/src/interfaces' -import { LiteGraph } from '@/lib/litegraph/src/litegraph' +import { litegraph } from '@/lib/litegraph/src/litegraphInstance' import { LinkDirection, LinkMarkerShape, @@ -117,7 +117,7 @@ export class LitegraphLinkAdapter { disabled: context.disabledPattern }, animation: { - time: LiteGraph.getTime() * 0.001 + time: litegraph().getTime() * 0.001 }, scale: context.scale, highlightedIds: new Set(Array.from(context.highlightedLinks).map(String)) diff --git a/src/renderer/core/canvas/litegraph/slotCalculations.test.ts b/src/renderer/core/canvas/litegraph/slotCalculations.test.ts index 969aedf10d3..55c4d14202d 100644 --- a/src/renderer/core/canvas/litegraph/slotCalculations.test.ts +++ b/src/renderer/core/canvas/litegraph/slotCalculations.test.ts @@ -1,17 +1,7 @@ import { fromPartial } from '@total-typescript/shoehorn' -import { beforeEach, describe, expect, it, vi } from 'vitest' - -const mockLiteGraph = vi.hoisted(() => ({ - NODE_TITLE_HEIGHT: 30, - NODE_SLOT_HEIGHT: 20, - NODE_COLLAPSED_WIDTH: 80, - vueNodesMode: false -})) - -vi.mock(import('@/lib/litegraph/src/litegraph'), () => ({ - LiteGraph: mockLiteGraph -})) +import { beforeEach, describe, expect, it } from 'vitest' +import { LiteGraph } from '@/lib/litegraph/src/litegraph' import type { LGraph } from '@/lib/litegraph/src/LGraph' import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' import type { @@ -31,8 +21,15 @@ import { } from './slotCalculations' import type { SlotPositionContext } from './slotCalculations' -const SLOT_HEIGHT = mockLiteGraph.NODE_SLOT_HEIGHT -const TITLE_HEIGHT = mockLiteGraph.NODE_TITLE_HEIGHT +const SLOT_HEIGHT = 20 +const TITLE_HEIGHT = 30 + +beforeEach(() => { + const previousMode = LiteGraph.vueNodesMode + return () => { + LiteGraph.vueNodesMode = previousMode + } +}) function makeContext( overrides: Partial = {} @@ -79,7 +76,7 @@ function makeNode( flags: { collapsed: overrides.collapsed ?? false }, title_mode: overrides.titleMode ?? TitleMode.NORMAL_TITLE, type: overrides.type ?? 'TestNode', - _collapsed_width: mockLiteGraph.NODE_COLLAPSED_WIDTH, + _collapsed_width: 80, constructor: { slot_start_y: undefined }, inputs: overrides.inputs ?? [], outputs: overrides.outputs ?? [], @@ -180,7 +177,7 @@ describe('calculateInputSlotPosFromSlot', () => { describe('getSlotPosition — legacy fallback (vueNodesMode disabled)', () => { beforeEach(() => { - mockLiteGraph.vueNodesMode = false + LiteGraph.vueNodesMode = false }) it('calculates input slot position from node.pos', () => { @@ -211,7 +208,7 @@ describe('getSlotPosition — legacy fallback (vueNodesMode disabled)', () => { const output = makeOutput() const node = makeNode({ outputs: [output], collapsed: true }) const [x, y] = getSlotPosition(node, 0, false) - expect(x).toBe(100 + mockLiteGraph.NODE_COLLAPSED_WIDTH) + expect(x).toBe(180) expect(y).toBe(200 - TITLE_HEIGHT * 0.5) }) @@ -225,7 +222,7 @@ describe('getSlotPosition — legacy fallback (vueNodesMode disabled)', () => { describe('Vue slot geometry', () => { beforeEach(() => { - mockLiteGraph.vueNodesMode = true + LiteGraph.vueNodesMode = true layoutStore.resetForTests() }) diff --git a/src/renderer/core/canvas/litegraph/slotCalculations.ts b/src/renderer/core/canvas/litegraph/slotCalculations.ts index 7bf77fbb6fc..8232a4fcf3b 100644 --- a/src/renderer/core/canvas/litegraph/slotCalculations.ts +++ b/src/renderer/core/canvas/litegraph/slotCalculations.ts @@ -12,7 +12,7 @@ import type { INodeInputSlot, INodeOutputSlot } from '@/lib/litegraph/src/types/slots' -import { LiteGraph } from '@/lib/litegraph/src/litegraph' +import { litegraph } from '@/lib/litegraph/src/litegraphInstance' import { isWidgetInputSlot } from '@/lib/litegraph/src/node/slotUtils' import { TitleMode } from '@/lib/litegraph/src/types/globalEnums' import { nodesInRenderOrder } from '@/renderer/core/canvas/litegraph/arrangeForLegacyRender' @@ -76,7 +76,7 @@ export function calculateInputSlotPosFromSlot( // Handle collapsed nodes if (collapsed) { - const halfTitle = LiteGraph.NODE_TITLE_HEIGHT * 0.5 + const halfTitle = litegraph().NODE_TITLE_HEIGHT * 0.5 return [nodeX, nodeY - halfTitle] } @@ -85,7 +85,7 @@ export function calculateInputSlotPosFromSlot( if (pos) return [nodeX + pos[0], nodeY + pos[1]] // Default vertical slots - const offsetX = LiteGraph.NODE_SLOT_HEIGHT * 0.5 + const offsetX = litegraph().NODE_SLOT_HEIGHT * 0.5 const nodeOffsetY = context.slotStartY || 0 let slotIndex = -1 const inputIndex = context.inputs.indexOf(input) @@ -99,7 +99,7 @@ export function calculateInputSlotPosFromSlot( } } } - const slotY = (slotIndex + 0.7) * LiteGraph.NODE_SLOT_HEIGHT + const slotY = (slotIndex + 0.7) * litegraph().NODE_SLOT_HEIGHT return [nodeX + offsetX, nodeY + slotY + nodeOffsetY] } @@ -119,8 +119,8 @@ function calculateOutputSlotPos( // Handle collapsed nodes if (collapsed) { - const width = collapsedWidth || LiteGraph.NODE_COLLAPSED_WIDTH - const halfTitle = LiteGraph.NODE_TITLE_HEIGHT * 0.5 + const width = collapsedWidth || litegraph().NODE_COLLAPSED_WIDTH + const halfTitle = litegraph().NODE_TITLE_HEIGHT * 0.5 return [nodeX + width, nodeY - halfTitle] } @@ -132,11 +132,11 @@ function calculateOutputSlotPos( if (outputPos) return [nodeX + outputPos[0], nodeY + outputPos[1]] // Default vertical slots - const offsetX = LiteGraph.NODE_SLOT_HEIGHT * 0.5 + const offsetX = litegraph().NODE_SLOT_HEIGHT * 0.5 const nodeOffsetY = context.slotStartY || 0 const defaultVerticalOutputs = getDefaultVerticalOutputs(context) const slotIndex = defaultVerticalOutputs.indexOf(outputSlot) - const slotY = (slotIndex + 0.7) * LiteGraph.NODE_SLOT_HEIGHT + const slotY = (slotIndex + 0.7) * litegraph().NODE_SLOT_HEIGHT // TODO: Why +1? return [nodeX + nodeWidth + 1 - offsetX, nodeY + slotY + nodeOffsetY] @@ -154,7 +154,7 @@ export function getSlotPosition( slotIndex: number, isInput: boolean ): Point { - if (LiteGraph.vueNodesMode) + if (litegraph().vueNodesMode) return getVueSlotPosition(node, slotIndex, isInput) const context: SlotPositionContext = { @@ -185,7 +185,7 @@ function getVueSlotPosition( if (offset) return [nodeX + offset.x, nodeY + offset.y] const nodeWidth = node.flags.collapsed - ? (node._collapsed_width ?? LiteGraph.NODE_COLLAPSED_WIDTH) + ? (node._collapsed_width ?? litegraph().NODE_COLLAPSED_WIDTH) : node.renderingSize[0] return calculateVueSlotPosition( node, @@ -223,7 +223,7 @@ function calculateVueSlotPosition( if (node.flags.collapsed) { return [ isInput ? nodeX : nodeX + nodeWidth, - nodeY - LiteGraph.NODE_TITLE_HEIGHT * 0.5 + nodeY - litegraph().NODE_TITLE_HEIGHT * 0.5 ] } @@ -265,7 +265,7 @@ function getWidgetSlotY( const widget = input._widget ?? node.widgets?.find((candidate) => candidate.name === input.widget.name) - return widget && widget.y + LiteGraph.NODE_SLOT_HEIGHT * 0.5 + return widget && widget.y + litegraph().NODE_SLOT_HEIGHT * 0.5 } function calculateVueOutputSlotPosition( @@ -288,13 +288,13 @@ function calculateVueOutputSlotPosition( function getVueSlotY(node: LGraphNode, slotIndex: number): number { return ( (slotIndex + (node.type === 'Reroute' ? 0.5 : 0.7)) * - LiteGraph.NODE_SLOT_HEIGHT + litegraph().NODE_SLOT_HEIGHT ) } function getVueNodeContentY(node: LGraphNode, nodeY: number): number { return node.title_mode === TitleMode.NO_TITLE - ? nodeY - LiteGraph.NODE_TITLE_HEIGHT + ? nodeY - litegraph().NODE_TITLE_HEIGHT : nodeY } @@ -320,7 +320,7 @@ function createSlotLayout( isInput: boolean, [x, y]: Point ): SlotLayout { - const size = LiteGraph.NODE_SLOT_HEIGHT + const size = litegraph().NODE_SLOT_HEIGHT const half = size * 0.5 return { nodeId: node.id, From deeaa683c136759810cbe706a4b0296191e116ef Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Sun, 11 Oct 2026 08:23:19 +0000 Subject: [PATCH 02/16] refactor: remove core imports of the litegraph barrel --- .fallow-baselines/dead-code.json | 32 +++++++++---------- src/lib/litegraph/src/LGraph.ts | 3 +- src/lib/litegraph/src/LGraphCanvas.ts | 2 +- src/lib/litegraph/src/LGraphGroup.ts | 3 +- src/lib/litegraph/src/LGraphNode.ts | 3 +- src/lib/litegraph/src/litegraphInstance.ts | 2 ++ src/lib/litegraph/src/node/NodeInputSlot.ts | 2 +- src/lib/litegraph/src/node/NodeOutputSlot.ts | 2 +- src/lib/litegraph/src/node/NodeSlot.ts | 3 +- .../src/subgraph/SubgraphIONodeBase.ts | 2 +- .../litegraph/src/subgraph/SubgraphInput.ts | 2 +- .../litegraph/src/subgraph/SubgraphNode.ts | 2 +- .../litegraph/src/subgraph/SubgraphOutput.ts | 2 +- .../src/subgraph/SubgraphSlotBase.ts | 2 +- .../litegraph/src/subgraph/subgraphUtils.ts | 3 +- .../litegraph/src/subgraph/unpackSubgraph.ts | 2 +- .../core/canvas/litegraph/selectionAdapter.ts | 10 +++--- 17 files changed, 41 insertions(+), 36 deletions(-) diff --git a/.fallow-baselines/dead-code.json b/.fallow-baselines/dead-code.json index 77543917784..99b3a1691b8 100644 --- a/.fallow-baselines/dead-code.json +++ b/.fallow-baselines/dead-code.json @@ -27,25 +27,25 @@ "src/composables/sidebarTabs/useJobHistorySidebarTab.ts->src/stores/workspace/sidebarTabStore.ts", "src/composables/usePaste.ts->src/scripts/app.ts", "src/extensions/core/load3d/Load3dUtils.ts->src/scripts/app.ts", - "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphCanvas.ts->src/lib/litegraph/src/litegraph.ts", - "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphGroup.ts->src/lib/litegraph/src/litegraph.ts", - "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/litegraph.ts", - "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/litegraph.ts", - "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LiteGraphGlobal.ts->src/lib/litegraph/src/litegraph.ts", - "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/litegraph.ts->src/lib/litegraph/src/subgraph/Subgraph.ts", - "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/litegraph.ts->src/lib/litegraph/src/subgraph/SubgraphInput.ts", - "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/litegraph.ts->src/lib/litegraph/src/subgraph/SubgraphOutput.ts", - "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/litegraph.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", + "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphCanvas.ts->src/lib/litegraph/src/LGraphNode.ts", + "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphCanvas.ts->src/renderer/core/canvas/litegraph/selectionAdapter.ts", + "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphGroup.ts->src/lib/litegraph/src/LGraphNode.ts", + "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphNode.ts", + "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/subgraph/SubgraphNode.ts", + "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", + "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/subgraph/unpackSubgraph.ts", + "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/utils/collections.ts", "src/lib/litegraph/src/LGraphCanvas.ts->src/lib/litegraph/src/LGraphGroup.ts", + "src/lib/litegraph/src/LGraphCanvas.ts->src/lib/litegraph/src/LGraphGroup.ts->src/lib/litegraph/src/LGraphNode.ts", "src/lib/litegraph/src/LGraphCanvas.ts->src/lib/litegraph/src/LGraphNode.ts", - "src/lib/litegraph/src/LGraphCanvas.ts->src/lib/litegraph/src/litegraph.ts", - "src/lib/litegraph/src/LGraphGroup.ts->src/lib/litegraph/src/litegraph.ts", - "src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/litegraph.ts", + "src/lib/litegraph/src/LGraphCanvas.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/subgraph/SubgraphNode.ts", + "src/lib/litegraph/src/LGraphCanvas.ts->src/lib/litegraph/src/LGraphGroup.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", + "src/lib/litegraph/src/LGraphCanvas.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", + "src/lib/litegraph/src/LGraphCanvas.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/utils/collections.ts", + "src/lib/litegraph/src/LGraphCanvas.ts->src/lib/litegraph/src/LGraphGroup.ts->src/renderer/core/canvas/litegraph/selectionAdapter.ts", + "src/lib/litegraph/src/LGraphCanvas.ts->src/lib/litegraph/src/LGraphNode.ts->src/renderer/core/canvas/litegraph/selectionAdapter.ts", + "src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/node/NodeInputSlot.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", "src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/utils/collections.ts", - "src/lib/litegraph/src/litegraph.ts->src/lib/litegraph/src/node/NodeInputSlot.ts", - "src/lib/litegraph/src/litegraph.ts->src/lib/litegraph/src/node/NodeOutputSlot.ts", - "src/lib/litegraph/src/litegraph.ts->src/lib/litegraph/src/subgraph/SubgraphNode.ts", - "src/lib/litegraph/src/litegraph.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", "src/lib/litegraph/src/node/NodeInputSlot.ts->src/lib/litegraph/src/node/NodeSlot.ts", "src/platform/cloud/subscription/composables/useSubscriptionDialog.ts->src/services/dialogService.ts", "src/platform/missingMedia/missingMediaStore.ts->src/scripts/app.ts", diff --git a/src/lib/litegraph/src/LGraph.ts b/src/lib/litegraph/src/LGraph.ts index 27b708d1fc4..56c15d74092 100644 --- a/src/lib/litegraph/src/LGraph.ts +++ b/src/lib/litegraph/src/LGraph.ts @@ -145,7 +145,8 @@ import type { } from './interfaces' import type { INodeInputSlot, INodeOutputSlot } from './types/slots' import type { LinkNetwork } from './types/linkNetwork' -import { LiteGraph, SubgraphNode } from './litegraph' +import { LiteGraph } from './litegraphInstance' +import { SubgraphNode } from './subgraph/SubgraphNode' import { alignOutsideContainer, alignToContainer, diff --git a/src/lib/litegraph/src/LGraphCanvas.ts b/src/lib/litegraph/src/LGraphCanvas.ts index bae87bd2990..4593f70a14f 100644 --- a/src/lib/litegraph/src/LGraphCanvas.ts +++ b/src/lib/litegraph/src/LGraphCanvas.ts @@ -144,7 +144,7 @@ import type { PanelWidgetCallback, PanelWidgetOptions } from './types/panel' -import { LiteGraph } from './litegraph' +import { LiteGraph } from './litegraphInstance' import { containsRect, createBounds, diff --git a/src/lib/litegraph/src/LGraphGroup.ts b/src/lib/litegraph/src/LGraphGroup.ts index 680dbcc6c11..cc8611c6008 100644 --- a/src/lib/litegraph/src/LGraphGroup.ts +++ b/src/lib/litegraph/src/LGraphGroup.ts @@ -24,7 +24,8 @@ import type { Size } from './interfaces' import type { IContextMenuValue } from './types/contextMenu' -import { LiteGraph, Rectangle } from './litegraph' +import { LiteGraph } from './litegraphInstance' +import { Rectangle } from './infrastructure/Rectangle' import { containsCentre, containsRect, diff --git a/src/lib/litegraph/src/LGraphNode.ts b/src/lib/litegraph/src/LGraphNode.ts index 04a6099f663..065b5d92875 100644 --- a/src/lib/litegraph/src/LGraphNode.ts +++ b/src/lib/litegraph/src/LGraphNode.ts @@ -120,7 +120,8 @@ import type { INodeSlotContextItem } from './types/slots' import type { Panel } from './types/panel' -import { LiteGraph, Subgraph } from './litegraph' +import { LiteGraph } from './litegraphInstance' +import { Subgraph } from './LGraph' import type { LGraphNodeConstructor, SubgraphNode } from './litegraph' import { createBounds, diff --git a/src/lib/litegraph/src/litegraphInstance.ts b/src/lib/litegraph/src/litegraphInstance.ts index 11f3cbc2143..88d74fb86a4 100644 --- a/src/lib/litegraph/src/litegraphInstance.ts +++ b/src/lib/litegraph/src/litegraphInstance.ts @@ -17,9 +17,11 @@ declare global { * The barrel constructs the singleton and calls {@link registerLiteGraphInstance}. */ let instance: LiteGraphGlobal | null = null +export let LiteGraph: LiteGraphGlobal export function registerLiteGraphInstance(value: LiteGraphGlobal): void { instance = value + LiteGraph = value globalThis.__COMFY_LITEGRAPH_INSTANCE__ = value } diff --git a/src/lib/litegraph/src/node/NodeInputSlot.ts b/src/lib/litegraph/src/node/NodeInputSlot.ts index af0e58c3c05..54c27e942a7 100644 --- a/src/lib/litegraph/src/node/NodeInputSlot.ts +++ b/src/lib/litegraph/src/node/NodeInputSlot.ts @@ -6,7 +6,7 @@ import type { INodeInputSlot, INodeOutputSlot } from '@/lib/litegraph/src/types/slots' -import { LiteGraph } from '@/lib/litegraph/src/litegraph' +import { LiteGraph } from '@/lib/litegraph/src/litegraphInstance' import { NodeSlot } from '@/lib/litegraph/src/node/NodeSlot' import { inputHasLink, inputLink } from '@/lib/litegraph/src/node/slotLinks' import { warnDeprecated } from '@/lib/litegraph/src/utils/feedback' diff --git a/src/lib/litegraph/src/node/NodeOutputSlot.ts b/src/lib/litegraph/src/node/NodeOutputSlot.ts index 23dfdb4a608..8892d2a8d56 100644 --- a/src/lib/litegraph/src/node/NodeOutputSlot.ts +++ b/src/lib/litegraph/src/node/NodeOutputSlot.ts @@ -6,7 +6,7 @@ import type { INodeInputSlot, INodeOutputSlot } from '@/lib/litegraph/src/types/slots' -import { LiteGraph } from '@/lib/litegraph/src/litegraph' +import { LiteGraph } from '@/lib/litegraph/src/litegraphInstance' import { createArrayMutationView } from '@/lib/litegraph/src/infrastructure/createMutationView' import { NodeSlot } from '@/lib/litegraph/src/node/NodeSlot' import type { IDrawOptions } from '@/lib/litegraph/src/node/NodeSlot' diff --git a/src/lib/litegraph/src/node/NodeSlot.ts b/src/lib/litegraph/src/node/NodeSlot.ts index 1400099ef01..6ea8556577b 100644 --- a/src/lib/litegraph/src/node/NodeSlot.ts +++ b/src/lib/litegraph/src/node/NodeSlot.ts @@ -15,7 +15,8 @@ import type { INodeOutputSlot, ISubgraphInput } from '@/lib/litegraph/src/types/slots' -import { LiteGraph, Rectangle } from '@/lib/litegraph/src/litegraph' +import { LiteGraph } from '@/lib/litegraph/src/litegraphInstance' +import { Rectangle } from '@/lib/litegraph/src/infrastructure/Rectangle' import { getCentre } from '@/lib/litegraph/src/measure' import type { SubgraphInput } from '@/lib/litegraph/src/subgraph/SubgraphInput' import type { SubgraphOutput } from '@/lib/litegraph/src/subgraph/SubgraphOutput' diff --git a/src/lib/litegraph/src/subgraph/SubgraphIONodeBase.ts b/src/lib/litegraph/src/subgraph/SubgraphIONodeBase.ts index 95eb6ff2851..1d4ef724338 100644 --- a/src/lib/litegraph/src/subgraph/SubgraphIONodeBase.ts +++ b/src/lib/litegraph/src/subgraph/SubgraphIONodeBase.ts @@ -15,7 +15,7 @@ import type { INodeInputSlot, INodeOutputSlot } from '@/lib/litegraph/src/types/slots' -import { LiteGraph } from '@/lib/litegraph/src/litegraph' +import { LiteGraph } from '@/lib/litegraph/src/litegraphInstance' import type { CanvasColour, CanvasPointer, diff --git a/src/lib/litegraph/src/subgraph/SubgraphInput.ts b/src/lib/litegraph/src/subgraph/SubgraphInput.ts index 2b8974aae09..c10ba575e45 100644 --- a/src/lib/litegraph/src/subgraph/SubgraphInput.ts +++ b/src/lib/litegraph/src/subgraph/SubgraphInput.ts @@ -11,7 +11,7 @@ import type { INodeInputSlot, INodeOutputSlot } from '@/lib/litegraph/src/types/slots' -import { LiteGraph } from '@/lib/litegraph/src/litegraph' +import { LiteGraph } from '@/lib/litegraph/src/litegraphInstance' import { NodeSlotType } from '@/lib/litegraph/src/types/globalEnums' import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets' diff --git a/src/lib/litegraph/src/subgraph/SubgraphNode.ts b/src/lib/litegraph/src/subgraph/SubgraphNode.ts index 37ee451cf6c..e3913f7eb3b 100644 --- a/src/lib/litegraph/src/subgraph/SubgraphNode.ts +++ b/src/lib/litegraph/src/subgraph/SubgraphNode.ts @@ -10,7 +10,7 @@ import { NullGraphError } from '@/lib/litegraph/src/infrastructure/NullGraphErro import { RecursionError } from '@/lib/litegraph/src/infrastructure/RecursionError' import type { IWidgetLocator } from '@/lib/litegraph/src/interfaces' import type { ISubgraphInput } from '@/lib/litegraph/src/types/slots' -import { LiteGraph } from '@/lib/litegraph/src/litegraph' +import { LiteGraph } from '@/lib/litegraph/src/litegraphInstance' import type { INodeInputSlot, ISlotType } from '@/lib/litegraph/src/litegraph' import { NodeInputSlot } from '@/lib/litegraph/src/node/NodeInputSlot' import { NodeOutputSlot } from '@/lib/litegraph/src/node/NodeOutputSlot' diff --git a/src/lib/litegraph/src/subgraph/SubgraphOutput.ts b/src/lib/litegraph/src/subgraph/SubgraphOutput.ts index d0691b0ab87..52224defa88 100644 --- a/src/lib/litegraph/src/subgraph/SubgraphOutput.ts +++ b/src/lib/litegraph/src/subgraph/SubgraphOutput.ts @@ -8,7 +8,7 @@ import type { INodeInputSlot, INodeOutputSlot } from '@/lib/litegraph/src/types/slots' -import { LiteGraph } from '@/lib/litegraph/src/litegraph' +import { LiteGraph } from '@/lib/litegraph/src/litegraphInstance' import { NodeSlotType } from '@/lib/litegraph/src/types/globalEnums' import type { SubgraphInput } from './SubgraphInput' diff --git a/src/lib/litegraph/src/subgraph/SubgraphSlotBase.ts b/src/lib/litegraph/src/subgraph/SubgraphSlotBase.ts index d79aa964562..aeda99ad134 100644 --- a/src/lib/litegraph/src/subgraph/SubgraphSlotBase.ts +++ b/src/lib/litegraph/src/subgraph/SubgraphSlotBase.ts @@ -15,7 +15,7 @@ import type { INodeInputSlot, INodeOutputSlot } from '@/lib/litegraph/src/types/slots' -import { LiteGraph } from '@/lib/litegraph/src/litegraph' +import { LiteGraph } from '@/lib/litegraph/src/litegraphInstance' import { SlotBase } from '@/lib/litegraph/src/node/SlotBase' import type { CanvasPointerEvent, diff --git a/src/lib/litegraph/src/subgraph/subgraphUtils.ts b/src/lib/litegraph/src/subgraph/subgraphUtils.ts index e405ca6ebf6..d26eca6c5c4 100644 --- a/src/lib/litegraph/src/subgraph/subgraphUtils.ts +++ b/src/lib/litegraph/src/subgraph/subgraphUtils.ts @@ -22,7 +22,8 @@ import type { INodeInputSlot, INodeOutputSlot } from '@/lib/litegraph/src/types/slots' -import { LiteGraph, createUuidv4 } from '@/lib/litegraph/src/litegraph' +import { LiteGraph } from '@/lib/litegraph/src/litegraphInstance' +import { createUuidv4 } from '@/utils/uuid' import { nextUniqueName } from '@/lib/litegraph/src/strings' import { UNASSIGNED_NODE_ID } from '@/types/nodeId' import type { diff --git a/src/lib/litegraph/src/subgraph/unpackSubgraph.ts b/src/lib/litegraph/src/subgraph/unpackSubgraph.ts index 535e41469e5..df3f0a35713 100644 --- a/src/lib/litegraph/src/subgraph/unpackSubgraph.ts +++ b/src/lib/litegraph/src/subgraph/unpackSubgraph.ts @@ -7,7 +7,7 @@ import type { Point } from '../interfaces' import type { INodeInputSlot } from '../types/slots' import type { LGraph } from '../LGraph' import { LGraphNode } from '../LGraphNode' -import { LiteGraph } from '../litegraph' +import { LiteGraph } from '../litegraphInstance' import type { ISerialisedNode } from '../types/serialisation' export type UnpackedTargetInput = diff --git a/src/renderer/core/canvas/litegraph/selectionAdapter.ts b/src/renderer/core/canvas/litegraph/selectionAdapter.ts index 70aefa35c7c..390952dde07 100644 --- a/src/renderer/core/canvas/litegraph/selectionAdapter.ts +++ b/src/renderer/core/canvas/litegraph/selectionAdapter.ts @@ -9,12 +9,10 @@ import { import type { LGraph } from '@/lib/litegraph/src/LGraph' import type { LGraphCanvas } from '@/lib/litegraph/src/LGraphCanvas' import type { Positionable } from '@/lib/litegraph/src/interfaces' -import { - LGraphGroup, - LGraphNode, - Reroute, - Subgraph -} from '@/lib/litegraph/src/litegraph' +import { LGraphGroup } from '@/lib/litegraph/src/LGraphGroup' +import { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import { Reroute } from '@/lib/litegraph/src/Reroute' +import { Subgraph } from '@/lib/litegraph/src/LGraph' import { SubgraphIONodeBase } from '@/lib/litegraph/src/subgraph/SubgraphIONodeBase' import type { SubgraphInputNode } from '@/lib/litegraph/src/subgraph/SubgraphInputNode' import type { SubgraphOutputNode } from '@/lib/litegraph/src/subgraph/SubgraphOutputNode' From e6604167c57a128eb5851f2ae4b6ee3e65c416d2 Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Sun, 11 Oct 2026 08:30:50 +0000 Subject: [PATCH 03/16] refactor: decouple litegraph entities from canvas initialization --- .fallow-baselines/dead-code.json | 22 ++++++------ src/lib/litegraph/src/LGraph.ts | 5 +-- src/lib/litegraph/src/LGraphCanvas.ts | 3 ++ src/lib/litegraph/src/LGraphGroup.ts | 15 ++++---- src/lib/litegraph/src/LGraphNode.ts | 7 ++-- .../litegraph/src/canvas/canvasClassAccess.ts | 34 +++++++++++++++++++ .../src/subgraph/SubgraphSlotBase.ts | 4 +-- 7 files changed, 65 insertions(+), 25 deletions(-) create mode 100644 src/lib/litegraph/src/canvas/canvasClassAccess.ts diff --git a/.fallow-baselines/dead-code.json b/.fallow-baselines/dead-code.json index 99b3a1691b8..a1f6d239535 100644 --- a/.fallow-baselines/dead-code.json +++ b/.fallow-baselines/dead-code.json @@ -27,26 +27,26 @@ "src/composables/sidebarTabs/useJobHistorySidebarTab.ts->src/stores/workspace/sidebarTabStore.ts", "src/composables/usePaste.ts->src/scripts/app.ts", "src/extensions/core/load3d/Load3dUtils.ts->src/scripts/app.ts", - "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphCanvas.ts->src/lib/litegraph/src/LGraphNode.ts", - "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphCanvas.ts->src/renderer/core/canvas/litegraph/selectionAdapter.ts", "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphGroup.ts->src/lib/litegraph/src/LGraphNode.ts", "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphNode.ts", + "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/subgraph/SubgraphInput.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", + "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/subgraph/SubgraphInputNode.ts->src/lib/litegraph/src/utils/collections.ts", "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/subgraph/SubgraphNode.ts", + "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/subgraph/SubgraphOutput.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", + "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/subgraph/SubgraphOutputNode.ts->src/lib/litegraph/src/utils/collections.ts", + "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphGroup.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/subgraph/unpackSubgraph.ts", "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/utils/collections.ts", - "src/lib/litegraph/src/LGraphCanvas.ts->src/lib/litegraph/src/LGraphGroup.ts", - "src/lib/litegraph/src/LGraphCanvas.ts->src/lib/litegraph/src/LGraphGroup.ts->src/lib/litegraph/src/LGraphNode.ts", - "src/lib/litegraph/src/LGraphCanvas.ts->src/lib/litegraph/src/LGraphNode.ts", - "src/lib/litegraph/src/LGraphCanvas.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/subgraph/SubgraphNode.ts", - "src/lib/litegraph/src/LGraphCanvas.ts->src/lib/litegraph/src/LGraphGroup.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", - "src/lib/litegraph/src/LGraphCanvas.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", - "src/lib/litegraph/src/LGraphCanvas.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/utils/collections.ts", - "src/lib/litegraph/src/LGraphCanvas.ts->src/lib/litegraph/src/LGraphGroup.ts->src/renderer/core/canvas/litegraph/selectionAdapter.ts", - "src/lib/litegraph/src/LGraphCanvas.ts->src/lib/litegraph/src/LGraphNode.ts->src/renderer/core/canvas/litegraph/selectionAdapter.ts", + "src/lib/litegraph/src/LGraphGroup.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/node/NodeInputSlot.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", + "src/lib/litegraph/src/LGraphGroup.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/node/NodeOutputSlot.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", "src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/node/NodeInputSlot.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", + "src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/node/NodeOutputSlot.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", + "src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/node/NodeInputSlot.ts->src/lib/litegraph/src/node/slotDescriptorView.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", + "src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/node/NodeOutputSlot.ts->src/lib/litegraph/src/node/slotDescriptorView.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", "src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/utils/collections.ts", "src/lib/litegraph/src/node/NodeInputSlot.ts->src/lib/litegraph/src/node/NodeSlot.ts", + "src/lib/litegraph/src/subgraph/EmptySubgraphInput.ts->src/lib/litegraph/src/subgraph/SubgraphInput.ts->src/lib/litegraph/src/subgraph/SubgraphInputNode.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", "src/platform/cloud/subscription/composables/useSubscriptionDialog.ts->src/services/dialogService.ts", "src/platform/missingMedia/missingMediaStore.ts->src/scripts/app.ts", "src/platform/missingModel/missingModelStore.ts->src/scripts/app.ts", diff --git a/src/lib/litegraph/src/LGraph.ts b/src/lib/litegraph/src/LGraph.ts index 56c15d74092..3c6a8dbe93b 100644 --- a/src/lib/litegraph/src/LGraph.ts +++ b/src/lib/litegraph/src/LGraph.ts @@ -108,7 +108,8 @@ import { } from './utils/namedValuesShadowDiffTelemetry' import type { DragAndScaleState } from './DragAndScale' -import { LGraphCanvas } from './LGraphCanvas' +import type { LGraphCanvas } from './LGraphCanvas' +import { canvasClass } from './canvas/canvasClassAccess' import { Rectangle } from './infrastructure/Rectangle' import { LGraphGroup } from './LGraphGroup' import { LGraphNode } from './LGraphNode' @@ -941,7 +942,7 @@ export class LGraph * Attach Canvas to this graph */ attachCanvas(canvas: LGraphCanvas): void { - if (!(canvas instanceof LGraphCanvas)) { + if (!(canvas instanceof canvasClass)) { throw new TypeError('attachCanvas expects an LGraphCanvas instance') } diff --git a/src/lib/litegraph/src/LGraphCanvas.ts b/src/lib/litegraph/src/LGraphCanvas.ts index 4593f70a14f..511e691b364 100644 --- a/src/lib/litegraph/src/LGraphCanvas.ts +++ b/src/lib/litegraph/src/LGraphCanvas.ts @@ -1,6 +1,7 @@ import { default as DOMPurify } from 'dompurify' import { cloneDeep, toString } from 'es-toolkit/compat' import { toValue } from 'vue' +import { provideCanvasClass } from './canvas/canvasClassAccess' import { isMiddleButtonEvent } from '@/base/pointerUtils' import { transferLinkPresentation } from '@/core/graph/transferLinkPresentation' @@ -9111,3 +9112,5 @@ defineDeprecatedProperty( 'applyNodePositions', 'LGraphCanvas.repositionNodesVueMode is deprecated. Use applyNodePositions instead.' ) + +provideCanvasClass(LGraphCanvas) diff --git a/src/lib/litegraph/src/LGraphGroup.ts b/src/lib/litegraph/src/LGraphGroup.ts index cc8611c6008..973fd95d967 100644 --- a/src/lib/litegraph/src/LGraphGroup.ts +++ b/src/lib/litegraph/src/LGraphGroup.ts @@ -10,7 +10,8 @@ import { toGroupId } from '@/types/groupId' import { hexToRgb, luminance, readableTextColor } from '@/utils/colorUtil' import type { LGraph } from './LGraph' -import { LGraphCanvas } from './LGraphCanvas' +import type { LGraphCanvas } from './LGraphCanvas' +import { canvasClass } from './canvas/canvasClassAccess' import { LGraphNode } from './LGraphNode' import { strokeShape } from './draw' import { createMutationView } from './infrastructure/createMutationView' @@ -124,7 +125,7 @@ export class LGraphGroup implements Positionable, IPinnable, IColorable { // TODO: Object instantiation pattern requires too much boilerplate and null checking. ID should be passed in via constructor. this.id = toGroupId(id ?? -1) this.title = title || 'Group' - const { pale_blue } = LGraphCanvas.node_colors + const { pale_blue } = canvasClass.node_colors this.color = pale_blue.groupcolor } @@ -140,7 +141,7 @@ export class LGraphGroup implements Positionable, IPinnable, IColorable { /** @inheritdoc {@link IColorable.getColorOption} */ getColorOption(): ColorOption | null { return ( - Object.values(LGraphCanvas.node_colors).find( + Object.values(canvasClass.node_colors).find( (colorOption) => colorOption.groupcolor === this.color ) ?? null ) @@ -460,19 +461,19 @@ export class LGraphGroup implements Positionable, IPinnable, IColorable { } }, null, - { content: 'Title', callback: LGraphCanvas.onShowPropertyEditor }, + { content: 'Title', callback: canvasClass.onShowPropertyEditor }, { content: 'Color', has_submenu: true, - callback: LGraphCanvas.onMenuNodeColors + callback: canvasClass.onMenuNodeColors }, { content: 'Font size', property: 'font_size', - callback: LGraphCanvas.onShowPropertyEditor + callback: canvasClass.onShowPropertyEditor }, null, - { content: 'Remove', callback: LGraphCanvas.onMenuNodeRemove } + { content: 'Remove', callback: canvasClass.onMenuNodeRemove } ] } diff --git a/src/lib/litegraph/src/LGraphNode.ts b/src/lib/litegraph/src/LGraphNode.ts index 065b5d92875..d69d608355e 100644 --- a/src/lib/litegraph/src/LGraphNode.ts +++ b/src/lib/litegraph/src/LGraphNode.ts @@ -56,7 +56,8 @@ import { LGraphBadge } from './LGraphBadge' import { badgeDrawObjects, badgeRows } from './nodeBadgeDraw' import { LGraphButton } from './LGraphButton' import type { LGraphButtonOptions } from './LGraphButton' -import { LGraphCanvas } from './LGraphCanvas' +import type { LGraphCanvas } from './LGraphCanvas' +import { canvasClass } from './canvas/canvasClassAccess' import { realignGroupWidgetChildLinks } from './linkDeduplication' import { LLink, replaceLinkTopology, slotFloatingLinks } from './LLink' import { @@ -660,7 +661,7 @@ export class LGraphNode /** @inheritdoc {@link IColorable.getColorOption} */ getColorOption(): ColorOption | null { return ( - Object.values(LGraphCanvas.node_colors).find( + Object.values(canvasClass.node_colors).find( (colorOption) => colorOption.color === this.color && colorOption.bgcolor === this.bgcolor @@ -2170,7 +2171,7 @@ export class LGraphNode function compute_text_size(text: string | undefined, fontStyle: string) { const value = text ?? '' return ( - LGraphCanvas._measureText?.(value, fontStyle) ?? + canvasClass._measureText?.(value, fontStyle) ?? font_size * value.length * 0.6 ) } diff --git a/src/lib/litegraph/src/canvas/canvasClassAccess.ts b/src/lib/litegraph/src/canvas/canvasClassAccess.ts new file mode 100644 index 00000000000..8bc5fe4a738 --- /dev/null +++ b/src/lib/litegraph/src/canvas/canvasClassAccess.ts @@ -0,0 +1,34 @@ +import type { ContextMenu } from '../ContextMenu' +import type { LGraphNode } from '../LGraphNode' +import type { ColorOption } from '../interfaces' +import type { + IContextMenuOptions, + IContextMenuValue +} from '../types/contextMenu' + +interface CanvasClassAccess { + [Symbol.hasInstance](value: unknown): boolean + node_colors: Record + _measureText?: (text: string, fontStyle?: string) => number + onShowPropertyEditor( + item: { property?: 'title' | 'font_size' }, + options: IContextMenuOptions, + event: MouseEvent, + menu: ContextMenu, + node: { title: string; font_size?: number } + ): void + onMenuNodeColors( + value: IContextMenuValue, + options: IContextMenuOptions, + event: MouseEvent, + menu: ContextMenu, + node: LGraphNode + ): boolean + onMenuNodeRemove(): void +} + +export let canvasClass: CanvasClassAccess + +export function provideCanvasClass(value: CanvasClassAccess): void { + canvasClass = value +} diff --git a/src/lib/litegraph/src/subgraph/SubgraphSlotBase.ts b/src/lib/litegraph/src/subgraph/SubgraphSlotBase.ts index aeda99ad134..6e09b961ebc 100644 --- a/src/lib/litegraph/src/subgraph/SubgraphSlotBase.ts +++ b/src/lib/litegraph/src/subgraph/SubgraphSlotBase.ts @@ -1,4 +1,4 @@ -import { LGraphCanvas } from '@/lib/litegraph/src/LGraphCanvas' +import { canvasClass } from '@/lib/litegraph/src/canvas/canvasClassAccess' import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' import type { LLink, LinkId } from '@/lib/litegraph/src/LLink' import type { RerouteId } from '@/lib/litegraph/src/Reroute' @@ -136,7 +136,7 @@ export abstract class SubgraphSlot } measure(): Readonly { - const width = LGraphCanvas._measureText?.(this.displayName) ?? 0 + const width = canvasClass._measureText?.(this.displayName) ?? 0 const { defaultHeight } = SubgraphSlot this.measurement.setValues(width + defaultHeight, defaultHeight) From 8ed625d04cf86ed550949e2f0e1102128666d5f6 Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Sun, 11 Oct 2026 08:45:44 +0000 Subject: [PATCH 04/16] refactor: remove litegraph class identity import cycles --- .fallow-baselines/dead-code.json | 20 -------- src/lib/litegraph/src/LGraph.ts | 3 ++ src/lib/litegraph/src/LGraphNode.ts | 13 +++-- src/lib/litegraph/src/node/NodeInputSlot.ts | 9 +++- src/lib/litegraph/src/node/NodeOutputSlot.ts | 2 +- src/lib/litegraph/src/node/NodeSlot.ts | 11 ++++- .../litegraph/src/subgraph/SubgraphInput.ts | 2 +- .../src/subgraph/SubgraphInputNode.ts | 12 +++++ .../litegraph/src/subgraph/SubgraphOutput.ts | 2 +- .../src/subgraph/SubgraphOutputNode.ts | 12 +++++ .../src/subgraph/subgraphTypeGuards.ts | 32 ++++++++++++ .../litegraph/src/subgraph/subgraphUtils.ts | 49 +------------------ src/lib/litegraph/src/utils/collections.ts | 10 +++- .../canvas/links/linkDropOrchestrator.test.ts | 3 +- 14 files changed, 95 insertions(+), 85 deletions(-) create mode 100644 src/lib/litegraph/src/subgraph/subgraphTypeGuards.ts diff --git a/.fallow-baselines/dead-code.json b/.fallow-baselines/dead-code.json index a1f6d239535..0aeaef93676 100644 --- a/.fallow-baselines/dead-code.json +++ b/.fallow-baselines/dead-code.json @@ -27,26 +27,6 @@ "src/composables/sidebarTabs/useJobHistorySidebarTab.ts->src/stores/workspace/sidebarTabStore.ts", "src/composables/usePaste.ts->src/scripts/app.ts", "src/extensions/core/load3d/Load3dUtils.ts->src/scripts/app.ts", - "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphGroup.ts->src/lib/litegraph/src/LGraphNode.ts", - "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphNode.ts", - "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/subgraph/SubgraphInput.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", - "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/subgraph/SubgraphInputNode.ts->src/lib/litegraph/src/utils/collections.ts", - "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/subgraph/SubgraphNode.ts", - "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/subgraph/SubgraphOutput.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", - "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/subgraph/SubgraphOutputNode.ts->src/lib/litegraph/src/utils/collections.ts", - "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphGroup.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", - "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", - "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/subgraph/unpackSubgraph.ts", - "src/lib/litegraph/src/LGraph.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/utils/collections.ts", - "src/lib/litegraph/src/LGraphGroup.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/node/NodeInputSlot.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", - "src/lib/litegraph/src/LGraphGroup.ts->src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/node/NodeOutputSlot.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", - "src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/node/NodeInputSlot.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", - "src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/node/NodeOutputSlot.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", - "src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/node/NodeInputSlot.ts->src/lib/litegraph/src/node/slotDescriptorView.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", - "src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/node/NodeOutputSlot.ts->src/lib/litegraph/src/node/slotDescriptorView.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", - "src/lib/litegraph/src/LGraphNode.ts->src/lib/litegraph/src/utils/collections.ts", - "src/lib/litegraph/src/node/NodeInputSlot.ts->src/lib/litegraph/src/node/NodeSlot.ts", - "src/lib/litegraph/src/subgraph/EmptySubgraphInput.ts->src/lib/litegraph/src/subgraph/SubgraphInput.ts->src/lib/litegraph/src/subgraph/SubgraphInputNode.ts->src/lib/litegraph/src/subgraph/subgraphUtils.ts", "src/platform/cloud/subscription/composables/useSubscriptionDialog.ts->src/services/dialogService.ts", "src/platform/missingMedia/missingMediaStore.ts->src/scripts/app.ts", "src/platform/missingModel/missingModelStore.ts->src/scripts/app.ts", diff --git a/src/lib/litegraph/src/LGraph.ts b/src/lib/litegraph/src/LGraph.ts index 3c6a8dbe93b..048c26a2fa7 100644 --- a/src/lib/litegraph/src/LGraph.ts +++ b/src/lib/litegraph/src/LGraph.ts @@ -159,6 +159,7 @@ import { SubgraphInput } from './subgraph/SubgraphInput' import { SubgraphInputNode } from './subgraph/SubgraphInputNode' import { SubgraphOutput } from './subgraph/SubgraphOutput' import { SubgraphOutputNode } from './subgraph/SubgraphOutputNode' +import { provideSubgraphGuard } from './subgraph/subgraphTypeGuards' import { captureUnpackedTargetInput, findUnavailableSubgraphNodeType, @@ -3808,3 +3809,5 @@ export class Subgraph } } } + +provideSubgraphGuard((value): value is Subgraph => value instanceof Subgraph) diff --git a/src/lib/litegraph/src/LGraphNode.ts b/src/lib/litegraph/src/LGraphNode.ts index d69d608355e..d9c13f719c4 100644 --- a/src/lib/litegraph/src/LGraphNode.ts +++ b/src/lib/litegraph/src/LGraphNode.ts @@ -51,7 +51,7 @@ import { } from '@/lib/litegraph/src/constants' import { cachedMeasureText } from '@/lib/litegraph/src/utils/textMeasureCache' import type { DragAndScale } from './DragAndScale' -import type { LGraph } from './LGraph' +import type { LGraph, Subgraph } from './LGraph' import { LGraphBadge } from './LGraphBadge' import { badgeDrawObjects, badgeRows } from './nodeBadgeDraw' import { LGraphButton } from './LGraphButton' @@ -122,7 +122,7 @@ import type { } from './types/slots' import type { Panel } from './types/panel' import { LiteGraph } from './litegraphInstance' -import { Subgraph } from './LGraph' +import { isSubgraph } from './subgraph/subgraphTypeGuards' import type { LGraphNodeConstructor, SubgraphNode } from './litegraph' import { createBounds, @@ -155,7 +155,7 @@ import type { TWidgetType, TWidgetValue } from './types/widgets' -import { findFreeSlotOfType } from './utils/collections' +import { findFreeSlotOfType, provideGraphNodeGuard } from './utils/collections' import { warnDeprecated } from './utils/feedback' import { computeLegacyWidgetShadow, @@ -3442,10 +3442,7 @@ export class LGraphNode } disconnected = true - if ( - link_info.target_id === SUBGRAPH_OUTPUT_ID && - graph instanceof Subgraph - ) { + if (link_info.target_id === SUBGRAPH_OUTPUT_ID && isSubgraph(graph)) { const targetSlot = legacyArrayItem( graph.outputNode.slots, link_info.target_slot @@ -4621,3 +4618,5 @@ export class LGraphNode ctx.fillStyle = originalFillStyle } } + +provideGraphNodeGuard((item): item is LGraphNode => item instanceof LGraphNode) diff --git a/src/lib/litegraph/src/node/NodeInputSlot.ts b/src/lib/litegraph/src/node/NodeInputSlot.ts index 54c27e942a7..d45cf99e2b2 100644 --- a/src/lib/litegraph/src/node/NodeInputSlot.ts +++ b/src/lib/litegraph/src/node/NodeInputSlot.ts @@ -7,13 +7,16 @@ import type { INodeOutputSlot } from '@/lib/litegraph/src/types/slots' import { LiteGraph } from '@/lib/litegraph/src/litegraphInstance' -import { NodeSlot } from '@/lib/litegraph/src/node/NodeSlot' +import { + NodeSlot, + provideNodeInputSlotGuard +} from '@/lib/litegraph/src/node/NodeSlot' import { inputHasLink, inputLink } from '@/lib/litegraph/src/node/slotLinks' import { warnDeprecated } from '@/lib/litegraph/src/utils/feedback' import type { IDrawOptions } from '@/lib/litegraph/src/node/NodeSlot' import type { SubgraphInput } from '@/lib/litegraph/src/subgraph/SubgraphInput' import type { SubgraphOutput } from '@/lib/litegraph/src/subgraph/SubgraphOutput' -import { isSubgraphInput } from '@/lib/litegraph/src/subgraph/subgraphUtils' +import { isSubgraphInput } from '@/lib/litegraph/src/subgraph/subgraphTypeGuards' import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets' export class NodeInputSlot extends NodeSlot implements INodeInputSlot { @@ -130,3 +133,5 @@ function linkOf(slot: NodeInputSlot): LLink | undefined { const { graph } = slot.node return graph ? inputLink(graph, slot.node.id, indexOf(slot)) : undefined } + +provideNodeInputSlotGuard((slot) => slot instanceof NodeInputSlot) diff --git a/src/lib/litegraph/src/node/NodeOutputSlot.ts b/src/lib/litegraph/src/node/NodeOutputSlot.ts index 8892d2a8d56..b0601bb3e4b 100644 --- a/src/lib/litegraph/src/node/NodeOutputSlot.ts +++ b/src/lib/litegraph/src/node/NodeOutputSlot.ts @@ -13,7 +13,7 @@ import type { IDrawOptions } from '@/lib/litegraph/src/node/NodeSlot' import { outputHasLinks, outputLinks } from '@/lib/litegraph/src/node/slotLinks' import type { SubgraphInput } from '@/lib/litegraph/src/subgraph/SubgraphInput' import type { SubgraphOutput } from '@/lib/litegraph/src/subgraph/SubgraphOutput' -import { isSubgraphOutput } from '@/lib/litegraph/src/subgraph/subgraphUtils' +import { isSubgraphOutput } from '@/lib/litegraph/src/subgraph/subgraphTypeGuards' import { warnDeprecated } from '@/lib/litegraph/src/utils/feedback' export class NodeOutputSlot extends NodeSlot implements INodeOutputSlot { diff --git a/src/lib/litegraph/src/node/NodeSlot.ts b/src/lib/litegraph/src/node/NodeSlot.ts index 6ea8556577b..2cb0ef39ee7 100644 --- a/src/lib/litegraph/src/node/NodeSlot.ts +++ b/src/lib/litegraph/src/node/NodeSlot.ts @@ -25,9 +25,16 @@ import { RenderShape } from '@/lib/litegraph/src/types/globalEnums' -import { NodeInputSlot } from './NodeInputSlot' import { SlotBase } from './SlotBase' +let isNodeInputSlot: (slot: NodeSlot) => boolean + +export function provideNodeInputSlotGuard( + guard: (slot: NodeSlot) => boolean +): void { + isNodeInputSlot = guard +} + export interface IDrawOptions { colorContext: DefaultConnectionColors labelPosition?: LabelPosition @@ -293,7 +300,7 @@ export abstract class NodeSlot extends SlotBase implements INodeSlot { ctx.rect(x - 7 + 0.5, y - 4, 14, 8) } else if (this.shape === RenderShape.ARROW) { // Adjust arrow direction based on whether this is an input or output slot - const isInput = this instanceof NodeInputSlot + const isInput = isNodeInputSlot(this) if (isInput) { ctx.moveTo(x + 8, y) ctx.lineTo(x - 4, y - 4) diff --git a/src/lib/litegraph/src/subgraph/SubgraphInput.ts b/src/lib/litegraph/src/subgraph/SubgraphInput.ts index c10ba575e45..3c727f95f51 100644 --- a/src/lib/litegraph/src/subgraph/SubgraphInput.ts +++ b/src/lib/litegraph/src/subgraph/SubgraphInput.ts @@ -18,7 +18,7 @@ import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets' import type { SubgraphInputNode } from './SubgraphInputNode' import type { SubgraphOutput } from './SubgraphOutput' import { SubgraphSlot } from './SubgraphSlotBase' -import { isNodeSlot, isSubgraphOutput } from './subgraphUtils' +import { isNodeSlot, isSubgraphOutput } from './subgraphTypeGuards' /** * An input "slot" from a parent graph into a subgraph. diff --git a/src/lib/litegraph/src/subgraph/SubgraphInputNode.ts b/src/lib/litegraph/src/subgraph/SubgraphInputNode.ts index 61fd158fc65..103a2d1b58e 100644 --- a/src/lib/litegraph/src/subgraph/SubgraphInputNode.ts +++ b/src/lib/litegraph/src/subgraph/SubgraphInputNode.ts @@ -25,6 +25,7 @@ import { EmptySubgraphInput } from './EmptySubgraphInput' import { SubgraphIONodeBase } from './SubgraphIONodeBase' import type { SubgraphInput } from './SubgraphInput' import type { SubgraphOutput } from './SubgraphOutput' +import { provideSubgraphInputGuard } from './subgraphTypeGuards' export class SubgraphInputNode extends SubgraphIONodeBase @@ -288,3 +289,14 @@ export class SubgraphInputNode this.drawSlots(ctx, colorContext, fromSlot, editorAlpha) } } + +function isSubgraphInput(slot: unknown): slot is SubgraphInput { + return ( + slot != null && + typeof slot === 'object' && + 'parent' in slot && + slot.parent instanceof SubgraphInputNode + ) +} + +provideSubgraphInputGuard(isSubgraphInput) diff --git a/src/lib/litegraph/src/subgraph/SubgraphOutput.ts b/src/lib/litegraph/src/subgraph/SubgraphOutput.ts index 52224defa88..be544328f7c 100644 --- a/src/lib/litegraph/src/subgraph/SubgraphOutput.ts +++ b/src/lib/litegraph/src/subgraph/SubgraphOutput.ts @@ -14,7 +14,7 @@ import { NodeSlotType } from '@/lib/litegraph/src/types/globalEnums' import type { SubgraphInput } from './SubgraphInput' import type { SubgraphOutputNode } from './SubgraphOutputNode' import { SubgraphSlot } from './SubgraphSlotBase' -import { isNodeSlot, isSubgraphInput } from './subgraphUtils' +import { isNodeSlot, isSubgraphInput } from './subgraphTypeGuards' /** * An output "slot" from a subgraph to a parent graph. diff --git a/src/lib/litegraph/src/subgraph/SubgraphOutputNode.ts b/src/lib/litegraph/src/subgraph/SubgraphOutputNode.ts index 0ef1c4f7bd0..4f935326747 100644 --- a/src/lib/litegraph/src/subgraph/SubgraphOutputNode.ts +++ b/src/lib/litegraph/src/subgraph/SubgraphOutputNode.ts @@ -23,6 +23,7 @@ import { EmptySubgraphOutput } from './EmptySubgraphOutput' import { SubgraphIONodeBase } from './SubgraphIONodeBase' import type { SubgraphInput } from './SubgraphInput' import type { SubgraphOutput } from './SubgraphOutput' +import { provideSubgraphOutputGuard } from './subgraphTypeGuards' export class SubgraphOutputNode extends SubgraphIONodeBase @@ -161,3 +162,14 @@ export class SubgraphOutputNode this.drawSlots(ctx, colorContext, fromSlot, editorAlpha) } } + +function isSubgraphOutput(slot: unknown): slot is SubgraphOutput { + return ( + slot != null && + typeof slot === 'object' && + 'parent' in slot && + slot.parent instanceof SubgraphOutputNode + ) +} + +provideSubgraphOutputGuard(isSubgraphOutput) diff --git a/src/lib/litegraph/src/subgraph/subgraphTypeGuards.ts b/src/lib/litegraph/src/subgraph/subgraphTypeGuards.ts new file mode 100644 index 00000000000..4cdb6f242ee --- /dev/null +++ b/src/lib/litegraph/src/subgraph/subgraphTypeGuards.ts @@ -0,0 +1,32 @@ +import type { Subgraph } from '../LGraph' +import type { INodeInputSlot, INodeOutputSlot } from '../types/slots' +import type { SubgraphInput } from './SubgraphInput' +import type { SubgraphOutput } from './SubgraphOutput' + +export let isSubgraph: (value: unknown) => value is Subgraph +export let isSubgraphInput: (slot: unknown) => slot is SubgraphInput +export let isSubgraphOutput: (slot: unknown) => slot is SubgraphOutput + +export function provideSubgraphGuard(guard: typeof isSubgraph): void { + isSubgraph = guard +} + +export function provideSubgraphInputGuard(guard: typeof isSubgraphInput): void { + isSubgraphInput = guard +} + +export function provideSubgraphOutputGuard( + guard: typeof isSubgraphOutput +): void { + isSubgraphOutput = guard +} + +export function isNodeSlot( + slot: unknown +): slot is INodeInputSlot | INodeOutputSlot { + return ( + slot != null && + typeof slot === 'object' && + ('link' in slot || 'links' in slot) + ) +} diff --git a/src/lib/litegraph/src/subgraph/subgraphUtils.ts b/src/lib/litegraph/src/subgraph/subgraphUtils.ts index d26eca6c5c4..84c2c7f5088 100644 --- a/src/lib/litegraph/src/subgraph/subgraphUtils.ts +++ b/src/lib/litegraph/src/subgraph/subgraphUtils.ts @@ -18,10 +18,7 @@ import { SUBGRAPH_OUTPUT_ID } from '@/lib/litegraph/src/constants' import type { Positionable } from '@/lib/litegraph/src/interfaces' -import type { - INodeInputSlot, - INodeOutputSlot -} from '@/lib/litegraph/src/types/slots' +import type { INodeOutputSlot } from '@/lib/litegraph/src/types/slots' import { LiteGraph } from '@/lib/litegraph/src/litegraphInstance' import { createUuidv4 } from '@/utils/uuid' import { nextUniqueName } from '@/lib/litegraph/src/strings' @@ -36,7 +33,6 @@ import type { GraphOrSubgraph, Subgraph } from './Subgraph' import type { SubgraphInput } from './SubgraphInput' import { SubgraphInputNode } from './SubgraphInputNode' import type { SubgraphNode } from './SubgraphNode' -import type { SubgraphOutput } from './SubgraphOutput' import { SubgraphOutputNode } from './SubgraphOutputNode' interface FilteredItems { @@ -653,45 +649,4 @@ export function reorderSubgraphInputs( } } -/** - * Type guard to check if a slot is a SubgraphInput. - * @param slot The slot to check - * @returns true if the slot is a SubgraphInput - */ -export function isSubgraphInput(slot: unknown): slot is SubgraphInput { - return ( - slot != null && - typeof slot === 'object' && - 'parent' in slot && - slot.parent instanceof SubgraphInputNode - ) -} - -/** - * Type guard to check if a slot is a SubgraphOutput. - * @param slot The slot to check - * @returns true if the slot is a SubgraphOutput - */ -export function isSubgraphOutput(slot: unknown): slot is SubgraphOutput { - return ( - slot != null && - typeof slot === 'object' && - 'parent' in slot && - slot.parent instanceof SubgraphOutputNode - ) -} - -/** - * Type guard to check if a slot is a regular node slot (INodeInputSlot or INodeOutputSlot). - * @param slot The slot to check - * @returns true if the slot is a regular node slot - */ -export function isNodeSlot( - slot: unknown -): slot is INodeInputSlot | INodeOutputSlot { - return ( - slot != null && - typeof slot === 'object' && - ('link' in slot || 'links' in slot) - ) -} +export { isSubgraphInput, isSubgraphOutput } from './subgraphTypeGuards' diff --git a/src/lib/litegraph/src/utils/collections.ts b/src/lib/litegraph/src/utils/collections.ts index 4f443ccb2aa..77844a706e1 100644 --- a/src/lib/litegraph/src/utils/collections.ts +++ b/src/lib/litegraph/src/utils/collections.ts @@ -1,8 +1,14 @@ -import { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' import { parseSlotTypes } from '@/lib/litegraph/src/strings' import type { ISlotType, Positionable } from '../interfaces' +let isGraphNode: (item: Positionable) => item is LGraphNode + +export function provideGraphNodeGuard(guard: typeof isGraphNode): void { + isGraphNode = guard +} + /** * Creates a flat set of all positionable items by recursively iterating through all child items. * @@ -57,7 +63,7 @@ export function findFirstNode( items: Iterable ): LGraphNode | undefined { for (const item of items) { - if (item instanceof LGraphNode) return item + if (isGraphNode(item)) return item } } diff --git a/src/renderer/core/canvas/links/linkDropOrchestrator.test.ts b/src/renderer/core/canvas/links/linkDropOrchestrator.test.ts index 969ab09c40b..fa01fdd924e 100644 --- a/src/renderer/core/canvas/links/linkDropOrchestrator.test.ts +++ b/src/renderer/core/canvas/links/linkDropOrchestrator.test.ts @@ -1,8 +1,7 @@ import { fromPartial } from '@total-typescript/shoehorn' import { beforeEach, describe, expect, it, vi } from 'vitest' -import { LGraph } from '@/lib/litegraph/src/LGraph' -import { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import { LGraph, LGraphNode } from '@/lib/litegraph/src/litegraph' import type { LinkConnectorAdapter } from '@/renderer/core/canvas/links/linkConnectorAdapter' import { useSlotLinkDragUIState } from '@/renderer/core/canvas/links/slotLinkDragUIState' import { getSlotKey } from '@/renderer/core/layout/slots/slotIdentifier' From bd7a9a33a6f8605e11c89432977753f36e30ecc0 Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Sun, 11 Oct 2026 19:24:33 +0000 Subject: [PATCH 05/16] refactor: isolate node property value type --- src/core/schemas/parseNodePropertyArray.ts | 2 +- src/core/schemas/previewExposureSchema.ts | 2 +- src/core/schemas/promotionSchema.ts | 2 +- src/core/schemas/proxyWidgetQuarantineSchema.ts | 2 +- src/lib/litegraph/src/subgraph/subgraphDeduplication.ts | 2 +- src/lib/litegraph/src/types/serialisation.ts | 2 +- src/types/nodeProperty.ts | 1 + src/types/nodeState.ts | 3 ++- 8 files changed, 9 insertions(+), 7 deletions(-) create mode 100644 src/types/nodeProperty.ts diff --git a/src/core/schemas/parseNodePropertyArray.ts b/src/core/schemas/parseNodePropertyArray.ts index f9c2aae3da4..aae821604fd 100644 --- a/src/core/schemas/parseNodePropertyArray.ts +++ b/src/core/schemas/parseNodePropertyArray.ts @@ -1,7 +1,7 @@ import type { z } from 'zod' import { fromZodError } from 'zod-validation-error' -import type { NodeProperty } from '@/lib/litegraph/src/LGraphNode' +import type { NodeProperty } from '@/types/nodeProperty' /** * @param property - Raw node property value. diff --git a/src/core/schemas/previewExposureSchema.ts b/src/core/schemas/previewExposureSchema.ts index 1dc50456010..0aeccf47eb3 100644 --- a/src/core/schemas/previewExposureSchema.ts +++ b/src/core/schemas/previewExposureSchema.ts @@ -1,6 +1,6 @@ import { z } from 'zod' -import type { NodeProperty } from '@/lib/litegraph/src/LGraphNode' +import type { NodeProperty } from '@/types/nodeProperty' import { toNodeId } from '@/types/nodeId' import { parseNodePropertyArray } from './parseNodePropertyArray' diff --git a/src/core/schemas/promotionSchema.ts b/src/core/schemas/promotionSchema.ts index 7907f36784a..ca49b2b8517 100644 --- a/src/core/schemas/promotionSchema.ts +++ b/src/core/schemas/promotionSchema.ts @@ -1,6 +1,6 @@ import { z } from 'zod' -import type { NodeProperty } from '@/lib/litegraph/src/LGraphNode' +import type { NodeProperty } from '@/types/nodeProperty' import { parseNodePropertyArray } from './parseNodePropertyArray' diff --git a/src/core/schemas/proxyWidgetQuarantineSchema.ts b/src/core/schemas/proxyWidgetQuarantineSchema.ts index 47cab8e21be..5fb63c640ed 100644 --- a/src/core/schemas/proxyWidgetQuarantineSchema.ts +++ b/src/core/schemas/proxyWidgetQuarantineSchema.ts @@ -1,6 +1,6 @@ import { z } from 'zod' -import type { NodeProperty } from '@/lib/litegraph/src/LGraphNode' +import type { NodeProperty } from '@/types/nodeProperty' import type { TWidgetValue } from '@/lib/litegraph/src/types/widgets' import { parseNodePropertyArray } from './parseNodePropertyArray' diff --git a/src/lib/litegraph/src/subgraph/subgraphDeduplication.ts b/src/lib/litegraph/src/subgraph/subgraphDeduplication.ts index 7479eaadbd2..5c2eccebe67 100644 --- a/src/lib/litegraph/src/subgraph/subgraphDeduplication.ts +++ b/src/lib/litegraph/src/subgraph/subgraphDeduplication.ts @@ -19,7 +19,7 @@ import { toNodeId } from '@/types/nodeId' import type { NodeId, SerializedNodeId } from '@/types/nodeId' import { toLinkId } from '@/types/linkId' import { toRerouteId } from '@/types/rerouteId' -import type { NodeProperty } from '@/types/nodeState' +import type { NodeProperty } from '@/types/nodeProperty' import { createUuidv4 } from '@/utils/uuid' import type { ExportedSubgraph, diff --git a/src/lib/litegraph/src/types/serialisation.ts b/src/lib/litegraph/src/types/serialisation.ts index 8c4a4cab7bf..e627ebfe162 100644 --- a/src/lib/litegraph/src/types/serialisation.ts +++ b/src/lib/litegraph/src/types/serialisation.ts @@ -3,7 +3,7 @@ import type { LinkPresentation } from '@/types/linkPresentation' import type { LGraphConfig, LGraphExtra, SubgraphId } from '../LGraph' import type { IGraphGroupFlags } from '../LGraphGroup' -import type { NodeProperty } from '@/types/nodeState' +import type { NodeProperty } from '@/types/nodeProperty' import type { SerializedNodeId } from '@/types/nodeId' import type { SerialisedLLinkArray } from '../LLink' import type { FloatingRerouteSlot } from '../Reroute' diff --git a/src/types/nodeProperty.ts b/src/types/nodeProperty.ts new file mode 100644 index 00000000000..6b42243a629 --- /dev/null +++ b/src/types/nodeProperty.ts @@ -0,0 +1 @@ +export type NodeProperty = string | number | boolean | object | null diff --git a/src/types/nodeState.ts b/src/types/nodeState.ts index 5e9f2805370..1be431777bf 100644 --- a/src/types/nodeState.ts +++ b/src/types/nodeState.ts @@ -10,9 +10,10 @@ import type { } from '@/lib/litegraph/src/types/globalEnums' import type { ISerialisedNode } from '@/lib/litegraph/src/types/serialisation' import type { NodeId } from '@/types/nodeId' +import type { NodeProperty } from '@/types/nodeProperty' import type { UUID } from '@/utils/uuid' -export type NodeProperty = string | number | boolean | object | null +export type { NodeProperty } from '@/types/nodeProperty' /** * The fields the renderer draws. Selection, execution, errors, geometry, widget From ba8f6b48263e69ae9789d33ac59f8c6ae833eca6 Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Sun, 11 Oct 2026 19:28:32 +0000 Subject: [PATCH 06/16] refactor: isolate widget value type --- src/core/schemas/proxyWidgetQuarantineSchema.ts | 4 ++-- src/lib/litegraph/src/types/widgets.ts | 2 +- src/stores/widgetValueStore.ts | 2 +- src/types/simplifiedWidget.ts | 6 +++--- src/types/widgetState.ts | 2 +- src/types/widgetValue.ts | 1 + 6 files changed, 9 insertions(+), 8 deletions(-) create mode 100644 src/types/widgetValue.ts diff --git a/src/core/schemas/proxyWidgetQuarantineSchema.ts b/src/core/schemas/proxyWidgetQuarantineSchema.ts index 5fb63c640ed..bb9d834edd6 100644 --- a/src/core/schemas/proxyWidgetQuarantineSchema.ts +++ b/src/core/schemas/proxyWidgetQuarantineSchema.ts @@ -1,7 +1,7 @@ import { z } from 'zod' import type { NodeProperty } from '@/types/nodeProperty' -import type { TWidgetValue } from '@/lib/litegraph/src/types/widgets' +import type { WidgetValue } from '@/types/widgetValue' import { parseNodePropertyArray } from './parseNodePropertyArray' import { serializedProxyWidgetTupleSchema } from './promotionSchema' @@ -32,7 +32,7 @@ const proxyWidgetErrorQuarantinePropertySchema = z.array( export type ProxyWidgetErrorQuarantineEntry = Omit< z.infer, 'hostValue' -> & { hostValue?: TWidgetValue } +> & { hostValue?: WidgetValue } export function parseProxyWidgetErrorQuarantine( property: NodeProperty | undefined diff --git a/src/lib/litegraph/src/types/widgets.ts b/src/lib/litegraph/src/types/widgets.ts index e33ea150b5b..4181e1bce2c 100644 --- a/src/lib/litegraph/src/types/widgets.ts +++ b/src/lib/litegraph/src/types/widgets.ts @@ -4,7 +4,7 @@ import type { CurveData } from '@/components/curve/types' import type { BoundingBox } from '@/types/boundingBoxes' import type { LightInfoEntry } from '@/types/lightInfo' import type { NodeId } from '@/types/nodeId' -import type { WidgetValue } from '@/types/simplifiedWidget' +import type { WidgetValue } from '@/types/widgetValue' import type { WidgetId } from '@/types/widgetId' import type { WidgetSurfaces, diff --git a/src/stores/widgetValueStore.ts b/src/stores/widgetValueStore.ts index c839ee9f7a3..e26cecc5218 100644 --- a/src/stores/widgetValueStore.ts +++ b/src/stores/widgetValueStore.ts @@ -11,7 +11,7 @@ import { widgetId as createWidgetId } from '@/types/widgetId' import type { WidgetId } from '@/types/widgetId' -import type { WidgetValue } from '@/types/simplifiedWidget' +import type { WidgetValue } from '@/types/widgetValue' import type { WidgetState, WidgetStateInit } from '@/types/widgetState' import { applyLegacyHiddenWrite, diff --git a/src/types/simplifiedWidget.ts b/src/types/simplifiedWidget.ts index 0f34c5a08f7..f6cbbed6909 100644 --- a/src/types/simplifiedWidget.ts +++ b/src/types/simplifiedWidget.ts @@ -10,6 +10,9 @@ import type { import { IS_CONTROL_WIDGET } from '@/core/graph/widgets/controlWidgetMarker' import type { NodeId } from '@/types/nodeId' import type { NodeLocatorId } from '@/types/nodeIdentification' +import type { WidgetValue } from '@/types/widgetValue' + +export type { WidgetValue } from '@/types/widgetValue' export const CONTROL_OPTIONS = [ 'fixed', @@ -23,9 +26,6 @@ export function isControlOption(value: unknown): value is ControlOptions { return CONTROL_OPTIONS.some((option) => option === value) } -/** Valid types for widget values */ -export type WidgetValue = string | number | boolean | object | undefined | null - function normalizeControlOption(val: WidgetValue): ControlOptions { if (isControlOption(val)) return val return 'randomize' diff --git a/src/types/widgetState.ts b/src/types/widgetState.ts index 04e0d010599..50417df94f1 100644 --- a/src/types/widgetState.ts +++ b/src/types/widgetState.ts @@ -3,7 +3,7 @@ import type { IWidgetOptions } from '@/lib/litegraph/src/types/widgets' import type { NodeId } from '@/types/nodeId' -import type { WidgetValue } from '@/types/simplifiedWidget' +import type { WidgetValue } from '@/types/widgetValue' export interface WidgetState< TValue = WidgetValue, diff --git a/src/types/widgetValue.ts b/src/types/widgetValue.ts new file mode 100644 index 00000000000..593279f69bc --- /dev/null +++ b/src/types/widgetValue.ts @@ -0,0 +1 @@ +export type WidgetValue = string | number | boolean | object | undefined | null From 2380c82edb72b9dc8e4180f1d65d405715dae325 Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Sun, 11 Oct 2026 19:30:51 +0000 Subject: [PATCH 07/16] refactor: colocate node binding contract with its guard --- src/lib/litegraph/src/types/widgets.ts | 5 +---- src/lib/litegraph/src/utils/type.ts | 6 +++++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/lib/litegraph/src/types/widgets.ts b/src/lib/litegraph/src/types/widgets.ts index 4181e1bce2c..5b55ab5552e 100644 --- a/src/lib/litegraph/src/types/widgets.ts +++ b/src/lib/litegraph/src/types/widgets.ts @@ -3,7 +3,6 @@ import type { CompositorWidgetValue } from '@/renderer/extensions/compositor/com import type { CurveData } from '@/components/curve/types' import type { BoundingBox } from '@/types/boundingBoxes' import type { LightInfoEntry } from '@/types/lightInfo' -import type { NodeId } from '@/types/nodeId' import type { WidgetValue } from '@/types/widgetValue' import type { WidgetId } from '@/types/widgetId' import type { @@ -22,9 +21,7 @@ import type { import type { CanvasPointer, LGraphCanvas, LGraphNode } from '../litegraph' import type { CanvasPointerEvent } from './events' -export interface NodeBindable { - setNodeId(nodeId: NodeId): void -} +export type { NodeBindable } from '../utils/type' export interface IWidgetOptions { on?: string diff --git a/src/lib/litegraph/src/utils/type.ts b/src/lib/litegraph/src/utils/type.ts index ccf9801bb63..604617a2240 100644 --- a/src/lib/litegraph/src/utils/type.ts +++ b/src/lib/litegraph/src/utils/type.ts @@ -1,7 +1,11 @@ import { without } from 'es-toolkit' import type { IColorable, ISlotType } from '@/lib/litegraph/src/interfaces' -import type { NodeBindable } from '@/lib/litegraph/src/types/widgets' +import type { NodeId } from '@/types/nodeId' + +export interface NodeBindable { + setNodeId(nodeId: NodeId): void +} /** * Converts a plain object to a class instance if it is not already an instance of the class. From fd2ce2f5eb224d7509c098f24a81eb2c15f85eba Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Sun, 11 Oct 2026 19:32:37 +0000 Subject: [PATCH 08/16] refactor: remove slot string utilities barrel dependency --- src/lib/litegraph/src/strings.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/litegraph/src/strings.ts b/src/lib/litegraph/src/strings.ts index 2ce4c237894..c24db6b665f 100644 --- a/src/lib/litegraph/src/strings.ts +++ b/src/lib/litegraph/src/strings.ts @@ -1,4 +1,4 @@ -import type { ISlotType } from './litegraph' +import type { ISlotType } from './interfaces' export function parseSlotTypes(type: ISlotType): string[] { return type == '' || type == '0' From 48bc0608c219c3ba468c6377aa70dc717b191f28 Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Sun, 11 Oct 2026 21:53:14 +0000 Subject: [PATCH 09/16] refactor: restore bundled frontend type declarations --- package.json | 1 + pnpm-lock.yaml | 35 +++++++++++++---------------------- pnpm-workspace.yaml | 1 + vite.types.config.mts | 3 ++- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index 88bc44a571d..aae86961cc9 100644 --- a/package.json +++ b/package.json @@ -160,6 +160,7 @@ "@comfyorg/website": "workspace:*", "@eslint/js": "catalog:", "@intlify/eslint-plugin-vue-i18n": "catalog:", + "@microsoft/api-extractor": "catalog:", "@pinia/testing": "catalog:", "@playwright/test": "catalog:", "@sentry/vite-plugin": "catalog:", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1e5773d10c4..b0bd03a4846 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -72,6 +72,9 @@ catalogs: '@lucide/vue': specifier: ^1.17.0 version: 1.24.0 + '@microsoft/api-extractor': + specifier: 7.58.9 + version: 7.58.9 '@pinia/testing': specifier: ^2.0.1 version: 2.0.1 @@ -574,7 +577,7 @@ importers: version: 14.4.0(vue@3.5.42(typescript@6.0.3)) '@vueuse/integrations': specifier: 'catalog:' - version: 14.4.0(axios@1.18.1)(fuse.js@7.0.0)(vue@3.5.42(typescript@6.0.3)) + version: 14.4.0(axios@1.18.1(debug@4.4.3))(fuse.js@7.0.0)(vue@3.5.42(typescript@6.0.3)) '@vueuse/router': specifier: ^14.4.0 version: 14.4.0(vue-router@5.2.0(@vue/compiler-sfc@3.5.42)(esbuild@0.28.1)(pinia@4.0.2(@vue/devtools-api@8.1.5)(typescript@6.0.3)(vue@3.5.42(typescript@6.0.3)))(rolldown@1.2.6)(vite@8.2.2(@types/node@25.9.5)(esbuild@0.28.1)(jiti@2.7.0)(terser@5.49.0)(tsx@4.23.1)(yaml@2.9.0))(vue@3.5.42(typescript@6.0.3)))(vue@3.5.42(typescript@6.0.3)) @@ -705,6 +708,9 @@ importers: '@intlify/eslint-plugin-vue-i18n': specifier: 'catalog:' version: 4.5.1(eslint@10.10.0(jiti@2.7.0))(jsonc-eslint-parser@3.1.0)(vue-eslint-parser@10.4.1(eslint@10.10.0(jiti@2.7.0)))(yaml-eslint-parser@2.1.0) + '@microsoft/api-extractor': + specifier: 'catalog:' + version: 7.58.9(@types/node@25.9.5) '@pinia/testing': specifier: 'catalog:' version: 2.0.1(pinia@4.0.2(@vue/devtools-api@8.1.5)(typescript@6.0.3)(vue@3.5.42(typescript@6.0.3))) @@ -11805,7 +11811,6 @@ snapshots: '@rushstack/node-core-library': 5.23.1(@types/node@25.9.5) transitivePeerDependencies: - '@types/node' - optional: true '@microsoft/api-extractor@7.58.9(@types/node@25.9.5)': dependencies: @@ -11824,7 +11829,6 @@ snapshots: typescript: 5.9.3 transitivePeerDependencies: - '@types/node' - optional: true '@microsoft/tsdoc-config@0.18.1': dependencies: @@ -11832,10 +11836,8 @@ snapshots: ajv: 8.20.0 jju: 1.4.0 resolve: 1.22.12 - optional: true - '@microsoft/tsdoc@0.16.0': - optional: true + '@microsoft/tsdoc@0.16.0': {} '@mixpanel/rrdom@2.0.0-alpha.18.5': dependencies: @@ -12418,18 +12420,15 @@ snapshots: semver: 7.7.4 optionalDependencies: '@types/node': 25.9.5 - optional: true '@rushstack/problem-matcher@0.2.1(@types/node@25.9.5)': optionalDependencies: '@types/node': 25.9.5 - optional: true '@rushstack/rig-package@0.7.3': dependencies: jju: 1.4.0 resolve: 1.22.12 - optional: true '@rushstack/terminal@0.24.0(@types/node@25.9.5)': dependencies: @@ -12438,7 +12437,6 @@ snapshots: supports-color: 8.1.1 optionalDependencies: '@types/node': 25.9.5 - optional: true '@rushstack/ts-command-line@5.3.10(@types/node@25.9.5)': dependencies: @@ -12448,7 +12446,6 @@ snapshots: string-argv: 0.3.2 transitivePeerDependencies: - '@types/node' - optional: true '@segment/analytics.js-video-plugins@0.2.1': dependencies: @@ -13036,8 +13033,7 @@ snapshots: tslib: 2.8.1 optional: true - '@types/argparse@1.0.38': - optional: true + '@types/argparse@1.0.38': {} '@types/aria-query@5.0.4': {} @@ -13785,7 +13781,7 @@ snapshots: '@vueuse/shared': 14.4.0(vue@3.5.42(typescript@6.0.3)) vue: 3.5.42(typescript@6.0.3) - '@vueuse/integrations@14.4.0(axios@1.18.1)(fuse.js@7.0.0)(vue@3.5.42(typescript@6.0.3))': + '@vueuse/integrations@14.4.0(axios@1.18.1(debug@4.4.3))(fuse.js@7.0.0)(vue@3.5.42(typescript@6.0.3))': dependencies: '@vueuse/core': 14.4.0(vue@3.5.42(typescript@6.0.3)) '@vueuse/shared': 14.4.0(vue@3.5.42(typescript@6.0.3)) @@ -13936,7 +13932,6 @@ snapshots: argparse@1.0.10: dependencies: sprintf-js: 1.0.3 - optional: true argparse@2.0.1: {} @@ -15653,8 +15648,7 @@ snapshots: import-fresh@4.0.0: {} - import-lazy@4.0.0: - optional: true + import-lazy@4.0.0: {} import-meta-resolve@4.2.0: {} @@ -15865,8 +15859,7 @@ snapshots: jiti@2.7.0: {} - jju@1.4.0: - optional: true + jju@1.4.0: {} joi@18.2.3: dependencies: @@ -18049,8 +18042,7 @@ snapshots: speakingurl@14.0.1: {} - sprintf-js@1.0.3: - optional: true + sprintf-js@1.0.3: {} sqids@0.3.0: {} @@ -18236,7 +18228,6 @@ snapshots: supports-color@8.1.1: dependencies: has-flag: 4.0.0 - optional: true supports-hyperlinks@4.5.0: dependencies: diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index dcf388ac377..380074a23e5 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -165,6 +165,7 @@ catalog: '@comfyorg/comfy-multi-player': 0.3.10 typescript-native-bridge: 6.0.3-bridge.17.tsgo.7.0.2 dependency-cruiser: ^18.5.0 + '@microsoft/api-extractor': 7.58.9 cleanupUnusedCatalogs: true diff --git a/vite.types.config.mts b/vite.types.config.mts index 531708909c3..fa0487d8414 100644 --- a/vite.types.config.mts +++ b/vite.types.config.mts @@ -17,7 +17,8 @@ export default defineConfig({ plugins: [ dts({ copyDtsFiles: true, - rollupTypes: true, + bundleTypes: true, + processor: 'vue', tsconfigPath: 'tsconfig.types.json' }) ] From 74dfe984ab7483702cb3087f9841ff2a3c0a580a Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Sun, 11 Oct 2026 22:10:58 +0000 Subject: [PATCH 10/16] refactor: remove litegraph type import cycles with exact interfaces --- .fallow-baselines/dead-code.json | 13 ++ ...xact-entity-types-without-import-cycles.md | 52 ++++++ scripts/litegraphDeclarations.test.ts | 153 ++++++++++++++++++ scripts/litegraphDeclarations.ts | 127 +++++++++++++++ .../graph/nodeShell/nodeShellLifecycle.ts | 9 +- src/core/graph/nodeShell/nodeShellState.ts | 7 +- .../subgraph/adoptPromotedWidgetValue.ts | 3 +- .../graph/subgraph/promotedWidgetTypes.ts | 3 +- .../subgraph/resolveConcretePromotedWidget.ts | 9 +- .../subgraph/resolveSubgraphInputLink.ts | 2 +- .../subgraph/resolveSubgraphInputTarget.ts | 3 +- src/lib/litegraph/src/ContextMenu.ts | 8 + src/lib/litegraph/src/CurveEditor.ts | 3 +- src/lib/litegraph/src/LGraph.ts | 27 +++- src/lib/litegraph/src/LGraphCanvas.ts | 27 +++- src/lib/litegraph/src/LGraphGroup.ts | 14 +- src/lib/litegraph/src/LGraphNode.ts | 30 +++- src/lib/litegraph/src/LLink.ts | 27 +++- src/lib/litegraph/src/LinkMap.ts | 3 +- src/lib/litegraph/src/LiteGraphGlobal.ts | 10 +- src/lib/litegraph/src/Reroute.ts | 15 +- .../src/canvas/FloatingRenderLink.ts | 21 ++- .../litegraph/src/canvas/InputIndicators.ts | 2 +- src/lib/litegraph/src/canvas/LinkConnector.ts | 19 ++- .../litegraph/src/canvas/MovingInputLink.ts | 19 ++- .../litegraph/src/canvas/MovingLinkBase.ts | 15 +- .../litegraph/src/canvas/MovingOutputLink.ts | 19 ++- src/lib/litegraph/src/canvas/RenderLink.ts | 28 ++-- .../litegraph/src/canvas/SelectedItemsView.ts | 3 +- .../src/canvas/ToInputFromIoNodeLink.ts | 20 ++- .../litegraph/src/canvas/ToInputRenderLink.ts | 18 ++- .../src/canvas/ToOutputFromIoNodeLink.ts | 14 +- .../src/canvas/ToOutputFromRerouteLink.ts | 15 +- .../src/canvas/ToOutputRenderLink.ts | 10 +- .../litegraph/src/canvas/canvasClassAccess.ts | 7 +- .../src/canvas/getCanvasContextMenuTarget.ts | 7 +- src/lib/litegraph/src/canvas/hitTesting.ts | 7 +- .../litegraph/src/canvas/linkBadgeRenderer.ts | 4 +- src/lib/litegraph/src/canvas/linkBadges.ts | 3 +- src/lib/litegraph/src/canvas/linkGeometry.ts | 4 +- .../litegraph/src/canvas/linkVisibility.ts | 8 +- src/lib/litegraph/src/canvas/measureSlots.ts | 3 +- .../src/canvas/resolvePointerTarget.ts | 20 ++- src/lib/litegraph/src/graphIntents.ts | 9 +- src/lib/litegraph/src/idAllocation.ts | 3 +- .../infrastructure/LGraphCanvasEventMap.ts | 15 +- .../src/infrastructure/LGraphEventMap.ts | 14 +- .../infrastructure/LinkConnectorEventMap.ts | 25 +-- .../src/infrastructure/SubgraphEventMap.ts | 11 +- .../infrastructure/SubgraphInputEventMap.ts | 10 +- src/lib/litegraph/src/linkDeduplication.ts | 11 +- src/lib/litegraph/src/litegraph.ts | 40 ++--- src/lib/litegraph/src/litegraphInstance.ts | 2 +- src/lib/litegraph/src/node/NodeInputSlot.ts | 13 +- src/lib/litegraph/src/node/NodeOutputSlot.ts | 13 +- src/lib/litegraph/src/node/NodeSlot.ts | 10 +- .../litegraph/src/node/slotDescriptorView.ts | 3 +- src/lib/litegraph/src/node/slotLinks.ts | 9 +- src/lib/litegraph/src/node/slotUtils.ts | 9 +- src/lib/litegraph/src/node/widgetsView.ts | 2 +- src/lib/litegraph/src/nodeBadgeDraw.ts | 2 +- src/lib/litegraph/src/remintLinkRemap.ts | 2 +- .../src/subgraph/EmptySubgraphInput.ts | 11 +- .../src/subgraph/EmptySubgraphOutput.ts | 11 +- .../src/subgraph/ExecutableNodeDTO.ts | 14 +- .../src/subgraph/SubgraphIONodeBase.ts | 35 ++-- .../litegraph/src/subgraph/SubgraphInput.ts | 17 +- .../src/subgraph/SubgraphInputNode.ts | 21 ++- .../litegraph/src/subgraph/SubgraphNode.ts | 37 +++-- .../litegraph/src/subgraph/SubgraphOutput.ts | 17 +- .../src/subgraph/SubgraphOutputNode.ts | 24 ++- .../src/subgraph/SubgraphSlotBase.ts | 19 ++- .../subgraph/promotedWidgetStoreProjection.ts | 2 +- .../src/subgraph/subgraphTypeGuards.ts | 9 +- .../litegraph/src/subgraph/subgraphUtils.ts | 19 ++- .../litegraph/src/subgraph/unpackSubgraph.ts | 3 +- src/lib/litegraph/src/types/contextMenu.ts | 9 +- .../src/types/entityRegistry.test.ts | 35 ++++ src/lib/litegraph/src/types/entityRegistry.ts | 34 ++++ src/lib/litegraph/src/types/events.ts | 9 +- src/lib/litegraph/src/types/linkNetwork.ts | 13 +- .../litegraph/src/types/nodeConstructor.ts | 26 +++ src/lib/litegraph/src/types/panel.ts | 3 +- src/lib/litegraph/src/types/serialisation.ts | 17 +- src/lib/litegraph/src/types/slots.ts | 9 +- src/lib/litegraph/src/types/widgets.ts | 6 +- src/lib/litegraph/src/utils/arrange.ts | 3 +- src/lib/litegraph/src/utils/collections.ts | 3 +- .../utils/namedValuesShadowDiffTelemetry.ts | 2 +- src/lib/litegraph/src/utils/widget.ts | 3 +- src/lib/litegraph/src/widgets/AssetWidget.ts | 3 +- src/lib/litegraph/src/widgets/BaseWidget.ts | 19 +-- src/lib/litegraph/src/widgets/ButtonWidget.ts | 3 +- src/lib/litegraph/src/widgets/ComboWidget.ts | 3 +- src/lib/litegraph/src/widgets/LegacyWidget.ts | 3 +- src/lib/litegraph/src/widgets/TextWidget.ts | 3 +- src/lib/litegraph/src/widgets/widgetMap.ts | 3 +- src/platform/nodeReplacement/cnrIdUtil.ts | 2 +- .../litegraph/arrangeForLegacyRender.ts | 5 +- .../canvas/litegraph/litegraphLinkAdapter.ts | 4 +- .../core/canvas/litegraph/selectionAdapter.ts | 12 +- .../core/canvas/litegraph/slotCalculations.ts | 7 +- .../operations/graphLayoutAttachment.ts | 11 +- .../core/layout/operations/layoutMutations.ts | 3 +- src/stores/clearNodeOwnedStoreState.ts | 3 +- src/stores/graphMetadataStore.ts | 5 +- src/stores/previewExposureStore.ts | 3 +- src/utils/graphTraversalUtil.ts | 3 +- src/utils/typeGuardUtil.ts | 4 +- vite.types.config.mts | 7 +- 110 files changed, 1183 insertions(+), 348 deletions(-) create mode 100644 docs/adr/TYPES-LITEGRAPH-0044-exact-entity-types-without-import-cycles.md create mode 100644 scripts/litegraphDeclarations.test.ts create mode 100644 scripts/litegraphDeclarations.ts create mode 100644 src/lib/litegraph/src/types/entityRegistry.test.ts create mode 100644 src/lib/litegraph/src/types/entityRegistry.ts create mode 100644 src/lib/litegraph/src/types/nodeConstructor.ts diff --git a/.fallow-baselines/dead-code.json b/.fallow-baselines/dead-code.json index 0aeaef93676..59f0274cf05 100644 --- a/.fallow-baselines/dead-code.json +++ b/.fallow-baselines/dead-code.json @@ -582,14 +582,27 @@ "unresolved_imports": ["index.html:./materialdesignicons.min.css"], "unlisted_dependencies": [], "duplicate_exports": [ + "BaseLGraph|src/lib/litegraph/src/LGraph.ts|src/lib/litegraph/src/types/entityRegistry.ts", "Bounds|src/renderer/core/layout/types.ts|src/renderer/core/spatial/QuadTree.ts", "ComfyDialog|src/scripts/ui.ts|src/scripts/ui/dialog.ts", + "ContextMenu|src/lib/litegraph/src/ContextMenu.ts|src/lib/litegraph/src/ContextMenu.ts|src/lib/litegraph/src/types/entityRegistry.ts", "Direction|src/lib/litegraph/src/interfaces.ts|src/renderer/core/canvas/pathRenderer.ts", + "GraphOrSubgraph|src/lib/litegraph/src/LGraph.ts|src/lib/litegraph/src/types/entityRegistry.ts", + "IGraphGroupFlags|src/lib/litegraph/src/LGraphGroup.ts|src/lib/litegraph/src/types/entityRegistry.ts", "JobListItem|src/composables/queue/useJobList.ts|src/platform/remote/comfyui/jobs/jobTypes.ts", + "LGraphCanvas|src/lib/litegraph/src/LGraphCanvas.ts|src/lib/litegraph/src/LGraphCanvas.ts|src/lib/litegraph/src/types/entityRegistry.ts", + "LGraphConfig|src/lib/litegraph/src/LGraph.ts|src/lib/litegraph/src/types/entityRegistry.ts", + "LGraphExtra|src/lib/litegraph/src/LGraph.ts|src/lib/litegraph/src/types/entityRegistry.ts", + "LGraphNode|src/lib/litegraph/src/LGraphNode.ts|src/lib/litegraph/src/LGraphNode.ts|src/lib/litegraph/src/types/entityRegistry.ts", "ModelFile|src/platform/assets/schemas/assetSchema.ts|src/platform/workflow/validation/schemas/workflowSchema.ts", "PendingInvite|src/platform/workspace/api/workspaceApi.ts|src/platform/workspace/stores/teamWorkspaceStore.ts", "Point|src/lib/litegraph/src/interfaces.ts|src/renderer/core/canvas/pathRenderer.ts|src/renderer/core/layout/types.ts", + "RenderLink|src/lib/litegraph/src/canvas/RenderLink.ts|src/lib/litegraph/src/types/entityRegistry.ts", + "ResolvedConnection|src/lib/litegraph/src/LLink.ts|src/lib/litegraph/src/types/entityRegistry.ts", + "SerialisedLLinkArray|src/lib/litegraph/src/LLink.ts|src/lib/litegraph/src/types/entityRegistry.ts", "Size|src/lib/litegraph/src/interfaces.ts|src/renderer/core/layout/types.ts", + "SlotTypeDefaultNodeOpts|src/lib/litegraph/src/LiteGraphGlobal.ts|src/lib/litegraph/src/types/entityRegistry.ts", + "SubgraphId|src/lib/litegraph/src/LGraph.ts|src/lib/litegraph/src/types/entityRegistry.ts", "User|src/schemas/apiSchema.ts|src/stores/userStore.ts", "WidgetValue|src/types/simplifiedWidget.ts|src/utils/widgetUtil.ts", "WorkspaceWithRole|src/platform/workspace/api/workspaceApi.ts|src/platform/workspace/workspaceTypes.ts", diff --git a/docs/adr/TYPES-LITEGRAPH-0044-exact-entity-types-without-import-cycles.md b/docs/adr/TYPES-LITEGRAPH-0044-exact-entity-types-without-import-cycles.md new file mode 100644 index 00000000000..6293bace018 --- /dev/null +++ b/docs/adr/TYPES-LITEGRAPH-0044-exact-entity-types-without-import-cycles.md @@ -0,0 +1,52 @@ +# ADR-TYPES-LITEGRAPH-0044: Exact entity types without import cycles + +Date: 2026-10-11 + +## Status + +Proposed + +## Context + +Litegraph's runtime imports are acyclic, but its public types are mutually +recursive. A node refers to its graph, and a graph refers to its nodes. +Importing these types from their implementation modules recreates the module +cycles. Replacing a concrete class with a public-member-only interface is not +compatible: TypeScript uses private and protected members when checking class +assignability, and extensions subclass these classes. + +## Decision + +Use same-name interfaces in `types/entityRegistry.ts`. Each implementation +augments its interface to extend the exact concrete type through a local alias. +Keep union, tuple, and primitive aliases in the merged +`LitegraphEntityRegistry` interface because an interface cannot preserve those +shapes by extending them. Existing public exports retain their names. + +This removes module-import cycles, not recursive type relationships or runtime +coupling. It does not add entity members, change layout mutation ownership, or +replace the dedicated stores required by ADR-ECS-0008 and ADR-CRDT-LAYOUT-0003. +All type providers must remain reachable from the public litegraph barrel's +TypeScript import graph. Runtime providers must remain statically reachable +from `main.ts` without type-only or dynamic-import edges. + +API Extractor does not reliably preserve local module augmentations. The types +build converts the leaf declarations into type re-exports of each provider's +exact alias, exports those aliases, and removes the internal augmentations +before bundling. The build derives the mapping from the source augmentations +rather than maintaining a second registry. The published package contains +ordinary declarations and does not require consumers to load our providers. + +## Alternatives and consequences + +- A structural contract layer would lose nominal compatibility or duplicate + hundreds of class members. It belongs to a separate extension API redesign. +- Merging the core class modules would combine unrelated responsibilities and + thousands of lines merely to reduce a graph metric. +- An indexed registry for every type works, but same-name interfaces avoid + indexed lookups for the class and object types that support inheritance. +- Source navigation now passes through the leaf interface. A partial source + program must include its providers; importing the supported barrel does so. +- Declaration publishing has an additional transformation. A compiler and + API Extractor integration test checks nominal, generic, and union types in + an isolated consumer. Source type assertions check the graph/node contracts. diff --git a/scripts/litegraphDeclarations.test.ts b/scripts/litegraphDeclarations.test.ts new file mode 100644 index 00000000000..432477deeb4 --- /dev/null +++ b/scripts/litegraphDeclarations.test.ts @@ -0,0 +1,153 @@ +import { Extractor, ExtractorConfig } from '@microsoft/api-extractor' +import { + mkdirSync, + mkdtempSync, + readFileSync, + rmSync, + writeFileSync +} from 'node:fs' +import { tmpdir } from 'node:os' +import { dirname, join } from 'node:path' +import ts from 'typescript' +import { expect, it, onTestFinished } from 'vitest' + +import { createLitegraphDeclarationTransform } from './litegraphDeclarations' + +function writeFiles(root: string, files: Record) { + for (const [file, text] of Object.entries(files)) { + mkdirSync(dirname(join(root, file)), { recursive: true }) + writeFileSync(join(root, file), text) + } +} + +it('publishes exact nominal, generic, and union types without augmentation dependencies', () => { + const root = mkdtempSync(join(tmpdir(), 'litegraph-declarations-')) + onTestFinished(() => rmSync(root, { recursive: true, force: true })) + writeFiles(root, { + 'package.json': JSON.stringify({ name: 'type-consumer', version: '1.0.0' }), + 'types/entityRegistry.ts': ` + export interface Graph {} + export interface LitegraphEntityRegistry {} + export type Choice = LitegraphEntityRegistry['Choice'] + export interface Box<_T = unknown> {} + `, + 'Graph.ts': ` + import { Node } from './Node' + export class Graph { + private identity = 1 + nodes: Node[] = [] + add(node: Node): this { node.graph = this; return this } + } + type RegisteredGraph = Graph + type RegisteredChoice = 'first' | 'second' + declare module './types/entityRegistry' { + interface Graph extends RegisteredGraph {} + interface LitegraphEntityRegistry { Choice: RegisteredChoice } + } + `, + 'Node.ts': ` + import type { Graph, Box, Choice } from './types/entityRegistry' + export class Node { + graph: Graph | null = null + box?: Box + choice?: Choice + } + `, + 'Box.ts': ` + export class Box { + private identity = 2 + constructor(public value: T) {} + } + type RegisteredBox = Box + declare module './types/entityRegistry' { + interface Box<_T = unknown> extends RegisteredBox<_T> {} + } + `, + 'index.ts': `export { Graph } from './Graph' + export { Node } from './Node' + export { Box } from './Box'` + }) + const transform = createLitegraphDeclarationTransform(root) + const options: ts.CompilerOptions = { + target: ts.ScriptTarget.ESNext, + module: ts.ModuleKind.ESNext, + moduleResolution: ts.ModuleResolutionKind.Bundler, + strict: true, + skipLibCheck: true, + types: [], + declaration: true, + emitDeclarationOnly: true, + outDir: join(root, 'out') + } + const program = ts.createProgram([join(root, 'index.ts')], options) + expect( + ts + .getPreEmitDiagnostics(program) + .map((diagnostic) => diagnostic.messageText) + ).toEqual([]) + program.emit(undefined, (file, text) => { + writeFiles(dirname(file), { + [file.slice(dirname(file).length + 1)]: + transform(file, text)?.content ?? text + }) + }) + const entry = join(root, 'out/index.d.ts') + const result = Extractor.invoke( + ExtractorConfig.prepare({ + configObject: { + projectFolder: root, + mainEntryPointFilePath: entry, + compiler: { + overrideTsconfig: { + compilerOptions: { types: [], skipLibCheck: true }, + files: [entry] + } + }, + apiReport: { enabled: false }, + docModel: { enabled: false }, + tsdocMetadata: { enabled: false }, + dtsRollup: { + enabled: true, + untrimmedFilePath: join(root, 'bundle.d.ts') + } + }, + configObjectFullPath: join(root, 'api-extractor.json'), + packageJsonFullPath: join(root, 'package.json') + }), + { + localBuild: true, + messageCallback: (message) => { + message.handled = true + } + } + ) + expect(result.succeeded).toBe(true) + expect(readFileSync(join(root, 'bundle.d.ts'), 'utf8')).not.toContain( + 'entityRegistry' + ) + writeFiles(root, { + 'consumer.ts': ` + import { Graph, Node, Box } from './bundle' + type Equal = (() => T extends A ? 1 : 2) extends (() => T extends B ? 1 : 2) ? true : false + type Check = T + export type GraphIdentity = Check> + export type BoxIdentity = Check | undefined>> + export type UnionIdentity = Check> + export type Nominality = Check> + const graph = new Graph() + const node = new Node() + node.graph = graph + export const concrete: Graph = node.graph + export const generic: Box = new Box('value') + ` + }) + const consumer = ts.createProgram([join(root, 'consumer.ts')], { + ...options, + noEmit: true + }) + expect( + ts + .getPreEmitDiagnostics(consumer) + .map((diagnostic) => diagnostic.messageText) + ).toEqual([]) +}) diff --git a/scripts/litegraphDeclarations.ts b/scripts/litegraphDeclarations.ts new file mode 100644 index 00000000000..c35866a521a --- /dev/null +++ b/scripts/litegraphDeclarations.ts @@ -0,0 +1,127 @@ +import { readdirSync, readFileSync } from 'node:fs' +import { relative, resolve } from 'node:path' +import ts from 'typescript' + +interface Registration { + file: string + names: { name: string; alias: string }[] +} + +function registryAugmentation(node: ts.Node): node is ts.ModuleDeclaration & { + body: ts.ModuleBlock +} { + return ( + ts.isModuleDeclaration(node) && + ts.isStringLiteral(node.name) && + node.name.text.endsWith('/entityRegistry') && + node.body !== undefined && + ts.isModuleBlock(node.body) + ) +} + +export function createLitegraphDeclarationTransform(root: string) { + const registrations: Registration[] = readdirSync(root, { + recursive: true, + encoding: 'utf8' + }).flatMap((file) => { + if (!file.endsWith('.ts')) return [] + const content = readFileSync(resolve(root, file), 'utf8') + if (!content.includes('declare module')) return [] + const source = ts.createSourceFile( + file, + content, + ts.ScriptTarget.Latest, + true + ) + const names = source.statements + .filter(registryAugmentation) + .flatMap((node) => + node.body.statements.flatMap((statement) => { + if (!ts.isInterfaceDeclaration(statement)) return [] + if (statement.name.text === 'LitegraphEntityRegistry') { + return statement.members.flatMap((member) => + ts.isPropertySignature(member) && member.type + ? [ + { + name: member.name.getText(source), + alias: member.type.getText(source) + } + ] + : [] + ) + } + return ( + statement.heritageClauses?.flatMap((clause) => + clause.types.map((type) => ({ + name: statement.name.text, + alias: type.expression.getText(source) + })) + ) ?? [] + ) + }) + ) + return names.length ? [{ file: file.replaceAll('\\', '/'), names }] : [] + }) + + return ( + filePath: string, + content: string + ): { content: string } | undefined => { + const outputPath = filePath.replaceAll('\\', '/') + if (outputPath.endsWith('/types/entityRegistry.d.ts')) { + return { + content: registrations + .map(({ file, names }) => { + const owner = relative('types', file) + .replaceAll('\\', '/') + .replace(/\.ts$/, '') + return `export type { ${names.map(({ name, alias }) => `${alias} as ${name}`).join(', ')} } from '${owner.startsWith('.') ? owner : './' + owner}'` + }) + .join('\n') + } + } + const registration = registrations.find(({ file }) => + outputPath.endsWith('/' + file.replace(/\.ts$/, '.d.ts')) + ) + if (!registration) return undefined + const source = ts.createSourceFile( + filePath, + content, + ts.ScriptTarget.Latest, + true + ) + const aliases = new Set(registration.names.map(({ alias }) => alias)) + const edits = source.statements.flatMap((statement) => { + if (registryAugmentation(statement)) { + return [ + { start: statement.getFullStart(), end: statement.getEnd(), text: '' } + ] + } + if ( + ts.isTypeAliasDeclaration(statement) && + aliases.has(statement.name.text) && + !statement.modifiers?.some( + (modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword + ) + ) { + return [ + { + start: statement.getStart(source), + end: statement.getStart(source), + text: 'export ' + } + ] + } + return [] + }) + return { + content: edits + .reverse() + .reduce( + (text, edit) => + text.slice(0, edit.start) + edit.text + text.slice(edit.end), + content + ) + } + } +} diff --git a/src/core/graph/nodeShell/nodeShellLifecycle.ts b/src/core/graph/nodeShell/nodeShellLifecycle.ts index bbc7f77eb0d..db276c7b134 100644 --- a/src/core/graph/nodeShell/nodeShellLifecycle.ts +++ b/src/core/graph/nodeShell/nodeShellLifecycle.ts @@ -1,3 +1,8 @@ +import type { + LGraph, + LGraphNode, + Subgraph +} from '@/lib/litegraph/src/types/entityRegistry' import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets' import type { WidgetRefusalReport } from '@/lib/litegraph/src/node/widgetsView' import { refuseAmbiguousNodeWidgets } from '@/lib/litegraph/src/node/widgetsView' @@ -10,10 +15,8 @@ import type { RefusedWidget } from '@/types/widgetId' import { registerNodeState, unregisterNodeState } from './nodeShellState' -import type { LGraph } from '@/lib/litegraph/src/LGraph' -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' import type { NodeId } from '@/types/nodeId' -import type { Subgraph } from '@/lib/litegraph/src/subgraph/Subgraph' + import type { UUID } from '@/utils/uuid' const REFUSAL_TEARDOWN_ERROR_TYPE = 'failure_tearing_down_refused_widget' diff --git a/src/core/graph/nodeShell/nodeShellState.ts b/src/core/graph/nodeShell/nodeShellState.ts index 3c78cf62284..28872eb2ec4 100644 --- a/src/core/graph/nodeShell/nodeShellState.ts +++ b/src/core/graph/nodeShell/nodeShellState.ts @@ -1,3 +1,7 @@ +import type { + LGraph, + LGraphNode +} from '@/lib/litegraph/src/types/entityRegistry' import { shallowReactive } from 'vue' import { assert } from '@/base/assert' @@ -15,8 +19,7 @@ import type { INodeInputSlot, INodeOutputSlot } from '@/lib/litegraph/src/types/slots' -import type { LGraph } from '@/lib/litegraph/src/LGraph' -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' + import type { TitleMode } from '@/lib/litegraph/src/types/globalEnums' import type { NodeState } from '@/types/nodeState' diff --git a/src/core/graph/subgraph/adoptPromotedWidgetValue.ts b/src/core/graph/subgraph/adoptPromotedWidgetValue.ts index 957339754be..cc668ff3921 100644 --- a/src/core/graph/subgraph/adoptPromotedWidgetValue.ts +++ b/src/core/graph/subgraph/adoptPromotedWidgetValue.ts @@ -1,5 +1,6 @@ +import type { LGraphNode } from '@/lib/litegraph/src/types/entityRegistry' import type { INodeInputSlot } from '@/lib/litegraph/src/types/slots' -import type { LGraphNode } from '@/lib/litegraph/src/litegraph' + import { isWidgetValue } from '@/lib/litegraph/src/types/widgets' import { useWidgetValueStore } from '@/stores/widgetValueStore' diff --git a/src/core/graph/subgraph/promotedWidgetTypes.ts b/src/core/graph/subgraph/promotedWidgetTypes.ts index 9bf9c0ba2bf..b5d63a8648a 100644 --- a/src/core/graph/subgraph/promotedWidgetTypes.ts +++ b/src/core/graph/subgraph/promotedWidgetTypes.ts @@ -1,4 +1,5 @@ -import type { LGraphNode } from '@/lib/litegraph/src/litegraph' +import type { LGraphNode } from '@/lib/litegraph/src/types/entityRegistry' + import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets' import type { NodeId } from '@/types/nodeId' import type { NodeExecutionId } from '@/types/nodeIdentification' diff --git a/src/core/graph/subgraph/resolveConcretePromotedWidget.ts b/src/core/graph/subgraph/resolveConcretePromotedWidget.ts index 4563c670ec0..28c36ecf1bd 100644 --- a/src/core/graph/subgraph/resolveConcretePromotedWidget.ts +++ b/src/core/graph/subgraph/resolveConcretePromotedWidget.ts @@ -1,11 +1,14 @@ +import type { + LGraphNode, + SubgraphNode, + SubgraphInput +} from '@/lib/litegraph/src/types/entityRegistry' import type { PromotedWidgetExecutionSource, ResolvedPromotedWidget } from '@/core/graph/subgraph/promotedWidgetTypes' import { resolveSubgraphInputTarget } from '@/core/graph/subgraph/resolveSubgraphInputTarget' -import type { LGraphNode } from '@/lib/litegraph/src/litegraph' -import type { SubgraphNode } from '@/lib/litegraph/src/subgraph/SubgraphNode' -import type { SubgraphInput } from '@/lib/litegraph/src/subgraph/SubgraphInput' + import { LGraphEventMode } from '@/lib/litegraph/src/types/globalEnums' import type { NodeExecutionId } from '@/types/nodeIdentification' import { createNodeExecutionId } from '@/types/nodeIdentification' diff --git a/src/core/graph/subgraph/resolveSubgraphInputLink.ts b/src/core/graph/subgraph/resolveSubgraphInputLink.ts index 4f95bf694e0..bd73f153594 100644 --- a/src/core/graph/subgraph/resolveSubgraphInputLink.ts +++ b/src/core/graph/subgraph/resolveSubgraphInputLink.ts @@ -1,5 +1,5 @@ +import type { LGraphNode } from '@/lib/litegraph/src/types/entityRegistry' import type { INodeInputSlot } from '@/lib/litegraph/src/types/slots' -import type { LGraphNode } from '@/lib/litegraph/src/litegraph' type SubgraphInputLinkContext = { inputNode: LGraphNode diff --git a/src/core/graph/subgraph/resolveSubgraphInputTarget.ts b/src/core/graph/subgraph/resolveSubgraphInputTarget.ts index b79b789059b..64031c52dea 100644 --- a/src/core/graph/subgraph/resolveSubgraphInputTarget.ts +++ b/src/core/graph/subgraph/resolveSubgraphInputTarget.ts @@ -1,4 +1,5 @@ -import type { LGraphNode } from '@/lib/litegraph/src/litegraph' +import type { LGraphNode } from '@/lib/litegraph/src/types/entityRegistry' + import type { NodeId } from '@/types/nodeId' import { resolveSubgraphInputLink } from './resolveSubgraphInputLink' diff --git a/src/lib/litegraph/src/ContextMenu.ts b/src/lib/litegraph/src/ContextMenu.ts index 4f1425788bb..d1d28134881 100644 --- a/src/lib/litegraph/src/ContextMenu.ts +++ b/src/lib/litegraph/src/ContextMenu.ts @@ -436,3 +436,11 @@ export class ContextMenu { return false } } + +type RegisteredContextMenu = ContextMenu + +declare module './types/entityRegistry' { + interface ContextMenu< + _TValue = unknown + > extends RegisteredContextMenu<_TValue> {} +} diff --git a/src/lib/litegraph/src/CurveEditor.ts b/src/lib/litegraph/src/CurveEditor.ts index b774b8e4972..04d157be003 100644 --- a/src/lib/litegraph/src/CurveEditor.ts +++ b/src/lib/litegraph/src/CurveEditor.ts @@ -1,7 +1,8 @@ +import type { LGraphCanvas } from '@/lib/litegraph/src/types/entityRegistry' import { clamp } from 'es-toolkit/compat' import type { Point, Rect } from './interfaces' -import type { LGraphCanvas } from './litegraph' + import { distance } from './measure' // used by some widgets to render a curve editor diff --git a/src/lib/litegraph/src/LGraph.ts b/src/lib/litegraph/src/LGraph.ts index 048c26a2fa7..ec00bc39e21 100644 --- a/src/lib/litegraph/src/LGraph.ts +++ b/src/lib/litegraph/src/LGraph.ts @@ -1,3 +1,4 @@ +import type { LGraphCanvas } from '@/lib/litegraph/src/types/entityRegistry' import { toString } from 'es-toolkit/compat' import { shallowRef, toRaw } from 'vue' @@ -108,7 +109,7 @@ import { } from './utils/namedValuesShadowDiffTelemetry' import type { DragAndScaleState } from './DragAndScale' -import type { LGraphCanvas } from './LGraphCanvas' + import { canvasClass } from './canvas/canvasClassAccess' import { Rectangle } from './infrastructure/Rectangle' import { LGraphGroup } from './LGraphGroup' @@ -121,7 +122,7 @@ import { unregisterLinkTopology } from './LLink' import { LinkMap } from './LinkMap' -import type { LinkId } from './LLink' +import type { LinkId } from '@/types/linkId' import { MapProxyHandler } from './MapProxyHandler' import { registerRerouteChain, @@ -129,7 +130,7 @@ import { unregisterAllRerouteChains, unregisterRerouteChain } from './Reroute' -import type { RerouteId } from './Reroute' +import type { RerouteId } from '@/types/rerouteId' import { CustomEventTarget } from './infrastructure/CustomEventTarget' import type { LGraphEventMap } from './infrastructure/LGraphEventMap' import type { SubgraphEventMap } from './infrastructure/SubgraphEventMap' @@ -3811,3 +3812,23 @@ export class Subgraph } provideSubgraphGuard((value): value is Subgraph => value instanceof Subgraph) + +type RegisteredLGraphConfig = LGraphConfig +type RegisteredLGraphExtra = LGraphExtra +type RegisteredLGraph = LGraph +type RegisteredSubgraph = Subgraph +type RegisteredSubgraphId = SubgraphId +type RegisteredGraphOrSubgraph = GraphOrSubgraph +type RegisteredBaseLGraph = BaseLGraph + +declare module './types/entityRegistry' { + interface LitegraphEntityRegistry { + SubgraphId: RegisteredSubgraphId + GraphOrSubgraph: RegisteredGraphOrSubgraph + } + interface LGraphConfig extends RegisteredLGraphConfig {} + interface LGraphExtra extends RegisteredLGraphExtra {} + interface LGraph extends RegisteredLGraph {} + interface Subgraph extends RegisteredSubgraph {} + interface BaseLGraph extends RegisteredBaseLGraph {} +} diff --git a/src/lib/litegraph/src/LGraphCanvas.ts b/src/lib/litegraph/src/LGraphCanvas.ts index 511e691b364..44790776a8b 100644 --- a/src/lib/litegraph/src/LGraphCanvas.ts +++ b/src/lib/litegraph/src/LGraphCanvas.ts @@ -1,3 +1,10 @@ +import type { + ContextMenu, + LGraph, + SubgraphId, + SlotTypeDefaultNodeOpts, + Subgraph +} from '@/lib/litegraph/src/types/entityRegistry' import { default as DOMPurify } from 'dompurify' import { cloneDeep, toString } from 'es-toolkit/compat' import { toValue } from 'vue' @@ -56,23 +63,23 @@ import { CANVAS_CLIPBOARD_ID_KEY, CANVAS_CLIPBOARD_KEY } from './canvas/clipboardStorage' -import type { ContextMenu } from './ContextMenu' + import { createCursorCache } from './cursorCache' import { DragAndScale } from './DragAndScale' import type { AnimationOptions } from './DragAndScale' -import type { LGraph, SubgraphId } from './LGraph' + import { LGraphGroup } from './LGraphGroup' -import type { SlotTypeDefaultNodeOpts } from './LiteGraphGlobal' + import { LGraphNode } from './LGraphNode' -import type { NodeProperty } from './LGraphNode' +import type { NodeProperty } from '@/types/nodeProperty' import { detachSerialisedLinks } from './linkDeduplication' import { parseNodeId, serializeNodeId } from '@/types/nodeId' import type { NodeId, SerializedNodeId } from '@/types/nodeId' import { LLink, slotFloatingLinks } from './LLink' import { inputHasLink, nodeLinkIds, outputLinks } from './node/slotLinks' -import type { LinkId } from './LLink' +import type { LinkId } from '@/types/linkId' import { Reroute } from './Reroute' -import type { RerouteId } from './Reroute' +import type { RerouteId } from '@/types/rerouteId' import type { CanvasInteractionModeReader } from './canvas/CanvasInteractionMode' import { LinkConnector } from './canvas/LinkConnector' import { findRerouteAtPoint } from './canvas/hitTesting' @@ -157,7 +164,7 @@ import { snapPoint } from './measure' import { NodeInputSlot } from './node/NodeInputSlot' -import type { Subgraph } from './subgraph/Subgraph' + import { SubgraphIONodeBase } from './subgraph/SubgraphIONodeBase' import { SubgraphInputNode } from './subgraph/SubgraphInputNode' import { SubgraphNode } from './subgraph/SubgraphNode' @@ -9114,3 +9121,9 @@ defineDeprecatedProperty( ) provideCanvasClass(LGraphCanvas) + +type RegisteredLGraphCanvas = LGraphCanvas + +declare module './types/entityRegistry' { + interface LGraphCanvas extends RegisteredLGraphCanvas {} +} diff --git a/src/lib/litegraph/src/LGraphGroup.ts b/src/lib/litegraph/src/LGraphGroup.ts index 973fd95d967..d1d3e3bda64 100644 --- a/src/lib/litegraph/src/LGraphGroup.ts +++ b/src/lib/litegraph/src/LGraphGroup.ts @@ -1,3 +1,7 @@ +import type { + LGraph, + LGraphCanvas +} from '@/lib/litegraph/src/types/entityRegistry' import { NullGraphError } from '@/lib/litegraph/src/infrastructure/NullGraphError' import { setGroupBoundsLayout } from '@/renderer/core/layout/operations/graphLayoutAttachment' import { layoutStore } from '@/renderer/core/layout/store/layoutStore' @@ -9,8 +13,6 @@ import type { GroupId } from '@/types/groupId' import { toGroupId } from '@/types/groupId' import { hexToRgb, luminance, readableTextColor } from '@/utils/colorUtil' -import type { LGraph } from './LGraph' -import type { LGraphCanvas } from './LGraphCanvas' import { canvasClass } from './canvas/canvasClassAccess' import { LGraphNode } from './LGraphNode' import { strokeShape } from './draw' @@ -499,3 +501,11 @@ export class LGraphGroup implements Positionable, IPinnable, IColorable { } setDirtyCanvas = LGraphNode.prototype.setDirtyCanvas } + +type RegisteredLGraphGroup = LGraphGroup +type RegisteredIGraphGroupFlags = IGraphGroupFlags + +declare module './types/entityRegistry' { + interface LGraphGroup extends RegisteredLGraphGroup {} + interface IGraphGroupFlags extends RegisteredIGraphGroupFlags {} +} diff --git a/src/lib/litegraph/src/LGraphNode.ts b/src/lib/litegraph/src/LGraphNode.ts index d9c13f719c4..a85254f680a 100644 --- a/src/lib/litegraph/src/LGraphNode.ts +++ b/src/lib/litegraph/src/LGraphNode.ts @@ -1,3 +1,13 @@ +import type { + LGraph, + Subgraph, + LGraphCanvas, + Reroute, + SubgraphNode, + SubgraphInputNode, + SubgraphOutputNode +} from '@/lib/litegraph/src/types/entityRegistry' +import type { LGraphNodeConstructor } from '@/lib/litegraph/src/types/nodeConstructor' import { toValue } from 'vue' import { @@ -30,7 +40,8 @@ import type { GraphScope } from '@/types/graphScopeId' import { linkIdReservations, mintLinkId } from './idAllocation' import { UNASSIGNED_NODE_ID, toNodeId, serializeNodeId } from '@/types/nodeId' import type { NodeId } from '@/types/nodeId' -import type { NodeProperty, NodeState } from '@/types/nodeState' +import type { NodeState } from '@/types/nodeState' +import type { NodeProperty } from '@/types/nodeProperty' import { deriveWidgetVisibility, isWidgetVisibleOnSurface, @@ -51,12 +62,12 @@ import { } from '@/lib/litegraph/src/constants' import { cachedMeasureText } from '@/lib/litegraph/src/utils/textMeasureCache' import type { DragAndScale } from './DragAndScale' -import type { LGraph, Subgraph } from './LGraph' + import { LGraphBadge } from './LGraphBadge' import { badgeDrawObjects, badgeRows } from './nodeBadgeDraw' import { LGraphButton } from './LGraphButton' import type { LGraphButtonOptions } from './LGraphButton' -import type { LGraphCanvas } from './LGraphCanvas' + import { canvasClass } from './canvas/canvasClassAccess' import { realignGroupWidgetChildLinks } from './linkDeduplication' import { LLink, replaceLinkTopology, slotFloatingLinks } from './LLink' @@ -89,7 +100,7 @@ import { runExtensionSerializeHook } from './extensionPersistence' import { anchorRerouteChain } from './Reroute' -import type { Reroute, RerouteId } from './Reroute' +import type { RerouteId } from '@/types/rerouteId' import { getNodeInputOnPos, getNodeOutputOnPos } from './canvas/measureSlots' import type { IDrawBoundingOptions } from './draw' import { emitNodeFieldWrite } from './graphIntents' @@ -123,7 +134,7 @@ import type { import type { Panel } from './types/panel' import { LiteGraph } from './litegraphInstance' import { isSubgraph } from './subgraph/subgraphTypeGuards' -import type { LGraphNodeConstructor, SubgraphNode } from './litegraph' + import { createBounds, isInRect, @@ -138,8 +149,7 @@ import { isWidgetInputSlot, outputAsSerialisable } from './node/slotUtils' -import type { SubgraphInputNode } from './subgraph/SubgraphInputNode' -import type { SubgraphOutputNode } from './subgraph/SubgraphOutputNode' + import type { NodeLike } from './types/NodeLike' import type { CanvasPointerEvent } from './types/events' import { @@ -4620,3 +4630,9 @@ export class LGraphNode } provideGraphNodeGuard((item): item is LGraphNode => item instanceof LGraphNode) + +type RegisteredLGraphNode = LGraphNode + +declare module './types/entityRegistry' { + interface LGraphNode extends RegisteredLGraphNode {} +} diff --git a/src/lib/litegraph/src/LLink.ts b/src/lib/litegraph/src/LLink.ts index 5ffb8ce952a..40bc93dce7a 100644 --- a/src/lib/litegraph/src/LLink.ts +++ b/src/lib/litegraph/src/LLink.ts @@ -1,9 +1,15 @@ +import type { + SubgraphInput, + SubgraphOutput, + LGraph, + LGraphNode, + Reroute +} from '@/lib/litegraph/src/types/entityRegistry' import { SUBGRAPH_INPUT_ID, SUBGRAPH_OUTPUT_ID } from '@/lib/litegraph/src/constants' -import type { SubgraphInput } from '@/lib/litegraph/src/subgraph/SubgraphInput' -import type { SubgraphOutput } from '@/lib/litegraph/src/subgraph/SubgraphOutput' + import { layoutStore } from '@/renderer/core/layout/store/layoutStore' import { useLinkPresentationStore } from '@/stores/linkPresentationStore' import { useLinkStore } from '@/stores/linkStore' @@ -18,10 +24,9 @@ import type { EndpointPatch } from '@/stores/linkStore' import type { LinkId } from '@/types/linkId' import type { LinkTopology } from '@/types/linkTopology' import type { RerouteId } from '@/types/rerouteId' -import type { LGraph } from './LGraph' -import type { LGraphNode } from './LGraphNode' + import type { NodeId, SerializedNodeId } from '@/types/nodeId' -import type { Reroute } from './Reroute' + import type { CanvasColour, ISlotType, LinkSegment, Point } from './interfaces' import type { INodeInputSlot, INodeOutputSlot } from './types/slots' import type { LinkNetwork, ReadonlyLinkNetwork } from './types/linkNetwork' @@ -727,3 +732,15 @@ export function unregisterAllLinkTopologies( unregisterLinkTopology(link) } } + +type RegisteredLLink = LLink +type RegisteredSerialisedLLinkArray = SerialisedLLinkArray +type RegisteredResolvedConnection = ResolvedConnection + +declare module './types/entityRegistry' { + interface LitegraphEntityRegistry { + SerialisedLLinkArray: RegisteredSerialisedLLinkArray + ResolvedConnection: RegisteredResolvedConnection + } + interface LLink extends RegisteredLLink {} +} diff --git a/src/lib/litegraph/src/LinkMap.ts b/src/lib/litegraph/src/LinkMap.ts index 518a1ff444d..862ba34b6bc 100644 --- a/src/lib/litegraph/src/LinkMap.ts +++ b/src/lib/litegraph/src/LinkMap.ts @@ -1,8 +1,7 @@ +import type { LLink } from '@/lib/litegraph/src/types/entityRegistry' import type { GraphScope } from '@/types/graphScopeId' import type { LinkId } from '@/types/linkId' -import type { LLink } from './LLink' - export class LinkMap extends Map { private cachedRevision = -1 private cachedLinks = new Map() diff --git a/src/lib/litegraph/src/LiteGraphGlobal.ts b/src/lib/litegraph/src/LiteGraphGlobal.ts index 41adc63fdf8..123b30fc8b6 100644 --- a/src/lib/litegraph/src/LiteGraphGlobal.ts +++ b/src/lib/litegraph/src/LiteGraphGlobal.ts @@ -5,7 +5,7 @@ import { LGraph } from './LGraph' import { LGraphCanvas } from './LGraphCanvas' import { LGraphGroup } from './LGraphGroup' import { LGraphNode } from './LGraphNode' -import type { NodeProperty } from './LGraphNode' +import type { NodeProperty } from '@/types/nodeProperty' import { LLink } from './LLink' import { Reroute } from './Reroute' import { InputIndicators } from './canvas/InputIndicators' @@ -1024,3 +1024,11 @@ export class LiteGraphGlobal { } } } + +type RegisteredSlotTypeDefaultNodeOpts = SlotTypeDefaultNodeOpts +type RegisteredLiteGraphGlobal = LiteGraphGlobal + +declare module './types/entityRegistry' { + interface SlotTypeDefaultNodeOpts extends RegisteredSlotTypeDefaultNodeOpts {} + interface LiteGraphGlobal extends RegisteredLiteGraphGlobal {} +} diff --git a/src/lib/litegraph/src/Reroute.ts b/src/lib/litegraph/src/Reroute.ts index 84d4705458b..34420abe54b 100644 --- a/src/lib/litegraph/src/Reroute.ts +++ b/src/lib/litegraph/src/Reroute.ts @@ -1,3 +1,7 @@ +import type { + LGraph, + LGraphNode +} from '@/lib/litegraph/src/types/entityRegistry' import { moveRerouteLayout } from '@/renderer/core/layout/operations/graphLayoutAttachment' import { layoutStore } from '@/renderer/core/layout/store/layoutStore' import { isSelectedIn, setSelectedIn } from '@/core/selection/selectionStore' @@ -29,10 +33,9 @@ function hasPointLength(value: unknown): boolean { } import { LGraphBadge } from './LGraphBadge' -import type { LGraph } from './LGraph' -import type { LGraphNode } from './LGraphNode' + import { LLink } from './LLink' -import type { LinkId } from './LLink' +import type { LinkId } from '@/types/linkId' import { createMutationView } from './infrastructure/createMutationView' import type { CanvasColour, @@ -899,3 +902,9 @@ export function unregisterAllRerouteChains( ): void { for (const reroute of graph.reroutes.values()) unregisterRerouteChain(reroute) } + +type RegisteredReroute = Reroute + +declare module './types/entityRegistry' { + interface Reroute extends RegisteredReroute {} +} diff --git a/src/lib/litegraph/src/canvas/FloatingRenderLink.ts b/src/lib/litegraph/src/canvas/FloatingRenderLink.ts index 2144713c9dd..74ba296e4bc 100644 --- a/src/lib/litegraph/src/canvas/FloatingRenderLink.ts +++ b/src/lib/litegraph/src/canvas/FloatingRenderLink.ts @@ -1,8 +1,14 @@ -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import type { + LGraphNode, + LLink, + Reroute, + SubgraphInput, + SubgraphOutput +} from '@/lib/litegraph/src/types/entityRegistry' + import { UNASSIGNED_NODE_ID } from '@/types/nodeId' import type { NodeId } from '@/types/nodeId' -import type { LLink } from '@/lib/litegraph/src/LLink' -import type { Reroute } from '@/lib/litegraph/src/Reroute' + import { SUBGRAPH_INPUT_ID, SUBGRAPH_OUTPUT_ID @@ -15,8 +21,7 @@ import type { INodeOutputSlot } from '@/lib/litegraph/src/types/slots' import type { LinkNetwork } from '@/lib/litegraph/src/types/linkNetwork' -import type { SubgraphInput } from '@/lib/litegraph/src/subgraph/SubgraphInput' -import type { SubgraphOutput } from '@/lib/litegraph/src/subgraph/SubgraphOutput' + import { LinkDirection } from '@/lib/litegraph/src/types/globalEnums' import type { RenderLink } from './RenderLink' @@ -220,3 +225,9 @@ export class FloatingRenderLink implements RenderLink { events.dispatch('output-moved', this) } } + +type RegisteredFloatingRenderLink = FloatingRenderLink + +declare module '../types/entityRegistry' { + interface FloatingRenderLink extends RegisteredFloatingRenderLink {} +} diff --git a/src/lib/litegraph/src/canvas/InputIndicators.ts b/src/lib/litegraph/src/canvas/InputIndicators.ts index f684a8a047b..a52978a09a1 100644 --- a/src/lib/litegraph/src/canvas/InputIndicators.ts +++ b/src/lib/litegraph/src/canvas/InputIndicators.ts @@ -1,5 +1,5 @@ +import type { LGraphCanvas } from '@/lib/litegraph/src/types/entityRegistry' import { isMiddleButtonHeld } from '@/base/pointerUtils' -import type { LGraphCanvas } from '@/lib/litegraph/src/LGraphCanvas' /** * A class that can be added to the render cycle to show pointer / keyboard status symbols. diff --git a/src/lib/litegraph/src/canvas/LinkConnector.ts b/src/lib/litegraph/src/canvas/LinkConnector.ts index 9b245978cd6..54edc079308 100644 --- a/src/lib/litegraph/src/canvas/LinkConnector.ts +++ b/src/lib/litegraph/src/canvas/LinkConnector.ts @@ -1,12 +1,17 @@ +import type { + LGraphNode, + Reroute, + SubgraphInput, + SubgraphOutput +} from '@/lib/litegraph/src/types/entityRegistry' import { remove } from 'es-toolkit' import { transferLinkPresentation } from '@/core/graph/transferLinkPresentation' import { useLinkPresentationStore } from '@/stores/linkPresentationStore' import { graphScopeOf } from '@/types/graphScopeId' -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' import { LLink, slotFloatingLinks } from '@/lib/litegraph/src/LLink' import { inputLinkId, outputLinks } from '@/lib/litegraph/src/node/slotLinks' -import type { Reroute } from '@/lib/litegraph/src/Reroute' + import { SUBGRAPH_INPUT_ID, SUBGRAPH_OUTPUT_ID @@ -26,9 +31,9 @@ import type { import { EmptySubgraphInput } from '@/lib/litegraph/src/subgraph/EmptySubgraphInput' import { EmptySubgraphOutput } from '@/lib/litegraph/src/subgraph/EmptySubgraphOutput' import { Subgraph } from '@/lib/litegraph/src/subgraph/Subgraph' -import type { SubgraphInput } from '@/lib/litegraph/src/subgraph/SubgraphInput' + import { SubgraphInputNode } from '@/lib/litegraph/src/subgraph/SubgraphInputNode' -import type { SubgraphOutput } from '@/lib/litegraph/src/subgraph/SubgraphOutput' + import { SubgraphOutputNode } from '@/lib/litegraph/src/subgraph/SubgraphOutputNode' import type { CanvasPointerEvent } from '@/lib/litegraph/src/types/events' import { LinkDirection } from '@/lib/litegraph/src/types/globalEnums' @@ -1243,3 +1248,9 @@ function canConnectInputLinkToReroute( } return true } + +type RegisteredLinkConnector = LinkConnector + +declare module '../types/entityRegistry' { + interface LinkConnector extends RegisteredLinkConnector {} +} diff --git a/src/lib/litegraph/src/canvas/MovingInputLink.ts b/src/lib/litegraph/src/canvas/MovingInputLink.ts index f7e8ec0ba32..0604ddcd72c 100644 --- a/src/lib/litegraph/src/canvas/MovingInputLink.ts +++ b/src/lib/litegraph/src/canvas/MovingInputLink.ts @@ -1,8 +1,13 @@ -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import type { + LGraphNode, + LLink, + Reroute, + SubgraphOutput +} from '@/lib/litegraph/src/types/entityRegistry' + import { transferLinkPresentation } from '@/core/graph/transferLinkPresentation' import { graphScopeOf } from '@/types/graphScopeId' -import type { LLink } from '@/lib/litegraph/src/LLink' -import type { Reroute } from '@/lib/litegraph/src/Reroute' + import type { CustomEventTarget } from '@/lib/litegraph/src/infrastructure/CustomEventTarget' import type { LinkConnectorEventMap } from '@/lib/litegraph/src/infrastructure/LinkConnectorEventMap' import type { Point, SlotIndex } from '@/lib/litegraph/src/interfaces' @@ -11,7 +16,7 @@ import type { INodeOutputSlot } from '@/lib/litegraph/src/types/slots' import type { LinkNetwork } from '@/lib/litegraph/src/types/linkNetwork' -import type { SubgraphOutput } from '@/lib/litegraph/src/subgraph/SubgraphOutput' + import type { NodeLike } from '@/lib/litegraph/src/types/NodeLike' import { LinkDirection } from '@/lib/litegraph/src/types/globalEnums' import type { SubgraphIO } from '@/lib/litegraph/src/types/serialisation' @@ -152,3 +157,9 @@ export class MovingInputLink extends MovingLinkBase { return this.inputNode.disconnectInput(this.inputIndex, true) } } + +type RegisteredMovingInputLink = MovingInputLink + +declare module '../types/entityRegistry' { + interface MovingInputLink extends RegisteredMovingInputLink {} +} diff --git a/src/lib/litegraph/src/canvas/MovingLinkBase.ts b/src/lib/litegraph/src/canvas/MovingLinkBase.ts index 535a28e6c3c..3ed904fab04 100644 --- a/src/lib/litegraph/src/canvas/MovingLinkBase.ts +++ b/src/lib/litegraph/src/canvas/MovingLinkBase.ts @@ -1,10 +1,16 @@ -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import type { + LGraphNode, + LLink, + Reroute, + SubgraphInput, + SubgraphOutput +} from '@/lib/litegraph/src/types/entityRegistry' + import type { NodeId } from '@/types/nodeId' import type { LinkPresentation } from '@/types/linkPresentation' import { useLinkPresentationStore } from '@/stores/linkPresentationStore' import { graphScopeOf } from '@/types/graphScopeId' -import type { LLink } from '@/lib/litegraph/src/LLink' -import type { Reroute } from '@/lib/litegraph/src/Reroute' + import type { CustomEventTarget } from '@/lib/litegraph/src/infrastructure/CustomEventTarget' import type { LinkConnectorEventMap } from '@/lib/litegraph/src/infrastructure/LinkConnectorEventMap' import type { Point, SlotIndex } from '@/lib/litegraph/src/interfaces' @@ -13,8 +19,7 @@ import type { INodeOutputSlot } from '@/lib/litegraph/src/types/slots' import type { LinkNetwork } from '@/lib/litegraph/src/types/linkNetwork' -import type { SubgraphInput } from '@/lib/litegraph/src/subgraph/SubgraphInput' -import type { SubgraphOutput } from '@/lib/litegraph/src/subgraph/SubgraphOutput' + import type { NodeLike } from '@/lib/litegraph/src/types/NodeLike' import { LinkDirection } from '@/lib/litegraph/src/types/globalEnums' diff --git a/src/lib/litegraph/src/canvas/MovingOutputLink.ts b/src/lib/litegraph/src/canvas/MovingOutputLink.ts index bb140b10c8d..46b764bf07c 100644 --- a/src/lib/litegraph/src/canvas/MovingOutputLink.ts +++ b/src/lib/litegraph/src/canvas/MovingOutputLink.ts @@ -1,8 +1,13 @@ -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import type { + LGraphNode, + LLink, + Reroute, + SubgraphInput +} from '@/lib/litegraph/src/types/entityRegistry' + import { transferLinkPresentation } from '@/core/graph/transferLinkPresentation' import { graphScopeOf } from '@/types/graphScopeId' -import type { LLink } from '@/lib/litegraph/src/LLink' -import type { Reroute } from '@/lib/litegraph/src/Reroute' + import type { CustomEventTarget } from '@/lib/litegraph/src/infrastructure/CustomEventTarget' import type { LinkConnectorEventMap } from '@/lib/litegraph/src/infrastructure/LinkConnectorEventMap' import type { Point, SlotIndex } from '@/lib/litegraph/src/interfaces' @@ -11,7 +16,7 @@ import type { INodeOutputSlot } from '@/lib/litegraph/src/types/slots' import type { LinkNetwork } from '@/lib/litegraph/src/types/linkNetwork' -import type { SubgraphInput } from '@/lib/litegraph/src/subgraph/SubgraphInput' + import type { NodeLike } from '@/lib/litegraph/src/types/NodeLike' import { LinkDirection } from '@/lib/litegraph/src/types/globalEnums' import type { SubgraphIO } from '@/lib/litegraph/src/types/serialisation' @@ -153,3 +158,9 @@ export class MovingOutputLink extends MovingLinkBase { return this.outputNode.disconnectOutput(this.outputIndex, this.inputNode) } } + +type RegisteredMovingOutputLink = MovingOutputLink + +declare module '../types/entityRegistry' { + interface MovingOutputLink extends RegisteredMovingOutputLink {} +} diff --git a/src/lib/litegraph/src/canvas/RenderLink.ts b/src/lib/litegraph/src/canvas/RenderLink.ts index 310f30bdb56..3a68d8034b1 100644 --- a/src/lib/litegraph/src/canvas/RenderLink.ts +++ b/src/lib/litegraph/src/canvas/RenderLink.ts @@ -1,17 +1,21 @@ -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import type { + LGraphNode, + LLink, + Reroute, + SubgraphIONode, + SubgraphInput, + SubgraphOutput +} from '@/lib/litegraph/src/types/entityRegistry' + import type { CustomEventTarget } from '@/lib/litegraph/src/infrastructure/CustomEventTarget' import type { LinkConnectorEventMap } from '@/lib/litegraph/src/infrastructure/LinkConnectorEventMap' import type { Point, SlotIndex } from '@/lib/litegraph/src/interfaces' import type { LinkNetwork } from '@/lib/litegraph/src/types/linkNetwork' import type { INodeInputSlot, - INodeOutputSlot, - LLink, - Reroute -} from '@/lib/litegraph/src/litegraph' -import type { SubgraphIONodeBase } from '@/lib/litegraph/src/subgraph/SubgraphIONodeBase' -import type { SubgraphInput } from '@/lib/litegraph/src/subgraph/SubgraphInput' -import type { SubgraphOutput } from '@/lib/litegraph/src/subgraph/SubgraphOutput' + INodeOutputSlot +} from '@/lib/litegraph/src/types/slots' + import type { NodeLike } from '@/lib/litegraph/src/types/NodeLike' import type { LinkDirection } from '@/lib/litegraph/src/types/globalEnums' @@ -28,7 +32,7 @@ export interface RenderLink { /** The network that the link belongs to. */ readonly network: LinkNetwork /** The node that the link is being connected from. */ - readonly node: LGraphNode | SubgraphIONodeBase + readonly node: LGraphNode | SubgraphIONode /** The slot that the link is being connected from. */ readonly fromSlot: | INodeOutputSlot @@ -93,3 +97,9 @@ export interface RenderLink { events: CustomEventTarget ): void } + +type RegisteredRenderLink = RenderLink + +declare module '../types/entityRegistry' { + interface RenderLink extends RegisteredRenderLink {} +} diff --git a/src/lib/litegraph/src/canvas/SelectedItemsView.ts b/src/lib/litegraph/src/canvas/SelectedItemsView.ts index eca6e619731..4eb5c96b750 100644 --- a/src/lib/litegraph/src/canvas/SelectedItemsView.ts +++ b/src/lib/litegraph/src/canvas/SelectedItemsView.ts @@ -1,4 +1,5 @@ -import type { LGraph } from '../LGraph' +import type { LGraph } from '@/lib/litegraph/src/types/entityRegistry' + import { clearGraphSelection, updateGraphSelection diff --git a/src/lib/litegraph/src/canvas/ToInputFromIoNodeLink.ts b/src/lib/litegraph/src/canvas/ToInputFromIoNodeLink.ts index 37a2d6b3ac2..2885e46672d 100644 --- a/src/lib/litegraph/src/canvas/ToInputFromIoNodeLink.ts +++ b/src/lib/litegraph/src/canvas/ToInputFromIoNodeLink.ts @@ -1,17 +1,21 @@ +import type { + LGraphNode, + LLink, + Reroute, + SubgraphInput, + SubgraphInputNode +} from '@/lib/litegraph/src/types/entityRegistry' import { transferLinkPresentation } from '@/core/graph/transferLinkPresentation' import { useLinkPresentationStore } from '@/stores/linkPresentationStore' import { graphScopeOf } from '@/types/graphScopeId' import type { LinkPresentation } from '@/types/linkPresentation' -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' -import type { LLink } from '@/lib/litegraph/src/LLink' -import type { Reroute } from '@/lib/litegraph/src/Reroute' + import type { CustomEventTarget } from '@/lib/litegraph/src/infrastructure/CustomEventTarget' import type { LinkConnectorEventMap } from '@/lib/litegraph/src/infrastructure/LinkConnectorEventMap' import type { Point, SlotIndex } from '@/lib/litegraph/src/interfaces' import type { INodeInputSlot } from '@/lib/litegraph/src/types/slots' import type { LinkNetwork } from '@/lib/litegraph/src/types/linkNetwork' -import type { SubgraphInput } from '@/lib/litegraph/src/subgraph/SubgraphInput' -import type { SubgraphInputNode } from '@/lib/litegraph/src/subgraph/SubgraphInputNode' + import type { NodeLike } from '@/lib/litegraph/src/types/NodeLike' import { LinkDirection } from '@/lib/litegraph/src/types/globalEnums' @@ -182,3 +186,9 @@ export class ToInputFromIoNodeLink implements RenderLink { return true } } + +type RegisteredToInputFromIoNodeLink = ToInputFromIoNodeLink + +declare module '../types/entityRegistry' { + interface ToInputFromIoNodeLink extends RegisteredToInputFromIoNodeLink {} +} diff --git a/src/lib/litegraph/src/canvas/ToInputRenderLink.ts b/src/lib/litegraph/src/canvas/ToInputRenderLink.ts index ccbe3f6b34a..ffc85663f58 100644 --- a/src/lib/litegraph/src/canvas/ToInputRenderLink.ts +++ b/src/lib/litegraph/src/canvas/ToInputRenderLink.ts @@ -1,6 +1,10 @@ -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' -import type { LLink } from '@/lib/litegraph/src/LLink' -import type { Reroute } from '@/lib/litegraph/src/Reroute' +import type { + LGraphNode, + LLink, + Reroute, + SubgraphOutput +} from '@/lib/litegraph/src/types/entityRegistry' + import type { CustomEventTarget } from '@/lib/litegraph/src/infrastructure/CustomEventTarget' import type { LinkConnectorEventMap } from '@/lib/litegraph/src/infrastructure/LinkConnectorEventMap' import type { Point, SlotIndex } from '@/lib/litegraph/src/interfaces' @@ -9,7 +13,7 @@ import type { INodeOutputSlot } from '@/lib/litegraph/src/types/slots' import type { LinkNetwork } from '@/lib/litegraph/src/types/linkNetwork' -import type { SubgraphOutput } from '@/lib/litegraph/src/subgraph/SubgraphOutput' + import type { NodeLike } from '@/lib/litegraph/src/types/NodeLike' import { LinkDirection } from '@/lib/litegraph/src/types/globalEnums' @@ -138,3 +142,9 @@ export class ToInputRenderLink implements RenderLink { throw new Error('ToInputRenderLink cannot connect to an output.') } } + +type RegisteredToInputRenderLink = ToInputRenderLink + +declare module '../types/entityRegistry' { + interface ToInputRenderLink extends RegisteredToInputRenderLink {} +} diff --git a/src/lib/litegraph/src/canvas/ToOutputFromIoNodeLink.ts b/src/lib/litegraph/src/canvas/ToOutputFromIoNodeLink.ts index 79b896e6e01..aa3b2c540c8 100644 --- a/src/lib/litegraph/src/canvas/ToOutputFromIoNodeLink.ts +++ b/src/lib/litegraph/src/canvas/ToOutputFromIoNodeLink.ts @@ -1,17 +1,21 @@ +import type { + LGraphNode, + LLink, + Reroute, + SubgraphOutput, + SubgraphOutputNode +} from '@/lib/litegraph/src/types/entityRegistry' import { transferLinkPresentation } from '@/core/graph/transferLinkPresentation' import { useLinkPresentationStore } from '@/stores/linkPresentationStore' import { graphScopeOf } from '@/types/graphScopeId' import type { LinkPresentation } from '@/types/linkPresentation' -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' -import type { LLink } from '@/lib/litegraph/src/LLink' -import type { Reroute } from '@/lib/litegraph/src/Reroute' + import type { CustomEventTarget } from '@/lib/litegraph/src/infrastructure/CustomEventTarget' import type { LinkConnectorEventMap } from '@/lib/litegraph/src/infrastructure/LinkConnectorEventMap' import type { Point, SlotIndex } from '@/lib/litegraph/src/interfaces' import type { INodeOutputSlot } from '@/lib/litegraph/src/types/slots' import type { LinkNetwork } from '@/lib/litegraph/src/types/linkNetwork' -import type { SubgraphOutput } from '@/lib/litegraph/src/subgraph/SubgraphOutput' -import type { SubgraphOutputNode } from '@/lib/litegraph/src/subgraph/SubgraphOutputNode' + import type { NodeLike } from '@/lib/litegraph/src/types/NodeLike' import { LinkDirection } from '@/lib/litegraph/src/types/globalEnums' import type { SubgraphIO } from '@/lib/litegraph/src/types/serialisation' diff --git a/src/lib/litegraph/src/canvas/ToOutputFromRerouteLink.ts b/src/lib/litegraph/src/canvas/ToOutputFromRerouteLink.ts index a2194985f2d..b116c976381 100644 --- a/src/lib/litegraph/src/canvas/ToOutputFromRerouteLink.ts +++ b/src/lib/litegraph/src/canvas/ToOutputFromRerouteLink.ts @@ -1,15 +1,18 @@ +import type { + LGraphNode, + Reroute, + LinkConnector +} from '@/lib/litegraph/src/types/entityRegistry' import { transferLinkPresentation } from '@/core/graph/transferLinkPresentation' import { useLinkPresentationStore } from '@/stores/linkPresentationStore' import { graphScopeOf } from '@/types/graphScopeId' -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' -import type { Reroute } from '@/lib/litegraph/src/Reroute' + import type { INodeInputSlot, - INodeOutputSlot, - LinkNetwork -} from '@/lib/litegraph/src/litegraph' + INodeOutputSlot +} from '@/lib/litegraph/src/types/slots' +import type { LinkNetwork } from '@/lib/litegraph/src/types/linkNetwork' -import type { LinkConnector } from './LinkConnector' import { ToInputRenderLink } from './ToInputRenderLink' import { ToOutputRenderLink } from './ToOutputRenderLink' diff --git a/src/lib/litegraph/src/canvas/ToOutputRenderLink.ts b/src/lib/litegraph/src/canvas/ToOutputRenderLink.ts index af184826f76..af831ab8ca4 100644 --- a/src/lib/litegraph/src/canvas/ToOutputRenderLink.ts +++ b/src/lib/litegraph/src/canvas/ToOutputRenderLink.ts @@ -1,5 +1,9 @@ -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' -import type { Reroute } from '@/lib/litegraph/src/Reroute' +import type { + LGraphNode, + Reroute, + SubgraphInput +} from '@/lib/litegraph/src/types/entityRegistry' + import type { CustomEventTarget } from '@/lib/litegraph/src/infrastructure/CustomEventTarget' import type { LinkConnectorEventMap } from '@/lib/litegraph/src/infrastructure/LinkConnectorEventMap' import type { Point, SlotIndex } from '@/lib/litegraph/src/interfaces' @@ -8,7 +12,7 @@ import type { INodeOutputSlot } from '@/lib/litegraph/src/types/slots' import type { LinkNetwork } from '@/lib/litegraph/src/types/linkNetwork' -import type { SubgraphInput } from '@/lib/litegraph/src/subgraph/SubgraphInput' + import type { NodeLike } from '@/lib/litegraph/src/types/NodeLike' import { LinkDirection } from '@/lib/litegraph/src/types/globalEnums' import type { SubgraphIO } from '@/lib/litegraph/src/types/serialisation' diff --git a/src/lib/litegraph/src/canvas/canvasClassAccess.ts b/src/lib/litegraph/src/canvas/canvasClassAccess.ts index 8bc5fe4a738..6d5bd29e622 100644 --- a/src/lib/litegraph/src/canvas/canvasClassAccess.ts +++ b/src/lib/litegraph/src/canvas/canvasClassAccess.ts @@ -1,5 +1,8 @@ -import type { ContextMenu } from '../ContextMenu' -import type { LGraphNode } from '../LGraphNode' +import type { + ContextMenu, + LGraphNode +} from '@/lib/litegraph/src/types/entityRegistry' + import type { ColorOption } from '../interfaces' import type { IContextMenuOptions, diff --git a/src/lib/litegraph/src/canvas/getCanvasContextMenuTarget.ts b/src/lib/litegraph/src/canvas/getCanvasContextMenuTarget.ts index f6c43198c62..42b5620bbd9 100644 --- a/src/lib/litegraph/src/canvas/getCanvasContextMenuTarget.ts +++ b/src/lib/litegraph/src/canvas/getCanvasContextMenuTarget.ts @@ -1,5 +1,8 @@ -import type { LGraphCanvas } from '../LGraphCanvas' -import type { LGraphGroup } from '../LGraphGroup' +import type { + LGraphCanvas, + LGraphGroup +} from '@/lib/litegraph/src/types/entityRegistry' + import { LLink } from '../LLink' import { Reroute } from '../Reroute' import type { LinkSegment } from '../interfaces' diff --git a/src/lib/litegraph/src/canvas/hitTesting.ts b/src/lib/litegraph/src/canvas/hitTesting.ts index fc0a2fd3c32..58295066f7e 100644 --- a/src/lib/litegraph/src/canvas/hitTesting.ts +++ b/src/lib/litegraph/src/canvas/hitTesting.ts @@ -1,8 +1,11 @@ +import type { + LGraph, + LGraphCanvas +} from '@/lib/litegraph/src/types/entityRegistry' import { layoutStore } from '@/renderer/core/layout/store/layoutStore' -import type { LGraph } from '../LGraph' import type { LinkSegment } from '../interfaces' -import type { LGraphCanvas } from '../LGraphCanvas' + import { Reroute } from '../Reroute' /** diff --git a/src/lib/litegraph/src/canvas/linkBadgeRenderer.ts b/src/lib/litegraph/src/canvas/linkBadgeRenderer.ts index c7d5a803edb..0549720c895 100644 --- a/src/lib/litegraph/src/canvas/linkBadgeRenderer.ts +++ b/src/lib/litegraph/src/canvas/linkBadgeRenderer.ts @@ -1,5 +1,5 @@ -import type { LGraph } from '../LGraph' -import type { LLink } from '../LLink' +import type { LGraph, LLink } from '@/lib/litegraph/src/types/entityRegistry' + import type { HiddenLinkBadge } from './linkBadges' import { graphScopeOf } from '@/types/graphScopeId' import { useLinkPresentationStore } from '@/stores/linkPresentationStore' diff --git a/src/lib/litegraph/src/canvas/linkBadges.ts b/src/lib/litegraph/src/canvas/linkBadges.ts index 64acb99da8f..9c83ff02bd2 100644 --- a/src/lib/litegraph/src/canvas/linkBadges.ts +++ b/src/lib/litegraph/src/canvas/linkBadges.ts @@ -1,8 +1,9 @@ +import type { LLink } from '@/lib/litegraph/src/types/entityRegistry' import { textOnColor } from '@/utils/colorUtil' import type { HasBoundingRect, Point, ReadOnlyRect, Rect } from '../interfaces' import { LGraphBadge } from '../LGraphBadge' -import type { LLink } from '../LLink' + import type { LinkId } from '@/types/linkId' import type { LinkPresentation } from '@/types/linkPresentation' import { compareNodeIds } from '@/types/nodeId' diff --git a/src/lib/litegraph/src/canvas/linkGeometry.ts b/src/lib/litegraph/src/canvas/linkGeometry.ts index 54c27964a6c..78699b2c7bd 100644 --- a/src/lib/litegraph/src/canvas/linkGeometry.ts +++ b/src/lib/litegraph/src/canvas/linkGeometry.ts @@ -1,5 +1,5 @@ -import type { LGraph } from '../LGraph' -import type { LLink } from '../LLink' +import type { LGraph, LLink } from '@/lib/litegraph/src/types/entityRegistry' + import type { Point } from '../interfaces' import { litegraph } from '../litegraphInstance' import { inputLinkId } from '../node/slotLinks' diff --git a/src/lib/litegraph/src/canvas/linkVisibility.ts b/src/lib/litegraph/src/canvas/linkVisibility.ts index 83bae69d5e8..73727c6a3a3 100644 --- a/src/lib/litegraph/src/canvas/linkVisibility.ts +++ b/src/lib/litegraph/src/canvas/linkVisibility.ts @@ -1,3 +1,8 @@ +import type { + LGraph, + LLink, + Reroute +} from '@/lib/litegraph/src/types/entityRegistry' import { st, t } from '@/i18n' import type { IContextMenuValue } from '../types/contextMenu' import { useLinkPresentationStore } from '@/stores/linkPresentationStore' @@ -5,9 +10,6 @@ import { graphScopeOf } from '@/types/graphScopeId' import type { GraphScope } from '@/types/graphScopeId' import type { LinkId } from '@/types/linkId' -import type { LGraph } from '../LGraph' -import type { LLink } from '../LLink' -import type { Reroute } from '../Reroute' import type { CanvasPointerEvent } from '../types/events' interface LinkMutationHost { diff --git a/src/lib/litegraph/src/canvas/measureSlots.ts b/src/lib/litegraph/src/canvas/measureSlots.ts index d5761c37885..7306c40f8cd 100644 --- a/src/lib/litegraph/src/canvas/measureSlots.ts +++ b/src/lib/litegraph/src/canvas/measureSlots.ts @@ -1,4 +1,5 @@ -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import type { LGraphNode } from '@/lib/litegraph/src/types/entityRegistry' + import type { Point } from '@/lib/litegraph/src/interfaces' import type { INodeInputSlot, diff --git a/src/lib/litegraph/src/canvas/resolvePointerTarget.ts b/src/lib/litegraph/src/canvas/resolvePointerTarget.ts index 009b35f08ce..0fe2b5d3e24 100644 --- a/src/lib/litegraph/src/canvas/resolvePointerTarget.ts +++ b/src/lib/litegraph/src/canvas/resolvePointerTarget.ts @@ -1,13 +1,17 @@ -import type { LGraph } from '../LGraph' -import type { LGraphCanvas } from '../LGraphCanvas' -import type { LGraphGroup } from '../LGraphGroup' -import type { LGraphNode } from '../LGraphNode' -import type { LLink } from '../LLink' -import type { Reroute } from '../Reroute' +import type { + LGraph, + LGraphCanvas, + LGraphGroup, + LGraphNode, + LLink, + Reroute, + SubgraphInputNode, + SubgraphOutputNode +} from '@/lib/litegraph/src/types/entityRegistry' + import type { LinkSegment, Point, Positionable } from '../interfaces' import { isInRectangle } from '../measure' -import type { SubgraphInputNode } from '../subgraph/SubgraphInputNode' -import type { SubgraphOutputNode } from '../subgraph/SubgraphOutputNode' + import { LinkMarkerShape, LinkRenderType } from '../types/globalEnums' import type { CanvasPointerEvent } from '../types/events' import { diff --git a/src/lib/litegraph/src/graphIntents.ts b/src/lib/litegraph/src/graphIntents.ts index 9e25114f08a..320813fc01d 100644 --- a/src/lib/litegraph/src/graphIntents.ts +++ b/src/lib/litegraph/src/graphIntents.ts @@ -1,3 +1,8 @@ +import type { + LGraph, + LGraphNode, + LLink +} from '@/lib/litegraph/src/types/entityRegistry' /** * Graph mutations announced as commands from the graph-API funnel they run * through (`LGraph.add/remove/_addLink/_removeLink/clear`, the widget value @@ -12,10 +17,6 @@ import { reportError } from '@/platform/telemetry/reportError' import type { LinkId } from '@/types/linkId' import type { NodeId } from '@/types/nodeId' -import type { LGraph } from './LGraph' -import type { LGraphNode } from './LGraphNode' -import type { LLink } from './LLink' - export type GraphIntentSource = 'local' | 'agent-remote' | 'load' /** diff --git a/src/lib/litegraph/src/idAllocation.ts b/src/lib/litegraph/src/idAllocation.ts index c1c4cbe122e..afa7a53e5d0 100644 --- a/src/lib/litegraph/src/idAllocation.ts +++ b/src/lib/litegraph/src/idAllocation.ts @@ -1,4 +1,5 @@ -import type { LGraph } from './LGraph' +import type { LGraph } from '@/lib/litegraph/src/types/entityRegistry' + import type { ISerialisedGroup, ISerialisedNode, diff --git a/src/lib/litegraph/src/infrastructure/LGraphCanvasEventMap.ts b/src/lib/litegraph/src/infrastructure/LGraphCanvasEventMap.ts index 5775f7525d9..b67dd1ca177 100644 --- a/src/lib/litegraph/src/infrastructure/LGraphCanvasEventMap.ts +++ b/src/lib/litegraph/src/infrastructure/LGraphCanvasEventMap.ts @@ -1,11 +1,16 @@ -import type { LGraph } from '@/lib/litegraph/src/LGraph' +import type { + LGraph, + LGraphGroup, + LGraphNode, + Subgraph, + SubgraphNode +} from '@/lib/litegraph/src/types/entityRegistry' + import type { LGraphButton } from '@/lib/litegraph/src/LGraphButton' -import type { LGraphGroup } from '@/lib/litegraph/src/LGraphGroup' -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' + import type { SerializedNodeId } from '@/types/nodeId' import type { ConnectingLink } from '@/lib/litegraph/src/types/slots' -import type { Subgraph } from '@/lib/litegraph/src/subgraph/Subgraph' -import type { SubgraphNode } from '@/lib/litegraph/src/subgraph/SubgraphNode' + import type { CanvasPointerEvent } from '@/lib/litegraph/src/types/events' export interface LGraphCanvasEventMap { diff --git a/src/lib/litegraph/src/infrastructure/LGraphEventMap.ts b/src/lib/litegraph/src/infrastructure/LGraphEventMap.ts index 62fe2aae93d..c0f6447aec8 100644 --- a/src/lib/litegraph/src/infrastructure/LGraphEventMap.ts +++ b/src/lib/litegraph/src/infrastructure/LGraphEventMap.ts @@ -1,9 +1,15 @@ -import type { LGraph } from '@/lib/litegraph/src/LGraph' +import type { + LGraph, + LGraphNode, + LLink, + ResolvedConnection, + Subgraph +} from '@/lib/litegraph/src/types/entityRegistry' + import type { SerializedNodeId } from '@/types/nodeId' -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' -import type { LLink, ResolvedConnection } from '@/lib/litegraph/src/LLink' + import type { ReadOnlyRect } from '@/lib/litegraph/src/interfaces' -import type { Subgraph } from '@/lib/litegraph/src/subgraph/Subgraph' + import type { NodeSlotType } from '@/lib/litegraph/src/types/globalEnums' import type { ExportedSubgraph, diff --git a/src/lib/litegraph/src/infrastructure/LinkConnectorEventMap.ts b/src/lib/litegraph/src/infrastructure/LinkConnectorEventMap.ts index 837c131dedc..c305919ca95 100644 --- a/src/lib/litegraph/src/infrastructure/LinkConnectorEventMap.ts +++ b/src/lib/litegraph/src/infrastructure/LinkConnectorEventMap.ts @@ -1,14 +1,17 @@ -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' -import type { LLink } from '@/lib/litegraph/src/LLink' -import type { Reroute } from '@/lib/litegraph/src/Reroute' -import type { FloatingRenderLink } from '@/lib/litegraph/src/canvas/FloatingRenderLink' -import type { MovingInputLink } from '@/lib/litegraph/src/canvas/MovingInputLink' -import type { MovingOutputLink } from '@/lib/litegraph/src/canvas/MovingOutputLink' -import type { RenderLink } from '@/lib/litegraph/src/canvas/RenderLink' -import type { ToInputFromIoNodeLink } from '@/lib/litegraph/src/canvas/ToInputFromIoNodeLink' -import type { ToInputRenderLink } from '@/lib/litegraph/src/canvas/ToInputRenderLink' -import type { SubgraphInputNode } from '@/lib/litegraph/src/subgraph/SubgraphInputNode' -import type { SubgraphOutputNode } from '@/lib/litegraph/src/subgraph/SubgraphOutputNode' +import type { + LGraphNode, + LLink, + Reroute, + FloatingRenderLink, + MovingInputLink, + MovingOutputLink, + ToInputFromIoNodeLink, + ToInputRenderLink, + SubgraphInputNode, + SubgraphOutputNode, + RenderLink +} from '@/lib/litegraph/src/types/entityRegistry' + import type { CanvasPointerEvent } from '@/lib/litegraph/src/types/events' import type { IWidget } from '@/lib/litegraph/src/types/widgets' diff --git a/src/lib/litegraph/src/infrastructure/SubgraphEventMap.ts b/src/lib/litegraph/src/infrastructure/SubgraphEventMap.ts index bb74f39f345..8bf6eb189dd 100644 --- a/src/lib/litegraph/src/infrastructure/SubgraphEventMap.ts +++ b/src/lib/litegraph/src/infrastructure/SubgraphEventMap.ts @@ -1,7 +1,10 @@ -import type { Subgraph } from '@/lib/litegraph/src/subgraph/Subgraph' -import type { SubgraphInput } from '@/lib/litegraph/src/subgraph/SubgraphInput' -import type { SubgraphNode } from '@/lib/litegraph/src/subgraph/SubgraphNode' -import type { SubgraphOutput } from '@/lib/litegraph/src/subgraph/SubgraphOutput' +import type { + Subgraph, + SubgraphInput, + SubgraphNode, + SubgraphOutput +} from '@/lib/litegraph/src/types/entityRegistry' + import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets' import type { LGraphEventMap } from './LGraphEventMap' diff --git a/src/lib/litegraph/src/infrastructure/SubgraphInputEventMap.ts b/src/lib/litegraph/src/infrastructure/SubgraphInputEventMap.ts index 3bf43110511..0112f081b98 100644 --- a/src/lib/litegraph/src/infrastructure/SubgraphInputEventMap.ts +++ b/src/lib/litegraph/src/infrastructure/SubgraphInputEventMap.ts @@ -1,6 +1,10 @@ -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' -import type { INodeInputSlot } from '@/lib/litegraph/src/litegraph' -import type { SubgraphInput } from '@/lib/litegraph/src/subgraph/SubgraphInput' +import type { + LGraphNode, + SubgraphInput +} from '@/lib/litegraph/src/types/entityRegistry' + +import type { INodeInputSlot } from '@/lib/litegraph/src/types/slots' + import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets' import type { LGraphEventMap } from './LGraphEventMap' diff --git a/src/lib/litegraph/src/linkDeduplication.ts b/src/lib/litegraph/src/linkDeduplication.ts index be0359220f7..af531ac38bc 100644 --- a/src/lib/litegraph/src/linkDeduplication.ts +++ b/src/lib/litegraph/src/linkDeduplication.ts @@ -1,3 +1,9 @@ +import type { + LGraph, + LGraphNode, + LLink, + SerialisedLLinkArray +} from '@/lib/litegraph/src/types/entityRegistry' import { useTelemetry } from '@/platform/telemetry' import { useLinkStore } from '@/stores/linkStore' import { graphScopeOf } from '@/types/graphScopeId' @@ -6,9 +12,8 @@ import { parseLinkId, toLinkId } from '@/types/linkId' import { toNodeId } from '@/types/nodeId' import type { NodeId } from '@/types/nodeId' import cloneDeep from 'es-toolkit/compat/cloneDeep' -import type { LGraph } from './LGraph' -import type { LGraphNode } from './LGraphNode' -import type { LinkId, LLink, SerialisedLLinkArray } from './LLink' + +import type { LinkId } from '@/types/linkId' import type { ExportedSubgraph, ISerialisedGraph, diff --git a/src/lib/litegraph/src/litegraph.ts b/src/lib/litegraph/src/litegraph.ts index 1d63166ace6..66186f34b06 100644 --- a/src/lib/litegraph/src/litegraph.ts +++ b/src/lib/litegraph/src/litegraph.ts @@ -1,13 +1,15 @@ -import type { ContextMenu } from './ContextMenu' -import type { LGraphNode } from './LGraphNode' +import type { + ContextMenu, + LGraphNode +} from '@/lib/litegraph/src/types/entityRegistry' + import { LiteGraphGlobal } from './LiteGraphGlobal' -import type { Point, Size } from './interfaces' +import type { Point } from './interfaces' import type { ConnectingLink } from './types/slots' import type { IContextMenuOptions } from './types/contextMenu' import { registerLiteGraphInstance } from './litegraphInstance' import { loadPolyfills } from './polyfills' import type { CanvasEventDetail } from './types/events' -import type { RenderShape, TitleMode } from './types/globalEnums' // Must remain above LiteGraphGlobal (circular dependency due to abstract factory behaviour in `configure`) export { Subgraph } from './subgraph/Subgraph' @@ -53,29 +55,6 @@ export interface LinkReleaseContextExtended { export interface LiteGraphCanvasEvent extends CustomEvent {} -export interface LGraphNodeConstructor { - new (title: string, type?: string): T - - title?: string - desc?: string - priority?: number - type?: string // TODO: to be, or not to be--that is the question - size?: Size - min_height?: number - slot_start_y?: number - widgets_info?: Record - collapsable?: boolean - color?: string - bgcolor?: string - shape?: RenderShape - title_mode?: TitleMode - title_color?: string - title_text_color?: string - keepAllLinksOnBypass: boolean - resizeHandleSize?: number - resizeEdgeSize?: number -} - // End backwards compat export type { CanvasInteractionModeReader } from './canvas/CanvasInteractionMode' @@ -180,3 +159,10 @@ export { MovingInputLink } from './canvas/MovingInputLink' export { ToInputRenderLink } from './canvas/ToInputRenderLink' export { LiteGraphGlobal } from './LiteGraphGlobal' export type { CreateNodeOptions } from './LiteGraphGlobal' + +type RegisteredLinkReleaseContextExtended = LinkReleaseContextExtended + +declare module './types/entityRegistry' { + interface LinkReleaseContextExtended extends RegisteredLinkReleaseContextExtended {} +} +export type { LGraphNodeConstructor } from './types/nodeConstructor' diff --git a/src/lib/litegraph/src/litegraphInstance.ts b/src/lib/litegraph/src/litegraphInstance.ts index 88d74fb86a4..0812e1a04cd 100644 --- a/src/lib/litegraph/src/litegraphInstance.ts +++ b/src/lib/litegraph/src/litegraphInstance.ts @@ -1,4 +1,4 @@ -import type { LiteGraphGlobal } from './LiteGraphGlobal' +import type { LiteGraphGlobal } from '@/lib/litegraph/src/types/entityRegistry' declare global { var __COMFY_LITEGRAPH_INSTANCE__: LiteGraphGlobal | undefined diff --git a/src/lib/litegraph/src/node/NodeInputSlot.ts b/src/lib/litegraph/src/node/NodeInputSlot.ts index d45cf99e2b2..e0761f22dde 100644 --- a/src/lib/litegraph/src/node/NodeInputSlot.ts +++ b/src/lib/litegraph/src/node/NodeInputSlot.ts @@ -1,5 +1,11 @@ -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' -import type { LLink, LinkId } from '@/lib/litegraph/src/LLink' +import type { + LGraphNode, + LLink, + SubgraphInput, + SubgraphOutput +} from '@/lib/litegraph/src/types/entityRegistry' + +import type { LinkId } from '@/types/linkId' import { LabelPosition } from '@/lib/litegraph/src/draw' import type { OptionalProps, Point } from '@/lib/litegraph/src/interfaces' import type { @@ -14,8 +20,7 @@ import { import { inputHasLink, inputLink } from '@/lib/litegraph/src/node/slotLinks' import { warnDeprecated } from '@/lib/litegraph/src/utils/feedback' import type { IDrawOptions } from '@/lib/litegraph/src/node/NodeSlot' -import type { SubgraphInput } from '@/lib/litegraph/src/subgraph/SubgraphInput' -import type { SubgraphOutput } from '@/lib/litegraph/src/subgraph/SubgraphOutput' + import { isSubgraphInput } from '@/lib/litegraph/src/subgraph/subgraphTypeGuards' import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets' diff --git a/src/lib/litegraph/src/node/NodeOutputSlot.ts b/src/lib/litegraph/src/node/NodeOutputSlot.ts index b0601bb3e4b..5526e06a6bc 100644 --- a/src/lib/litegraph/src/node/NodeOutputSlot.ts +++ b/src/lib/litegraph/src/node/NodeOutputSlot.ts @@ -1,5 +1,11 @@ -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' -import type { LLink, LinkId } from '@/lib/litegraph/src/LLink' +import type { + LGraphNode, + LLink, + SubgraphInput, + SubgraphOutput +} from '@/lib/litegraph/src/types/entityRegistry' + +import type { LinkId } from '@/types/linkId' import { LabelPosition } from '@/lib/litegraph/src/draw' import type { OptionalProps, Point } from '@/lib/litegraph/src/interfaces' import type { @@ -11,8 +17,7 @@ import { createArrayMutationView } from '@/lib/litegraph/src/infrastructure/crea import { NodeSlot } from '@/lib/litegraph/src/node/NodeSlot' import type { IDrawOptions } from '@/lib/litegraph/src/node/NodeSlot' import { outputHasLinks, outputLinks } from '@/lib/litegraph/src/node/slotLinks' -import type { SubgraphInput } from '@/lib/litegraph/src/subgraph/SubgraphInput' -import type { SubgraphOutput } from '@/lib/litegraph/src/subgraph/SubgraphOutput' + import { isSubgraphOutput } from '@/lib/litegraph/src/subgraph/subgraphTypeGuards' import { warnDeprecated } from '@/lib/litegraph/src/utils/feedback' diff --git a/src/lib/litegraph/src/node/NodeSlot.ts b/src/lib/litegraph/src/node/NodeSlot.ts index 2cb0ef39ee7..334aa4eb976 100644 --- a/src/lib/litegraph/src/node/NodeSlot.ts +++ b/src/lib/litegraph/src/node/NodeSlot.ts @@ -1,7 +1,12 @@ +import type { + LGraphNode, + SubgraphInput, + SubgraphOutput +} from '@/lib/litegraph/src/types/entityRegistry' import { shallowReactive } from 'vue' import { MAX_MULTITYPE_SLICES } from '@/constants/slotColors' -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' + import { LabelPosition, SlotShape, SlotType } from '@/lib/litegraph/src/draw' import type { CanvasColour, @@ -18,8 +23,7 @@ import type { import { LiteGraph } from '@/lib/litegraph/src/litegraphInstance' import { Rectangle } from '@/lib/litegraph/src/infrastructure/Rectangle' import { getCentre } from '@/lib/litegraph/src/measure' -import type { SubgraphInput } from '@/lib/litegraph/src/subgraph/SubgraphInput' -import type { SubgraphOutput } from '@/lib/litegraph/src/subgraph/SubgraphOutput' + import { LinkDirection, RenderShape diff --git a/src/lib/litegraph/src/node/slotDescriptorView.ts b/src/lib/litegraph/src/node/slotDescriptorView.ts index c20bef00f56..e22c79ac0c3 100644 --- a/src/lib/litegraph/src/node/slotDescriptorView.ts +++ b/src/lib/litegraph/src/node/slotDescriptorView.ts @@ -1,4 +1,5 @@ -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import type { LGraphNode } from '@/lib/litegraph/src/types/entityRegistry' + import type { INodeInputSlot, INodeOutputSlot diff --git a/src/lib/litegraph/src/node/slotLinks.ts b/src/lib/litegraph/src/node/slotLinks.ts index f66910c8b85..7b85d671c8d 100644 --- a/src/lib/litegraph/src/node/slotLinks.ts +++ b/src/lib/litegraph/src/node/slotLinks.ts @@ -1,3 +1,8 @@ +import type { + LGraph, + LGraphNode, + LLink +} from '@/lib/litegraph/src/types/entityRegistry' import { useLinkStore } from '@/stores/linkStore' import type { EndpointUpdateError } from '@/stores/linkStore' import { graphScopeOf } from '@/types/graphScopeId' @@ -5,11 +10,9 @@ import type { LinkId } from '@/types/linkId' import type { NodeId } from '@/types/nodeId' import type { RerouteId } from '@/types/rerouteId' -import type { LGraph } from '../LGraph' -import type { LGraphNode } from '../LGraphNode' import type { INodeInputSlot } from '../types/slots' import { slotFloatingLinks } from '../LLink' -import type { LLink } from '../LLink' + import { NodeSlotType } from '../types/globalEnums' /** * Store-backed reads over the links attached to a node's slots. diff --git a/src/lib/litegraph/src/node/slotUtils.ts b/src/lib/litegraph/src/node/slotUtils.ts index 6e28e80c765..169fa592c91 100644 --- a/src/lib/litegraph/src/node/slotUtils.ts +++ b/src/lib/litegraph/src/node/slotUtils.ts @@ -1,11 +1,12 @@ -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' -import type { LinkId } from '@/lib/litegraph/src/LLink' +import type { LGraphNode } from '@/lib/litegraph/src/types/entityRegistry' + +import type { LinkId } from '@/types/linkId' import type { SharedIntersection } from '@/lib/litegraph/src/interfaces' -import type { IWidgetInputSlot } from '@/lib/litegraph/src/types/slots' import type { + IWidgetInputSlot, INodeInputSlot, INodeOutputSlot -} from '@/lib/litegraph/src/litegraph' +} from '@/lib/litegraph/src/types/slots' import { inputLinkId, outputLinkIds } from '@/lib/litegraph/src/node/slotLinks' import type { ISerialisableNodeInput, diff --git a/src/lib/litegraph/src/node/widgetsView.ts b/src/lib/litegraph/src/node/widgetsView.ts index 1fff0a7e20b..c468eced3da 100644 --- a/src/lib/litegraph/src/node/widgetsView.ts +++ b/src/lib/litegraph/src/node/widgetsView.ts @@ -1,6 +1,6 @@ +import type { LGraphNode } from '@/lib/litegraph/src/types/entityRegistry' import { shallowReactive } from 'vue' -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets' import { toConcreteWidget } from '@/lib/litegraph/src/widgets/widgetMap' import { useWidgetValueStore } from '@/stores/widgetValueStore' diff --git a/src/lib/litegraph/src/nodeBadgeDraw.ts b/src/lib/litegraph/src/nodeBadgeDraw.ts index d65167af9ff..0e4c0b18b8f 100644 --- a/src/lib/litegraph/src/nodeBadgeDraw.ts +++ b/src/lib/litegraph/src/nodeBadgeDraw.ts @@ -1,10 +1,10 @@ +import type { LGraphNode } from '@/lib/litegraph/src/types/entityRegistry' import { truncate } from 'es-toolkit/compat' import type { BadgeData, CoreBadgeData } from '@/types/badgeData' import { LGraphBadge } from './LGraphBadge' import type { LGraphIconOptions } from './LGraphIcon' -import type { LGraphNode } from './LGraphNode' const CORE_TEXT_LIMIT = 31 diff --git a/src/lib/litegraph/src/remintLinkRemap.ts b/src/lib/litegraph/src/remintLinkRemap.ts index 04f5c942470..581f9417afe 100644 --- a/src/lib/litegraph/src/remintLinkRemap.ts +++ b/src/lib/litegraph/src/remintLinkRemap.ts @@ -1,6 +1,6 @@ +import type { LLink } from '@/lib/litegraph/src/types/entityRegistry' import { UNASSIGNED_NODE_ID, toNodeId } from '@/types/nodeId' -import type { LLink } from './LLink' import type { ISerialisedNode } from './types/serialisation' import type { EndpointPatch } from '@/stores/linkStore' import type { NodeId } from '@/types/nodeId' diff --git a/src/lib/litegraph/src/subgraph/EmptySubgraphInput.ts b/src/lib/litegraph/src/subgraph/EmptySubgraphInput.ts index 8bdf44d22d1..f030df08f88 100644 --- a/src/lib/litegraph/src/subgraph/EmptySubgraphInput.ts +++ b/src/lib/litegraph/src/subgraph/EmptySubgraphInput.ts @@ -1,13 +1,16 @@ -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' -import type { LLink } from '@/lib/litegraph/src/LLink' -import type { RerouteId } from '@/lib/litegraph/src/Reroute' +import type { + LGraphNode, + LLink, + SubgraphInputNode +} from '@/lib/litegraph/src/types/entityRegistry' + +import type { RerouteId } from '@/types/rerouteId' import type { Point } from '@/lib/litegraph/src/interfaces' import type { INodeInputSlot } from '@/lib/litegraph/src/types/slots' import { nextUniqueName } from '@/lib/litegraph/src/strings' import { zeroUuid } from '@/utils/uuid' import { SubgraphInput } from './SubgraphInput' -import type { SubgraphInputNode } from './SubgraphInputNode' /** * A virtual slot that simply creates a new input slot when connected to. diff --git a/src/lib/litegraph/src/subgraph/EmptySubgraphOutput.ts b/src/lib/litegraph/src/subgraph/EmptySubgraphOutput.ts index 62cf76b737d..584d81a8dda 100644 --- a/src/lib/litegraph/src/subgraph/EmptySubgraphOutput.ts +++ b/src/lib/litegraph/src/subgraph/EmptySubgraphOutput.ts @@ -1,13 +1,16 @@ -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' -import type { LLink } from '@/lib/litegraph/src/LLink' -import type { RerouteId } from '@/lib/litegraph/src/Reroute' +import type { + LGraphNode, + LLink, + SubgraphOutputNode +} from '@/lib/litegraph/src/types/entityRegistry' + +import type { RerouteId } from '@/types/rerouteId' import type { Point } from '@/lib/litegraph/src/interfaces' import type { INodeOutputSlot } from '@/lib/litegraph/src/types/slots' import { nextUniqueName } from '@/lib/litegraph/src/strings' import { zeroUuid } from '@/utils/uuid' import { SubgraphOutput } from './SubgraphOutput' -import type { SubgraphOutputNode } from './SubgraphOutputNode' /** * A virtual slot that simply creates a new output slot when connected to. diff --git a/src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts b/src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts index 8e54346a7b6..164a96c77f1 100644 --- a/src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts +++ b/src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts @@ -1,8 +1,13 @@ +import type { + LGraph, + LGraphNode, + Subgraph, + SubgraphNode +} from '@/lib/litegraph/src/types/entityRegistry' import { inputLinkId } from '@/lib/litegraph/src/node/slotLinks' -import type { LGraph } from '@/lib/litegraph/src/LGraph' -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' + import type { SerializedNodeId } from '@/types/nodeId' -import type { LinkId } from '@/lib/litegraph/src/LLink' +import type { LinkId } from '@/types/linkId' import { InvalidLinkError } from '@/lib/litegraph/src/infrastructure/InvalidLinkError' import { useWidgetValueStore } from '@/stores/widgetValueStore' import { NullGraphError } from '@/lib/litegraph/src/infrastructure/NullGraphError' @@ -12,9 +17,6 @@ import type { ISlotType } from '@/lib/litegraph/src/interfaces' import { LGraphEventMode } from '@/lib/litegraph/src/types/globalEnums' import { litegraph } from '@/lib/litegraph/src/litegraphInstance' -import type { Subgraph } from './Subgraph' -import type { SubgraphNode } from './SubgraphNode' - export type ExecutionId = string /** diff --git a/src/lib/litegraph/src/subgraph/SubgraphIONodeBase.ts b/src/lib/litegraph/src/subgraph/SubgraphIONodeBase.ts index 1d4ef724338..30d25d42f1b 100644 --- a/src/lib/litegraph/src/subgraph/SubgraphIONodeBase.ts +++ b/src/lib/litegraph/src/subgraph/SubgraphIONodeBase.ts @@ -1,27 +1,33 @@ +import type { + LinkConnector, + Subgraph, + SubgraphInput, + SubgraphOutput +} from '@/lib/litegraph/src/types/entityRegistry' import { toSelectableKey } from '@/core/selection/selectionState' import { isSelectedIn, setSelectedIn } from '@/core/selection/selectionStore' import { graphScopeOf } from '@/types/graphScopeId' import { serializeNodeId } from '@/types/nodeId' import type { NodeId } from '@/types/nodeId' -import type { LinkConnector } from '@/lib/litegraph/src/canvas/LinkConnector' + import { Rectangle } from '@/lib/litegraph/src/infrastructure/Rectangle' import type { DefaultConnectionColors, Point, - Positionable + Positionable, + CanvasColour } from '@/lib/litegraph/src/interfaces' -import type { Hoverable } from '@/lib/litegraph/src/types/events' +import type { + Hoverable, + CanvasPointerEvent +} from '@/lib/litegraph/src/types/events' import type { INodeInputSlot, INodeOutputSlot } from '@/lib/litegraph/src/types/slots' import { LiteGraph } from '@/lib/litegraph/src/litegraphInstance' -import type { - CanvasColour, - CanvasPointer, - CanvasPointerEvent, - IContextMenuValue -} from '@/lib/litegraph/src/litegraph' +import type { CanvasPointer } from '@/lib/litegraph/src/CanvasPointer' +import type { IContextMenuValue } from '@/lib/litegraph/src/types/contextMenu' import { snapPoint } from '@/lib/litegraph/src/measure' import { CanvasItem } from '@/lib/litegraph/src/types/globalEnums' import type { @@ -31,9 +37,6 @@ import type { import type { EmptySubgraphInput } from './EmptySubgraphInput' import type { EmptySubgraphOutput } from './EmptySubgraphOutput' -import type { Subgraph } from './Subgraph' -import type { SubgraphInput } from './SubgraphInput' -import type { SubgraphOutput } from './SubgraphOutput' export abstract class SubgraphIONodeBase< TSlot extends SubgraphInput | SubgraphOutput @@ -398,3 +401,11 @@ export abstract class SubgraphIONodeBase< } } } + +type RegisteredSubgraphIONode = SubgraphIONodeBase< + SubgraphInput | SubgraphOutput +> + +declare module '../types/entityRegistry' { + interface SubgraphIONode extends RegisteredSubgraphIONode {} +} diff --git a/src/lib/litegraph/src/subgraph/SubgraphInput.ts b/src/lib/litegraph/src/subgraph/SubgraphInput.ts index 3c727f95f51..cae03cbbc86 100644 --- a/src/lib/litegraph/src/subgraph/SubgraphInput.ts +++ b/src/lib/litegraph/src/subgraph/SubgraphInput.ts @@ -1,9 +1,14 @@ +import type { + LGraphNode, + SubgraphInputNode, + SubgraphOutput +} from '@/lib/litegraph/src/types/entityRegistry' import { inputLink } from '@/lib/litegraph/src/node/slotLinks' -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' + import { LLink, replaceLinkTopology } from '@/lib/litegraph/src/LLink' import { linkIdReservations, mintLinkId } from '../idAllocation' import { anchorRerouteChain } from '@/lib/litegraph/src/Reroute' -import type { RerouteId } from '@/lib/litegraph/src/Reroute' +import type { RerouteId } from '@/types/rerouteId' import { CustomEventTarget } from '@/lib/litegraph/src/infrastructure/CustomEventTarget' import type { SubgraphInputEventMap } from '@/lib/litegraph/src/infrastructure/SubgraphInputEventMap' import type { Point, ReadOnlyRect } from '@/lib/litegraph/src/interfaces' @@ -15,8 +20,6 @@ import { LiteGraph } from '@/lib/litegraph/src/litegraphInstance' import { NodeSlotType } from '@/lib/litegraph/src/types/globalEnums' import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets' -import type { SubgraphInputNode } from './SubgraphInputNode' -import type { SubgraphOutput } from './SubgraphOutput' import { SubgraphSlot } from './SubgraphSlotBase' import { isNodeSlot, isSubgraphOutput } from './subgraphTypeGuards' @@ -251,3 +254,9 @@ export class SubgraphInput extends SubgraphSlot { return false } } + +type RegisteredSubgraphInput = SubgraphInput + +declare module '../types/entityRegistry' { + interface SubgraphInput extends RegisteredSubgraphInput {} +} diff --git a/src/lib/litegraph/src/subgraph/SubgraphInputNode.ts b/src/lib/litegraph/src/subgraph/SubgraphInputNode.ts index 103a2d1b58e..33a7b1490c9 100644 --- a/src/lib/litegraph/src/subgraph/SubgraphInputNode.ts +++ b/src/lib/litegraph/src/subgraph/SubgraphInputNode.ts @@ -1,10 +1,16 @@ +import type { + LGraphNode, + LinkConnector, + SubgraphInput, + SubgraphOutput +} from '@/lib/litegraph/src/types/entityRegistry' import type { CanvasPointer } from '@/lib/litegraph/src/CanvasPointer' -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' + import type { NodeId } from '@/types/nodeId' import { LLink, slotFloatingLinks } from '@/lib/litegraph/src/LLink' import { linkIdReservations, mintLinkId } from '../idAllocation' -import type { RerouteId } from '@/lib/litegraph/src/Reroute' -import type { LinkConnector } from '@/lib/litegraph/src/canvas/LinkConnector' +import type { RerouteId } from '@/types/rerouteId' + import { SUBGRAPH_INPUT_ID } from '@/lib/litegraph/src/constants' import type { DefaultConnectionColors, @@ -23,8 +29,7 @@ import { nextUniqueName } from '@/lib/litegraph/src/strings' import { EmptySubgraphInput } from './EmptySubgraphInput' import { SubgraphIONodeBase } from './SubgraphIONodeBase' -import type { SubgraphInput } from './SubgraphInput' -import type { SubgraphOutput } from './SubgraphOutput' + import { provideSubgraphInputGuard } from './subgraphTypeGuards' export class SubgraphInputNode @@ -300,3 +305,9 @@ function isSubgraphInput(slot: unknown): slot is SubgraphInput { } provideSubgraphInputGuard(isSubgraphInput) + +type RegisteredSubgraphInputNode = SubgraphInputNode + +declare module '../types/entityRegistry' { + interface SubgraphInputNode extends RegisteredSubgraphInputNode {} +} diff --git a/src/lib/litegraph/src/subgraph/SubgraphNode.ts b/src/lib/litegraph/src/subgraph/SubgraphNode.ts index e3913f7eb3b..373783059c7 100644 --- a/src/lib/litegraph/src/subgraph/SubgraphNode.ts +++ b/src/lib/litegraph/src/subgraph/SubgraphNode.ts @@ -1,25 +1,34 @@ +import type { + BaseLGraph, + LGraph, + SubgraphId, + LGraphCanvas, + ResolvedConnection, + GraphOrSubgraph, + Subgraph, + SubgraphInput +} from '@/lib/litegraph/src/types/entityRegistry' import cloneDeep from 'es-toolkit/compat/cloneDeep' -import type { BaseLGraph, LGraph, SubgraphId } from '@/lib/litegraph/src/LGraph' + import type { LGraphButton } from '@/lib/litegraph/src/LGraphButton' -import type { LGraphCanvas } from '@/lib/litegraph/src/LGraphCanvas' + import { LGraphNode } from '@/lib/litegraph/src/LGraphNode' import type { DrawTitleBoxOptions } from '@/lib/litegraph/src/LGraphNode' import { LLink } from '@/lib/litegraph/src/LLink' -import type { ResolvedConnection } from '@/lib/litegraph/src/LLink' + import { NullGraphError } from '@/lib/litegraph/src/infrastructure/NullGraphError' import { RecursionError } from '@/lib/litegraph/src/infrastructure/RecursionError' -import type { IWidgetLocator } from '@/lib/litegraph/src/interfaces' -import type { ISubgraphInput } from '@/lib/litegraph/src/types/slots' +import type { IWidgetLocator, ISlotType } from '@/lib/litegraph/src/interfaces' +import type { + ISubgraphInput, + INodeInputSlot +} from '@/lib/litegraph/src/types/slots' import { LiteGraph } from '@/lib/litegraph/src/litegraphInstance' -import type { INodeInputSlot, ISlotType } from '@/lib/litegraph/src/litegraph' import { NodeInputSlot } from '@/lib/litegraph/src/node/NodeInputSlot' import { NodeOutputSlot } from '@/lib/litegraph/src/node/NodeOutputSlot' import { UNASSIGNED_NODE_ID, toNodeId } from '@/types/nodeId' import type { SerializedNodeId } from '@/types/nodeId' -import type { - GraphOrSubgraph, - Subgraph -} from '@/lib/litegraph/src/subgraph/Subgraph' + import type { ExportedSubgraphInstance, ISerialisedNode @@ -53,7 +62,7 @@ import { deriveWidgetVisibility } from '@/types/widgetVisibility' import { ExecutableNodeDTO } from './ExecutableNodeDTO' import type { ExecutableLGraphNode, ExecutionId } from './ExecutableNodeDTO' import { createPromotedWidgetStoreProjection } from './promotedWidgetStoreProjection' -import type { SubgraphInput } from './SubgraphInput' + import { createBitmapCache } from './svgBitmapCache' const workflowSvg = new Image() @@ -1052,3 +1061,9 @@ export class SubgraphNode extends LGraphNode implements BaseLGraph { return shapes.every((shape) => shape === shapes[0]) ? shapes[0] : undefined } } + +type RegisteredSubgraphNode = SubgraphNode + +declare module '../types/entityRegistry' { + interface SubgraphNode extends RegisteredSubgraphNode {} +} diff --git a/src/lib/litegraph/src/subgraph/SubgraphOutput.ts b/src/lib/litegraph/src/subgraph/SubgraphOutput.ts index be544328f7c..460baa33826 100644 --- a/src/lib/litegraph/src/subgraph/SubgraphOutput.ts +++ b/src/lib/litegraph/src/subgraph/SubgraphOutput.ts @@ -1,8 +1,13 @@ -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import type { + LGraphNode, + SubgraphInput, + SubgraphOutputNode +} from '@/lib/litegraph/src/types/entityRegistry' + import { LLink, replaceLinkTopology } from '@/lib/litegraph/src/LLink' import { linkIdReservations, mintLinkId } from '../idAllocation' import { anchorRerouteChain } from '@/lib/litegraph/src/Reroute' -import type { RerouteId } from '@/lib/litegraph/src/Reroute' +import type { RerouteId } from '@/types/rerouteId' import type { Point, ReadOnlyRect } from '@/lib/litegraph/src/interfaces' import type { INodeInputSlot, @@ -11,8 +16,6 @@ import type { import { LiteGraph } from '@/lib/litegraph/src/litegraphInstance' import { NodeSlotType } from '@/lib/litegraph/src/types/globalEnums' -import type { SubgraphInput } from './SubgraphInput' -import type { SubgraphOutputNode } from './SubgraphOutputNode' import { SubgraphSlot } from './SubgraphSlotBase' import { isNodeSlot, isSubgraphInput } from './subgraphTypeGuards' @@ -156,3 +159,9 @@ export class SubgraphOutput extends SubgraphSlot { this.linkIds.length = 0 } } + +type RegisteredSubgraphOutput = SubgraphOutput + +declare module '../types/entityRegistry' { + interface SubgraphOutput extends RegisteredSubgraphOutput {} +} diff --git a/src/lib/litegraph/src/subgraph/SubgraphOutputNode.ts b/src/lib/litegraph/src/subgraph/SubgraphOutputNode.ts index 4f935326747..799ac23ea53 100644 --- a/src/lib/litegraph/src/subgraph/SubgraphOutputNode.ts +++ b/src/lib/litegraph/src/subgraph/SubgraphOutputNode.ts @@ -1,9 +1,16 @@ +import type { + LGraphNode, + LLink, + LinkConnector, + SubgraphInput, + SubgraphOutput +} from '@/lib/litegraph/src/types/entityRegistry' import type { CanvasPointer } from '@/lib/litegraph/src/CanvasPointer' -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' + import type { NodeId } from '@/types/nodeId' -import type { LLink } from '@/lib/litegraph/src/LLink' -import type { RerouteId } from '@/lib/litegraph/src/Reroute' -import type { LinkConnector } from '@/lib/litegraph/src/canvas/LinkConnector' + +import type { RerouteId } from '@/types/rerouteId' + import { SUBGRAPH_OUTPUT_ID } from '@/lib/litegraph/src/constants' import type { DefaultConnectionColors, @@ -21,8 +28,7 @@ import { findFreeSlotOfType } from '@/lib/litegraph/src/utils/collections' import { EmptySubgraphOutput } from './EmptySubgraphOutput' import { SubgraphIONodeBase } from './SubgraphIONodeBase' -import type { SubgraphInput } from './SubgraphInput' -import type { SubgraphOutput } from './SubgraphOutput' + import { provideSubgraphOutputGuard } from './subgraphTypeGuards' export class SubgraphOutputNode @@ -173,3 +179,9 @@ function isSubgraphOutput(slot: unknown): slot is SubgraphOutput { } provideSubgraphOutputGuard(isSubgraphOutput) + +type RegisteredSubgraphOutputNode = SubgraphOutputNode + +declare module '../types/entityRegistry' { + interface SubgraphOutputNode extends RegisteredSubgraphOutputNode {} +} diff --git a/src/lib/litegraph/src/subgraph/SubgraphSlotBase.ts b/src/lib/litegraph/src/subgraph/SubgraphSlotBase.ts index 6e09b961ebc..de7effe75bf 100644 --- a/src/lib/litegraph/src/subgraph/SubgraphSlotBase.ts +++ b/src/lib/litegraph/src/subgraph/SubgraphSlotBase.ts @@ -1,7 +1,15 @@ +import type { + LGraphNode, + LLink, + SubgraphInput, + SubgraphInputNode, + SubgraphOutput, + SubgraphOutputNode +} from '@/lib/litegraph/src/types/entityRegistry' import { canvasClass } from '@/lib/litegraph/src/canvas/canvasClassAccess' -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' -import type { LLink, LinkId } from '@/lib/litegraph/src/LLink' -import type { RerouteId } from '@/lib/litegraph/src/Reroute' + +import type { LinkId } from '@/types/linkId' +import type { RerouteId } from '@/types/rerouteId' import { SlotShape } from '@/lib/litegraph/src/draw' import { ConstrainedSize } from '@/lib/litegraph/src/infrastructure/ConstrainedSize' import { Rectangle } from '@/lib/litegraph/src/infrastructure/Rectangle' @@ -27,11 +35,6 @@ import type { } from '@/lib/litegraph/src/types/serialisation' import type { UUID } from '@/utils/uuid' -import type { SubgraphInput } from './SubgraphInput' -import type { SubgraphInputNode } from './SubgraphInputNode' -import type { SubgraphOutput } from './SubgraphOutput' -import type { SubgraphOutputNode } from './SubgraphOutputNode' - interface SubgraphSlotDrawOptions { ctx: CanvasRenderingContext2D colorContext: DefaultConnectionColors diff --git a/src/lib/litegraph/src/subgraph/promotedWidgetStoreProjection.ts b/src/lib/litegraph/src/subgraph/promotedWidgetStoreProjection.ts index bda29121361..058a825a0b5 100644 --- a/src/lib/litegraph/src/subgraph/promotedWidgetStoreProjection.ts +++ b/src/lib/litegraph/src/subgraph/promotedWidgetStoreProjection.ts @@ -1,4 +1,4 @@ -import type { INodeInputSlot } from '@/lib/litegraph/src/litegraph' +import type { INodeInputSlot } from '@/lib/litegraph/src/types/slots' import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets' import { useWidgetValueStore } from '@/stores/widgetValueStore' import type { WidgetId } from '@/types/widgetId' diff --git a/src/lib/litegraph/src/subgraph/subgraphTypeGuards.ts b/src/lib/litegraph/src/subgraph/subgraphTypeGuards.ts index 4cdb6f242ee..79aa2c0e281 100644 --- a/src/lib/litegraph/src/subgraph/subgraphTypeGuards.ts +++ b/src/lib/litegraph/src/subgraph/subgraphTypeGuards.ts @@ -1,7 +1,10 @@ -import type { Subgraph } from '../LGraph' +import type { + Subgraph, + SubgraphInput, + SubgraphOutput +} from '@/lib/litegraph/src/types/entityRegistry' + import type { INodeInputSlot, INodeOutputSlot } from '../types/slots' -import type { SubgraphInput } from './SubgraphInput' -import type { SubgraphOutput } from './SubgraphOutput' export let isSubgraph: (value: unknown) => value is Subgraph export let isSubgraphInput: (slot: unknown) => slot is SubgraphInput diff --git a/src/lib/litegraph/src/subgraph/subgraphUtils.ts b/src/lib/litegraph/src/subgraph/subgraphUtils.ts index 84c2c7f5088..7087e222717 100644 --- a/src/lib/litegraph/src/subgraph/subgraphUtils.ts +++ b/src/lib/litegraph/src/subgraph/subgraphUtils.ts @@ -1,9 +1,18 @@ +import type { + LGraph, + SubgraphId, + ResolvedConnection, + GraphOrSubgraph, + Subgraph, + SubgraphInput, + SubgraphNode +} from '@/lib/litegraph/src/types/entityRegistry' import { isEqual } from 'es-toolkit' -import type { LGraph, SubgraphId } from '@/lib/litegraph/src/LGraph' + import { LGraphGroup } from '@/lib/litegraph/src/LGraphGroup' import { LGraphNode } from '@/lib/litegraph/src/LGraphNode' import { LLink, slotFloatingLinks } from '@/lib/litegraph/src/LLink' -import type { ResolvedConnection } from '@/lib/litegraph/src/LLink' + import { captureInputLayout, inputLinkId, @@ -11,7 +20,7 @@ import { replaceNodeInputs } from '@/lib/litegraph/src/node/slotLinks' import { Reroute } from '@/lib/litegraph/src/Reroute' -import type { RerouteId } from '@/lib/litegraph/src/Reroute' +import type { RerouteId } from '@/types/rerouteId' import { toRerouteId } from '@/types/rerouteId' import { SUBGRAPH_INPUT_ID, @@ -29,10 +38,8 @@ import type { SubgraphIO } from '@/lib/litegraph/src/types/serialisation' -import type { GraphOrSubgraph, Subgraph } from './Subgraph' -import type { SubgraphInput } from './SubgraphInput' import { SubgraphInputNode } from './SubgraphInputNode' -import type { SubgraphNode } from './SubgraphNode' + import { SubgraphOutputNode } from './SubgraphOutputNode' interface FilteredItems { diff --git a/src/lib/litegraph/src/subgraph/unpackSubgraph.ts b/src/lib/litegraph/src/subgraph/unpackSubgraph.ts index df3f0a35713..addb45e1e2b 100644 --- a/src/lib/litegraph/src/subgraph/unpackSubgraph.ts +++ b/src/lib/litegraph/src/subgraph/unpackSubgraph.ts @@ -1,3 +1,4 @@ +import type { LGraph } from '@/lib/litegraph/src/types/entityRegistry' import type { UUID } from '@/utils/uuid' import { createUuidv4 } from '@/utils/uuid' import type { NodeId } from '@/types/nodeId' @@ -5,7 +6,7 @@ import { toNodeId } from '@/types/nodeId' import type { Point } from '../interfaces' import type { INodeInputSlot } from '../types/slots' -import type { LGraph } from '../LGraph' + import { LGraphNode } from '../LGraphNode' import { LiteGraph } from '../litegraphInstance' import type { ISerialisedNode } from '../types/serialisation' diff --git a/src/lib/litegraph/src/types/contextMenu.ts b/src/lib/litegraph/src/types/contextMenu.ts index b48539dfc21..bd3302d2797 100644 --- a/src/lib/litegraph/src/types/contextMenu.ts +++ b/src/lib/litegraph/src/types/contextMenu.ts @@ -1,5 +1,8 @@ -import type { ContextMenu } from '../ContextMenu' -import type { LGraphNode } from '../LGraphNode' +import type { + ContextMenu, + LGraphNode +} from '@/lib/litegraph/src/types/entityRegistry' + import type { IFoundSlot } from './slots' interface IContextMenuBase { @@ -58,7 +61,7 @@ export interface IContextMenuValue< interface IContextMenuSubmenu< TValue = unknown > extends IContextMenuOptions { - options: ConstructorParameters>[0] + options: ConstructorParameters['constructor']>[0] } export interface ContextMenuDivElement< diff --git a/src/lib/litegraph/src/types/entityRegistry.test.ts b/src/lib/litegraph/src/types/entityRegistry.test.ts new file mode 100644 index 00000000000..603fb886256 --- /dev/null +++ b/src/lib/litegraph/src/types/entityRegistry.test.ts @@ -0,0 +1,35 @@ +import { expectTypeOf, it } from 'vitest' + +import type { NodeId } from '@/types/nodeId' + +import type { BaseLGraph } from '../LGraph' +import type { + ContextMenu, + LGraph, + LGraphNode, + LGraphNodeConstructor, + Subgraph +} from '../litegraph' +import type { GraphOrSubgraph } from '../subgraph/Subgraph' +import type * as Entities from './entityRegistry' +import type { LGraphNodeConstructor as NodeConstructor } from './nodeConstructor' +import type { NodeBindable } from './widgets' + +it('preserves concrete graph, node, constructor, and generic menu contracts', () => { + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf< + Entities.LitegraphEntityRegistry['GraphOrSubgraph'] + >().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf<{ + setNodeId(nodeId: NodeId): void + }>() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf>().toEqualTypeOf< + ContextMenu + >() + expectTypeOf().toEqualTypeOf() +}) diff --git a/src/lib/litegraph/src/types/entityRegistry.ts b/src/lib/litegraph/src/types/entityRegistry.ts new file mode 100644 index 00000000000..330f20b1ae0 --- /dev/null +++ b/src/lib/litegraph/src/types/entityRegistry.ts @@ -0,0 +1,34 @@ +export interface LitegraphEntityRegistry {} +export interface ContextMenu<_TValue = unknown> {} +export interface LGraphNode {} +export interface LGraph {} +export interface Subgraph {} +export interface LGraphCanvas {} +export interface SubgraphNode {} +export interface SubgraphInput {} +export interface SubgraphOutput {} +export interface SubgraphInputNode {} +export interface SubgraphOutputNode {} +export interface LLink {} +export interface Reroute {} +export interface LGraphGroup {} +export interface LiteGraphGlobal {} +export interface LinkConnector {} +export interface FloatingRenderLink {} +export interface MovingInputLink {} +export interface MovingOutputLink {} +export interface ToInputFromIoNodeLink {} +export interface ToInputRenderLink {} +export type GraphOrSubgraph = LitegraphEntityRegistry['GraphOrSubgraph'] +export interface LGraphConfig {} +export interface LGraphExtra {} +export type SubgraphId = LitegraphEntityRegistry['SubgraphId'] +export interface BaseLGraph {} +export interface IGraphGroupFlags {} +export type SerialisedLLinkArray = + LitegraphEntityRegistry['SerialisedLLinkArray'] +export type ResolvedConnection = LitegraphEntityRegistry['ResolvedConnection'] +export interface SlotTypeDefaultNodeOpts {} +export interface LinkReleaseContextExtended {} +export interface RenderLink {} +export interface SubgraphIONode {} diff --git a/src/lib/litegraph/src/types/events.ts b/src/lib/litegraph/src/types/events.ts index d8ca2f2f1aa..f6ff160abd0 100644 --- a/src/lib/litegraph/src/types/events.ts +++ b/src/lib/litegraph/src/types/events.ts @@ -1,11 +1,14 @@ +import type { + LGraphGroup, + LGraphNode, + LinkReleaseContextExtended +} from '@/lib/litegraph/src/types/entityRegistry' /** * Event interfaces for event extension */ -import type { LGraphGroup } from '../LGraphGroup' + import type { Rectangle } from '../infrastructure/Rectangle' import type { HasBoundingRect, Point } from '../interfaces' -import type { LGraphNode } from '../LGraphNode' -import type { LinkReleaseContextExtended } from '../litegraph' /** For Canvas*Event - adds graph space co-ordinates (property names are shipped) */ interface ICanvasPosition { diff --git a/src/lib/litegraph/src/types/linkNetwork.ts b/src/lib/litegraph/src/types/linkNetwork.ts index 4e0636f06e8..087270da52c 100644 --- a/src/lib/litegraph/src/types/linkNetwork.ts +++ b/src/lib/litegraph/src/types/linkNetwork.ts @@ -1,14 +1,15 @@ +import type { + LGraphNode, + LLink, + Reroute, + SubgraphInputNode, + SubgraphOutputNode +} from '@/lib/litegraph/src/types/entityRegistry' import type { LinkId } from '@/types/linkId' import type { NodeId } from '@/types/nodeId' import type { RerouteId } from '@/types/rerouteId' import type { UUID } from '@/utils/uuid' -import type { LGraphNode } from '../LGraphNode' -import type { LLink } from '../LLink' -import type { Reroute } from '../Reroute' -import type { SubgraphInputNode } from '../subgraph/SubgraphInputNode' -import type { SubgraphOutputNode } from '../subgraph/SubgraphOutputNode' - export interface ReadonlyLinkNetwork { readonly rootGraph: { readonly id: UUID } readonly links: ReadonlyMap diff --git a/src/lib/litegraph/src/types/nodeConstructor.ts b/src/lib/litegraph/src/types/nodeConstructor.ts new file mode 100644 index 00000000000..72321a30a8f --- /dev/null +++ b/src/lib/litegraph/src/types/nodeConstructor.ts @@ -0,0 +1,26 @@ +import type { LGraphNode } from './entityRegistry' +import type { Size } from '../interfaces' +import type { RenderShape, TitleMode } from './globalEnums' + +export interface LGraphNodeConstructor { + new (title: string, type?: string): T + + title?: string + desc?: string + priority?: number + type?: string // TODO: to be, or not to be--that is the question + size?: Size + min_height?: number + slot_start_y?: number + widgets_info?: Record + collapsable?: boolean + color?: string + bgcolor?: string + shape?: RenderShape + title_mode?: TitleMode + title_color?: string + title_text_color?: string + keepAllLinksOnBypass: boolean + resizeHandleSize?: number + resizeEdgeSize?: number +} diff --git a/src/lib/litegraph/src/types/panel.ts b/src/lib/litegraph/src/types/panel.ts index 10ae3876333..73cde7ce9ce 100644 --- a/src/lib/litegraph/src/types/panel.ts +++ b/src/lib/litegraph/src/types/panel.ts @@ -1,4 +1,5 @@ -import type { LGraphNode } from '../LGraphNode' +import type { LGraphNode } from '@/lib/litegraph/src/types/entityRegistry' + import type { IContextMenuValue } from './contextMenu' import type { TWidgetValue } from './widgets' diff --git a/src/lib/litegraph/src/types/serialisation.ts b/src/lib/litegraph/src/types/serialisation.ts index e627ebfe162..1b5312cf0eb 100644 --- a/src/lib/litegraph/src/types/serialisation.ts +++ b/src/lib/litegraph/src/types/serialisation.ts @@ -1,12 +1,17 @@ +import type { + LGraphConfig, + LGraphExtra, + SubgraphId, + IGraphGroupFlags, + SerialisedLLinkArray +} from '@/lib/litegraph/src/types/entityRegistry' import type { UUID } from '@/utils/uuid' import type { LinkPresentation } from '@/types/linkPresentation' -import type { LGraphConfig, LGraphExtra, SubgraphId } from '../LGraph' -import type { IGraphGroupFlags } from '../LGraphGroup' import type { NodeProperty } from '@/types/nodeProperty' import type { SerializedNodeId } from '@/types/nodeId' -import type { SerialisedLLinkArray } from '../LLink' -import type { FloatingRerouteSlot } from '../Reroute' + +import type { FloatingRerouteSlot } from '@/types/rerouteChain' import type { Dictionary, INodeFlags, @@ -16,7 +21,7 @@ import type { Size } from '../interfaces' import type { INodeInputSlot, INodeOutputSlot } from './slots' -import type { LiteGraph } from '../litegraph' +import type { LiteGraphGlobal } from './entityRegistry' import type { RenderShape } from './globalEnums' import type { TWidgetValue } from './widgets' @@ -142,7 +147,7 @@ export interface ISerialisedGraph extends BaseExportedGraph { links: SerialisedLLinkArray[] floatingLinks?: SerialisableLLink[] groups: ISerialisedGroup[] - version: typeof LiteGraph.VERSION + version: LiteGraphGlobal['VERSION'] extra?: LGraphExtra } diff --git a/src/lib/litegraph/src/types/slots.ts b/src/lib/litegraph/src/types/slots.ts index b890b6a0092..3f988f6cbcc 100644 --- a/src/lib/litegraph/src/types/slots.ts +++ b/src/lib/litegraph/src/types/slots.ts @@ -1,12 +1,15 @@ +import type { + LGraphNode, + LLink, + SubgraphInput +} from '@/lib/litegraph/src/types/entityRegistry' import type { LinkId } from '@/types/linkId' import type { RerouteId } from '@/types/rerouteId' import type { SlotIndex } from '@/types/slotId' import type { WidgetId } from '@/types/widgetId' -import type { LGraphNode } from '../LGraphNode' -import type { LLink } from '../LLink' import type { IWidgetLocator, ISlotType, INodeSlot, Point } from '../interfaces' -import type { SubgraphInput } from '../subgraph/SubgraphInput' + import type { LinkDirection } from './globalEnums' import type { IBaseWidget } from './widgets' diff --git a/src/lib/litegraph/src/types/widgets.ts b/src/lib/litegraph/src/types/widgets.ts index 5b55ab5552e..fb29414e849 100644 --- a/src/lib/litegraph/src/types/widgets.ts +++ b/src/lib/litegraph/src/types/widgets.ts @@ -1,3 +1,7 @@ +import type { + LGraphCanvas, + LGraphNode +} from '@/lib/litegraph/src/types/entityRegistry' import type { Bounds } from '@/renderer/core/layout/types' import type { CompositorWidgetValue } from '@/renderer/extensions/compositor/components/types' import type { CurveData } from '@/components/curve/types' @@ -18,7 +22,7 @@ import type { RequiredProps, Size } from '../interfaces' -import type { CanvasPointer, LGraphCanvas, LGraphNode } from '../litegraph' +import type { CanvasPointer } from '@/lib/litegraph/src/CanvasPointer' import type { CanvasPointerEvent } from './events' export type { NodeBindable } from '../utils/type' diff --git a/src/lib/litegraph/src/utils/arrange.ts b/src/lib/litegraph/src/utils/arrange.ts index 712d7d7bd0a..01accef4ab7 100644 --- a/src/lib/litegraph/src/utils/arrange.ts +++ b/src/lib/litegraph/src/utils/arrange.ts @@ -1,4 +1,5 @@ -import type { LGraphNode } from '../LGraphNode' +import type { LGraphNode } from '@/lib/litegraph/src/types/entityRegistry' + import type { Direction } from '../interfaces' export interface NewNodePosition { diff --git a/src/lib/litegraph/src/utils/collections.ts b/src/lib/litegraph/src/utils/collections.ts index 77844a706e1..fa2e385a301 100644 --- a/src/lib/litegraph/src/utils/collections.ts +++ b/src/lib/litegraph/src/utils/collections.ts @@ -1,4 +1,5 @@ -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import type { LGraphNode } from '@/lib/litegraph/src/types/entityRegistry' + import { parseSlotTypes } from '@/lib/litegraph/src/strings' import type { ISlotType, Positionable } from '../interfaces' diff --git a/src/lib/litegraph/src/utils/namedValuesShadowDiffTelemetry.ts b/src/lib/litegraph/src/utils/namedValuesShadowDiffTelemetry.ts index d7a3fc97f6c..8b3fa6ace2f 100644 --- a/src/lib/litegraph/src/utils/namedValuesShadowDiffTelemetry.ts +++ b/src/lib/litegraph/src/utils/namedValuesShadowDiffTelemetry.ts @@ -1,7 +1,7 @@ +import type { LGraphNode } from '@/lib/litegraph/src/types/entityRegistry' import { getCnrIdFromNode } from '@/platform/nodeReplacement/cnrIdUtil' import { useTelemetry } from '@/platform/telemetry' -import type { LGraphNode } from '../LGraphNode' import type { NamedValuesShadowDiffResult } from './namedValuesShadowDiff' const SHADOW_DIFF_SUMMARY_SAMPLE_RATE = 0.05 diff --git a/src/lib/litegraph/src/utils/widget.ts b/src/lib/litegraph/src/utils/widget.ts index ba6e8aaede7..a64c3a6c3f8 100644 --- a/src/lib/litegraph/src/utils/widget.ts +++ b/src/lib/litegraph/src/utils/widget.ts @@ -1,4 +1,5 @@ -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import type { LGraphNode } from '@/lib/litegraph/src/types/entityRegistry' + import type { IBaseWidget, IWidgetOptions diff --git a/src/lib/litegraph/src/widgets/AssetWidget.ts b/src/lib/litegraph/src/widgets/AssetWidget.ts index b01520b3a52..533eda92828 100644 --- a/src/lib/litegraph/src/widgets/AssetWidget.ts +++ b/src/lib/litegraph/src/widgets/AssetWidget.ts @@ -1,4 +1,5 @@ -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import type { LGraphNode } from '@/lib/litegraph/src/types/entityRegistry' + import type { IAssetWidget } from '@/lib/litegraph/src/types/widgets' import { BaseWidget, extensionValue } from './BaseWidget' diff --git a/src/lib/litegraph/src/widgets/BaseWidget.ts b/src/lib/litegraph/src/widgets/BaseWidget.ts index 5ed3e6430f8..ae9fc0d1801 100644 --- a/src/lib/litegraph/src/widgets/BaseWidget.ts +++ b/src/lib/litegraph/src/widgets/BaseWidget.ts @@ -1,21 +1,18 @@ +import type { + LGraphCanvas, + LGraphNode +} from '@/lib/litegraph/src/types/entityRegistry' import { t } from '@/i18n' import { drawTextInArea } from '@/lib/litegraph/src/draw' import { cachedMeasureText } from '@/lib/litegraph/src/utils/textMeasureCache' import { Rectangle } from '@/lib/litegraph/src/infrastructure/Rectangle' -import type { Point } from '@/lib/litegraph/src/interfaces' +import type { Point, Size } from '@/lib/litegraph/src/interfaces' import type { NodeId } from '@/types/nodeId' -import type { - CanvasPointer, - LGraphCanvas, - LGraphNode, - Size -} from '@/lib/litegraph/src/litegraph' +import type { CanvasPointer } from '@/lib/litegraph/src/CanvasPointer' import { litegraph } from '@/lib/litegraph/src/litegraphInstance' import type { CanvasPointerEvent } from '@/lib/litegraph/src/types/events' -import type { - IBaseWidget, - NodeBindable -} from '@/lib/litegraph/src/types/widgets' +import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets' +import type { NodeBindable } from '@/lib/litegraph/src/utils/type' import { deriveWidgetRenderState } from '@/lib/litegraph/src/utils/widget' import { useWidgetValueStore } from '@/stores/widgetValueStore' import type { WidgetId } from '@/types/widgetId' diff --git a/src/lib/litegraph/src/widgets/ButtonWidget.ts b/src/lib/litegraph/src/widgets/ButtonWidget.ts index 8da6d90c23f..1117f14b5a0 100644 --- a/src/lib/litegraph/src/widgets/ButtonWidget.ts +++ b/src/lib/litegraph/src/widgets/ButtonWidget.ts @@ -1,4 +1,5 @@ -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import type { LGraphNode } from '@/lib/litegraph/src/types/entityRegistry' + import type { IButtonWidget } from '@/lib/litegraph/src/types/widgets' import { BaseWidget, extensionValue } from './BaseWidget' diff --git a/src/lib/litegraph/src/widgets/ComboWidget.ts b/src/lib/litegraph/src/widgets/ComboWidget.ts index 613f653cd97..a3999e8e3da 100644 --- a/src/lib/litegraph/src/widgets/ComboWidget.ts +++ b/src/lib/litegraph/src/widgets/ComboWidget.ts @@ -1,7 +1,8 @@ +import type { LGraphNode } from '@/lib/litegraph/src/types/entityRegistry' import { clamp } from 'es-toolkit/compat' import type { IContextMenuValue } from '@/lib/litegraph/src/types/contextMenu' -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' + import { litegraph } from '@/lib/litegraph/src/litegraphInstance' import type { ComboWidgetValues, diff --git a/src/lib/litegraph/src/widgets/LegacyWidget.ts b/src/lib/litegraph/src/widgets/LegacyWidget.ts index 11faf94914f..f759fa1dd7c 100644 --- a/src/lib/litegraph/src/widgets/LegacyWidget.ts +++ b/src/lib/litegraph/src/widgets/LegacyWidget.ts @@ -1,4 +1,5 @@ -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import type { LGraphNode } from '@/lib/litegraph/src/types/entityRegistry' + import { litegraph } from '@/lib/litegraph/src/litegraphInstance' import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets' diff --git a/src/lib/litegraph/src/widgets/TextWidget.ts b/src/lib/litegraph/src/widgets/TextWidget.ts index 0e0c37d4c33..5bdb056b8ef 100644 --- a/src/lib/litegraph/src/widgets/TextWidget.ts +++ b/src/lib/litegraph/src/widgets/TextWidget.ts @@ -1,4 +1,5 @@ -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import type { LGraphNode } from '@/lib/litegraph/src/types/entityRegistry' + import type { IStringWidget } from '@/lib/litegraph/src/types/widgets' import { BaseWidget, extensionValue } from './BaseWidget' diff --git a/src/lib/litegraph/src/widgets/widgetMap.ts b/src/lib/litegraph/src/widgets/widgetMap.ts index 736cbfefcf6..bcf26ce7b4e 100644 --- a/src/lib/litegraph/src/widgets/widgetMap.ts +++ b/src/lib/litegraph/src/widgets/widgetMap.ts @@ -1,4 +1,5 @@ -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import type { LGraphNode } from '@/lib/litegraph/src/types/entityRegistry' + import type { IAssetWidget, IBaseWidget, diff --git a/src/platform/nodeReplacement/cnrIdUtil.ts b/src/platform/nodeReplacement/cnrIdUtil.ts index 165944ccd31..c1730d0f6ab 100644 --- a/src/platform/nodeReplacement/cnrIdUtil.ts +++ b/src/platform/nodeReplacement/cnrIdUtil.ts @@ -1,4 +1,4 @@ -import type { LGraphNode } from '@/lib/litegraph/src/litegraph' +import type { LGraphNode } from '@/lib/litegraph/src/types/entityRegistry' /** * Extracts the custom node registry ID (cnr_id or aux_id) from a raw diff --git a/src/renderer/core/canvas/litegraph/arrangeForLegacyRender.ts b/src/renderer/core/canvas/litegraph/arrangeForLegacyRender.ts index 519e0c21544..2318f3276dc 100644 --- a/src/renderer/core/canvas/litegraph/arrangeForLegacyRender.ts +++ b/src/renderer/core/canvas/litegraph/arrangeForLegacyRender.ts @@ -1,6 +1,9 @@ +import type { + LGraph, + LGraphNode +} from '@/lib/litegraph/src/types/entityRegistry' import log from 'loglevel' -import type { LGraph, LGraphNode } from '@/lib/litegraph/src/litegraph' import { layoutStore } from '@/renderer/core/layout/store/layoutStore' import { compareNodeIds } from '@/types/nodeId' diff --git a/src/renderer/core/canvas/litegraph/litegraphLinkAdapter.ts b/src/renderer/core/canvas/litegraph/litegraphLinkAdapter.ts index 3d0f0d17578..245ce766a9e 100644 --- a/src/renderer/core/canvas/litegraph/litegraphLinkAdapter.ts +++ b/src/renderer/core/canvas/litegraph/litegraphLinkAdapter.ts @@ -1,3 +1,4 @@ +import type { LLink, Reroute } from '@/lib/litegraph/src/types/entityRegistry' /** * Litegraph Link Adapter * @@ -6,8 +7,7 @@ * rendering data that can be consumed by the PathRenderer. * Maintains backward compatibility with existing litegraph integration. */ -import type { LLink } from '@/lib/litegraph/src/LLink' -import type { Reroute } from '@/lib/litegraph/src/Reroute' + import type { CanvasColour, Point } from '@/lib/litegraph/src/interfaces' import { litegraph } from '@/lib/litegraph/src/litegraphInstance' import { diff --git a/src/renderer/core/canvas/litegraph/selectionAdapter.ts b/src/renderer/core/canvas/litegraph/selectionAdapter.ts index 390952dde07..2f18b88921a 100644 --- a/src/renderer/core/canvas/litegraph/selectionAdapter.ts +++ b/src/renderer/core/canvas/litegraph/selectionAdapter.ts @@ -1,3 +1,9 @@ +import type { + LGraph, + LGraphCanvas, + SubgraphInputNode, + SubgraphOutputNode +} from '@/lib/litegraph/src/types/entityRegistry' import type { SelectableKey, SelectionCommand @@ -6,16 +12,14 @@ import { parseSelectableKey, toSelectableKey } from '@/core/selection/selectionState' -import type { LGraph } from '@/lib/litegraph/src/LGraph' -import type { LGraphCanvas } from '@/lib/litegraph/src/LGraphCanvas' + import type { Positionable } from '@/lib/litegraph/src/interfaces' import { LGraphGroup } from '@/lib/litegraph/src/LGraphGroup' import { LGraphNode } from '@/lib/litegraph/src/LGraphNode' import { Reroute } from '@/lib/litegraph/src/Reroute' import { Subgraph } from '@/lib/litegraph/src/LGraph' import { SubgraphIONodeBase } from '@/lib/litegraph/src/subgraph/SubgraphIONodeBase' -import type { SubgraphInputNode } from '@/lib/litegraph/src/subgraph/SubgraphInputNode' -import type { SubgraphOutputNode } from '@/lib/litegraph/src/subgraph/SubgraphOutputNode' + import { useSelectionStore } from '@/core/selection/selectionStore' import { graphScopeOf } from '@/types/graphScopeId' import { toNodeId } from '@/types/nodeId' diff --git a/src/renderer/core/canvas/litegraph/slotCalculations.ts b/src/renderer/core/canvas/litegraph/slotCalculations.ts index 8232a4fcf3b..2e713f19289 100644 --- a/src/renderer/core/canvas/litegraph/slotCalculations.ts +++ b/src/renderer/core/canvas/litegraph/slotCalculations.ts @@ -1,3 +1,7 @@ +import type { + LGraphNode, + LGraph +} from '@/lib/litegraph/src/types/entityRegistry' /** * Slot Position Calculations * @@ -5,8 +9,7 @@ * This allows both litegraph nodes and the layout system to use the same * calculation logic while providing their own position data. */ -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' -import type { LGraph } from '@/lib/litegraph/src/LGraph' + import type { Point } from '@/lib/litegraph/src/interfaces' import type { INodeInputSlot, diff --git a/src/renderer/core/layout/operations/graphLayoutAttachment.ts b/src/renderer/core/layout/operations/graphLayoutAttachment.ts index f1e0f757d18..da30dc73d5e 100644 --- a/src/renderer/core/layout/operations/graphLayoutAttachment.ts +++ b/src/renderer/core/layout/operations/graphLayoutAttachment.ts @@ -1,7 +1,10 @@ -import type { LGraph } from '@/lib/litegraph/src/LGraph' -import type { LGraphGroup } from '@/lib/litegraph/src/LGraphGroup' -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' -import type { Reroute } from '@/lib/litegraph/src/Reroute' +import type { + LGraph, + LGraphGroup, + LGraphNode, + Reroute +} from '@/lib/litegraph/src/types/entityRegistry' + import { createMutationView } from '@/lib/litegraph/src/infrastructure/createMutationView' import { Rectangle } from '@/lib/litegraph/src/infrastructure/Rectangle' import type { diff --git a/src/renderer/core/layout/operations/layoutMutations.ts b/src/renderer/core/layout/operations/layoutMutations.ts index 08d1878aa24..452a73d423c 100644 --- a/src/renderer/core/layout/operations/layoutMutations.ts +++ b/src/renderer/core/layout/operations/layoutMutations.ts @@ -1,6 +1,7 @@ +import type { LGraph } from '@/lib/litegraph/src/types/entityRegistry' import type { NodeId } from '@/types/nodeId' import type { UUID } from '@/utils/uuid' -import type { LGraph } from '@/lib/litegraph/src/litegraph' + import { layoutStore } from '@/renderer/core/layout/store/layoutStore' import type { LayoutSource, Point } from '@/renderer/core/layout/types' diff --git a/src/stores/clearNodeOwnedStoreState.ts b/src/stores/clearNodeOwnedStoreState.ts index 241ed46d970..e10f7728c19 100644 --- a/src/stores/clearNodeOwnedStoreState.ts +++ b/src/stores/clearNodeOwnedStoreState.ts @@ -1,4 +1,5 @@ -import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import type { LGraphNode } from '@/lib/litegraph/src/types/entityRegistry' + import { createNodeLocatorId } from '@/types/nodeIdentification' import { parseNodeId } from '@/types/nodeId' diff --git a/src/stores/graphMetadataStore.ts b/src/stores/graphMetadataStore.ts index 774031f67c5..e25a9d0a2b9 100644 --- a/src/stores/graphMetadataStore.ts +++ b/src/stores/graphMetadataStore.ts @@ -1,7 +1,10 @@ +import type { + LGraphConfig, + LGraphExtra +} from '@/lib/litegraph/src/types/entityRegistry' import { defineStore } from 'pinia' import { shallowReactive } from 'vue' -import type { LGraphConfig, LGraphExtra } from '@/lib/litegraph/src/LGraph' import type { UUID } from '@/utils/uuid' interface GraphMetadata { diff --git a/src/stores/previewExposureStore.ts b/src/stores/previewExposureStore.ts index aa3fa6dee9b..ec432b9b11e 100644 --- a/src/stores/previewExposureStore.ts +++ b/src/stores/previewExposureStore.ts @@ -1,3 +1,4 @@ +import type { SubgraphNode } from '@/lib/litegraph/src/types/entityRegistry' import { defineStore } from 'pinia' import { ref } from 'vue' @@ -8,7 +9,7 @@ import type { import { resolvePreviewExposureChain } from '@/core/graph/subgraph/preview/previewExposureChain' import type { PromotedWidgetSource } from '@/core/graph/subgraph/promotedWidgetTypes' import type { PreviewExposure } from '@/core/schemas/previewExposureSchema' -import type { SubgraphNode } from '@/lib/litegraph/src/litegraph' + import { nextUniqueName } from '@/lib/litegraph/src/strings' import { createNodeLocatorId } from '@/types/nodeIdentification' import type { NodeLocatorId } from '@/types/nodeIdentification' diff --git a/src/utils/graphTraversalUtil.ts b/src/utils/graphTraversalUtil.ts index 556a04cc690..408b1017ead 100644 --- a/src/utils/graphTraversalUtil.ts +++ b/src/utils/graphTraversalUtil.ts @@ -3,7 +3,8 @@ import type { LGraphNode, Subgraph, SubgraphNode -} from '@/lib/litegraph/src/litegraph' +} from '@/lib/litegraph/src/types/entityRegistry' + import { LGraphEventMode } from '@/lib/litegraph/src/types/globalEnums' import type { NodeExecutionId, NodeLocatorId } from '@/types/nodeIdentification' import { diff --git a/src/utils/typeGuardUtil.ts b/src/utils/typeGuardUtil.ts index 9d456c3b033..c16e68b48db 100644 --- a/src/utils/typeGuardUtil.ts +++ b/src/utils/typeGuardUtil.ts @@ -1,9 +1,9 @@ import type { - INodeSlot, LGraph, LGraphNode, Subgraph -} from '@/lib/litegraph/src/litegraph' +} from '@/lib/litegraph/src/types/entityRegistry' +import type { INodeSlot } from '@/lib/litegraph/src/interfaces' import type { ResultItemType } from '@/schemas/resultItemTypeSchema' /** diff --git a/vite.types.config.mts b/vite.types.config.mts index fa0487d8414..81434eb2ad1 100644 --- a/vite.types.config.mts +++ b/vite.types.config.mts @@ -2,6 +2,8 @@ import { resolve } from 'path' import { defineConfig } from 'vite' import dts from 'vite-plugin-dts' +import { createLitegraphDeclarationTransform } from './scripts/litegraphDeclarations' + export default defineConfig({ build: { lib: { @@ -19,7 +21,10 @@ export default defineConfig({ copyDtsFiles: true, bundleTypes: true, processor: 'vue', - tsconfigPath: 'tsconfig.types.json' + tsconfigPath: 'tsconfig.types.json', + beforeWriteFile: createLitegraphDeclarationTransform( + resolve(__dirname, 'src/lib/litegraph/src') + ) }) ] }) From b6b2a113441de542148d5f8e0c60fde741546b20 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 12 Oct 2026 05:15:13 +0000 Subject: [PATCH 11/16] fix: repair pnpm lockfile --- pnpm-lock.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b0bd03a4846..223f126d9b8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -577,7 +577,7 @@ importers: version: 14.4.0(vue@3.5.42(typescript@6.0.3)) '@vueuse/integrations': specifier: 'catalog:' - version: 14.4.0(axios@1.18.1(debug@4.4.3))(fuse.js@7.0.0)(vue@3.5.42(typescript@6.0.3)) + version: 14.4.0(axios@1.18.1)(fuse.js@7.0.0)(vue@3.5.42(typescript@6.0.3)) '@vueuse/router': specifier: ^14.4.0 version: 14.4.0(vue-router@5.2.0(@vue/compiler-sfc@3.5.42)(esbuild@0.28.1)(pinia@4.0.2(@vue/devtools-api@8.1.5)(typescript@6.0.3)(vue@3.5.42(typescript@6.0.3)))(rolldown@1.2.6)(vite@8.2.2(@types/node@25.9.5)(esbuild@0.28.1)(jiti@2.7.0)(terser@5.49.0)(tsx@4.23.1)(yaml@2.9.0))(vue@3.5.42(typescript@6.0.3)))(vue@3.5.42(typescript@6.0.3)) @@ -13781,7 +13781,7 @@ snapshots: '@vueuse/shared': 14.4.0(vue@3.5.42(typescript@6.0.3)) vue: 3.5.42(typescript@6.0.3) - '@vueuse/integrations@14.4.0(axios@1.18.1(debug@4.4.3))(fuse.js@7.0.0)(vue@3.5.42(typescript@6.0.3))': + '@vueuse/integrations@14.4.0(axios@1.18.1)(fuse.js@7.0.0)(vue@3.5.42(typescript@6.0.3))': dependencies: '@vueuse/core': 14.4.0(vue@3.5.42(typescript@6.0.3)) '@vueuse/shared': 14.4.0(vue@3.5.42(typescript@6.0.3)) From f2c045d3b7076b21b2d20d2ce96527565d5ac54f Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Mon, 12 Oct 2026 05:32:01 +0000 Subject: [PATCH 12/16] fix: isolate declaration bundle consumer test --- scripts/litegraphDeclarations.test.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/litegraphDeclarations.test.ts b/scripts/litegraphDeclarations.test.ts index 432477deeb4..7fd63083fdd 100644 --- a/scripts/litegraphDeclarations.test.ts +++ b/scripts/litegraphDeclarations.test.ts @@ -122,10 +122,11 @@ it('publishes exact nominal, generic, and union types without augmentation depen } ) expect(result.succeeded).toBe(true) - expect(readFileSync(join(root, 'bundle.d.ts'), 'utf8')).not.toContain( - 'entityRegistry' - ) + const bundle = readFileSync(join(root, 'bundle.d.ts'), 'utf8') + expect(bundle).not.toContain('entityRegistry') + rmSync(root, { recursive: true, force: true }) writeFiles(root, { + 'bundle.d.ts': bundle, 'consumer.ts': ` import { Graph, Node, Box } from './bundle' type Equal = (() => T extends A ? 1 : 2) extends (() => T extends B ? 1 : 2) ? true : false @@ -143,6 +144,7 @@ it('publishes exact nominal, generic, and union types without augmentation depen }) const consumer = ts.createProgram([join(root, 'consumer.ts')], { ...options, + skipLibCheck: false, noEmit: true }) expect( From a52b77a359ab3e39e1121bfe7a1d4257a7a8e5e8 Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Fri, 16 Oct 2026 00:39:19 +0000 Subject: [PATCH 13/16] chore: update lint baseline for compatibility re-exports Amp-Thread-ID: https://ampcode.com/threads/T-b5f0b249-59df-4eca-a578-b3de03e7b95b --- oxlint-suppressions.json | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/oxlint-suppressions.json b/oxlint-suppressions.json index 38679a5d827..68045029cef 100644 --- a/oxlint-suppressions.json +++ b/oxlint-suppressions.json @@ -579,7 +579,7 @@ }, "src/lib/litegraph/src/litegraph.ts": { "comfy/no-reexports": { - "count": 54 + "count": 55 } }, "src/lib/litegraph/src/litegraphInstance.ts": { @@ -620,6 +620,16 @@ "count": 1 } }, + "src/lib/litegraph/src/subgraph/subgraphUtils.ts": { + "comfy/no-reexports": { + "count": 1 + } + }, + "src/lib/litegraph/src/types/widgets.ts": { + "comfy/no-reexports": { + "count": 1 + } + }, "src/lib/litegraph/src/utils/arrange.ts": { "comfy/no-positional-boolean-params": { "count": 1 @@ -1431,6 +1441,16 @@ "count": 36 } }, + "src/types/nodeState.ts": { + "comfy/no-reexports": { + "count": 1 + } + }, + "src/types/simplifiedWidget.ts": { + "comfy/no-reexports": { + "count": 1 + } + }, "src/types/slotId.test.ts": { "comfy/prefer-array-containing": { "count": 1 @@ -1571,4 +1591,4 @@ "count": 1 } } -} \ No newline at end of file +} From bafd45564897393eb6c654244e492157574632ed Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Fri, 16 Oct 2026 00:43:45 +0000 Subject: [PATCH 14/16] [automated] Apply ESLint and Oxfmt fixes --- oxlint-suppressions.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oxlint-suppressions.json b/oxlint-suppressions.json index 68045029cef..800cdb8426b 100644 --- a/oxlint-suppressions.json +++ b/oxlint-suppressions.json @@ -1591,4 +1591,4 @@ "count": 1 } } -} +} \ No newline at end of file From 97a6c5e10e470ac2ceaf87306c46d852cab6d720 Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Fri, 16 Oct 2026 04:46:21 +0000 Subject: [PATCH 15/16] test: allow declaration compilation time on CI Amp-Thread-ID: https://ampcode.com/threads/T-b5f0b249-59df-4eca-a578-b3de03e7b95b --- scripts/litegraphDeclarations.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/litegraphDeclarations.test.ts b/scripts/litegraphDeclarations.test.ts index 7fd63083fdd..9d32ce31552 100644 --- a/scripts/litegraphDeclarations.test.ts +++ b/scripts/litegraphDeclarations.test.ts @@ -152,4 +152,4 @@ it('publishes exact nominal, generic, and union types without augmentation depen .getPreEmitDiagnostics(consumer) .map((diagnostic) => diagnostic.messageText) ).toEqual([]) -}) +}, 30_000) From 3df7be4c0633dec8c5a025f959ba0b35dd4e2a4e Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Fri, 16 Oct 2026 20:59:45 +0000 Subject: [PATCH 16/16] fix: avoid graph import cycle in selection adapter Amp-Thread-ID: https://ampcode.com/threads/T-b5f0b249-59df-4eca-a578-b3de03e7b95b --- src/renderer/core/canvas/litegraph/selectionAdapter.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/renderer/core/canvas/litegraph/selectionAdapter.ts b/src/renderer/core/canvas/litegraph/selectionAdapter.ts index a018d1ffe2b..dc0a207e1cd 100644 --- a/src/renderer/core/canvas/litegraph/selectionAdapter.ts +++ b/src/renderer/core/canvas/litegraph/selectionAdapter.ts @@ -18,8 +18,8 @@ import type { Positionable } from '@/lib/litegraph/src/interfaces' import { LGraphGroup } from '@/lib/litegraph/src/LGraphGroup' import { LGraphNode } from '@/lib/litegraph/src/LGraphNode' import { Reroute } from '@/lib/litegraph/src/Reroute' -import { Subgraph } from '@/lib/litegraph/src/LGraph' import { SubgraphIONodeBase } from '@/lib/litegraph/src/subgraph/SubgraphIONodeBase' +import { isSubgraph } from '@/lib/litegraph/src/subgraph/subgraphTypeGuards' import { useSelectionStore } from '@/core/selection/selectionStore' import { graphScopeOf } from '@/types/graphScopeId' @@ -55,7 +55,7 @@ export function resolveSelectable( case 'reroute': return graph.getReroute(toRerouteId(Number(id))) case 'io': - if (!(graph instanceof Subgraph)) return undefined + if (!isSubgraph(graph)) return undefined return [graph.inputNode, graph.outputNode].find( (ioNode) => String(ioNode.id) === id )