@elicdavis/node-flow 0.1.14 → 0.1.15

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.
package/dist/index.d.mts CHANGED
@@ -44,12 +44,19 @@ interface ContextMenuConfig {
44
44
  items?: Array<ContextMenuItemConfig>;
45
45
  }
46
46
 
47
+ /** Serializable camera orientation for save/restore. */
48
+ interface CameraOrientation {
49
+ position: Vector2;
50
+ zoom: number;
51
+ }
47
52
  declare class Camera {
48
53
  zoom: number;
49
54
  position: Vector2;
50
55
  constructor();
51
56
  screenSpaceToGraphSpace(screenPosition: Vector2, out: Vector2): void;
52
57
  graphSpaceToScreenSpace(graphPosition: Vector2, out: Vector2): void;
58
+ getOrientation(): CameraOrientation;
59
+ setOrientation(orientation: CameraOrientation): void;
53
60
  reset(): void;
54
61
  }
55
62
 
@@ -505,6 +512,18 @@ declare class NodeFlowGraph {
505
512
  * state used by Ctrl+click and box-select styling via FlowNode.selected()).
506
513
  */
507
514
  getSelectedNodes(): Array<FlowNode>;
515
+ /**
516
+ * Returns a copy of the current camera orientation (screen-space pan + zoom).
517
+ */
518
+ getCamera(): CameraOrientation;
519
+ /**
520
+ * Restores a previously saved camera orientation.
521
+ */
522
+ setCamera(orientation: CameraOrientation): void;
523
+ /**
524
+ * Resets the camera to the default orientation (origin, zoom 1).
525
+ */
526
+ resetCamera(): void;
508
527
  /**
509
528
  * Adjusts camera position and zoom so all nodes fit in view (~10% padding).
510
529
  * Falls back to camera.reset() when there are no nodes.
@@ -828,4 +847,4 @@ declare class WidgetFactory {
828
847
  }
829
848
  declare const GlobalWidgetFactory: WidgetFactory;
830
849
 
831
- export { ButtonWidget, ColorWidget, type ContextMenuConfig, type ContextMenuItemConfig, ContextMenuItemState, FlowNode, type FlowNodeConfig, type FlowNodeGraphConfiguration, type FlowNodeStyle, type FlowNodeTitleConfig, FlowNote, type FlowNoteConfig, GlobalWidgetFactory, type GraphRenderer, ImageWidget, MessageType, NodeFlowGraph, type NodeIntersection, type NodeMessageConfig, NodeState, type NoteAddedCallback, type NoteContentChangeCallback, type NoteDragStartCallback, type NoteDragStopCallback, type NoteRemovedCallback, type NoteSubsystemConfig, type NoteWidthChangeCallback, NumberWidget, Publisher, type PublisherConfig, SliderWidget, StringWidget, TextWidget, Theme, ToggleWidget, type WidgetConfig };
850
+ export { ButtonWidget, type CameraOrientation, ColorWidget, type ContextMenuConfig, type ContextMenuItemConfig, ContextMenuItemState, FlowNode, type FlowNodeConfig, type FlowNodeGraphConfiguration, type FlowNodeStyle, type FlowNodeTitleConfig, FlowNote, type FlowNoteConfig, GlobalWidgetFactory, type GraphRenderer, ImageWidget, MessageType, NodeFlowGraph, type NodeIntersection, type NodeMessageConfig, NodeState, type NoteAddedCallback, type NoteContentChangeCallback, type NoteDragStartCallback, type NoteDragStopCallback, type NoteRemovedCallback, type NoteSubsystemConfig, type NoteWidthChangeCallback, NumberWidget, Publisher, type PublisherConfig, SliderWidget, StringWidget, TextWidget, Theme, ToggleWidget, type WidgetConfig };
package/dist/index.d.ts CHANGED
@@ -44,12 +44,19 @@ interface ContextMenuConfig {
44
44
  items?: Array<ContextMenuItemConfig>;
45
45
  }
46
46
 
47
+ /** Serializable camera orientation for save/restore. */
48
+ interface CameraOrientation {
49
+ position: Vector2;
50
+ zoom: number;
51
+ }
47
52
  declare class Camera {
48
53
  zoom: number;
49
54
  position: Vector2;
50
55
  constructor();
51
56
  screenSpaceToGraphSpace(screenPosition: Vector2, out: Vector2): void;
52
57
  graphSpaceToScreenSpace(graphPosition: Vector2, out: Vector2): void;
58
+ getOrientation(): CameraOrientation;
59
+ setOrientation(orientation: CameraOrientation): void;
53
60
  reset(): void;
54
61
  }
