@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,772 @@
1
+ import { ContextMenu } from './ContextMenu';
2
+ import { CustomEventDispatcher, ICustomEventTarget } from './infrastructure/CustomEventTarget';
3
+ import { LGraphCanvasEventMap } from './infrastructure/LGraphCanvasEventMap';
4
+ import { CanvasColour, ColorOption, ConnectingLink, DefaultConnectionColors, Dictionary, Direction, IBoundaryNodes, IContextMenuOptions, IContextMenuValue, INodeInputSlot, INodeOutputSlot, INodeSlotContextItem, ISlotType, LinkSegment, NullableProperties, Point, Positionable, ReadOnlyPoint, ReadOnlyRect, Rect, Size } from './interfaces';
5
+ import { LGraph } from './LGraph';
6
+ import { CanvasPointerEvent, CanvasPointerExtensions } from './types/events';
7
+ import { SubgraphIO } from './types/serialisation';
8
+ import { NeverNever, PickNevers } from './types/utility';
9
+ import { IBaseWidget } from './types/widgets';
10
+ import { UUID } from './utils/uuid';
11
+ import { LinkConnector } from './canvas/LinkConnector';
12
+ import { CanvasPointer } from './CanvasPointer';
13
+ import { AnimationOptions, DragAndScale } from './DragAndScale';
14
+ import { LGraphGroup } from './LGraphGroup';
15
+ import { LGraphNode, NodeId, NodeProperty } from './LGraphNode';
16
+ import { LiteGraph, Rectangle } from './litegraph';
17
+ import { LinkId, LLink } from './LLink';
18
+ import { Reroute, RerouteId } from './Reroute';
19
+ import { Subgraph } from './subgraph/Subgraph';
20
+ import { SubgraphInputNode } from './subgraph/SubgraphInputNode';
21
+ import { SubgraphOutputNode } from './subgraph/SubgraphOutputNode';
22
+ import { CanvasItem, LinkDirection, LinkMarkerShape, RenderShape } from './types/globalEnums';
23
+ interface IShowSearchOptions {
24
+ node_to?: LGraphNode | null;
25
+ node_from?: LGraphNode | null;
26
+ slot_from: number | INodeOutputSlot | INodeInputSlot | null | undefined;
27
+ type_filter_in?: ISlotType;
28
+ type_filter_out?: ISlotType | false;
29
+ do_type_filter?: boolean;
30
+ show_general_if_none_on_typefilter?: boolean;
31
+ show_general_after_typefiltered?: boolean;
32
+ hide_on_mouse_leave?: boolean;
33
+ show_all_if_empty?: boolean;
34
+ show_all_on_open?: boolean;
35
+ }
36
+ interface ICreateNodeOptions {
37
+ /** input */
38
+ nodeFrom?: SubgraphInputNode | LGraphNode | null;
39
+ /** input */
40
+ slotFrom?: number | INodeOutputSlot | INodeInputSlot | SubgraphIO | null;
41
+ /** output */
42
+ nodeTo?: SubgraphOutputNode | LGraphNode | null;
43
+ /** output */
44
+ slotTo?: number | INodeOutputSlot | INodeInputSlot | SubgraphIO | null;
45
+ /** pass the event coords */
46
+ /** Create the connection from a reroute */
47
+ afterRerouteId?: RerouteId;
48
+ /** choose a nodetype to add, AUTO to set at first good */
49
+ nodeType?: string;
50
+ e?: CanvasPointerEvent;
51
+ allow_searchbox?: boolean;
52
+ }
53
+ interface ICreateDefaultNodeOptions extends ICreateNodeOptions {
54
+ /** Position of new node */
55
+ position: Point;
56
+ /** adjust x,y */
57
+ posAdd?: Point;
58
+ /** alpha, adjust the position x,y based on the new node size w,h */
59
+ posSizeFix?: Point;
60
+ }
61
+ interface ICloseable {
62
+ close(): void;
63
+ }
64
+ interface IDialogExtensions extends ICloseable {
65
+ modified(): void;
66
+ is_modified: boolean;
67
+ }
68
+ interface IDialog extends HTMLDivElement, IDialogExtensions {
69
+ }
70
+ type PromptDialog = Omit<IDialog, "modified">;
71
+ interface IDialogOptions {
72
+ position?: Point;
73
+ event?: MouseEvent;
74
+ checkForInput?: boolean;
75
+ closeOnLeave?: boolean;
76
+ onclose?(): void;
77
+ }
78
+ /** @inheritdoc {@link LGraphCanvas.state} */
79
+ export interface LGraphCanvasState {
80
+ /** {@link Positionable} items are being dragged on the canvas. */
81
+ draggingItems: boolean;
82
+ /** The canvas itself is being dragged. */
83
+ draggingCanvas: boolean;
84
+ /** The canvas is read-only, preventing changes to nodes, disconnecting links, moving items, etc. */
85
+ readOnly: boolean;
86
+ /** Bit flags indicating what is currently below the pointer. */
87
+ hoveringOver: CanvasItem;
88
+ /** If `true`, pointer move events will set the canvas cursor style. */
89
+ shouldSetCursor: boolean;
90
+ /**
91
+ * Dirty flag indicating that {@link selectedItems} has changed.
92
+ * Downstream consumers may reset to false once actioned.
93
+ */
94
+ selectionChanged: boolean;
95
+ }
96
+ /**
97
+ * The items created by a clipboard paste operation.
98
+ * Includes maps of original copied IDs to newly created items.
99
+ */
100
+ interface ClipboardPasteResult {
101
+ /** All successfully created items */
102
+ created: Positionable[];
103
+ /** Map: original node IDs to newly created nodes */
104
+ nodes: Map<NodeId, LGraphNode>;
105
+ /** Map: original link IDs to new link IDs */
106
+ links: Map<LinkId, LLink>;
107
+ /** Map: original reroute IDs to newly created reroutes */
108
+ reroutes: Map<RerouteId, Reroute>;
109
+ /** Map: original subgraph IDs to newly created subgraphs */
110
+ subgraphs: Map<UUID, Subgraph>;
111
+ }
112
+ /** Options for {@link LGraphCanvas.pasteFromClipboard}. */
113
+ interface IPasteFromClipboardOptions {
114
+ /** If `true`, always attempt to connect inputs of pasted nodes - including to nodes that were not pasted. */
115
+ connectInputs?: boolean;
116
+ /** The position to paste the items at. */
117
+ position?: Point;
118
+ }
119
+ interface ICreatePanelOptions {
120
+ closable?: any;
121
+ window?: any;
122
+ onOpen?: () => void;
123
+ onClose?: () => void;
124
+ width?: any;
125
+ height?: any;
126
+ }
127
+ /**
128
+ * This class is in charge of rendering one graph inside a canvas. And provides all the interaction required.
129
+ * Valid callbacks are: onNodeSelected, onNodeDeselected, onShowNodePanel, onNodeDblClicked
130
+ */
131
+ export declare class LGraphCanvas implements CustomEventDispatcher<LGraphCanvasEventMap> {
132
+ #private;
133
+ static DEFAULT_BACKGROUND_IMAGE: string;
134
+ static DEFAULT_EVENT_LINK_COLOR: string;
135
+ /** Link type to colour dictionary. */
136
+ static link_type_colors: Dictionary<string>;
137
+ static gradients: Record<string, CanvasGradient>;
138
+ static search_limit: number;
139
+ static node_colors: Record<string, ColorOption>;
140
+ /**
141
+ * @internal Exclusively a workaround for design limitation in {@link LGraphNode.computeSize}.
142
+ */
143
+ static _measureText?: (text: string, fontStyle?: string) => number;
144
+ /**
145
+ * The state of this canvas, e.g. whether it is being dragged, or read-only.
146
+ *
147
+ * Implemented as a POCO that can be proxied without side-effects.
148
+ */
149
+ state: LGraphCanvasState;
150
+ get subgraph(): Subgraph | undefined;
151
+ set subgraph(value: Subgraph | undefined);
152
+ /** Dispatches a custom event on the canvas. */
153
+ dispatch<T extends keyof NeverNever<LGraphCanvasEventMap>>(type: T, detail: LGraphCanvasEventMap[T]): boolean;
154
+ dispatch<T extends keyof PickNevers<LGraphCanvasEventMap>>(type: T): boolean;
155
+ dispatchEvent<TEvent extends keyof LGraphCanvasEventMap>(type: TEvent, detail: LGraphCanvasEventMap[TEvent]): void;
156
+ private _previously_dragging_canvas;
157
+ /** @deprecated @inheritdoc {@link LGraphCanvasState.readOnly} */
158
+ get read_only(): boolean;
159
+ set read_only(value: boolean);
160
+ get isDragging(): boolean;
161
+ set isDragging(value: boolean);
162
+ get hoveringOver(): CanvasItem;
163
+ set hoveringOver(value: CanvasItem);
164
+ /** @deprecated Replace all references with {@link pointer}.{@link CanvasPointer.isDown isDown}. */
165
+ get pointer_is_down(): boolean;
166
+ /** @deprecated Replace all references with {@link pointer}.{@link CanvasPointer.isDouble isDouble}. */
167
+ get pointer_is_double(): boolean;
168
+ /** @deprecated @inheritdoc {@link LGraphCanvasState.draggingCanvas} */
169
+ get dragging_canvas(): boolean;
170
+ set dragging_canvas(value: boolean);
171
+ /**
172
+ * @deprecated Use {@link LGraphNode.titleFontStyle} instead.
173
+ */
174
+ get title_text_font(): string;
175
+ get inner_text_font(): string;
176
+ /** Maximum frames per second to render. 0: unlimited. Default: 0 */
177
+ get maximumFps(): number;
178
+ set maximumFps(value: number);
179
+ /**
180
+ * @deprecated Use {@link LiteGraphGlobal.ROUND_RADIUS} instead.
181
+ */
182
+ get round_radius(): number;
183
+ /**
184
+ * @deprecated Use {@link LiteGraphGlobal.ROUND_RADIUS} instead.
185
+ */
186
+ set round_radius(value: number);
187
+ /**
188
+ * Render low quality when zoomed out.
189
+ */
190
+ get low_quality(): boolean;
191
+ options: {
192
+ skip_events?: any;
193
+ viewport?: any;
194
+ skip_render?: any;
195
+ autoresize?: any;
196
+ };
197
+ background_image: string;
198
+ readonly ds: DragAndScale;
199
+ readonly pointer: CanvasPointer;
200
+ zoom_modify_alpha: boolean;
201
+ zoom_speed: number;
202
+ node_title_color: string;
203
+ default_link_color: string;
204
+ default_connection_color: {
205
+ input_off: string;
206
+ input_on: string;
207
+ output_off: string;
208
+ output_on: string;
209
+ };
210
+ default_connection_color_byType: Dictionary<CanvasColour>;
211
+ default_connection_color_byTypeOff: Dictionary<CanvasColour>;
212
+ /** Gets link colours. Extremely basic impl. until the legacy object dictionaries are removed. */
213
+ colourGetter: DefaultConnectionColors;
214
+ highquality_render: boolean;
215
+ use_gradients: boolean;
216
+ editor_alpha: number;
217
+ pause_rendering: boolean;
218
+ clear_background: boolean;
219
+ clear_background_color: string;
220
+ render_only_selected: boolean;
221
+ show_info: boolean;
222
+ allow_dragcanvas: boolean;
223
+ allow_dragnodes: boolean;
224
+ allow_interaction: boolean;
225
+ multi_select: boolean;
226
+ allow_searchbox: boolean;
227
+ allow_reconnect_links: boolean;
228
+ align_to_grid: boolean;
229
+ drag_mode: boolean;
230
+ dragging_rectangle: Rect | null;
231
+ filter?: string | null;
232
+ set_canvas_dirty_on_mouse_event: boolean;
233
+ always_render_background: boolean;
234
+ render_shadows: boolean;
235
+ render_canvas_border: boolean;
236
+ render_connections_shadows: boolean;
237
+ render_connections_border: boolean;
238
+ render_curved_connections: boolean;
239
+ render_connection_arrows: boolean;
240
+ render_collapsed_slots: boolean;
241
+ render_execution_order: boolean;
242
+ render_link_tooltip: boolean;
243
+ /** Shape of the markers shown at the midpoint of links. Default: Circle */
244
+ linkMarkerShape: LinkMarkerShape;
245
+ links_render_mode: number;
246
+ /** Zoom threshold for low quality rendering. Zoom below this threshold will render low quality. */
247
+ low_quality_zoom_threshold: number;
248
+ /** mouse in canvas coordinates, where 0,0 is the top-left corner of the blue rectangle */
249
+ readonly mouse: Point;
250
+ /** mouse in graph coordinates, where 0,0 is the top-left corner of the blue rectangle */
251
+ readonly graph_mouse: Point;
252
+ /** @deprecated LEGACY: REMOVE THIS, USE {@link graph_mouse} INSTEAD */
253
+ canvas_mouse: Point;
254
+ /** to personalize the search box */
255
+ onSearchBox?: (helper: Element, str: string, canvas: LGraphCanvas) => any;
256
+ onSearchBoxSelection?: (name: any, event: any, canvas: LGraphCanvas) => void;
257
+ onMouse?: (e: CanvasPointerEvent) => boolean;
258
+ /** to render background objects (behind nodes and connections) in the canvas affected by transform */
259
+ onDrawBackground?: (ctx: CanvasRenderingContext2D, visible_area: any) => void;
260
+ /** to render foreground objects (above nodes and connections) in the canvas affected by transform */
261
+ onDrawForeground?: (arg0: CanvasRenderingContext2D, arg1: any) => void;
262
+ connections_width: number;
263
+ /** The current node being drawn by {@link drawNode}. This should NOT be used to determine the currently selected node. See {@link selectedItems} */
264
+ current_node: LGraphNode | null;
265
+ /** used for widgets */
266
+ node_widget?: [LGraphNode, IBaseWidget] | null;
267
+ /** The link to draw a tooltip for. */
268
+ over_link_center?: LinkSegment;
269
+ last_mouse_position: Point;
270
+ /** The visible area of this canvas. Tightly coupled with {@link ds}. */
271
+ visible_area: Rectangle;
272
+ /** Contains all links and reroutes that were rendered. Repopulated every render cycle. */
273
+ renderedPaths: Set<LinkSegment>;
274
+ /** @deprecated Replaced by {@link renderedPaths}, but length is set to 0 by some extensions. */
275
+ visible_links: LLink[];
276
+ /** @deprecated This array is populated and cleared to support legacy extensions. The contents are ignored by Litegraph. */
277
+ connecting_links: ConnectingLink[] | null;
278
+ linkConnector: LinkConnector;
279
+ /** The viewport of this canvas. Tightly coupled with {@link ds}. */
280
+ readonly viewport?: Rect;
281
+ autoresize: boolean;
282
+ static active_canvas: LGraphCanvas;
283
+ frame: number;
284
+ last_draw_time: number;
285
+ render_time: number;
286
+ fps: number;
287
+ /** @deprecated See {@link LGraphCanvas.selectedItems} */
288
+ selected_nodes: Dictionary<LGraphNode>;
289
+ /** All selected nodes, groups, and reroutes */
290
+ selectedItems: Set<Positionable>;
291
+ /** The group currently being resized. */
292
+ resizingGroup: LGraphGroup | null;
293
+ /** @deprecated See {@link LGraphCanvas.selectedItems} */
294
+ selected_group: LGraphGroup | null;
295
+ /** The nodes that are currently visible on the canvas. */
296
+ visible_nodes: LGraphNode[];
297
+ node_over?: LGraphNode;
298
+ node_capturing_input?: LGraphNode | null;
299
+ highlighted_links: Dictionary<boolean>;
300
+ dirty_canvas: boolean;
301
+ dirty_bgcanvas: boolean;
302
+ /** A map of nodes that require selective-redraw */
303
+ dirty_nodes: Map<NodeId, LGraphNode>;
304
+ dirty_area?: Rect | null;
305
+ /** @deprecated Unused */
306
+ node_in_panel?: LGraphNode | null;
307
+ last_mouse: ReadOnlyPoint;
308
+ last_mouseclick: number;
309
+ graph: LGraph | Subgraph | null;
310
+ get _graph(): LGraph | Subgraph;
311
+ canvas: HTMLCanvasElement & ICustomEventTarget<LGraphCanvasEventMap>;
312
+ bgcanvas: HTMLCanvasElement;
313
+ ctx: CanvasRenderingContext2D;
314
+ _events_binded?: boolean;
315
+ _mousedown_callback?(e: PointerEvent): void;
316
+ _mousewheel_callback?(e: WheelEvent): void;
317
+ _mousemove_callback?(e: PointerEvent): void;
318
+ _mouseup_callback?(e: PointerEvent): void;
319
+ _mouseout_callback?(e: PointerEvent): void;
320
+ _mousecancel_callback?(e: PointerEvent): void;
321
+ _key_callback?(e: KeyboardEvent): void;
322
+ bgctx?: CanvasRenderingContext2D | null;
323
+ is_rendering?: boolean;
324
+ /** @deprecated Panels */
325
+ block_click?: boolean;
326
+ /** @deprecated Panels */
327
+ last_click_position?: Point | null;
328
+ resizing_node?: LGraphNode | null;
329
+ /** @deprecated See {@link LGraphCanvas.resizingGroup} */
330
+ selected_group_resizing?: boolean;
331
+ /** @deprecated See {@link pointer}.{@link CanvasPointer.dragStarted dragStarted} */
332
+ last_mouse_dragging?: boolean;
333
+ onMouseDown?: (arg0: CanvasPointerEvent) => void;
334
+ _highlight_pos?: Point;
335
+ _highlight_input?: INodeInputSlot;
336
+ /** @deprecated Panels */
337
+ node_panel?: any;
338
+ /** @deprecated Panels */
339
+ options_panel?: any;
340
+ _bg_img?: HTMLImageElement;
341
+ _pattern?: CanvasPattern;
342
+ _pattern_img?: HTMLImageElement;
343
+ prompt_box?: PromptDialog | null;
344
+ search_box?: HTMLDivElement;
345
+ /** @deprecated Panels */
346
+ SELECTED_NODE?: LGraphNode;
347
+ /** @deprecated Panels */
348
+ NODEPANEL_IS_OPEN?: boolean;
349
+ /** If true, enable drag zoom. Ctrl+Shift+Drag Up/Down: zoom canvas. */
350
+ dragZoomEnabled: boolean;
351
+ getMenuOptions?(): IContextMenuValue<string>[];
352
+ getExtraMenuOptions?(canvas: LGraphCanvas, options: IContextMenuValue<string>[]): IContextMenuValue<string>[];
353
+ static active_node: LGraphNode;
354
+ /** called before modifying the graph */
355
+ onBeforeChange?(graph: LGraph): void;
356
+ /** called after modifying the graph */
357
+ onAfterChange?(graph: LGraph): void;
358
+ onClear?: () => void;
359
+ /** called after moving a node @deprecated Does not handle multi-node move, and can return the wrong node. */
360
+ onNodeMoved?: (node_dragged: LGraphNode | undefined) => void;
361
+ /** @deprecated Called with the deprecated {@link selected_nodes} when the selection changes. Replacement not yet impl. */
362
+ onSelectionChange?: (selected: Dictionary<Positionable>) => void;
363
+ /** called when rendering a tooltip */
364
+ onDrawLinkTooltip?: (ctx: CanvasRenderingContext2D, link: LLink | null, canvas?: LGraphCanvas) => boolean;
365
+ /** to render foreground objects not affected by transform (for GUIs) */
366
+ onDrawOverlay?: (ctx: CanvasRenderingContext2D) => void;
367
+ onRenderBackground?: (canvas: HTMLCanvasElement, ctx: CanvasRenderingContext2D) => boolean;
368
+ onNodeDblClicked?: (n: LGraphNode) => void;
369
+ onShowNodePanel?: (n: LGraphNode) => void;
370
+ onNodeSelected?: (node: LGraphNode) => void;
371
+ onNodeDeselected?: (node: LGraphNode) => void;
372
+ onRender?: (canvas: HTMLCanvasElement, ctx: CanvasRenderingContext2D) => void;
373
+ /**
374
+ * Creates a new instance of LGraphCanvas.
375
+ * @param canvas The canvas HTML element (or its id) to use, or null / undefined to leave blank.
376
+ * @param graph The graph that owns this canvas.
377
+ * @param options
378
+ */
379
+ constructor(canvas: HTMLCanvasElement, graph: LGraph, options?: LGraphCanvas["options"]);
380
+ static onGroupAdd(info: unknown, entry: unknown, mouse_event: MouseEvent): void;
381
+ /**
382
+ * @deprecated Functionality moved to {@link getBoundaryNodes}. The new function returns null on failure, instead of an object with all null properties.
383
+ * Determines the furthest nodes in each direction
384
+ * @param nodes the nodes to from which boundary nodes will be extracted
385
+ * @returns
386
+ */
387
+ static getBoundaryNodes(nodes: LGraphNode[] | Dictionary<LGraphNode>): NullableProperties<IBoundaryNodes>;
388
+ /**
389
+ * @deprecated Functionality moved to {@link alignNodes}. The new function does not set dirty canvas.
390
+ * @param nodes a list of nodes
391
+ * @param direction Direction to align the nodes
392
+ * @param align_to Node to align to (if null, align to the furthest node in the given direction)
393
+ */
394
+ static alignNodes(nodes: Dictionary<LGraphNode>, direction: Direction, align_to?: LGraphNode): void;
395
+ static onNodeAlign(value: IContextMenuValue, options: IContextMenuOptions, event: MouseEvent, prev_menu: ContextMenu<string>, node: LGraphNode): void;
396
+ static onGroupAlign(value: IContextMenuValue, options: IContextMenuOptions, event: MouseEvent, prev_menu: ContextMenu<string>): void;
397
+ static createDistributeMenu(value: IContextMenuValue, options: IContextMenuOptions, event: MouseEvent, prev_menu: ContextMenu<string>): void;
398
+ static onMenuAdd(value: unknown, options: unknown, e: MouseEvent, prev_menu?: ContextMenu<string>, callback?: (node: LGraphNode | null) => void): boolean | undefined;
399
+ static onMenuCollapseAll(): void;
400
+ static onMenuNodeEdit(): void;
401
+ /** @param _options Parameter is never used */
402
+ static showMenuNodeOptionalOutputs(v: unknown,
403
+ /** Unused - immediately overwritten */
404
+ _options: INodeOutputSlot[], e: MouseEvent, prev_menu: ContextMenu<INodeSlotContextItem>, node: LGraphNode): boolean | undefined;
405
+ /** @param value Parameter is never used */
406
+ static onShowMenuNodeProperties(value: NodeProperty | undefined, options: unknown, e: MouseEvent, prev_menu: ContextMenu<string>, node: LGraphNode): boolean | undefined;
407
+ /** @deprecated */
408
+ static decodeHTML(str: string): string;
409
+ static onMenuResizeNode(value: IContextMenuValue, options: IContextMenuOptions, e: MouseEvent, menu: ContextMenu, node: LGraphNode): void;
410
+ static onShowPropertyEditor(item: {
411
+ property: keyof LGraphNode;
412
+ type: string;
413
+ }, options: IContextMenuOptions<string>, e: MouseEvent, menu: ContextMenu<string>, node: LGraphNode): void;
414
+ static getPropertyPrintableValue(value: unknown, values: unknown[] | object | undefined): string | undefined;
415
+ static onMenuNodeCollapse(value: IContextMenuValue, options: IContextMenuOptions, e: MouseEvent, menu: ContextMenu, node: LGraphNode): void;
416
+ static onMenuToggleAdvanced(value: IContextMenuValue, options: IContextMenuOptions, e: MouseEvent, menu: ContextMenu, node: LGraphNode): void;
417
+ static onMenuNodeMode(value: IContextMenuValue, options: IContextMenuOptions, e: MouseEvent, menu: ContextMenu, node: LGraphNode): boolean;
418
+ /** @param value Parameter is never used */
419
+ static onMenuNodeColors(value: IContextMenuValue<string | null>, options: IContextMenuOptions, e: MouseEvent, menu: ContextMenu<string | null>, node: LGraphNode): boolean;
420
+ static onMenuNodeShapes(value: IContextMenuValue<typeof LiteGraph.VALID_SHAPES[number]>, options: IContextMenuOptions<typeof LiteGraph.VALID_SHAPES[number]>, e: MouseEvent, menu?: ContextMenu<typeof LiteGraph.VALID_SHAPES[number]>, node?: LGraphNode): boolean;
421
+ static onMenuNodeRemove(): void;
422
+ static onMenuNodeClone(value: IContextMenuValue, options: IContextMenuOptions, e: MouseEvent, menu: ContextMenu, node: LGraphNode): void;
423
+ /**
424
+ * clears all the data inside
425
+ *
426
+ */
427
+ clear(): void;
428
+ /**
429
+ * Assigns a new graph to this canvas.
430
+ */
431
+ setGraph(newGraph: LGraph | Subgraph): void;
432
+ openSubgraph(subgraph: Subgraph): void;
433
+ /**
434
+ * @returns the visually active graph (in case there are more in the stack)
435
+ */
436
+ getCurrentGraph(): LGraph | null;
437
+ /**
438
+ * Sets the current HTML canvas element.
439
+ * Calls bindEvents to add input event listeners, and (re)creates the background canvas.
440
+ * @param canvas The canvas element to assign, or its HTML element ID. If null or undefined, the current reference is cleared.
441
+ * @param skip_events If true, events on the previous canvas will not be removed. Has no effect on the first invocation.
442
+ */
443
+ setCanvas(canvas: string | HTMLCanvasElement, skip_events?: boolean): void;
444
+ /** Captures an event and prevents default - returns false. */
445
+ _doNothing(e: Event): boolean;
446
+ /** Captures an event and prevents default - returns true. */
447
+ _doReturnTrue(e: Event): boolean;
448
+ /**
449
+ * binds mouse, keyboard, touch and drag events to the canvas
450
+ */
451
+ bindEvents(): void;
452
+ /**
453
+ * unbinds mouse events from the canvas
454
+ */
455
+ unbindEvents(): void;
456
+ /**
457
+ * Ensures the canvas will be redrawn on the next frame by setting the dirty flag(s).
458
+ * Without parameters, this function does nothing.
459
+ * @todo Impl. `setDirty()` or similar as shorthand to redraw everything.
460
+ * @param fgcanvas If true, marks the foreground canvas as dirty (nodes and anything drawn on top of them). Default: false
461
+ * @param bgcanvas If true, mark the background canvas as dirty (background, groups, links). Default: false
462
+ */
463
+ setDirty(fgcanvas: boolean, bgcanvas?: boolean): void;
464
+ /**
465
+ * Used to attach the canvas in a popup
466
+ * @returns returns the window where the canvas is attached (the DOM root node)
467
+ */
468
+ getCanvasWindow(): Window;
469
+ /**
470
+ * starts rendering the content of the canvas when needed
471
+ *
472
+ */
473
+ startRendering(): void;
474
+ /**
475
+ * stops rendering the content of the canvas (to save resources)
476
+ *
477
+ */
478
+ stopRendering(): void;
479
+ blockClick(): void;
480
+ /**
481
+ * Gets the widget at the current cursor position.
482
+ * @param node Optional node to check for widgets under cursor
483
+ * @returns The widget located at the current cursor position, if any is found.
484
+ * @deprecated Use {@link LGraphNode.getWidgetOnPos} instead.
485
+ * ```ts
486
+ * const [x, y] = canvas.graph_mouse
487
+ * const widget = canvas.node_over?.getWidgetOnPos(x, y, true)
488
+ * ```
489
+ */
490
+ getWidgetAtCursor(node?: LGraphNode): IBaseWidget | undefined;
491
+ /**
492
+ * Clears highlight and mouse-over information from nodes that should not have it.
493
+ *
494
+ * Intended to be called when the pointer moves away from a node.
495
+ * @param node The node that the mouse is now over
496
+ * @param e MouseEvent that is triggering this
497
+ */
498
+ updateMouseOverNodes(node: LGraphNode | null, e: CanvasPointerEvent): void;
499
+ processMouseDown(e: PointerEvent): void;
500
+ /**
501
+ * Called when a mouse move event has to be processed
502
+ */
503
+ processMouseMove(e: PointerEvent): void;
504
+ /**
505
+ * Called when a mouse up event has to be processed
506
+ */
507
+ processMouseUp(e: PointerEvent): void;
508
+ /**
509
+ * Called when the mouse moves off the canvas. Clears all node hover states.
510
+ * @param e
511
+ */
512
+ processMouseOut(e: PointerEvent): void;
513
+ processMouseCancel(): void;
514
+ /**
515
+ * Called when a mouse wheel event has to be processed
516
+ */
517
+ processMouseWheel(e: WheelEvent): void;
518
+ /**
519
+ * process a key event
520
+ */
521
+ processKey(e: KeyboardEvent): void;
522
+ /**
523
+ * Copies canvas items to an internal, app-specific clipboard backed by local storage.
524
+ * When called without parameters, it copies {@link selectedItems}.
525
+ * @param items The items to copy. If nullish, all selected items are copied.
526
+ */
527
+ copyToClipboard(items?: Iterable<Positionable>): void;
528
+ emitEvent(detail: LGraphCanvasEventMap["litegraph:canvas"]): void;
529
+ /** @todo Refactor to where it belongs - e.g. Deleting / creating nodes is not actually canvas event. */
530
+ emitBeforeChange(): void;
531
+ /** @todo See {@link emitBeforeChange} */
532
+ emitAfterChange(): void;
533
+ /**
534
+ * Pastes the items from the canvas "clipbaord" - a local storage variable.
535
+ */
536
+ _pasteFromClipboard(options?: IPasteFromClipboardOptions): ClipboardPasteResult | undefined;
537
+ pasteFromClipboard(options?: IPasteFromClipboardOptions): void;
538
+ processNodeDblClicked(n: LGraphNode): void;
539
+ /**
540
+ * Determines whether to select or deselect an item that has received a pointer event. Will deselect other nodes if
541
+ * @param item Canvas item to select/deselect
542
+ * @param e The MouseEvent to handle
543
+ * @param sticky Prevents deselecting individual nodes (as used by aux/right-click)
544
+ * @remarks
545
+ * Accessibility: anyone using {@link mutli_select} always deselects when clicking empty space.
546
+ */
547
+ processSelect<TPositionable extends Positionable = LGraphNode>(item: TPositionable | null | undefined, e: CanvasPointerEvent | undefined, sticky?: boolean): void;
548
+ /**
549
+ * Selects a {@link Positionable} item.
550
+ * @param item The canvas item to add to the selection.
551
+ */
552
+ select<TPositionable extends Positionable = LGraphNode>(item: TPositionable): void;
553
+ /**
554
+ * Deselects a {@link Positionable} item.
555
+ * @param item The canvas item to remove from the selection.
556
+ */
557
+ deselect<TPositionable extends Positionable = LGraphNode>(item: TPositionable): void;
558
+ /** @deprecated See {@link LGraphCanvas.processSelect} */
559
+ processNodeSelected(item: LGraphNode, e: CanvasPointerEvent): void;
560
+ /** @deprecated See {@link LGraphCanvas.select} */
561
+ selectNode(node: LGraphNode, add_to_current_selection?: boolean): void;
562
+ get empty(): boolean;
563
+ get positionableItems(): Generator<LGraphNode | Reroute | LGraphGroup, any, any>;
564
+ /**
565
+ * Selects several items.
566
+ * @param items Items to select - if falsy, all items on the canvas will be selected
567
+ * @param add_to_current_selection If set, the items will be added to the current selection instead of replacing it
568
+ */
569
+ selectItems(items?: Positionable[], add_to_current_selection?: boolean): void;
570
+ /**
571
+ * selects several nodes (or adds them to the current selection)
572
+ * @deprecated See {@link LGraphCanvas.selectItems}
573
+ */
574
+ selectNodes(nodes?: LGraphNode[], add_to_current_selection?: boolean): void;
575
+ /** @deprecated See {@link LGraphCanvas.deselect} */
576
+ deselectNode(node: LGraphNode): void;
577
+ /**
578
+ * Deselects all items on the canvas.
579
+ * @param keepSelected If set, this item will not be removed from the selection.
580
+ */
581
+ deselectAll(keepSelected?: Positionable): void;
582
+ /** @deprecated See {@link LGraphCanvas.deselectAll} */
583
+ deselectAllNodes(): void;
584
+ /**
585
+ * Deletes all selected items from the graph.
586
+ * @todo Refactor deletion task to LGraph. Selection is a canvas property, delete is a graph action.
587
+ */
588
+ deleteSelected(): void;
589
+ /**
590
+ * deletes all nodes in the current selection from the graph
591
+ * @deprecated See {@link LGraphCanvas.deleteSelected}
592
+ */
593
+ deleteSelectedNodes(): void;
594
+ /**
595
+ * centers the camera on a given node
596
+ */
597
+ centerOnNode(node: LGraphNode): void;
598
+ /**
599
+ * adds some useful properties to a mouse event, like the position in graph coordinates
600
+ */
601
+ adjustMouseEvent<T extends MouseEvent>(e: T & Partial<CanvasPointerExtensions>): asserts e is T & CanvasPointerEvent;
602
+ /**
603
+ * changes the zoom level of the graph (default is 1), you can pass also a place used to pivot the zoom
604
+ */
605
+ setZoom(value: number, zooming_center: Point): void;
606
+ /**
607
+ * converts a coordinate from graph coordinates to canvas2D coordinates
608
+ */
609
+ convertOffsetToCanvas(pos: Point, out: Point): Point;
610
+ /**
611
+ * converts a coordinate from Canvas2D coordinates to graph space
612
+ */
613
+ convertCanvasToOffset(pos: Point, out?: Point): Point;
614
+ convertEventToCanvasOffset(e: MouseEvent): Point;
615
+ /**
616
+ * brings a node to front (above all other nodes)
617
+ */
618
+ bringToFront(node: LGraphNode): void;
619
+ /**
620
+ * sends a node to the back (below all other nodes)
621
+ */
622
+ sendToBack(node: LGraphNode): void;
623
+ /**
624
+ * Determines which nodes are visible and populates {@link out} with the results.
625
+ * @param nodes The list of nodes to check - if falsy, all nodes in the graph will be checked
626
+ * @param out Array to write visible nodes into - if falsy, a new array is created instead
627
+ * @returns Array passed ({@link out}), or a new array containing all visible nodes
628
+ */
629
+ computeVisibleNodes(nodes?: LGraphNode[], out?: LGraphNode[]): LGraphNode[];
630
+ /**
631
+ * Checks if a node is visible on the canvas.
632
+ * @param node The node to check
633
+ * @returns `true` if the node is visible, otherwise `false`
634
+ */
635
+ isNodeVisible(node: LGraphNode): boolean;
636
+ /**
637
+ * renders the whole canvas content, by rendering in two separated canvas, one containing the background grid and the connections, and one containing the nodes)
638
+ */
639
+ draw(force_canvas?: boolean, force_bgcanvas?: boolean): void;
640
+ /**
641
+ * draws the front canvas (the one containing all the nodes)
642
+ */
643
+ drawFrontCanvas(): void;
644
+ /**
645
+ * draws some useful stats in the corner of the canvas
646
+ */
647
+ renderInfo(ctx: CanvasRenderingContext2D, x: number, y: number): void;
648
+ /**
649
+ * draws the back canvas (the one containing the background and the connections)
650
+ */
651
+ drawBackCanvas(): void;
652
+ /**
653
+ * draws the given node inside the canvas
654
+ */
655
+ drawNode(node: LGraphNode, ctx: CanvasRenderingContext2D): void;
656
+ /**
657
+ * Draws the link mouseover effect and tooltip.
658
+ * @param ctx Canvas 2D context to draw on
659
+ * @param link The link to render the mouseover effect for
660
+ * @remarks
661
+ * Called against {@link LGraphCanvas.over_link_center}.
662
+ * @todo Split tooltip from hover, so it can be drawn / eased separately
663
+ */
664
+ drawLinkTooltip(ctx: CanvasRenderingContext2D, link: LinkSegment): void;
665
+ /**
666
+ * Draws the shape of the given node on the canvas
667
+ * @param node The node to draw
668
+ * @param ctx 2D canvas rendering context used to draw
669
+ * @param size Size of the background to draw, in graph units. Differs from node size if collapsed, etc.
670
+ * @param fgcolor Foreground colour - used for text
671
+ * @param bgcolor Background colour of the node
672
+ * @param _selected Whether to render the node as selected. Likely to be removed in future, as current usage is simply the selected property of the node.
673
+ */
674
+ drawNodeShape(node: LGraphNode, ctx: CanvasRenderingContext2D, size: Size, fgcolor: CanvasColour, bgcolor: CanvasColour, _selected: boolean): void;
675
+ /**
676
+ * Draws a snap guide for a {@link Positionable} item.
677
+ *
678
+ * Initial design was a simple white rectangle representing the location the
679
+ * item would land if dropped.
680
+ * @param ctx The 2D canvas context to draw on
681
+ * @param item The item to draw a snap guide for
682
+ * @param shape The shape of the snap guide to draw
683
+ * @todo Update to align snapping with boundingRect
684
+ * @todo Shapes
685
+ */
686
+ drawSnapGuide(ctx: CanvasRenderingContext2D, item: Positionable, shape?: RenderShape): void;
687
+ drawConnections(ctx: CanvasRenderingContext2D): void;
688
+ /**
689
+ * draws a link between two points
690
+ * @param ctx Canvas 2D rendering context
691
+ * @param a start pos
692
+ * @param b end pos
693
+ * @param link the link object with all the link info
694
+ * @param skip_border ignore the shadow of the link
695
+ * @param flow show flow animation (for events)
696
+ * @param color the color for the link
697
+ * @param start_dir the direction enum
698
+ * @param end_dir the direction enum
699
+ */
700
+ renderLink(ctx: CanvasRenderingContext2D, a: ReadOnlyPoint, b: ReadOnlyPoint, link: LLink | null, skip_border: boolean, flow: number | null, color: CanvasColour | null, start_dir: LinkDirection, end_dir: LinkDirection, { startControl, endControl, reroute, num_sublines, disabled, }?: {
701
+ /** When defined, render data will be saved to this reroute instead of the {@link link}. */
702
+ reroute?: Reroute;
703
+ /** Offset of the bezier curve control point from {@link a point a} (output side) */
704
+ startControl?: ReadOnlyPoint;
705
+ /** Offset of the bezier curve control point from {@link b point b} (input side) */
706
+ endControl?: ReadOnlyPoint;
707
+ /** Number of sublines (useful to represent vec3 or rgb) @todo If implemented, refactor calculations out of the loop */
708
+ num_sublines?: number;
709
+ /** Whether this is a floating link segment */
710
+ disabled?: boolean;
711
+ }): void;
712
+ /**
713
+ * Finds a point along a spline represented by a to b, with spline endpoint directions dictacted by start_dir and end_dir.
714
+ * @param a Start point
715
+ * @param b End point
716
+ * @param t Time: distance between points (e.g 0.25 is 25% along the line)
717
+ * @param start_dir Spline start direction
718
+ * @param end_dir Spline end direction
719
+ * @returns The point at {@link t} distance along the spline a-b.
720
+ */
721
+ computeConnectionPoint(a: ReadOnlyPoint, b: ReadOnlyPoint, t: number, start_dir: LinkDirection, end_dir: LinkDirection): Point;
722
+ drawExecutionOrder(ctx: CanvasRenderingContext2D): void;
723
+ /**
724
+ * draws the widgets stored inside a node
725
+ * @deprecated Use {@link LGraphNode.drawWidgets} instead.
726
+ * @remarks Currently there are extensions hijacking this function, so we cannot remove it.
727
+ */
728
+ drawNodeWidgets(node: LGraphNode, _posY: null, ctx: CanvasRenderingContext2D): void;
729
+ /**
730
+ * draws every group area in the background
731
+ */
732
+ drawGroups(canvas: HTMLCanvasElement, ctx: CanvasRenderingContext2D): void;
733
+ /**
734
+ * resizes the canvas to a given size, if no size is passed, then it tries to fill the parentNode
735
+ * @todo Remove or rewrite
736
+ */
737
+ resize(width?: number, height?: number): void;
738
+ onNodeSelectionChange(): void;
739
+ /**
740
+ * Determines the furthest nodes in each direction for the currently selected nodes
741
+ */
742
+ boundaryNodesForSelection(): NullableProperties<IBoundaryNodes>;
743
+ showLinkMenu(segment: LinkSegment, e: CanvasPointerEvent): boolean;
744
+ createDefaultNodeForSlot(optPass: ICreateDefaultNodeOptions): boolean;
745
+ showConnectionMenu(optPass: Partial<ICreateNodeOptions & {
746
+ e: MouseEvent;
747
+ }>): ContextMenu<string> | undefined;
748
+ prompt(title: string, value: any, callback: (arg0: any) => void, event: CanvasPointerEvent, multiline?: boolean): HTMLDivElement;
749
+ showSearchBox(event: MouseEvent, searchOptions?: IShowSearchOptions): HTMLDivElement;
750
+ showEditPropertyValue(node: LGraphNode, property: string, options: IDialogOptions): IDialog | undefined;
751
+ createDialog(html: string, options: IDialogOptions): IDialog;
752
+ createPanel(title: string, options: ICreatePanelOptions): any;
753
+ closePanels(): void;
754
+ showShowNodePanel(node: LGraphNode): void;
755
+ checkPanels(): void;
756
+ getCanvasMenuOptions(): IContextMenuValue<string>[];
757
+ getNodeMenuOptions(node: LGraphNode): (IContextMenuValue<INodeSlotContextItem, unknown, unknown> | IContextMenuValue<string, unknown, unknown> | IContextMenuValue<string | null, unknown, unknown> | IContextMenuValue<"default" | "box" | "round" | "card", unknown, unknown> | IContextMenuValue<unknown, LGraphNode, unknown> | null)[];
758
+ /** @deprecated */
759
+ getGroupMenuOptions(group: LGraphGroup): (IContextMenuValue<string, unknown, unknown> | IContextMenuValue<string | null, unknown, unknown> | null)[];
760
+ processContextMenu(node: LGraphNode | undefined, event: CanvasPointerEvent): void;
761
+ /**
762
+ * Starts an animation to fit the view around the specified selection of nodes.
763
+ * @param bounds The bounds to animate the view to, defined by a rectangle.
764
+ */
765
+ animateToBounds(bounds: ReadOnlyRect, options?: AnimationOptions): void;
766
+ /**
767
+ * Fits the view to the selected nodes with animation.
768
+ * If nothing is selected, the view is fitted around all items in the graph.
769
+ */
770
+ fitViewToSelectionAnimated(options?: AnimationOptions): void;
771
+ }
772
+ export {};