Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions .fallow-baselines/dead-code.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/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/litegraph.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",
"src/platform/missingModel/missingModelStore.ts->src/scripts/app.ts",
Expand Down
6 changes: 3 additions & 3 deletions src/lib/litegraph/src/ContextMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -215,7 +215,7 @@ export class ContextMenu<TValue = unknown> {
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})`
}
}
Expand Down Expand Up @@ -384,7 +384,7 @@ export class ContextMenu<TValue = unknown> {
} else if (!ContextMenu.isCursorOverElement(e, this.parentMenu.root)) {
ContextMenu.trigger(
this.parentMenu.root,
`${LiteGraph.pointerevents_method}leave`,
`${litegraph().pointerevents_method}leave`,
e
)
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/litegraph/src/DragAndScale.ts
Original file line number Diff line number Diff line change
@@ -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 {
/**
Expand Down
11 changes: 8 additions & 3 deletions src/lib/litegraph/src/LGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -145,7 +146,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,
Expand All @@ -157,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,
Expand Down Expand Up @@ -940,7 +943,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')
}

Expand Down Expand Up @@ -3806,3 +3809,5 @@ export class Subgraph
}
}
}

provideSubgraphGuard((value): value is Subgraph => value instanceof Subgraph)
5 changes: 4 additions & 1 deletion src/lib/litegraph/src/LGraphCanvas.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -144,7 +145,7 @@ import type {
PanelWidgetCallback,
PanelWidgetOptions
} from './types/panel'
import { LiteGraph } from './litegraph'
import { LiteGraph } from './litegraphInstance'
import {
containsRect,
createBounds,
Expand Down Expand Up @@ -9111,3 +9112,5 @@ defineDeprecatedProperty(
'applyNodePositions',
'LGraphCanvas.repositionNodesVueMode is deprecated. Use applyNodePositions instead.'
)

provideCanvasClass(LGraphCanvas)
18 changes: 10 additions & 8 deletions src/lib/litegraph/src/LGraphGroup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NullGraphError } from '@/lib/litegraph/src/infrastructure/NullGraphError'
import { setGroupBoundsLayout } from '@/renderer/core/layout/operations/graphLayoutAttachment'

Check warning on line 2 in src/lib/litegraph/src/LGraphGroup.ts

View workflow job for this annotation

GitHub Actions / lint-pr / lint

comfy(no-restricted-paths)

src/lib/litegraph/src/LGraphGroup.ts:2:38: Unexpected path "@/renderer/core/layout/operations/graphLayoutAttachment" imported in restricted zone. src/lib/ is vendored leaf code and cannot import from app layers (violates layer architecture: lib → base → platform → workbench → renderer). Invert the dependency: have the app layer pass what it needs in, or move the shared type down into src/lib/ or src/base/.
import { layoutStore } from '@/renderer/core/layout/store/layoutStore'

Check warning on line 3 in src/lib/litegraph/src/LGraphGroup.ts

View workflow job for this annotation

GitHub Actions / lint-pr / lint

comfy(no-restricted-paths)

src/lib/litegraph/src/LGraphGroup.ts:3:29: Unexpected path "@/renderer/core/layout/store/layoutStore" imported in restricted zone. src/lib/ is vendored leaf code and cannot import from app layers (violates layer architecture: lib → base → platform → workbench → renderer). Invert the dependency: have the app layer pass what it needs in, or move the shared type down into src/lib/ or src/base/.
import { isSelectedIn, setSelectedIn } from '@/core/selection/selectionStore'
import { toSelectableKey } from '@/core/selection/selectionState'
Expand All @@ -10,7 +10,8 @@
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'
Expand All @@ -24,7 +25,8 @@
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,
Expand Down Expand Up @@ -123,7 +125,7 @@
// 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
}

Expand All @@ -139,7 +141,7 @@
/** @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
)
Expand Down Expand Up @@ -459,19 +461,19 @@
}
},
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 }
]
}

Expand Down
21 changes: 11 additions & 10 deletions src/lib/litegraph/src/LGraphNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ 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'
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 {
Expand Down Expand Up @@ -120,7 +121,8 @@ import type {
INodeSlotContextItem
} from './types/slots'
import type { Panel } from './types/panel'
import { LiteGraph, Subgraph } from './litegraph'
import { LiteGraph } from './litegraphInstance'
import { isSubgraph } from './subgraph/subgraphTypeGuards'
import type { LGraphNodeConstructor, SubgraphNode } from './litegraph'
import {
createBounds,
Expand Down Expand Up @@ -153,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,
Expand Down Expand Up @@ -659,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
Expand Down Expand Up @@ -2169,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
)
}
Expand Down Expand Up @@ -3440,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
Expand Down Expand Up @@ -4619,3 +4618,5 @@ export class LGraphNode
ctx.fillStyle = originalFillStyle
}
}

provideGraphNodeGuard((item): item is LGraphNode => item instanceof LGraphNode)
4 changes: 2 additions & 2 deletions src/lib/litegraph/src/Reroute.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { moveRerouteLayout } from '@/renderer/core/layout/operations/graphLayoutAttachment'

Check warning on line 1 in src/lib/litegraph/src/Reroute.ts

View workflow job for this annotation

GitHub Actions / lint-pr / lint

comfy(no-restricted-paths)

src/lib/litegraph/src/Reroute.ts:1:35: Unexpected path "@/renderer/core/layout/operations/graphLayoutAttachment" imported in restricted zone. src/lib/ is vendored leaf code and cannot import from app layers (violates layer architecture: lib → base → platform → workbench → renderer). Invert the dependency: have the app layer pass what it needs in, or move the shared type down into src/lib/ or src/base/.
import { layoutStore } from '@/renderer/core/layout/store/layoutStore'
import { isSelectedIn, setSelectedIn } from '@/core/selection/selectionStore'
import { toSelectableKey } from '@/core/selection/selectionState'
Expand Down Expand Up @@ -43,7 +43,7 @@
} 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'

Expand Down Expand Up @@ -472,7 +472,7 @@
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
Expand Down
34 changes: 34 additions & 0 deletions src/lib/litegraph/src/canvas/canvasClassAccess.ts
Original file line number Diff line number Diff line change
@@ -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<string, ColorOption>
_measureText?: (text: string, fontStyle?: string) => number
onShowPropertyEditor(
item: { property?: 'title' | 'font_size' },
options: IContextMenuOptions<string>,
event: MouseEvent,
menu: ContextMenu<string>,
node: { title: string; font_size?: number }
): void
onMenuNodeColors(
value: IContextMenuValue<string | null>,
options: IContextMenuOptions,
event: MouseEvent,
menu: ContextMenu<string | null>,
node: LGraphNode
): boolean
onMenuNodeRemove(): void
}

export let canvasClass: CanvasClassAccess

export function provideCanvasClass(value: CanvasClassAccess): void {
canvasClass = value
}
10 changes: 5 additions & 5 deletions src/lib/litegraph/src/canvas/linkGeometry.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions src/lib/litegraph/src/litegraphInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
11 changes: 8 additions & 3 deletions src/lib/litegraph/src/node/NodeInputSlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import type {
INodeInputSlot,
INodeOutputSlot
} from '@/lib/litegraph/src/types/slots'
import { LiteGraph } from '@/lib/litegraph/src/litegraph'
import { NodeSlot } from '@/lib/litegraph/src/node/NodeSlot'
import { LiteGraph } from '@/lib/litegraph/src/litegraphInstance'
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 {
Expand Down Expand Up @@ -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)
Loading
Loading