55
62
 
@@ -505,6 +512,18 @@ declare class NodeFlowGraph {
505
512
  * state used by Ctrl+click and box-select styling via FlowNode.selected()).
506
513
  */
507
514
  getSelectedNodes(): Array<FlowNode>;
515
+ /**
516
+ * Returns a copy of the current camera orientation (screen-space pan + zoom).
517
+ */
518
+ getCamera(): CameraOrientation;
519
+ /**
520
+ * Restores a previously saved camera orientation.
521
+ */
522
+ setCamera(orientation: CameraOrientation): void;
523
+ /**
524
+ * Resets the camera to the default orientation (origin, zoom 1).
525
+ */
526
+ resetCamera(): void;
508
527
  /**
509
528
  * Adjusts camera position and zoom so all nodes fit in view (~10% padding).
510
529
  * Falls back to camera.reset() when there are no nodes.
@@ -828,4 +847,4 @@ declare class WidgetFactory {
828
847
  }
829
848
  declare const GlobalWidgetFactory: WidgetFactory;
830
849
 
831
- export { ButtonWidget, ColorWidget, type ContextMenuConfig, type ContextMenuItemConfig, ContextMenuItemState, FlowNode, type FlowNodeConfig, type FlowNodeGraphConfiguration, type FlowNodeStyle, type FlowNodeTitleConfig, FlowNote, type FlowNoteConfig, GlobalWidgetFactory, type GraphRenderer, ImageWidget, MessageType, NodeFlowGraph, type NodeIntersection, type NodeMessageConfig, NodeState, type NoteAddedCallback, type NoteContentChangeCallback, type NoteDragStartCallback, type NoteDragStopCallback, type NoteRemovedCallback, type NoteSubsystemConfig, type NoteWidthChangeCallback, NumberWidget, Publisher, type PublisherConfig, SliderWidget, StringWidget, TextWidget, Theme, ToggleWidget, type WidgetConfig };
850
+ export { ButtonWidget, type CameraOrientation, ColorWidget, type ContextMenuConfig, type ContextMenuItemConfig, ContextMenuItemState, FlowNode, type FlowNodeConfig, type FlowNodeGraphConfiguration, type FlowNodeStyle, type FlowNodeTitleConfig, FlowNote, type FlowNoteConfig, GlobalWidgetFactory, type GraphRenderer, ImageWidget, MessageType, NodeFlowGraph, type NodeIntersection, type NodeMessageConfig, NodeState, type NoteAddedCallback, type NoteContentChangeCallback, type NoteDragStartCallback, type NoteDragStopCallback, type NoteRemovedCallback, type NoteSubsystemConfig, type NoteWidthChangeCallback, NumberWidget, Publisher, type PublisherConfig, SliderWidget, StringWidget, TextWidget, Theme, ToggleWidget, type WidgetConfig };
package/dist/index.js CHANGED
@@ -3133,6 +3133,20 @@ var Camera = class {
3133
3133
  out.x = this.position.x + graphPosition.x * this.zoom;
3134
3134
  out.y = this.position.y + graphPosition.y * this.zoom;
3135
3135
  }
3136
+ getOrientation() {
3137
+ return {
3138
+ position: {
3139
+ x: this.position.x,
3140
+ y: this.position.y
3141
+ },
3142
+ zoom: this.zoom
3143
+ };
3144
+ }
3145
+ setOrientation(orientation) {
3146
+ this.position.x = orientation.position.x;
3147
+ this.position.y = orientation.position.y;
3148
+ this.zoom = orientation.zoom;
3149
+ }
3136
3150
  reset() {
3137
3151
  this.zoom = 1;
3138
3152
  this.position.x = 0;
@@ -4563,44 +4577,42 @@ var FlowNode = class {
4563
4577
  // }
4564
4578
  calculateBounds(ctx, camera) {
4565
4579
  const tempMeasurement = Zero();
4566
- const zoom = camera.zoom;
4567
- const scaledPadding = __privateGet(this, _padding2) * zoom;
4568
- const doubleScaledPadding = scaledPadding * 2;
4569
- const scaledElementSpacing = __privateGet(this, _elementSpacing) * zoom;
4580
+ const doublePadding = __privateGet(this, _padding2) * 2;
4570
4581
  const screenSpacePosition = Zero();
4571
4582
  camera.graphSpaceToScreenSpace(__privateGet(this, _position), screenSpacePosition);
4572
4583
  const size = Zero();
4573
- __privateGet(this, _title2).size(ctx, zoom, size);
4584
+ __privateGet(this, _title2).size(ctx, 1, size);
4574
4585
  const subtitleSize = Zero();
4575
- __privateGet(this, _subTitle).size(ctx, zoom, subtitleSize);
4586
+ __privateGet(this, _subTitle).size(ctx, 1, subtitleSize);
4576
4587
  size.x = Math.max(size.x, subtitleSize.x);
4577
4588
  if (__privateGet(this, _infoText) !== "") {
4578
4589
  size.x += size.y * 4;
4579
4590
  }
4580
- size.x += doubleScaledPadding;
4581
- size.y += doubleScaledPadding + scaledElementSpacing * __privateGet(this, _input).length;
4591
+ size.x += doublePadding;
4592
+ size.y += doublePadding + __privateGet(this, _elementSpacing) * __privateGet(this, _input).length;
4582
4593
  for (let i = 0; i < __privateGet(this, _input).length; i++) {
4583
4594
  const port = __privateGet(this, _input)[i];
4584
- __privateGet(this, _portTextStyle).measure(ctx, zoom, port.getDisplayName(), tempMeasurement);
4595
+ __privateGet(this, _portTextStyle).measure(ctx, 1, port.getDisplayName(), tempMeasurement);
4585
4596
  size.y += tempMeasurement.y;
4586
- size.x = Math.max(size.x, tempMeasurement.x + doubleScaledPadding);
4597
+ size.x = Math.max(size.x, tempMeasurement.x + doublePadding);
4587
4598
  }
4588
- size.y += scaledElementSpacing * __privateGet(this, _output).length;
4599
+ size.y += __privateGet(this, _elementSpacing) * __privateGet(this, _output).length;
4589
4600
  for (let i = 0; i < __privateGet(this, _output).length; i++) {
4590
4601
  const port = __privateGet(this, _output)[i];
4591
- __privateGet(this, _portTextStyle).measure(ctx, zoom, port.getDisplayName(), tempMeasurement);
4602
+ __privateGet(this, _portTextStyle).measure(ctx, 1, port.getDisplayName(), tempMeasurement);
4592
4603
  size.y += tempMeasurement.y;
4593
- size.x = Math.max(size.x, tempMeasurement.x + doubleScaledPadding);
4604
+ size.x = Math.max(size.x, tempMeasurement.x + doublePadding);
4594
4605
  }
4595
- size.y += scaledElementSpacing * __privateGet(this, _widgets).length;
4606
+ size.y += __privateGet(this, _elementSpacing) * __privateGet(this, _widgets).length;
4596
4607
  for (let i = 0; i < __privateGet(this, _widgets).length; i++) {
4597
4608
  const element = __privateGet(this, _widgets)[i];
4598
4609
  const eleSize = element.Size();
4599
- size.y += eleSize.y * zoom;
4600
- size.x = Math.max(size.x, eleSize.x * zoom + doubleScaledPadding);
4610
+ size.y += eleSize.y;
4611
+ size.x = Math.max(size.x, eleSize.x + doublePadding);
4601
4612
  }
4602
- size.y += scaledElementSpacing;
4603
- size.x = Math.max(size.x, MINIMUM_NODE_WIDTH * zoom);
4613
+ size.y += __privateGet(this, _elementSpacing);
4614
+ size.x = Math.max(size.x, MINIMUM_NODE_WIDTH);
4615
+ ScaleVector(size, camera.zoom);
4604
4616
  return {
4605
4617
  Position: screenSpacePosition,
4606
4618
  Size: size
@@ -4832,27 +4844,29 @@ var FlowNode = class {
4832
4844
  for (let i = 0; i < __privateGet(this, _input).length; i++) {
4833
4845
  ctx.textAlign = "left" /* Left */;
