@cjlapao/ui-kit 0.2.45 → 0.2.46

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.js CHANGED
@@ -83024,6 +83024,10 @@ function KnowledgeMap({
83024
83024
  hoverHighlight = true,
83025
83025
  grid = true,
83026
83026
  gridTone = "blue",
83027
+ autoRevealSelected = true,
83028
+ autoCenterSelected = true,
83029
+ autoFitOnInspector = false,
83030
+ onViewportChange,
83027
83031
  size: controlSize = "sm",
83028
83032
  controlsTone = "auto",
83029
83033
  onDiagnostics,
@@ -83095,16 +83099,7 @@ function KnowledgeMap({
83095
83099
  useEffect91(() => {
83096
83100
  onDiagnostics?.(geometry.diagnostics);
83097
83101
  }, [geometry.diagnostics, onDiagnostics]);
83098
- useEffect91(() => {
83099
- const host = hostRef.current;
83100
- if (!host) return;
83101
- const update = () => setSize({ width: Math.max(1, host.clientWidth), height: Math.max(120, height) });
83102
- update();
83103
- if (typeof ResizeObserver === "undefined") return;
83104
- const observer = new ResizeObserver(update);
83105
- observer.observe(host);
83106
- return () => observer.disconnect();
83107
- }, [height]);
83102
+ const sizeRef = useRef97(size);
83108
83103
  const bounds = useMemo73(() => {
83109
83104
  let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity;
83110
83105
  for (const point of scene.points) {
@@ -83207,14 +83202,124 @@ function KnowledgeMap({
83207
83202
  for (let node = hostRef.current; node; node = node.parentElement) observer.observe(node, { attributes: true, attributeFilter: ["class", "data-color-scheme", "style"] });
83208
83203
  return () => observer.disconnect();
83209
83204
  }, []);
83210
- const zoom = useCallback58((factor, anchor = { x: size.width / 2, y: size.height / 2 }) => setCamera((current) => {
83211
- const next = Math.max(0.25, Math.min(24, current.zoom * factor)), scale = next / current.zoom;
83212
- return {
83213
- zoom: next,
83214
- x: anchor.x - size.width / 2 - (anchor.x - size.width / 2 - current.x) * scale,
83215
- y: anchor.y - size.height / 2 - (anchor.y - size.height / 2 - current.y) * scale
83205
+ const cameraRef = useRef97(camera);
83206
+ const commitCamera = useCallback58((next) => {
83207
+ setCamera((current) => {
83208
+ const value = typeof next === "function" ? next(current) : next;
83209
+ cameraRef.current = value;
83210
+ return value;
83211
+ });
83212
+ }, []);
83213
+ useEffect91(() => {
83214
+ onViewportChange?.({ ...camera });
83215
+ }, [camera, onViewportChange]);
83216
+ useEffect91(() => {
83217
+ const host = hostRef.current;
83218
+ if (!host) return;
83219
+ const update = () => {
83220
+ const rect = host.getBoundingClientRect();
83221
+ const next = { width: Math.max(1, rect.width), height: Math.max(120, height) };
83222
+ const prev = sizeRef.current;
83223
+ if (prev.width === next.width && prev.height === next.height) return;
83224
+ const cam = cameraRef.current;
83225
+ if (Math.abs(cam.zoom - 1) > 1e-6 && scene.points.length) {
83226
+ const fit = (w, h) => Math.max(1e-6, Math.min((w - 100) / bounds.width, (h - 100) / bounds.height, 3));
83227
+ const oldFit = fit(prev.width, prev.height), newFit = fit(next.width, next.height);
83228
+ if (oldFit !== newFit) commitCamera((current) => ({ zoom: current.zoom * (oldFit / newFit), x: current.x + (prev.width - next.width) / 2, y: current.y + (prev.height - next.height) / 2 }));
83229
+ }
83230
+ sizeRef.current = next;
83231
+ setSize(next);
83232
+ };
83233
+ update();
83234
+ if (typeof ResizeObserver === "undefined") return;
83235
+ const observer = new ResizeObserver(update);
83236
+ observer.observe(host);
83237
+ return () => observer.disconnect();
83238
+ }, [height, bounds, scene.points.length, commitCamera]);
83239
+ const panFrame = useRef97(null);
83240
+ const cancelPan = useCallback58(() => {
83241
+ if (panFrame.current !== null) {
83242
+ cancelAnimationFrame(panFrame.current);
83243
+ panFrame.current = null;
83244
+ }
83245
+ }, []);
83246
+ const animateView = useCallback58((target, onDone) => {
83247
+ cancelPan();
83248
+ const from = cameraRef.current;
83249
+ if (from.x === target.x && from.y === target.y && from.zoom === target.zoom) {
83250
+ onDone?.();
83251
+ return;
83252
+ }
83253
+ const commit = (v) => {
83254
+ cameraRef.current = v;
83255
+ setCamera(v);
83216
83256
  };
83217
- }), [size.width, size.height]);
83257
+ if (typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
83258
+ commit(target);
83259
+ onDone?.();
83260
+ return;
83261
+ }
83262
+ const start = Date.now();
83263
+ const step = () => {
83264
+ panFrame.current = requestAnimationFrame(() => {
83265
+ const t = Math.min(1, (Date.now() - start) / 300), e = 1 - Math.pow(1 - t, 3);
83266
+ commit({ x: from.x + (target.x - from.x) * e, y: from.y + (target.y - from.y) * e, zoom: from.zoom + (target.zoom - from.zoom) * e });
83267
+ if (t < 1) step();
83268
+ else {
83269
+ panFrame.current = null;
83270
+ onDone?.();
83271
+ }
83272
+ });
83273
+ };
83274
+ step();
83275
+ }, [cancelPan]);
83276
+ const revealPoint = useCallback58((point, center = false) => {
83277
+ const v = cameraRef.current, margin = 18;
83278
+ if (center) {
83279
+ animateView({ zoom: v.zoom, x: -(point.x - bounds.x) * fitZoom * v.zoom, y: -(point.y - bounds.y) * fitZoom * v.zoom });
83280
+ return;
83281
+ }
83282
+ const sx = (point.x - bounds.x) * fitZoom * v.zoom + size.width / 2 + v.x;
83283
+ const sy = (point.y - bounds.y) * fitZoom * v.zoom + size.height / 2 + v.y;
83284
+ let dx = 0, dy = 0;
83285
+ if (sx < margin) dx = margin - sx;
83286
+ else if (sx > size.width - margin) dx = size.width - margin - sx;
83287
+ if (sy < margin) dy = margin - sy;
83288
+ else if (sy > size.height - margin) dy = size.height - margin - sy;
83289
+ if (dx === 0 && dy === 0) return;
83290
+ animateView({ x: v.x + dx, y: v.y + dy, zoom: v.zoom });
83291
+ }, [animateView, bounds, fitZoom, size]);
83292
+ const zoom = useCallback58((factor, anchor = { x: size.width / 2, y: size.height / 2 }) => {
83293
+ cancelPan();
83294
+ commitCamera((current) => {
83295
+ const next = Math.max(0.25, Math.min(24, current.zoom * factor)), scale = next / current.zoom;
83296
+ return {
83297
+ zoom: next,
83298
+ x: anchor.x - size.width / 2 - (anchor.x - size.width / 2 - current.x) * scale,
83299
+ y: anchor.y - size.height / 2 - (anchor.y - size.height / 2 - current.y) * scale
83300
+ };
83301
+ });
83302
+ }, [cancelPan, commitCamera, size.width, size.height]);
83303
+ const cameraMove = useRef97({ reveal: revealPoint, fit: animateView });
83304
+ cameraMove.current = { reveal: revealPoint, fit: animateView };
83305
+ const wasSelected = useRef97(false);
83306
+ useEffect91(() => {
83307
+ const opening = !!selection && !wasSelected.current;
83308
+ wasSelected.current = !!selection;
83309
+ if (!selection || disabled || loading) return;
83310
+ if (!autoRevealSelected && !autoFitOnInspector) return;
83311
+ const positioned = scene.points.find((point) => point.memoryId === selection);
83312
+ if (!positioned) return;
83313
+ const reduced = typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
83314
+ const timer = setTimeout(() => {
83315
+ if (opening && autoFitOnInspector) cameraMove.current.fit(INITIAL_CAMERA, () => {
83316
+ if (autoRevealSelected) cameraMove.current.reveal(positioned, autoCenterSelected);
83317
+ });
83318
+ else if (autoRevealSelected) cameraMove.current.reveal(positioned, autoCenterSelected);
83319
+ }, reduced ? 0 : 260);
83320
+ return () => clearTimeout(timer);
83321
+ }, [selection, disabled, loading, autoRevealSelected, autoCenterSelected, autoFitOnInspector, scene]);
83322
+ useEffect91(() => cancelPan, [cancelPan]);
83218
83323
  useEffect91(() => {
83219
83324
  const canvas = canvasRef.current;
83220
83325
  if (!canvas) return;
@@ -83283,15 +83388,17 @@ function KnowledgeMap({
83283
83388
  "aria-describedby": helpId,
83284
83389
  onKeyDown: (event) => {
83285
83390
  if (disabled || loading) return;
83391
+ cancelPan();
83286
83392
  if (["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "+", "=", "-", "Home", "Escape"].includes(event.key)) event.preventDefault();
83287
83393
  if (event.key === "+" || event.key === "=") zoom(1.3);
83288
83394
  else if (event.key === "-") zoom(1 / 1.3);
83289
- else if (event.key === "Home") setCamera(INITIAL_CAMERA);
83395
+ else if (event.key === "Home") commitCamera(INITIAL_CAMERA);
83290
83396
  else if (event.key === "Escape") select(null);
83291
- else if (event.key.startsWith("Arrow")) setCamera((current) => ({ ...current, x: current.x + (event.key === "ArrowLeft" ? 32 : event.key === "ArrowRight" ? -32 : 0), y: current.y + (event.key === "ArrowUp" ? 32 : event.key === "ArrowDown" ? -32 : 0) }));
83397
+ else if (event.key.startsWith("Arrow")) commitCamera((current) => ({ ...current, x: current.x + (event.key === "ArrowLeft" ? 32 : event.key === "ArrowRight" ? -32 : 0), y: current.y + (event.key === "ArrowUp" ? 32 : event.key === "ArrowDown" ? -32 : 0) }));
83292
83398
  },
83293
83399
  onPointerDown: (event) => {
83294
83400
  if (disabled || loading || event.button !== 0) return;
83401
+ cancelPan();
83295
83402
  event.currentTarget.setPointerCapture?.(event.pointerId);
83296
83403
  drag.current = { x: event.clientX, y: event.clientY, camera, moved: false };
83297
83404
  },
@@ -83303,7 +83410,7 @@ function KnowledgeMap({
83303
83410
  if (Math.hypot(dx, dy) > 4) start.moved = true;
83304
83411
  if (start.moved) {
83305
83412
  setHovered(null);
83306
- setCamera({ ...start.camera, x: start.camera.x + dx, y: start.camera.y + dy });
83413
+ commitCamera({ ...start.camera, x: start.camera.x + dx, y: start.camera.y + dy });
83307
83414
  }
83308
83415
  return;
83309
83416
  }
@@ -83329,7 +83436,10 @@ function KnowledgeMap({
83329
83436
  ),
83330
83437
  !loading && !scene.points.length && /* @__PURE__ */ jsx416("p", { className: "kit-knowledge-map-empty", role: "status", children: copy("empty") }),
83331
83438
  showControls && !loading && /* @__PURE__ */ jsxs250("div", { className: "absolute bottom-3 right-3 z-10 flex items-center gap-0.5 rounded-lg border border-neutral-200 bg-white/90 p-1 shadow-sm backdrop-blur dark:border-neutral-700 dark:bg-neutral-900/90", children: [
83332
- /* @__PURE__ */ jsx416(IconButton_default, { size: "xs", variant: "ghost", color: chain.controlsTone, disabled, srLabel: copy("fit"), tooltip: copy("fit"), onClick: () => setCamera(INITIAL_CAMERA), icon: /* @__PURE__ */ jsxs250("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
83439
+ /* @__PURE__ */ jsx416(IconButton_default, { size: "xs", variant: "ghost", color: chain.controlsTone, disabled, srLabel: copy("fit"), tooltip: copy("fit"), onClick: () => {
83440
+ cancelPan();
83441
+ commitCamera(INITIAL_CAMERA);
83442
+ }, icon: /* @__PURE__ */ jsxs250("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
83333
83443
  /* @__PURE__ */ jsx416("path", { d: "M4 9V5a1 1 0 0 1 1-1h4" }),
83334
83444
  /* @__PURE__ */ jsx416("path", { d: "M15 4h4a1 1 0 0 1 1 1v4" }),
83335
83445
  /* @__PURE__ */ jsx416("path", { d: "M20 15v4a1 1 0 0 1-1 1h-4" }),
@@ -83342,8 +83452,9 @@ function KnowledgeMap({
83342
83452
  ] }),
83343
83453
  /* @__PURE__ */ jsx416(IconButton_default, { size: "xs", variant: "ghost", color: chain.controlsTone, disabled: disabled || camera.zoom >= 24, srLabel: copy("zoomIn"), tooltip: copy("zoomIn"), onClick: () => zoom(1.3), icon: "Add" }),
83344
83454
  /* @__PURE__ */ jsx416(IconButton_default, { size: "xs", variant: "ghost", color: chain.controlsTone, disabled, srLabel: copy("reset"), tooltip: copy("reset"), onClick: () => {
83455
+ cancelPan();
83345
83456
  select(null);
83346
- setCamera(INITIAL_CAMERA);
83457
+ commitCamera(INITIAL_CAMERA);
83347
83458
  }, icon: "Reset" })
83348
83459
  ] })
83349
83460
  ] }),
@@ -83373,7 +83484,6 @@ import { jsx as jsx417, jsxs as jsxs251 } from "react/jsx-runtime";
83373
83484
  var INSPECTOR_WIDTH_DEFAULT = 340;
83374
83485
  var INSPECTOR_WIDTH_MIN = 180;
83375
83486
  var INSPECTOR_WIDTH_MAX = 480;
83376
- var INSPECTOR_GAP = 16;
83377
83487
  var INSPECTOR_MIN_MAIN_WIDTH_DEFAULT = 360;
83378
83488
  function compact2(props) {
83379
83489
  return Object.fromEntries(Object.entries(props).filter(([, value]) => value !== void 0));
@@ -83438,7 +83548,7 @@ function KnowledgeExplorer({
83438
83548
  const inspectorOpen = inspectorVisible && !loading && !!selectedMemory;
83439
83549
  const gridRef = useRef98(null);
83440
83550
  const width = Math.min(INSPECTOR_WIDTH_MAX, Math.max(INSPECTOR_WIDTH_MIN, inspectorWidth ?? INSPECTOR_WIDTH_DEFAULT));
83441
- const threshold = inspectorStackBelow ?? width + INSPECTOR_GAP + (inspectorMinMainWidth ?? INSPECTOR_MIN_MAIN_WIDTH_DEFAULT);
83551
+ const threshold = inspectorStackBelow ?? (inspectorMinMainWidth ?? INSPECTOR_MIN_MAIN_WIDTH_DEFAULT);
83442
83552
  const [stacked, setStacked] = useState111(false);
83443
83553
  useEffect92(() => {
83444
83554
  const el = gridRef.current;
@@ -83928,27 +84038,33 @@ var MAX_ORBIT_AGENTS = 12;
83928
84038
  var MAX_FOCUS_AGENTS = 20;
83929
84039
  var EXPANDED_RADIUS = 164;
83930
84040
  var COLLAPSED_RADIUS = 62;
84041
+ var NARROW_BELOW_DEFAULT = 400;
84042
+ var ZOOM_MIN = 0.25;
84043
+ var ZOOM_MAX = 3;
83931
84044
  var INSPECTOR_WIDTH = 280;
83932
- var INSPECTOR_GAP2 = 16;
84045
+ var INSPECTOR_GAP = 16;
83933
84046
  var INSPECTOR_MIN_MAIN_WIDTH_DEFAULT2 = 360;
83934
84047
  var AgentMapSkeleton = ({ projects: count }) => /* @__PURE__ */ jsx421("div", { "aria-hidden": "true", className: "cj-agent-map__skeleton animate-pulse motion-reduce:animate-none", children: Array.from({ length: Math.max(1, count) }).map((_, i) => /* @__PURE__ */ jsxs255("div", { className: "cj-agent-map__skeleton-project", children: [
83935
84048
  /* @__PURE__ */ jsx421("span", { className: "cj-agent-map__skeleton-hub" }),
83936
84049
  /* @__PURE__ */ jsx421(SkeletonBar, { width: "4.5rem" }),
83937
84050
  /* @__PURE__ */ jsx421(SkeletonBar, { width: "3rem", height: "h-2.5" })
83938
84051
  ] }, i)) });
83939
- function AgentMap({ projects, expandedProjectId, defaultExpandedProjectId = null, onExpandedProjectChange, selectedAgentId, defaultSelectedAgentId = null, onAgentSelect, onSelectionClear, renderAgentDetails, ariaLabel = "Agent activity", live = false, scattered = false, grid, panelVariant = "elevated", detailsVariant = "elevated", listVariant = "subtle", panelTone = "none", detailsTone = "none", listTone = "none", gridTone = "blue", glowTone = "blue", emptyProjects, noActiveAgentsMessage, robotVariant = "solid", loading = false, loadingMessage, loaderType = "spinner", loaderProgress, skeletonProjects = 3, inspectorTitle = "Inspector", inspectorMinMainWidth = INSPECTOR_MIN_MAIN_WIDTH_DEFAULT2, inspectorStackBelow, fullHeight = false, fullWidth = true, className, style }) {
84052
+ function AgentMap({ projects, expandedProjectId, defaultExpandedProjectId = null, onExpandedProjectChange, selectedAgentId, defaultSelectedAgentId = null, onAgentSelect, onSelectionClear, renderAgentDetails, ariaLabel = "Agent activity", live = false, scattered = false, grid, panelVariant = "elevated", detailsVariant = "elevated", listVariant = "subtle", panelTone = "none", detailsTone = "none", listTone = "none", gridTone = "blue", glowTone = "blue", emptyProjects, noActiveAgentsMessage, robotVariant = "solid", loading = false, loadingMessage, loaderType = "spinner", loaderProgress, skeletonProjects = 3, inspectorTitle = "Inspector", inspectorMinMainWidth = INSPECTOR_MIN_MAIN_WIDTH_DEFAULT2, inspectorStackBelow, narrowBelow = NARROW_BELOW_DEFAULT, zoomable = true, fullHeight = false, fullWidth = true, className, style }) {
83940
84053
  const [internalExpanded, setInternalExpanded] = useState113(defaultExpandedProjectId);
83941
84054
  const [internalSelected, setInternalSelected] = useState113(defaultSelectedAgentId);
83942
84055
  const [width, setWidth] = useState113(720);
83943
84056
  const [viewportHeight, setViewportHeight] = useState113(420);
83944
84057
  const [scrollLeft, setScrollLeft] = useState113(0);
83945
84058
  const [stacked, setStacked] = useState113(false);
84059
+ const [zoom, setZoom] = useState113(1);
84060
+ const zoomRef = useRef100(1);
83946
84061
  const rootRef = useRef100(null);
84062
+ const panelRef = useRef100(null);
83947
84063
  const viewportRef = useRef100(null);
83948
84064
  const orbsViewportRef = useRef100(null);
83949
84065
  const expanded = expandedProjectId === void 0 ? internalExpanded : expandedProjectId;
83950
84066
  const selected = selectedAgentId === void 0 ? internalSelected : selectedAgentId;
83951
- const narrow = width < 400 || fullHeight && viewportHeight < 364;
84067
+ const narrow = width < narrowBelow;
83952
84068
  useEffect94(() => {
83953
84069
  const el = viewportRef.current;
83954
84070
  if (!el) return;
@@ -83967,28 +84083,49 @@ function AgentMap({ projects, expandedProjectId, defaultExpandedProjectId = null
83967
84083
  return () => observer.disconnect();
83968
84084
  }, [fullHeight, projects]);
83969
84085
  useEffect94(() => {
83970
- const el = rootRef.current;
83971
- if (!el) return;
83972
- const threshold = inspectorStackBelow ?? INSPECTOR_WIDTH + INSPECTOR_GAP2 + inspectorMinMainWidth;
84086
+ const main = panelRef.current;
84087
+ if (!main) return;
84088
+ const squeeze = fullWidth && !!selected && !stacked ? 0 : fullWidth ? INSPECTOR_WIDTH + INSPECTOR_GAP : 0;
84089
+ const threshold = inspectorStackBelow ?? inspectorMinMainWidth;
83973
84090
  const measure = () => {
83974
- const w = el.getBoundingClientRect().width;
83975
- if (w > 0) setStacked(w < threshold);
84091
+ const w = main.getBoundingClientRect().width;
84092
+ if (w > 0) setStacked(w - squeeze < threshold);
83976
84093
  };
83977
84094
  measure();
83978
84095
  if (typeof ResizeObserver === "undefined") return;
83979
84096
  const observer = new ResizeObserver(measure);
83980
- observer.observe(el);
84097
+ observer.observe(main);
83981
84098
  return () => observer.disconnect();
83982
- }, [inspectorMinMainWidth, inspectorStackBelow]);
84099
+ }, [inspectorMinMainWidth, inspectorStackBelow, fullWidth, selected, stacked, projects.length]);
83983
84100
  const expandedProject = projects.find((project) => project.id === expanded);
83984
84101
  const focused = !narrow && !!expandedProject && expandedProject.agents.length > MAX_ORBIT_AGENTS && expandedProject.agents.length <= MAX_FOCUS_AGENTS;
83985
84102
  const showLargeAgentList = !!expandedProject && expandedProject.agents.length > MAX_FOCUS_AGENTS;
83986
- const graphHeight = fullHeight && !narrow ? showLargeAgentList ? Math.max(160, Math.floor(viewportHeight * 0.45)) : Math.max(364, viewportHeight) : 420;
84103
+ const graphHeight = fullHeight && !narrow ? showLargeAgentList ? Math.max(160, Math.floor(viewportHeight * 0.45)) : Math.max(160, viewportHeight) : 420;
83987
84104
  const layout = useMemo76(() => {
83988
84105
  const items = projects.map((p) => ({ id: p.id, radius: p.id === expanded && p.agents.length <= MAX_ORBIT_AGENTS ? EXPANDED_RADIUS : COLLAPSED_RADIUS }));
83989
84106
  return scattered && !narrow ? scatterProjects(items, width, graphHeight, 18) : { ...layoutProjectsHorizontally(items, graphHeight, 18, scattered), scale: 1 };
83990
84107
  }, [projects, expanded, graphHeight, scattered, narrow, width]);
83991
- const canvasWidth = Math.max(width, layout.width, focused ? scrollLeft + width : 0);
84108
+ const canvasWidth = Math.max(width, layout.width, focused ? (scrollLeft + width) / zoom : 0);
84109
+ function zoomTo(next) {
84110
+ const clamped = Math.min(ZOOM_MAX, Math.max(ZOOM_MIN, Math.round(next * 1e3) / 1e3));
84111
+ const z = zoomRef.current;
84112
+ if (clamped === z) return;
84113
+ const vp = orbsViewportRef.current;
84114
+ const half = (vp?.clientWidth ?? 0) / 2;
84115
+ const world = (vp ? vp.scrollLeft + half : 0) / z;
84116
+ zoomRef.current = clamped;
84117
+ setZoom(clamped);
84118
+ if (vp) requestAnimationFrame(() => {
84119
+ vp.scrollLeft = Math.max(0, world * clamped - half);
84120
+ });
84121
+ }
84122
+ function zoomBy(factor) {
84123
+ zoomTo(zoomRef.current * factor);
84124
+ }
84125
+ function fitToView() {
84126
+ const vp = orbsViewportRef.current;
84127
+ zoomTo(canvasWidth > 0 ? (vp?.clientWidth || width) / canvasWidth : 1);
84128
+ }
83992
84129
  useEffect94(() => {
83993
84130
  const viewport = orbsViewportRef.current;
83994
84131
  if (!viewport) return;
@@ -84000,21 +84137,92 @@ function AgentMap({ projects, expandedProjectId, defaultExpandedProjectId = null
84000
84137
  const selection = projects.flatMap((project) => project.agents.map((agent) => ({ project, agent }))).find((item) => item.agent.id === selected);
84001
84138
  useEffect94(() => {
84002
84139
  if (!selection) return;
84140
+ let origin = null;
84003
84141
  const handlePointerDown = (event) => {
84142
+ origin = { x: event.clientX, y: event.clientY };
84143
+ };
84144
+ const handlePointerUp = (event) => {
84145
+ const start = origin;
84146
+ origin = null;
84147
+ if (!start || Math.hypot(event.clientX - start.x, event.clientY - start.y) > 4) return;
84004
84148
  const target = event.target;
84005
84149
  if (!(target instanceof Element)) return;
84006
84150
  const root = rootRef.current;
84007
- if (root?.contains(target) && (target.closest(".cj-agent-map__inspector") || target.closest(".cj-agent-map__agent, .cj-agent-map__list-agent, .cj-agent-map__hub, .cj-agent-map__list-project"))) return;
84151
+ if (root?.contains(target) && (target.closest(".cj-agent-map__inspector") || target.closest(".cj-agent-map__agent, .cj-agent-map__list-agent, .cj-agent-map__hub, .cj-agent-map__list-project, .cj-agent-map__zoom") || target.closest('[data-slot="scrollarea-scrollbar"]'))) return;
84008
84152
  if (selectedAgentId === void 0) setInternalSelected(null);
84009
84153
  onSelectionClear?.();
84010
84154
  };
84155
+ const handlePointerCancel = () => {
84156
+ origin = null;
84157
+ };
84011
84158
  document.addEventListener("pointerdown", handlePointerDown);
84012
- return () => document.removeEventListener("pointerdown", handlePointerDown);
84159
+ document.addEventListener("pointerup", handlePointerUp);
84160
+ document.addEventListener("pointercancel", handlePointerCancel);
84161
+ return () => {
84162
+ document.removeEventListener("pointerdown", handlePointerDown);
84163
+ document.removeEventListener("pointerup", handlePointerUp);
84164
+ document.removeEventListener("pointercancel", handlePointerCancel);
84165
+ };
84013
84166
  }, [selection, selectedAgentId, onSelectionClear]);
84014
84167
  const agents = projects.flatMap((project) => project.agents);
84015
84168
  const activeCount = agents.filter((agent) => agent.status === "working").length;
84016
84169
  const attentionCount = agents.filter((agent) => agent.status === "attention").length;
84017
84170
  const showSkeleton = loading && loaderType === "skeleton";
84171
+ const pan = useRef100(null);
84172
+ const suppressPanClick = useRef100(false);
84173
+ const [panning, setPanning] = useState113(false);
84174
+ const [pannable, setPannable] = useState113(false);
84175
+ useEffect94(() => {
84176
+ const vp = orbsViewportRef.current;
84177
+ if (!vp) {
84178
+ setPannable(false);
84179
+ return;
84180
+ }
84181
+ const check = () => setPannable(vp.scrollWidth > vp.clientWidth + 1 || vp.scrollHeight > vp.clientHeight + 1);
84182
+ check();
84183
+ if (typeof ResizeObserver === "undefined") return;
84184
+ const observer = new ResizeObserver(check);
84185
+ observer.observe(vp);
84186
+ const frame = vp.querySelector(".cj-agent-map__canvas-frame");
84187
+ if (frame) observer.observe(frame);
84188
+ return () => observer.disconnect();
84189
+ }, [width, zoom, graphHeight, canvasWidth, focused, narrow, loading, showSkeleton, projects.length]);
84190
+ function beginPan(event) {
84191
+ if (event.button !== 0 || event.pointerType === "touch" || pan.current) return;
84192
+ const vp = orbsViewportRef.current;
84193
+ if (!vp || vp.scrollWidth <= vp.clientWidth + 1 && vp.scrollHeight <= vp.clientHeight + 1) return;
84194
+ pan.current = { id: event.pointerId, x: event.clientX, y: event.clientY, originX: event.clientX, originY: event.clientY, left: vp.scrollLeft, top: vp.scrollTop, moved: false };
84195
+ }
84196
+ function movePan(event) {
84197
+ const p = pan.current;
84198
+ const vp = orbsViewportRef.current;
84199
+ if (!p || p.id !== event.pointerId || !vp) return;
84200
+ p.moved || (p.moved = Math.hypot(event.clientX - p.originX, event.clientY - p.originY) > 4);
84201
+ if (!p.moved) return;
84202
+ setPanning(true);
84203
+ const frame = event.currentTarget;
84204
+ if (!frame.hasPointerCapture?.(event.pointerId)) frame.setPointerCapture?.(event.pointerId);
84205
+ vp.scrollLeft = p.left - (event.clientX - p.originX);
84206
+ vp.scrollTop = p.top - (event.clientY - p.originY);
84207
+ }
84208
+ function endPan(event) {
84209
+ const p = pan.current;
84210
+ if (!p || p.id !== event.pointerId) return;
84211
+ pan.current = null;
84212
+ setPanning(false);
84213
+ if (p.moved) suppressPanClick.current = true;
84214
+ }
84215
+ useEffect94(() => {
84216
+ const el = orbsViewportRef.current;
84217
+ if (!el || !zoomable || narrow || loading || showSkeleton || projects.length === 0) return;
84218
+ const onWheel = (event) => {
84219
+ if (!(event.ctrlKey || event.metaKey)) return;
84220
+ event.preventDefault();
84221
+ zoomBy(event.deltaY < 0 ? 1.12 : 1 / 1.12);
84222
+ };
84223
+ el.addEventListener("wheel", onWheel, { passive: false });
84224
+ return () => el.removeEventListener("wheel", onWheel);
84225
+ }, [zoomable, narrow, loading, showSkeleton, projects.length]);
84018
84226
  function toggle(project) {
84019
84227
  const next = expanded === project.id ? null : project.id;
84020
84228
  if (selection) {
@@ -84058,7 +84266,7 @@ function AgentMap({ projects, expandedProjectId, defaultExpandedProjectId = null
84058
84266
  }
84059
84267
  const inactiveMessage = noActiveAgentsMessage === void 0 ? agents.length === 0 ? "No agents are assigned to these projects yet." : "No agents are currently working." : noActiveAgentsMessage;
84060
84268
  return /* @__PURE__ */ jsxs255("div", { ref: rootRef, className: ["cj-agent-map", (stacked || projects.length === 0) && "cj-agent-map--stacked", selection && "cj-agent-map--inspector-open", fullHeight && "cj-agent-map--full-height", fullWidth ? "cj-agent-map--full-width" : "cj-agent-map--intrinsic-width", className].filter(Boolean).join(" "), style, children: [
84061
- /* @__PURE__ */ jsxs255(Panel_default, { variant: panelVariant, tone: panelTone, padding: "none", scrollable: false, flexBody: true, className: "cj-agent-map__panel", children: [
84269
+ /* @__PURE__ */ jsxs255(Panel_default, { ref: panelRef, variant: panelVariant, tone: panelTone, padding: "none", scrollable: false, flexBody: true, className: "cj-agent-map__panel", children: [
84062
84270
  /* @__PURE__ */ jsxs255("div", { className: "cj-agent-map__header", children: [
84063
84271
  /* @__PURE__ */ jsx421("strong", { children: ariaLabel }),
84064
84272
  live && /* @__PURE__ */ jsx421("span", { className: "cj-agent-map__live", children: "\u25CF Live" }),
@@ -84107,7 +84315,13 @@ function AgentMap({ projects, expandedProjectId, defaultExpandedProjectId = null
84107
84315
  expanded === project.id && agentList(project)
84108
84316
  ] }, project.id);
84109
84317
  }) })
84110
- ] }) }) }) : /* @__PURE__ */ jsx421(ScrollArea, { vertical: false, variant: "auto", className: "cj-agent-map__orbs-scroll", contentClassName: "cj-agent-map__orbs-content", viewportRef: orbsViewportRef, "aria-label": "Project map", style: { height: graphHeight }, children: /* @__PURE__ */ jsxs255("div", { className: "cj-agent-map__canvas", style: { width: canvasWidth, height: graphHeight }, children: [
84318
+ ] }) }) }) : /* @__PURE__ */ jsx421(ScrollArea, { vertical: zoom > 1, variant: "auto", className: "cj-agent-map__orbs-scroll", contentClassName: "cj-agent-map__orbs-content", viewportRef: orbsViewportRef, "aria-label": "Project map", style: { height: graphHeight }, children: /* @__PURE__ */ jsx421("div", { className: `cj-agent-map__canvas-frame${panning ? " cursor-grabbing" : pannable ? " cursor-grab" : ""}`, style: { width: Math.round(canvasWidth * zoom), height: Math.round(graphHeight * zoom), userSelect: panning ? "none" : void 0 }, onPointerDown: beginPan, onPointerMove: movePan, onPointerUp: endPan, onPointerCancel: endPan, onClickCapture: (event) => {
84319
+ if (suppressPanClick.current) {
84320
+ suppressPanClick.current = false;
84321
+ event.preventDefault();
84322
+ event.stopPropagation();
84323
+ }
84324
+ }, children: /* @__PURE__ */ jsxs255("div", { className: "cj-agent-map__canvas", style: { width: canvasWidth, height: graphHeight, transform: `scale(${zoom})`, transformOrigin: "0 0" }, children: [
84111
84325
  projects.map((project, i) => {
84112
84326
  const pos = layout.circles[i];
84113
84327
  const open = expanded === project.id;
@@ -84118,7 +84332,7 @@ function AgentMap({ projects, expandedProjectId, defaultExpandedProjectId = null
84118
84332
  const scale = focused ? 0.7 : project.agents.length > 8 ? Math.max(0.72, 8 / project.agents.length) : 1;
84119
84333
  const hubScale = open ? scale : layout.scale;
84120
84334
  const color2 = attention ? COLORS2.attention : completed === project.agents.length && completed > 0 ? COLORS2.completed : COLORS2.working;
84121
- return /* @__PURE__ */ jsxs255("div", { className: ["cj-agent-map__project", focused && !open && "cj-agent-map__project--background", focused && open && "cj-agent-map__project--focused"].filter(Boolean).join(" "), style: { left: focused && open ? scrollLeft + width / 2 : pos.x, top: focused && open ? graphHeight / 2 : pos.y, ...open ? {} : { "--overflow-offset": `${58 * layout.scale}px` } }, "aria-hidden": focused && !open ? true : void 0, children: [
84335
+ return /* @__PURE__ */ jsxs255("div", { className: ["cj-agent-map__project", focused && !open && "cj-agent-map__project--background", focused && open && "cj-agent-map__project--focused"].filter(Boolean).join(" "), style: { left: focused && open ? (scrollLeft + width / 2) / zoom : pos.x, top: focused && open ? graphHeight / 2 : pos.y, ...open ? {} : { "--overflow-offset": `${58 * layout.scale}px` } }, "aria-hidden": focused && !open ? true : void 0, children: [
84122
84336
  orbit && /* @__PURE__ */ jsx421("svg", { className: "cj-agent-map__lines", "aria-hidden": "true", viewBox: "-164 -164 328 328", children: project.agents.map((agent, j) => /* @__PURE__ */ jsx421("line", { x1: "0", y1: "0", x2: points[j].x, y2: points[j].y, stroke: COLORS2[agent.status] }, agent.id)) }),
84123
84337
  /* @__PURE__ */ jsxs255("button", { type: "button", className: ["cj-agent-map__hub", attention && "cj-agent-map__hub--attention"].filter(Boolean).join(" "), style: { "--agent-color": color2, "--hub-scale": hubScale }, disabled: focused && !open, title: project.name, "aria-expanded": open, "aria-label": `${project.name}, ${project.agents.length} agents${attention ? `, ${attention} need attention` : ""}`, onClick: () => toggle(project), children: [
84124
84338
  /* @__PURE__ */ jsx421("strong", { children: project.name }),
@@ -84136,8 +84350,22 @@ function AgentMap({ projects, expandedProjectId, defaultExpandedProjectId = null
84136
84350
  open && !orbit && /* @__PURE__ */ jsx421("span", { className: "cj-agent-map__overflow", children: "See agents below" })
84137
84351
  ] }, project.id);
84138
84352
  }),
84139
- focused && expandedProject && /* @__PURE__ */ jsx421("button", { type: "button", className: "cj-agent-map__exit-focus", style: { left: scrollLeft + 14 }, onClick: () => toggle(expandedProject), children: "\u2190 All projects" })
84140
- ] }) }),
84353
+ focused && expandedProject && /* @__PURE__ */ jsx421("button", { type: "button", className: "cj-agent-map__exit-focus", style: { left: (scrollLeft + 14) / zoom }, onClick: () => toggle(expandedProject), children: "\u2190 All projects" })
84354
+ ] }) }) }),
84355
+ zoomable && !narrow && !loading && !showSkeleton && projects.length > 0 && /* @__PURE__ */ jsxs255("div", { className: "cj-agent-map__zoom absolute bottom-3 right-3 z-10 flex items-center gap-0.5 rounded-lg border border-neutral-200 bg-white/90 p-1 shadow-sm backdrop-blur dark:border-neutral-700 dark:bg-neutral-900/90", role: "group", "aria-label": "Map zoom controls", children: [
84356
+ /* @__PURE__ */ jsx421(IconButton_default, { icon: /* @__PURE__ */ jsxs255("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
84357
+ /* @__PURE__ */ jsx421("path", { d: "M4 9V5a1 1 0 0 1 1-1h4" }),
84358
+ /* @__PURE__ */ jsx421("path", { d: "M15 4h4a1 1 0 0 1 1 1v4" }),
84359
+ /* @__PURE__ */ jsx421("path", { d: "M20 15v4a1 1 0 0 1-1 1h-4" }),
84360
+ /* @__PURE__ */ jsx421("path", { d: "M9 20H5a1 1 0 0 1-1-1v-4" })
84361
+ ] }), size: "xs", variant: "ghost", color: "slate", srLabel: "Fit map to view", tooltip: "Fit map to view", onClick: fitToView }),
84362
+ /* @__PURE__ */ jsx421(IconButton_default, { icon: /* @__PURE__ */ jsx421("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx421("path", { d: "M6 12h12" }) }), size: "xs", variant: "ghost", color: "slate", disabled: zoom <= ZOOM_MIN, srLabel: "Zoom out", tooltip: "Zoom out", onClick: () => zoomBy(0.8) }),
84363
+ /* @__PURE__ */ jsxs255("span", { className: "min-w-[3.5ch] px-1 text-center text-[11px] tabular-nums text-neutral-500 dark:text-neutral-400", "aria-label": "Zoom level", children: [
84364
+ Math.round(zoom * 100),
84365
+ "%"
84366
+ ] }),
84367
+ /* @__PURE__ */ jsx421(IconButton_default, { icon: "Add", size: "xs", variant: "ghost", color: "slate", disabled: zoom >= ZOOM_MAX, srLabel: "Zoom in", tooltip: "Zoom in", onClick: () => zoomBy(1.25) })
84368
+ ] }),
84141
84369
  !loading && !narrow && expandedProject && expandedProject.agents.length > MAX_FOCUS_AGENTS && /* @__PURE__ */ jsx421("div", { className: "cj-agent-map__list", children: agentList(expandedProject) })
84142
84370
  ] }),
84143
84371
  !loading && projects.length > 0 && /* @__PURE__ */ jsx421("div", { className: "cj-agent-map__legend", children: Object.keys(LABELS).map((status) => /* @__PURE__ */ jsxs255("span", { children: [
@@ -85235,14 +85463,93 @@ function useNetworkCanvas(options) {
85235
85463
  draw();
85236
85464
  });
85237
85465
  }, [draw]);
85466
+ const panFrame = useRef102(null);
85467
+ const cancelPan = useCallback60(() => {
85468
+ if (panFrame.current !== null) {
85469
+ cancelAnimationFrame(panFrame.current);
85470
+ panFrame.current = null;
85471
+ }
85472
+ }, []);
85238
85473
  const update = useCallback60(
85239
85474
  (next) => {
85475
+ cancelPan();
85240
85476
  view.current = next;
85241
85477
  setZoom(next.zoom);
85242
85478
  requestDraw();
85243
85479
  latest.current.onViewportChange?.({ ...next });
85244
85480
  },
85245
- [requestDraw]
85481
+ [requestDraw, cancelPan]
85482
+ );
85483
+ const animateView = useCallback60(
85484
+ (target, onDone) => {
85485
+ cancelPan();
85486
+ const from = { ...view.current };
85487
+ if (from.x === target.x && from.y === target.y && from.zoom === target.zoom) {
85488
+ onDone?.();
85489
+ return;
85490
+ }
85491
+ const commit = (v) => {
85492
+ view.current = v;
85493
+ setZoom(v.zoom);
85494
+ requestDraw();
85495
+ latest.current.onViewportChange?.({ ...v });
85496
+ };
85497
+ if (typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
85498
+ commit(target);
85499
+ onDone?.();
85500
+ return;
85501
+ }
85502
+ const start = Date.now();
85503
+ const step = () => {
85504
+ panFrame.current = requestAnimationFrame(() => {
85505
+ const t = Math.min(1, (Date.now() - start) / 300);
85506
+ const e = 1 - Math.pow(1 - t, 3);
85507
+ commit({
85508
+ x: from.x + (target.x - from.x) * e,
85509
+ y: from.y + (target.y - from.y) * e,
85510
+ zoom: from.zoom + (target.zoom - from.zoom) * e
85511
+ });
85512
+ if (t < 1) step();
85513
+ else {
85514
+ panFrame.current = null;
85515
+ onDone?.();
85516
+ }
85517
+ });
85518
+ };
85519
+ step();
85520
+ },
85521
+ [cancelPan, requestDraw]
85522
+ );
85523
+ const revealNode = useCallback60(
85524
+ (node, center = false) => {
85525
+ const v = view.current;
85526
+ const { width, height } = size.current;
85527
+ if (center) {
85528
+ animateView({
85529
+ ...v,
85530
+ x: width / 2 - node.x * v.zoom,
85531
+ y: height / 2 - node.y * v.zoom
85532
+ });
85533
+ return;
85534
+ }
85535
+ const margin = 8 + Math.max(node.radius, 1.5 / v.zoom) * v.zoom;
85536
+ const sx = node.x * v.zoom + v.x, sy = node.y * v.zoom + v.y;
85537
+ let dx = 0, dy = 0;
85538
+ if (sx < margin) dx = margin - sx;
85539
+ else if (sx > width - margin) dx = width - margin - sx;
85540
+ if (sy < margin) dy = margin - sy;
85541
+ else if (sy > height - margin) dy = height - margin - sy;
85542
+ if (dx === 0 && dy === 0) return;
85543
+ animateView({ ...v, x: v.x + dx, y: v.y + dy });
85544
+ },
85545
+ [animateView]
85546
+ );
85547
+ const animateFit = useCallback60(
85548
+ (onDone) => animateView(
85549
+ fitNetwork(latest.current.nodes, size.current.width, size.current.height),
85550
+ onDone
85551
+ ),
85552
+ [animateView]
85246
85553
  );
85247
85554
  const fit = useCallback60(
85248
85555
  () => update(
@@ -85321,17 +85628,27 @@ function useNetworkCanvas(options) {
85321
85628
  theme.disconnect();
85322
85629
  window.removeEventListener("resize", measure);
85323
85630
  if (frame.current !== null) cancelAnimationFrame(frame.current);
85631
+ if (panFrame.current !== null) cancelAnimationFrame(panFrame.current);
85324
85632
  frame.current = null;
85325
85633
  };
85326
85634
  }, [fit, update, requestDraw, options.active]);
85327
- return { canvasRef, view, zoom, update, fit, zoomBy, focusNode };
85635
+ return {
85636
+ canvasRef,
85637
+ view,
85638
+ zoom,
85639
+ update,
85640
+ fit,
85641
+ zoomBy,
85642
+ focusNode,
85643
+ revealNode,
85644
+ animateFit
85645
+ };
85328
85646
  }
85329
85647
 
85330
85648
  // src/components/NetworkGraph/NetworkGraph.tsx
85331
85649
  import { Fragment as Fragment69, jsx as jsx424, jsxs as jsxs257 } from "react/jsx-runtime";
85332
85650
  var NO_COMMUNITIES = [];
85333
85651
  var NO_HIGHLIGHTS = [];
85334
- var INSPECTOR_GAP3 = 16;
85335
85652
  var INSPECTOR_WIDTH_DEFAULT2 = 280;
85336
85653
  var INSPECTOR_WIDTH_MIN2 = 180;
85337
85654
  var INSPECTOR_WIDTH_MAX2 = 480;
@@ -85375,6 +85692,9 @@ function NetworkGraph({
85375
85692
  hoverHighlight = true,
85376
85693
  fullHeight = false,
85377
85694
  fullWidth = true,
85695
+ autoRevealSelected = true,
85696
+ autoCenterSelected = true,
85697
+ autoFitOnInspector = false,
85378
85698
  ariaLabel,
85379
85699
  emptyMessage,
85380
85700
  onViewportChange,
@@ -85405,13 +85725,13 @@ function NetworkGraph({
85405
85725
  useEffect97(() => {
85406
85726
  const element = rootRef.current;
85407
85727
  if (!element || !inspector) return;
85408
- const threshold = inspectorStackBelow ?? resolvedInspectorWidth + INSPECTOR_GAP3 + inspectorMinMainWidth;
85728
+ const threshold = inspectorStackBelow ?? inspectorMinMainWidth;
85409
85729
  const measure = () => setInspectorStacked(element.getBoundingClientRect().width < threshold);
85410
85730
  measure();
85411
85731
  const observer = new ResizeObserver(measure);
85412
85732
  observer.observe(element);
85413
85733
  return () => observer.disconnect();
85414
- }, [inspector, resolvedInspectorWidth, inspectorMinMainWidth, inspectorStackBelow]);
85734
+ }, [inspector, inspectorMinMainWidth, inspectorStackBelow]);
85415
85735
  const model = useMemo78(
85416
85736
  () => buildNetwork(nodes, edges, communities),
85417
85737
  [nodes, edges, communities]
@@ -85486,6 +85806,37 @@ function NetworkGraph({
85486
85806
  onViewportChange
85487
85807
  });
85488
85808
  const locked = disabled || loading;
85809
+ const { revealNode, animateFit } = canvas;
85810
+ const inspectorOpen = !!inspector && selected !== null;
85811
+ const inspectorWasOpen = useRef103(false);
85812
+ useEffect97(() => {
85813
+ const opening = inspectorOpen && !inspectorWasOpen.current;
85814
+ inspectorWasOpen.current = inspectorOpen;
85815
+ if (!inspectorOpen || locked) return;
85816
+ if (!autoRevealSelected && !autoFitOnInspector) return;
85817
+ const positioned = selected !== null ? model.byId.get(selected) : void 0;
85818
+ const reduced = typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
85819
+ const timer = setTimeout(() => {
85820
+ if (opening && autoFitOnInspector)
85821
+ animateFit(() => {
85822
+ if (positioned && autoRevealSelected)
85823
+ revealNode(positioned, autoCenterSelected);
85824
+ });
85825
+ else if (positioned && autoRevealSelected)
85826
+ revealNode(positioned, autoCenterSelected);
85827
+ }, reduced ? 0 : 260);
85828
+ return () => clearTimeout(timer);
85829
+ }, [
85830
+ inspectorOpen,
85831
+ selected,
85832
+ locked,
85833
+ autoRevealSelected,
85834
+ autoCenterSelected,
85835
+ autoFitOnInspector,
85836
+ model,
85837
+ revealNode,
85838
+ animateFit
85839
+ ]);
85489
85840
  const drag = useRef103(null);
85490
85841
  const select = (id) => {
85491
85842
  if (locked) return;