@ankhorage/zora 27.4.0 → 27.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.
Files changed (114) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -1
  3. package/dist/features/graph-view/adapters/inbound/web-artifact/GraphView.d.ts.map +1 -1
  4. package/dist/features/graph-view/adapters/inbound/web-artifact/GraphView.js +11 -7
  5. package/dist/features/graph-view/adapters/inbound/web-artifact/GraphView.js.map +1 -1
  6. package/dist/features/graph-view/adapters/inbound/web-artifact/bindGraphEvents.d.ts +2 -2
  7. package/dist/features/graph-view/adapters/inbound/web-artifact/bindGraphEvents.d.ts.map +1 -1
  8. package/dist/features/graph-view/adapters/inbound/web-artifact/bindGraphEvents.js +7 -7
  9. package/dist/features/graph-view/adapters/inbound/web-artifact/bindGraphEvents.js.map +1 -1
  10. package/dist/features/graph-view/adapters/inbound/web-artifact/createGraphPointerDownReader.d.ts +7 -0
  11. package/dist/features/graph-view/adapters/inbound/web-artifact/createGraphPointerDownReader.d.ts.map +1 -0
  12. package/dist/features/graph-view/adapters/inbound/web-artifact/createGraphPointerDownReader.js +40 -0
  13. package/dist/features/graph-view/adapters/inbound/web-artifact/createGraphPointerDownReader.js.map +1 -0
  14. package/dist/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.d.ts +1 -1
  15. package/dist/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.d.ts.map +1 -1
  16. package/dist/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.js +28 -4
  17. package/dist/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.js.map +1 -1
  18. package/dist/features/selection/application/resolveSelectionEventIntent.d.ts +1 -1
  19. package/dist/features/selection/application/resolveSelectionEventIntent.d.ts.map +1 -1
  20. package/dist/features/selection/application/resolveSelectionEventIntent.js +14 -5
  21. package/dist/features/selection/application/resolveSelectionEventIntent.js.map +1 -1
  22. package/package.json +2 -2
  23. package/src/features/graph-view/adapters/inbound/web-artifact/GraphView.tsx +16 -4
  24. package/src/features/graph-view/adapters/inbound/web-artifact/bindGraphEvents.ts +24 -4
  25. package/src/features/graph-view/adapters/inbound/web-artifact/createGraphPointerDownReader.test.ts +28 -0
  26. package/src/features/graph-view/adapters/inbound/web-artifact/createGraphPointerDownReader.ts +48 -0
  27. package/src/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.test.ts +16 -6
  28. package/src/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.ts +34 -3
  29. package/src/features/selection/application/resolveSelectionEventIntent.test.ts +1 -0
  30. package/src/features/selection/application/resolveSelectionEventIntent.ts +18 -4
  31. package/web-dist/authoring/index.js +6 -5
  32. package/web-dist/chunks/{Accordion-md1g54wg.js → Accordion-eq27a9ms.js} +6 -5
  33. package/web-dist/chunks/{Accordion-9n062we9.js → Accordion-x33am5bc.js} +1 -1
  34. package/web-dist/components/app-bar/AppBar.js +1 -1
  35. package/web-dist/components/app-header/AppHeader.js +1 -1
  36. package/web-dist/components/auth-screen/AuthScreen.js +1 -1
  37. package/web-dist/components/badge/Badge.js +1 -1
  38. package/web-dist/components/barcode-scanner-view/BarcodeScannerView.js +1 -1
  39. package/web-dist/components/breadcrumbs/Breadcrumbs.js +1 -1
  40. package/web-dist/components/button/Button.js +1 -1
  41. package/web-dist/components/button-group/ButtonGroup.js +1 -1
  42. package/web-dist/components/camera-permission-view/CameraPermissionView.js +1 -1
  43. package/web-dist/components/card/Card.js +1 -1
  44. package/web-dist/components/chat-list-item/ChatListItem.js +1 -1
  45. package/web-dist/components/checkbox/Checkbox.js +1 -1
  46. package/web-dist/components/checkbox-group/CheckboxGroup.js +1 -1
  47. package/web-dist/components/collection-editor/CollectionEditor.js +1 -1
  48. package/web-dist/components/color-hue-scale/ColorHueScale.js +1 -1
  49. package/web-dist/components/color-picker/ColorPicker.js +1 -1
  50. package/web-dist/components/color-tone/ColorTone.js +1 -1
  51. package/web-dist/components/color-wheel/ColorWheel.js +1 -1
  52. package/web-dist/components/content-rail/ContentRail.js +1 -1
  53. package/web-dist/components/data-table/DataTable.js +1 -1
  54. package/web-dist/components/date-picker/DatePicker.js +1 -1
  55. package/web-dist/components/dialog/Dialog.js +1 -1
  56. package/web-dist/components/empty-state/EmptyState.js +1 -1
  57. package/web-dist/components/field/Field.js +1 -1
  58. package/web-dist/components/flat-list/FlatList.js +1 -1
  59. package/web-dist/components/forgot-password-form/ForgotPasswordForm.js +1 -1
  60. package/web-dist/components/form/Form.js +1 -1
  61. package/web-dist/components/form-actions/FormActions.js +1 -1
  62. package/web-dist/components/form-error/FormError.js +1 -1
  63. package/web-dist/components/graph-view/GraphView.js +81 -18
  64. package/web-dist/components/hero/Hero.js +1 -1
  65. package/web-dist/components/icon-button/IconButton.js +1 -1
  66. package/web-dist/components/list/List.js +1 -1
  67. package/web-dist/components/list-item/ListItem.js +1 -1
  68. package/web-dist/components/list-section/ListSection.js +1 -1
  69. package/web-dist/components/matrix-grid/MatrixGrid.js +2 -2
  70. package/web-dist/components/media-card/MediaCard.js +1 -1
  71. package/web-dist/components/message-bubble/MessageBubble.js +1 -1
  72. package/web-dist/components/metric-card/MetricCard.js +1 -1
  73. package/web-dist/components/missing-element/MissingElement.js +1 -1
  74. package/web-dist/components/o-auth-provider-button/OAuthProviderButton.js +1 -1
  75. package/web-dist/components/o-auth-provider-list/OAuthProviderList.js +1 -1
  76. package/web-dist/components/otp-form/OtpForm.js +1 -1
  77. package/web-dist/components/pagination/Pagination.js +1 -1
  78. package/web-dist/components/palette-item/PaletteItem.js +1 -1
  79. package/web-dist/components/popover-menu/PopoverMenu.js +1 -1
  80. package/web-dist/components/post-card/PostCard.js +1 -1
  81. package/web-dist/components/product-card/ProductCard.js +1 -1
  82. package/web-dist/components/radio/Radio.js +1 -1
  83. package/web-dist/components/radio-group/RadioGroup.js +1 -1
  84. package/web-dist/components/reader/Reader.js +2 -2
  85. package/web-dist/components/scan-overlay/ScanOverlay.js +1 -1
  86. package/web-dist/components/search-input/SearchInput.js +1 -1
  87. package/web-dist/components/section-list/SectionList.js +1 -1
  88. package/web-dist/components/select/Select.js +1 -1
  89. package/web-dist/components/selectable-item/SelectableItem.js +1 -1
  90. package/web-dist/components/selection-provider/SelectionProvider.js +1 -1
  91. package/web-dist/components/sign-in-form/SignInForm.js +1 -1
  92. package/web-dist/components/sign-up-form/SignUpForm.js +1 -1
  93. package/web-dist/components/skeleton/Skeleton.js +1 -1
  94. package/web-dist/components/skeleton-card/SkeletonCard.js +1 -1
  95. package/web-dist/components/skeleton-list/SkeletonList.js +1 -1
  96. package/web-dist/components/skeleton-text/SkeletonText.js +1 -1
  97. package/web-dist/components/surface/Surface.js +1 -1
  98. package/web-dist/components/switch/Switch.js +1 -1
  99. package/web-dist/components/tab/Tab.js +1 -1
  100. package/web-dist/components/tab-list/TabList.js +1 -1
  101. package/web-dist/components/tab-panel/TabPanel.js +1 -1
  102. package/web-dist/components/tabs/Tabs.js +1 -1
  103. package/web-dist/components/text-input/TextInput.js +1 -1
  104. package/web-dist/components/theme-mode-toggle/ThemeModeToggle.js +1 -1
  105. package/web-dist/components/time-picker/TimePicker.js +1 -1
  106. package/web-dist/components/toast/Toast.js +1 -1
  107. package/web-dist/components/toast-provider/ToastProvider.js +1 -1
  108. package/web-dist/components/toolbar/Toolbar.js +1 -1
  109. package/web-dist/components/tree-item/TreeItem.js +3 -3
  110. package/web-dist/components/tree-view/TreeView.js +1 -1
  111. package/web-dist/components/uploader/Uploader.js +1 -1
  112. package/web-dist/manifest.json +85 -85
  113. package/web-dist/runtime/ZoraProvider.js +1 -1
  114. /package/web-dist/chunks/{Accordion-ys214jt5.js → Accordion-c6edgxay.js} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 27.4.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 956067d: Update dependencies: `@ankhorage/surface`.
8
+
9
+ ## 27.4.1
10
+
11
+ ### Patch Changes
12
+
13
+ - fc3a199: Preserve native Control and Command modifier intent for GraphView node selection callbacks.
14
+
3
15
  ## 27.4.0
4
16
 
5
17
  ### Minor Changes
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  # ZORA
5
5
 
6
- ![license: MIT](././paradox/badges/license.svg) ![npm: v27.4.0](././paradox/badges/npm.svg) ![runtime: bun](././paradox/badges/runtime.svg) ![typescript: strict](././paradox/badges/typescript.svg) ![eslint: checked](././paradox/badges/eslint.svg) ![prettier: checked](././paradox/badges/prettier.svg) ![build: checked](././paradox/badges/build.svg) ![tests: checked](././paradox/badges/tests.svg) ![paradox: warnings](././paradox/badges/docs.svg)
6
+ ![license: MIT](././paradox/badges/license.svg) ![npm: v27.4.2](././paradox/badges/npm.svg) ![runtime: bun](././paradox/badges/runtime.svg) ![typescript: strict](././paradox/badges/typescript.svg) ![eslint: checked](././paradox/badges/eslint.svg) ![prettier: checked](././paradox/badges/prettier.svg) ![build: checked](././paradox/badges/build.svg) ![tests: checked](././paradox/badges/tests.svg) ![paradox: warnings](././paradox/badges/docs.svg)
7
7
 
8
8
  Provides opinionated React Native and React Native Web UI components, theme primitives, registries, and reader surfaces built on @ankhorage/surface.
9
9
 
@@ -1 +1 @@
1
- {"version":3,"file":"GraphView.d.ts","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/GraphView.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAGV,cAAc,EAEf,MAAM,iCAAiC,CAAC;AAQzC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,qBAiC9C;yBAjCe,SAAS"}
1
+ {"version":3,"file":"GraphView.d.ts","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/GraphView.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAGV,cAAc,EAEf,MAAM,iCAAiC,CAAC;AASzC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,qBA0C9C;yBA1Ce,SAAS"}
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import { GRAPH_VIEW_EVENTS } from '../../../constants/events';
3
+ import { createGraphPointerDownReader } from './createGraphPointerDownReader';
3
4
  import { createGraphRuntime } from './createGraphRuntime';
4
5
  import { createGraphViewDomCallbacks } from './createGraphViewDomCallbacks';
5
6
  import { GraphNodeOverlay } from './GraphNodeOverlay';
@@ -26,8 +27,11 @@ import { GraphNodeOverlay } from './GraphNodeOverlay';
26
27
  */
