@codebolt/litegraph 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/LICENSE +19 -0
  2. package/README.md +161 -0
  3. package/dist/CanvasPointer.d.ts +120 -0
  4. package/dist/ContextMenu.d.ts +41 -0
  5. package/dist/CurveEditor.d.ts +18 -0
  6. package/dist/DragAndScale.d.ts +67 -0
  7. package/dist/LGraph.d.ts +407 -0
  8. package/dist/LGraphBadge.d.ts +33 -0
  9. package/dist/LGraphButton.d.ts +27 -0
  10. package/dist/LGraphCanvas.d.ts +772 -0
  11. package/dist/LGraphGroup.d.ts +81 -0
  12. package/dist/LGraphIcon.d.ts +22 -0
  13. package/dist/LGraphNode.d.ts +883 -0
  14. package/dist/LLink.d.ts +194 -0
  15. package/dist/LiteGraphGlobal.d.ts +360 -0
  16. package/dist/MapProxyHandler.d.ts +13 -0
  17. package/dist/Reroute.d.ts +185 -0
  18. package/dist/canvas/FloatingRenderLink.d.ts +55 -0
  19. package/dist/canvas/InputIndicators.d.ts +45 -0
  20. package/dist/canvas/LinkConnector.d.ts +165 -0
  21. package/dist/canvas/MovingInputLink.d.ts +34 -0
  22. package/dist/canvas/MovingLinkBase.d.ts +55 -0
  23. package/dist/canvas/MovingOutputLink.d.ts +30 -0
  24. package/dist/canvas/RenderLink.d.ts +39 -0
  25. package/dist/canvas/ToInputFromIoNodeLink.d.ts +37 -0
  26. package/dist/canvas/ToInputRenderLink.d.ts +35 -0
  27. package/dist/canvas/ToOutputFromIoNodeLink.d.ts +33 -0
  28. package/dist/canvas/ToOutputFromRerouteLink.d.ts +15 -0
  29. package/dist/canvas/ToOutputRenderLink.d.ts +32 -0
  30. package/dist/canvas/measureSlots.d.ts +22 -0
  31. package/dist/constants.d.ts +9 -0
  32. package/dist/css/litegraph.css +638 -0
  33. package/dist/draw.d.ts +65 -0
  34. package/dist/infrastructure/ConstrainedSize.d.ts +27 -0
  35. package/dist/infrastructure/CustomEventTarget.d.ts +72 -0
  36. package/dist/infrastructure/InvalidLinkError.d.ts +3 -0
  37. package/dist/infrastructure/LGraphCanvasEventMap.d.ts +41 -0
  38. package/dist/infrastructure/LGraphEventMap.d.ts +43 -0
  39. package/dist/infrastructure/LinkConnectorEventMap.d.ts +47 -0
  40. package/dist/infrastructure/NullGraphError.d.ts +3 -0
  41. package/dist/infrastructure/Rectangle.d.ts +163 -0
  42. package/dist/infrastructure/RecursionError.d.ts +6 -0
  43. package/dist/infrastructure/SlotIndexError.d.ts +3 -0
  44. package/dist/infrastructure/SubgraphEventMap.d.ts +49 -0
  45. package/dist/infrastructure/SubgraphInputEventMap.d.ts +13 -0
  46. package/dist/interfaces.d.ts +388 -0
  47. package/dist/litegraph.d.ts +95 -0
  48. package/dist/litegraph.es.js +17613 -0
  49. package/dist/litegraph.es.js.map +1 -0
  50. package/dist/litegraph.umd.js +3 -0
  51. package/dist/litegraph.umd.js.map +1 -0
  52. package/dist/measure.d.ts +168 -0
  53. package/dist/node/NodeInputSlot.d.ts +20 -0
  54. package/dist/node/NodeOutputSlot.d.ts +18 -0
  55. package/dist/node/NodeSlot.d.ts +35 -0
  56. package/dist/node/SlotBase.d.ts +27 -0
  57. package/dist/node/slotUtils.d.ts +17 -0
  58. package/dist/polyfills.d.ts +1 -0
  59. package/dist/strings.d.ts +22 -0
  60. package/dist/subgraph/EmptySubgraphInput.d.ts +15 -0
  61. package/dist/subgraph/EmptySubgraphOutput.d.ts +15 -0
  62. package/dist/subgraph/ExecutableNodeDTO.d.ts +96 -0
  63. package/dist/subgraph/Subgraph.d.ts +65 -0
  64. package/dist/subgraph/SubgraphIONodeBase.d.ts +80 -0
  65. package/dist/subgraph/SubgraphInput.d.ts +47 -0
  66. package/dist/subgraph/SubgraphInputNode.d.ts +33 -0
  67. package/dist/subgraph/SubgraphNode.d.ts +73 -0
  68. package/dist/subgraph/SubgraphOutput.d.ts +30 -0
  69. package/dist/subgraph/SubgraphOutputNode.d.ts +31 -0
  70. package/dist/subgraph/SubgraphSlotBase.d.ts +61 -0
  71. package/dist/subgraph/subgraphUtils.d.ts +77 -0
  72. package/dist/types/NodeLike.d.ts +7 -0
  73. package/dist/types/events.d.ts +64 -0
  74. package/dist/types/globalEnums.d.ts +130 -0
  75. package/dist/types/serialisation.d.ts +198 -0
  76. package/dist/types/utility.d.ts +11 -0
  77. package/dist/types/widgets.d.ts +209 -0
  78. package/dist/utils/arrange.d.ts +22 -0
  79. package/dist/utils/collections.d.ts +38 -0
  80. package/dist/utils/feedback.d.ts +7 -0
  81. package/dist/utils/object.d.ts +1 -0
  82. package/dist/utils/spaceDistribution.d.ts +11 -0
  83. package/dist/utils/textUtils.d.ts +9 -0
  84. package/dist/utils/type.d.ts +14 -0
  85. package/dist/utils/uuid.d.ts +13 -0
  86. package/dist/utils/widget.d.ts +7 -0
  87. package/dist/widgets/BaseSteppedWidget.d.ts +34 -0
  88. package/dist/widgets/BaseWidget.d.ts +125 -0
  89. package/dist/widgets/BooleanWidget.d.ts +9 -0
  90. package/dist/widgets/ButtonWidget.d.ts +16 -0
  91. package/dist/widgets/ComboWidget.d.ts +17 -0
  92. package/dist/widgets/KnobWidget.d.ts +20 -0
  93. package/dist/widgets/LegacyWidget.d.ts +14 -0
  94. package/dist/widgets/NumberWidget.d.ts +18 -0
  95. package/dist/widgets/SliderWidget.d.ts +20 -0
  96. package/dist/widgets/TextWidget.d.ts +13 -0
  97. package/dist/widgets/widgetMap.d.ts +50 -0
  98. package/package.json +76 -0
