@cocorof/graphier 1.4.1 → 1.4.2

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.ts CHANGED
@@ -174,6 +174,19 @@ export declare type LinkEventHandler = (link: GraphLink) => void;
174
174
 
175
175
  export declare const minimal: ThemeConfig;
176
176
 
177
+ export declare interface NavigationConfig {
178
+ /** What left-drag does (default: "rotate" in 3D, "pan" in 2D) */
179
+ leftButton?: "rotate" | "pan";
180
+ /** What right-drag does (default: "pan" in 3D, "rotate" in 2D) */
181
+ rightButton?: "rotate" | "pan";
182
+ /**
183
+ * Keyboard scheme — "pan": arrows/WASD pan + z/x zoom; "fly": thrust
184
+ * flight; "orbit": orbit around target; "off": disabled.
185
+ * (default: cameraMode in 3D, "pan" in 2D)
186
+ */
187
+ keyboard?: "fly" | "orbit" | "pan" | "off";
188
+ }
189
+
177
190
  export declare const neon: ThemeConfig;
178
191
 
179
192
  export declare const NetworkGraph3D: ForwardRefExoticComponent<NetworkGraph3DProps & RefAttributes<NetworkGraph3DRef>>;
@@ -341,6 +354,12 @@ export declare interface RendererConfig {
341
354
  * - "orbit": z/x zoom, arrow keys orbit around target
342
355
  */
343
356
  cameraMode?: "fly" | "orbit";
357
+ /**
358
+ * Pointer/keyboard navigation overrides. Defaults depend on layout
359
+ * dimensionality — 3D: left=rotate, right=pan, keyboard=cameraMode;
360
+ * 2D: left=pan, right=rotate, keyboard="pan".
361
+ */
362
+ navigation?: NavigationConfig;
344
363
  }
345
364
 
346
365
  export declare interface ResolvedTheme {
package/dist/index.js CHANGED
@@ -2266,34 +2266,38 @@ function createScene(container, backgroundColor, style, rendererConfig) {
2266
2266
  flags
2267
2267
  };
2268
2268
  }
2269
- function applyCameraMode2D(state, is2D) {
2269
+ const MOUSE_ACTION = {
2270
+ rotate: THREE.MOUSE.ROTATE,
2271
+ pan: THREE.MOUSE.PAN
2272
+ };
2273
+ function applyNavigationMode(state, is2D, nav) {
2270
2274
  const { controls, camera, keyboard } = state;
2271
2275
  state.flags.is2D = is2D;
2272
- controls.enableRotate = true;
2276
+ const left = (nav == null ? void 0 : nav.leftButton) ?? (is2D ? "pan" : "rotate");
2277
+ const right = (nav == null ? void 0 : nav.rightButton) ?? (is2D ? "rotate" : "pan");
2278
+ controls.mouseButtons = {
2279
+ LEFT: MOUSE_ACTION[left],
2280
+ MIDDLE: THREE.MOUSE.DOLLY,
2281
+ RIGHT: MOUSE_ACTION[right]
2282
+ };
2283
+ controls.enableRotate = left === "rotate" || right === "rotate";
2284
+ controls.touches = left === "pan" ? { ONE: THREE.TOUCH.PAN, TWO: THREE.TOUCH.DOLLY_PAN } : { ONE: THREE.TOUCH.ROTATE, TWO: THREE.TOUCH.DOLLY_PAN };
2273
2285
  controls.enableZoom = is2D;
2274
2286
  controls.screenSpacePanning = is2D;
2275
- keyboard.setEnabled(true);
2276
- keyboard.setMode(is2D ? "pan" : state.flags.keyboardMode3D);
2287
+ const kb = (nav == null ? void 0 : nav.keyboard) ?? (is2D ? "pan" : state.flags.keyboardMode3D);
2288
+ if (kb === "off") {
2289
+ keyboard.setEnabled(false);
2290
+ } else {
2291
+ keyboard.setEnabled(true);
2292
+ keyboard.setMode(kb);
2293
+ }
2277
2294
  if (is2D) {
2278
- controls.mouseButtons = {
2279
- LEFT: THREE.MOUSE.PAN,
2280
- MIDDLE: THREE.MOUSE.DOLLY,
2281
- RIGHT: THREE.MOUSE.ROTATE
2282
- };
2283
- controls.touches = { ONE: THREE.TOUCH.PAN, TWO: THREE.TOUCH.DOLLY_PAN };
2284
2295
  const t = controls.target;
2285
2296
  const dist = Math.max(camera.position.distanceTo(t), 50);
2286
2297
  t.z = 0;
2287
2298
  camera.up.set(0, 1, 0);
2288
2299
  camera.position.set(t.x, t.y, dist);
2289
2300
  camera.lookAt(t);
2290
- } else {
2291
- controls.mouseButtons = {
2292
- LEFT: THREE.MOUSE.ROTATE,
2293
- MIDDLE: THREE.MOUSE.DOLLY,
2294
- RIGHT: THREE.MOUSE.PAN
2295
- };
2296
- controls.touches = { ONE: THREE.TOUCH.ROTATE, TWO: THREE.TOUCH.DOLLY_PAN };
2297
2301
  }
2298
2302
  controls.update();
2299
2303
  }
@@ -3500,10 +3504,11 @@ function NetworkGraph3DInner(props, ref) {
3500
3504
  );
3501
3505
  }
3502
3506
  }, [visibleSet, linkVisibility, mergedData]);
3507
+ const navKey = JSON.stringify((rendererProp == null ? void 0 : rendererProp.navigation) ?? null);
3503
3508
  useEffect(() => {
3504
3509
  const s = sceneRef.current;
3505
- if (s) applyCameraMode2D(s, is2D);
3506
- }, [is2D]);
3510
+ if (s) applyNavigationMode(s, is2D, rendererProp == null ? void 0 : rendererProp.navigation);
3511
+ }, [is2D, navKey]);
3507
3512
  useEffect(() => {
3508
3513
  const gObj = graphObjRef.current;
3509
3514
  const sceneState = sceneRef.current;
@@ -3755,11 +3760,12 @@ function NetworkGraph3DInner(props, ref) {
3755
3760
  const s = sceneRef.current;
3756
3761
  if (!s) return null;
3757
3762
  const cam = s.camera;
3758
- const dist = Math.abs(cam.position.z);
3763
+ const t = s.controls.target;
3764
+ const dist = Math.max(cam.position.distanceTo(t), 1);
3759
3765
  const halfH = Math.tan(cam.fov * Math.PI / 360) * dist;
3760
3766
  return {
3761
- cx: cam.position.x,
3762
- cy: cam.position.y,
3767
+ cx: t.x,
3768
+ cy: t.y,
3763
3769
  halfW: halfH * cam.aspect,
3764
3770
  halfH
3765
3771
  };