27
28
  export function GraphView(props) {
28
29
  const hostRef = React.useRef(null);
29
- const { containerRef, renderedNodes, runtimeRef } = useGraphViewRuntime(props, hostRef);
30
- return (<div ref={hostRef} aria-label={props.ariaLabel ?? 'Graph'} className={props.className} role="application" style={{
30
+ const pointerDownReader = React.useMemo(createGraphPointerDownReader, []);
31
+ const { containerRef, renderedNodes, runtimeRef } = useGraphViewRuntime(props, hostRef, pointerDownReader);
32
+ return (<div ref={hostRef} onPointerDown={(event) => {
33
+ pointerDownReader.write(event.nativeEvent);
34
+ }} onPointerCancel={pointerDownReader.clear} aria-label={props.ariaLabel ?? 'Graph'} className={props.className} role="application" style={{
31
35
  height: '100%',
32
36
  minHeight: 0,
33
37
  minWidth: 0,
@@ -42,12 +46,12 @@ export function GraphView(props) {
42
46
  /*** Publish the same canonical event registry on the standalone GraphView artifact. */
43
47
  GraphView.events = GRAPH_VIEW_EVENTS;
44
48
  /*** Compose React synchronization around the single imperative graph runtime. */
45
- function useGraphViewRuntime(props, hostRef) {
49
+ function useGraphViewRuntime(props, hostRef, pointerDownReader) {
46
50
  const containerRef = React.useRef(null);
47
51
  const runtimeRef = React.useRef(null);
48
52
  const callbacksRef = useGraphCallbacksRef(props, hostRef);
49
53
  const [renderedNodes, setRenderedNodes] = React.useState([]);
50
- useRuntimeLifecycle(containerRef, runtimeRef, callbacksRef);
54
+ useRuntimeLifecycle(containerRef, runtimeRef, callbacksRef, pointerDownReader);
51
55
  useRuntimeGraphUpdate(runtimeRef, props);
52
56
  useRuntimeSelection(runtimeRef, props.selectedNodeIds);
53
57
  useRenderedNodeSubscription(runtimeRef, props.renderNode, setRenderedNodes);
@@ -79,18 +83,18 @@ function useGraphCallbacksRef(props, hostRef) {
79
83
  return callbacksRef;
80
84
  }
81
85
  /*** Create and dispose the runtime only with the underlying browser container lifetime. */
82
- function useRuntimeLifecycle(containerRef, runtimeRef, callbacksRef) {
86
+ function useRuntimeLifecycle(containerRef, runtimeRef, callbacksRef, pointerDownReader) {
83
87
  React.useEffect(() => {
84
88
  const container = containerRef.current;
85
89
  if (container === null)
86
90
  return;
87
- const runtime = createGraphRuntime(container, callbacksRef);
91
+ const runtime = createGraphRuntime(container, callbacksRef, pointerDownReader.read);
88
92
  runtimeRef.current = runtime;
89
93
  return () => {
90
94
  runtime.destroy();
91
95
  runtimeRef.current = null;
92
96
  };
93
- }, [callbacksRef, containerRef, runtimeRef]);
97
+ }, [callbacksRef, containerRef, pointerDownReader, runtimeRef]);
94
98
  }
95
99
  /*** Synchronize graph data and layout policy without exposing Cytoscape to React. */
96
100
  function useRuntimeGraphUpdate(runtimeRef, props) {
@@ -1 +1 @@
1
- {"version":3,"file":"GraphView.js","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/GraphView.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAQ1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAqB,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAItD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,SAAS,CA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OAAO,GAAG,UAAU,CAAC,OAAO,CAAC;QACnC,IAAI,OAAO,KAAK,IAAI,IAAI,WAAW,KAAK,SAAS;YAAE,OAAO;QAC1D,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;YAC/B,IAAI,IAAI;gBAAE,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC,EAAE,CAAC,WAAW,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC;AACvC,CAAC;AAED,uEAAuE;AACvE,SAAS,aAAa,CAAC,KAAqB;IAC1C,OAAO;QACL,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,gBAAgB,EAAE,KAAK,CAAC,gBAAgB;QACxC,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,gBAAgB,EAAE,KAAK,CAAC,gBAAgB;QACxC,qBAAqB,EAAE,KAAK,CAAC,qBAAqB;KACnD,CAAC;AACJ,CAAC","sourcesContent":["import type { CytoscapeOptions } from 'cytoscape';\nimport React from 'react';\n\nimport type {\n GraphViewCallbacks,\n GraphViewNode,\n GraphViewProps,\n GraphViewRenderedNode,\n} from '../../../../../types/graph-view';\nimport { GRAPH_VIEW_EVENTS } from '../../../constants/events';\nimport { createGraphRuntime, type GraphRuntime } from './createGraphRuntime';\nimport { createGraphViewDomCallbacks } from './createGraphViewDomCallbacks';\nimport { GraphNodeOverlay } from './GraphNodeOverlay';\n\ntype GraphContainer = NonNullable<CytoscapeOptions['container']>;\n\n/***\n * Render a browser graph while one runtime owns Cytoscape layout, viewport, and disposal.\n * zoomMode Use `fit-relative` to make controller zoom, events and min/max limits relative\n * to the visible-node fit (1 = fit). The default `absolute` keeps engine-space zoom units.\n * sizeNodesToLabels Opt in to renderer-measured plain labels, including bold and Unicode\n * text. Keep padding in styleRules. Compound and rich-node dimensions retain their existing owners.\n * minReadableLabelSize Expand the manual zoom ceiling until plain labels reach this CSS-pixel size.\n * maxFitLabelSize Cap automatic fitting at this plain-label CSS-pixel size, leaving whitespace for tiny graphs.\n * Browser lifecycle events named by public GRAPH_VIEW_EVENTS bubble from the root\n * with `detail.controller`: the same public GraphViewController delivered to React.\n * Browser integrations can call `measureNodes` without accessing the Cytoscape runtime.\n * The standalone browser artifact exposes the same names as `GraphView.events`.\n * onSpacingFactorChange Receive the spacing accepted by explicit fit({ optimizeSpacing: true }).\n * Ordinary zoom never adjusts spacing or relayouts. Explicit optimization preserves layout ordering,\n * stops once effective fit reaches maxFitLabelSize, keeps labels and unrelated compound boundaries\n * collision-safe, and permits only a small rendered background-overlap fallback for dense graphs.\n * topologyUpdatePolicy Use `preserve-positions` for controlled incremental topology changes. It\n * retains settled nodes and the user viewport, and initially places new nodes on a deterministic\n * local grid. Use an explicit controller fit or a layout change when a complete rearrangement is\n * intentional.\n */\nexport function GraphView(props: GraphViewProps) {\n const hostRef = React.useRef<HTMLDivElement | null>(null);\n const { containerRef, renderedNodes, runtimeRef } = useGraphViewRuntime(props, hostRef);\n\n return (\n <div\n ref={hostRef}\n aria-label={props.ariaLabel ?? 'Graph'}\n className={props.className}\n role=\"application\"\n style={{\n height: '100%',\n minHeight: 0,\n minWidth: 0,\n position: 'relative',\n width: '100%',\n ...props.style,\n }}\n >\n <div ref={containerRef} style={{ height: '100%', width: '100%' }} />\n {props.renderNode ? (\n <GraphNodeOverlay\n nodes={props.nodes}\n renderedNodes={renderedNodes}\n renderNode={props.renderNode}\n onNodeEvent={(id, type, selectionIntent) =>\n runtimeRef.current?.handleOverlayNodeEvent(id, type, selectionIntent)\n }\n onNodeSize={(id, size) => runtimeRef.current?.setNodeSize(id, size)}\n />\n ) : null}\n </div>\n );\n}\n\n/*** Publish the same canonical event registry on the standalone GraphView artifact. */\nGraphView.events = GRAPH_VIEW_EVENTS;\n\n/*** Compose React synchronization around the single imperative graph runtime. */\nfunction useGraphViewRuntime(\n props: GraphViewProps,\n hostRef: React.RefObject<HTMLDivElement | null>,\n) {\n const containerRef = React.useRef<GraphContainer | null>(null);\n const runtimeRef = React.useRef<GraphRuntime | null>(null);\n const callbacksRef = useGraphCallbacksRef(props, hostRef);\n const [renderedNodes, setRenderedNodes] = React.useState<readonly GraphViewRenderedNode[]>([]);\n\n useRuntimeLifecycle(containerRef, runtimeRef, callbacksRef);\n useRuntimeGraphUpdate(runtimeRef, props);\n useRuntimeSelection(runtimeRef, props.selectedNodeIds);\n useRenderedNodeSubscription(runtimeRef, props.renderNode, setRenderedNodes);\n useKnownNodeSizes(runtimeRef, props.nodes, props.getNodeSize);\n\n return { containerRef, renderedNodes, runtimeRef };\n}\n\n/*** Keep the callback ref current without mutating refs during render. */\nfunction useGraphCallbacksRef(\n props: GraphViewProps,\n hostRef: React.RefObject<HTMLDivElement | null>,\n) {\n const callbacksRef = React.useRef<GraphViewCallbacks>(\n createGraphViewDomCallbacks(readCallbacks(props), hostRef),\n );\n const {\n onEdgeEvent,\n onLayoutComplete,\n onNodeEvent,\n onReady,\n onViewportChange,\n onSpacingFactorChange,\n } = props;\n\n React.useEffect(() => {\n callbacksRef.current = createGraphViewDomCallbacks(\n {\n onEdgeEvent,\n onLayoutComplete,\n onNodeEvent,\n onReady,\n onViewportChange,\n onSpacingFactorChange,\n },\n hostRef,\n );\n }, [\n onEdgeEvent,\n onLayoutComplete,\n onNodeEvent,\n onReady,\n onViewportChange,\n onSpacingFactorChange,\n hostRef,\n ]);\n\n return callbacksRef;\n}\n\n/*** Create and dispose the runtime only with the underlying browser container lifetime. */\nfunction useRuntimeLifecycle(\n containerRef: { current: GraphContainer | null },\n runtimeRef: { current: GraphRuntime | null },\n callbacksRef: { current: GraphViewCallbacks },\n) {\n React.useEffect(() => {\n const container = containerRef.current;\n if (container === null) return;\n const runtime = createGraphRuntime(container, callbacksRef);\n runtimeRef.current = runtime;\n return () => {\n runtime.destroy();\n runtimeRef.current = null;\n };\n }, [callbacksRef, containerRef, runtimeRef]);\n}\n\n/*** Synchronize graph data and layout policy without exposing Cytoscape to React. */\nfunction useRuntimeGraphUpdate(\n runtimeRef: { current: GraphRuntime | null },\n props: GraphViewProps,\n) {\n const {\n edges,\n fitPadding,\n layout,\n layoutOptions,\n maxZoom,\n minReadableLabelSize,\n maxFitLabelSize,\n minZoom,\n zoomMode,\n sizeNodesToLabels,\n nodes,\n renderNode,\n spacingFactor,\n styleRules,\n topologyUpdatePolicy,\n } = props;\n\n React.useEffect(() => {\n runtimeRef.current?.update({\n edges,\n fitPadding,\n layout,\n layoutOptions,\n maxZoom,\n minReadableLabelSize,\n maxFitLabelSize,\n minZoom,\n zoomMode,\n sizeNodesToLabels,\n nodes,\n richNodeRendering: renderNode !== undefined,\n spacingFactor,\n styleRules,\n topologyUpdatePolicy,\n });\n }, [\n edges,\n fitPadding,\n layout,\n layoutOptions,\n maxZoom,\n minReadableLabelSize,\n maxFitLabelSize,\n minZoom,\n zoomMode,\n sizeNodesToLabels,\n nodes,\n renderNode,\n runtimeRef,\n spacingFactor,\n styleRules,\n topologyUpdatePolicy,\n ]);\n}\n\n/*** Synchronize optional controlled selection independently from graph layout. */\nfunction useRuntimeSelection(\n runtimeRef: { current: GraphRuntime | null },\n selectedNodeIds: readonly string[] | undefined,\n) {\n React.useEffect(() => {\n runtimeRef.current?.setSelectedNodeIds(selectedNodeIds);\n }, [runtimeRef, selectedNodeIds]);\n}\n\n/*** Subscribe the optional rich-node overlay to rendered runtime positions. */\nfunction useRenderedNodeSubscription(\n runtimeRef: { current: GraphRuntime | null },\n renderNode: GraphViewProps['renderNode'],\n setRenderedNodes: (nodes: readonly GraphViewRenderedNode[]) => void,\n) {\n React.useEffect(() => {\n const runtime = runtimeRef.current;\n if (runtime === null || renderNode === undefined) {\n setRenderedNodes([]);\n return;\n }\n return runtime.subscribeRenderedNodes(setRenderedNodes);\n }, [renderNode, runtimeRef, setRenderedNodes]);\n}\n\n/*** Seed known rich-node dimensions without requiring DOM measurement. */\nfunction useKnownNodeSizes(\n runtimeRef: { current: GraphRuntime | null },\n nodes: readonly GraphViewNode[],\n getNodeSize: GraphViewProps['getNodeSize'],\n) {\n React.useEffect(() => {\n const runtime = runtimeRef.current;\n if (runtime === null || getNodeSize === undefined) return;\n for (const node of nodes) {\n const size = getNodeSize(node);\n if (size) runtime.setNodeSize(node.id, size);\n }\n }, [getNodeSize, nodes, runtimeRef]);\n}\n\n/*** Read callback props for the initial runtime callback-ref value. */\nfunction readCallbacks(props: GraphViewProps): GraphViewCallbacks {\n return {\n onEdgeEvent: props.onEdgeEvent,\n onLayoutComplete: props.onLayoutComplete,\n onNodeEvent: props.onNodeEvent,\n onReady: props.onReady,\n onViewportChange: props.onViewportChange,\n onSpacingFactorChange: props.onSpacingFactorChange,\n };\n}\n"]}
1
+ {"version":3,"file":"GraphView.js","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/GraphView.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAQ1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAC9E,OAAO,EAAE,kBAAkB,EAAqB,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAItD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,SAAS,CAAC,KAAqB;IAC7C,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAwB,IAAI,CAAC,CAAC;IAC1D,MAAM,iBAAiB,GAAG,KAAK,CAAC,OAAO,CAAC,4BAA4B,EAAE,EAAE,CAAC,CAAC;IAC1E,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,GAAG,mBAAmB,CACrE,KA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1E,SAAS,iBAAiB,CACxB,UAA4C,EAC5C,KAA+B,EAC/B,WAA0C;IAE1C,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC;QACnC,IAAI,OAAO,KAAK,IAAI,IAAI,WAAW,KAAK,SAAS;YAAE,OAAO;QAC1D,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;YAC/B,IAAI,IAAI;gBAAE,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC,EAAE,CAAC,WAAW,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC;AACvC,CAAC;AAED,uEAAuE;AACvE,SAAS,aAAa,CAAC,KAAqB;IAC1C,OAAO;QACL,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,gBAAgB,EAAE,KAAK,CAAC,gBAAgB;QACxC,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,gBAAgB,EAAE,KAAK,CAAC,gBAAgB;QACxC,qBAAqB,EAAE,KAAK,CAAC,qBAAqB;KACnD,CAAC;AACJ,CAAC","sourcesContent":["import type { CytoscapeOptions } from 'cytoscape';\nimport React from 'react';\n\nimport type {\n GraphViewCallbacks,\n GraphViewNode,\n GraphViewProps,\n GraphViewRenderedNode,\n} from '../../../../../types/graph-view';\nimport { GRAPH_VIEW_EVENTS } from '../../../constants/events';\nimport { createGraphPointerDownReader } from './createGraphPointerDownReader';\nimport { createGraphRuntime, type GraphRuntime } from './createGraphRuntime';\nimport { createGraphViewDomCallbacks } from './createGraphViewDomCallbacks';\nimport { GraphNodeOverlay } from './GraphNodeOverlay';\n\ntype GraphContainer = NonNullable<CytoscapeOptions['container']>;\n\n/***\n * Render a browser graph while one runtime owns Cytoscape layout, viewport, and disposal.\n * zoomMode Use `fit-relative` to make controller zoom, events and min/max limits relative\n * to the visible-node fit (1 = fit). The default `absolute` keeps engine-space zoom units.\n * sizeNodesToLabels Opt in to renderer-measured plain labels, including bold and Unicode\n * text. Keep padding in styleRules. Compound and rich-node dimensions retain their existing owners.\n * minReadableLabelSize Expand the manual zoom ceiling until plain labels reach this CSS-pixel size.\n * maxFitLabelSize Cap automatic fitting at this plain-label CSS-pixel size, leaving whitespace for tiny graphs.\n * Browser lifecycle events named by public GRAPH_VIEW_EVENTS bubble from the root\n * with `detail.controller`: the same public GraphViewController delivered to React.\n * Browser integrations can call `measureNodes` without accessing the Cytoscape runtime.\n * The standalone browser artifact exposes the same names as `GraphView.events`.\n * onSpacingFactorChange Receive the spacing accepted by explicit fit({ optimizeSpacing: true }).\n * Ordinary zoom never adjusts spacing or relayouts. Explicit optimization preserves layout ordering,\n * stops once effective fit reaches maxFitLabelSize, keeps labels and unrelated compound boundaries\n * collision-safe, and permits only a small rendered background-overlap fallback for dense graphs.\n * topologyUpdatePolicy Use `preserve-positions` for controlled incremental topology changes. It\n * retains settled nodes and the user viewport, and initially places new nodes on a deterministic\n * local grid. Use an explicit controller fit or a layout change when a complete rearrangement is\n * intentional.\n */\nexport function GraphView(props: GraphViewProps) {\n const hostRef = React.useRef<HTMLDivElement | null>(null);\n const pointerDownReader = React.useMemo(createGraphPointerDownReader, []);\n const { containerRef, renderedNodes, runtimeRef } = useGraphViewRuntime(\n props,\n hostRef,\n pointerDownReader,\n );\n\n return (\n <div\n ref={hostRef}\n onPointerDown={(event) => {\n pointerDownReader.write(event.nativeEvent);\n }}\n onPointerCancel={pointerDownReader.clear}\n aria-label={props.ariaLabel ?? 'Graph'}\n className={props.className}\n role=\"application\"\n style={{\n height: '100%',\n minHeight: 0,\n minWidth: 0,\n position: 'relative',\n width: '100%',\n ...props.style,\n }}\n >\n <div ref={containerRef} style={{ height: '100%', width: '100%' }} />\n {props.renderNode ? (\n <GraphNodeOverlay\n nodes={props.nodes}\n renderedNodes={renderedNodes}\n renderNode={props.renderNode}\n onNodeEvent={(id, type, selectionIntent) =>\n runtimeRef.current?.handleOverlayNodeEvent(id, type, selectionIntent)\n }\n onNodeSize={(id, size) => runtimeRef.current?.setNodeSize(id, size)}\n />\n ) : null}\n </div>\n );\n}\n\n/*** Publish the same canonical event registry on the standalone GraphView artifact. */\nGraphView.events = GRAPH_VIEW_EVENTS;\n\n/*** Compose React synchronization around the single imperative graph runtime. */\nfunction useGraphViewRuntime(\n props: GraphViewProps,\n hostRef: React.RefObject<HTMLDivElement | null>,\n pointerDownReader: ReturnType<typeof createGraphPointerDownReader>,\n) {\n const containerRef = React.useRef<GraphContainer | null>(null);\n const runtimeRef = React.useRef<GraphRuntime | null>(null);\n const callbacksRef = useGraphCallbacksRef(props, hostRef);\n const [renderedNodes, setRenderedNodes] = React.useState<readonly GraphViewRenderedNode[]>([]);\n\n useRuntimeLifecycle(containerRef, runtimeRef, callbacksRef, pointerDownReader);\n useRuntimeGraphUpdate(runtimeRef, props);\n useRuntimeSelection(runtimeRef, props.selectedNodeIds);\n useRenderedNodeSubscription(runtimeRef, props.renderNode, setRenderedNodes);\n useKnownNodeSizes(runtimeRef, props.nodes, props.getNodeSize);\n\n return { containerRef, renderedNodes, runtimeRef };\n}\n\n/*** Keep the callback ref current without mutating refs during render. */\nfunction useGraphCallbacksRef(\n props: GraphViewProps,\n hostRef: React.RefObject<HTMLDivElement | null>,\n) {\n const callbacksRef = React.useRef<GraphViewCallbacks>(\n createGraphViewDomCallbacks(readCallbacks(props), hostRef),\n );\n const {\n onEdgeEvent,\n onLayoutComplete,\n onNodeEvent,\n onReady,\n onViewportChange,\n onSpacingFactorChange,\n } = props;\n\n React.useEffect(() => {\n callbacksRef.current = createGraphViewDomCallbacks(\n {\n onEdgeEvent,\n onLayoutComplete,\n onNodeEvent,\n onReady,\n onViewportChange,\n onSpacingFactorChange,\n },\n hostRef,\n );\n }, [\n onEdgeEvent,\n onLayoutComplete,\n onNodeEvent,\n onReady,\n onViewportChange,\n onSpacingFactorChange,\n hostRef,\n ]);\n\n return callbacksRef;\n}\n\n/*** Create and dispose the runtime only with the underlying browser container lifetime. */\nfunction useRuntimeLifecycle(\n containerRef: { current: GraphContainer | null },\n runtimeRef: { current: GraphRuntime | null },\n callbacksRef: { current: GraphViewCallbacks },\n pointerDownReader: ReturnType<typeof createGraphPointerDownReader>,\n) {\n React.useEffect(() => {\n const container = containerRef.current;\n if (container === null) return;\n const runtime = createGraphRuntime(container, callbacksRef, pointerDownReader.read);\n runtimeRef.current = runtime;\n return () => {\n runtime.destroy();\n runtimeRef.current = null;\n };\n }, [callbacksRef, containerRef, pointerDownReader, runtimeRef]);\n}\n\n/*** Synchronize graph data and layout policy without exposing Cytoscape to React. */\nfunction useRuntimeGraphUpdate(\n runtimeRef: { current: GraphRuntime | null },\n props: GraphViewProps,\n) {\n const {\n edges,\n fitPadding,\n layout,\n layoutOptions,\n maxZoom,\n minReadableLabelSize,\n maxFitLabelSize,\n minZoom,\n zoomMode,\n sizeNodesToLabels,\n nodes,\n renderNode,\n spacingFactor,\n styleRules,\n topologyUpdatePolicy,\n } = props;\n\n React.useEffect(() => {\n runtimeRef.current?.update({\n edges,\n fitPadding,\n layout,\n layoutOptions,\n maxZoom,\n minReadableLabelSize,\n maxFitLabelSize,\n minZoom,\n zoomMode,\n sizeNodesToLabels,\n nodes,\n richNodeRendering: renderNode !== undefined,\n spacingFactor,\n styleRules,\n topologyUpdatePolicy,\n });\n }, [\n edges,\n fitPadding,\n layout,\n layoutOptions,\n maxZoom,\n minReadableLabelSize,\n maxFitLabelSize,\n minZoom,\n zoomMode,\n sizeNodesToLabels,\n nodes,\n renderNode,\n runtimeRef,\n spacingFactor,\n styleRules,\n topologyUpdatePolicy,\n ]);\n}\n\n/*** Synchronize optional controlled selection independently from graph layout. */\nfunction useRuntimeSelection(\n runtimeRef: { current: GraphRuntime | null },\n selectedNodeIds: readonly string[] | undefined,\n) {\n React.useEffect(() => {\n runtimeRef.current?.setSelectedNodeIds(selectedNodeIds);\n }, [runtimeRef, selectedNodeIds]);\n}\n\n/*** Subscribe the optional rich-node overlay to rendered runtime positions. */\nfunction useRenderedNodeSubscription(\n runtimeRef: { current: GraphRuntime | null },\n renderNode: GraphViewProps['renderNode'],\n setRenderedNodes: (nodes: readonly GraphViewRenderedNode[]) => void,\n) {\n React.useEffect(() => {\n const runtime = runtimeRef.current;\n if (runtime === null || renderNode === undefined) {\n setRenderedNodes([]);\n return;\n }\n return runtime.subscribeRenderedNodes(setRenderedNodes);\n }, [renderNode, runtimeRef, setRenderedNodes]);\n}\n\n/*** Seed known rich-node dimensions without requiring DOM measurement. */\nfunction useKnownNodeSizes(\n runtimeRef: { current: GraphRuntime | null },\n nodes: readonly GraphViewNode[],\n getNodeSize: GraphViewProps['getNodeSize'],\n) {\n React.useEffect(() => {\n const runtime = runtimeRef.current;\n if (runtime === null || getNodeSize === undefined) return;\n for (const node of nodes) {\n const size = getNodeSize(node);\n if (size) runtime.setNodeSize(node.id, size);\n }\n }, [getNodeSize, nodes, runtimeRef]);\n}\n\n/*** Read callback props for the initial runtime callback-ref value. */\nfunction readCallbacks(props: GraphViewProps): GraphViewCallbacks {\n return {\n onEdgeEvent: props.onEdgeEvent,\n onLayoutComplete: props.onLayoutComplete,\n onNodeEvent: props.onNodeEvent,\n onReady: props.onReady,\n onViewportChange: props.onViewportChange,\n onSpacingFactorChange: props.onSpacingFactorChange,\n };\n}\n"]}
@@ -1,7 +1,7 @@
1
- import type { Core } from 'cytoscape';
1
+ import type { Core, EventObject } from 'cytoscape';
2
2
  import type { GraphViewCallbacks, GraphViewController } from '../../../../../types/graph-view';
3
3
  /*** Bind stable Cytoscape events that always read the latest React callbacks. */
4
4
  export declare function bindGraphEvents(cy: Core, callbacksRef: {
5
5
  current: GraphViewCallbacks;
6
- }, controller: GraphViewController, onRuntimeChange: () => void): () => void;
6
+ }, controller: GraphViewController, onRuntimeChange: () => void, readLatestPointerDown?: (event: EventObject) => unknown): () => void;
7
7
  //# sourceMappingURL=bindGraphEvents.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bindGraphEvents.d.ts","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/bindGraphEvents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAe,MAAM,WAAW,CAAC;AAEnD,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EAGpB,MAAM,iCAAiC,CAAC;AAGzC,iFAAiF;AACjF,wBAAgB,eAAe,CAC7B,EAAE,EAAE,IAAI,EACR,YAAY,EAAE;IAAE,OAAO,EAAE,kBAAkB,CAAA;CAAE,EAC7C,UAAU,EAAE,mBAAmB,EAC/B,eAAe,EAAE,MAAM,IAAI,cAe5B"}
1
+ {"version":3,"file":"bindGraphEvents.d.ts","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/bindGraphEvents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAEnD,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EAGpB,MAAM,iCAAiC,CAAC;AAGzC,iFAAiF;AACjF,wBAAgB,eAAe,CAC7B,EAAE,EAAE,IAAI,EACR,YAAY,EAAE;IAAE,OAAO,EAAE,kBAAkB,CAAA;CAAE,EAC7C,UAAU,EAAE,mBAAmB,EAC/B,eAAe,EAAE,MAAM,IAAI,EAC3B,qBAAqB,GAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAoB,cA2BpE"}
@@ -1,8 +1,8 @@
1
1
  import { resolveSelectionEventIntent } from '../../../../selection/application/resolveSelectionEventIntent';
2
2
  /*** Bind stable Cytoscape events that always read the latest React callbacks. */
3
- export function bindGraphEvents(cy, callbacksRef, controller, onRuntimeChange) {
4
- const nodeHandlers = bindElementEvents(cy, 'node', callbacksRef, onRuntimeChange);
5
- const edgeHandlers = bindElementEvents(cy, 'edge', callbacksRef, onRuntimeChange);
3
+ export function bindGraphEvents(cy, callbacksRef, controller, onRuntimeChange, readLatestPointerDown = () => null) {
4
+ const nodeHandlers = bindElementEvents(cy, 'node', callbacksRef, onRuntimeChange, readLatestPointerDown);
5
+ const edgeHandlers = bindElementEvents(cy, 'edge', callbacksRef, onRuntimeChange, readLatestPointerDown);
6
6
  const viewportHandler = () => {
7
7
  callbacksRef.current.onViewportChange?.(controller.getViewport());
8
8
  onRuntimeChange();
@@ -15,13 +15,13 @@ export function bindGraphEvents(cy, callbacksRef, controller, onRuntimeChange) {
15
15
  };
16
16
  }
17
17
  /*** Bind one selector's translated event set without resubscribing on callback changes. */
18
- function bindElementEvents(cy, selector, callbacksRef, onRuntimeChange) {
18
+ function bindElementEvents(cy, selector, callbacksRef, onRuntimeChange, readLatestPointerDown) {
19
19
  return EVENT_TYPES.map(([cytoscapeEvent, type]) => {
20
20
  const handler = (event) => {
21
21
  const target = event.target;
22
22
  if (!isGraphEventTarget(target))
23
23
  return;
24
- emitElementEvent(callbacksRef.current, selector, createElementEvent(event, target.id(), type));
24
+ emitElementEvent(callbacksRef.current, selector, createElementEvent(event, target.id(), type, type === 'press' ? readLatestPointerDown(event) : null));
25
25
  onRuntimeChange();
26
26
  };
27
27
  cy.on(cytoscapeEvent, selector, handler);
@@ -29,13 +29,13 @@ function bindElementEvents(cy, selector, callbacksRef, onRuntimeChange) {
29
29
  });
30
30
  }
31
31
  /*** Translate one renderer event into the engine-neutral public event contract. */
32
- function createElementEvent(event, id, type) {
32
+ function createElementEvent(event, id, type, nativeEvent) {
33
33
  if (type !== 'press')
34
34
  return { id, type };
35
35
  return {
36
36
  id,
37
37
  type,
38
- selectionIntent: resolveSelectionEventIntent(event, 'pointer'),
38
+ selectionIntent: resolveSelectionEventIntent(event, 'pointer', nativeEvent),
39
39
  };
40
40
  }
41
41
  /*** Return whether a Cytoscape event target exposes the element identifier contract. */
@@ -1 +1 @@
1
- {"version":3,"file":"bindGraphEvents.js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E,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;AACH,CAAC;AAED,MAAM,WAAW,GAAG;IAClB,CAAC,KAAK,EAAE,OAAO,CAAC;IAChB,CAAC,QAAQ,EAAE,cAAc,CAAC;IAC1B,CAAC,QAAQ,EAAE,QAAQ,CAAC;IACpB,CAAC,UAAU,EAAE,UAAU,CAAC;IACxB,CAAC,WAAW,EAAE,eAAe,CAAC;IAC9B,CAAC,UAAU,EAAE,eAAe,CAAC;CAC+C,CAAC","sourcesContent":["import type { Core, EventObject } from 'cytoscape';\n\nimport type {\n GraphViewCallbacks,\n GraphViewController,\n GraphViewElementEvent,\n GraphViewElementEventType,\n} from '../../../../../types/graph-view';\nimport { resolveSelectionEventIntent } from '../../../../selection/application/resolveSelectionEventIntent';\n\n/*** Bind stable Cytoscape events that always read the latest React callbacks. */\nexport function bindGraphEvents(\n cy: Core,\n callbacksRef: { current: GraphViewCallbacks },\n controller: GraphViewController,\n onRuntimeChange: () => void,\n) {\n const nodeHandlers = bindElementEvents(cy, 'node', callbacksRef, onRuntimeChange);\n const edgeHandlers = bindElementEvents(cy, 'edge', callbacksRef, onRuntimeChange);\n const viewportHandler = () => {\n callbacksRef.current.onViewportChange?.(controller.getViewport());\n onRuntimeChange();\n };\n cy.on('zoom pan', viewportHandler);\n\n return () => {\n unbindElementEvents(cy, 'node', nodeHandlers);\n unbindElementEvents(cy, 'edge', edgeHandlers);\n cy.off('zoom pan', viewportHandler);\n };\n}\n\ntype ElementSelector = 'edge' | 'node';\n\ninterface BoundElementHandler {\n readonly cytoscapeEvent: string;\n readonly handler: (event: EventObject) => void;\n}\n\n/*** Bind one selector's translated event set without resubscribing on callback changes. */\nfunction bindElementEvents(\n cy: Core,\n selector: ElementSelector,\n callbacksRef: { current: GraphViewCallbacks },\n onRuntimeChange: () => void,\n): readonly BoundElementHandler[] {\n return EVENT_TYPES.map(([cytoscapeEvent, type]) => {\n const handler = (event: EventObject) => {\n const target: unknown = event.target;\n if (!isGraphEventTarget(target)) return;\n emitElementEvent(\n callbacksRef.current,\n selector,\n createElementEvent(event, target.id(), type),\n );\n onRuntimeChange();\n };\n cy.on(cytoscapeEvent, selector, handler);\n return { cytoscapeEvent, handler };\n });\n}\n\n/*** Translate one renderer event into the engine-neutral public event contract. */\nfunction createElementEvent(\n event: EventObject,\n id: string,\n type: GraphViewElementEventType,\n): GraphViewElementEvent {\n if (type !== 'press') return { id, type };\n return {\n id,\n type,\n selectionIntent: resolveSelectionEventIntent(event, 'pointer'),\n };\n}\n\n/*** Return whether a Cytoscape event target exposes the element identifier contract. */\nfunction isGraphEventTarget(value: unknown): value is GraphEventTarget {\n return (\n typeof value === 'object' && value !== null && 'id' in value && typeof value.id === 'function'\n );\n}\n\ninterface GraphEventTarget {\n id(): string;\n}\n\n/*** Emit one translated element event without dynamic callback-property access. */\nfunction emitElementEvent(\n callbacks: GraphViewCallbacks,\n selector: ElementSelector,\n event: GraphViewElementEvent,\n) {\n if (selector === 'node') {\n callbacks.onNodeEvent?.(event);\n return;\n }\n callbacks.onEdgeEvent?.(event);\n}\n\n/*** Remove one selector's event handlers using the exact bound callback identities. */\nfunction unbindElementEvents(\n cy: Core,\n selector: ElementSelector,\n handlers: readonly BoundElementHandler[],\n) {\n for (const { cytoscapeEvent, handler } of handlers) {\n cy.off(cytoscapeEvent, selector, handler);\n }\n}\n\nconst EVENT_TYPES = [\n ['tap', 'press'],\n ['dbltap', 'double-press'],\n ['select', 'select'],\n ['unselect', 'unselect'],\n ['mouseover', 'pointer-enter'],\n ['mouseout', 'pointer-leave'],\n] as const satisfies readonly (readonly [string, GraphViewElementEventType])[];\n"]}
1
+ {"version":3,"file":"bindGraphEvents.js","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/bindGraphEvents.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,2BAA2B,EAAE,MAAM,+DAA+D,CAAC;AAE5G,iFAAiF;AACjF,MAAM,UAAU,eAAe,CAC7B,EAAQ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AAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;AACH,CAAC;AAED,MAAM,WAAW,GAAG;IAClB,CAAC,KAAK,EAAE,OAAO,CAAC;IAChB,CAAC,QAAQ,EAAE,cAAc,CAAC;IAC1B,CAAC,QAAQ,EAAE,QAAQ,CAAC;IACpB,CAAC,UAAU,EAAE,UAAU,CAAC;IACxB,CAAC,WAAW,EAAE,eAAe,CAAC;IAC9B,CAAC,UAAU,EAAE,eAAe,CAAC;CAC+C,CAAC","sourcesContent":["import type { Core, EventObject } from 'cytoscape';\n\nimport type {\n GraphViewCallbacks,\n GraphViewController,\n GraphViewElementEvent,\n GraphViewElementEventType,\n} from '../../../../../types/graph-view';\nimport { resolveSelectionEventIntent } from '../../../../selection/application/resolveSelectionEventIntent';\n\n/*** Bind stable Cytoscape events that always read the latest React callbacks. */\nexport function bindGraphEvents(\n cy: Core,\n callbacksRef: { current: GraphViewCallbacks },\n controller: GraphViewController,\n onRuntimeChange: () => void,\n readLatestPointerDown: (event: EventObject) => unknown = () => null,\n) {\n const nodeHandlers = bindElementEvents(\n cy,\n 'node',\n callbacksRef,\n onRuntimeChange,\n readLatestPointerDown,\n );\n const edgeHandlers = bindElementEvents(\n cy,\n 'edge',\n callbacksRef,\n onRuntimeChange,\n readLatestPointerDown,\n );\n const viewportHandler = () => {\n callbacksRef.current.onViewportChange?.(controller.getViewport());\n onRuntimeChange();\n };\n cy.on('zoom pan', viewportHandler);\n\n return () => {\n unbindElementEvents(cy, 'node', nodeHandlers);\n unbindElementEvents(cy, 'edge', edgeHandlers);\n cy.off('zoom pan', viewportHandler);\n };\n}\n\ntype ElementSelector = 'edge' | 'node';\n\ninterface BoundElementHandler {\n readonly cytoscapeEvent: string;\n readonly handler: (event: EventObject) => void;\n}\n\n/*** Bind one selector's translated event set without resubscribing on callback changes. */\nfunction bindElementEvents(\n cy: Core,\n selector: ElementSelector,\n callbacksRef: { current: GraphViewCallbacks },\n onRuntimeChange: () => void,\n readLatestPointerDown: (event: EventObject) => unknown,\n): readonly BoundElementHandler[] {\n return EVENT_TYPES.map(([cytoscapeEvent, type]) => {\n const handler = (event: EventObject) => {\n const target: unknown = event.target;\n if (!isGraphEventTarget(target)) return;\n emitElementEvent(\n callbacksRef.current,\n selector,\n createElementEvent(\n event,\n target.id(),\n type,\n type === 'press' ? readLatestPointerDown(event) : null,\n ),\n );\n onRuntimeChange();\n };\n cy.on(cytoscapeEvent, selector, handler);\n return { cytoscapeEvent, handler };\n });\n}\n\n/*** Translate one renderer event into the engine-neutral public event contract. */\nfunction createElementEvent(\n event: EventObject,\n id: string,\n type: GraphViewElementEventType,\n nativeEvent: unknown,\n): GraphViewElementEvent {\n if (type !== 'press') return { id, type };\n return {\n id,\n type,\n selectionIntent: resolveSelectionEventIntent(event, 'pointer', nativeEvent),\n };\n}\n\n/*** Return whether a Cytoscape event target exposes the element identifier contract. */\nfunction isGraphEventTarget(value: unknown): value is GraphEventTarget {\n return (\n typeof value === 'object' && value !== null && 'id' in value && typeof value.id === 'function'\n );\n}\n\ninterface GraphEventTarget {\n id(): string;\n}\n\n/*** Emit one translated element event without dynamic callback-property access. */\nfunction emitElementEvent(\n callbacks: GraphViewCallbacks,\n selector: ElementSelector,\n event: GraphViewElementEvent,\n) {\n if (selector === 'node') {\n callbacks.onNodeEvent?.(event);\n return;\n }\n callbacks.onEdgeEvent?.(event);\n}\n\n/*** Remove one selector's event handlers using the exact bound callback identities. */\nfunction unbindElementEvents(\n cy: Core,\n selector: ElementSelector,\n handlers: readonly BoundElementHandler[],\n) {\n for (const { cytoscapeEvent, handler } of handlers) {\n cy.off(cytoscapeEvent, selector, handler);\n }\n}\n\nconst EVENT_TYPES = [\n ['tap', 'press'],\n ['dbltap', 'double-press'],\n ['select', 'select'],\n ['unselect', 'unselect'],\n ['mouseover', 'pointer-enter'],\n ['mouseout', 'pointer-leave'],\n] as const satisfies readonly (readonly [string, GraphViewElementEventType])[];\n"]}
@@ -0,0 +1,7 @@
1
+ /*** Correlate one native pointer-down snapshot with its renderer activation without retaining stale modifiers. */
2
+ export declare function createGraphPointerDownReader(): {
3
+ clear: () => void;
4
+ read: (rendererEvent: unknown) => unknown;
5
+ write: (event: unknown) => void;
6
+ };
7
+ //# sourceMappingURL=createGraphPointerDownReader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createGraphPointerDownReader.d.ts","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/createGraphPointerDownReader.ts"],"names":[],"mappings":"AAEA,kHAAkH;AAClH,wBAAgB,4BAA4B;;0BAOlB,OAAO,KAAG,OAAO;mBAMxB,OAAO;EAIzB"}
@@ -0,0 +1,40 @@
1
+ import { isRecord } from '@ankhorage/utility/object';
2
+ /*** Correlate one native pointer-down snapshot with its renderer activation without retaining stale modifiers. */
3
+ export function createGraphPointerDownReader() {
4
+ let latestPointerDown = null;
5
+ return {
6
+ clear: () => {
7
+ latestPointerDown = null;
8
+ },
9
+ read: (rendererEvent) => {
10
+ const pointerDown = latestPointerDown;
11
+ latestPointerDown = null;
12
+ if (pointerDown === null)
13
+ return null;
14
+ return matchesPointerActivation(pointerDown, rendererEvent) ? pointerDown.event : null;
15
+ },
16
+ write: (event) => {
17
+ latestPointerDown = createPointerDownSnapshot(event);
18
+ },
19
+ };
20
+ }
21
+ /*** Match only the same browser pointer so unrelated renderer events cannot inherit modifiers. */
22
+ function matchesPointerActivation(pointerDown, rendererEvent) {
23
+ return readRendererPointerId(rendererEvent) === pointerDown.pointerId;
24
+ }
25
+ /*** Retain a browser pointer event only when it provides a stable pointer identity. */
26
+ function createPointerDownSnapshot(event) {
27
+ if (!isRecord(event) || typeof event.pointerId !== 'number')
28
+ return null;
29
+ return { event, pointerId: event.pointerId };
30
+ }
31
+ /*** Read Cytoscape's underlying browser event without trusting programmatic event shapes. */
32
+ function readRendererPointerId(value) {
33
+ if (!isRecord(value))
34
+ return null;
35
+ const { originalEvent } = value;
36
+ if (!isRecord(originalEvent) || typeof originalEvent.pointerId !== 'number')
37
+ return null;
38
+ return originalEvent.pointerId;
39
+ }
40
+ //# sourceMappingURL=createGraphPointerDownReader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createGraphPointerDownReader.js","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/createGraphPointerDownReader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAErD,kHAAkH;AAClH,MAAM,UAAU,4BAA4B;IAC1C,IAAI,iBAAiB,GAAoC,IAAI,CAAC;IAE9D,OAAO;QACL,KAAK,EAAE,GAAG,EAAE;YACV,iBAAiB,GAAG,IAAI,CAAC;QAC3B,CAAC;QACD,IAAI,EAAE,CAAC,aAAsB,EAAW,EAAE;YACxC,MAAM,WAAW,GAAG,iBAAiB,CAAC;YACtC,iBAAiB,GAAG,IAAI,CAAC;YACzB,IAAI,WAAW,KAAK,IAAI;gBAAE,OAAO,IAAI,CAAC;YACtC,OAAO,wBAAwB,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;QACzF,CAAC;QACD,KAAK,EAAE,CAAC,KAAc,EAAE,EAAE;YACxB,iBAAiB,GAAG,yBAAyB,CAAC,KAAK,CAAC,CAAC;QACvD,CAAC;KACF,CAAC;AACJ,CAAC;AAED,kGAAkG;AAClG,SAAS,wBAAwB,CAC/B,WAAqC,EACrC,aAAsB;IAEtB,OAAO,qBAAqB,CAAC,aAAa,CAAC,KAAK,WAAW,CAAC,SAAS,CAAC;AACxE,CAAC;AAED,uFAAuF;AACvF,SAAS,yBAAyB,CAAC,KAAc;IAC/C,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,SAAS,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACzE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;AAC/C,CAAC;AAED,6FAA6F;AAC7F,SAAS,qBAAqB,CAAC,KAAc;IAC3C,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAClC,MAAM,EAAE,aAAa,EAAE,GAAG,KAAK,CAAC;IAChC,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,OAAO,aAAa,CAAC,SAAS,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACzF,OAAO,aAAa,CAAC,SAAS,CAAC;AACjC,CAAC","sourcesContent":["import { isRecord } from '@ankhorage/utility/object';\n\n/*** Correlate one native pointer-down snapshot with its renderer activation without retaining stale modifiers. */\nexport function createGraphPointerDownReader() {\n let latestPointerDown: GraphPointerDownSnapshot | null = null;\n\n return {\n clear: () => {\n latestPointerDown = null;\n },\n read: (rendererEvent: unknown): unknown => {\n const pointerDown = latestPointerDown;\n latestPointerDown = null;\n if (pointerDown === null) return null;\n return matchesPointerActivation(pointerDown, rendererEvent) ? pointerDown.event : null;\n },\n write: (event: unknown) => {\n latestPointerDown = createPointerDownSnapshot(event);\n },\n };\n}\n\n/*** Match only the same browser pointer so unrelated renderer events cannot inherit modifiers. */\nfunction matchesPointerActivation(\n pointerDown: GraphPointerDownSnapshot,\n rendererEvent: unknown,\n): boolean {\n return readRendererPointerId(rendererEvent) === pointerDown.pointerId;\n}\n\n/*** Retain a browser pointer event only when it provides a stable pointer identity. */\nfunction createPointerDownSnapshot(event: unknown): GraphPointerDownSnapshot | null {\n if (!isRecord(event) || typeof event.pointerId !== 'number') return null;\n return { event, pointerId: event.pointerId };\n}\n\n/*** Read Cytoscape's underlying browser event without trusting programmatic event shapes. */\nfunction readRendererPointerId(value: unknown): number | null {\n if (!isRecord(value)) return null;\n const { originalEvent } = value;\n if (!isRecord(originalEvent) || typeof originalEvent.pointerId !== 'number') return null;\n return originalEvent.pointerId;\n}\n\ninterface GraphPointerDownSnapshot {\n readonly event: unknown;\n readonly pointerId: number;\n}\n"]}
@@ -15,6 +15,6 @@ export interface GraphRuntime {
15
15
  /*** Create one Cytoscape runtime that exclusively owns layout, fit, resize, and disposal. */
16
16
  export declare function createGraphRuntime(container: GraphContainer, callbacksRef: {
17
17
  current: GraphViewCallbacks;
18
- }): GraphRuntime;
18
+ }, readLatestPointerDown?: (event: unknown) => unknown): GraphRuntime;
19
19
  export {};
20
20
  //# sourceMappingURL=createGraphRuntime.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createGraphRuntime.d.ts","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAkB,EAAa,KAAK,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAExE,OAAO,KAAK,EACV,kBAAkB,EAClB,yBAAyB,EAEzB,qBAAqB,EACrB,aAAa,EAEd,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAkBhF,KAAK,cAAc,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;AACpD,KAAK,oBAAoB,GAAG,CAAC,KAAK,EAAE,SAAS,qBAAqB,EAAE,KAAK,IAAI,CAAC;AAE9E,MAAM,WAAW,YAAY;IAC3B,OAAO,IAAI,IAAI,CAAC;IAChB,sBAAsB,CACpB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,yBAAyB,EAC/B,eAAe,CAAC,EAAE,eAAe,GAChC,IAAI,CAAC;IACR,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,IAAI,CAAC;IACnD,kBAAkB,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,GAAG,IAAI,CAAC;IACjE,sBAAsB,CAAC,QAAQ,EAAE,oBAAoB,GAAG,MAAM,IAAI,CAAC;IACnE,MAAM,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAAC;CACzC;AA6BD,6FAA6F;AAC7F,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,cAAc,EACzB,YAAY,EAAE;IAAE,OAAO,EAAE,kBAAkB,CAAA;CAAE,GAC5C,YAAY,CAoBd"}
1
+ {"version":3,"file":"createGraphRuntime.d.ts","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAkB,EAAa,KAAK,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAExE,OAAO,KAAK,EACV,kBAAkB,EAClB,yBAAyB,EAEzB,qBAAqB,EACrB,aAAa,EAEd,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAkBhF,KAAK,cAAc,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;AACpD,KAAK,oBAAoB,GAAG,CAAC,KAAK,EAAE,SAAS,qBAAqB,EAAE,KAAK,IAAI,CAAC;AAE9E,MAAM,WAAW,YAAY;IAC3B,OAAO,IAAI,IAAI,CAAC;IAChB,sBAAsB,CACpB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,yBAAyB,EAC/B,eAAe,CAAC,EAAE,eAAe,GAChC,IAAI,CAAC;IACR,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,IAAI,CAAC;IACnD,kBAAkB,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,GAAG,IAAI,CAAC;IACjE,sBAAsB,CAAC,QAAQ,EAAE,oBAAoB,GAAG,MAAM,IAAI,CAAC;IACnE,MAAM,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAAC;CACzC;AA8BD,6FAA6F;AAC7F,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,cAAc,EACzB,YAAY,EAAE;IAAE,OAAO,EAAE,kBAAkB,CAAA;CAAE,EAC7C,qBAAqB,GAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAoB,GAC9D,YAAY,CAoBd"}
@@ -16,7 +16,7 @@ import { shouldFitGraphAfterLayout } from './shouldFitGraphAfterLayout';
16
16
  import { sizeGraphNodesToLabels } from './sizeGraphNodesToLabels';
17
17
  import { syncGraphElements } from './syncGraphElements';
18
18
  /*** Create one Cytoscape runtime that exclusively owns layout, fit, resize, and disposal. */
19
- export function createGraphRuntime(container, callbacksRef) {
19
+ export function createGraphRuntime(container, callbacksRef, readLatestPointerDown = () => null) {
20
20
  const cy = cytoscape({
21
21
  container,
22
22
  elements: [],
@@ -25,7 +25,7 @@ export function createGraphRuntime(container, callbacksRef) {
25
25
  selectionType: 'additive',
26
26
  userPanningEnabled: true,
27
27
  });
28
- const state = createRuntimeState(cy, container, callbacksRef);
28
+ const state = createRuntimeState(cy, container, callbacksRef, readLatestPointerDown);
29
29
  return {
30
30
  destroy: () => destroyRuntime(state),
31
31
  handleOverlayNodeEvent: (id, type, selectionIntent) => handleOverlayNodeEvent(state, id, type, selectionIntent),
@@ -36,7 +36,7 @@ export function createGraphRuntime(container, callbacksRef) {
36
36
  };
37
37
  }
38
38
  /*** Build the mutable state shared by the single graph-runtime owner. */
39
- function createRuntimeState(cy, container, callbacksRef) {
39
+ function createRuntimeState(cy, container, callbacksRef, readLatestPointerDown) {
40
40
  const fitPaddingRef = { current: 50 };
41
41
  const viewport = createGraphController(cy, fitPaddingRef, (options) => requestOptimizedFit(state, options));
42
42
  const { controller } = viewport;
@@ -54,6 +54,7 @@ function createRuntimeState(cy, container, callbacksRef) {
54
54
  generationRef: { current: 0 },
55
55
  geometryRef: { current: null },
56
56
  hoveredNodeIds: new Set(),
57
+ initialLayoutScheduledRef: { current: false },
57
58
  latestUpdateRef: { current: null },
58
59
  layoutRef: { current: null },
59
60
  layoutRunningRef,
@@ -67,7 +68,7 @@ function createRuntimeState(cy, container, callbacksRef) {
67
68
  relayoutScheduledRef: { current: false },
68
69
  renderedNodeListeners,
69
70
  };
70
- const unbindEvents = bindGraphEvents(cy, callbacksRef, controller, () => emitRenderedNodes(stateBase));
71
+ const unbindEvents = bindGraphEvents(cy, callbacksRef, controller, () => emitRenderedNodes(stateBase), readLatestPointerDown);
71
72
  const resizeObserver = createGraphResizeObserver({
72
73
  container,
73
74
  cy,
@@ -163,6 +164,29 @@ function getRetainedNodeIds(previous, input, preservesTopology) {
163
164
  }
164
165
  /*** Start a generation-safe layout whose completion is the only normal automatic fit trigger. */
165
166
  function startCurrentLayout(state, input) {
167
+ if (!state.readyRef.current) {
168
+ scheduleInitialLayout(state);
169
+ return;
170
+ }
171
+ startGraphLayout(state, input);
172
+ }
173
+ /*** Coalesce progressive pre-ready topology updates before the initial layout can complete. */
174
+ function scheduleInitialLayout(state) {
175
+ if (state.initialLayoutScheduledRef.current)
176
+ return;
177
+ state.initialLayoutScheduledRef.current = true;
178
+ scheduleGraphFrame(() => {
179
+ scheduleGraphFrame(() => {
180
+ state.initialLayoutScheduledRef.current = false;
181
+ const input = state.latestUpdateRef.current;
182
+ if (input === null || state.cy.destroyed() || state.readyRef.current)
183
+ return;
184
+ startGraphLayout(state, input);
185
+ });
186
+ });
187
+ }
188
+ /*** Start one layout generation after its input has reached the runtime owner. */
189
+ function startGraphLayout(state, input) {
166
190
  state.pendingInitialFitRef.current = false;
167
191
  const generation = state.generationRef.current + 1;
168
192
  state.generationRef.current = generation;
@@ -1 +1 @@
1
- {"version":3,"file":"createGraphRuntime.js","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,EAAE,EAAoC,MAAM,WAAW,CAAC;AAWxE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,E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AC,qBAAqB,CAAC,KAAK,EAAE,CAAC;IACpC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE;QAAE,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC;AAChD,CAAC;AAED,oBAAoB,EAAE,CAAC","sourcesContent":["import type { SelectionIntent } from '@ankhorage/utility/selection';\nimport cytoscape, { type Core, type CytoscapeOptions } from 'cytoscape';\n\nimport type {\n GraphViewCallbacks,\n GraphViewElementEventType,\n GraphViewFitOptions,\n GraphViewRenderedNode,\n GraphViewSize,\n GraphViewStyleRule,\n} from '../../../../../types/graph-view';\nimport type { GraphRuntimeUpdate } from '../../../../../types/graphViewRuntime';\nimport { bindGraphEvents } from './bindGraphEvents';\nimport { compactGraphSpacing } from './compactGraphSpacing';\nimport { createGraphController } from './createGraphController';\nimport { createGraphLoopSizer } from './createGraphLoopSizer';\nimport { createGraphResizeObserver, type GraphResizeObserver } from './createGraphResizeObserver';\nimport { getGraphGeometryKey } from './getGraphGeometryKey';\nimport { getGraphTopologyKey } from './getGraphTopologyKey';\nimport { hasGraphLayoutChanged } from './hasGraphLayoutChanged';\nimport { placeAddedGraphNodes } from './placeAddedGraphNodes';\nimport { readGraphRenderedNodes } from './readGraphRenderedNodes';\nimport { registerGraphLayouts } from './registerGraphLayouts';\nimport { runGraphLayout } from './runGraphLayout';\nimport { scheduleGraphFrame } from './scheduleGraphFrame';\nimport { shouldFitGraphAfterLayout } from './shouldFitGraphAfterLayout';\nimport { sizeGraphNodesToLabels } from './sizeGraphNodesToLabels';\nimport { syncGraphElements } from './syncGraphElements';\n\ntype GraphContainer = CytoscapeOptions['container'];\ntype RenderedNodeListener = (nodes: readonly GraphViewRenderedNode[]) => void;\n\nexport interface GraphRuntime {\n destroy(): void;\n handleOverlayNodeEvent(\n id: string,\n type: GraphViewElementEventType,\n selectionIntent?: SelectionIntent,\n ): void;\n setNodeSize(id: string, size: GraphViewSize): void;\n setSelectedNodeIds(nodeIds: readonly string[] | undefined): void;\n subscribeRenderedNodes(listener: RenderedNodeListener): () => void;\n update(input: GraphRuntimeUpdate): void;\n}\n\ninterface GraphRuntimeState {\n readonly fitRequestRef: { current: GraphViewFitOptions | null };\n readonly optimizedSpacingRef: { current: number | null };\n readonly callbacksRef: { current: GraphViewCallbacks };\n readonly controller: ReturnType<typeof createGraphController>['controller'];\n readonly viewport: ReturnType<typeof createGraphController>;\n readonly cy: Core;\n readonly fitPaddingRef: { current: number };\n readonly generationRef: { current: number };\n readonly geometryRef: { current: string | null };\n readonly hoveredNodeIds: Set<string>;\n readonly latestUpdateRef: { current: GraphRuntimeUpdate | null };\n readonly layoutRef: { current: ReturnType<typeof runGraphLayout> | null };\n readonly layoutRunningRef: { current: boolean };\n readonly nodeSizes: Map<string, GraphViewSize>;\n readonly labelSizedNodeIds: Set<string>;\n readonly loopSizer: ReturnType<typeof createGraphLoopSizer>;\n readonly pendingInitialFitRef: { current: boolean };\n readonly readyRef: { current: boolean };\n readonly settledLayoutRef: { current: GraphRuntimeUpdate['layout'] | null };\n readonly settledTopologyRef: { current: string | null };\n readonly relayoutScheduledRef: { current: boolean };\n readonly renderedNodeListeners: Set<RenderedNodeListener>;\n readonly resizeObserver: GraphResizeObserver | null;\n readonly unbindEvents: () => void;\n}\n\n/*** Create one Cytoscape runtime that exclusively owns layout, fit, resize, and disposal. */\nexport function createGraphRuntime(\n container: GraphContainer,\n callbacksRef: { current: GraphViewCallbacks },\n): GraphRuntime {\n const cy = cytoscape({\n container,\n elements: [],\n minZoom: 0.05,\n maxZoom: 2,\n selectionType: 'additive',\n userPanningEnabled: true,\n });\n const state = createRuntimeState(cy, container, callbacksRef);\n\n return {\n destroy: () => destroyRuntime(state),\n handleOverlayNodeEvent: (id, type, selectionIntent) =>\n handleOverlayNodeEvent(state, id, type, selectionIntent),\n setNodeSize: (id, size) => setNodeSize(state, id, size),\n setSelectedNodeIds: (nodeIds) => setSelectedNodeIds(state, nodeIds),\n subscribeRenderedNodes: (listener) => subscribeRenderedNodes(state, listener),\n update: (input) => updateRuntime(state, input),\n };\n}\n\n/*** Build the mutable state shared by the single graph-runtime owner. */\nfunction createRuntimeState(\n cy: Core,\n container: GraphContainer,\n callbacksRef: { current: GraphViewCallbacks },\n): GraphRuntimeState {\n const fitPaddingRef = { current: 50 };\n const viewport = createGraphController(cy, fitPaddingRef, (options) =>\n requestOptimizedFit(state, options),\n );\n const { controller } = viewport;\n const layoutRunningRef = { current: false };\n const readyRef = { current: false };\n const renderedNodeListeners = new Set<RenderedNodeListener>();\n const stateBase = {\n fitRequestRef: { current: null as GraphViewFitOptions | null },\n optimizedSpacingRef: { current: null as number | null },\n callbacksRef,\n controller,\n viewport,\n cy,\n fitPaddingRef,\n generationRef: { current: 0 },\n geometryRef: { current: null as string | null },\n hoveredNodeIds: new Set<string>(),\n latestUpdateRef: { current: null as GraphRuntimeUpdate | null },\n layoutRef: { current: null as ReturnType<typeof runGraphLayout> | null },\n layoutRunningRef,\n nodeSizes: new Map<string, GraphViewSize>(),\n labelSizedNodeIds: new Set<string>(),\n loopSizer: createGraphLoopSizer(cy),\n pendingInitialFitRef: { current: false },\n readyRef,\n settledLayoutRef: { current: null as GraphRuntimeUpdate['layout'] | null },\n settledTopologyRef: { current: null as string | null },\n relayoutScheduledRef: { current: false },\n renderedNodeListeners,\n };\n const unbindEvents = bindGraphEvents(cy, callbacksRef, controller, () =>\n emitRenderedNodes(stateBase),\n );\n const resizeObserver = createGraphResizeObserver({\n container,\n cy,\n beginViewportResize: () => viewport.beginResize(),\n settleViewport: (fit) => viewport.settle(fit),\n layoutRunningRef,\n pendingInitialFitRef: stateBase.pendingInitialFitRef,\n onViewportSettled: (completedPendingInitialFit) => {\n emitRenderedNodes(stateBase);\n if (!completedPendingInitialFit || readyRef.current) return;\n readyRef.current = true;\n callbacksRef.current.onReady?.(controller);\n callbacksRef.current.onLayoutComplete?.(controller);\n },\n readyRef,\n });\n\n const state = { ...stateBase, resizeObserver, unbindEvents };\n return state;\n}\n\n/***\n * Reconcile presentation in place and relayout only when graph geometry or layout policy changes.\n * Batch reconciliation and skip layout for presentation-only updates.\n */\nfunction updateRuntime(state: GraphRuntimeState, input: GraphRuntimeUpdate) {\n if (state.cy.destroyed()) return;\n const last = state.latestUpdateRef.current;\n const acceptsSpacing =\n state.optimizedSpacingRef.current !== null &&\n state.optimizedSpacingRef.current === input.spacingFactor;\n const previous = acceptsSpacing && last ? { ...last, spacingFactor: input.spacingFactor } : last;\n if (acceptsSpacing) state.optimizedSpacingRef.current = null;\n state.latestUpdateRef.current = input;\n state.fitPaddingRef.current = input.fitPadding ?? 50;\n state.viewport.configure(input);\n const preservesTopology = shouldPreserveTopology(state, previous, input);\n const retainedNodeIds = getRetainedNodeIds(previous, input, preservesTopology);\n const retainedGeometry =\n retainedNodeIds === null ? null : getGraphGeometryKey(state.cy, retainedNodeIds);\n state.cy.batch(() => {\n if (previous?.nodes !== input.nodes || previous.edges !== input.edges) {\n syncGraphElements(state.cy, input.nodes, input.edges);\n if (preservesTopology) placeAddedGraphNodes(state.cy, previous?.nodes ?? [], input.nodes);\n }\n if (\n previous?.styleRules !== input.styleRules ||\n previous?.richNodeRendering !== input.richNodeRendering\n ) {\n state.loopSizer.reset();\n applyGraphStyles(state.cy, input.styleRules, input.richNodeRendering);\n }\n });\n sizeGraphNodesToLabels(\n state.cy,\n state.labelSizedNodeIds,\n input.sizeNodesToLabels === true && !input.richNodeRendering,\n );\n applyKnownNodeSizes(state);\n state.loopSizer.update();\n const geometry = getGraphGeometryKey(state.cy);\n // Keep native double-press targets stable for paint-only class changes. A class that changes\n // measured node dimensions remains a geometry change and must relayout.\n const geometryChanged =\n retainedGeometry === null\n ? geometry !== state.geometryRef.current\n : retainedGeometry !== getGraphGeometryKey(state.cy, retainedNodeIds ?? undefined);\n const relayout = hasGraphLayoutChanged(previous, input, preservesTopology) || geometryChanged;\n state.geometryRef.current = geometry;\n if (!relayout) {\n if (\n previous?.zoomMode !== input.zoomMode ||\n previous?.fitPadding !== input.fitPadding ||\n previous?.minZoom !== input.minZoom ||\n previous?.maxZoom !== input.maxZoom ||\n previous?.minReadableLabelSize !== input.minReadableLabelSize ||\n previous?.maxFitLabelSize !== input.maxFitLabelSize\n ) {\n state.viewport.settle(previous?.zoomMode !== input.zoomMode);\n }\n emitRenderedNodes(state);\n return;\n }\n stopCurrentLayout(state);\n state.fitRequestRef.current = null;\n state.optimizedSpacingRef.current = null;\n startCurrentLayout(state, input);\n}\n\n/*** Preserve only opt-in topology updates after the initial layout and fit have settled. */\nfunction shouldPreserveTopology(\n state: GraphRuntimeState,\n previous: GraphRuntimeUpdate | null,\n input: GraphRuntimeUpdate,\n): boolean {\n return (\n previous !== null &&\n state.readyRef.current &&\n !state.pendingInitialFitRef.current &&\n input.topologyUpdatePolicy === 'preserve-positions'\n );\n}\n\n/*** Limit stable-update geometry checks to nodes that existed before reconciliation. */\nfunction getRetainedNodeIds(\n previous: GraphRuntimeUpdate | null,\n input: GraphRuntimeUpdate,\n preservesTopology: boolean,\n): ReadonlySet<string> | null {\n if (!preservesTopology || previous === null) return null;\n const nextNodeIds = new Set(input.nodes.map((node) => node.id));\n return new Set(previous.nodes.map((node) => node.id).filter((id) => nextNodeIds.has(id)));\n}\n\n/*** Start a generation-safe layout whose completion is the only normal automatic fit trigger. */\nfunction startCurrentLayout(state: GraphRuntimeState, input: GraphRuntimeUpdate) {\n state.pendingInitialFitRef.current = false;\n const generation = state.generationRef.current + 1;\n state.generationRef.current = generation;\n state.layoutRunningRef.current = true;\n state.cy.resize();\n state.layoutRef.current = runGraphLayout(\n state.cy,\n {\n layout: input.layout ?? 'concentric',\n layoutOptions: input.layoutOptions,\n spacingFactor: input.spacingFactor ?? 1,\n },\n () => completeCurrentLayout(state, generation),\n );\n}\n\n/***\n * Settle only the latest layout generation and fit once from node bounds.\n * Discard stale completions and avoid repeated automatic fits.\n */\nfunction completeCurrentLayout(state: GraphRuntimeState, generation: number) {\n scheduleGraphFrame(() => {\n if (state.cy.destroyed() || generation !== state.generationRef.current) return;\n state.loopSizer.update();\n state.layoutRef.current = null;\n state.cy.resize();\n state.layoutRunningRef.current = false;\n state.resizeObserver?.flushAfterLayout();\n if (!hasUsableViewport(state.cy)) {\n if (!state.readyRef.current) state.pendingInitialFitRef.current = true;\n return;\n }\n state.pendingInitialFitRef.current = false;\n const input = state.latestUpdateRef.current;\n if (input === null) return;\n const topology = getGraphTopologyKey(input.nodes, input.edges);\n const shouldFit = shouldFitGraphAfterLayout(\n state.readyRef.current,\n topology !== state.settledTopologyRef.current,\n input.layout !== state.settledLayoutRef.current,\n );\n state.viewport.settle(shouldFit);\n state.settledLayoutRef.current = input.layout;\n state.settledTopologyRef.current = topology;\n const fitRequest = state.fitRequestRef.current;\n state.fitRequestRef.current = null;\n if (fitRequest) requestOptimizedFit(state, fitRequest);\n emitRenderedNodes(state);\n\n if (!state.readyRef.current) {\n state.readyRef.current = true;\n state.callbacksRef.current.onReady?.(state.controller);\n }\n state.callbacksRef.current.onLayoutComplete?.(state.controller);\n });\n}\n\n/***\n * Handle explicit readable-fit intent in the runtime owner, never from zoom or React effects.\n * Bounded spacing optimization preserves the settled algorithm instead of repeatedly running it.\n */\nfunction requestOptimizedFit(state: GraphRuntimeState, options: GraphViewFitOptions) {\n if (state.cy.destroyed()) return;\n if (state.layoutRunningRef.current) {\n state.fitRequestRef.current = options;\n return;\n }\n const input = state.latestUpdateRef.current;\n if (!input) return;\n const previous = state.optimizedSpacingRef.current ?? input.spacingFactor ?? 1;\n const spacing = compactGraphSpacing(state.cy, previous, {\n fitPadding: options.padding ?? state.fitPaddingRef.current,\n maxFitZoom: state.viewport.getFitZoomLimit(),\n minReadableZoom: state.viewport.getReadableZoomTarget(),\n });\n state.geometryRef.current = getGraphGeometryKey(state.cy);\n state.loopSizer.update();\n state.viewport.settle(false);\n state.controller.fit({ ...options, optimizeSpacing: false });\n if (spacing !== previous) {\n state.optimizedSpacingRef.current = spacing;\n state.callbacksRef.current.onSpacingFactorChange?.(spacing);\n }\n emitRenderedNodes(state);\n}\n\n/*** Stop the current layout and invalidate every stale completion callback. */\nfunction stopCurrentLayout(state: GraphRuntimeState) {\n state.generationRef.current += 1;\n state.layoutRunningRef.current = false;\n state.layoutRef.current?.stop();\n state.layoutRef.current = null;\n}\n\n/*** Apply consumer styles and hide native node paint only when React rich nodes are active. */\nfunction applyGraphStyles(\n cy: Core,\n rules: readonly GraphViewStyleRule[] | undefined,\n richNodeRendering: boolean,\n) {\n const styles = [...(rules ?? [])];\n if (richNodeRendering) {\n styles.push({\n selector: 'node',\n style: {\n 'background-opacity': 0,\n 'border-width': 0,\n label: '',\n 'overlay-opacity': 0,\n },\n });\n }\n if (styles.length > 0) cy.style(styles).update();\n}\n\n/***\n * Synchronize controlled selection without rerunning layout.\n * Selection updates must not trigger graph reconstruction or layout.\n */\nfunction setSelectedNodeIds(state: GraphRuntimeState, nodeIds: readonly string[] | undefined) {\n if (state.cy.destroyed() || nodeIds === undefined) return;\n const selectedIds = new Set(nodeIds);\n state.cy.nodes().forEach((node) => {\n if (selectedIds.has(node.id())) node.select();\n else node.unselect();\n });\n emitRenderedNodes(state);\n}\n\n/***\n * Persist one rich-node size and schedule at most one relayout for changed geometry.\n * Ignore unchanged measurements before scheduling layout work.\n */\nfunction setNodeSize(state: GraphRuntimeState, id: string, size: GraphViewSize) {\n const previous = state.nodeSizes.get(id);\n if (previous?.width === size.width && previous.height === size.height) return;\n state.nodeSizes.set(id, size);\n applyNodeSize(state.cy, id, size);\n scheduleMeasuredNodeRelayout(state);\n}\n\n/*** Apply every known rich-node size after Cytoscape elements are replaced. */\nfunction applyKnownNodeSizes(state: GraphRuntimeState) {\n for (const [id, size] of state.nodeSizes) applyNodeSize(state.cy, id, size);\n}\n\n/*** Apply one measured model-space size as a Cytoscape per-node style bypass. */\nfunction applyNodeSize(cy: Core, id: string, size: GraphViewSize) {\n const node = cy.getElementById(id);\n if (node.empty()) return;\n node.style({ height: size.height, width: size.width });\n}\n\n/***\n * Coalesce DOM measurements into one follow-up layout generation.\n * Keep one scheduled layout per frame instead of one per measured node.\n */\nfunction scheduleMeasuredNodeRelayout(state: GraphRuntimeState) {\n if (state.relayoutScheduledRef.current) return;\n state.relayoutScheduledRef.current = true;\n scheduleGraphFrame(() => {\n state.relayoutScheduledRef.current = false;\n const input = state.latestUpdateRef.current;\n if (input === null || state.cy.destroyed()) return;\n stopCurrentLayout(state);\n startCurrentLayout(state, input);\n });\n}\n\n/*** Subscribe one React overlay to rendered node state without exposing the Cytoscape core. */\nfunction subscribeRenderedNodes(state: GraphRuntimeState, listener: RenderedNodeListener) {\n state.renderedNodeListeners.add(listener);\n listener(readGraphRenderedNodes(state.cy, state.hoveredNodeIds));\n return () => {\n state.renderedNodeListeners.delete(listener);\n };\n}\n\n/***\n * Publish current rendered node positions only to active rich-node subscribers.\n * Skip snapshot preparation when no overlay is subscribed.\n */\nfunction emitRenderedNodes(\n state: Pick<GraphRuntimeState, 'cy' | 'hoveredNodeIds' | 'renderedNodeListeners'>,\n) {\n if (state.renderedNodeListeners.size === 0) return;\n const nodes = readGraphRenderedNodes(state.cy, state.hoveredNodeIds);\n for (const listener of state.renderedNodeListeners) listener(nodes);\n}\n\n/*** Translate one rich-overlay event back into normal graph selection and callbacks. */\nfunction handleOverlayNodeEvent(\n state: GraphRuntimeState,\n id: string,\n type: GraphViewElementEventType,\n selectionIntent?: SelectionIntent,\n) {\n if (type === 'pointer-enter') state.hoveredNodeIds.add(id);\n if (type === 'pointer-leave') state.hoveredNodeIds.delete(id);\n if (type === 'press') state.cy.getElementById(id).select();\n state.callbacksRef.current.onNodeEvent?.({ id, type, selectionIntent });\n emitRenderedNodes(state);\n}\n\n/*** Return whether Cytoscape currently has dimensions suitable for fitting. */\nfunction hasUsableViewport(cy: Core): boolean {\n return cy.width() > 0 && cy.height() > 0;\n}\n\n/*** Dispose all runtime resources in the reverse order they were acquired. */\nfunction destroyRuntime(state: GraphRuntimeState) {\n state.resizeObserver?.disconnect();\n stopCurrentLayout(state);\n state.unbindEvents();\n state.renderedNodeListeners.clear();\n if (!state.cy.destroyed()) state.cy.destroy();\n}\n\nregisterGraphLayouts();\n"]}
1
+ {"version":3,"file":"createGraphRuntime.js","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,EAAE,EAAoC,MAAM,WAAW,CAAC;AAWxE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,yBAAyB,EAA4B,MAAM,6BAA6B,CAAC;AAClG,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AA8CxD,6FAA6F;AAC7F,MAAM,UAAU,kBAAkB,CAChC,SAAyB,EACzB,YAA6C,EAC7C,wBAAqD,GAAG,EAAE,CAAC,IAAI;IAE/D,MAAM,EAAE,GAAG,SAA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BAAiB,CAAC,KAAK,CAAC,CAAC;IACzB,KAAK,CAAC,YAAY,EAAE,CAAC;IACrB,KAAK,CAAC,qBAAqB,CAAC,KAAK,EAAE,CAAC;IACpC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE;QAAE,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC;AAChD,CAAC;AAED,oBAAoB,EAAE,CAAC","sourcesContent":["import type { SelectionIntent } from '@ankhorage/utility/selection';\nimport cytoscape, { type Core, type CytoscapeOptions } from 'cytoscape';\n\nimport type {\n GraphViewCallbacks,\n GraphViewElementEventType,\n GraphViewFitOptions,\n GraphViewRenderedNode,\n GraphViewSize,\n GraphViewStyleRule,\n} from '../../../../../types/graph-view';\nimport type { GraphRuntimeUpdate } from '../../../../../types/graphViewRuntime';\nimport { bindGraphEvents } from './bindGraphEvents';\nimport { compactGraphSpacing } from './compactGraphSpacing';\nimport { createGraphController } from './createGraphController';\nimport { createGraphLoopSizer } from './createGraphLoopSizer';\nimport { createGraphResizeObserver, type GraphResizeObserver } from './createGraphResizeObserver';\nimport { getGraphGeometryKey } from './getGraphGeometryKey';\nimport { getGraphTopologyKey } from './getGraphTopologyKey';\nimport { hasGraphLayoutChanged } from './hasGraphLayoutChanged';\nimport { placeAddedGraphNodes } from './placeAddedGraphNodes';\nimport { readGraphRenderedNodes } from './readGraphRenderedNodes';\nimport { registerGraphLayouts } from './registerGraphLayouts';\nimport { runGraphLayout } from './runGraphLayout';\nimport { scheduleGraphFrame } from './scheduleGraphFrame';\nimport { shouldFitGraphAfterLayout } from './shouldFitGraphAfterLayout';\nimport { sizeGraphNodesToLabels } from './sizeGraphNodesToLabels';\nimport { syncGraphElements } from './syncGraphElements';\n\ntype GraphContainer = CytoscapeOptions['container'];\ntype RenderedNodeListener = (nodes: readonly GraphViewRenderedNode[]) => void;\n\nexport interface GraphRuntime {\n destroy(): void;\n handleOverlayNodeEvent(\n id: string,\n type: GraphViewElementEventType,\n selectionIntent?: SelectionIntent,\n ): void;\n setNodeSize(id: string, size: GraphViewSize): void;\n setSelectedNodeIds(nodeIds: readonly string[] | undefined): void;\n subscribeRenderedNodes(listener: RenderedNodeListener): () => void;\n update(input: GraphRuntimeUpdate): void;\n}\n\ninterface GraphRuntimeState {\n readonly fitRequestRef: { current: GraphViewFitOptions | null };\n readonly optimizedSpacingRef: { current: number | null };\n readonly callbacksRef: { current: GraphViewCallbacks };\n readonly controller: ReturnType<typeof createGraphController>['controller'];\n readonly viewport: ReturnType<typeof createGraphController>;\n readonly cy: Core;\n readonly fitPaddingRef: { current: number };\n readonly generationRef: { current: number };\n readonly geometryRef: { current: string | null };\n readonly hoveredNodeIds: Set<string>;\n readonly initialLayoutScheduledRef: { current: boolean };\n readonly latestUpdateRef: { current: GraphRuntimeUpdate | null };\n readonly layoutRef: { current: ReturnType<typeof runGraphLayout> | null };\n readonly layoutRunningRef: { current: boolean };\n readonly nodeSizes: Map<string, GraphViewSize>;\n readonly labelSizedNodeIds: Set<string>;\n readonly loopSizer: ReturnType<typeof createGraphLoopSizer>;\n readonly pendingInitialFitRef: { current: boolean };\n readonly readyRef: { current: boolean };\n readonly settledLayoutRef: { current: GraphRuntimeUpdate['layout'] | null };\n readonly settledTopologyRef: { current: string | null };\n readonly relayoutScheduledRef: { current: boolean };\n readonly renderedNodeListeners: Set<RenderedNodeListener>;\n readonly resizeObserver: GraphResizeObserver | null;\n readonly unbindEvents: () => void;\n}\n\n/*** Create one Cytoscape runtime that exclusively owns layout, fit, resize, and disposal. */\nexport function createGraphRuntime(\n container: GraphContainer,\n callbacksRef: { current: GraphViewCallbacks },\n readLatestPointerDown: (event: unknown) => unknown = () => null,\n): GraphRuntime {\n const cy = cytoscape({\n container,\n elements: [],\n minZoom: 0.05,\n maxZoom: 2,\n selectionType: 'additive',\n userPanningEnabled: true,\n });\n const state = createRuntimeState(cy, container, callbacksRef, readLatestPointerDown);\n\n return {\n destroy: () => destroyRuntime(state),\n handleOverlayNodeEvent: (id, type, selectionIntent) =>\n handleOverlayNodeEvent(state, id, type, selectionIntent),\n setNodeSize: (id, size) => setNodeSize(state, id, size),\n setSelectedNodeIds: (nodeIds) => setSelectedNodeIds(state, nodeIds),\n subscribeRenderedNodes: (listener) => subscribeRenderedNodes(state, listener),\n update: (input) => updateRuntime(state, input),\n };\n}\n\n/*** Build the mutable state shared by the single graph-runtime owner. */\nfunction createRuntimeState(\n cy: Core,\n container: GraphContainer,\n callbacksRef: { current: GraphViewCallbacks },\n readLatestPointerDown: (event: unknown) => unknown,\n): GraphRuntimeState {\n const fitPaddingRef = { current: 50 };\n const viewport = createGraphController(cy, fitPaddingRef, (options) =>\n requestOptimizedFit(state, options),\n );\n const { controller } = viewport;\n const layoutRunningRef = { current: false };\n const readyRef = { current: false };\n const renderedNodeListeners = new Set<RenderedNodeListener>();\n const stateBase = {\n fitRequestRef: { current: null as GraphViewFitOptions | null },\n optimizedSpacingRef: { current: null as number | null },\n callbacksRef,\n controller,\n viewport,\n cy,\n fitPaddingRef,\n generationRef: { current: 0 },\n geometryRef: { current: null as string | null },\n hoveredNodeIds: new Set<string>(),\n initialLayoutScheduledRef: { current: false },\n latestUpdateRef: { current: null as GraphRuntimeUpdate | null },\n layoutRef: { current: null as ReturnType<typeof runGraphLayout> | null },\n layoutRunningRef,\n nodeSizes: new Map<string, GraphViewSize>(),\n labelSizedNodeIds: new Set<string>(),\n loopSizer: createGraphLoopSizer(cy),\n pendingInitialFitRef: { current: false },\n readyRef,\n settledLayoutRef: { current: null as GraphRuntimeUpdate['layout'] | null },\n settledTopologyRef: { current: null as string | null },\n relayoutScheduledRef: { current: false },\n renderedNodeListeners,\n };\n const unbindEvents = bindGraphEvents(\n cy,\n callbacksRef,\n controller,\n () => emitRenderedNodes(stateBase),\n readLatestPointerDown,\n );\n const resizeObserver = createGraphResizeObserver({\n container,\n cy,\n beginViewportResize: () => viewport.beginResize(),\n settleViewport: (fit) => viewport.settle(fit),\n layoutRunningRef,\n pendingInitialFitRef: stateBase.pendingInitialFitRef,\n onViewportSettled: (completedPendingInitialFit) => {\n emitRenderedNodes(stateBase);\n if (!completedPendingInitialFit || readyRef.current) return;\n readyRef.current = true;\n callbacksRef.current.onReady?.(controller);\n callbacksRef.current.onLayoutComplete?.(controller);\n },\n readyRef,\n });\n\n const state = { ...stateBase, resizeObserver, unbindEvents };\n return state;\n}\n\n/***\n * Reconcile presentation in place and relayout only when graph geometry or layout policy changes.\n * Batch reconciliation and skip layout for presentation-only updates.\n */\nfunction updateRuntime(state: GraphRuntimeState, input: GraphRuntimeUpdate) {\n if (state.cy.destroyed()) return;\n const last = state.latestUpdateRef.current;\n const acceptsSpacing =\n state.optimizedSpacingRef.current !== null &&\n state.optimizedSpacingRef.current === input.spacingFactor;\n const previous = acceptsSpacing && last ? { ...last, spacingFactor: input.spacingFactor } : last;\n if (acceptsSpacing) state.optimizedSpacingRef.current = null;\n state.latestUpdateRef.current = input;\n state.fitPaddingRef.current = input.fitPadding ?? 50;\n state.viewport.configure(input);\n const preservesTopology = shouldPreserveTopology(state, previous, input);\n const retainedNodeIds = getRetainedNodeIds(previous, input, preservesTopology);\n const retainedGeometry =\n retainedNodeIds === null ? null : getGraphGeometryKey(state.cy, retainedNodeIds);\n state.cy.batch(() => {\n if (previous?.nodes !== input.nodes || previous.edges !== input.edges) {\n syncGraphElements(state.cy, input.nodes, input.edges);\n if (preservesTopology) placeAddedGraphNodes(state.cy, previous?.nodes ?? [], input.nodes);\n }\n if (\n previous?.styleRules !== input.styleRules ||\n previous?.richNodeRendering !== input.richNodeRendering\n ) {\n state.loopSizer.reset();\n applyGraphStyles(state.cy, input.styleRules, input.richNodeRendering);\n }\n });\n sizeGraphNodesToLabels(\n state.cy,\n state.labelSizedNodeIds,\n input.sizeNodesToLabels === true && !input.richNodeRendering,\n );\n applyKnownNodeSizes(state);\n state.loopSizer.update();\n const geometry = getGraphGeometryKey(state.cy);\n // Keep native double-press targets stable for paint-only class changes. A class that changes\n // measured node dimensions remains a geometry change and must relayout.\n const geometryChanged =\n retainedGeometry === null\n ? geometry !== state.geometryRef.current\n : retainedGeometry !== getGraphGeometryKey(state.cy, retainedNodeIds ?? undefined);\n const relayout = hasGraphLayoutChanged(previous, input, preservesTopology) || geometryChanged;\n state.geometryRef.current = geometry;\n if (!relayout) {\n if (\n previous?.zoomMode !== input.zoomMode ||\n previous?.fitPadding !== input.fitPadding ||\n previous?.minZoom !== input.minZoom ||\n previous?.maxZoom !== input.maxZoom ||\n previous?.minReadableLabelSize !== input.minReadableLabelSize ||\n previous?.maxFitLabelSize !== input.maxFitLabelSize\n ) {\n state.viewport.settle(previous?.zoomMode !== input.zoomMode);\n }\n emitRenderedNodes(state);\n return;\n }\n stopCurrentLayout(state);\n state.fitRequestRef.current = null;\n state.optimizedSpacingRef.current = null;\n startCurrentLayout(state, input);\n}\n\n/*** Preserve only opt-in topology updates after the initial layout and fit have settled. */\nfunction shouldPreserveTopology(\n state: GraphRuntimeState,\n previous: GraphRuntimeUpdate | null,\n input: GraphRuntimeUpdate,\n): boolean {\n return (\n previous !== null &&\n state.readyRef.current &&\n !state.pendingInitialFitRef.current &&\n input.topologyUpdatePolicy === 'preserve-positions'\n );\n}\n\n/*** Limit stable-update geometry checks to nodes that existed before reconciliation. */\nfunction getRetainedNodeIds(\n previous: GraphRuntimeUpdate | null,\n input: GraphRuntimeUpdate,\n preservesTopology: boolean,\n): ReadonlySet<string> | null {\n if (!preservesTopology || previous === null) return null;\n const nextNodeIds = new Set(input.nodes.map((node) => node.id));\n return new Set(previous.nodes.map((node) => node.id).filter((id) => nextNodeIds.has(id)));\n}\n\n/*** Start a generation-safe layout whose completion is the only normal automatic fit trigger. */\nfunction startCurrentLayout(state: GraphRuntimeState, input: GraphRuntimeUpdate) {\n if (!state.readyRef.current) {\n scheduleInitialLayout(state);\n return;\n }\n startGraphLayout(state, input);\n}\n\n/*** Coalesce progressive pre-ready topology updates before the initial layout can complete. */\nfunction scheduleInitialLayout(state: GraphRuntimeState) {\n if (state.initialLayoutScheduledRef.current) return;\n state.initialLayoutScheduledRef.current = true;\n scheduleGraphFrame(() => {\n scheduleGraphFrame(() => {\n state.initialLayoutScheduledRef.current = false;\n const input = state.latestUpdateRef.current;\n if (input === null || state.cy.destroyed() || state.readyRef.current) return;\n startGraphLayout(state, input);\n });\n });\n}\n\n/*** Start one layout generation after its input has reached the runtime owner. */\nfunction startGraphLayout(state: GraphRuntimeState, input: GraphRuntimeUpdate) {\n state.pendingInitialFitRef.current = false;\n const generation = state.generationRef.current + 1;\n state.generationRef.current = generation;\n state.layoutRunningRef.current = true;\n state.cy.resize();\n state.layoutRef.current = runGraphLayout(\n state.cy,\n {\n layout: input.layout ?? 'concentric',\n layoutOptions: input.layoutOptions,\n spacingFactor: input.spacingFactor ?? 1,\n },\n () => completeCurrentLayout(state, generation),\n );\n}\n\n/***\n * Settle only the latest layout generation and fit once from node bounds.\n * Discard stale completions and avoid repeated automatic fits.\n */\nfunction completeCurrentLayout(state: GraphRuntimeState, generation: number) {\n scheduleGraphFrame(() => {\n if (state.cy.destroyed() || generation !== state.generationRef.current) return;\n state.loopSizer.update();\n state.layoutRef.current = null;\n state.cy.resize();\n state.layoutRunningRef.current = false;\n state.resizeObserver?.flushAfterLayout();\n if (!hasUsableViewport(state.cy)) {\n if (!state.readyRef.current) state.pendingInitialFitRef.current = true;\n return;\n }\n state.pendingInitialFitRef.current = false;\n const input = state.latestUpdateRef.current;\n if (input === null) return;\n const topology = getGraphTopologyKey(input.nodes, input.edges);\n const shouldFit = shouldFitGraphAfterLayout(\n state.readyRef.current,\n topology !== state.settledTopologyRef.current,\n input.layout !== state.settledLayoutRef.current,\n );\n state.viewport.settle(shouldFit);\n state.settledLayoutRef.current = input.layout;\n state.settledTopologyRef.current = topology;\n const fitRequest = state.fitRequestRef.current;\n state.fitRequestRef.current = null;\n if (fitRequest) requestOptimizedFit(state, fitRequest);\n emitRenderedNodes(state);\n\n if (!state.readyRef.current) {\n state.readyRef.current = true;\n state.callbacksRef.current.onReady?.(state.controller);\n }\n state.callbacksRef.current.onLayoutComplete?.(state.controller);\n });\n}\n\n/***\n * Handle explicit readable-fit intent in the runtime owner, never from zoom or React effects.\n * Bounded spacing optimization preserves the settled algorithm instead of repeatedly running it.\n */\nfunction requestOptimizedFit(state: GraphRuntimeState, options: GraphViewFitOptions) {\n if (state.cy.destroyed()) return;\n if (state.layoutRunningRef.current) {\n state.fitRequestRef.current = options;\n return;\n }\n const input = state.latestUpdateRef.current;\n if (!input) return;\n const previous = state.optimizedSpacingRef.current ?? input.spacingFactor ?? 1;\n const spacing = compactGraphSpacing(state.cy, previous, {\n fitPadding: options.padding ?? state.fitPaddingRef.current,\n maxFitZoom: state.viewport.getFitZoomLimit(),\n minReadableZoom: state.viewport.getReadableZoomTarget(),\n });\n state.geometryRef.current = getGraphGeometryKey(state.cy);\n state.loopSizer.update();\n state.viewport.settle(false);\n state.controller.fit({ ...options, optimizeSpacing: false });\n if (spacing !== previous) {\n state.optimizedSpacingRef.current = spacing;\n state.callbacksRef.current.onSpacingFactorChange?.(spacing);\n }\n emitRenderedNodes(state);\n}\n\n/*** Stop the current layout and invalidate every stale completion callback. */\nfunction stopCurrentLayout(state: GraphRuntimeState) {\n state.generationRef.current += 1;\n state.layoutRunningRef.current = false;\n state.layoutRef.current?.stop();\n state.layoutRef.current = null;\n}\n\n/*** Apply consumer styles and hide native node paint only when React rich nodes are active. */\nfunction applyGraphStyles(\n cy: Core,\n rules: readonly GraphViewStyleRule[] | undefined,\n richNodeRendering: boolean,\n) {\n const styles = [...(rules ?? [])];\n if (richNodeRendering) {\n styles.push({\n selector: 'node',\n style: {\n 'background-opacity': 0,\n 'border-width': 0,\n label: '',\n 'overlay-opacity': 0,\n },\n });\n }\n if (styles.length > 0) cy.style(styles).update();\n}\n\n/***\n * Synchronize controlled selection without rerunning layout.\n * Selection updates must not trigger graph reconstruction or layout.\n */\nfunction setSelectedNodeIds(state: GraphRuntimeState, nodeIds: readonly string[] | undefined) {\n if (state.cy.destroyed() || nodeIds === undefined) return;\n const selectedIds = new Set(nodeIds);\n state.cy.nodes().forEach((node) => {\n if (selectedIds.has(node.id())) node.select();\n else node.unselect();\n });\n emitRenderedNodes(state);\n}\n\n/***\n * Persist one rich-node size and schedule at most one relayout for changed geometry.\n * Ignore unchanged measurements before scheduling layout work.\n */\nfunction setNodeSize(state: GraphRuntimeState, id: string, size: GraphViewSize) {\n const previous = state.nodeSizes.get(id);\n if (previous?.width === size.width && previous.height === size.height) return;\n state.nodeSizes.set(id, size);\n applyNodeSize(state.cy, id, size);\n scheduleMeasuredNodeRelayout(state);\n}\n\n/*** Apply every known rich-node size after Cytoscape elements are replaced. */\nfunction applyKnownNodeSizes(state: GraphRuntimeState) {\n for (const [id, size] of state.nodeSizes) applyNodeSize(state.cy, id, size);\n}\n\n/*** Apply one measured model-space size as a Cytoscape per-node style bypass. */\nfunction applyNodeSize(cy: Core, id: string, size: GraphViewSize) {\n const node = cy.getElementById(id);\n if (node.empty()) return;\n node.style({ height: size.height, width: size.width });\n}\n\n/***\n * Coalesce DOM measurements into one follow-up layout generation.\n * Keep one scheduled layout per frame instead of one per measured node.\n */\nfunction scheduleMeasuredNodeRelayout(state: GraphRuntimeState) {\n if (state.relayoutScheduledRef.current) return;\n state.relayoutScheduledRef.current = true;\n scheduleGraphFrame(() => {\n state.relayoutScheduledRef.current = false;\n const input = state.latestUpdateRef.current;\n if (input === null || state.cy.destroyed()) return;\n stopCurrentLayout(state);\n startCurrentLayout(state, input);\n });\n}\n\n/*** Subscribe one React overlay to rendered node state without exposing the Cytoscape core. */\nfunction subscribeRenderedNodes(state: GraphRuntimeState, listener: RenderedNodeListener) {\n state.renderedNodeListeners.add(listener);\n listener(readGraphRenderedNodes(state.cy, state.hoveredNodeIds));\n return () => {\n state.renderedNodeListeners.delete(listener);\n };\n}\n\n/***\n * Publish current rendered node positions only to active rich-node subscribers.\n * Skip snapshot preparation when no overlay is subscribed.\n */\nfunction emitRenderedNodes(\n state: Pick<GraphRuntimeState, 'cy' | 'hoveredNodeIds' | 'renderedNodeListeners'>,\n) {\n if (state.renderedNodeListeners.size === 0) return;\n const nodes = readGraphRenderedNodes(state.cy, state.hoveredNodeIds);\n for (const listener of state.renderedNodeListeners) listener(nodes);\n}\n\n/*** Translate one rich-overlay event back into normal graph selection and callbacks. */\nfunction handleOverlayNodeEvent(\n state: GraphRuntimeState,\n id: string,\n type: GraphViewElementEventType,\n selectionIntent?: SelectionIntent,\n) {\n if (type === 'pointer-enter') state.hoveredNodeIds.add(id);\n if (type === 'pointer-leave') state.hoveredNodeIds.delete(id);\n if (type === 'press') state.cy.getElementById(id).select();\n state.callbacksRef.current.onNodeEvent?.({ id, type, selectionIntent });\n emitRenderedNodes(state);\n}\n\n/*** Return whether Cytoscape currently has dimensions suitable for fitting. */\nfunction hasUsableViewport(cy: Core): boolean {\n return cy.width() > 0 && cy.height() > 0;\n}\n\n/*** Dispose all runtime resources in the reverse order they were acquired. */\nfunction destroyRuntime(state: GraphRuntimeState) {\n state.resizeObserver?.disconnect();\n stopCurrentLayout(state);\n state.unbindEvents();\n state.renderedNodeListeners.clear();\n if (!state.cy.destroyed()) state.cy.destroy();\n}\n\nregisterGraphLayouts();\n"]}
@@ -1,5 +1,5 @@
1
1
  import { type SelectionActivationKind } from '@ankhorage/utility/interaction';
2
2
  import type { SelectionIntent } from '@ankhorage/utility/selection';
3
3
  /*** Normalize DOM, React Native, and renderer events into one semantic selection intent. */
4
- export declare function resolveSelectionEventIntent(event: unknown, fallbackKind: SelectionActivationKind): SelectionIntent;
4
+ export declare function resolveSelectionEventIntent(event: unknown, fallbackKind: SelectionActivationKind, nativeEvent?: unknown): SelectionIntent;
5
5
  //# sourceMappingURL=resolveSelectionEventIntent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolveSelectionEventIntent.d.ts","sourceRoot":"","sources":["../../../../src/features/selection/application/resolveSelectionEventIntent.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,uBAAuB,EAE7B,MAAM,gCAAgC,CAAC;AAExC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAEpE,4FAA4F;AAC5F,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,OAAO,EACd,YAAY,EAAE,uBAAuB,GACpC,eAAe,CAejB"}
1
+ {"version":3,"file":"resolveSelectionEventIntent.d.ts","sourceRoot":"","sources":["../../../../src/features/selection/application/resolveSelectionEventIntent.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,uBAAuB,EAE7B,MAAM,gCAAgC,CAAC;AAExC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAEpE,4FAA4F;AAC5F,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,OAAO,EACd,YAAY,EAAE,uBAAuB,EACrC,WAAW,GAAE,OAAY,GACxB,eAAe,CA4BjB"}