@@ -0,0 +1,185 @@
1
+ import { CanvasColour, INodeInputSlot, INodeOutputSlot, LinkNetwork, LinkSegment, Point, Positionable, ReadonlyLinkNetwork, ReadOnlyRect } from './interfaces';
2
+ import { LGraphNode, NodeId } from './LGraphNode';
3
+ import { Serialisable, SerialisableReroute } from './types/serialisation';
4
+ import { LinkId, LLink } from './LLink';
5
+ export type RerouteId = number;
6
+ /** The input or output slot that an incomplete reroute link is connected to. */
7
+ export interface FloatingRerouteSlot {
8
+ /** Floating connection to an input or output */
9
+ slotType: "input" | "output";
10
+ }
11
+ /**
12
+ * Represents an additional point on the graph that a link path will travel through. Used for visual organisation only.
13
+ *
14
+ * Requires no disposal or clean up.
15
+ * Stores only primitive values (IDs) to reference other items in its network,
16
+ * and a `WeakRef` to a {@link LinkNetwork} to resolve them.
17
+ */
18
+ export declare class Reroute implements Positionable, LinkSegment, Serialisable<SerialisableReroute> {
19
+ #private;
20
+ readonly id: RerouteId;
21
+ static radius: number;
22
+ /** Maximum distance from reroutes to their bezier curve control points. */
23
+ static maxSplineOffset: number;
24
+ static drawIdBadge: boolean;
25
+ static slotRadius: number;
26
+ /** Distance from reroute centre to slot centre. */
27
+ static get slotOffset(): number;
28
+ get parentId(): RerouteId | undefined;
29
+ /** Ignores attempts to create an infinite loop. @inheritdoc */
30
+ set parentId(value: RerouteId | undefined);
31
+ get parent(): Reroute | undefined;
32
+ /** This property is only defined on the last reroute of a floating reroute chain (closest to input end). */
33
+ floating?: FloatingRerouteSlot;
34
+ /** @inheritdoc */
35
+ get pos(): Point;
36
+ set pos(value: Point);
37
+ /** @inheritdoc */
38
+ get boundingRect(): ReadOnlyRect;
39
+ /** The total number of links & floating links using this reroute */
40
+ get totalLinks(): number;
41
+ /** @inheritdoc */
42
+ selected?: boolean;
43
+ /** The ID ({@link LLink.id}) of every link using this reroute */
44
+ linkIds: Set<LinkId>;
45
+ /** The ID ({@link LLink.id}) of every floating link using this reroute */
46
+ floatingLinkIds: Set<LinkId>;
47
+ /** Cached cos */
48
+ cos: number;
49
+ sin: number;
50
+ /** Bezier curve control point for the "target" (input) side of the link */
51
+ controlPoint: Point;
52
+ /** @inheritdoc */
53
+ path?: Path2D;
54
+ /** @inheritdoc */
55
+ _centreAngle?: number;
56
+ /** @inheritdoc */
57
+ _pos: Float32Array;
58
+ /** @inheritdoc */
59
+ _dragging?: boolean;
60
+ /** Colour of the first link that rendered this reroute */
61
+ _colour?: CanvasColour;
62
+ /** Colour of the first link that rendered this reroute */
63
+ get colour(): CanvasColour;
64
+ get isSlotHovered(): boolean;
65
+ get isInputHovered(): boolean;
66
+ get isOutputHovered(): boolean;
67
+ get firstLink(): LLink | undefined;
68
+ get firstFloatingLink(): LLink | undefined;
69
+ /** @inheritdoc */
70
+ get origin_id(): NodeId | undefined;
71
+ /** @inheritdoc */
72
+ get origin_slot(): number | undefined;
73
+ /**
74
+ * Initialises a new link reroute object.
75
+ * @param id Unique identifier for this reroute
76
+ * @param network The network of links this reroute belongs to. Internally converted to a WeakRef.
77
+ * @param pos Position in graph coordinates
78
+ * @param linkIds Link IDs ({@link LLink.id}) of all links that use this reroute
79
+ */
80
+ constructor(id: RerouteId, network: LinkNetwork, pos?: Point, parentId?: RerouteId, linkIds?: Iterable<LinkId>, floatingLinkIds?: Iterable<LinkId>);
81
+ /**
82
+ * Applies a new parentId to the reroute, and optinoally a new position and linkId.
83
+ * Primarily used for deserialisation.
84
+ * @param parentId The ID of the reroute prior to this reroute, or
85
+ * `undefined` if it is the first reroute connected to a nodes output
86
+ * @param pos The position of this reroute
87
+ * @param linkIds All link IDs that pass through this reroute
88
+ */
89
+ update(parentId: RerouteId | undefined, pos?: Point, linkIds?: Iterable<LinkId>, floating?: FloatingRerouteSlot): void;
90
+ /**
91
+ * Validates the linkIds this reroute has. Removes broken links.
92
+ * @param links Collection of valid links
93
+ * @returns true if any links remain after validation
94
+ */
95
+ validateLinks(links: ReadonlyMap<LinkId, LLink>, floatingLinks: ReadonlyMap<LinkId, LLink>): boolean;
96
+ /**
97
+ * Retrieves an ordered array of all reroutes from the node output.
98
+ * @param visited Internal. A set of reroutes that this function
99
+ * has already visited whilst recursing up the chain.
100
+ * @returns An ordered array of all reroutes from the node output to this reroute, inclusive.
101
+ * `null` if an infinite loop is detected.
102
+ * `undefined` if the reroute chain or {@link LinkNetwork} are invalid.
103
+ */
104
+ getReroutes(visited?: Set<Reroute>): Reroute[] | null;
105
+ /**
106
+ * Internal. Called by {@link LLink.findNextReroute}. Not intended for use by itself.
107
+ * @param withParentId The rerouteId to look for
108
+ * @param visited A set of reroutes that have already been visited
109
+ * @returns The reroute that was found, `undefined` if no reroute was found, or `null` if an infinite loop was detected.
110
+ */
111
+ findNextReroute(withParentId: RerouteId, visited?: Set<Reroute>): Reroute | null | undefined;
112
+ /**
113
+ * Finds the output node and output slot of the first link passing through this reroute.
114
+ * @returns The output node and output slot of the first link passing through this reroute, or `undefined` if no link is found.
115
+ */
116
+ findSourceOutput(): {
117
+ node: LGraphNode;
118
+ output: INodeOutputSlot;
119
+ } | undefined;
120
+ /**
121
+ * Finds the inputs and nodes of (floating) links passing through this reroute.
122
+ * @returns An array of objects containing the node and input slot of each link passing through this reroute.
123
+ */
124
+ findTargetInputs(): {
125
+ node: LGraphNode;
126
+ input: INodeInputSlot;
127
+ link: LLink;
128
+ }[] | undefined;
129
+ /**
130
+ * Retrieves all floating links passing through this reroute.
131
+ * @param from Filters the links by the currently connected link side.
132
+ * @returns An array of floating links
133
+ */
134
+ getFloatingLinks(from: "input" | "output"): LLink[] | undefined;
135
+ /**
136
+ * Changes the origin node/output of all floating links that pass through this reroute.
137
+ * @param node The new origin node
138
+ * @param output The new origin output slot
139
+ * @param index The slot index of {@link output}
140
+ */
141
+ setFloatingLinkOrigin(node: LGraphNode, output: INodeOutputSlot, index: number): void;
142
+ /** @inheritdoc */
143
+ move(deltaX: number, deltaY: number): void;
144
+ /** @inheritdoc */
145
+ snapToGrid(snapTo: number): boolean;
146
+ removeAllFloatingLinks(): void;
147
+ removeFloatingLink(linkId: LinkId): void;
148
+ /**
149
+ * Removes a link or floating link from this reroute, by matching link object instance equality.
150
+ * @param link The link to remove.
151
+ * @remarks Does not remove the link from the network.
152
+ */
153
+ removeLink(link: LLink): void;
154
+ remove(): void;
155
+ calculateAngle(lastRenderTime: number, network: ReadonlyLinkNetwork, linkStart: Point): void;
156
+ /**
157
+ * Renders the reroute on the canvas.
158
+ * @param ctx Canvas context to draw on
159
+ * @param backgroundPattern The canvas background pattern; used to make floating reroutes appear washed out.
160
+ * @remarks Leaves {@link ctx}.fillStyle, strokeStyle, and lineWidth dirty (perf.).
161
+ */
162
+ draw(ctx: CanvasRenderingContext2D, backgroundPattern?: CanvasPattern): void;
163
+ /**
164
+ * Draws the input and output slots on the canvas, if the slots are visible.
165
+ * @param ctx The canvas context to draw on.
166
+ */
167
+ drawSlots(ctx: CanvasRenderingContext2D): void;
168
+ drawHighlight(ctx: CanvasRenderingContext2D, colour: CanvasColour): void;
169
+ /**
170
+ * Updates visibility of the input and output slots, based on the position of the pointer.
171
+ * @param pos The position of the pointer.
172
+ * @returns `true` if any changes require a redraw.
173
+ */
174
+ updateVisibility(pos: Point): boolean;
175
+ /** Prevents rendering of the input and output slots. */
176
+ hideSlots(): void;
177
+ /**
178
+ * Precisely determines if {@link pos} is inside this reroute.
179
+ * @param pos The position to check (canvas space)
180
+ * @returns `true` if {@link pos} is within the reroute's radius.
181
+ */
182
+ containsPoint(pos: Point): boolean;
183
+ /** @inheritdoc */
184
+ asSerialisable(): SerialisableReroute;
185
+ }
@@ -0,0 +1,55 @@
1
+ import { RenderLink } from './RenderLink';
2
+ import { CustomEventTarget } from '../infrastructure/CustomEventTarget';
3
+ import { LinkConnectorEventMap } from '../infrastructure/LinkConnectorEventMap';
4
+ import { INodeOutputSlot, LinkNetwork, INodeInputSlot, Point } from '../interfaces';
5
+ import { LGraphNode, NodeId } from '../LGraphNode';
6
+ import { LLink } from '../LLink';
7
+ import { Reroute } from '../Reroute';
8
+ import { SubgraphInput } from '../subgraph/SubgraphInput';
9
+ import { SubgraphOutput } from '../subgraph/SubgraphOutput';
10
+ import { LinkDirection } from '../types/globalEnums';
11
+ /**
12
+ * Represents a floating link that is currently being dragged from one slot to another.
13
+ *
14
+ * This is a heavier, but short-lived convenience data structure. All refs to FloatingRenderLinks should be discarded on drop.
15
+ * @remarks
16
+ * At time of writing, Litegraph is using several different styles and methods to handle link dragging.
17
+ *
18
+ * Once the library has undergone more substantial changes to the way links are managed,
19
+ * many properties of this class will be superfluous and removable.
20
+ */
21
+ export declare class FloatingRenderLink implements RenderLink {
22
+ readonly network: LinkNetwork;
23
+ readonly link: LLink;
24
+ readonly toType: "input" | "output";
25
+ readonly fromReroute: Reroute;
26
+ readonly dragDirection: LinkDirection;
27
+ readonly node: LGraphNode;
28
+ readonly fromSlot: INodeOutputSlot | INodeInputSlot;
29
+ readonly fromPos: Point;
30
+ readonly fromDirection: LinkDirection;
31
+ readonly fromSlotIndex: number;
32
+ readonly outputNodeId: NodeId;
33
+ readonly outputNode?: LGraphNode;
34
+ readonly outputSlot?: INodeOutputSlot;
35
+ readonly outputIndex: number;
36
+ readonly outputPos?: Point;
37
+ readonly inputNodeId: NodeId;
38
+ readonly inputNode?: LGraphNode;
39
+ readonly inputSlot?: INodeInputSlot;
40
+ readonly inputIndex: number;
41
+ readonly inputPos?: Point;
42
+ constructor(network: LinkNetwork, link: LLink, toType: "input" | "output", fromReroute: Reroute, dragDirection?: LinkDirection);
43
+ canConnectToInput(): boolean;
44
+ canConnectToOutput(): boolean;
45
+ canConnectToReroute(reroute: Reroute): boolean;
46
+ connectToInput(node: LGraphNode, input: INodeInputSlot, _events?: CustomEventTarget<LinkConnectorEventMap>): void;
47
+ connectToOutput(node: LGraphNode, output: INodeOutputSlot, _events?: CustomEventTarget<LinkConnectorEventMap>): void;
48
+ connectToSubgraphInput(input: SubgraphInput, _events?: CustomEventTarget<LinkConnectorEventMap>): void;
49
+ connectToSubgraphOutput(output: SubgraphOutput, _events?: CustomEventTarget<LinkConnectorEventMap>): void;
50
+ connectToRerouteInput(reroute: Reroute, { node: inputNode, input }: {
51
+ node: LGraphNode;
52
+ input: INodeInputSlot;
53
+ }, events: CustomEventTarget<LinkConnectorEventMap>): void;
54
+ connectToRerouteOutput(reroute: Reroute, outputNode: LGraphNode, output: INodeOutputSlot, events: CustomEventTarget<LinkConnectorEventMap>): void;
55
+ }
@@ -0,0 +1,45 @@
1
+ import { LGraphCanvas } from '../LGraphCanvas';
2
+ /**
3
+ * A class that can be added to the render cycle to show pointer / keyboard status symbols.
4
+ *
5
+ * Used to create videos of feature changes.
6
+ *
7
+ * Example usage with ComfyUI_frontend, via console / devtools:
8
+ *
9
+ * ```ts
10
+ * const inputIndicators = new InputIndicators(canvas)
11
+ * // Dispose:
12
+ * inputIndicators.dispose()
13
+ * ```
14
+ */
15
+ export declare class InputIndicators implements Disposable {
16
+ #private;
17
+ canvas: LGraphCanvas;
18
+ radius: number;
19
+ startAngle: number;
20
+ endAngle: number;
21
+ inactiveColour: string;
22
+ colour1: string;
23
+ colour2: string;
24
+ colour3: string;
25
+ fontString: string;
26
+ enabled: boolean;
27
+ shiftDown: boolean;
28
+ undoDown: boolean;
29
+ redoDown: boolean;
30
+ ctrlDown: boolean;
31
+ altDown: boolean;
32
+ mouse0Down: boolean;
33
+ mouse1Down: boolean;
34
+ mouse2Down: boolean;
35
+ x: number;
36
+ y: number;
37
+ controller?: AbortController;
38
+ constructor(canvas: LGraphCanvas);
39
+ onPointerDownOrMove(e: MouseEvent): void;
40
+ onPointerUp(): void;
41
+ onKeyDownOrUp(e: KeyboardEvent): void;
42
+ draw(): void;
43
+ dispose(): void;
44
+ [Symbol.dispose](): void;
45
+ }
@@ -0,0 +1,165 @@
1
+ import { RenderLink } from './RenderLink';
2
+ import { LinkConnectorEventMap } from '../infrastructure/LinkConnectorEventMap';
3
+ import { ConnectingLink, ItemLocator, LinkNetwork, LinkSegment, INodeInputSlot, INodeOutputSlot } from '../interfaces';
4
+ import { LGraphNode } from '../LGraphNode';
5
+ import { Reroute } from '../Reroute';
6
+ import { SubgraphInput } from '../subgraph/SubgraphInput';
7
+ import { SubgraphOutput } from '../subgraph/SubgraphOutput';
8
+ import { CanvasPointerEvent } from '../types/events';
9
+ import { IBaseWidget } from '../types/widgets';
10
+ import { CustomEventTarget } from '../infrastructure/CustomEventTarget';
11
+ import { LLink } from '../LLink';
12
+ import { SubgraphInputNode } from '../subgraph/SubgraphInputNode';
13
+ import { SubgraphOutputNode } from '../subgraph/SubgraphOutputNode';
14
+ import { FloatingRenderLink } from './FloatingRenderLink';
15
+ import { MovingInputLink } from './MovingInputLink';
16
+ import { MovingOutputLink } from './MovingOutputLink';
17
+ import { ToInputFromIoNodeLink } from './ToInputFromIoNodeLink';
18
+ import { ToInputRenderLink } from './ToInputRenderLink';
19
+ import { ToOutputFromIoNodeLink } from './ToOutputFromIoNodeLink';
20
+ import { ToOutputRenderLink } from './ToOutputRenderLink';
21
+ /**
22
+ * A Litegraph state object for the {@link LinkConnector}.
23
+ * References are only held atomically within a function, never passed.
24
+ * The concrete implementation may be replaced or proxied without side-effects.
25
+ */
26
+ export interface LinkConnectorState {
27
+ /**
28
+ * The type of slot that links are being connected **to**.
29
+ * - When `undefined`, no operation is being performed.
30
+ * - A change in this property indicates the start or end of dragging links.
31
+ */
32
+ connectingTo: "input" | "output" | undefined;
33
+ multi: boolean;
34
+ /** When `true`, existing links are being repositioned. Otherwise, new links are being created. */
35
+ draggingExistingLinks: boolean;
36
+ /** When set, connecting links will all snap to this position. */
37
+ snapLinksPos?: [number, number];
38
+ }
39
+ /** Discriminated union to simplify type narrowing. */
40
+ type RenderLinkUnion = MovingInputLink | MovingOutputLink | FloatingRenderLink | ToInputRenderLink | ToOutputRenderLink | ToInputFromIoNodeLink | ToOutputFromIoNodeLink;
41
+ export interface LinkConnectorExport {
42
+ renderLinks: RenderLink[];
43
+ inputLinks: LLink[];
44
+ outputLinks: LLink[];
45
+ floatingLinks: LLink[];
46
+ state: LinkConnectorState;
47
+ network: LinkNetwork;
48
+ }
49
+ /**
50
+ * Component of {@link LGraphCanvas} that handles connecting and moving links.
51
+ * @see {@link LLink}
52
+ */
53
+ export declare class LinkConnector {
54
+ #private;
55
+ /**
56
+ * Link connection state POJO. Source of truth for state of link drag operations.
57
+ *
58
+ * Can be replaced or proxied to allow notifications.
59
+ * Is always dereferenced at the start of an operation.
60
+ */
61
+ state: LinkConnectorState;
62
+ readonly events: CustomEventTarget<LinkConnectorEventMap, "reset" | "before-drop-links" | "after-drop-links" | "before-move-input" | "before-move-output" | "input-moved" | "output-moved" | "link-created" | "dropped-on-reroute" | "dropped-on-node" | "dropped-on-io-node" | "dropped-on-canvas" | "dropped-on-widget">;
63
+ /** Contains information for rendering purposes only. */
64
+ readonly renderLinks: RenderLinkUnion[];
65
+ /** Existing links that are being moved **to** a new input slot. */
66
+ readonly inputLinks: LLink[];
67
+ /** Existing links that are being moved **to** a new output slot. */
68
+ readonly outputLinks: LLink[];
69
+ /** Existing floating links that are being moved to a new slot. */
70
+ readonly floatingLinks: LLink[];
71
+ readonly hiddenReroutes: Set<Reroute>;
72
+ /** The widget beneath the pointer, if it is a valid connection target. */
73
+ overWidget?: IBaseWidget;
74
+ /** The type (returned by downstream callback) for {@link overWidget} */
75
+ overWidgetType?: string;
76
+ /** The reroute beneath the pointer, if it is a valid connection target. */
77
+ overReroute?: Reroute;
78
+ constructor(setConnectingLinks: (value: ConnectingLink[]) => void);
79
+ get isConnecting(): boolean;
80
+ get draggingExistingLinks(): boolean;
81
+ /** Drag an existing link to a different input. */
82
+ moveInputLink(network: LinkNetwork, input: INodeInputSlot): void;
83
+ /** Drag all links from an output to a new output. */
84
+ moveOutputLink(network: LinkNetwork, output: INodeOutputSlot): void;
85
+ /**
86
+ * Drags a new link from an output slot to an input slot.
87
+ * @param network The network that the link being connected belongs to
88
+ * @param node The node the link is being dragged from
89
+ * @param output The output slot that the link is being dragged from
90
+ */
91
+ dragNewFromOutput(network: LinkNetwork, node: LGraphNode, output: INodeOutputSlot, fromReroute?: Reroute): void;
92
+ /**
93
+ * Drags a new link from an input slot to an output slot.
94
+ * @param network The network that the link being connected belongs to
95
+ * @param node The node the link is being dragged from
96
+ * @param input The input slot that the link is being dragged from
97
+ */
98
+ dragNewFromInput(network: LinkNetwork, node: LGraphNode, input: INodeInputSlot, fromReroute?: Reroute): void;
99
+ dragNewFromSubgraphInput(network: LinkNetwork, inputNode: SubgraphInputNode, input: SubgraphInput, fromReroute?: Reroute): void;
100
+ dragNewFromSubgraphOutput(network: LinkNetwork, outputNode: SubgraphOutputNode, output: SubgraphOutput, fromReroute?: Reroute): void;
101
+ /**
102
+ * Drags a new link from a reroute to an input slot.
103
+ * @param network The network that the link being connected belongs to
104
+ * @param reroute The reroute that the link is being dragged from
105
+ */
106
+ dragFromReroute(network: LinkNetwork, reroute: Reroute): void;
107
+ /**
108
+ * Drags a new link from a reroute to an output slot.
109
+ * @param network The network that the link being connected belongs to
110
+ * @param reroute The reroute that the link is being dragged from
111
+ */
112
+ dragFromRerouteToOutput(network: LinkNetwork, reroute: Reroute): void;
113
+ dragFromLinkSegment(network: LinkNetwork, linkSegment: LinkSegment): void;
114
+ /**
115
+ * Connects the links being dropped
116
+ * @param event Contains the drop location, in canvas space
117
+ */
118
+ dropLinks(locator: ItemLocator, event: CanvasPointerEvent): void;
119
+ dropOnIoNode(ioNode: SubgraphInputNode | SubgraphOutputNode, event: CanvasPointerEvent): void;
120
+ dropOnNode(node: LGraphNode, event: CanvasPointerEvent): void;
121
+ dropOnReroute(reroute: Reroute, event: CanvasPointerEvent): void;
122
+ /** @internal Temporary workaround - requires refactor. */
123
+ _connectOutputToReroute(reroute: Reroute, renderLink: RenderLinkUnion): void;
124
+ dropOnNothing(event: CanvasPointerEvent): void;
125
+ /**
126
+ * Disconnects all moving links.
127
+ * @remarks This is called when the links are dropped on the canvas.
128
+ * May be called by consumers to e.g. drag links into a bin / void.
129
+ */
130
+ disconnectLinks(): void;
131
+ /**
132
+ * Connects the links being dropped onto a node to the first matching slot.
133
+ * @param node The node that the links are being dropped on
134
+ * @param event Contains the drop location, in canvas space
135
+ */
136
+ connectToNode(node: LGraphNode, event: CanvasPointerEvent): void;
137
+ isInputValidDrop(node: LGraphNode, input: INodeInputSlot): boolean;
138
+ isNodeValidDrop(node: LGraphNode): boolean;
139
+ /**
140
+ * Checks if a reroute is a valid drop target for any of the links being connected.
141
+ * @param reroute The reroute that would be dropped on.
142
+ * @returns `true` if any of the current links being connected are valid for the given reroute.
143
+ */
144
+ isRerouteValidDrop(reroute: Reroute): boolean;
145
+ /**
146
+ * Exports the current state of the link connector.
147
+ * @param network The network that the links being connected belong to.
148
+ * @returns A POJO with the state of the link connector, links being connected, and their network.
149
+ * @remarks Other than {@link network}, all properties are shallow cloned.
150
+ */
151
+ export(network: LinkNetwork): LinkConnectorExport;
152
+ /**
153
+ * Adds an event listener that will be automatically removed when the reset event is fired.
154
+ * @param eventName The event to listen for.
155
+ * @param listener The listener to call when the event is fired.
156
+ */
157
+ listenUntilReset<K extends keyof LinkConnectorEventMap>(eventName: K, listener: Parameters<typeof this.events.addEventListener<K>>[1], options?: Parameters<typeof this.events.addEventListener<K>>[2]): void;
158
+ /**
159
+ * Resets everything to its initial state.
160
+ *
161
+ * Effectively cancels moving or connecting links.
162
+ */
163
+ reset(force?: boolean): void;
164
+ }
165
+ export {};
@@ -0,0 +1,34 @@
1
+ import { CustomEventTarget } from '../infrastructure/CustomEventTarget';
2
+ import { LinkConnectorEventMap } from '../infrastructure/LinkConnectorEventMap';
3
+ import { INodeInputSlot, INodeOutputSlot, LinkNetwork, Point } from '../interfaces';
4
+ import { LGraphNode } from '../LGraphNode';
5
+ import { LLink } from '../LLink';
6
+ import { Reroute } from '../Reroute';
7
+ import { SubgraphOutput } from '../subgraph/SubgraphOutput';
8
+ import { NodeLike } from '../types/NodeLike';
9
+ import { SubgraphIO } from '../types/serialisation';
10
+ import { LinkDirection } from '../types/globalEnums';
11
+ import { MovingLinkBase } from './MovingLinkBase';
12
+ export declare class MovingInputLink extends MovingLinkBase {
13
+ readonly toType = "input";
14
+ readonly node: LGraphNode;
15
+ readonly fromSlot: INodeOutputSlot;
16
+ readonly fromPos: Point;
17
+ readonly fromDirection: LinkDirection;
18
+ readonly fromSlotIndex: number;
19
+ constructor(network: LinkNetwork, link: LLink, fromReroute?: Reroute, dragDirection?: LinkDirection);
20
+ canConnectToInput(inputNode: NodeLike, input: INodeInputSlot | SubgraphIO): boolean;
21
+ canConnectToOutput(): false;
22
+ canConnectToReroute(reroute: Reroute): boolean;
23
+ connectToInput(inputNode: LGraphNode, input: INodeInputSlot, events: CustomEventTarget<LinkConnectorEventMap>): LLink | null | undefined;
24
+ connectToOutput(): never;
25
+ connectToSubgraphInput(): void;
26
+ connectToSubgraphOutput(output: SubgraphOutput, events?: CustomEventTarget<LinkConnectorEventMap>): void;
27
+ connectToRerouteInput(reroute: Reroute, { node: inputNode, input, link: existingLink }: {
28
+ node: LGraphNode;
29
+ input: INodeInputSlot;
30
+ link: LLink;
31
+ }, events: CustomEventTarget<LinkConnectorEventMap>, originalReroutes: Reroute[]): void;
32
+ connectToRerouteOutput(): never;
33
+ disconnect(): boolean;
34
+ }
@@ -0,0 +1,55 @@
1
+ import { RenderLink } from './RenderLink';
2
+ import { CustomEventTarget } from '../infrastructure/CustomEventTarget';
3
+ import { LinkConnectorEventMap } from '../infrastructure/LinkConnectorEventMap';
4
+ import { INodeInputSlot, INodeOutputSlot, LinkNetwork, Point } from '../interfaces';
5
+ import { LGraphNode, NodeId } from '../LGraphNode';
6
+ import { LLink } from '../LLink';
7
+ import { Reroute } from '../Reroute';
8
+ import { SubgraphInput } from '../subgraph/SubgraphInput';
9
+ import { SubgraphOutput } from '../subgraph/SubgraphOutput';
10
+ import { LinkDirection } from '../types/globalEnums';
11
+ /**
12
+ * Represents an existing link that is currently being dragged by the user from one slot to another.
13
+ *
14
+ * This is a heavier, but short-lived convenience data structure.
15
+ * All refs to {@link MovingInputLink} and {@link MovingOutputLink} should be discarded on drop.
16
+ * @remarks
17
+ * At time of writing, Litegraph is using several different styles and methods to handle link dragging.
18
+ *
19
+ * Once the library has undergone more substantial changes to the way links are managed,
20
+ * many properties of this class will be superfluous and removable.
21
+ */
22
+ export declare abstract class MovingLinkBase implements RenderLink {
23
+ readonly network: LinkNetwork;
24
+ readonly link: LLink;
25
+ readonly toType: "input" | "output";
26
+ readonly fromReroute?: Reroute | undefined;
27
+ readonly dragDirection: LinkDirection;
28
+ abstract readonly node: LGraphNode;
29
+ abstract readonly fromSlot: INodeOutputSlot | INodeInputSlot;
30
+ abstract readonly fromPos: Point;
31
+ abstract readonly fromDirection: LinkDirection;
32
+ abstract readonly fromSlotIndex: number;
33
+ readonly outputNodeId: NodeId;
34
+ readonly outputNode: LGraphNode;
35
+ readonly outputSlot: INodeOutputSlot;
36
+ readonly outputIndex: number;
37
+ readonly outputPos: Point;
38
+ readonly inputNodeId: NodeId;
39
+ readonly inputNode: LGraphNode;
40
+ readonly inputSlot: INodeInputSlot;
41
+ readonly inputIndex: number;
42
+ readonly inputPos: Point;
43
+ constructor(network: LinkNetwork, link: LLink, toType: "input" | "output", fromReroute?: Reroute | undefined, dragDirection?: LinkDirection);
44
+ abstract connectToInput(node: LGraphNode, input: INodeInputSlot, events?: CustomEventTarget<LinkConnectorEventMap>): void;
45
+ abstract connectToOutput(node: LGraphNode, output: INodeOutputSlot, events?: CustomEventTarget<LinkConnectorEventMap>): void;
46
+ abstract connectToSubgraphInput(input: SubgraphInput, events?: CustomEventTarget<LinkConnectorEventMap>): void;
47
+ abstract connectToSubgraphOutput(output: SubgraphOutput, events?: CustomEventTarget<LinkConnectorEventMap>): void;
48
+ abstract connectToRerouteInput(reroute: Reroute, { node, input, link }: {
49
+ node: LGraphNode;
50
+ input: INodeInputSlot;
51
+ link: LLink;
52
+ }, events: CustomEventTarget<LinkConnectorEventMap>, originalReroutes: Reroute[]): void;
53
+ abstract connectToRerouteOutput(reroute: Reroute, outputNode: LGraphNode, output: INodeOutputSlot, events: CustomEventTarget<LinkConnectorEventMap>): void;
54
+ abstract disconnect(): boolean;
55
+ }
@@ -0,0 +1,30 @@
1
+ import { CustomEventTarget } from '../infrastructure/CustomEventTarget';
2
+ import { LinkConnectorEventMap } from '../infrastructure/LinkConnectorEventMap';
3
+ import { INodeInputSlot, INodeOutputSlot, LinkNetwork, Point } from '../interfaces';
4
+ import { LGraphNode } from '../LGraphNode';
5
+ import { LLink } from '../LLink';
6
+ import { Reroute } from '../Reroute';
7
+ import { SubgraphInput } from '../subgraph/SubgraphInput';
8
+ import { NodeLike } from '../types/NodeLike';
9
+ import { SubgraphIO } from '../types/serialisation';
10
+ import { LinkDirection } from '../types/globalEnums';
11
+ import { MovingLinkBase } from './MovingLinkBase';
12
+ export declare class MovingOutputLink extends MovingLinkBase {
13
+ readonly toType = "output";
14
+ readonly node: LGraphNode;
15
+ readonly fromSlot: INodeInputSlot;
16
+ readonly fromPos: Point;
17
+ readonly fromDirection: LinkDirection;
18
+ readonly fromSlotIndex: number;
19
+ constructor(network: LinkNetwork, link: LLink, fromReroute?: Reroute, dragDirection?: LinkDirection);
20
+ canConnectToInput(): false;
21
+ canConnectToOutput(outputNode: NodeLike, output: INodeOutputSlot | SubgraphIO): boolean;
22
+ canConnectToReroute(reroute: Reroute): boolean;
23
+ connectToInput(): never;
24
+ connectToOutput(outputNode: LGraphNode, output: INodeOutputSlot, events: CustomEventTarget<LinkConnectorEventMap>): LLink | null | undefined;
25
+ connectToSubgraphInput(input: SubgraphInput, events?: CustomEventTarget<LinkConnectorEventMap>): void;
26
+ connectToSubgraphOutput(): void;
27
+ connectToRerouteInput(): never;
28
+ connectToRerouteOutput(reroute: Reroute, outputNode: LGraphNode, output: INodeOutputSlot, events: CustomEventTarget<LinkConnectorEventMap>): void;
29
+ disconnect(): boolean;
30
+ }
@@ -0,0 +1,39 @@
1
+ import { CustomEventTarget } from '../infrastructure/CustomEventTarget';
2
+ import { LinkConnectorEventMap } from '../infrastructure/LinkConnectorEventMap';
3
+ import { LinkNetwork, Point } from '../interfaces';
4
+ import { LGraphNode } from '../LGraphNode';
5
+ import { INodeInputSlot, INodeOutputSlot, LLink, Reroute } from '../litegraph';
6
+ import { SubgraphInput } from '../subgraph/SubgraphInput';
7
+ import { SubgraphIONodeBase } from '../subgraph/SubgraphIONodeBase';
8
+ import { SubgraphOutput } from '../subgraph/SubgraphOutput';
9
+ import { LinkDirection } from '../types/globalEnums';
10
+ export interface RenderLink {
11
+ /** The type of link being connected. */
12
+ readonly toType: "input" | "output";
13
+ /** The source {@link Point} of the link being connected. */
14
+ readonly fromPos: Point;
15
+ /** The direction the link starts off as. If {@link toType} is `output`, this will be the direction the link input faces. */
16
+ readonly fromDirection: LinkDirection;
17
+ /** If set, this will force a dragged link "point" from the cursor in the specified direction. */
18
+ dragDirection: LinkDirection;
19
+ /** The network that the link belongs to. */
20
+ readonly network: LinkNetwork;
21
+ /** The node that the link is being connected from. */
22
+ readonly node: LGraphNode | SubgraphIONodeBase<SubgraphInput | SubgraphOutput>;
23
+ /** The slot that the link is being connected from. */
24
+ readonly fromSlot: INodeOutputSlot | INodeInputSlot | SubgraphInput | SubgraphOutput;
25
+ /** The index of the slot that the link is being connected from. */
26
+ readonly fromSlotIndex: number;
27
+ /** The reroute that the link is being connected from. */
28
+ readonly fromReroute?: Reroute;
29
+ connectToInput(node: LGraphNode, input: INodeInputSlot, events?: CustomEventTarget<LinkConnectorEventMap>): void;
30
+ connectToOutput(node: LGraphNode, output: INodeOutputSlot, events?: CustomEventTarget<LinkConnectorEventMap>): void;
31
+ connectToSubgraphInput(input: SubgraphInput, events?: CustomEventTarget<LinkConnectorEventMap>): void;
32
+ connectToSubgraphOutput(output: SubgraphOutput, events?: CustomEventTarget<LinkConnectorEventMap>): void;
33
+ connectToRerouteInput(reroute: Reroute, { node, input, link }: {
34
+ node: LGraphNode;
35
+ input: INodeInputSlot;
36
+ link: LLink;
37
+ }, events: CustomEventTarget<LinkConnectorEventMap>, originalReroutes: Reroute[]): void;
38
+ connectToRerouteOutput(reroute: Reroute, outputNode: LGraphNode, output: INodeOutputSlot, events: CustomEventTarget<LinkConnectorEventMap>): void;
39
+ }
@@ -0,0 +1,37 @@
1
+ import { RenderLink } from './RenderLink';
2
+ import { CustomEventTarget } from '../infrastructure/CustomEventTarget';
3
+ import { LinkConnectorEventMap } from '../infrastructure/LinkConnectorEventMap';
4
+ import { INodeInputSlot, LinkNetwork, Point } from '../interfaces';
5
+ import { LGraphNode } from '../LGraphNode';
6
+ import { LLink } from '../LLink';
7
+ import { Reroute } from '../Reroute';
8
+ import { SubgraphInput } from '../subgraph/SubgraphInput';
9
+ import { SubgraphInputNode } from '../subgraph/SubgraphInputNode';
10
+ import { NodeLike } from '../types/NodeLike';
11
+ import { LinkDirection } from '../types/globalEnums';
12
+ /** Connecting TO an input slot. */
13
+ export declare class ToInputFromIoNodeLink implements RenderLink {
14
+ readonly network: LinkNetwork;
15
+ readonly node: SubgraphInputNode;
16
+ readonly fromSlot: SubgraphInput;
17
+ readonly fromReroute?: Reroute | undefined;
18
+ dragDirection: LinkDirection;
19
+ readonly toType = "input";
20
+ readonly fromSlotIndex: number;
21
+ readonly fromPos: Point;
22
+ fromDirection: LinkDirection;
23
+ readonly existingLink?: LLink;
24
+ constructor(network: LinkNetwork, node: SubgraphInputNode, fromSlot: SubgraphInput, fromReroute?: Reroute | undefined, dragDirection?: LinkDirection, existingLink?: LLink);
25
+ canConnectToInput(inputNode: NodeLike, input: INodeInputSlot): boolean;
26
+ canConnectToOutput(): false;
27
+ connectToInput(node: LGraphNode, input: INodeInputSlot, events: CustomEventTarget<LinkConnectorEventMap>): void;
28
+ connectToSubgraphOutput(): void;
29
+ connectToRerouteInput(reroute: Reroute, { node: inputNode, input, link, }: {
30
+ node: LGraphNode;
31
+ input: INodeInputSlot;
32
+ link: LLink;
33
+ }, events: CustomEventTarget<LinkConnectorEventMap>, originalReroutes: Reroute[]): void;
34
+ connectToOutput(): void;
35
+ connectToSubgraphInput(): void;
36
+ connectToRerouteOutput(): void;
37
+ }