@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,168 @@
1
+ import { HasBoundingRect, Point, ReadOnlyPoint, ReadOnlyRect, Rect } from './interfaces';
2
+ import { Alignment, LinkDirection } from './types/globalEnums';
3
+ /**
4
+ * Calculates the distance between two points (2D vector)
5
+ * @param a Point a as `x, y`
6
+ * @param b Point b as `x, y`
7
+ * @returns Distance between point {@link a} & {@link b}
8
+ */
9
+ export declare function distance(a: ReadOnlyPoint, b: ReadOnlyPoint): number;
10
+ /**
11
+ * Calculates the distance2 (squared) between two points (2D vector).
12
+ * Much faster when only comparing distances (closest/furthest point).
13
+ * @param x1 Origin point X
14
+ * @param y1 Origin point Y
15
+ * @param x2 Destination point X
16
+ * @param y2 Destination point Y
17
+ * @returns Distance2 (squared) between point [{@link x1}, {@link y1}] & [{@link x2}, {@link y2}]
18
+ */
19
+ export declare function dist2(x1: number, y1: number, x2: number, y2: number): number;
20
+ /**
21
+ * Determines whether a point is inside a rectangle.
22
+ *
23
+ * Otherwise identical to {@link isInsideRectangle}, it also returns `true` if `x` equals `left` or `y` equals `top`.
24
+ * @param x Point x
25
+ * @param y Point y
26
+ * @param left Rect x
27
+ * @param top Rect y
28
+ * @param width Rect width
29
+ * @param height Rect height
30
+ * @returns `true` if the point is inside the rect, otherwise `false`
31
+ */
32
+ export declare function isInRectangle(x: number, y: number, left: number, top: number, width: number, height: number): boolean;
33
+ /**
34
+ * Determines whether a {@link Point} is inside a {@link Rect}.
35
+ * @param point The point to check, as `x, y`
36
+ * @param rect The rectangle, as `x, y, width, height`
37
+ * @returns `true` if the point is inside the rect, otherwise `false`
38
+ */
39
+ export declare function isPointInRect(point: ReadOnlyPoint, rect: ReadOnlyRect): boolean;
40
+ /**
41
+ * Determines whether the point represented by {@link x}, {@link y} is inside a {@link Rect}.
42
+ * @param x X co-ordinate of the point to check
43
+ * @param y Y co-ordinate of the point to check
44
+ * @param rect The rectangle, as `x, y, width, height`
45
+ * @returns `true` if the point is inside the rect, otherwise `false`
46
+ */
47
+ export declare function isInRect(x: number, y: number, rect: ReadOnlyRect): boolean;
48
+ /**
49
+ * Determines whether a point (`x, y`) is inside a rectangle.
50
+ *
51
+ * This is the original litegraph implementation. It returns `false` if `x` is equal to `left`, or `y` is equal to `top`.
52
+ * @deprecated
53
+ * Use {@link isInRectangle} to match inclusive of top left.
54
+ * This function returns a false negative when an integer point (e.g. pixel) is on the leftmost or uppermost edge of a rectangle.
55
+ * @param x Point x
56
+ * @param y Point y
57
+ * @param left Rect x
58
+ * @param top Rect y
59
+ * @param width Rect width
60
+ * @param height Rect height
61
+ * @returns `true` if the point is inside the rect, otherwise `false`
62
+ */
63
+ export declare function isInsideRectangle(x: number, y: number, left: number, top: number, width: number, height: number): boolean;
64
+ /**
65
+ * Determines if two rectangles have any overlap
66
+ * @param a Rectangle A as `x, y, width, height`
67
+ * @param b Rectangle B as `x, y, width, height`
68
+ * @returns `true` if rectangles overlap, otherwise `false`
69
+ */
70
+ export declare function overlapBounding(a: ReadOnlyRect, b: ReadOnlyRect): boolean;
71
+ /**
72
+ * Returns the centre of a rectangle.
73
+ * @param rect The rectangle, as `x, y, width, height`
74
+ * @returns The centre of the rectangle, as `x, y`
75
+ */
76
+ export declare function getCentre(rect: ReadOnlyRect): Point;
77
+ /**
78
+ * Determines if rectangle {@link a} contains the centre point of rectangle {@link b}.
79
+ * @param a Container rectangle A as `x, y, width, height`
80
+ * @param b Sub-rectangle B as `x, y, width, height`
81
+ * @returns `true` if {@link a} contains most of {@link b}, otherwise `false`
82
+ */
83
+ export declare function containsCentre(a: ReadOnlyRect, b: ReadOnlyRect): boolean;
84
+ /**
85
+ * Determines if rectangle {@link a} wholly contains rectangle {@link b}.
86
+ * @param a Container rectangle A as `x, y, width, height`
87
+ * @param b Sub-rectangle B as `x, y, width, height`
88
+ * @returns `true` if {@link a} wholly contains {@link b}, otherwise `false`
89
+ */
90
+ export declare function containsRect(a: ReadOnlyRect, b: ReadOnlyRect): boolean;
91
+ /**
92
+ * Adds an offset in the specified direction to {@link out}
93
+ * @param amount Amount of offset to add
94
+ * @param direction Direction to add the offset to
95
+ * @param out The {@link Point} to add the offset to
96
+ */
97
+ export declare function addDirectionalOffset(amount: number, direction: LinkDirection, out: Point): void;
98
+ /**
99
+ * Rotates an offset in 90° increments.
100
+ *
101
+ * Swaps/flips axis values of a 2D vector offset - effectively rotating
102
+ * {@link offset} by 90°
103
+ * @param offset The zero-based offset to rotate
104
+ * @param from Direction to rotate from
105
+ * @param to Direction to rotate to
106
+ */
107
+ export declare function rotateLink(offset: Point, from: LinkDirection, to: LinkDirection): void;
108
+ /**
109
+ * Check if a point is to to the left or right of a line.
110
+ * Project a line from lineStart -> lineEnd. Determine if point is to the left
111
+ * or right of that projection.
112
+ * {@link https://www.geeksforgeeks.org/orientation-3-ordered-points/}
113
+ * @param lineStart The start point of the line
114
+ * @param lineEnd The end point of the line
115
+ * @param x X co-ordinate of the point to check
116
+ * @param y Y co-ordinate of the point to check
117
+ * @returns 0 if all three points are in a straight line, a negative value if
118
+ * point is to the left of the projected line, or positive if the point is to
119
+ * the right
120
+ */
121
+ export declare function getOrientation(lineStart: ReadOnlyPoint, lineEnd: ReadOnlyPoint, x: number, y: number): number;
122
+ /**
123
+ * @param out The array to store the point in
124
+ * @param a Start point
125
+ * @param b End point
126
+ * @param controlA Start curve control point
127
+ * @param controlB End curve control point
128
+ * @param t Time: factor of distance to travel along the curve (e.g 0.25 is 25% along the curve)
129
+ */
130
+ export declare function findPointOnCurve(out: Point, a: ReadOnlyPoint, b: ReadOnlyPoint, controlA: ReadOnlyPoint, controlB: ReadOnlyPoint, t?: number): void;
131
+ export declare function createBounds(objects: Iterable<HasBoundingRect>, padding?: number): ReadOnlyRect | null;
132
+ /**
133
+ * Snaps the provided {@link Point} or {@link Rect} ({@link pos}) to a grid of size {@link snapTo}.
134
+ * @param pos The point that will be snapped
135
+ * @param snapTo The value to round up/down by (multiples thereof)
136
+ * @returns `true` if snapTo is truthy, otherwise `false`
137
+ * @remarks `NaN` propagates through this function and does not affect return value.
138
+ */
139
+ export declare function snapPoint(pos: Point | Rect, snapTo: number): boolean;
140
+ /**
141
+ * Aligns a {@link Rect} relative to the edges or centre of a {@link container} rectangle.
142
+ *
143
+ * With no {@link inset}, the element will be placed on the interior of the {@link container},
144
+ * with their edges lined up on the {@link anchors}. A positive {@link inset} moves the element towards the centre,
145
+ * negative will push it outside the {@link container}.
146
+ * @param rect The bounding rect of the element to align.
147
+ * If using the element's pos/size backing store, this function will move the element.
148
+ * @param anchors The direction(s) to anchor the element to
149
+ * @param container The rectangle inside which to align the element
150
+ * @param inset Relative offset from each {@link anchors} edge, with positive always leading to the centre, as an `[x, y]` point
151
+ * @returns The original {@link rect}, modified in place.
152
+ */
153
+ export declare function alignToContainer(rect: Rect, anchors: Alignment, [containerX, containerY, containerWidth, containerHeight]: ReadOnlyRect, [insetX, insetY]?: ReadOnlyPoint): Rect;
154
+ /**
155
+ * Aligns a {@link Rect} relative to the edges of {@link other}.
156
+ *
157
+ * With no {@link outset}, the element will be placed on the exterior of the {@link other},
158
+ * with their edges lined up on the {@link anchors}. A positive {@link outset} moves the element away from the {@link other},
159
+ * negative will push it inside the {@link other}.
160
+ * @param rect The bounding rect of the element to align.
161
+ * If using the element's pos/size backing store, this function will move the element.
162
+ * @param anchors The direction(s) to anchor the element to
163
+ * @param other The rectangle to align {@link rect} to
164
+ * @param outset Relative offset from each {@link anchors} edge, with positive always moving away from the centre of the {@link other}, as an `[x, y]` point
165
+ * @returns The original {@link rect}, modified in place.
166
+ */
167
+ export declare function alignOutsideContainer(rect: Rect, anchors: Alignment, [otherX, otherY, otherWidth, otherHeight]: ReadOnlyRect, [outsetX, outsetY]?: ReadOnlyPoint): Rect;
168
+ export declare function clamp(value: number, min: number, max: number): number;
@@ -0,0 +1,20 @@
1
+ import { INodeInputSlot, INodeOutputSlot, OptionalProps, ReadOnlyPoint } from '../interfaces';
2
+ import { LGraphNode } from '../LGraphNode';
3
+ import { LinkId } from '../LLink';
4
+ import { SubgraphInput } from '../subgraph/SubgraphInput';
5
+ import { SubgraphOutput } from '../subgraph/SubgraphOutput';
6
+ import { IBaseWidget } from '../types/widgets';
7
+ import { IDrawOptions, NodeSlot } from './NodeSlot';
8
+ export declare class NodeInputSlot extends NodeSlot implements INodeInputSlot {
9
+ #private;
10
+ link: LinkId | null;
11
+ get isWidgetInputSlot(): boolean;
12
+ /** Internal use only; API is not finalised and may change at any time. */
13
+ get _widget(): IBaseWidget | undefined;
14
+ set _widget(widget: IBaseWidget | undefined);
15
+ get collapsedPos(): ReadOnlyPoint;
16
+ constructor(slot: OptionalProps<INodeInputSlot, "boundingRect">, node: LGraphNode);
17
+ get isConnected(): boolean;
18
+ isValidTarget(fromSlot: INodeInputSlot | INodeOutputSlot | SubgraphInput | SubgraphOutput): boolean;
19
+ draw(ctx: CanvasRenderingContext2D, options: Omit<IDrawOptions, "doStroke" | "labelPosition">): void;
20
+ }
@@ -0,0 +1,18 @@
1
+ import { INodeInputSlot, INodeOutputSlot, OptionalProps, ReadOnlyPoint } from '../interfaces';
2
+ import { LGraphNode } from '../LGraphNode';
3
+ import { LinkId } from '../LLink';
4
+ import { SubgraphInput } from '../subgraph/SubgraphInput';
5
+ import { SubgraphOutput } from '../subgraph/SubgraphOutput';
6
+ import { IDrawOptions, NodeSlot } from './NodeSlot';
7
+ export declare class NodeOutputSlot extends NodeSlot implements INodeOutputSlot {
8
+ #private;
9
+ links: LinkId[] | null;
10
+ _data?: unknown;
11
+ slot_index?: number;
12
+ get isWidgetInputSlot(): false;
13
+ get collapsedPos(): ReadOnlyPoint;
14
+ constructor(slot: OptionalProps<INodeOutputSlot, "boundingRect">, node: LGraphNode);
15
+ isValidTarget(fromSlot: INodeInputSlot | INodeOutputSlot | SubgraphInput | SubgraphOutput): boolean;
16
+ get isConnected(): boolean;
17
+ draw(ctx: CanvasRenderingContext2D, options: Omit<IDrawOptions, "doStroke" | "labelPosition">): void;
18
+ }
@@ -0,0 +1,35 @@
1
+ import { CanvasColour, DefaultConnectionColors, INodeInputSlot, INodeOutputSlot, INodeSlot, OptionalProps, Point, ReadOnlyPoint } from '../interfaces';
2
+ import { LGraphNode } from '../LGraphNode';
3
+ import { SubgraphInput } from '../subgraph/SubgraphInput';
4
+ import { SubgraphOutput } from '../subgraph/SubgraphOutput';
5
+ import { LabelPosition } from '../draw';
6
+ import { SlotBase } from './SlotBase';
7
+ export interface IDrawOptions {
8
+ colorContext: DefaultConnectionColors;
9
+ labelPosition?: LabelPosition;
10
+ lowQuality?: boolean;
11
+ doStroke?: boolean;
12
+ highlight?: boolean;
13
+ }
14
+ /** Shared base class for {@link LGraphNode} input and output slots. */
15
+ export declare abstract class NodeSlot extends SlotBase implements INodeSlot {
16
+ #private;
17
+ pos?: Point;
18
+ /** The center point of this slot when the node is collapsed. */
19
+ abstract get collapsedPos(): ReadOnlyPoint;
20
+ get node(): LGraphNode;
21
+ get highlightColor(): CanvasColour;
22
+ abstract get isWidgetInputSlot(): boolean;
23
+ constructor(slot: OptionalProps<INodeSlot, "boundingRect">, node: LGraphNode);
24
+ /**
25
+ * Whether this slot is a valid target for a dragging link.
26
+ * @param fromSlot The slot that the link is being connected from.
27
+ */
28
+ abstract isValidTarget(fromSlot: INodeInputSlot | INodeOutputSlot | SubgraphInput | SubgraphOutput): boolean;
29
+ /**
30
+ * The label to display in the UI.
31
+ */
32
+ get renderingLabel(): string;
33
+ draw(ctx: CanvasRenderingContext2D, { colorContext, labelPosition, lowQuality, highlight, doStroke, }: IDrawOptions): void;
34
+ drawCollapsed(ctx: CanvasRenderingContext2D): void;
35
+ }
@@ -0,0 +1,27 @@
1
+ import { CanvasColour, DefaultConnectionColors, INodeSlot, ISlotType, IWidgetLocator, Point } from '../interfaces';
2
+ import { LLink } from '../LLink';
3
+ import { RenderShape, LinkDirection } from '../types/globalEnums';
4
+ import { Rectangle } from '../infrastructure/Rectangle';
5
+ /** Base class for all input & output slots. */
6
+ export declare abstract class SlotBase implements INodeSlot {
7
+ name: string;
8
+ localized_name?: string;
9
+ label?: string;
10
+ type: ISlotType;
11
+ dir?: LinkDirection;
12
+ removable?: boolean;
13
+ shape?: RenderShape;
14
+ color_off?: CanvasColour;
15
+ color_on?: CanvasColour;
16
+ locked?: boolean;
17
+ nameLocked?: boolean;
18
+ widget?: IWidgetLocator;
19
+ _floatingLinks?: Set<LLink>;
20
+ hasErrors?: boolean;
21
+ /** The centre point of the slot. */
22
+ abstract pos?: Point;
23
+ readonly boundingRect: Rectangle;
24
+ constructor(name: string, type: ISlotType, boundingRect?: Rectangle);
25
+ abstract get isConnected(): boolean;
26
+ renderingColor(colorContext: DefaultConnectionColors): CanvasColour;
27
+ }
@@ -0,0 +1,17 @@
1
+ import { IWidgetInputSlot, SharedIntersection } from '../interfaces';
2
+ import { INodeInputSlot, INodeOutputSlot, INodeSlot, IWidget } from '../litegraph';
3
+ import { ISerialisableNodeInput, ISerialisableNodeOutput } from '../types/serialisation';
4
+ type CommonIoSlotProps = SharedIntersection<ISerialisableNodeInput, ISerialisableNodeOutput>;
5
+ export declare function shallowCloneCommonProps(slot: CommonIoSlotProps): CommonIoSlotProps;
6
+ export declare function inputAsSerialisable(slot: INodeInputSlot): ISerialisableNodeInput;
7
+ export declare function outputAsSerialisable(slot: INodeOutputSlot & {
8
+ widget?: IWidget;
9
+ }): ISerialisableNodeOutput;
10
+ export declare function isINodeInputSlot(slot: INodeSlot): slot is INodeInputSlot;
11
+ export declare function isINodeOutputSlot(slot: INodeSlot): slot is INodeOutputSlot;
12
+ /**
13
+ * Type guard: Whether this input slot is attached to a widget.
14
+ * @param slot The slot to check.
15
+ */
16
+ export declare function isWidgetInputSlot(slot: INodeInputSlot): slot is IWidgetInputSlot;
17
+ export {};
@@ -0,0 +1 @@
1
+ export declare function loadPolyfills(): void;
@@ -0,0 +1,22 @@
1
+ import { ISlotType } from './litegraph';
2
+ /**
3
+ * Uses the standard String() function to coerce to string, unless the value is null or undefined - then null.
4
+ * @param value The value to convert
5
+ * @returns String(value) or null
6
+ */
7
+ export declare function stringOrNull(value: unknown): string | null;
8
+ /**
9
+ * Uses the standard String() function to coerce to string, unless the value is null or undefined - then an empty string
10
+ * @param value The value to convert
11
+ * @returns String(value) or ""
12
+ */
13
+ export declare function stringOrEmpty(value: unknown): string;
14
+ export declare function parseSlotTypes(type: ISlotType): string[];
15
+ /**
16
+ * Creates a unique name by appending an underscore and a number to the end of the name
17
+ * if it already exists.
18
+ * @param name The name to make unique
19
+ * @param existingNames The names that already exist. Default: an empty array
20
+ * @returns The name, or a unique name if it already exists.
21
+ */
22
+ export declare function nextUniqueName(name: string, existingNames?: string[]): string;
@@ -0,0 +1,15 @@
1
+ import { SubgraphInputNode } from './SubgraphInputNode';
2
+ import { INodeInputSlot, Point } from '../interfaces';
3
+ import { LGraphNode } from '../LGraphNode';
4
+ import { RerouteId } from '../Reroute';
5
+ import { LLink } from '../LLink';
6
+ import { SubgraphInput } from './SubgraphInput';
7
+ /**
8
+ * A virtual slot that simply creates a new input slot when connected to.
9
+ */
10
+ export declare class EmptySubgraphInput extends SubgraphInput {
11
+ parent: SubgraphInputNode;
12
+ constructor(parent: SubgraphInputNode);
13
+ connect(slot: INodeInputSlot, node: LGraphNode, afterRerouteId?: RerouteId): LLink | undefined;
14
+ get labelPos(): Point;
15
+ }
@@ -0,0 +1,15 @@
1
+ import { SubgraphOutputNode } from './SubgraphOutputNode';
2
+ import { INodeOutputSlot, Point } from '../interfaces';
3
+ import { LGraphNode } from '../LGraphNode';
4
+ import { RerouteId } from '../Reroute';
5
+ import { LLink } from '../LLink';
6
+ import { SubgraphOutput } from './SubgraphOutput';
7
+ /**
8
+ * A virtual slot that simply creates a new output slot when connected to.
9
+ */
10
+ export declare class EmptySubgraphOutput extends SubgraphOutput {
11
+ parent: SubgraphOutputNode;
12
+ constructor(parent: SubgraphOutputNode);
13
+ connect(slot: INodeOutputSlot, node: LGraphNode, afterRerouteId?: RerouteId): LLink | undefined;
14
+ get labelPos(): Point;
15
+ }
@@ -0,0 +1,96 @@
1
+ import { SubgraphNode } from './SubgraphNode';
2
+ import { CallbackParams, CallbackReturn, ISlotType } from '../interfaces';
3
+ import { LGraph } from '../LGraph';
4
+ import { LGraphNode, NodeId } from '../LGraphNode';
5
+ import { LGraphEventMode } from '../litegraph';
6
+ import { Subgraph } from './Subgraph';
7
+ export type ExecutionId = string;
8
+ /**
9
+ * Interface describing the data transfer objects used when compiling a graph for execution.
10
+ */
11
+ export type ExecutableLGraphNode = Omit<ExecutableNodeDTO, "graph" | "node" | "subgraphNode">;
12
+ /**
13
+ * The end result of resolving a DTO input.
14
+ * When a widget value is returned, {@link widgetInfo} is present and {@link origin_slot} is `-1`.
15
+ */
16
+ type ResolvedInput = {
17
+ /** DTO for the node that the link originates from. */
18
+ node: ExecutableLGraphNode;
19
+ /** Full unique execution ID of the node that the link originates from. In the case of a widget value, this is the ID of the subgraph node. */
20
+ origin_id: ExecutionId;
21
+ /** The slot index of the output on the node that the link originates from. `-1` when widget value is set. */
22
+ origin_slot: number;
23
+ /** Boxed widget value (e.g. for widgets). If this box is `undefined`, then an input link is connected, and widget values from the subgraph node are ignored. */
24
+ widgetInfo?: {
25
+ value: unknown;
26
+ };
27
+ };
28
+ /**
29
+ * Concrete implementation of {@link ExecutableLGraphNode}.
30
+ * @remarks This is the class that is used to create the data transfer objects for executable nodes.
31
+ */
32
+ export declare class ExecutableNodeDTO implements ExecutableLGraphNode {
33
+ #private;
34
+ /** The actual node that this DTO wraps. */
35
+ readonly node: LGraphNode | SubgraphNode;
36
+ /** A list of subgraph instance node IDs from the root graph to the containing instance. @see {@link id} */
37
+ readonly subgraphNodePath: readonly NodeId[];
38
+ /** A flattened map of all DTOs in this node network. Subgraph instances have been expanded into their inner nodes. */
39
+ readonly nodesByExecutionId: Map<ExecutionId, ExecutableLGraphNode>;
40
+ /** The actual subgraph instance that contains this node, otherise undefined. */
41
+ readonly subgraphNode?: SubgraphNode | undefined;
42
+ applyToGraph?(...args: CallbackParams<typeof this.node.applyToGraph>): CallbackReturn<typeof this.node.applyToGraph>;
43
+ /** The graph that this node is a part of. */
44
+ readonly graph: LGraph | Subgraph;
45
+ inputs: {
46
+ linkId: number | null;
47
+ name: string;
48
+ type: ISlotType;
49
+ }[];
50
+ /**
51
+ * The path to the acutal node through subgraph instances, represented as a list of all subgraph node IDs (instances),
52
+ * followed by the actual original node ID within the subgraph. Each segment is separated by `:`.
53
+ *
54
+ * e.g. `1:2:3`:
55
+ * - `1` is the node ID of the first subgraph node in the parent workflow
56
+ * - `2` is the node ID of the second subgraph node in the first subgraph
57
+ * - `3` is the node ID of the actual node in the subgraph definition
58
+ */
59
+ get id(): string;
60
+ get type(): string;
61
+ get title(): string;
62
+ get mode(): LGraphEventMode;
63
+ get comfyClass(): string | undefined;
64
+ get isVirtualNode(): boolean | undefined;
65
+ get widgets(): import('../types/widgets').IBaseWidget<string | number | boolean | object | undefined, string, import('../types/widgets').IWidgetOptions<unknown>>[] | undefined;
66
+ get subgraphId(): string | undefined;
67
+ constructor(
68
+ /** The actual node that this DTO wraps. */
69
+ node: LGraphNode | SubgraphNode,
70
+ /** A list of subgraph instance node IDs from the root graph to the containing instance. @see {@link id} */
71
+ subgraphNodePath: readonly NodeId[],
72
+ /** A flattened map of all DTOs in this node network. Subgraph instances have been expanded into their inner nodes. */
73
+ nodesByExecutionId: Map<ExecutionId, ExecutableLGraphNode>,
74
+ /** The actual subgraph instance that contains this node, otherise undefined. */
75
+ subgraphNode?: SubgraphNode | undefined);
76
+ /** Returns either the DTO itself, or the DTOs of the inner nodes of the subgraph. */
77
+ getInnerNodes(): ExecutableLGraphNode[];
78
+ /**
79
+ * Resolves the executable node & link IDs for a given input slot.
80
+ * @param slot The slot index of the input.
81
+ * @param visited Leave empty unless overriding this method.
82
+ * A set of unique IDs, used to guard against infinite recursion.
83
+ * If overriding, ensure that the set is passed on all recursive calls.
84
+ * @returns The node and the origin ID / slot index of the output.
85
+ */
86
+ resolveInput(slot: number, visited?: Set<string>): ResolvedInput | undefined;
87
+ /**
88
+ * Determines whether this output is a valid endpoint for a link (non-virtual, non-bypass).
89
+ * @param slot The slot index of the output.
90
+ * @param type The type of the input
91
+ * @param visited A set of unique IDs to guard against infinite recursion. See {@link resolveInput}.
92
+ * @returns The node and the origin ID / slot index of the output.
93
+ */
94
+ resolveOutput(slot: number, type: ISlotType, visited: Set<string>): ResolvedInput | undefined;
95
+ }
96
+ export {};
@@ -0,0 +1,65 @@
1
+ import { SubgraphEventMap } from '../infrastructure/SubgraphEventMap';
2
+ import { DefaultConnectionColors, INodeInputSlot, INodeOutputSlot } from '../interfaces';
3
+ import { LGraphCanvas } from '../LGraphCanvas';
4
+ import { ExportedSubgraph, ExposedWidget, ISerialisedGraph, Serialisable, SerialisableGraph } from '../types/serialisation';
5
+ import { CustomEventTarget } from '../infrastructure/CustomEventTarget';
6
+ import { BaseLGraph, LGraph } from '../LGraph';
7
+ import { SubgraphInput } from './SubgraphInput';
8
+ import { SubgraphInputNode } from './SubgraphInputNode';
9
+ import { SubgraphOutput } from './SubgraphOutput';
10
+ import { SubgraphOutputNode } from './SubgraphOutputNode';
11
+ /** Internal; simplifies type definitions. */
12
+ export type GraphOrSubgraph = LGraph | Subgraph;
13
+ /** A subgraph definition. */
14
+ export declare class Subgraph extends LGraph implements BaseLGraph, Serialisable<ExportedSubgraph> {
15
+ #private;
16
+ readonly events: CustomEventTarget<SubgraphEventMap>;
17
+ /** Limits the number of levels / depth that subgraphs may be nested. Prevents uncontrolled programmatic nesting. */
18
+ static MAX_NESTED_SUBGRAPHS: number;
19
+ /** The display name of the subgraph. */
20
+ name: string;
21
+ readonly inputNode: SubgraphInputNode;
22
+ readonly outputNode: SubgraphOutputNode;
23
+ /** Ordered list of inputs to the subgraph itself. Similar to a reroute, with the input side in the graph, and the output side in the subgraph. */
24
+ readonly inputs: SubgraphInput[];
25
+ /** Ordered list of outputs from the subgraph itself. Similar to a reroute, with the input side in the subgraph, and the output side in the graph. */
26
+ readonly outputs: SubgraphOutput[];
27
+ /** A list of node widgets displayed in the parent graph, on the subgraph object. */
28
+ readonly widgets: ExposedWidget[];
29
+ get rootGraph(): LGraph;
30
+ constructor(rootGraph: LGraph, data: ExportedSubgraph);
31
+ getIoNodeOnPos(x: number, y: number): SubgraphInputNode | SubgraphOutputNode | undefined;
32
+ configure(data: ISerialisedGraph & ExportedSubgraph | SerialisableGraph & ExportedSubgraph, keep_old?: boolean): boolean | undefined;
33
+ attachCanvas(canvas: LGraphCanvas): void;
34
+ addInput(name: string, type: string): SubgraphInput;
35
+ addOutput(name: string, type: string): SubgraphOutput;
36
+ /**
37
+ * Renames an input slot in the subgraph.
38
+ * @param input The input slot to rename.
39
+ * @param name The new name for the input slot.
40
+ */
41
+ renameInput(input: SubgraphInput, name: string): void;
42
+ /**
43
+ * Renames an output slot in the subgraph.
44
+ * @param output The output slot to rename.
45
+ * @param name The new name for the output slot.
46
+ */
47
+ renameOutput(output: SubgraphOutput, name: string): void;
48
+ /**
49
+ * Removes an input slot from the subgraph.
50
+ * @param input The input slot to remove.
51
+ */
52
+ removeInput(input: SubgraphInput): void;
53
+ /**
54
+ * Removes an output slot from the subgraph.
55
+ * @param output The output slot to remove.
56
+ */
57
+ removeOutput(output: SubgraphOutput): void;
58
+ draw(ctx: CanvasRenderingContext2D, colorContext: DefaultConnectionColors, fromSlot?: INodeInputSlot | INodeOutputSlot | SubgraphInput | SubgraphOutput, editorAlpha?: number): void;
59
+ /**
60
+ * Clones the subgraph, creating an identical copy with a new ID.
61
+ * @returns A new subgraph with the same configuration, but a new ID.
62
+ */
63
+ clone(keepId?: boolean): Subgraph;
64
+ asSerialisable(): ExportedSubgraph & Required<Pick<SerialisableGraph, "nodes" | "groups" | "extra">>;
65
+ }
@@ -0,0 +1,80 @@
1
+ import { EmptySubgraphInput } from './EmptySubgraphInput';
2
+ import { EmptySubgraphOutput } from './EmptySubgraphOutput';
3
+ import { Subgraph } from './Subgraph';
4
+ import { SubgraphInput } from './SubgraphInput';
5
+ import { SubgraphOutput } from './SubgraphOutput';
6
+ import { LinkConnector } from '../canvas/LinkConnector';
7
+ import { DefaultConnectionColors, Hoverable, INodeInputSlot, INodeOutputSlot, Point, Positionable } from '../interfaces';
8
+ import { NodeId } from '../LGraphNode';
9
+ import { ExportedSubgraphIONode, Serialisable } from '../types/serialisation';
10
+ import { Rectangle } from '../infrastructure/Rectangle';
11
+ import { CanvasColour, CanvasPointer, CanvasPointerEvent } from '../litegraph';
12
+ import { CanvasItem } from '../types/globalEnums';
13
+ export declare abstract class SubgraphIONodeBase<TSlot extends SubgraphInput | SubgraphOutput> implements Positionable, Hoverable, Serialisable<ExportedSubgraphIONode> {
14
+ #private;
15
+ /** The subgraph that this node belongs to. */
16
+ readonly subgraph: Subgraph;
17
+ static margin: number;
18
+ static minWidth: number;
19
+ static roundedRadius: number;
20
+ abstract readonly id: NodeId;
21
+ get boundingRect(): Rectangle;
22
+ selected: boolean;
23
+ pinned: boolean;
24
+ readonly removable = false;
25
+ isPointerOver: boolean;
26
+ abstract readonly emptySlot: EmptySubgraphInput | EmptySubgraphOutput;
27
+ get pos(): Point;
28
+ set pos(value: Point);
29
+ get size(): import('../interfaces').Size;
30
+ set size(value: import('../interfaces').Size);
31
+ protected get sideLineWidth(): number;
32
+ protected get sideStrokeStyle(): CanvasColour;
33
+ abstract readonly slots: TSlot[];
34
+ abstract get allSlots(): TSlot[];
35
+ constructor(
36
+ /** The subgraph that this node belongs to. */
37
+ subgraph: Subgraph);
38
+ move(deltaX: number, deltaY: number): void;
39
+ /** @inheritdoc */
40
+ snapToGrid(snapTo: number): boolean;
41
+ abstract onPointerDown(e: CanvasPointerEvent, pointer: CanvasPointer, linkConnector: LinkConnector): void;
42
+ containsPoint(point: Point): boolean;
43
+ abstract get slotAnchorX(): number;
44
+ onPointerMove(e: CanvasPointerEvent): CanvasItem;
45
+ onPointerEnter(): void;
46
+ onPointerLeave(): void;
47
+ /**
48
+ * Renames an IO slot in the subgraph.
49
+ * @param slot The slot to rename.
50
+ * @param name The new name for the slot.
51
+ */
52
+ abstract renameSlot(slot: TSlot, name: string): void;
53
+ /**
54
+ * Removes an IO slot from the subgraph.
55
+ * @param slot The slot to remove.
56
+ */
57
+ abstract removeSlot(slot: TSlot): void;
58
+ /**
59
+ * Gets the slot at a given position in canvas space.
60
+ * @param x The x coordinate of the position.
61
+ * @param y The y coordinate of the position.
62
+ * @returns The slot at the given position, otherwise `undefined`.
63
+ */
64
+ getSlotInPosition(x: number, y: number): TSlot | undefined;
65
+ /**
66
+ * Shows the context menu for an IO slot.
67
+ * @param slot The slot to show the context menu for.
68
+ * @param event The event that triggered the context menu.
69
+ */
70
+ protected showSlotContextMenu(slot: TSlot, event: CanvasPointerEvent): void;
71
+ /** Arrange the slots in this node. */
72
+ arrange(): void;
73
+ draw(ctx: CanvasRenderingContext2D, colorContext: DefaultConnectionColors, fromSlot?: INodeInputSlot | INodeOutputSlot | SubgraphInput | SubgraphOutput, editorAlpha?: number): void;
74
+ /** @internal Leaves {@link ctx} dirty. */
75
+ protected abstract drawProtected(ctx: CanvasRenderingContext2D, colorContext: DefaultConnectionColors, fromSlot?: INodeInputSlot | INodeOutputSlot | SubgraphInput | SubgraphOutput, editorAlpha?: number): void;
76
+ /** @internal Leaves {@link ctx} dirty. */
77
+ protected drawSlots(ctx: CanvasRenderingContext2D, colorContext: DefaultConnectionColors, fromSlot?: INodeInputSlot | INodeOutputSlot | SubgraphInput | SubgraphOutput, editorAlpha?: number): void;
78
+ configure(data: ExportedSubgraphIONode): void;
79
+ asSerialisable(): ExportedSubgraphIONode;
80
+ }
@@ -0,0 +1,47 @@
1
+ import { SubgraphInputNode } from './SubgraphInputNode';
2
+ import { SubgraphOutput } from './SubgraphOutput';
3
+ import { SubgraphInputEventMap } from '../infrastructure/SubgraphInputEventMap';
4
+ import { INodeInputSlot, INodeOutputSlot, Point, ReadOnlyRect } from '../interfaces';
5
+ import { LGraphNode } from '../LGraphNode';
6
+ import { RerouteId } from '../Reroute';
7
+ import { IBaseWidget } from '../types/widgets';
8
+ import { CustomEventTarget } from '../infrastructure/CustomEventTarget';
9
+ import { LLink } from '../LLink';
10
+ import { SubgraphSlot } from './SubgraphSlotBase';
11
+ /**
12
+ * An input "slot" from a parent graph into a subgraph.
13
+ *
14
+ * IMPORTANT: A subgraph "input" is both an input AND an output. It creates an extra link connection point between
15
+ * a parent graph and a subgraph, so is conceptually similar to a reroute.
16
+ *
17
+ * This can be a little confusing, but is easier to visualise when imagining editing a subgraph.
18
+ * You have "Subgraph Inputs", because they are coming into the subgraph, which then connect to "node inputs".
19
+ *
20
+ * Functionally, however, when editing a subgraph, that "subgraph input" is the "origin" or "output side" of a link.
21
+ */
22
+ export declare class SubgraphInput extends SubgraphSlot {
23
+ #private;
24
+ parent: SubgraphInputNode;
25
+ events: CustomEventTarget<SubgraphInputEventMap, "input-connected" | "input-disconnected" | "configuring" | "configured" | "subgraph-created" | "convert-to-subgraph" | "open-subgraph">;
26
+ get _widget(): IBaseWidget<string | number | boolean | object | undefined, string, import('../types/widgets').IWidgetOptions<unknown>> | undefined;
27
+ set _widget(widget: IBaseWidget<string | number | boolean | object | undefined, string, import('../types/widgets').IWidgetOptions<unknown>> | undefined);
28
+ connect(slot: INodeInputSlot, node: LGraphNode, afterRerouteId?: RerouteId): LLink | undefined;
29
+ get labelPos(): Point;
30
+ getConnectedWidgets(): IBaseWidget[];
31
+ /**
32
+ * Validates that the connection between the new slot and the existing widget is valid.
33
+ * Used to prevent connections between widgets that are not of the same type.
34
+ * @param otherWidget The widget to compare to.
35
+ * @returns `true` if the connection is valid, otherwise `false`.
36
+ */
37
+ matchesWidget(otherWidget: IBaseWidget): boolean;
38
+ disconnect(): void;
39
+ /** For inputs, x is the right edge of the input node. */
40
+ arrange(rect: ReadOnlyRect): void;
41
+ /**
42
+ * Checks if this slot is a valid target for a connection from the given slot.
43
+ * For SubgraphInput (which acts as an output inside the subgraph),
44
+ * the fromSlot should be an input slot.
45
+ */
46
+ isValidTarget(fromSlot: INodeInputSlot | INodeOutputSlot | SubgraphInput | SubgraphOutput): boolean;
47
+ }