symbiote-ui 0.3.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/LICENSE +21 -0
- package/README.md +76 -0
- package/canvas/AutoLayout.js +731 -0
- package/canvas/Breadcrumb/Breadcrumb.css.js +75 -0
- package/canvas/Breadcrumb/Breadcrumb.js +96 -0
- package/canvas/Breadcrumb/Breadcrumb.tpl.js +7 -0
- package/canvas/CanvasConnectionRenderer.js +971 -0
- package/canvas/CanvasGraph/CanvasGraph.css.js +29 -0
- package/canvas/CanvasGraph/CanvasGraph.js +1697 -0
- package/canvas/CanvasGraph/CanvasGraphDrawState.js +280 -0
- package/canvas/CanvasGraph/CanvasGraphGeometry.js +194 -0
- package/canvas/CanvasViewport.js +550 -0
- package/canvas/ConnectionRenderer.js +1283 -0
- package/canvas/FlowSimulator.js +326 -0
- package/canvas/ForceLayout.js +226 -0
- package/canvas/ForceWorker.js +1303 -0
- package/canvas/FrameManager.js +223 -0
- package/canvas/GraphExplorerShell/GraphExplorerShell.css.js +136 -0
- package/canvas/GraphExplorerShell/GraphExplorerShell.js +129 -0
- package/canvas/GraphExplorerShell/GraphExplorerShell.tpl.js +12 -0
- package/canvas/GraphTabs/GraphTabs.css.js +101 -0
- package/canvas/GraphTabs/GraphTabs.js +189 -0
- package/canvas/GraphTabs/GraphTabs.tpl.js +12 -0
- package/canvas/LODManager.js +88 -0
- package/canvas/Minimap/Minimap.css.js +73 -0
- package/canvas/Minimap/Minimap.js +210 -0
- package/canvas/Minimap/Minimap.tpl.js +7 -0
- package/canvas/NodeCanvas/NodeCanvas.css.js +398 -0
- package/canvas/NodeCanvas/NodeCanvas.js +1499 -0
- package/canvas/NodeCanvas/NodeCanvas.tpl.js +22 -0
- package/canvas/NodeSearch/NodeSearch.css.js +97 -0
- package/canvas/NodeSearch/NodeSearch.js +140 -0
- package/canvas/NodeSearch/NodeSearch.tpl.js +25 -0
- package/canvas/NodeViewManager.js +748 -0
- package/canvas/PcbRouteDiagnostics.js +463 -0
- package/canvas/PcbRouter.js +1127 -0
- package/canvas/PinExpansion.js +134 -0
- package/canvas/PseudoConnection.js +84 -0
- package/canvas/SelectionSync.js +163 -0
- package/canvas/SubgraphManager.js +203 -0
- package/canvas/SubgraphRouter.js +452 -0
- package/canvas/ViewportActions.js +473 -0
- package/canvas/graph-explorer.js +339 -0
- package/canvas/graph-layout.js +148 -0
- package/canvas/graph-model.js +68 -0
- package/canvas/html-in-canvas.js +202 -0
- package/canvas/project-graph-builder.js +440 -0
- package/canvas/project-graph-model.js +183 -0
- package/chat/ChatComposer/ChatComposer.css.js +652 -0
- package/chat/ChatComposer/ChatComposer.js +304 -0
- package/chat/ChatList/ChatList.css.js +102 -0
- package/chat/ChatList/ChatList.js +99 -0
- package/chat/ChatList/ChatList.tpl.js +20 -0
- package/chat/ChatListItem/ChatListItem.css.js +117 -0
- package/chat/ChatListItem/ChatListItem.js +32 -0
- package/chat/ChatListItem/ChatListItem.tpl.js +17 -0
- package/chat/ChatMessageItem/ChatMessageItem.css.js +628 -0
- package/chat/ChatMessageItem/ChatMessageItem.js +156 -0
- package/chat/ChatSidebar/ChatSidebar.css.js +150 -0
- package/chat/ChatSidebar/ChatSidebar.js +230 -0
- package/chat/ChatSidebar/ChatSidebar.tpl.js +18 -0
- package/chat/ChatSidebar/constants.js +11 -0
- package/chat/ChatSidebarItem/ChatSidebarItem.css.js +445 -0
- package/chat/ChatSidebarItem/ChatSidebarItem.js +304 -0
- package/chat/ChatTranscript/ChatTranscript.css.js +90 -0
- package/chat/ChatTranscript/ChatTranscript.js +244 -0
- package/chat/chat-context.js +123 -0
- package/chat/message-model.js +156 -0
- package/cli.js +20 -0
- package/control/Button/Button.css.js +93 -0
- package/control/Button/Button.js +78 -0
- package/control/Button/Button.tpl.js +3 -0
- package/control/Field/Field.css.js +91 -0
- package/control/Field/Field.js +17 -0
- package/control/Field/Field.tpl.js +3 -0
- package/core/Connection.js +47 -0
- package/core/Editor.js +449 -0
- package/core/Frame.js +33 -0
- package/core/GraphMermaid.js +348 -0
- package/core/GraphText.js +228 -0
- package/core/Node.js +145 -0
- package/core/Portal.js +106 -0
- package/core/Socket.js +187 -0
- package/core/SubgraphNode.js +121 -0
- package/core/base-path.js +55 -0
- package/core/dom-utils.js +14 -0
- package/core/index.js +18 -0
- package/core/local-cache.js +26 -0
- package/core/state-sync.js +227 -0
- package/custom-elements.json +6380 -0
- package/discover.js +240 -0
- package/display/Badge/Badge.css.js +44 -0
- package/display/Badge/Badge.js +17 -0
- package/display/Badge/Badge.tpl.js +3 -0
- package/display/Banner/Banner.css.js +61 -0
- package/display/Banner/Banner.js +17 -0
- package/display/Banner/Banner.tpl.js +3 -0
- package/display/CodeBlock/CodeBlock.css.js +194 -0
- package/display/CodeBlock/CodeBlock.js +220 -0
- package/display/CodeBlock/CodeBlock.tpl.js +11 -0
- package/display/DataTable/DataTable.css.js +101 -0
- package/display/DataTable/DataTable.js +136 -0
- package/display/DataTable/DataTable.tpl.js +13 -0
- package/display/EmptyState/EmptyState.css.js +33 -0
- package/display/EmptyState/EmptyState.js +17 -0
- package/display/EmptyState/EmptyState.tpl.js +3 -0
- package/display/EventFeed/EventFeed.css.js +145 -0
- package/display/EventFeed/EventFeed.js +64 -0
- package/display/EventFeed/EventFeed.tpl.js +14 -0
- package/display/EventFeed/EventFeedItem.js +116 -0
- package/display/EventFeed/EventFeedItem.tpl.js +22 -0
- package/display/LoadingOverlay/LoadingOverlay.css.js +91 -0
- package/display/LoadingOverlay/LoadingOverlay.js +48 -0
- package/display/LoadingOverlay/LoadingOverlay.tpl.js +12 -0
- package/display/Metric/Metric.css.js +60 -0
- package/display/Metric/Metric.js +17 -0
- package/display/Metric/Metric.tpl.js +6 -0
- package/display/OutputGraphPreview/OutputGraphPreview.css.js +122 -0
- package/display/OutputGraphPreview/OutputGraphPreview.js +89 -0
- package/display/OutputGraphPreview/OutputGraphPreview.tpl.js +13 -0
- package/display/OutputListPreview/OutputListPreview.css.js +109 -0
- package/display/OutputListPreview/OutputListPreview.js +77 -0
- package/display/OutputListPreview/OutputListPreview.tpl.js +13 -0
- package/display/SourceEditor/SourceEditor.css.js +39 -0
- package/display/SourceEditor/SourceEditor.js +129 -0
- package/display/SourceEditor/SourceEditor.tpl.js +10 -0
- package/display/SourceViewer/SourceViewer.css.js +80 -0
- package/display/SourceViewer/SourceViewer.js +418 -0
- package/display/SourceViewer/SourceViewer.tpl.js +17 -0
- package/display/StatusRibbon/StatusRibbon.css.js +73 -0
- package/display/StatusRibbon/StatusRibbon.js +87 -0
- package/display/StatusRibbon/StatusRibbon.tpl.js +7 -0
- package/display/event-feed-adapter.js +72 -0
- package/display/format-utils.js +29 -0
- package/display/highlight.js +659 -0
- package/display/icons.js +37 -0
- package/display/markdown-formatter.js +60 -0
- package/display/network-approval-page.js +487 -0
- package/display/output-preview.js +261 -0
- package/effects/CellBg/CellBg.css.js +33 -0
- package/effects/CellBg/CellBg.js +410 -0
- package/effects/CellBg/CellBg.tpl.js +5 -0
- package/graph/canvas-adapter.js +223 -0
- package/graph/graph-algorithms.js +31 -0
- package/graph/index.js +46 -0
- package/graph/model.js +176 -0
- package/graph/project-graph-build.js +66 -0
- package/graph/project-graph-metadata.js +253 -0
- package/graph/project-package.js +128 -0
- package/graph/project-runtime.js +116 -0
- package/graph/project-transaction.js +284 -0
- package/graph/skeleton-utils.js +84 -0
- package/graph/theme-contract.js +36 -0
- package/graph/transaction-parser.js +56 -0
- package/icons/MaterialSymbols.js +69 -0
- package/icons/material-symbols-outlined-400.ttf +0 -0
- package/icons/material-symbols.css +24 -0
- package/index.js +95 -0
- package/inspector/InspectorPanel/InspectorPanel.css.js +375 -0
- package/inspector/InspectorPanel/InspectorPanel.js +368 -0
- package/inspector/InspectorPanel/InspectorPanel.tpl.js +96 -0
- package/inspector/TemplatePreview/TemplatePreview.css.js +104 -0
- package/inspector/TemplatePreview/TemplatePreview.js +145 -0
- package/inspector/TemplatePreview/TemplatePreview.tpl.js +33 -0
- package/interactions/ConnectFlow.js +304 -0
- package/interactions/Drag.js +104 -0
- package/interactions/Selector.js +133 -0
- package/interactions/SnapGrid.js +66 -0
- package/interactions/Zoom.js +139 -0
- package/layout/ActionZone/ActionZone.css.js +88 -0
- package/layout/ActionZone/ActionZone.js +261 -0
- package/layout/ActionZone/ActionZone.tpl.js +11 -0
- package/layout/CrossLayoutPortalBridge/CrossLayoutPortalBridge.js +255 -0
- package/layout/Layout/Layout.css.js +91 -0
- package/layout/Layout/Layout.js +637 -0
- package/layout/Layout/Layout.tpl.js +27 -0
- package/layout/LayoutNode/LayoutNode.css.js +302 -0
- package/layout/LayoutNode/LayoutNode.js +509 -0
- package/layout/LayoutNode/LayoutNode.tpl.js +39 -0
- package/layout/LayoutPreview/LayoutPreview.css.js +46 -0
- package/layout/LayoutPreview/LayoutPreview.js +102 -0
- package/layout/LayoutPreview/LayoutPreview.tpl.js +6 -0
- package/layout/LayoutRouter/LayoutRouter.js +274 -0
- package/layout/LayoutRouter/SectionRegistry.js +135 -0
- package/layout/LayoutRouter/routerSync.js +250 -0
- package/layout/LayoutSidebar/LayoutSidebar.css.js +411 -0
- package/layout/LayoutSidebar/LayoutSidebar.js +368 -0
- package/layout/LayoutSidebar/LayoutSidebar.tpl.js +26 -0
- package/layout/LayoutSidebar/SidebarSection.css.js +20 -0
- package/layout/LayoutSidebar/SidebarSection.js +184 -0
- package/layout/LayoutSidebar/SidebarSection.tpl.js +22 -0
- package/layout/LayoutTree.js +373 -0
- package/layout/PanelMenu/PanelMenu.css.js +43 -0
- package/layout/PanelMenu/PanelMenu.js +95 -0
- package/layout/PanelMenu/PanelMenu.tpl.js +17 -0
- package/layout/ProjectTabs/ProjectTabs.css.js +188 -0
- package/layout/ProjectTabs/ProjectTabs.js +77 -0
- package/layout/ProjectTabs/ProjectTabs.tpl.js +15 -0
- package/layout/index.js +40 -0
- package/list/ListDetailShell/ListDetailShell.css.js +128 -0
- package/list/ListDetailShell/ListDetailShell.js +72 -0
- package/list/ListDetailShell/ListDetailShell.tpl.js +36 -0
- package/list/ListItem/ListItem.css.js +111 -0
- package/list/ListItem/ListItem.js +66 -0
- package/list/ListItem/ListItem.tpl.js +18 -0
- package/locale/index.js +503 -0
- package/manifest/component-registry.js +2446 -0
- package/manifest/graph-schema.js +285 -0
- package/manifest/index.js +6 -0
- package/manifest/project-schema-catalog.js +246 -0
- package/manifest/rule-catalog.js +201 -0
- package/manifest/theme-catalog.js +2149 -0
- package/manifest/ui-schema-catalog.js +334 -0
- package/menu/ContextMenu/ContextMenu.css.js +61 -0
- package/menu/ContextMenu/ContextMenu.js +82 -0
- package/menu/ContextMenu/ContextMenu.tpl.js +19 -0
- package/navigation/QuickOpen/QuickOpen.css.js +92 -0
- package/navigation/QuickOpen/QuickOpen.js +185 -0
- package/navigation/QuickOpen/QuickOpen.tpl.js +15 -0
- package/navigation/quick-open-utils.js +101 -0
- package/node/CtrlItem/CtrlItem.css.js +41 -0
- package/node/CtrlItem/CtrlItem.js +24 -0
- package/node/CtrlItem/CtrlItem.tpl.js +17 -0
- package/node/GraphFrame/GraphFrame.css.js +66 -0
- package/node/GraphFrame/GraphFrame.js +32 -0
- package/node/GraphFrame/GraphFrame.tpl.js +13 -0
- package/node/GraphNode/GraphNode.css.js +815 -0
- package/node/GraphNode/GraphNode.js +173 -0
- package/node/GraphNode/GraphNode.tpl.js +33 -0
- package/node/NodeCallout/NodeCallout.css.js +91 -0
- package/node/NodeCallout/NodeCallout.js +281 -0
- package/node/NodeCallout/NodeCallout.tpl.js +8 -0
- package/node/NodeSocket/NodeSocket.css.js +68 -0
- package/node/NodeSocket/NodeSocket.js +26 -0
- package/node/NodeSocket/NodeSocket.tpl.js +7 -0
- package/node/PortItem/PortItem.css.js +93 -0
- package/node/PortItem/PortItem.js +87 -0
- package/node/PortItem/PortItem.tpl.js +10 -0
- package/package.json +165 -0
- package/palette/PaletteBrowser/PaletteBrowser.css.js +143 -0
- package/palette/PaletteBrowser/PaletteBrowser.js +152 -0
- package/palette/PaletteBrowser/PaletteBrowser.tpl.js +23 -0
- package/plugins/History.js +408 -0
- package/plugins/Readonly.js +60 -0
- package/rules/symbiote-3x.json +170 -0
- package/schemas/component-descriptor-v1.json +91 -0
- package/schemas/component-descriptor-v2.json +145 -0
- package/schemas/graph-model-v1.json +179 -0
- package/schemas/graph-v1.json +91 -0
- package/schemas/project-package-v1.json +102 -0
- package/schemas/project-transaction-v1.json +114 -0
- package/schemas/runtime-ui-v1.json +80 -0
- package/schemas/theme-rule-block-v1.json +73 -0
- package/shapes/CircleShape.js +79 -0
- package/shapes/CommentShape.js +35 -0
- package/shapes/DiamondShape.js +130 -0
- package/shapes/NodeShape.js +79 -0
- package/shapes/PillShape.js +91 -0
- package/shapes/RectShape.js +84 -0
- package/shapes/SVGShape.js +525 -0
- package/shapes/index.js +63 -0
- package/surface/Card/Card.css.js +57 -0
- package/surface/Card/Card.js +17 -0
- package/surface/Card/Card.tpl.js +3 -0
- package/themes/Palette.js +30 -0
- package/themes/Skin.js +113 -0
- package/themes/Theme.js +82 -0
- package/themes/carbon.js +135 -0
- package/themes/dark.js +140 -0
- package/themes/default-dark.js +714 -0
- package/themes/default-provider.css +635 -0
- package/themes/default-provider.js +718 -0
- package/themes/ebook.js +136 -0
- package/themes/grey.js +137 -0
- package/themes/light.js +139 -0
- package/themes/neon.js +138 -0
- package/themes/pcb.js +273 -0
- package/themes/synthwave.js +138 -0
- package/tokens/base.json +29 -0
- package/tokens/themes/carbon.json +11 -0
- package/tokens/themes/dark.json +12 -0
- package/tokens/themes/default-dark.json +1543 -0
- package/tokens/themes/default-provider.json +1543 -0
- package/tokens/themes/ebook.json +11 -0
- package/tokens/themes/grey.json +11 -0
- package/tokens/themes/light.json +12 -0
- package/tokens/themes/neon.json +11 -0
- package/tokens/themes/pcb.json +11 -0
- package/tokens/themes/synthwave.json +11 -0
- package/toolbar/QuickToolbar/QuickToolbar.css.js +152 -0
- package/toolbar/QuickToolbar/QuickToolbar.js +529 -0
- package/toolbar/QuickToolbar/QuickToolbar.tpl.js +34 -0
- package/tree/TreePanel/TreePanel.css.js +112 -0
- package/tree/TreePanel/TreePanel.js +147 -0
- package/tree/TreePanel/TreePanel.tpl.js +18 -0
- package/tree/TreeView/TreeView.css.js +122 -0
- package/tree/TreeView/TreeView.js +365 -0
- package/tree/TreeView/TreeView.tpl.js +10 -0
- package/ui/dialogs.js +221 -0
- package/ui/host-adapters.js +114 -0
- package/ui/index.js +660 -0
- package/ui/locale.js +50 -0
- package/ui/overlay-stack.js +89 -0
- package/ui/shared-styles.js +26 -0
- package/webmcp.js +37 -0
- package/xr/deep-graph.js +646 -0
- package/xr/emulation.js +198 -0
- package/xr/gesture.js +228 -0
- package/xr/html-canvas-renderer.js +472 -0
- package/xr/index.js +15 -0
- package/xr/layout-projection.js +1046 -0
- package/xr/panel-frame.js +128 -0
- package/xr/panel-host.js +267 -0
- package/xr/pointer.js +258 -0
- package/xr/scene-controller.js +242 -0
- package/xr/spatial-scene.js +212 -0
- package/xr/theme-bridge.js +105 -0
- package/xr/three-webxr-adapter.js +3439 -0
- package/xr/webgl-layer-renderer.js +419 -0
- package/xr/webxr.js +679 -0
- package/xr/workbench.js +516 -0
|
@@ -0,0 +1,550 @@
|
|
|
1
|
+
/* global requestAnimationFrame, cancelAnimationFrame, getComputedStyle */
|
|
2
|
+
/**
|
|
3
|
+
* CanvasViewport.js
|
|
4
|
+
*
|
|
5
|
+
* Manages viewport transformations (pan/zoom), Level of Detail (LOD),
|
|
6
|
+
* and node virtualization (phantom data) to optimize rendering of large graphs.
|
|
7
|
+
*
|
|
8
|
+
* @module symbiote-node/canvas/CanvasViewport
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export class CanvasViewport {
|
|
12
|
+
/** @type {import('./NodeCanvas/NodeCanvas.js').NodeCanvas} */
|
|
13
|
+
#canvas;
|
|
14
|
+
/** @type {Map<string, HTMLElement>} */
|
|
15
|
+
#nodeViews;
|
|
16
|
+
/** @type {import('./NodeViewManager.js').NodeViewManager} */
|
|
17
|
+
#viewManager;
|
|
18
|
+
/** @type {function(): import('./ConnectionRenderer.js').ConnectionRenderer} */
|
|
19
|
+
#getConnRenderer;
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
/** All node data objects from editor — the full set regardless of DOM state */
|
|
23
|
+
#allNodes = new Map();
|
|
24
|
+
/** Position + size cache for nodes without DOM (phantom rendering on Canvas) */
|
|
25
|
+
#phantomData = new Map();
|
|
26
|
+
/** Degree (connection count) per node — for dot sizing */
|
|
27
|
+
#nodeDegrees = new Map();
|
|
28
|
+
/** Debounce timer for promote/demote batch */
|
|
29
|
+
#virtTimer = null;
|
|
30
|
+
/** Dirty flag — phantom positions changed, needs re-sync to renderer */
|
|
31
|
+
#phantomDirty = false;
|
|
32
|
+
|
|
33
|
+
/** @type {number|null} */
|
|
34
|
+
#panAnimFrame = null;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {object} config
|
|
38
|
+
* @param {import('./NodeCanvas/NodeCanvas.js').NodeCanvas} config.canvas
|
|
39
|
+
* @param {Map<string, HTMLElement>} config.nodeViews
|
|
40
|
+
* @param {import('./NodeViewManager.js').NodeViewManager} config.viewManager
|
|
41
|
+
* @param {function(): import('./ConnectionRenderer.js').ConnectionRenderer} config.getConnRenderer
|
|
42
|
+
*/
|
|
43
|
+
constructor({ canvas, nodeViews, viewManager, getConnRenderer }) {
|
|
44
|
+
this.#canvas = canvas;
|
|
45
|
+
this.#nodeViews = nodeViews;
|
|
46
|
+
this.#viewManager = viewManager;
|
|
47
|
+
this.#getConnRenderer = getConnRenderer;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Reset and initialize virtualization data from a new editor
|
|
52
|
+
* @param {import('../core/Editor.js').NodeEditor} editor
|
|
53
|
+
*/
|
|
54
|
+
initializeData(editor) {
|
|
55
|
+
this.#allNodes.clear();
|
|
56
|
+
this.#phantomData.clear();
|
|
57
|
+
this.#nodeDegrees.clear();
|
|
58
|
+
|
|
59
|
+
for (const node of editor.getNodes()) {
|
|
60
|
+
this.#allNodes.set(node.id, node);
|
|
61
|
+
this.#nodeDegrees.set(node.id, 0);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let allConns = editor.getConnections();
|
|
65
|
+
for (const conn of allConns) {
|
|
66
|
+
this.#nodeDegrees.set(conn.from, (this.#nodeDegrees.get(conn.from) || 0) + 1);
|
|
67
|
+
this.#nodeDegrees.set(conn.to, (this.#nodeDegrees.get(conn.to) || 0) + 1);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const VIRT_THRESHOLD = 200;
|
|
71
|
+
if (this.#allNodes.size <= VIRT_THRESHOLD) {
|
|
72
|
+
|
|
73
|
+
this.#viewManager.addViews(editor.getNodes());
|
|
74
|
+
} else {
|
|
75
|
+
|
|
76
|
+
let defaultW = 180,
|
|
77
|
+
defaultH = 60;
|
|
78
|
+
for (const [id, node] of this.#allNodes) {
|
|
79
|
+
this.#phantomData.set(id, {
|
|
80
|
+
id,
|
|
81
|
+
x: 0,
|
|
82
|
+
y: 0,
|
|
83
|
+
w: defaultW,
|
|
84
|
+
h: defaultH,
|
|
85
|
+
degree: this.#nodeDegrees.get(id) || 0,
|
|
86
|
+
color: null,
|
|
87
|
+
label: node.label || id,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Clear all virtualization data
|
|
95
|
+
*/
|
|
96
|
+
clear() {
|
|
97
|
+
this.#allNodes.clear();
|
|
98
|
+
this.#phantomData.clear();
|
|
99
|
+
this.#nodeDegrees.clear();
|
|
100
|
+
if (this.#virtTimer) {
|
|
101
|
+
clearTimeout(this.#virtTimer);
|
|
102
|
+
this.#virtTimer = null;
|
|
103
|
+
}
|
|
104
|
+
if (this.#panAnimFrame) {
|
|
105
|
+
cancelAnimationFrame(this.#panAnimFrame);
|
|
106
|
+
this.#panAnimFrame = null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Handle node creation event
|
|
112
|
+
* @param {import('../../core/Node.js').Node} node
|
|
113
|
+
*/
|
|
114
|
+
handleNodeCreated(node) {
|
|
115
|
+
this.#allNodes.set(node.id, node);
|
|
116
|
+
if (this.#phantomData.size > 0) {
|
|
117
|
+
this.#phantomData.set(node.id, {
|
|
118
|
+
id: node.id,
|
|
119
|
+
x: 0,
|
|
120
|
+
y: 0,
|
|
121
|
+
w: 180,
|
|
122
|
+
h: 60,
|
|
123
|
+
degree: 0,
|
|
124
|
+
color: null,
|
|
125
|
+
label: node.label || node.id,
|
|
126
|
+
});
|
|
127
|
+
} else {
|
|
128
|
+
this.#viewManager.addView(node);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Update phantom node position cache
|
|
134
|
+
* @param {string} nodeId
|
|
135
|
+
* @param {number} x
|
|
136
|
+
* @param {number} y
|
|
137
|
+
*/
|
|
138
|
+
updatePhantomPosition(nodeId, x, y) {
|
|
139
|
+
let pd = this.#phantomData.get(nodeId);
|
|
140
|
+
if (pd) {
|
|
141
|
+
pd.x = x;
|
|
142
|
+
pd.y = y;
|
|
143
|
+
this.#phantomDirty = true;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Update viewport transform and schedule culling
|
|
149
|
+
*/
|
|
150
|
+
updateTransform() {
|
|
151
|
+
|
|
152
|
+
if (this.#canvas._gridBase === undefined) {
|
|
153
|
+
this.#canvas._gridBase =
|
|
154
|
+
parseInt(getComputedStyle(this.#canvas).getPropertyValue('--sn-grid-size')) || 20;
|
|
155
|
+
}
|
|
156
|
+
let gridBase = this.#canvas._gridBase;
|
|
157
|
+
let zoom = this.#canvas.$.zoom;
|
|
158
|
+
let multiplier = zoom < 0.5 ? 2 : 1;
|
|
159
|
+
let gridSize = gridBase * multiplier * zoom;
|
|
160
|
+
this.#canvas.style.backgroundSize = `${gridSize}px ${gridSize}px`;
|
|
161
|
+
this.#canvas.style.backgroundPosition = `${this.#canvas.$.panX}px ${this.#canvas.$.panY}px`;
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
let toolbar = this.#canvas.ref.quickToolbar;
|
|
165
|
+
if (toolbar) {
|
|
166
|
+
toolbar._transform = { zoom, panX: this.#canvas.$.panX, panY: this.#canvas.$.panY };
|
|
167
|
+
if (toolbar._nodeEl) toolbar.updatePosition(toolbar._nodeEl);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
if (!this.#canvas._cullingScheduled) {
|
|
172
|
+
this.#canvas._cullingScheduled = true;
|
|
173
|
+
requestAnimationFrame(() => {
|
|
174
|
+
this.#canvas._cullingScheduled = false;
|
|
175
|
+
this.#applyCullingAndLOD();
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Apply culling and level of detail logic based on zoom/pan
|
|
182
|
+
* @private
|
|
183
|
+
*/
|
|
184
|
+
#applyCullingAndLOD() {
|
|
185
|
+
if (!this.#canvas.ref.canvasContainer) return;
|
|
186
|
+
if (this.#nodeViews.size === 0 && this.#phantomData.size === 0) return;
|
|
187
|
+
|
|
188
|
+
let cw = this.#canvas.ref.canvasContainer.clientWidth;
|
|
189
|
+
let ch = this.#canvas.ref.canvasContainer.clientHeight;
|
|
190
|
+
let zoom = this.#canvas.$.zoom;
|
|
191
|
+
let panX = this.#canvas.$.panX;
|
|
192
|
+
let panY = this.#canvas.$.panY;
|
|
193
|
+
let margin = 300;
|
|
194
|
+
|
|
195
|
+
let lod = zoom < 0.5 ? 'medium' : 'full';
|
|
196
|
+
this.#canvas._currentLod = lod;
|
|
197
|
+
|
|
198
|
+
if (this.#canvas.ref.connections) {
|
|
199
|
+
let isDimmed = this.#canvas.ref.connections.hasAttribute('data-lod-dimmed');
|
|
200
|
+
if (lod !== 'full') {
|
|
201
|
+
if (!isDimmed) this.#canvas.ref.connections.setAttribute('data-lod-dimmed', '');
|
|
202
|
+
} else {
|
|
203
|
+
if (isDimmed) this.#canvas.ref.connections.removeAttribute('data-lod-dimmed');
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
let isVirtualized = this.#phantomData.size > 0 || this.#allNodes.size > 200;
|
|
208
|
+
const FAR_ZOOM = zoom < 0.25;
|
|
209
|
+
let toPromote = [];
|
|
210
|
+
let toDemote = [];
|
|
211
|
+
|
|
212
|
+
for (const [id, el] of this.#nodeViews) {
|
|
213
|
+
let pos = el._position;
|
|
214
|
+
if (!pos) continue;
|
|
215
|
+
|
|
216
|
+
let screenX = pos.x * zoom + panX;
|
|
217
|
+
let screenY = pos.y * zoom + panY;
|
|
218
|
+
if (!el._cachedW) {
|
|
219
|
+
el._cachedW = el.offsetWidth || 180;
|
|
220
|
+
el._cachedH = el.offsetHeight || 60;
|
|
221
|
+
}
|
|
222
|
+
let w = el._cachedW * zoom;
|
|
223
|
+
let h = el._cachedH * zoom;
|
|
224
|
+
|
|
225
|
+
let visible =
|
|
226
|
+
screenX + w > -margin &&
|
|
227
|
+
screenX < cw + margin &&
|
|
228
|
+
screenY + h > -margin &&
|
|
229
|
+
screenY < ch + margin;
|
|
230
|
+
|
|
231
|
+
if (isVirtualized && FAR_ZOOM) {
|
|
232
|
+
toDemote.push(id);
|
|
233
|
+
} else if (visible) {
|
|
234
|
+
if (el.style.visibility !== '') el.style.visibility = '';
|
|
235
|
+
if (el.getAttribute('data-lod') !== lod) el.setAttribute('data-lod', lod);
|
|
236
|
+
} else if (isVirtualized) {
|
|
237
|
+
toDemote.push(id);
|
|
238
|
+
} else {
|
|
239
|
+
if (el.style.visibility !== 'hidden') el.style.visibility = 'hidden';
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (isVirtualized && !FAR_ZOOM) {
|
|
244
|
+
for (const [id, pd] of this.#phantomData) {
|
|
245
|
+
let screenX = pd.x * zoom + panX;
|
|
246
|
+
let screenY = pd.y * zoom + panY;
|
|
247
|
+
let w = (pd.w || 180) * zoom;
|
|
248
|
+
let h = (pd.h || 60) * zoom;
|
|
249
|
+
|
|
250
|
+
let visible =
|
|
251
|
+
screenX + w > -margin &&
|
|
252
|
+
screenX < cw + margin &&
|
|
253
|
+
screenY + h > -margin &&
|
|
254
|
+
screenY < ch + margin;
|
|
255
|
+
|
|
256
|
+
if (visible) toPromote.push(id);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (FAR_ZOOM && toDemote.length > 0) {
|
|
261
|
+
if (this.#virtTimer) {
|
|
262
|
+
clearTimeout(this.#virtTimer);
|
|
263
|
+
this.#virtTimer = null;
|
|
264
|
+
}
|
|
265
|
+
for (const id of toDemote) this.#demoteNode(id);
|
|
266
|
+
this.#syncPhantomToRenderer();
|
|
267
|
+
} else if (toPromote.length > 0 || toDemote.length > 0) {
|
|
268
|
+
if (this.#virtTimer) clearTimeout(this.#virtTimer);
|
|
269
|
+
this.#virtTimer = setTimeout(() => {
|
|
270
|
+
this.#virtTimer = null;
|
|
271
|
+
for (const id of toDemote) this.#demoteNode(id);
|
|
272
|
+
for (const id of toPromote) this.#promoteNode(id);
|
|
273
|
+
this.#syncPhantomToRenderer();
|
|
274
|
+
}, 100);
|
|
275
|
+
} else if (this.#phantomDirty) {
|
|
276
|
+
this.#phantomDirty = false;
|
|
277
|
+
this.#syncPhantomToRenderer();
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Promote a phantom node to a full DOM node
|
|
283
|
+
* @param {string} nodeId
|
|
284
|
+
* @private
|
|
285
|
+
*/
|
|
286
|
+
#promoteNode(nodeId) {
|
|
287
|
+
if (this.#nodeViews.has(nodeId)) return;
|
|
288
|
+
let node = this.#allNodes.get(nodeId);
|
|
289
|
+
if (!node) return;
|
|
290
|
+
|
|
291
|
+
let pd = this.#phantomData.get(nodeId);
|
|
292
|
+
this.#viewManager.addView(node);
|
|
293
|
+
let el = this.#nodeViews.get(nodeId);
|
|
294
|
+
if (el && pd) {
|
|
295
|
+
el._position = { x: pd.x, y: pd.y };
|
|
296
|
+
el._cachedW = pd.w;
|
|
297
|
+
el._cachedH = pd.h;
|
|
298
|
+
el.style.transform = `translate(${pd.x}px, ${pd.y}px)`;
|
|
299
|
+
}
|
|
300
|
+
this.#phantomData.delete(nodeId);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Demote a DOM node to a phantom node
|
|
305
|
+
* @param {string} nodeId
|
|
306
|
+
* @private
|
|
307
|
+
*/
|
|
308
|
+
#demoteNode(nodeId) {
|
|
309
|
+
if (!this.#nodeViews.has(nodeId)) return;
|
|
310
|
+
let el = this.#nodeViews.get(nodeId);
|
|
311
|
+
let color = null;
|
|
312
|
+
if (el) {
|
|
313
|
+
color = el._cachedBgColor || el.style.backgroundColor || null;
|
|
314
|
+
}
|
|
315
|
+
let dims = this.#viewManager.removeViewInstant(nodeId);
|
|
316
|
+
if (dims) {
|
|
317
|
+
let node = this.#allNodes.get(nodeId);
|
|
318
|
+
this.#phantomData.set(nodeId, {
|
|
319
|
+
id: nodeId,
|
|
320
|
+
x: dims.x,
|
|
321
|
+
y: dims.y,
|
|
322
|
+
w: dims.w,
|
|
323
|
+
h: dims.h,
|
|
324
|
+
degree: this.#nodeDegrees.get(nodeId) || 0,
|
|
325
|
+
color,
|
|
326
|
+
label: node?.label || nodeId,
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Sync phantom node data to the connection renderer
|
|
333
|
+
* @private
|
|
334
|
+
*/
|
|
335
|
+
#syncPhantomToRenderer() {
|
|
336
|
+
let connRenderer = this.#getConnRenderer();
|
|
337
|
+
if (connRenderer && typeof connRenderer.setPhantomNodes === 'function') {
|
|
338
|
+
connRenderer.setPhantomNodes([...this.#phantomData.values()]);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Trigger a manual sync of phantom nodes
|
|
344
|
+
*/
|
|
345
|
+
syncPhantom() {
|
|
346
|
+
this.#phantomDirty = false;
|
|
347
|
+
this.#syncPhantomToRenderer();
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Fit all nodes (phantom and DOM) within the viewport
|
|
352
|
+
*/
|
|
353
|
+
fitView() {
|
|
354
|
+
if (this.#nodeViews.size === 0 && this.#phantomData.size === 0) return;
|
|
355
|
+
|
|
356
|
+
let minX = Infinity,
|
|
357
|
+
minY = Infinity,
|
|
358
|
+
maxX = -Infinity,
|
|
359
|
+
maxY = -Infinity;
|
|
360
|
+
|
|
361
|
+
for (const [, el] of this.#nodeViews) {
|
|
362
|
+
if (!el._position) continue;
|
|
363
|
+
let x = el._position.x;
|
|
364
|
+
let y = el._position.y;
|
|
365
|
+
let w = el._cachedW || el.offsetWidth || 150;
|
|
366
|
+
let h = el._cachedH || el.offsetHeight || 40;
|
|
367
|
+
if (x < minX) minX = x;
|
|
368
|
+
if (y < minY) minY = y;
|
|
369
|
+
if (x + w > maxX) maxX = x + w;
|
|
370
|
+
if (y + h > maxY) maxY = y + h;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
for (const [, pd] of this.#phantomData) {
|
|
374
|
+
if (pd.x < minX) minX = pd.x;
|
|
375
|
+
if (pd.y < minY) minY = pd.y;
|
|
376
|
+
if (pd.x + pd.w > maxX) maxX = pd.x + pd.w;
|
|
377
|
+
if (pd.y + pd.h > maxY) maxY = pd.y + pd.h;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (minX === Infinity) return;
|
|
381
|
+
|
|
382
|
+
let graphW = maxX - minX;
|
|
383
|
+
let graphH = maxY - minY;
|
|
384
|
+
let canvasRect = this.#canvas.ref.canvasContainer.getBoundingClientRect();
|
|
385
|
+
|
|
386
|
+
let visibleWidth = canvasRect.width;
|
|
387
|
+
let inspector = this.#canvas.ref.inspector || this.#canvas.querySelector('inspector-panel');
|
|
388
|
+
if (inspector && !inspector.hasAttribute('hidden')) {
|
|
389
|
+
visibleWidth -= inspector.offsetWidth || 280;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
let scaleX = (visibleWidth - 80) / graphW;
|
|
393
|
+
let scaleY = (canvasRect.height - 80) / graphH;
|
|
394
|
+
let scale = Math.max(0.001, Math.min(scaleX, scaleY, 1.5));
|
|
395
|
+
|
|
396
|
+
let centerX = (minX + maxX) / 2;
|
|
397
|
+
let centerY = (minY + maxY) / 2;
|
|
398
|
+
|
|
399
|
+
this.#canvas.$.zoom = scale;
|
|
400
|
+
this.#canvas.$.panX = visibleWidth / 2 - centerX * scale;
|
|
401
|
+
this.#canvas.$.panY = canvasRect.height / 2 - centerY * scale;
|
|
402
|
+
this.updateTransform();
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Fly camera to a specific node, zooming in
|
|
407
|
+
* @param {string} nodeId
|
|
408
|
+
* @param {Object} [options]
|
|
409
|
+
* @param {number} [options.zoom=0.8]
|
|
410
|
+
* @returns {boolean} True if successful
|
|
411
|
+
*/
|
|
412
|
+
flyToNode(nodeId, { zoom = 0.8 } = {}) {
|
|
413
|
+
let el = this.#nodeViews.get(nodeId);
|
|
414
|
+
|
|
415
|
+
if (!el && this.#phantomData.has(nodeId)) {
|
|
416
|
+
this.#promoteNode(nodeId);
|
|
417
|
+
el = this.#nodeViews.get(nodeId);
|
|
418
|
+
}
|
|
419
|
+
if (!el) return false;
|
|
420
|
+
|
|
421
|
+
let pos =
|
|
422
|
+
el._position ||
|
|
423
|
+
(() => {
|
|
424
|
+
let pd = this.#phantomData.get(nodeId);
|
|
425
|
+
return pd ? { x: pd.x, y: pd.y } : { x: 0, y: 0 };
|
|
426
|
+
})();
|
|
427
|
+
|
|
428
|
+
let canvasRect = this.#canvas.ref.canvasContainer.getBoundingClientRect();
|
|
429
|
+
let visibleWidth = canvasRect.width;
|
|
430
|
+
|
|
431
|
+
let inspector = this.#canvas.ref.inspector || this.#canvas.querySelector('inspector-panel');
|
|
432
|
+
if (inspector && !inspector.hasAttribute('hidden') && inspector.offsetWidth > 20) {
|
|
433
|
+
visibleWidth -= inspector.offsetWidth;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
let elWidth = el._cachedW || el.offsetWidth || 150;
|
|
437
|
+
let elHeight = el._cachedH || el.offsetHeight || 40;
|
|
438
|
+
|
|
439
|
+
let nodeX = pos.x + elWidth / 2;
|
|
440
|
+
let nodeY = pos.y + elHeight / 2;
|
|
441
|
+
|
|
442
|
+
let newPanX = visibleWidth / 2 - nodeX * zoom;
|
|
443
|
+
let newPanY = canvasRect.height / 2 - nodeY * zoom;
|
|
444
|
+
|
|
445
|
+
let dz = Math.abs(this.#canvas.$.zoom - zoom);
|
|
446
|
+
let dx = Math.abs(this.#canvas.$.panX - newPanX);
|
|
447
|
+
let dy = Math.abs(this.#canvas.$.panY - newPanY);
|
|
448
|
+
|
|
449
|
+
if (dz < 0.01 && dx < 2 && dy < 2) {
|
|
450
|
+
this.#canvas.selectNode(nodeId);
|
|
451
|
+
if (!this.#canvas._cullingScheduled) {
|
|
452
|
+
this.#canvas._cullingScheduled = true;
|
|
453
|
+
requestAnimationFrame(() => {
|
|
454
|
+
this.#canvas._cullingScheduled = false;
|
|
455
|
+
this.#applyCullingAndLOD();
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
return true;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
this.#canvas.$.zoom = zoom;
|
|
462
|
+
this.#canvas.$.panX = newPanX;
|
|
463
|
+
this.#canvas.$.panY = newPanY;
|
|
464
|
+
|
|
465
|
+
this.#canvas.selectNode(nodeId);
|
|
466
|
+
return true;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Pan smoothly to a specific node
|
|
471
|
+
* @param {string} nodeId
|
|
472
|
+
* @param {number} [duration=400]
|
|
473
|
+
*/
|
|
474
|
+
panToNode(nodeId, duration = 400) {
|
|
475
|
+
let el = this.#nodeViews.get(nodeId);
|
|
476
|
+
if (!el?._position) return;
|
|
477
|
+
let container = this.#canvas.ref.canvasContainer;
|
|
478
|
+
if (!container) return;
|
|
479
|
+
|
|
480
|
+
let cx = container.clientWidth / 2;
|
|
481
|
+
let cy = container.clientHeight / 2;
|
|
482
|
+
let nodeW = (el.offsetWidth || 180) / 2;
|
|
483
|
+
let nodeH = (el.offsetHeight || 60) / 2;
|
|
484
|
+
let targetX = -(el._position.x + nodeW) * this.#canvas.$.zoom + cx;
|
|
485
|
+
let targetY = -(el._position.y + nodeH) * this.#canvas.$.zoom + cy;
|
|
486
|
+
|
|
487
|
+
this.animatePan(targetX, targetY, duration);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Animate pan to a target coordinate
|
|
492
|
+
* @param {number} targetX
|
|
493
|
+
* @param {number} targetY
|
|
494
|
+
* @param {number} duration
|
|
495
|
+
*/
|
|
496
|
+
animatePan(targetX, targetY, duration) {
|
|
497
|
+
if (this.#panAnimFrame) {
|
|
498
|
+
cancelAnimationFrame(this.#panAnimFrame);
|
|
499
|
+
this.#panAnimFrame = null;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
let startX = this.#canvas.$.panX;
|
|
503
|
+
let startY = this.#canvas.$.panY;
|
|
504
|
+
let dx = targetX - startX;
|
|
505
|
+
let dy = targetY - startY;
|
|
506
|
+
|
|
507
|
+
if (Math.abs(dx) < 1 && Math.abs(dy) < 1) return;
|
|
508
|
+
|
|
509
|
+
let startTime = performance.now();
|
|
510
|
+
|
|
511
|
+
let step = (now) => {
|
|
512
|
+
let elapsed = now - startTime;
|
|
513
|
+
let t = Math.min(elapsed / duration, 1);
|
|
514
|
+
let ease = 1 - Math.pow(1 - t, 3);
|
|
515
|
+
|
|
516
|
+
this.#canvas.$.panX = startX + dx * ease;
|
|
517
|
+
this.#canvas.$.panY = startY + dy * ease;
|
|
518
|
+
this.updateTransform();
|
|
519
|
+
|
|
520
|
+
if (t < 1) {
|
|
521
|
+
this.#panAnimFrame = requestAnimationFrame(step);
|
|
522
|
+
} else {
|
|
523
|
+
this.#panAnimFrame = null;
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
this.#panAnimFrame = requestAnimationFrame(step);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
getPositions() {
|
|
531
|
+
let positions = {};
|
|
532
|
+
for (const [id, el] of this.#nodeViews) {
|
|
533
|
+
if (el._position) {
|
|
534
|
+
positions[id] = [el._position.x, el._position.y];
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
for (const [id, pd] of this.#phantomData) {
|
|
538
|
+
if (!positions[id]) {
|
|
539
|
+
positions[id] = [pd.x, pd.y];
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
return positions;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
hasNode(nodeId) {
|
|
546
|
+
return this.#nodeViews.has(nodeId) || this.#phantomData.has(nodeId);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
export { CanvasViewport as default };
|