@elicdavis/node-flow 0.1.13 → 0.1.14

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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@elicdavis/node-flow",
3
3
  "description": "build node graphs",
4
4
  "author": "Eli C Davis",
5
- "version": "0.1.13",
5
+ "version": "0.1.14",
6
6
  "license": "MIT",
7
7
  "keywords": [
8
8
  "nodes",
package/src/camera.ts CHANGED
@@ -1,5 +1,11 @@
1
1
  import { Vector2, Zero } from "./types/vector2";
2
2
 
3
+ /** Serializable camera orientation for save/restore. */
4
+ export interface CameraOrientation {
5
+ position: Vector2;
6
+ zoom: number;
7
+ }
8
+
3
9
  export class Camera {
4
10
 
5
11
  zoom: number;
@@ -22,9 +28,25 @@ export class Camera {
22
28
  out.y = this.position.y + (graphPosition.y * this.zoom);
23
29
  }
24
30
 
31
+ getOrientation(): CameraOrientation {
32
+ return {
33
+ position: {
34
+ x: this.position.x,
35
+ y: this.position.y,
36
+ },
37
+ zoom: this.zoom,
38
+ };
39
+ }
40
+
41
+ setOrientation(orientation: CameraOrientation): void {
42
+ this.position.x = orientation.position.x;
43
+ this.position.y = orientation.position.y;
44
+ this.zoom = orientation.zoom;
45
+ }
46
+
25
47
  reset(): void {
26
48
  this.zoom = 1;
27
49
  this.position.x = 0;
28
50
  this.position.y = 0;
29
51
  }
30
- }
52
+ }
package/src/graph.ts CHANGED
@@ -14,7 +14,8 @@ import { ConnectionRendererConfiguration, NodeAddedCallback, NodeRemovedCallback
14
14
  import { Connection } from './connection';
15
15
  import { Publisher } from './nodes/publisher';
16
16
  import { VectorPool } from './types/pool';
17
- import { Camera } from './camera';
17
+ import { Camera, CameraOrientation } from './camera';
18
+ export { CameraOrientation };
18
19
  import { PassSubsystem } from './pass/subsystem';
19
20
  import { QuickMenu } from './quickMenu';
20
21
 
@@ -388,6 +389,20 @@ export class NodeFlowGraph {
388
389
  return this.#mainNodeSubsystem.getSelectedNodes();
389
390
  }
390
391
 
392
+ /**
393
+ * Returns a copy of the current camera orientation (screen-space pan + zoom).
394
+ */
395
+ getCamera(): CameraOrientation {
396
+ return this.#camera.getOrientation();
397
+ }
398
+
399
+ /**
400
+ * Restores a previously saved camera orientation.
401
+ */
402
+ setCamera(orientation: CameraOrientation): void {
403
+ this.#camera.setOrientation(orientation);
404
+ }
405
+
391
406
  /**
392
407
  * Adjusts camera position and zoom so all nodes fit in view (~10% padding).
393
408
  * Falls back to camera.reset() when there are no nodes.