4834
4846
  const port = __privateGet(this, _input)[i];
4835
- __privateGet(this, _portTextStyle).measure(ctx, camera.zoom, port.getDisplayName(), tempMeasurement);
4847
+ __privateGet(this, _portTextStyle).measure(ctx, 1, port.getDisplayName(), tempMeasurement);
4848
+ const portHeight = tempMeasurement.y * camera.zoom;
4836
4849
  const position = VectorPool.get();
4837
4850
  position.x = nodeBounds.Position.x;
4838
- position.y = startY + tempMeasurement.y / 2;
4851
+ position.y = startY + portHeight / 2;
4839
4852
  __privateGet(this, _portTextStyle).setupStyle(ctx, camera.zoom);
4840
4853
  ctx.fillText(port.getDisplayName(), leftSide, position.y);
4841
4854
  __privateGet(this, _inputPortPositions).Push(port.render(ctx, position, camera, mousePosition, postProcess));
4842
- startY += tempMeasurement.y + scaledElementSpacing;
4855
+ startY += portHeight + scaledElementSpacing;
4843
4856
  }
4844
4857
  const rightSide = nodeBounds.Position.x + nodeBounds.Size.x;
4845
4858
  ctx.textAlign = "right" /* Right */;
4846
4859
  for (let i = 0; i < __privateGet(this, _output).length; i++) {
4847
4860
  const port = __privateGet(this, _output)[i];
4848
- __privateGet(this, _portTextStyle).measure(ctx, camera.zoom, port.getDisplayName(), tempMeasurement);
4861
+ __privateGet(this, _portTextStyle).measure(ctx, 1, port.getDisplayName(), tempMeasurement);
4862
+ const portHeight = tempMeasurement.y * camera.zoom;
4849
4863
  const position = VectorPool.get();
4850
4864
  position.x = rightSide;
4851
- position.y = startY + tempMeasurement.y / 2;
4865
+ position.y = startY + portHeight / 2;
4852
4866
  __privateGet(this, _portTextStyle).setupStyle(ctx, camera.zoom);
4853
4867
  ctx.fillText(port.getDisplayName(), rightSide - scaledPadding, position.y);
4854
4868
  __privateGet(this, _outputPortPositions).Push(port.render(ctx, position, camera, mousePosition, postProcess));
4855
- startY += tempMeasurement.y + scaledElementSpacing;
4869
+ startY += portHeight + scaledElementSpacing;
4856
4870
  }
4857
4871
  for (let i = 0; i < __privateGet(this, _widgets).length; i++) {
4858
4872
  const widget = __privateGet(this, _widgets)[i];
@@ -6681,6 +6695,24 @@ var NodeFlowGraph = class {
6681
6695
  getSelectedNodes() {
6682
6696
  return __privateGet(this, _mainNodeSubsystem).getSelectedNodes();
6683
6697
  }
6698
+ /**
6699
+ * Returns a copy of the current camera orientation (screen-space pan + zoom).
6700
+ */
6701
+ getCamera() {
6702
+ return __privateGet(this, _camera).getOrientation();
6703
+ }
6704
+ /**
6705
+ * Restores a previously saved camera orientation.
6706
+ */
6707
+ setCamera(orientation) {
6708
+ __privateGet(this, _camera).setOrientation(orientation);
6709
+ }
6710
+ /**
6711
+ * Resets the camera to the default orientation (origin, zoom 1).
6712
+ */
6713
+ resetCamera() {
6714
+ __privateGet(this, _camera).reset();
6715
+ }
6684
6716
  /**
6685
6717
  * Adjusts camera position and zoom so all nodes fit in view (~10% padding).
6686
6718
  * Falls back to camera.reset() when there are no nodes.