@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,198 @@
1
+ import { Dictionary, INodeFlags, INodeInputSlot, INodeOutputSlot, INodeSlot, ISlotType, Point, Size } from '../interfaces';
2
+ import { LGraphConfig, LGraphExtra, LGraphState } from '../LGraph';
3
+ import { IGraphGroupFlags } from '../LGraphGroup';
4
+ import { NodeId, NodeProperty } from '../LGraphNode';
5
+ import { LiteGraph } from '../litegraph';
6
+ import { LinkId, SerialisedLLinkArray } from '../LLink';
7
+ import { FloatingRerouteSlot, RerouteId } from '../Reroute';
8
+ import { TWidgetValue } from '../types/widgets';
9
+ import { RenderShape } from './globalEnums';
10
+ import { UUID } from '../utils/uuid';
11
+ /**
12
+ * An object that implements custom pre-serialization logic via {@link Serialisable.asSerialisable}.
13
+ */
14
+ export interface Serialisable<SerialisableObject> {
15
+ /**
16
+ * Prepares this object for serialization.
17
+ * Creates a partial shallow copy of itself, with only the properties that should be serialised.
18
+ * @returns An object that can immediately be serialized to JSON.
19
+ */
20
+ asSerialisable(): SerialisableObject;
21
+ }
22
+ export interface BaseExportedGraph {
23
+ /** Unique graph ID. Automatically generated if not provided. */
24
+ id: UUID;
25
+ /** The revision number of this graph. Not automatically incremented; intended for use by a downstream save function. */
26
+ revision: number;
27
+ config?: LGraphConfig;
28
+ /** Details of the appearance and location of subgraphs shown in this graph. Similar to */
29
+ subgraphs?: ExportedSubgraphInstance[];
30
+ /** Definitions of re-usable objects that are referenced elsewhere in this exported graph. */
31
+ definitions?: {
32
+ /** The base definition of subgraphs used in this workflow. That is, what you see when you open / edit a subgraph. */
33
+ subgraphs?: ExportedSubgraph[];
34
+ };
35
+ }
36
+ export interface SerialisableGraph extends BaseExportedGraph {
37
+ /** Schema version. @remarks Version bump should add to const union, which is used to narrow type during deserialise. */
38
+ version: 0 | 1;
39
+ state: LGraphState;
40
+ groups?: ISerialisedGroup[];
41
+ nodes?: ISerialisedNode[];
42
+ links?: SerialisableLLink[];
43
+ floatingLinks?: SerialisableLLink[];
44
+ reroutes?: SerialisableReroute[];
45
+ extra?: LGraphExtra;
46
+ }
47
+ export type ISerialisableNodeInput = Omit<INodeInputSlot, "boundingRect" | "widget"> & {
48
+ widget?: {
49
+ name: string;
50
+ };
51
+ };
52
+ export type ISerialisableNodeOutput = Omit<INodeOutputSlot, "boundingRect" | "_data"> & {
53
+ widget?: {
54
+ name: string;
55
+ };
56
+ };
57
+ /** Serialised LGraphNode */
58
+ export interface ISerialisedNode {
59
+ title?: string;
60
+ id: NodeId;
61
+ type: string;
62
+ pos: Point;
63
+ size: Size;
64
+ flags: INodeFlags;
65
+ order: number;
66
+ mode: number;
67
+ outputs?: ISerialisableNodeOutput[];
68
+ inputs?: ISerialisableNodeInput[];
69
+ properties?: Dictionary<NodeProperty | undefined>;
70
+ shape?: RenderShape;
71
+ boxcolor?: string;
72
+ color?: string;
73
+ bgcolor?: string;
74
+ showAdvanced?: boolean;
75
+ /**
76
+ * Note: Some custom nodes overrides the `widgets_values` property to an
77
+ * object that has `length` property and index access. It is not safe to call
78
+ * any array methods on it.
79
+ * See example in https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite/blob/8629188458dc6cb832f871ece3bd273507e8a766/web/js/VHS.core.js#L59-L84
80
+ */
81
+ widgets_values?: TWidgetValue[];
82
+ }
83
+ /** Properties of nodes that are used by subgraph instances. */
84
+ type NodeSubgraphSharedProps = Omit<ISerialisedNode, "properties" | "showAdvanced">;
85
+ /** A single instance of a subgraph; where it is used on a graph, any customisation to shape / colour etc. */
86
+ export interface ExportedSubgraphInstance extends NodeSubgraphSharedProps {
87
+ /**
88
+ * The ID of the actual subgraph definition.
89
+ * @see {@link ExportedSubgraph.subgraphs}
90
+ */
91
+ type: UUID;
92
+ }
93
+ /**
94
+ * Original implementation from static litegraph.d.ts
95
+ * Maintained for backwards compat
96
+ */
97
+ export interface ISerialisedGraph extends BaseExportedGraph {
98
+ last_node_id: NodeId;
99
+ last_link_id: number;
100
+ nodes: ISerialisedNode[];
101
+ links: SerialisedLLinkArray[];
102
+ floatingLinks?: SerialisableLLink[];
103
+ groups: ISerialisedGroup[];
104
+ version: typeof LiteGraph.VERSION;
105
+ extra?: LGraphExtra;
106
+ }
107
+ /**
108
+ * Defines a subgraph and its contents.
109
+ * Can be referenced multiple times in a schema.
110
+ */
111
+ export interface ExportedSubgraph extends SerialisableGraph {
112
+ /** The display name of the subgraph. */
113
+ name: string;
114
+ inputNode: ExportedSubgraphIONode;
115
+ outputNode: ExportedSubgraphIONode;
116
+ /** 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. */
117
+ inputs?: SubgraphIO[];
118
+ /** 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. */
119
+ outputs?: SubgraphIO[];
120
+ /** A list of node widgets displayed in the parent graph, on the subgraph object. */
121
+ widgets?: ExposedWidget[];
122
+ }
123
+ /** Properties shared by subgraph and node I/O slots. */
124
+ type SubgraphIOShared = Omit<INodeSlot, "boundingRect" | "nameLocked" | "locked" | "removable" | "_floatingLinks">;
125
+ /** Subgraph I/O slots */
126
+ export interface SubgraphIO extends SubgraphIOShared {
127
+ /** Slot ID (internal; never changes once instantiated). */
128
+ id: UUID;
129
+ /** The data type this slot uses. Unlike nodes, this does not support legacy numeric types. */
130
+ type: string;
131
+ /** Links connected to this slot, or `undefined` if not connected. An ouptut slot should only ever have one link. */
132
+ linkIds?: LinkId[];
133
+ }
134
+ /** A reference to a node widget shown in the parent graph */
135
+ export interface ExposedWidget {
136
+ /** The ID of the node (inside the subgraph) that the widget belongs to. */
137
+ id: NodeId;
138
+ /** The name of the widget to show in the parent graph. */
139
+ name: string;
140
+ }
141
+ /** Serialised LGraphGroup */
142
+ export interface ISerialisedGroup {
143
+ id: number;
144
+ title: string;
145
+ bounding: number[];
146
+ color?: string;
147
+ font_size?: number;
148
+ flags?: IGraphGroupFlags;
149
+ }
150
+ export type TClipboardLink = [
151
+ targetRelativeIndex: number,
152
+ originSlot: number,
153
+ nodeRelativeIndex: number,
154
+ targetSlot: number,
155
+ targetNodeId: NodeId
156
+ ];
157
+ /** Items copied from the canvas */
158
+ export interface ClipboardItems {
159
+ nodes?: ISerialisedNode[];
160
+ groups?: ISerialisedGroup[];
161
+ reroutes?: SerialisableReroute[];
162
+ links?: SerialisableLLink[];
163
+ subgraphs?: ExportedSubgraph[];
164
+ }
165
+ /** @deprecated */
166
+ export interface IClipboardContents {
167
+ nodes?: ISerialisedNode[];
168
+ links?: TClipboardLink[];
169
+ }
170
+ export interface SerialisableReroute {
171
+ id: RerouteId;
172
+ parentId?: RerouteId;
173
+ pos: Point;
174
+ linkIds: LinkId[];
175
+ floating?: FloatingRerouteSlot;
176
+ }
177
+ export interface SerialisableLLink {
178
+ /** Link ID */
179
+ id: LinkId;
180
+ /** Output node ID */
181
+ origin_id: NodeId;
182
+ /** Output slot index */
183
+ origin_slot: number;
184
+ /** Input node ID */
185
+ target_id: NodeId;
186
+ /** Input slot index */
187
+ target_slot: number;
188
+ /** Data type of the link */
189
+ type: ISlotType;
190
+ /** ID of the last reroute (from input to output) that this link passes through, otherwise `undefined` */
191
+ parentId?: RerouteId;
192
+ }
193
+ export interface ExportedSubgraphIONode {
194
+ id: NodeId;
195
+ bounding: [number, number, number, number];
196
+ pinned?: boolean;
197
+ }
198
+ export {};
@@ -0,0 +1,11 @@
1
+ /**
2
+ * General-purpose, TypeScript utility types.
3
+ */
4
+ /** {@link Pick} only properties that evaluate to `never`. */
5
+ export type PickNevers<T> = {
6
+ [K in keyof T as T[K] extends never ? K : never]: T[K];
7
+ };
8
+ /** {@link Omit} all properties that evaluate to `never`. */
9
+ export type NeverNever<T> = {
10
+ [K in keyof T as T[K] extends never ? never : K]: T[K];
11
+ };
@@ -0,0 +1,209 @@
1
+ import { CanvasColour, Point, RequiredProps, Size } from '../interfaces';
2
+ import { CanvasPointer, LGraphCanvas, LGraphNode } from '../litegraph';
3
+ import { CanvasPointerEvent } from './events';
4
+ export interface IWidgetOptions<TValues = unknown[]> {
5
+ on?: string;
6
+ off?: string;
7
+ max?: number;
8
+ min?: number;
9
+ slider_color?: CanvasColour;
10
+ marker_color?: CanvasColour;
11
+ precision?: number;
12
+ read_only?: boolean;
13
+ /**
14
+ * @deprecated Use {@link IWidgetOptions.step2} instead.
15
+ * The legacy step is scaled up by 10x in the legacy frontend logic.
16
+ */
17
+ step?: number;
18
+ /** The step value for numeric widgets. */
19
+ step2?: number;
20
+ y?: number;
21
+ multiline?: boolean;
22
+ property?: string;
23
+ /** If `true`, an input socket will not be created for this widget. */
24
+ socketless?: boolean;
25
+ values?: TValues;
26
+ callback?: IWidget["callback"];
27
+ }
28
+ export interface IWidgetSliderOptions extends IWidgetOptions<number[]> {
29
+ min: number;
30
+ max: number;
31
+ step2: number;
32
+ slider_color?: CanvasColour;
33
+ marker_color?: CanvasColour;
34
+ }
35
+ export interface IWidgetKnobOptions extends IWidgetOptions<number[]> {
36
+ min: number;
37
+ max: number;
38
+ step2: number;
39
+ slider_color?: CanvasColour;
40
+ marker_color?: CanvasColour;
41
+ gradient_stops?: string;
42
+ }
43
+ /**
44
+ * A widget for a node.
45
+ * All types are based on IBaseWidget - additions can be made there or directly on individual types.
46
+ *
47
+ * Implemented as a discriminative union of widget types, so this type itself cannot be extended.
48
+ * Recommend declaration merging any properties that use IWidget (e.g. {@link LGraphNode.widgets}) with a new type alias.
49
+ * @see ICustomWidget
50
+ */
51
+ export type IWidget = IBooleanWidget | INumericWidget | IStringWidget | IComboWidget | IStringComboWidget | ICustomWidget | ISliderWidget | IButtonWidget | IKnobWidget;
52
+ export interface IBooleanWidget extends IBaseWidget<boolean, "toggle"> {
53
+ type: "toggle";
54
+ value: boolean;
55
+ }
56
+ /** Any widget that uses a numeric backing */
57
+ export interface INumericWidget extends IBaseWidget<number, "number"> {
58
+ type: "number";
59
+ value: number;
60
+ }
61
+ export interface ISliderWidget extends IBaseWidget<number, "slider", IWidgetSliderOptions> {
62
+ type: "slider";
63
+ value: number;
64
+ marker?: number;
65
+ }
66
+ export interface IKnobWidget extends IBaseWidget<number, "knob", IWidgetKnobOptions> {
67
+ type: "knob";
68
+ value: number;
69
+ options: IWidgetKnobOptions;
70
+ }
71
+ /** Avoids the type issues with the legacy IComboWidget type */
72
+ export interface IStringComboWidget extends IBaseWidget<string, "combo", RequiredProps<IWidgetOptions<string[]>, "values">> {
73
+ type: "combo";
74
+ value: string;
75
+ }
76
+ type ComboWidgetValues = string[] | Record<string, string> | ((widget?: IComboWidget, node?: LGraphNode) => string[]);
77
+ /** A combo-box widget (dropdown, select, etc) */
78
+ export interface IComboWidget extends IBaseWidget<string | number, "combo", RequiredProps<IWidgetOptions<ComboWidgetValues>, "values">> {
79
+ type: "combo";
80
+ value: string | number;
81
+ }
82
+ /** A widget with a string value */
83
+ export interface IStringWidget extends IBaseWidget<string, "string" | "text", IWidgetOptions<string[]>> {
84
+ type: "string" | "text";
85
+ value: string;
86
+ }
87
+ export interface IButtonWidget extends IBaseWidget<string | undefined, "button"> {
88
+ type: "button";
89
+ value: string | undefined;
90
+ clicked: boolean;
91
+ }
92
+ /** A custom widget - accepts any value and has no built-in special handling */
93
+ export interface ICustomWidget extends IBaseWidget<string | object, "custom"> {
94
+ type: "custom";
95
+ value: string | object;
96
+ }
97
+ /**
98
+ * Valid widget types. TS cannot provide easily extensible type safety for this at present.
99
+ * Override linkedWidgets[]
100
+ * Values not in this list will not result in litegraph errors, however they will be treated the same as "custom".
101
+ */
102
+ export type TWidgetType = IWidget["type"];
103
+ export type TWidgetValue = IWidget["value"];
104
+ /**
105
+ * The base type for all widgets. Should not be implemented directly.
106
+ * @template TValue The type of value this widget holds.
107
+ * @template TType A string designating the type of widget, e.g. "toggle" or "string".
108
+ * @template TOptions The options for this widget.
109
+ * @see IWidget
110
+ */
111
+ export interface IBaseWidget<TValue = boolean | number | string | object | undefined, TType extends string = string, TOptions extends IWidgetOptions<unknown> = IWidgetOptions<unknown>> {
112
+ linkedWidgets?: IBaseWidget[];
113
+ name: string;
114
+ options: TOptions;
115
+ label?: string;
116
+ /** Widget type (see {@link TWidgetType}) */
117
+ type: TType;
118
+ value?: TValue;
119
+ /**
120
+ * Whether the widget value should be serialized on node serialization.
121
+ * @default true
122
+ */
123
+ serialize?: boolean;
124
+ /**
125
+ * The computed height of the widget. Used by customized node resize logic.
126
+ * See scripts/domWidget.ts for more details.
127
+ * @readonly [Computed] This property is computed by the node.
128
+ */
129
+ computedHeight?: number;
130
+ /**
131
+ * The starting y position of the widget after layout.
132
+ * @readonly [Computed] This property is computed by the node.
133
+ */
134
+ y: number;
135
+ /**
136
+ * The y position of the widget after drawing (rendering).
137
+ * @readonly [Computed] This property is computed by the node.
138
+ * @deprecated There is no longer dynamic y adjustment on rendering anymore.
139
+ * Use {@link IBaseWidget.y} instead.
140
+ */
141
+ last_y?: number;
142
+ width?: number;
143
+ /**
144
+ * Whether the widget is disabled. Disabled widgets are rendered at half opacity.
145
+ * See also {@link IBaseWidget.computedDisabled}.
146
+ */
147
+ disabled?: boolean;
148
+ /**
149
+ * The disabled state used for rendering based on various conditions including
150
+ * {@link IBaseWidget.disabled}.
151
+ * @readonly [Computed] This property is computed by the node.
152
+ */
153
+ computedDisabled?: boolean;
154
+ hidden?: boolean;
155
+ advanced?: boolean;
156
+ tooltip?: string;
157
+ callback?(value: any, canvas?: LGraphCanvas, node?: LGraphNode, pos?: Point, e?: CanvasPointerEvent): void;
158
+ /**
159
+ * Simple callback for pointer events, allowing custom widgets to events relevant to them.
160
+ * @param event The pointer event that triggered this callback
161
+ * @param pointerOffset Offset of the pointer relative to {@link node.pos}
162
+ * @param node The node this widget belongs to
163
+ * @todo Expose CanvasPointer API to custom widgets
164
+ */
165
+ mouse?(event: CanvasPointerEvent, pointerOffset: Point, node: LGraphNode): boolean;
166
+ /**
167
+ * Draw the widget.
168
+ * @param ctx The canvas context to draw on.
169
+ * @param node The node this widget belongs to.
170
+ * @param widget_width The width of the widget.
171
+ * @param y The y position of the widget.
172
+ * @param H The height of the widget.
173
+ * @param lowQuality Whether to draw the widget in low quality.
174
+ */
175
+ draw?(ctx: CanvasRenderingContext2D, node: LGraphNode, widget_width: number, y: number, H: number, lowQuality?: boolean): void;
176
+ /**
177
+ * Compute the size of the widget. Overrides {@link IBaseWidget.computeSize}.
178
+ * @param width The width of the widget.
179
+ * @deprecated Use {@link IBaseWidget.computeLayoutSize} instead.
180
+ * @returns The size of the widget.
181
+ */
182
+ computeSize?(width?: number): Size;
183
+ /**
184
+ * Compute the layout size of the widget.
185
+ * @param node The node this widget belongs to.
186
+ * @returns The layout size of the widget.
187
+ */
188
+ computeLayoutSize?(this: IBaseWidget, node: LGraphNode): {
189
+ minHeight: number;
190
+ maxHeight?: number;
191
+ minWidth: number;
192
+ maxWidth?: number;
193
+ };
194
+ /**
195
+ * Callback for pointerdown events, allowing custom widgets to register callbacks to occur
196
+ * for all {@link CanvasPointer} events.
197
+ *
198
+ * This callback is operated early in the pointerdown logic; actions that prevent it from firing are:
199
+ * - `Ctrl + Drag` Multi-select
200
+ * - `Alt + Click/Drag` Clone node
201
+ * @param pointer The CanvasPointer handling this event
202
+ * @param node The node this widget belongs to
203
+ * @param canvas The LGraphCanvas where this event originated
204
+ * @returns Returning `true` from this callback forces Litegraph to ignore the event and
205
+ * not process it any further.
206
+ */
207
+ onPointerDown?(pointer: CanvasPointer, node: LGraphNode, canvas: LGraphCanvas): boolean;
208
+ }
209
+ export {};
@@ -0,0 +1,22 @@
1
+ import { Direction, IBoundaryNodes } from '../interfaces';
2
+ import { LGraphNode } from '../LGraphNode';
3
+ /**
4
+ * Finds the nodes that are farthest in all four directions, representing the boundary of the nodes.
5
+ * @param nodes The nodes to check the edges of
6
+ * @returns An object listing the furthest node (edge) in all four directions.
7
+ * `null` if no nodes were supplied or the first node was falsy.
8
+ */
9
+ export declare function getBoundaryNodes(nodes: LGraphNode[]): IBoundaryNodes | null;
10
+ /**
11
+ * Distributes nodes evenly along a horizontal or vertical plane.
12
+ * @param nodes The nodes to distribute
13
+ * @param horizontal If true, distributes along the horizontal plane. Otherwise, the vertical plane.
14
+ */
15
+ export declare function distributeNodes(nodes: LGraphNode[], horizontal?: boolean): void;
16
+ /**
17
+ * Aligns all nodes along the edge of a node.
18
+ * @param nodes The nodes to align
19
+ * @param direction The edge to align nodes on
20
+ * @param align_to The node to align all other nodes to. If undefined, the farthest node will be used.
21
+ */
22
+ export declare function alignNodes(nodes: LGraphNode[], direction: Direction, align_to?: LGraphNode): void;
@@ -0,0 +1,38 @@
1
+ import { ConnectingLink, ISlotType, Positionable } from '../interfaces';
2
+ import { LinkId } from '../LLink';
3
+ import { LGraphNode } from '../LGraphNode';
4
+ /**
5
+ * Creates a flat set of all positionable items by recursively iterating through all child items.
6
+ *
7
+ * Does not include or recurse into pinned items.
8
+ * @param items The original set of items to iterate through
9
+ * @returns All unpinned items in the original set, and recursively, their children
10
+ */
11
+ export declare function getAllNestedItems(items: ReadonlySet<Positionable>): Set<Positionable>;
12
+ /**
13
+ * Iterates through a collection of {@link Positionable} items, returning the first {@link LGraphNode}.
14
+ * @param items The items to search through
15
+ * @returns The first node found in {@link items}, otherwise `undefined`
16
+ */
17
+ export declare function findFirstNode(items: Iterable<Positionable>): LGraphNode | undefined;
18
+ /** @returns `true` if the provided link ID is currently being dragged. */
19
+ export declare function isDraggingLink(linkId: LinkId, connectingLinks: ConnectingLink[] | null | undefined): ConnectingLink | undefined;
20
+ /**
21
+ * Finds the first free in/out slot with any of the comma-delimited types in {@link type}.
22
+ *
23
+ * If no slots are free, falls back in order to:
24
+ * - The first free wildcard slot
25
+ * - The first occupied slot
26
+ * - The first occupied wildcard slot
27
+ * @param slots The iterable of node slots slots to search through
28
+ * @param type The {@link ISlotType type} of slot to find
29
+ * @param hasNoLinks A predicate that returns `true` if the slot is free.
30
+ * @returns The index and slot if found, otherwise `undefined`.
31
+ */
32
+ export declare function findFreeSlotOfType<T extends {
33
+ type: ISlotType;
34
+ }>(slots: T[], type: ISlotType, hasNoLinks: (slot: T) => boolean): {
35
+ index: number;
36
+ slot: T;
37
+ } | undefined;
38
+ export declare function removeFromArray<T>(array: T[], value: T): boolean;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Warns that a deprecated function has been used via the public
3
+ * {@link onDeprecationWarning} / {@link onEveryDeprecationWarning} callback arrays.
4
+ * @param message Plain-language detail about what has been deprecated. This **should not** include unique data; use {@link source}.
5
+ * @param source A reference object to include alongside the message, e.g. `this`.
6
+ */
7
+ export declare function warnDeprecated(message: string, source?: object): void;
@@ -0,0 +1 @@
1
+ export declare function omitBy<T extends object>(obj: T, predicate: (value: any) => boolean): Partial<T>;
@@ -0,0 +1,11 @@
1
+ export interface SpaceRequest {
2
+ minSize: number;
3
+ maxSize?: number;
4
+ }
5
+ /**
6
+ * Distributes available space among items with min/max size constraints
7
+ * @param totalSpace Total space available to distribute
8
+ * @param requests Array of space requests with size constraints
9
+ * @returns Array of space allocations
10
+ */
11
+ export declare function distributeSpace(totalSpace: number, requests: SpaceRequest[]): number[];
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Truncates text to fit within a given width using binary search for optimal performance.
3
+ * @param ctx The canvas rendering context used for text measurement
4
+ * @param text The text to truncate
5
+ * @param maxWidth The maximum width the text should occupy
6
+ * @param ellipsis The ellipsis string to append (default: "...")
7
+ * @returns The truncated text with ellipsis if needed
8
+ */
9
+ export declare function truncateText(ctx: CanvasRenderingContext2D, text: string, maxWidth: number, ellipsis?: string): string;
@@ -0,0 +1,14 @@
1
+ import { IColorable } from '../interfaces';
2
+ /**
3
+ * Converts a plain object to a class instance if it is not already an instance of the class.
4
+ *
5
+ * Requires specific constructor signature; first parameter must be the object to convert.
6
+ * @param cls The class to convert to
7
+ * @param args The object to convert, followed by any other constructor arguments
8
+ * @returns The class instance
9
+ */
10
+ export declare function toClass<P, C extends P, Args extends unknown[]>(cls: new (instance: P, ...args: Args) => C, ...args: [P, ...Args]): C;
11
+ /**
12
+ * Checks if an object is an instance of {@link IColorable}.
13
+ */
14
+ export declare function isColorable(obj: unknown): obj is IColorable;
@@ -0,0 +1,13 @@
1
+ export type UUID = string;
2
+ /** Special-case zero-UUID, consisting entirely of zeros. Used as a default value. */
3
+ export declare const zeroUuid = "00000000-0000-0000-0000-000000000000";
4
+ /**
5
+ * Creates a UUIDv4 string.
6
+ * @returns A new UUIDv4 string
7
+ * @remarks
8
+ * Original implementation from https://gist.github.com/jed/982883?permalink_comment_id=852670#gistcomment-852670
9
+ *
10
+ * Prefers the {@link crypto.randomUUID} method if available, falling back to
11
+ * {@link crypto.getRandomValues}, then finally the legacy {@link Math.random} method.
12
+ */
13
+ export declare function createUuidv4(): UUID;
@@ -0,0 +1,7 @@
1
+ import { IWidgetOptions } from '../types/widgets';
2
+ /**
3
+ * The step value for numeric widgets.
4
+ * Use {@link IWidgetOptions.step2} if available, otherwise fallback to
5
+ * {@link IWidgetOptions.step} which is scaled up by 10x in the legacy frontend logic.
6
+ */
7
+ export declare function getWidgetStep(options: IWidgetOptions<unknown>): number;
@@ -0,0 +1,34 @@
1
+ import { IBaseWidget } from '../types/widgets';
2
+ import { BaseWidget, DrawWidgetOptions, WidgetEventOptions } from './BaseWidget';
3
+ /**
4
+ * Base class for widgets that have increment and decrement buttons.
5
+ */
6
+ export declare abstract class BaseSteppedWidget<TWidget extends IBaseWidget = IBaseWidget> extends BaseWidget<TWidget> {
7
+ /**
8
+ * Whether the widget can increment its value
9
+ * @returns `true` if the widget can increment its value, otherwise `false`
10
+ */
11
+ abstract canIncrement(): boolean;
12
+ /**
13
+ * Whether the widget can decrement its value
14
+ * @returns `true` if the widget can decrement its value, otherwise `false`
15
+ */
16
+ abstract canDecrement(): boolean;
17
+ /**
18
+ * Increment the value of the widget
19
+ * @param options The options for the widget event
20
+ */
21
+ abstract incrementValue(options: WidgetEventOptions): void;
22
+ /**
23
+ * Decrement the value of the widget
24
+ * @param options The options for the widget event
25
+ */
26
+ abstract decrementValue(options: WidgetEventOptions): void;
27
+ /**
28
+ * Draw the arrow buttons for the widget
29
+ * @param ctx The canvas rendering context
30
+ * @param width The width of the widget
31
+ */
32
+ drawArrowButtons(ctx: CanvasRenderingContext2D, width: number): void;
33
+ drawWidget(ctx: CanvasRenderingContext2D, options: DrawWidgetOptions): void;
34
+ }