@flanksource/clicky-ui 0.3.44 → 0.3.45
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/README.md +2 -0
- package/dist/ai.cjs +4 -2
- package/dist/ai.cjs.map +1 -1
- package/dist/ai.js +3 -1
- package/dist/components/MdxEditorField.cjs +40 -22
- package/dist/components/MdxEditorField.cjs.map +1 -1
- package/dist/components/MdxEditorField.d.ts.map +1 -1
- package/dist/components/MdxEditorField.js +41 -23
- package/dist/components/MdxEditorField.js.map +1 -1
- package/dist/components/json-schema-form-item-summary.cjs +6 -1
- package/dist/components/json-schema-form-item-summary.cjs.map +1 -1
- package/dist/components/json-schema-form-item-summary.d.ts.map +1 -1
- package/dist/components/json-schema-form-item-summary.js +6 -1
- package/dist/components/json-schema-form-item-summary.js.map +1 -1
- package/dist/data/CodeBlock.cjs +3 -2
- package/dist/data/CodeBlock.cjs.map +1 -1
- package/dist/data/CodeBlock.d.ts +3 -1
- package/dist/data/CodeBlock.d.ts.map +1 -1
- package/dist/data/CodeBlock.js +3 -2
- package/dist/data/CodeBlock.js.map +1 -1
- package/dist/data/GraphDiagram.cjs +18 -6
- package/dist/data/GraphDiagram.cjs.map +1 -1
- package/dist/data/GraphDiagram.d.ts +9 -1
- package/dist/data/GraphDiagram.d.ts.map +1 -1
- package/dist/data/GraphDiagram.js +18 -6
- package/dist/data/GraphDiagram.js.map +1 -1
- package/dist/data/GraphDiagramNodes.cjs +38 -29
- package/dist/data/GraphDiagramNodes.cjs.map +1 -1
- package/dist/data/GraphDiagramNodes.d.ts +8 -2
- package/dist/data/GraphDiagramNodes.d.ts.map +1 -1
- package/dist/data/GraphDiagramNodes.js +38 -29
- package/dist/data/GraphDiagramNodes.js.map +1 -1
- package/dist/data/JsonView.cjs +118 -49
- package/dist/data/JsonView.cjs.map +1 -1
- package/dist/data/JsonView.d.ts +13 -10
- package/dist/data/JsonView.d.ts.map +1 -1
- package/dist/data/JsonView.js +118 -49
- package/dist/data/JsonView.js.map +1 -1
- package/dist/data/MarkdownEditor.cjs +2 -2
- package/dist/data/MarkdownEditor.cjs.map +1 -1
- package/dist/data/MarkdownEditor.js +2 -2
- package/dist/data/MarkdownEditor.js.map +1 -1
- package/dist/data/ai/AdvancedChatConfig.cjs +90 -249
- package/dist/data/ai/AdvancedChatConfig.cjs.map +1 -1
- package/dist/data/ai/AdvancedChatConfig.d.ts +2 -5
- package/dist/data/ai/AdvancedChatConfig.d.ts.map +1 -1
- package/dist/data/ai/AdvancedChatConfig.js +91 -250
- package/dist/data/ai/AdvancedChatConfig.js.map +1 -1
- package/dist/data/ai/ChatButton.cjs +2 -0
- package/dist/data/ai/ChatButton.cjs.map +1 -1
- package/dist/data/ai/ChatButton.d.ts +1 -1
- package/dist/data/ai/ChatButton.d.ts.map +1 -1
- package/dist/data/ai/ChatButton.js +2 -0
- package/dist/data/ai/ChatButton.js.map +1 -1
- package/dist/data/ai/ChatFab.cjs +5 -1
- package/dist/data/ai/ChatFab.cjs.map +1 -1
- package/dist/data/ai/ChatFab.d.ts +5 -1
- package/dist/data/ai/ChatFab.d.ts.map +1 -1
- package/dist/data/ai/ChatFab.js +5 -1
- package/dist/data/ai/ChatFab.js.map +1 -1
- package/dist/data/ai/ChatWindow.cjs +2 -8
- package/dist/data/ai/ChatWindow.cjs.map +1 -1
- package/dist/data/ai/ChatWindow.d.ts.map +1 -1
- package/dist/data/ai/ChatWindow.js +2 -8
- package/dist/data/ai/ChatWindow.js.map +1 -1
- package/dist/data/ai/ChatWindow.runtime.cjs +0 -5
- package/dist/data/ai/ChatWindow.runtime.cjs.map +1 -1
- package/dist/data/ai/ChatWindow.runtime.d.ts +0 -2
- package/dist/data/ai/ChatWindow.runtime.d.ts.map +1 -1
- package/dist/data/ai/ChatWindow.runtime.js +0 -5
- package/dist/data/ai/ChatWindow.runtime.js.map +1 -1
- package/dist/data/ai/PromptRunEditor/runtimeActions.cjs +2 -2
- package/dist/data/ai/PromptRunEditor/runtimeActions.cjs.map +1 -1
- package/dist/data/ai/PromptRunEditor/runtimeActions.d.ts.map +1 -1
- package/dist/data/ai/PromptRunEditor/runtimeActions.js +2 -2
- package/dist/data/ai/PromptRunEditor/runtimeActions.js.map +1 -1
- package/dist/data/ai/SessionInspector.approvals.cjs +3 -6
- package/dist/data/ai/SessionInspector.approvals.cjs.map +1 -1
- package/dist/data/ai/SessionInspector.approvals.js +3 -6
- package/dist/data/ai/SessionInspector.approvals.js.map +1 -1
- package/dist/data/ai/SessionViewer.cjs +13 -4
- package/dist/data/ai/SessionViewer.cjs.map +1 -1
- package/dist/data/ai/SessionViewer.d.ts +5 -1
- package/dist/data/ai/SessionViewer.d.ts.map +1 -1
- package/dist/data/ai/SessionViewer.header.cjs +1 -1
- package/dist/data/ai/SessionViewer.header.cjs.map +1 -1
- package/dist/data/ai/SessionViewer.header.js +1 -1
- package/dist/data/ai/SessionViewer.header.js.map +1 -1
- package/dist/data/ai/SessionViewer.js +13 -4
- package/dist/data/ai/SessionViewer.js.map +1 -1
- package/dist/data/ai/SessionViewer.model.cjs +2 -0
- package/dist/data/ai/SessionViewer.model.cjs.map +1 -1
- package/dist/data/ai/SessionViewer.model.d.ts +1 -0
- package/dist/data/ai/SessionViewer.model.d.ts.map +1 -1
- package/dist/data/ai/SessionViewer.model.js +2 -0
- package/dist/data/ai/SessionViewer.model.js.map +1 -1
- package/dist/data/ai/SessionViewer.rows.cjs +41 -27
- package/dist/data/ai/SessionViewer.rows.cjs.map +1 -1
- package/dist/data/ai/SessionViewer.rows.d.ts +4 -2
- package/dist/data/ai/SessionViewer.rows.d.ts.map +1 -1
- package/dist/data/ai/SessionViewer.rows.js +41 -27
- package/dist/data/ai/SessionViewer.rows.js.map +1 -1
- package/dist/data/ai/SessionViewer.tokens.cjs +35 -0
- package/dist/data/ai/SessionViewer.tokens.cjs.map +1 -0
- package/dist/data/ai/SessionViewer.tokens.d.ts +5 -0
- package/dist/data/ai/SessionViewer.tokens.d.ts.map +1 -0
- package/dist/data/ai/SessionViewer.tokens.js +35 -0
- package/dist/data/ai/SessionViewer.tokens.js.map +1 -0
- package/dist/data/ai/SessionViewer.tool-cost.cjs +128 -0
- package/dist/data/ai/SessionViewer.tool-cost.cjs.map +1 -0
- package/dist/data/ai/SessionViewer.tool-cost.d.ts +6 -0
- package/dist/data/ai/SessionViewer.tool-cost.d.ts.map +1 -0
- package/dist/data/ai/SessionViewer.tool-cost.js +128 -0
- package/dist/data/ai/SessionViewer.tool-cost.js.map +1 -0
- package/dist/data/ai/SessionViewer.tool-details.cjs +3 -1
- package/dist/data/ai/SessionViewer.tool-details.cjs.map +1 -1
- package/dist/data/ai/SessionViewer.tool-details.d.ts.map +1 -1
- package/dist/data/ai/SessionViewer.tool-details.js +3 -1
- package/dist/data/ai/SessionViewer.tool-details.js.map +1 -1
- package/dist/data/ai/SessionViewer.tool-row.cjs +55 -35
- package/dist/data/ai/SessionViewer.tool-row.cjs.map +1 -1
- package/dist/data/ai/SessionViewer.tool-row.d.ts +2 -1
- package/dist/data/ai/SessionViewer.tool-row.d.ts.map +1 -1
- package/dist/data/ai/SessionViewer.tool-row.js +55 -35
- package/dist/data/ai/SessionViewer.tool-row.js.map +1 -1
- package/dist/data/ai/SessionViewer.unified.d.ts +4 -0
- package/dist/data/ai/SessionViewer.unified.d.ts.map +1 -1
- package/dist/data/ai/SessionViewerMenu.cjs +18 -1
- package/dist/data/ai/SessionViewerMenu.cjs.map +1 -1
- package/dist/data/ai/SessionViewerMenu.d.ts +6 -1
- package/dist/data/ai/SessionViewerMenu.d.ts.map +1 -1
- package/dist/data/ai/SessionViewerMenu.js +18 -1
- package/dist/data/ai/SessionViewerMenu.js.map +1 -1
- package/dist/data/ai/ToolPreferences.cjs +149 -143
- package/dist/data/ai/ToolPreferences.cjs.map +1 -1
- package/dist/data/ai/ToolPreferences.d.ts +20 -6
- package/dist/data/ai/ToolPreferences.d.ts.map +1 -1
- package/dist/data/ai/ToolPreferences.js +151 -146
- package/dist/data/ai/ToolPreferences.js.map +1 -1
- package/dist/data/ai/ToolPreferences.model.cjs +14 -10
- package/dist/data/ai/ToolPreferences.model.cjs.map +1 -1
- package/dist/data/ai/ToolPreferences.model.d.ts +1 -0
- package/dist/data/ai/ToolPreferences.model.d.ts.map +1 -1
- package/dist/data/ai/ToolPreferences.model.js +15 -11
- package/dist/data/ai/ToolPreferences.model.js.map +1 -1
- package/dist/data/ai/ToolPreferencesList.cjs +1 -0
- package/dist/data/ai/ToolPreferencesList.cjs.map +1 -1
- package/dist/data/ai/ToolPreferencesList.d.ts +4 -1
- package/dist/data/ai/ToolPreferencesList.d.ts.map +1 -1
- package/dist/data/ai/ToolPreferencesList.js +2 -1
- package/dist/data/ai/ToolPreferencesList.js.map +1 -1
- package/dist/data/ai/ToolSchemaBrowser.cjs +52 -53
- package/dist/data/ai/ToolSchemaBrowser.cjs.map +1 -1
- package/dist/data/ai/ToolSchemaBrowser.d.ts +6 -3
- package/dist/data/ai/ToolSchemaBrowser.d.ts.map +1 -1
- package/dist/data/ai/ToolSchemaBrowser.directory-header.cjs +9 -13
- package/dist/data/ai/ToolSchemaBrowser.directory-header.cjs.map +1 -1
- package/dist/data/ai/ToolSchemaBrowser.directory-header.d.ts +5 -2
- package/dist/data/ai/ToolSchemaBrowser.directory-header.d.ts.map +1 -1
- package/dist/data/ai/ToolSchemaBrowser.directory-header.js +9 -13
- package/dist/data/ai/ToolSchemaBrowser.directory-header.js.map +1 -1
- package/dist/data/ai/ToolSchemaBrowser.js +53 -54
- package/dist/data/ai/ToolSchemaBrowser.js.map +1 -1
- package/dist/data/ai/ToolSchemaBrowser.model.cjs +19 -27
- package/dist/data/ai/ToolSchemaBrowser.model.cjs.map +1 -1
- package/dist/data/ai/ToolSchemaBrowser.model.d.ts +9 -6
- package/dist/data/ai/ToolSchemaBrowser.model.d.ts.map +1 -1
- package/dist/data/ai/ToolSchemaBrowser.model.js +20 -28
- package/dist/data/ai/ToolSchemaBrowser.model.js.map +1 -1
- package/dist/data/ai/ToolSchemaBrowser.sidebar.cjs +12 -213
- package/dist/data/ai/ToolSchemaBrowser.sidebar.cjs.map +1 -1
- package/dist/data/ai/ToolSchemaBrowser.sidebar.d.ts +1 -3
- package/dist/data/ai/ToolSchemaBrowser.sidebar.d.ts.map +1 -1
- package/dist/data/ai/ToolSchemaBrowser.sidebar.js +13 -214
- package/dist/data/ai/ToolSchemaBrowser.sidebar.js.map +1 -1
- package/dist/data/ai/ToolSchemaBrowser.strategies.cjs +54 -0
- package/dist/data/ai/ToolSchemaBrowser.strategies.cjs.map +1 -0
- package/dist/data/ai/ToolSchemaBrowser.strategies.d.ts +9 -0
- package/dist/data/ai/ToolSchemaBrowser.strategies.d.ts.map +1 -0
- package/dist/data/ai/ToolSchemaBrowser.strategies.js +54 -0
- package/dist/data/ai/ToolSchemaBrowser.strategies.js.map +1 -0
- package/dist/data/ai/ToolSchemaBrowser.tree.cjs +179 -0
- package/dist/data/ai/ToolSchemaBrowser.tree.cjs.map +1 -0
- package/dist/data/ai/ToolSchemaBrowser.tree.d.ts +20 -0
- package/dist/data/ai/ToolSchemaBrowser.tree.d.ts.map +1 -0
- package/dist/data/ai/ToolSchemaBrowser.tree.js +179 -0
- package/dist/data/ai/ToolSchemaBrowser.tree.js.map +1 -0
- package/dist/data/ai/index.d.ts +2 -2
- package/dist/data/ai/index.d.ts.map +1 -1
- package/dist/data/ai/runtime-profiles/PermissionStrategiesEditor.cjs +8 -28
- package/dist/data/ai/runtime-profiles/PermissionStrategiesEditor.cjs.map +1 -1
- package/dist/data/ai/runtime-profiles/PermissionStrategiesEditor.d.ts.map +1 -1
- package/dist/data/ai/runtime-profiles/PermissionStrategiesEditor.js +9 -29
- package/dist/data/ai/runtime-profiles/PermissionStrategiesEditor.js.map +1 -1
- package/dist/data/ai/session-token-sizing.d.ts +32 -0
- package/dist/data/ai/session-token-sizing.d.ts.map +1 -0
- package/dist/data/ai/use-session-token-sizing.cjs +73 -0
- package/dist/data/ai/use-session-token-sizing.cjs.map +1 -0
- package/dist/data/ai/use-session-token-sizing.d.ts +21 -0
- package/dist/data/ai/use-session-token-sizing.d.ts.map +1 -0
- package/dist/data/ai/use-session-token-sizing.js +73 -0
- package/dist/data/ai/use-session-token-sizing.js.map +1 -0
- package/dist/data/call-graph/CallGraph.cjs +250 -0
- package/dist/data/call-graph/CallGraph.cjs.map +1 -0
- package/dist/data/call-graph/CallGraph.d.ts +69 -0
- package/dist/data/call-graph/CallGraph.d.ts.map +1 -0
- package/dist/data/call-graph/CallGraph.js +250 -0
- package/dist/data/call-graph/CallGraph.js.map +1 -0
- package/dist/data/call-graph/CallGraphGlyphs.cjs +39 -0
- package/dist/data/call-graph/CallGraphGlyphs.cjs.map +1 -0
- package/dist/data/call-graph/CallGraphGlyphs.d.ts +19 -0
- package/dist/data/call-graph/CallGraphGlyphs.d.ts.map +1 -0
- package/dist/data/call-graph/CallGraphGlyphs.js +39 -0
- package/dist/data/call-graph/CallGraphGlyphs.js.map +1 -0
- package/dist/data/call-graph/CallGraphMembers.cjs +50 -0
- package/dist/data/call-graph/CallGraphMembers.cjs.map +1 -0
- package/dist/data/call-graph/CallGraphMembers.d.ts +22 -0
- package/dist/data/call-graph/CallGraphMembers.d.ts.map +1 -0
- package/dist/data/call-graph/CallGraphMembers.js +50 -0
- package/dist/data/call-graph/CallGraphMembers.js.map +1 -0
- package/dist/data/call-graph/CallGraphParts.cjs +204 -0
- package/dist/data/call-graph/CallGraphParts.cjs.map +1 -0
- package/dist/data/call-graph/CallGraphParts.d.ts +44 -0
- package/dist/data/call-graph/CallGraphParts.d.ts.map +1 -0
- package/dist/data/call-graph/CallGraphParts.js +204 -0
- package/dist/data/call-graph/CallGraphParts.js.map +1 -0
- package/dist/data/call-graph/CallGraphToolbar.cjs +186 -0
- package/dist/data/call-graph/CallGraphToolbar.cjs.map +1 -0
- package/dist/data/call-graph/CallGraphToolbar.d.ts +45 -0
- package/dist/data/call-graph/CallGraphToolbar.d.ts.map +1 -0
- package/dist/data/call-graph/CallGraphToolbar.js +186 -0
- package/dist/data/call-graph/CallGraphToolbar.js.map +1 -0
- package/dist/data/call-graph/call-graph-exclude.cjs +75 -0
- package/dist/data/call-graph/call-graph-exclude.cjs.map +1 -0
- package/dist/data/call-graph/call-graph-exclude.d.ts +31 -0
- package/dist/data/call-graph/call-graph-exclude.d.ts.map +1 -0
- package/dist/data/call-graph/call-graph-exclude.js +75 -0
- package/dist/data/call-graph/call-graph-exclude.js.map +1 -0
- package/dist/data/call-graph/call-graph-labels.cjs +96 -0
- package/dist/data/call-graph/call-graph-labels.cjs.map +1 -0
- package/dist/data/call-graph/call-graph-labels.d.ts +53 -0
- package/dist/data/call-graph/call-graph-labels.d.ts.map +1 -0
- package/dist/data/call-graph/call-graph-labels.js +96 -0
- package/dist/data/call-graph/call-graph-labels.js.map +1 -0
- package/dist/data/call-graph/call-graph-model.cjs +161 -0
- package/dist/data/call-graph/call-graph-model.cjs.map +1 -0
- package/dist/data/call-graph/call-graph-model.d.ts +102 -0
- package/dist/data/call-graph/call-graph-model.d.ts.map +1 -0
- package/dist/data/call-graph/call-graph-model.js +161 -0
- package/dist/data/call-graph/call-graph-model.js.map +1 -0
- package/dist/data/call-graph/call-graph-vocabulary.cjs +177 -0
- package/dist/data/call-graph/call-graph-vocabulary.cjs.map +1 -0
- package/dist/data/call-graph/call-graph-vocabulary.d.ts +72 -0
- package/dist/data/call-graph/call-graph-vocabulary.d.ts.map +1 -0
- package/dist/data/call-graph/call-graph-vocabulary.js +177 -0
- package/dist/data/call-graph/call-graph-vocabulary.js.map +1 -0
- package/dist/data/call-graph/call-graph.fixtures.d.ts +63 -0
- package/dist/data/call-graph/call-graph.fixtures.d.ts.map +1 -0
- package/dist/data/call-graph/index.d.ts +7 -0
- package/dist/data/call-graph/index.d.ts.map +1 -0
- package/dist/data/call-graph/types.cjs +5 -0
- package/dist/data/call-graph/types.cjs.map +1 -0
- package/dist/data/call-graph/types.d.ts +135 -0
- package/dist/data/call-graph/types.d.ts.map +1 -0
- package/dist/data/call-graph/types.js +5 -0
- package/dist/data/call-graph/types.js.map +1 -0
- package/dist/data/call-graph/use-call-graph.cjs +93 -0
- package/dist/data/call-graph/use-call-graph.cjs.map +1 -0
- package/dist/data/call-graph/use-call-graph.d.ts +24 -0
- package/dist/data/call-graph/use-call-graph.d.ts.map +1 -0
- package/dist/data/call-graph/use-call-graph.js +93 -0
- package/dist/data/call-graph/use-call-graph.js.map +1 -0
- package/dist/data/chat/Chat.cjs +39 -15
- package/dist/data/chat/Chat.cjs.map +1 -1
- package/dist/data/chat/Chat.d.ts.map +1 -1
- package/dist/data/chat/Chat.fixtures.cjs +2 -2
- package/dist/data/chat/Chat.fixtures.cjs.map +1 -1
- package/dist/data/chat/Chat.fixtures.js +2 -2
- package/dist/data/chat/Chat.fixtures.js.map +1 -1
- package/dist/data/chat/Chat.js +40 -16
- package/dist/data/chat/Chat.js.map +1 -1
- package/dist/data/chat/ChatRuntimeToolbar.cjs +3 -6
- package/dist/data/chat/ChatRuntimeToolbar.cjs.map +1 -1
- package/dist/data/chat/ChatRuntimeToolbar.d.ts.map +1 -1
- package/dist/data/chat/ChatRuntimeToolbar.js +3 -6
- package/dist/data/chat/ChatRuntimeToolbar.js.map +1 -1
- package/dist/data/chat/ContextMeter.bar.cjs +5 -8
- package/dist/data/chat/ContextMeter.bar.cjs.map +1 -1
- package/dist/data/chat/ContextMeter.bar.d.ts +1 -1
- package/dist/data/chat/ContextMeter.bar.d.ts.map +1 -1
- package/dist/data/chat/ContextMeter.bar.js +5 -8
- package/dist/data/chat/ContextMeter.bar.js.map +1 -1
- package/dist/data/chat/ContextMeter.cjs +18 -19
- package/dist/data/chat/ContextMeter.cjs.map +1 -1
- package/dist/data/chat/ContextMeter.d.ts +1 -1
- package/dist/data/chat/ContextMeter.d.ts.map +1 -1
- package/dist/data/chat/ContextMeter.js +18 -19
- package/dist/data/chat/ContextMeter.js.map +1 -1
- package/dist/data/chat/Conversation.cjs +2 -1
- package/dist/data/chat/Conversation.cjs.map +1 -1
- package/dist/data/chat/Conversation.d.ts +4 -1
- package/dist/data/chat/Conversation.d.ts.map +1 -1
- package/dist/data/chat/Conversation.js +2 -1
- package/dist/data/chat/Conversation.js.map +1 -1
- package/dist/data/chat/Message.cjs +39 -12
- package/dist/data/chat/Message.cjs.map +1 -1
- package/dist/data/chat/Message.d.ts +1 -1
- package/dist/data/chat/Message.d.ts.map +1 -1
- package/dist/data/chat/Message.js +40 -13
- package/dist/data/chat/Message.js.map +1 -1
- package/dist/data/chat/ToolCall.cjs +60 -5
- package/dist/data/chat/ToolCall.cjs.map +1 -1
- package/dist/data/chat/ToolCall.d.ts +7 -2
- package/dist/data/chat/ToolCall.d.ts.map +1 -1
- package/dist/data/chat/ToolCall.js +60 -5
- package/dist/data/chat/ToolCall.js.map +1 -1
- package/dist/data/chat/approval.cjs.map +1 -1
- package/dist/data/chat/approval.d.ts +2 -2
- package/dist/data/chat/approval.d.ts.map +1 -1
- package/dist/data/chat/approval.js.map +1 -1
- package/dist/data/chat/tool-policy.cjs +59 -2
- package/dist/data/chat/tool-policy.cjs.map +1 -1
- package/dist/data/chat/tool-policy.d.ts +9 -0
- package/dist/data/chat/tool-policy.d.ts.map +1 -1
- package/dist/data/chat/tool-policy.js +59 -2
- package/dist/data/chat/tool-policy.js.map +1 -1
- package/dist/data/chat/types.cjs +6 -0
- package/dist/data/chat/types.cjs.map +1 -1
- package/dist/data/chat/types.d.ts +13 -4
- package/dist/data/chat/types.d.ts.map +1 -1
- package/dist/data/chat/types.js +7 -1
- package/dist/data/chat/types.js.map +1 -1
- package/dist/data/chat/usage-snapshot.cjs +11 -6
- package/dist/data/chat/usage-snapshot.cjs.map +1 -1
- package/dist/data/chat/usage-snapshot.d.ts +0 -1
- package/dist/data/chat/usage-snapshot.d.ts.map +1 -1
- package/dist/data/chat/usage-snapshot.js +11 -6
- package/dist/data/chat/usage-snapshot.js.map +1 -1
- package/dist/data/diagnostics/StackFrameRow.cjs +3 -3
- package/dist/data/diagnostics/StackFrameRow.cjs.map +1 -1
- package/dist/data/diagnostics/StackFrameRow.js +3 -3
- package/dist/data/diagnostics/StackFrameRow.js.map +1 -1
- package/dist/data/graph-columns-layout.cjs +26 -10
- package/dist/data/graph-columns-layout.cjs.map +1 -1
- package/dist/data/graph-columns-layout.d.ts +8 -0
- package/dist/data/graph-columns-layout.d.ts.map +1 -1
- package/dist/data/graph-columns-layout.js +26 -10
- package/dist/data/graph-columns-layout.js.map +1 -1
- package/dist/data/graph-diagram-model.cjs.map +1 -1
- package/dist/data/graph-diagram-model.d.ts +5 -0
- package/dist/data/graph-diagram-model.d.ts.map +1 -1
- package/dist/data/graph-diagram-model.js.map +1 -1
- package/dist/data/graph-edge-routing.cjs +9 -3
- package/dist/data/graph-edge-routing.cjs.map +1 -1
- package/dist/data/graph-edge-routing.d.ts +2 -0
- package/dist/data/graph-edge-routing.d.ts.map +1 -1
- package/dist/data/graph-edge-routing.js +9 -3
- package/dist/data/graph-edge-routing.js.map +1 -1
- package/dist/data/json-view/JsonSource.cjs +84 -0
- package/dist/data/json-view/JsonSource.cjs.map +1 -0
- package/dist/data/json-view/JsonSource.d.ts +7 -0
- package/dist/data/json-view/JsonSource.d.ts.map +1 -0
- package/dist/data/json-view/JsonSource.js +84 -0
- package/dist/data/json-view/JsonSource.js.map +1 -0
- package/dist/data/json-view/parse-prefix.cjs +132 -0
- package/dist/data/json-view/parse-prefix.cjs.map +1 -0
- package/dist/data/json-view/parse-prefix.d.ts +11 -0
- package/dist/data/json-view/parse-prefix.d.ts.map +1 -0
- package/dist/data/json-view/parse-prefix.js +132 -0
- package/dist/data/json-view/parse-prefix.js.map +1 -0
- package/dist/data/json-view/parse-source.cjs +62 -0
- package/dist/data/json-view/parse-source.cjs.map +1 -0
- package/dist/data/json-view/parse-source.d.ts +16 -0
- package/dist/data/json-view/parse-source.d.ts.map +1 -0
- package/dist/data/json-view/parse-source.js +62 -0
- package/dist/data/json-view/parse-source.js.map +1 -0
- package/dist/data/json-view/story-fixtures.d.ts +6 -0
- package/dist/data/json-view/story-fixtures.d.ts.map +1 -0
- package/dist/data/json-view/types.d.ts +14 -0
- package/dist/data/json-view/types.d.ts.map +1 -0
- package/dist/data/runtime/RuntimeBar.cjs +2 -5
- package/dist/data/runtime/RuntimeBar.cjs.map +1 -1
- package/dist/data/runtime/RuntimeBar.d.ts +2 -4
- package/dist/data/runtime/RuntimeBar.d.ts.map +1 -1
- package/dist/data/runtime/RuntimeBar.fields.cjs +2 -2
- package/dist/data/runtime/RuntimeBar.fields.cjs.map +1 -1
- package/dist/data/runtime/RuntimeBar.fields.js +2 -2
- package/dist/data/runtime/RuntimeBar.fields.js.map +1 -1
- package/dist/data/runtime/RuntimeBar.js +2 -5
- package/dist/data/runtime/RuntimeBar.js.map +1 -1
- package/dist/data/runtime/RuntimeBar.selection.cjs +4 -1
- package/dist/data/runtime/RuntimeBar.selection.cjs.map +1 -1
- package/dist/data/runtime/RuntimeBar.selection.d.ts.map +1 -1
- package/dist/data/runtime/RuntimeBar.selection.js +5 -2
- package/dist/data/runtime/RuntimeBar.selection.js.map +1 -1
- package/dist/data/runtime/RuntimeBarActions.cjs +1 -5
- package/dist/data/runtime/RuntimeBarActions.cjs.map +1 -1
- package/dist/data/runtime/RuntimeBarActions.d.ts +1 -1
- package/dist/data/runtime/RuntimeBarActions.d.ts.map +1 -1
- package/dist/data/runtime/RuntimeBarActions.js +1 -5
- package/dist/data/runtime/RuntimeBarActions.js.map +1 -1
- package/dist/data/runtime/RuntimeBarIdentity.cjs +6 -14
- package/dist/data/runtime/RuntimeBarIdentity.cjs.map +1 -1
- package/dist/data/runtime/RuntimeBarIdentity.d.ts +0 -1
- package/dist/data/runtime/RuntimeBarIdentity.d.ts.map +1 -1
- package/dist/data/runtime/RuntimeBarIdentity.js +6 -14
- package/dist/data/runtime/RuntimeBarIdentity.js.map +1 -1
- package/dist/data/runtime/RuntimeBarLayout.cjs +8 -27
- package/dist/data/runtime/RuntimeBarLayout.cjs.map +1 -1
- package/dist/data/runtime/RuntimeBarLayout.d.ts.map +1 -1
- package/dist/data/runtime/RuntimeBarLayout.js +8 -27
- package/dist/data/runtime/RuntimeBarLayout.js.map +1 -1
- package/dist/data/runtime/RuntimeBarSegment.cjs +1 -5
- package/dist/data/runtime/RuntimeBarSegment.cjs.map +1 -1
- package/dist/data/runtime/RuntimeBarSegment.d.ts.map +1 -1
- package/dist/data/runtime/RuntimeBarSegment.js +1 -5
- package/dist/data/runtime/RuntimeBarSegment.js.map +1 -1
- package/dist/data/runtime/use-runtime-bar-overflow.cjs +4 -10
- package/dist/data/runtime/use-runtime-bar-overflow.cjs.map +1 -1
- package/dist/data/runtime/use-runtime-bar-overflow.d.ts +1 -2
- package/dist/data/runtime/use-runtime-bar-overflow.d.ts.map +1 -1
- package/dist/data/runtime/use-runtime-bar-overflow.js +4 -10
- package/dist/data/runtime/use-runtime-bar-overflow.js.map +1 -1
- package/dist/data/test-runner/TestRunner.fixtures.d.ts +0 -20
- package/dist/data/test-runner/TestRunner.fixtures.d.ts.map +1 -1
- package/dist/data/test-runner/TestRunner.large-fixtures.d.ts +22 -0
- package/dist/data/test-runner/TestRunner.large-fixtures.d.ts.map +1 -0
- package/dist/data/use-pan-zoom.cjs +23 -10
- package/dist/data/use-pan-zoom.cjs.map +1 -1
- package/dist/data/use-pan-zoom.d.ts +16 -2
- package/dist/data/use-pan-zoom.d.ts.map +1 -1
- package/dist/data/use-pan-zoom.js +23 -10
- package/dist/data/use-pan-zoom.js.map +1 -1
- package/dist/data/version-info.cjs +3 -3
- package/dist/data/version-info.js +3 -3
- package/dist/data.cjs +26 -2
- package/dist/data.cjs.map +1 -1
- package/dist/data.d.ts +1 -0
- package/dist/data.d.ts.map +1 -1
- package/dist/data.js +24 -0
- package/dist/data.js.map +1 -1
- package/dist/index.cjs +28 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -1
- package/dist/layout/Workspace.cjs +13 -4
- package/dist/layout/Workspace.cjs.map +1 -1
- package/dist/layout/Workspace.d.ts +7 -2
- package/dist/layout/Workspace.d.ts.map +1 -1
- package/dist/layout/Workspace.js +13 -4
- package/dist/layout/Workspace.js.map +1 -1
- package/dist/lib/permission-strategies.cjs +71 -11
- package/dist/lib/permission-strategies.cjs.map +1 -1
- package/dist/lib/permission-strategies.d.ts +3 -0
- package/dist/lib/permission-strategies.d.ts.map +1 -1
- package/dist/lib/permission-strategies.js +71 -11
- package/dist/lib/permission-strategies.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +5 -3
- package/dist/data/ai/ToolSchemaBrowser.selection-toolbar.cjs +0 -57
- package/dist/data/ai/ToolSchemaBrowser.selection-toolbar.cjs.map +0 -1
- package/dist/data/ai/ToolSchemaBrowser.selection-toolbar.d.ts +0 -7
- package/dist/data/ai/ToolSchemaBrowser.selection-toolbar.d.ts.map +0 -1
- package/dist/data/ai/ToolSchemaBrowser.selection-toolbar.js +0 -57
- package/dist/data/ai/ToolSchemaBrowser.selection-toolbar.js.map +0 -1
- package/dist/data/runtime/RuntimeBar.context.cjs +0 -8
- package/dist/data/runtime/RuntimeBar.context.cjs.map +0 -1
- package/dist/data/runtime/RuntimeBar.context.d.ts +0 -2
- package/dist/data/runtime/RuntimeBar.context.d.ts.map +0 -1
- package/dist/data/runtime/RuntimeBar.context.js +0 -8
- package/dist/data/runtime/RuntimeBar.context.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph-diagram-model.js","sources":["../../src/data/graph-diagram-model.ts"],"sourcesContent":["import type { KeyboardEvent, ReactNode } from \"react\";\nimport type { BadgeTone } from \"./Badge\";\nimport type { GraphLayoutPosition } from \"./graph-layout\";\n\nexport interface GraphDiagramNode {\n id: string;\n label: ReactNode;\n /** Drawn before the label, on the same line. Give the icon its own `title` so it names itself. */\n icon?: ReactNode;\n detail?: ReactNode;\n badge?: ReactNode;\n tone?: BadgeTone;\n shape?: \"pill\" | \"rect\";\n /** Accessible name for the node, when `label` alone isn't enough. */\n ariaLabel?: string;\n /** Full text for the node, shown as its native tooltip. */\n title?: string;\n /** Column of the node. Required by the \"columns\" layout; may be negative. */\n level?: number;\n /** \"columns\" layout: nodes sharing a group are stacked together and boxed. */\n group?: string;\n /** Dimmed styling, for a node that leads nowhere further: external, unresolved, not expandable. */\n muted?: boolean;\n /** Neighbours not drawn yet. Renders a `+N` control on the node's outer side. */\n expandCount?: number;\n}\n\nexport interface GraphDiagramEdge {\n id: string;\n from: string;\n to: string;\n /** Short text shown in a pill on the edge. */\n label?: string;\n /** Drawn in the pill before the label. An edge with an icon and no label still gets a pill. */\n icon?: ReactNode;\n /** What `icon` says, in words. It precedes the label in the edge's accessible name. */\n iconLabel?: string;\n /** Full text for the edge, shown as its native tooltip. */\n title?: string;\n tone?: BadgeTone;\n dashed?: boolean;\n}\n\nexport interface GraphDiagramGroup {\n id: string;\n label: ReactNode;\n /** Full text for the group, shown as its caption's native tooltip: what a shortened `label` stands for. */\n title?: string;\n}\n\nexport type GraphDiagramLayout = \"ring\" | \"columns\";\n\n/**\n * Whether edges compete for attention or take turns. With focus on, an edge\n * shows its label pill only while it is in focus — selected, hovered, or\n * attached to the selected or hovered node — and while anything is in focus\n * the other edges fade. \"auto\" turns it on past `DENSE_EDGE_COUNT` edges.\n */\nexport type GraphDiagramEdgeFocus = \"auto\" | \"on\" | \"off\";\n\n/** The most edges a diagram draws with every pill showing under `edgeFocus=\"auto\"`. */\nexport const DENSE_EDGE_COUNT = 32;\n\nexport function edgeFocusOn(mode: GraphDiagramEdgeFocus, edgeCount: number): boolean {\n return mode === \"on\" || (mode === \"auto\" && edgeCount > DENSE_EDGE_COUNT);\n}\n\n/** The edges in focus: the named ones, and every edge attached to a named node. */\nexport function focusedEdgeIds(\n edges: readonly { id: string; from: string; to: string }[],\n focus: { nodes: readonly (string | undefined)[]; edges: readonly (string | undefined)[] },\n): Set<string> {\n return new Set(\n edges\n .filter((edge) => focus.edges.includes(edge.id) || focus.nodes.includes(edge.from) || focus.nodes.includes(edge.to))\n .map((edge) => edge.id),\n );\n}\n\n/** Maps a point in layout coordinates to the CSS offsets of the stage it is drawn on. */\nexport type GraphPlacer = (point: GraphLayoutPosition) => { left: number | string; top: number | string };\n\nexport const TONE_TEXT_CLASS: Record<BadgeTone, string> = {\n neutral: \"text-muted-foreground\",\n success: \"text-emerald-600 dark:text-emerald-400\",\n danger: \"text-red-600 dark:text-red-400\",\n warning: \"text-amber-600 dark:text-amber-400\",\n info: \"text-sky-600 dark:text-sky-400\",\n};\n\nexport const TONE_NODE_CLASS: Record<BadgeTone, string> = {\n neutral: \"border-border bg-card text-foreground\",\n success: \"border-emerald-500/50 bg-emerald-500/10 text-foreground\",\n danger: \"border-red-500/50 bg-red-500/10 text-foreground\",\n warning: \"border-amber-500/50 bg-amber-500/10 text-foreground\",\n info: \"border-sky-500/50 bg-sky-500/10 text-foreground\",\n};\n\n/** The node's accessible name: its `ariaLabel`, else a plain-text label, else its id. */\nexport function nodeName(node: GraphDiagramNode): string {\n if (node.ariaLabel !== undefined) return node.ariaLabel;\n return typeof node.label === \"string\" ? node.label : node.id;\n}\n\n/** A selectable edge's accessible name: `<from> to <to>`, then what its pill shows, in words. */\nexport function edgeName(edge: GraphDiagramEdge, names: Record<string, string>): string {\n const ends = `${requireEntry(names, edge.from, \"node name\")} to ${requireEntry(names, edge.to, \"node name\")}`;\n const pill = [edge.iconLabel, edge.label].filter(Boolean).join(\" \");\n return pill === \"\" ? ends : `${ends}: ${pill}`;\n}\n\n// A pill is not measured: its size is estimated from its content, at the mean\n// glyph advance of its 10px medium label plus its padding and border.\nconst LABEL_CHAR_WIDTH = 5.4;\nconst LABEL_CHROME = 14;\n// The pill's icon slot (`text-sm`, so a 1em icon is 14px) and its `gap-1` to the text.\nconst LABEL_ICON_SIZE = 14;\nconst LABEL_ICON_GAP = 4;\n\n/** Estimated px width of an edge's pill. An icon counts as a fixed width, whatever it draws. */\nexport function edgeLabelWidth(edge: GraphDiagramEdge): number {\n const icon = edge.icon == null ? 0 : LABEL_ICON_SIZE + (edge.label ? LABEL_ICON_GAP : 0);\n return (edge.label?.length ?? 0) * LABEL_CHAR_WIDTH + icon + LABEL_CHROME;\n}\n\nexport function requireEntry<T>(entries: Record<string, T>, id: string, what: string): T {\n const entry = entries[id];\n if (entry === undefined) {\n throw new Error(`GraphDiagram: no ${what} computed for \"${id}\"`);\n }\n return entry;\n}\n\n/** Props that report an element as hovered while the pointer is over it or the keyboard focus is inside it. */\nexport function hoverHandlers(id: string, onHover: (id: string | undefined) => void) {\n const enter = () => onHover(id);\n const leave = () => onHover(undefined);\n return { onMouseEnter: enter, onMouseLeave: leave, onFocus: enter, onBlur: leave };\n}\n\n/** Enter and Space activate a focused `role=\"button\"` element, as they do a native button. */\nexport function activateOnKey(event: KeyboardEvent<Element>, activate: () => void): void {\n if (event.key === \"Enter\" || event.key === \" \") {\n event.preventDefault();\n activate();\n }\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"graph-diagram-model.js","sources":["../../src/data/graph-diagram-model.ts"],"sourcesContent":["import type { KeyboardEvent, ReactNode } from \"react\";\nimport type { BadgeTone } from \"./Badge\";\nimport type { GraphLayoutPosition } from \"./graph-layout\";\n\nexport interface GraphDiagramNode {\n id: string;\n label: ReactNode;\n /** Drawn before the label, on the same line. Give the icon its own `title` so it names itself. */\n icon?: ReactNode;\n detail?: ReactNode;\n badge?: ReactNode;\n tone?: BadgeTone;\n shape?: \"pill\" | \"rect\";\n /** Accessible name for the node, when `label` alone isn't enough. */\n ariaLabel?: string;\n /** Full text for the node, shown as its native tooltip. */\n title?: string;\n /** Column of the node. Required by the \"columns\" layout; may be negative. */\n level?: number;\n /** \"columns\" layout: nodes sharing a group are stacked together and boxed. */\n group?: string;\n /**\n * \"columns\" layout: \"compact\" draws the node on one short line at `compactNodeHeight`, its icon and\n * label only, for a member its group box already names the owner of. Defaults to \"regular\".\n */\n size?: \"regular\" | \"compact\";\n /** Dimmed styling, for a node that leads nowhere further: external, unresolved, not expandable. */\n muted?: boolean;\n /** Neighbours not drawn yet. Renders a `+N` control on the node's outer side. */\n expandCount?: number;\n}\n\nexport interface GraphDiagramEdge {\n id: string;\n from: string;\n to: string;\n /** Short text shown in a pill on the edge. */\n label?: string;\n /** Drawn in the pill before the label. An edge with an icon and no label still gets a pill. */\n icon?: ReactNode;\n /** What `icon` says, in words. It precedes the label in the edge's accessible name. */\n iconLabel?: string;\n /** Full text for the edge, shown as its native tooltip. */\n title?: string;\n tone?: BadgeTone;\n dashed?: boolean;\n}\n\nexport interface GraphDiagramGroup {\n id: string;\n label: ReactNode;\n /** Full text for the group, shown as its caption's native tooltip: what a shortened `label` stands for. */\n title?: string;\n}\n\nexport type GraphDiagramLayout = \"ring\" | \"columns\";\n\n/**\n * Whether edges compete for attention or take turns. With focus on, an edge\n * shows its label pill only while it is in focus — selected, hovered, or\n * attached to the selected or hovered node — and while anything is in focus\n * the other edges fade. \"auto\" turns it on past `DENSE_EDGE_COUNT` edges.\n */\nexport type GraphDiagramEdgeFocus = \"auto\" | \"on\" | \"off\";\n\n/** The most edges a diagram draws with every pill showing under `edgeFocus=\"auto\"`. */\nexport const DENSE_EDGE_COUNT = 32;\n\nexport function edgeFocusOn(mode: GraphDiagramEdgeFocus, edgeCount: number): boolean {\n return mode === \"on\" || (mode === \"auto\" && edgeCount > DENSE_EDGE_COUNT);\n}\n\n/** The edges in focus: the named ones, and every edge attached to a named node. */\nexport function focusedEdgeIds(\n edges: readonly { id: string; from: string; to: string }[],\n focus: { nodes: readonly (string | undefined)[]; edges: readonly (string | undefined)[] },\n): Set<string> {\n return new Set(\n edges\n .filter((edge) => focus.edges.includes(edge.id) || focus.nodes.includes(edge.from) || focus.nodes.includes(edge.to))\n .map((edge) => edge.id),\n );\n}\n\n/** Maps a point in layout coordinates to the CSS offsets of the stage it is drawn on. */\nexport type GraphPlacer = (point: GraphLayoutPosition) => { left: number | string; top: number | string };\n\nexport const TONE_TEXT_CLASS: Record<BadgeTone, string> = {\n neutral: \"text-muted-foreground\",\n success: \"text-emerald-600 dark:text-emerald-400\",\n danger: \"text-red-600 dark:text-red-400\",\n warning: \"text-amber-600 dark:text-amber-400\",\n info: \"text-sky-600 dark:text-sky-400\",\n};\n\nexport const TONE_NODE_CLASS: Record<BadgeTone, string> = {\n neutral: \"border-border bg-card text-foreground\",\n success: \"border-emerald-500/50 bg-emerald-500/10 text-foreground\",\n danger: \"border-red-500/50 bg-red-500/10 text-foreground\",\n warning: \"border-amber-500/50 bg-amber-500/10 text-foreground\",\n info: \"border-sky-500/50 bg-sky-500/10 text-foreground\",\n};\n\n/** The node's accessible name: its `ariaLabel`, else a plain-text label, else its id. */\nexport function nodeName(node: GraphDiagramNode): string {\n if (node.ariaLabel !== undefined) return node.ariaLabel;\n return typeof node.label === \"string\" ? node.label : node.id;\n}\n\n/** A selectable edge's accessible name: `<from> to <to>`, then what its pill shows, in words. */\nexport function edgeName(edge: GraphDiagramEdge, names: Record<string, string>): string {\n const ends = `${requireEntry(names, edge.from, \"node name\")} to ${requireEntry(names, edge.to, \"node name\")}`;\n const pill = [edge.iconLabel, edge.label].filter(Boolean).join(\" \");\n return pill === \"\" ? ends : `${ends}: ${pill}`;\n}\n\n// A pill is not measured: its size is estimated from its content, at the mean\n// glyph advance of its 10px medium label plus its padding and border.\nconst LABEL_CHAR_WIDTH = 5.4;\nconst LABEL_CHROME = 14;\n// The pill's icon slot (`text-sm`, so a 1em icon is 14px) and its `gap-1` to the text.\nconst LABEL_ICON_SIZE = 14;\nconst LABEL_ICON_GAP = 4;\n\n/** Estimated px width of an edge's pill. An icon counts as a fixed width, whatever it draws. */\nexport function edgeLabelWidth(edge: GraphDiagramEdge): number {\n const icon = edge.icon == null ? 0 : LABEL_ICON_SIZE + (edge.label ? LABEL_ICON_GAP : 0);\n return (edge.label?.length ?? 0) * LABEL_CHAR_WIDTH + icon + LABEL_CHROME;\n}\n\nexport function requireEntry<T>(entries: Record<string, T>, id: string, what: string): T {\n const entry = entries[id];\n if (entry === undefined) {\n throw new Error(`GraphDiagram: no ${what} computed for \"${id}\"`);\n }\n return entry;\n}\n\n/** Props that report an element as hovered while the pointer is over it or the keyboard focus is inside it. */\nexport function hoverHandlers(id: string, onHover: (id: string | undefined) => void) {\n const enter = () => onHover(id);\n const leave = () => onHover(undefined);\n return { onMouseEnter: enter, onMouseLeave: leave, onFocus: enter, onBlur: leave };\n}\n\n/** Enter and Space activate a focused `role=\"button\"` element, as they do a native button. */\nexport function activateOnKey(event: KeyboardEvent<Element>, activate: () => void): void {\n if (event.key === \"Enter\" || event.key === \" \") {\n event.preventDefault();\n activate();\n }\n}\n"],"names":[],"mappings":"AAkEO,MAAM,mBAAmB;AAEzB,SAAS,YAAY,MAA6B,WAA4B;AACnF,SAAO,SAAS,QAAS,SAAS,UAAU,YAAY;AAC1D;AAGO,SAAS,eACd,OACA,OACa;AACb,SAAO,IAAI;AAAA,IACT,MACG,OAAO,CAAC,SAAS,MAAM,MAAM,SAAS,KAAK,EAAE,KAAK,MAAM,MAAM,SAAS,KAAK,IAAI,KAAK,MAAM,MAAM,SAAS,KAAK,EAAE,CAAC,EAClH,IAAI,CAAC,SAAS,KAAK,EAAE;AAAA,EAAA;AAE5B;AAKO,MAAM,kBAA6C;AAAA,EACxD,SAAS;AAAA,EACT,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,MAAM;AACR;AAEO,MAAM,kBAA6C;AAAA,EACxD,SAAS;AAAA,EACT,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,MAAM;AACR;AAGO,SAAS,SAAS,MAAgC;AACvD,MAAI,KAAK,cAAc,OAAW,QAAO,KAAK;AAC9C,SAAO,OAAO,KAAK,UAAU,WAAW,KAAK,QAAQ,KAAK;AAC5D;AAGO,SAAS,SAAS,MAAwB,OAAuC;AACtF,QAAM,OAAO,GAAG,aAAa,OAAO,KAAK,MAAM,WAAW,CAAC,OAAO,aAAa,OAAO,KAAK,IAAI,WAAW,CAAC;AAC3G,QAAM,OAAO,CAAC,KAAK,WAAW,KAAK,KAAK,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG;AAClE,SAAO,SAAS,KAAK,OAAO,GAAG,IAAI,KAAK,IAAI;AAC9C;AAIA,MAAM,mBAAmB;AACzB,MAAM,eAAe;AAErB,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;AAGhB,SAAS,eAAe,MAAgC;AA3DxD;AA4DL,QAAM,OAAO,KAAK,QAAQ,OAAO,IAAI,mBAAmB,KAAK,QAAQ,iBAAiB;AACtF,YAAQ,UAAK,UAAL,mBAAY,WAAU,KAAK,mBAAmB,OAAO;AAC/D;AAEO,SAAS,aAAgB,SAA4B,IAAY,MAAiB;AACvF,QAAM,QAAQ,QAAQ,EAAE;AACxB,MAAI,UAAU,QAAW;AACvB,UAAM,IAAI,MAAM,oBAAoB,IAAI,kBAAkB,EAAE,GAAG;AAAA,EACjE;AACA,SAAO;AACT;AAGO,SAAS,cAAc,IAAY,SAA2C;AACnF,QAAM,QAAQ,MAAM,QAAQ,EAAE;AAC9B,QAAM,QAAQ,MAAM,QAAQ,MAAS;AACrC,SAAO,EAAE,cAAc,OAAO,cAAc,OAAO,SAAS,OAAO,QAAQ,MAAA;AAC7E;AAGO,SAAS,cAAc,OAA+B,UAA4B;AACvF,MAAI,MAAM,QAAQ,WAAW,MAAM,QAAQ,KAAK;AAC9C,UAAM,eAAA;AACN,aAAA;AAAA,EACF;AACF;"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
function heightOf(dimensions, id) {
|
|
4
|
+
var _a;
|
|
5
|
+
return ((_a = dimensions.nodeHeights) == null ? void 0 : _a[id]) ?? dimensions.nodeHeight;
|
|
6
|
+
}
|
|
3
7
|
const CURVE_OFFSET = 22;
|
|
4
8
|
const MIN_SIDE_REACH = 36;
|
|
5
9
|
const LOOP_BASE_REACH = 24;
|
|
@@ -136,7 +140,7 @@ function planLoops(edges, positions, nodeWidth) {
|
|
|
136
140
|
function loopRoute(from, to, options) {
|
|
137
141
|
const { side, maxReach } = options.plan;
|
|
138
142
|
const halfW = options.dimensions.nodeWidth / 2;
|
|
139
|
-
const spread = options.self ? options.
|
|
143
|
+
const spread = options.self ? options.loopHeight / 4 : 0;
|
|
140
144
|
const startY = from.y - spread;
|
|
141
145
|
const endY = to.y + spread;
|
|
142
146
|
const reach = Math.min(maxReach, Math.max(MIN_SIDE_REACH, LOOP_BASE_REACH + LOOP_SPAN_RATE * Math.abs(endY - startY))) + options.index * CURVE_OFFSET;
|
|
@@ -154,14 +158,16 @@ function loopRoute(from, to, options) {
|
|
|
154
158
|
}
|
|
155
159
|
function routeSideGroup(group, positions, dimensions, loops, routes) {
|
|
156
160
|
const halfW = dimensions.nodeWidth / 2;
|
|
157
|
-
const
|
|
161
|
+
const first = requireEdge(group, 0);
|
|
162
|
+
const shorter = Math.min(heightOf(dimensions, first.from), heightOf(dimensions, first.to));
|
|
163
|
+
const step = group.length > 1 ? Math.min(CURVE_OFFSET, Math.max(0, shorter - PORT_INSET) / (group.length - 1)) : 0;
|
|
158
164
|
group.forEach((edge, index) => {
|
|
159
165
|
const from = requirePosition(positions, edge.from);
|
|
160
166
|
const to = requirePosition(positions, edge.to);
|
|
161
167
|
if (isLoop(from, to, dimensions.nodeWidth)) {
|
|
162
168
|
const plan = loops.get(from.x);
|
|
163
169
|
if (!plan) throw new Error(`routeEdges: no loop plan for the column of "${edge.from}"`);
|
|
164
|
-
routes[edge.id] = loopRoute(from, to, { self: edge.from === edge.to, index, dimensions, plan });
|
|
170
|
+
routes[edge.id] = loopRoute(from, to, { self: edge.from === edge.to, index, dimensions, plan, loopHeight: heightOf(dimensions, edge.from) });
|
|
165
171
|
return;
|
|
166
172
|
}
|
|
167
173
|
const direction = to.x > from.x ? 1 : -1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph-edge-routing.cjs","sources":["../../src/data/graph-edge-routing.ts"],"sourcesContent":["// Edge routing and label placement for GraphDiagram: pure math, no React.\n// Split from graph-layout.ts, which owns the position types and `ringLayout`\n// and re-exports this file's API.\n\nimport type { GraphLayoutPosition } from \"./graph-layout\";\n\nexport interface GraphLayoutEdge {\n id: string;\n from: string;\n to: string;\n}\n\n/** Start, two control points and end of a cubic Bézier. */\nexport type CubicCurve = readonly [GraphLayoutPosition, GraphLayoutPosition, GraphLayoutPosition, GraphLayoutPosition];\n\nexport interface EdgeRoute {\n /** SVG path `d` attribute, clipped to the node rectangle boundaries. */\n path: string;\n /** Midpoint of the rendered path, for placing an edge label. */\n labelX: number;\n labelY: number;\n /**\n * Set on a loop, whose midpoint is its outermost point: \"start\" when a label\n * should begin at the point and run right of it, \"end\" when it should end\n * there and run left. A centred label would reach back over the node.\n */\n labelAnchor?: \"start\" | \"end\";\n /** A side-anchored edge between two columns: its curve, for placing a label elsewhere than its midpoint. */\n curve?: CubicCurve;\n}\n\nexport interface RouteEdgesDimensions {\n nodeWidth: number;\n nodeHeight: number;\n}\n\nexport interface RouteEdgesOptions {\n /** Where edges attach: clipped toward the node centre, or at the left/right side middles. Defaults to \"center\". */\n anchor?: \"center\" | \"side\";\n}\n\nconst CURVE_OFFSET = 22;\nconst MIN_SIDE_REACH = 36;\n/** A loop reaches this far plus a share of the height it spans, so a longer loop arcs outside a shorter one. */\nconst LOOP_BASE_REACH = 24;\nconst LOOP_SPAN_RATE = 0.18;\nconst MAX_LOOP_REACH = 240;\n/** The share of the gap to the next column a loop may bulge into. */\nconst LOOP_GAP_SHARE = 0.6;\n/** A cubic whose two control points share an x peaks at 3/4 of their offset. */\nconst CUBIC_PEAK = 0.75;\n/** Vertical margin kept between fanned side anchors and the node's corners. */\nconst PORT_INSET = 12;\n\nfunction unorderedPairKey(a: string, b: string): string {\n return a < b ? `${a}\\0${b}` : `${b}\\0${a}`;\n}\n\nfunction requirePosition(positions: Record<string, GraphLayoutPosition>, id: string): GraphLayoutPosition {\n const position = positions[id];\n if (!position) {\n throw new Error(`routeEdges: no layout position for node \"${id}\"`);\n }\n return position;\n}\n\nfunction requireEdge(group: readonly GraphLayoutEdge[], index: number): GraphLayoutEdge {\n const edge = group[index];\n if (!edge) {\n throw new Error(`routeEdges: expected an edge at index ${index}`);\n }\n return edge;\n}\n\n/** Point on the rectangle (centred at `center`, half-extents `halfW`/`halfH`) where the ray toward `towards` exits. */\nfunction clipToRect(\n center: GraphLayoutPosition,\n towards: GraphLayoutPosition,\n halfW: number,\n halfH: number,\n): GraphLayoutPosition {\n const dx = towards.x - center.x;\n const dy = towards.y - center.y;\n if (dx === 0 && dy === 0) return { x: center.x, y: center.y };\n\n const scaleX = dx !== 0 ? halfW / Math.abs(dx) : Number.POSITIVE_INFINITY;\n const scaleY = dy !== 0 ? halfH / Math.abs(dy) : Number.POSITIVE_INFINITY;\n const scale = Math.min(scaleX, scaleY);\n\n return { x: center.x + dx * scale, y: center.y + dy * scale };\n}\n\n/** Point at t=0.5 on the quadratic Bézier defined by p0 (start), p1 (control), p2 (end). */\nfunction quadraticMidpoint(\n p0: GraphLayoutPosition,\n p1: GraphLayoutPosition,\n p2: GraphLayoutPosition,\n): GraphLayoutPosition {\n return {\n x: 0.25 * p0.x + 0.5 * p1.x + 0.25 * p2.x,\n y: 0.25 * p0.y + 0.5 * p1.y + 0.25 * p2.y,\n };\n}\n\n/** Edges sharing an unordered node pair, in input order; throws on an edge whose node has no position. */\nfunction groupEdgesByPair(\n edges: readonly GraphLayoutEdge[],\n positions: Record<string, GraphLayoutPosition>,\n): GraphLayoutEdge[][] {\n const groups = new Map<string, GraphLayoutEdge[]>();\n for (const edge of edges) {\n if (!(edge.from in positions)) {\n throw new Error(`routeEdges: edge \"${edge.id}\" references unknown node \"${edge.from}\"`);\n }\n if (!(edge.to in positions)) {\n throw new Error(`routeEdges: edge \"${edge.id}\" references unknown node \"${edge.to}\"`);\n }\n const key = unorderedPairKey(edge.from, edge.to);\n const group = groups.get(key);\n if (group) {\n group.push(edge);\n } else {\n groups.set(key, [edge]);\n }\n }\n return [...groups.values()];\n}\n\nfunction routeCenterGroup(\n group: readonly GraphLayoutEdge[],\n positions: Record<string, GraphLayoutPosition>,\n dimensions: RouteEdgesDimensions,\n routes: Record<string, EdgeRoute>,\n): void {\n const halfW = dimensions.nodeWidth / 2;\n const halfH = dimensions.nodeHeight / 2;\n const first = requireEdge(group, 0);\n const posA = requirePosition(positions, first.from);\n const posB = requirePosition(positions, first.to);\n const dx = posB.x - posA.x;\n const dy = posB.y - posA.y;\n const len = Math.hypot(dx, dy) || 1;\n const perpX = -dy / len;\n const perpY = dx / len;\n const midX = (posA.x + posB.x) / 2;\n const midY = (posA.y + posB.y) / 2;\n\n group.forEach((edge, index) => {\n const isCurved = group.length > 1;\n const sign = index % 2 === 0 ? 1 : -1;\n const magnitude = Math.floor(index / 2) + 1;\n const offset = isCurved ? sign * magnitude * CURVE_OFFSET : 0;\n\n const control = { x: midX + perpX * offset, y: midY + perpY * offset };\n const fromCenter = requirePosition(positions, edge.from);\n const toCenter = requirePosition(positions, edge.to);\n const start = clipToRect(fromCenter, control, halfW, halfH);\n const end = clipToRect(toCenter, control, halfW, halfH);\n\n const path = isCurved\n ? `M ${start.x} ${start.y} Q ${control.x} ${control.y} ${end.x} ${end.y}`\n : `M ${start.x} ${start.y} L ${end.x} ${end.y}`;\n\n const label = isCurved\n ? quadraticMidpoint(start, control, end)\n : { x: (start.x + end.x) / 2, y: (start.y + end.y) / 2 };\n\n routes[edge.id] = { path, labelX: label.x, labelY: label.y };\n });\n}\n\n/** The point at `t` (0 at the start, 1 at the end) along a cubic Bézier. */\nexport function pointOnCurve([p0, c1, c2, p3]: CubicCurve, t: number): GraphLayoutPosition {\n const u = 1 - t;\n const weights = [u * u * u, 3 * u * u * t, 3 * u * t * t, t * t * t] as const;\n return {\n x: weights[0] * p0.x + weights[1] * c1.x + weights[2] * c2.x + weights[3] * p3.x,\n y: weights[0] * p0.y + weights[1] * c1.y + weights[2] * c2.y + weights[3] * p3.y,\n };\n}\n\nfunction cubicRoute(curve: CubicCurve): EdgeRoute {\n const [p0, c1, c2, p3] = curve;\n const label = pointOnCurve(curve, 0.5);\n return {\n path: `M ${p0.x} ${p0.y} C ${c1.x} ${c1.y} ${c2.x} ${c2.y} ${p3.x} ${p3.y}`,\n labelX: label.x,\n labelY: label.y,\n };\n}\n\ninterface LoopPlan {\n /** 1 when the column's loops bulge right of it, -1 when left. */\n side: 1 | -1;\n /** The furthest a loop's control points may sit from the column, so it stays clear of the next one. */\n maxReach: number;\n}\n\nfunction isLoop(from: GraphLayoutPosition, to: GraphLayoutPosition, nodeWidth: number): boolean {\n return Math.abs(to.x - from.x) < nodeWidth;\n}\n\n/**\n * For each column (each distinct node x), where its loops go: the side with\n * fewer edges to other columns attached, the right on a tie, and no further\n * than a share of the gap to the next column on that side.\n */\nfunction planLoops(\n edges: readonly GraphLayoutEdge[],\n positions: Record<string, GraphLayoutPosition>,\n nodeWidth: number,\n): Map<number, LoopPlan> {\n const attached = new Map<number, { left: number; right: number }>();\n for (const { x } of Object.values(positions)) attached.set(x, { left: 0, right: 0 });\n const attach = (x: number, side: \"left\" | \"right\") => {\n const tally = attached.get(x);\n if (tally) tally[side] += 1;\n };\n for (const edge of edges) {\n const from = requirePosition(positions, edge.from);\n const to = requirePosition(positions, edge.to);\n if (isLoop(from, to, nodeWidth)) continue;\n const forward = to.x > from.x;\n attach(from.x, forward ? \"right\" : \"left\");\n attach(to.x, forward ? \"left\" : \"right\");\n }\n const columns = [...attached.keys()];\n return new Map(\n columns.map((x) => {\n const tally = attached.get(x) ?? { left: 0, right: 0 };\n const side = tally.left < tally.right ? -1 : 1;\n const gaps = columns.filter((other) => (other - x) * side > 0).map((other) => Math.abs(other - x) - nodeWidth);\n const room = gaps.length === 0 ? Number.POSITIVE_INFINITY : (LOOP_GAP_SHARE * Math.min(...gaps)) / CUBIC_PEAK;\n return [x, { side, maxReach: Math.min(MAX_LOOP_REACH, Math.max(0, room)) }];\n }),\n );\n}\n\n/** Out of one side of a column and back into it: an edge inside one column, or a self-edge. */\nfunction loopRoute(\n from: GraphLayoutPosition,\n to: GraphLayoutPosition,\n options: { self: boolean; index: number; dimensions: RouteEdgesDimensions; plan: LoopPlan },\n): EdgeRoute {\n const { side, maxReach } = options.plan;\n const halfW = options.dimensions.nodeWidth / 2;\n const spread = options.self ? options.dimensions.nodeHeight / 4 : 0;\n const startY = from.y - spread;\n const endY = to.y + spread;\n const reach =\n Math.min(maxReach, Math.max(MIN_SIDE_REACH, LOOP_BASE_REACH + LOOP_SPAN_RATE * Math.abs(endY - startY))) +\n options.index * CURVE_OFFSET;\n const outer = side > 0 ? Math.max(from.x, to.x) : Math.min(from.x, to.x);\n const bulge = outer + side * (halfW + reach);\n return {\n ...cubicRoute([\n { x: from.x + side * halfW, y: startY },\n { x: bulge, y: startY },\n { x: bulge, y: endY },\n { x: to.x + side * halfW, y: endY },\n ]),\n labelAnchor: side > 0 ? \"start\" : \"end\",\n };\n}\n\nfunction routeSideGroup(\n group: readonly GraphLayoutEdge[],\n positions: Record<string, GraphLayoutPosition>,\n dimensions: RouteEdgesDimensions,\n loops: ReadonlyMap<number, LoopPlan>,\n routes: Record<string, EdgeRoute>,\n): void {\n const halfW = dimensions.nodeWidth / 2;\n const step =\n group.length > 1\n ? Math.min(CURVE_OFFSET, (dimensions.nodeHeight - PORT_INSET) / (group.length - 1))\n : 0;\n\n group.forEach((edge, index) => {\n const from = requirePosition(positions, edge.from);\n const to = requirePosition(positions, edge.to);\n if (isLoop(from, to, dimensions.nodeWidth)) {\n const plan = loops.get(from.x);\n if (!plan) throw new Error(`routeEdges: no loop plan for the column of \"${edge.from}\"`);\n routes[edge.id] = loopRoute(from, to, { self: edge.from === edge.to, index, dimensions, plan });\n return;\n }\n const direction = to.x > from.x ? 1 : -1;\n const shift = (index - (group.length - 1) / 2) * step;\n const start = { x: from.x + direction * halfW, y: from.y + shift };\n const end = { x: to.x - direction * halfW, y: to.y + shift };\n const reach = Math.max(MIN_SIDE_REACH, Math.abs(end.x - start.x) / 2);\n const curve: CubicCurve = [\n start,\n { x: start.x + direction * reach, y: start.y },\n { x: end.x - direction * reach, y: end.y },\n end,\n ];\n routes[edge.id] = { ...cubicRoute(curve), curve };\n });\n}\n\n/**\n * Routes each edge as an SVG path. Edges sharing an unordered node pair — a\n * reciprocal A→B + B→A, or literal duplicates — are always fanned apart so\n * they never overlap.\n *\n * `anchor: \"center\"` (the default) clips each edge to the source/target node\n * rectangles: a lone edge is a straight line, a fanned one a quadratic curve\n * offset from the line between the two node centres.\n *\n * `anchor: \"side\"` is for column layouts: an edge leaves the side of its\n * source facing the target and enters the facing side of the target as a\n * cubic curve. An edge between two nodes of one column, and a self-edge, is a\n * loop: it arcs out of the column and back on the side with fewer edges to\n * other columns, the further the more height it spans, so loops nest.\n *\n * Throws when an edge references a node id absent from `positions`, naming\n * the edge id, rather than silently dropping or mis-routing it.\n */\nexport function routeEdges(\n edges: readonly GraphLayoutEdge[],\n positions: Record<string, GraphLayoutPosition>,\n dimensions: RouteEdgesDimensions,\n options: RouteEdgesOptions = {},\n): Record<string, EdgeRoute> {\n const routes: Record<string, EdgeRoute> = {};\n const groups = groupEdgesByPair(edges, positions);\n if (options.anchor !== \"side\") {\n for (const group of groups) routeCenterGroup(group, positions, dimensions, routes);\n return routes;\n }\n const loops = planLoops(edges, positions, dimensions.nodeWidth);\n for (const group of groups) routeSideGroup(group, positions, dimensions, loops, routes);\n return routes;\n}\n\n/** How far the side-anchored loops of `edges` reach past the outermost columns, on each side. */\nexport function loopOverhang(\n edges: readonly GraphLayoutEdge[],\n positions: Record<string, GraphLayoutPosition>,\n dimensions: RouteEdgesDimensions,\n): { left: number; right: number } {\n const xs = Object.values(positions).map((position) => position.x);\n const loops = Object.values(routeEdges(edges, positions, dimensions, { anchor: \"side\" })).filter(\n (route) => route.labelAnchor !== undefined,\n );\n if (loops.length === 0) return { left: 0, right: 0 };\n const peaks = loops.map((route) => route.labelX);\n const halfW = dimensions.nodeWidth / 2;\n return {\n left: Math.max(0, Math.min(...xs) - halfW - Math.min(...peaks)),\n right: Math.max(0, Math.max(...peaks) - (Math.max(...xs) + halfW)),\n };\n}\n\nexport interface EdgeLabelBox {\n id: string;\n /** The label's anchor: its centre, its left edge when `anchor` is \"start\", its right edge when \"end\". */\n x: number;\n y: number;\n width: number;\n height: number;\n anchor?: \"start\" | \"end\";\n}\n\nfunction labelLeft(box: EdgeLabelBox): number {\n if (box.anchor === \"start\") return box.x;\n return box.anchor === \"end\" ? box.x - box.width : box.x - box.width / 2;\n}\n\n/**\n * Resolves the y of each edge label so no two labels cover each other: taken\n * top to bottom, a label that would overlap one already placed drops just\n * below it. Labels keep their x, and a label that overlaps nothing keeps its y.\n */\nexport function spreadLabels(boxes: readonly EdgeLabelBox[], gap = 2): Record<string, number> {\n const placed: { left: number; right: number; y: number; height: number }[] = [];\n const ys: Record<string, number> = {};\n for (const box of [...boxes].sort((a, b) => a.y - b.y)) {\n const left = labelLeft(box);\n const right = left + box.width;\n let y = box.y;\n for (let moved = true; moved; ) {\n moved = false;\n for (const other of placed) {\n const clearance = (box.height + other.height) / 2 + gap;\n if (left < other.right && other.left < right && Math.abs(y - other.y) < clearance) {\n y = other.y + clearance;\n moved = true;\n }\n }\n }\n placed.push({ left, right, y, height: box.height });\n ys[box.id] = y;\n }\n return ys;\n}\n"],"names":[],"mappings":";;AAyCA,MAAM,eAAe;AACrB,MAAM,iBAAiB;AAEvB,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;AACvB,MAAM,iBAAiB;AAEvB,MAAM,iBAAiB;AAEvB,MAAM,aAAa;AAEnB,MAAM,aAAa;AAEnB,SAAS,iBAAiB,GAAW,GAAmB;AACtD,SAAO,IAAI,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,KAAK,CAAC;AAC1C;AAEA,SAAS,gBAAgB,WAAgD,IAAiC;AACxG,QAAM,WAAW,UAAU,EAAE;AAC7B,MAAI,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AAM,CAAC,IAAI,WAAW;AACjF,cAAI,MAAM,IAAI;AACd,kBAAQ;AAAA,QACV;AAAA,MACF;AAAA,IACF;AACA,WAAO,KAAK,EAAE,MAAM,OAAO,GAAG,QAAQ,IAAI,QAAQ;AAClD,OAAG,IAAI,EAAE,IAAI;AAAA,EACf;AACA,SAAO;AACT;;;;;"}
|
|
1
|
+
{"version":3,"file":"graph-edge-routing.cjs","sources":["../../src/data/graph-edge-routing.ts"],"sourcesContent":["// Edge routing and label placement for GraphDiagram: pure math, no React.\n// Split from graph-layout.ts, which owns the position types and `ringLayout`\n// and re-exports this file's API.\n\nimport type { GraphLayoutPosition } from \"./graph-layout\";\n\nexport interface GraphLayoutEdge {\n id: string;\n from: string;\n to: string;\n}\n\n/** Start, two control points and end of a cubic Bézier. */\nexport type CubicCurve = readonly [GraphLayoutPosition, GraphLayoutPosition, GraphLayoutPosition, GraphLayoutPosition];\n\nexport interface EdgeRoute {\n /** SVG path `d` attribute, clipped to the node rectangle boundaries. */\n path: string;\n /** Midpoint of the rendered path, for placing an edge label. */\n labelX: number;\n labelY: number;\n /**\n * Set on a loop, whose midpoint is its outermost point: \"start\" when a label\n * should begin at the point and run right of it, \"end\" when it should end\n * there and run left. A centred label would reach back over the node.\n */\n labelAnchor?: \"start\" | \"end\";\n /** A side-anchored edge between two columns: its curve, for placing a label elsewhere than its midpoint. */\n curve?: CubicCurve;\n}\n\nexport interface RouteEdgesDimensions {\n nodeWidth: number;\n nodeHeight: number;\n /** Heights of the nodes not drawn at `nodeHeight`, by id. */\n nodeHeights?: Readonly<Record<string, number>>;\n}\n\nfunction heightOf(dimensions: RouteEdgesDimensions, id: string): number {\n return dimensions.nodeHeights?.[id] ?? dimensions.nodeHeight;\n}\n\nexport interface RouteEdgesOptions {\n /** Where edges attach: clipped toward the node centre, or at the left/right side middles. Defaults to \"center\". */\n anchor?: \"center\" | \"side\";\n}\n\nconst CURVE_OFFSET = 22;\nconst MIN_SIDE_REACH = 36;\n/** A loop reaches this far plus a share of the height it spans, so a longer loop arcs outside a shorter one. */\nconst LOOP_BASE_REACH = 24;\nconst LOOP_SPAN_RATE = 0.18;\nconst MAX_LOOP_REACH = 240;\n/** The share of the gap to the next column a loop may bulge into. */\nconst LOOP_GAP_SHARE = 0.6;\n/** A cubic whose two control points share an x peaks at 3/4 of their offset. */\nconst CUBIC_PEAK = 0.75;\n/** Vertical margin kept between fanned side anchors and the node's corners. */\nconst PORT_INSET = 12;\n\nfunction unorderedPairKey(a: string, b: string): string {\n return a < b ? `${a}\\0${b}` : `${b}\\0${a}`;\n}\n\nfunction requirePosition(positions: Record<string, GraphLayoutPosition>, id: string): GraphLayoutPosition {\n const position = positions[id];\n if (!position) {\n throw new Error(`routeEdges: no layout position for node \"${id}\"`);\n }\n return position;\n}\n\nfunction requireEdge(group: readonly GraphLayoutEdge[], index: number): GraphLayoutEdge {\n const edge = group[index];\n if (!edge) {\n throw new Error(`routeEdges: expected an edge at index ${index}`);\n }\n return edge;\n}\n\n/** Point on the rectangle (centred at `center`, half-extents `halfW`/`halfH`) where the ray toward `towards` exits. */\nfunction clipToRect(\n center: GraphLayoutPosition,\n towards: GraphLayoutPosition,\n halfW: number,\n halfH: number,\n): GraphLayoutPosition {\n const dx = towards.x - center.x;\n const dy = towards.y - center.y;\n if (dx === 0 && dy === 0) return { x: center.x, y: center.y };\n\n const scaleX = dx !== 0 ? halfW / Math.abs(dx) : Number.POSITIVE_INFINITY;\n const scaleY = dy !== 0 ? halfH / Math.abs(dy) : Number.POSITIVE_INFINITY;\n const scale = Math.min(scaleX, scaleY);\n\n return { x: center.x + dx * scale, y: center.y + dy * scale };\n}\n\n/** Point at t=0.5 on the quadratic Bézier defined by p0 (start), p1 (control), p2 (end). */\nfunction quadraticMidpoint(\n p0: GraphLayoutPosition,\n p1: GraphLayoutPosition,\n p2: GraphLayoutPosition,\n): GraphLayoutPosition {\n return {\n x: 0.25 * p0.x + 0.5 * p1.x + 0.25 * p2.x,\n y: 0.25 * p0.y + 0.5 * p1.y + 0.25 * p2.y,\n };\n}\n\n/** Edges sharing an unordered node pair, in input order; throws on an edge whose node has no position. */\nfunction groupEdgesByPair(\n edges: readonly GraphLayoutEdge[],\n positions: Record<string, GraphLayoutPosition>,\n): GraphLayoutEdge[][] {\n const groups = new Map<string, GraphLayoutEdge[]>();\n for (const edge of edges) {\n if (!(edge.from in positions)) {\n throw new Error(`routeEdges: edge \"${edge.id}\" references unknown node \"${edge.from}\"`);\n }\n if (!(edge.to in positions)) {\n throw new Error(`routeEdges: edge \"${edge.id}\" references unknown node \"${edge.to}\"`);\n }\n const key = unorderedPairKey(edge.from, edge.to);\n const group = groups.get(key);\n if (group) {\n group.push(edge);\n } else {\n groups.set(key, [edge]);\n }\n }\n return [...groups.values()];\n}\n\nfunction routeCenterGroup(\n group: readonly GraphLayoutEdge[],\n positions: Record<string, GraphLayoutPosition>,\n dimensions: RouteEdgesDimensions,\n routes: Record<string, EdgeRoute>,\n): void {\n const halfW = dimensions.nodeWidth / 2;\n const halfH = dimensions.nodeHeight / 2;\n const first = requireEdge(group, 0);\n const posA = requirePosition(positions, first.from);\n const posB = requirePosition(positions, first.to);\n const dx = posB.x - posA.x;\n const dy = posB.y - posA.y;\n const len = Math.hypot(dx, dy) || 1;\n const perpX = -dy / len;\n const perpY = dx / len;\n const midX = (posA.x + posB.x) / 2;\n const midY = (posA.y + posB.y) / 2;\n\n group.forEach((edge, index) => {\n const isCurved = group.length > 1;\n const sign = index % 2 === 0 ? 1 : -1;\n const magnitude = Math.floor(index / 2) + 1;\n const offset = isCurved ? sign * magnitude * CURVE_OFFSET : 0;\n\n const control = { x: midX + perpX * offset, y: midY + perpY * offset };\n const fromCenter = requirePosition(positions, edge.from);\n const toCenter = requirePosition(positions, edge.to);\n const start = clipToRect(fromCenter, control, halfW, halfH);\n const end = clipToRect(toCenter, control, halfW, halfH);\n\n const path = isCurved\n ? `M ${start.x} ${start.y} Q ${control.x} ${control.y} ${end.x} ${end.y}`\n : `M ${start.x} ${start.y} L ${end.x} ${end.y}`;\n\n const label = isCurved\n ? quadraticMidpoint(start, control, end)\n : { x: (start.x + end.x) / 2, y: (start.y + end.y) / 2 };\n\n routes[edge.id] = { path, labelX: label.x, labelY: label.y };\n });\n}\n\n/** The point at `t` (0 at the start, 1 at the end) along a cubic Bézier. */\nexport function pointOnCurve([p0, c1, c2, p3]: CubicCurve, t: number): GraphLayoutPosition {\n const u = 1 - t;\n const weights = [u * u * u, 3 * u * u * t, 3 * u * t * t, t * t * t] as const;\n return {\n x: weights[0] * p0.x + weights[1] * c1.x + weights[2] * c2.x + weights[3] * p3.x,\n y: weights[0] * p0.y + weights[1] * c1.y + weights[2] * c2.y + weights[3] * p3.y,\n };\n}\n\nfunction cubicRoute(curve: CubicCurve): EdgeRoute {\n const [p0, c1, c2, p3] = curve;\n const label = pointOnCurve(curve, 0.5);\n return {\n path: `M ${p0.x} ${p0.y} C ${c1.x} ${c1.y} ${c2.x} ${c2.y} ${p3.x} ${p3.y}`,\n labelX: label.x,\n labelY: label.y,\n };\n}\n\ninterface LoopPlan {\n /** 1 when the column's loops bulge right of it, -1 when left. */\n side: 1 | -1;\n /** The furthest a loop's control points may sit from the column, so it stays clear of the next one. */\n maxReach: number;\n}\n\nfunction isLoop(from: GraphLayoutPosition, to: GraphLayoutPosition, nodeWidth: number): boolean {\n return Math.abs(to.x - from.x) < nodeWidth;\n}\n\n/**\n * For each column (each distinct node x), where its loops go: the side with\n * fewer edges to other columns attached, the right on a tie, and no further\n * than a share of the gap to the next column on that side.\n */\nfunction planLoops(\n edges: readonly GraphLayoutEdge[],\n positions: Record<string, GraphLayoutPosition>,\n nodeWidth: number,\n): Map<number, LoopPlan> {\n const attached = new Map<number, { left: number; right: number }>();\n for (const { x } of Object.values(positions)) attached.set(x, { left: 0, right: 0 });\n const attach = (x: number, side: \"left\" | \"right\") => {\n const tally = attached.get(x);\n if (tally) tally[side] += 1;\n };\n for (const edge of edges) {\n const from = requirePosition(positions, edge.from);\n const to = requirePosition(positions, edge.to);\n if (isLoop(from, to, nodeWidth)) continue;\n const forward = to.x > from.x;\n attach(from.x, forward ? \"right\" : \"left\");\n attach(to.x, forward ? \"left\" : \"right\");\n }\n const columns = [...attached.keys()];\n return new Map(\n columns.map((x) => {\n const tally = attached.get(x) ?? { left: 0, right: 0 };\n const side = tally.left < tally.right ? -1 : 1;\n const gaps = columns.filter((other) => (other - x) * side > 0).map((other) => Math.abs(other - x) - nodeWidth);\n const room = gaps.length === 0 ? Number.POSITIVE_INFINITY : (LOOP_GAP_SHARE * Math.min(...gaps)) / CUBIC_PEAK;\n return [x, { side, maxReach: Math.min(MAX_LOOP_REACH, Math.max(0, room)) }];\n }),\n );\n}\n\n/** Out of one side of a column and back into it: an edge inside one column, or a self-edge. */\nfunction loopRoute(\n from: GraphLayoutPosition,\n to: GraphLayoutPosition,\n options: { self: boolean; index: number; dimensions: RouteEdgesDimensions; plan: LoopPlan; loopHeight: number },\n): EdgeRoute {\n const { side, maxReach } = options.plan;\n const halfW = options.dimensions.nodeWidth / 2;\n const spread = options.self ? options.loopHeight / 4 : 0;\n const startY = from.y - spread;\n const endY = to.y + spread;\n const reach =\n Math.min(maxReach, Math.max(MIN_SIDE_REACH, LOOP_BASE_REACH + LOOP_SPAN_RATE * Math.abs(endY - startY))) +\n options.index * CURVE_OFFSET;\n const outer = side > 0 ? Math.max(from.x, to.x) : Math.min(from.x, to.x);\n const bulge = outer + side * (halfW + reach);\n return {\n ...cubicRoute([\n { x: from.x + side * halfW, y: startY },\n { x: bulge, y: startY },\n { x: bulge, y: endY },\n { x: to.x + side * halfW, y: endY },\n ]),\n labelAnchor: side > 0 ? \"start\" : \"end\",\n };\n}\n\nfunction routeSideGroup(\n group: readonly GraphLayoutEdge[],\n positions: Record<string, GraphLayoutPosition>,\n dimensions: RouteEdgesDimensions,\n loops: ReadonlyMap<number, LoopPlan>,\n routes: Record<string, EdgeRoute>,\n): void {\n const halfW = dimensions.nodeWidth / 2;\n const first = requireEdge(group, 0);\n const shorter = Math.min(heightOf(dimensions, first.from), heightOf(dimensions, first.to));\n const step = group.length > 1 ? Math.min(CURVE_OFFSET, Math.max(0, shorter - PORT_INSET) / (group.length - 1)) : 0;\n\n group.forEach((edge, index) => {\n const from = requirePosition(positions, edge.from);\n const to = requirePosition(positions, edge.to);\n if (isLoop(from, to, dimensions.nodeWidth)) {\n const plan = loops.get(from.x);\n if (!plan) throw new Error(`routeEdges: no loop plan for the column of \"${edge.from}\"`);\n routes[edge.id] = loopRoute(from, to, { self: edge.from === edge.to, index, dimensions, plan, loopHeight: heightOf(dimensions, edge.from) });\n return;\n }\n const direction = to.x > from.x ? 1 : -1;\n const shift = (index - (group.length - 1) / 2) * step;\n const start = { x: from.x + direction * halfW, y: from.y + shift };\n const end = { x: to.x - direction * halfW, y: to.y + shift };\n const reach = Math.max(MIN_SIDE_REACH, Math.abs(end.x - start.x) / 2);\n const curve: CubicCurve = [\n start,\n { x: start.x + direction * reach, y: start.y },\n { x: end.x - direction * reach, y: end.y },\n end,\n ];\n routes[edge.id] = { ...cubicRoute(curve), curve };\n });\n}\n\n/**\n * Routes each edge as an SVG path. Edges sharing an unordered node pair — a\n * reciprocal A→B + B→A, or literal duplicates — are always fanned apart so\n * they never overlap.\n *\n * `anchor: \"center\"` (the default) clips each edge to the source/target node\n * rectangles: a lone edge is a straight line, a fanned one a quadratic curve\n * offset from the line between the two node centres.\n *\n * `anchor: \"side\"` is for column layouts: an edge leaves the side of its\n * source facing the target and enters the facing side of the target as a\n * cubic curve. An edge between two nodes of one column, and a self-edge, is a\n * loop: it arcs out of the column and back on the side with fewer edges to\n * other columns, the further the more height it spans, so loops nest.\n *\n * Throws when an edge references a node id absent from `positions`, naming\n * the edge id, rather than silently dropping or mis-routing it.\n */\nexport function routeEdges(\n edges: readonly GraphLayoutEdge[],\n positions: Record<string, GraphLayoutPosition>,\n dimensions: RouteEdgesDimensions,\n options: RouteEdgesOptions = {},\n): Record<string, EdgeRoute> {\n const routes: Record<string, EdgeRoute> = {};\n const groups = groupEdgesByPair(edges, positions);\n if (options.anchor !== \"side\") {\n for (const group of groups) routeCenterGroup(group, positions, dimensions, routes);\n return routes;\n }\n const loops = planLoops(edges, positions, dimensions.nodeWidth);\n for (const group of groups) routeSideGroup(group, positions, dimensions, loops, routes);\n return routes;\n}\n\n/** How far the side-anchored loops of `edges` reach past the outermost columns, on each side. */\nexport function loopOverhang(\n edges: readonly GraphLayoutEdge[],\n positions: Record<string, GraphLayoutPosition>,\n dimensions: RouteEdgesDimensions,\n): { left: number; right: number } {\n const xs = Object.values(positions).map((position) => position.x);\n const loops = Object.values(routeEdges(edges, positions, dimensions, { anchor: \"side\" })).filter(\n (route) => route.labelAnchor !== undefined,\n );\n if (loops.length === 0) return { left: 0, right: 0 };\n const peaks = loops.map((route) => route.labelX);\n const halfW = dimensions.nodeWidth / 2;\n return {\n left: Math.max(0, Math.min(...xs) - halfW - Math.min(...peaks)),\n right: Math.max(0, Math.max(...peaks) - (Math.max(...xs) + halfW)),\n };\n}\n\nexport interface EdgeLabelBox {\n id: string;\n /** The label's anchor: its centre, its left edge when `anchor` is \"start\", its right edge when \"end\". */\n x: number;\n y: number;\n width: number;\n height: number;\n anchor?: \"start\" | \"end\";\n}\n\nfunction labelLeft(box: EdgeLabelBox): number {\n if (box.anchor === \"start\") return box.x;\n return box.anchor === \"end\" ? box.x - box.width : box.x - box.width / 2;\n}\n\n/**\n * Resolves the y of each edge label so no two labels cover each other: taken\n * top to bottom, a label that would overlap one already placed drops just\n * below it. Labels keep their x, and a label that overlaps nothing keeps its y.\n */\nexport function spreadLabels(boxes: readonly EdgeLabelBox[], gap = 2): Record<string, number> {\n const placed: { left: number; right: number; y: number; height: number }[] = [];\n const ys: Record<string, number> = {};\n for (const box of [...boxes].sort((a, b) => a.y - b.y)) {\n const left = labelLeft(box);\n const right = left + box.width;\n let y = box.y;\n for (let moved = true; moved; ) {\n moved = false;\n for (const other of placed) {\n const clearance = (box.height + other.height) / 2 + gap;\n if (left < other.right && other.left < right && Math.abs(y - other.y) < clearance) {\n y = other.y + clearance;\n moved = true;\n }\n }\n }\n placed.push({ left, right, y, height: box.height });\n ys[box.id] = y;\n }\n return ys;\n}\n"],"names":[],"mappings":";;AAsCA,SAAS,SAAS,YAAkC,IAAoB;;AACtE,WAAO,gBAAW,gBAAX,mBAAyB,QAAO,WAAW;AACpD;AAOA,MAAM,eAAe;AACrB,MAAM,iBAAiB;AAEvB,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;AACvB,MAAM,iBAAiB;AAEvB,MAAM,iBAAiB;AAEvB,MAAM,aAAa;AAEnB,MAAM,aAAa;AAEnB,SAAS,iBAAiB,GAAW,GAAmB;AACtD,SAAO,IAAI,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,KAAK,CAAC;AAC1C;AAEA,SAAS,gBAAgB,WAAgD,IAAiC;AACxG,QAAM,WAAW,UAAU,EAAE;AAC7B,MAAI,CAAC,UAAU;AACb,UAAM,IAAI,MAAM,4CAA4C,EAAE,GAAG;AAAA,EACnE;AACA,SAAO;AACT;AAEA,SAAS,YAAY,OAAmC,OAAgC;AACtF,QAAM,OAAO,MAAM,KAAK;AACxB,MAAI,CAAC,MAAM;AACT,UAAM,IAAI,MAAM,yCAAyC,KAAK,EAAE;AAAA,EAClE;AACA,SAAO;AACT;AAGA,SAAS,WACP,QACA,SACA,OACA,OACqB;AACrB,QAAM,KAAK,QAAQ,IAAI,OAAO;AAC9B,QAAM,KAAK,QAAQ,IAAI,OAAO;AAC9B,MAAI,OAAO,KAAK,OAAO,EAAG,QAAO,EAAE,GAAG,OAAO,GAAG,GAAG,OAAO,EAAA;AAE1D,QAAM,SAAS,OAAO,IAAI,QAAQ,KAAK,IAAI,EAAE,IAAI,OAAO;AACxD,QAAM,SAAS,OAAO,IAAI,QAAQ,KAAK,IAAI,EAAE,IAAI,OAAO;AACxD,QAAM,QAAQ,KAAK,IAAI,QAAQ,MAAM;AAErC,SAAO,EAAE,GAAG,OAAO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AI,GAAG,KAAK,CAAC;AAAA,IAC9D,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,KAAK,KAAK,KAAK,IAAI,GAAG,EAAE,IAAI,MAAM;AAAA,EAAA;AAErE;AAYA,SAAS,UAAU,KAA2B;AAC5C,MAAI,IAAI,WAAW,QAAS,QAAO,IAAI;AACvC,SAAO,IAAI,WAAW,QAAQ,IAAI,IAAI,IAAI,QAAQ,IAAI,IAAI,IAAI,QAAQ;AACxE;AAOO,SAAS,aAAa,OAAgC,MAAM,GAA2B;AAC5F,QAAM,SAAuE,CAAA;AAC7E,QAAM,KAA6B,CAAA;AACnC,aAAW,OAAO,CAAC,GAAG,KAAK,EAAE,KAAK,CAAC,GAAG,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG;AACtD,UAAM,OAAO,UAAU,GAAG;AAC1B,UAAM,QAAQ,OAAO,IAAI;AACzB,QAAI,IAAI,IAAI;AACZ,aAAS,QAAQ,MAAM,SAAS;AAC9B,cAAQ;AACR,iBAAW,SAAS,QAAQ;AAC1B,cAAM,aAAa,IAAI,SAAS,MAAM,UAAU,IAAI;AACpD,YAAI,OAAO,MAAM,SAAS,MAAM,OAAO,SAAS,KAAK,IAAI,IAAI,MAAM,CAAC,IAAI,WAAW;AACjF,cAAI,MAAM,IAAI;AACd,kBAAQ;AAAA,QACV;AAAA,MACF;AAAA,IACF;AACA,WAAO,KAAK,EAAE,MAAM,OAAO,GAAG,QAAQ,IAAI,QAAQ;AAClD,OAAG,IAAI,EAAE,IAAI;AAAA,EACf;AACA,SAAO;AACT;;;;;"}
|
|
@@ -24,6 +24,8 @@ export interface EdgeRoute {
|
|
|
24
24
|
export interface RouteEdgesDimensions {
|
|
25
25
|
nodeWidth: number;
|
|
26
26
|
nodeHeight: number;
|
|
27
|
+
/** Heights of the nodes not drawn at `nodeHeight`, by id. */
|
|
28
|
+
nodeHeights?: Readonly<Record<string, number>>;
|
|
27
29
|
}
|
|
28
30
|
export interface RouteEdgesOptions {
|
|
29
31
|
/** Where edges attach: clipped toward the node centre, or at the left/right side middles. Defaults to "center". */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph-edge-routing.d.ts","sourceRoot":"","sources":["../../src/data/graph-edge-routing.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAE1D,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,2DAA2D;AAC3D,MAAM,MAAM,UAAU,GAAG,SAAS,CAAC,mBAAmB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,mBAAmB,CAAC,CAAC;AAEvH,MAAM,WAAW,SAAS;IACxB,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,gEAAgE;IAChE,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;IAC9B,4GAA4G;IAC5G,KAAK,CAAC,EAAE,UAAU,CAAC;CACpB;AAED,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"graph-edge-routing.d.ts","sourceRoot":"","sources":["../../src/data/graph-edge-routing.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAE1D,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,2DAA2D;AAC3D,MAAM,MAAM,UAAU,GAAG,SAAS,CAAC,mBAAmB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,mBAAmB,CAAC,CAAC;AAEvH,MAAM,WAAW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,yGAAyG;IACzG,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;CAC1B;AAOD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,YAAY,EAAE,EAAE,GAAG,SAAI,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAqB5F"}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
function heightOf(dimensions, id) {
|
|
2
|
+
var _a;
|
|
3
|
+
return ((_a = dimensions.nodeHeights) == null ? void 0 : _a[id]) ?? dimensions.nodeHeight;
|
|
4
|
+
}
|
|
1
5
|
const CURVE_OFFSET = 22;
|
|
2
6
|
const MIN_SIDE_REACH = 36;
|
|
3
7
|
const LOOP_BASE_REACH = 24;
|
|
@@ -134,7 +138,7 @@ function planLoops(edges, positions, nodeWidth) {
|
|
|
134
138
|
function loopRoute(from, to, options) {
|
|
135
139
|
const { side, maxReach } = options.plan;
|
|
136
140
|
const halfW = options.dimensions.nodeWidth / 2;
|
|
137
|
-
const spread = options.self ? options.
|
|
141
|
+
const spread = options.self ? options.loopHeight / 4 : 0;
|
|
138
142
|
const startY = from.y - spread;
|
|
139
143
|
const endY = to.y + spread;
|
|
140
144
|
const reach = Math.min(maxReach, Math.max(MIN_SIDE_REACH, LOOP_BASE_REACH + LOOP_SPAN_RATE * Math.abs(endY - startY))) + options.index * CURVE_OFFSET;
|
|
@@ -152,14 +156,16 @@ function loopRoute(from, to, options) {
|
|
|
152
156
|
}
|
|
153
157
|
function routeSideGroup(group, positions, dimensions, loops, routes) {
|
|
154
158
|
const halfW = dimensions.nodeWidth / 2;
|
|
155
|
-
const
|
|
159
|
+
const first = requireEdge(group, 0);
|
|
160
|
+
const shorter = Math.min(heightOf(dimensions, first.from), heightOf(dimensions, first.to));
|
|
161
|
+
const step = group.length > 1 ? Math.min(CURVE_OFFSET, Math.max(0, shorter - PORT_INSET) / (group.length - 1)) : 0;
|
|
156
162
|
group.forEach((edge, index) => {
|
|
157
163
|
const from = requirePosition(positions, edge.from);
|
|
158
164
|
const to = requirePosition(positions, edge.to);
|
|
159
165
|
if (isLoop(from, to, dimensions.nodeWidth)) {
|
|
160
166
|
const plan = loops.get(from.x);
|
|
161
167
|
if (!plan) throw new Error(`routeEdges: no loop plan for the column of "${edge.from}"`);
|
|
162
|
-
routes[edge.id] = loopRoute(from, to, { self: edge.from === edge.to, index, dimensions, plan });
|
|
168
|
+
routes[edge.id] = loopRoute(from, to, { self: edge.from === edge.to, index, dimensions, plan, loopHeight: heightOf(dimensions, edge.from) });
|
|
163
169
|
return;
|
|
164
170
|
}
|
|
165
171
|
const direction = to.x > from.x ? 1 : -1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph-edge-routing.js","sources":["../../src/data/graph-edge-routing.ts"],"sourcesContent":["// Edge routing and label placement for GraphDiagram: pure math, no React.\n// Split from graph-layout.ts, which owns the position types and `ringLayout`\n// and re-exports this file's API.\n\nimport type { GraphLayoutPosition } from \"./graph-layout\";\n\nexport interface GraphLayoutEdge {\n id: string;\n from: string;\n to: string;\n}\n\n/** Start, two control points and end of a cubic Bézier. */\nexport type CubicCurve = readonly [GraphLayoutPosition, GraphLayoutPosition, GraphLayoutPosition, GraphLayoutPosition];\n\nexport interface EdgeRoute {\n /** SVG path `d` attribute, clipped to the node rectangle boundaries. */\n path: string;\n /** Midpoint of the rendered path, for placing an edge label. */\n labelX: number;\n labelY: number;\n /**\n * Set on a loop, whose midpoint is its outermost point: \"start\" when a label\n * should begin at the point and run right of it, \"end\" when it should end\n * there and run left. A centred label would reach back over the node.\n */\n labelAnchor?: \"start\" | \"end\";\n /** A side-anchored edge between two columns: its curve, for placing a label elsewhere than its midpoint. */\n curve?: CubicCurve;\n}\n\nexport interface RouteEdgesDimensions {\n nodeWidth: number;\n nodeHeight: number;\n}\n\nexport interface RouteEdgesOptions {\n /** Where edges attach: clipped toward the node centre, or at the left/right side middles. Defaults to \"center\". */\n anchor?: \"center\" | \"side\";\n}\n\nconst CURVE_OFFSET = 22;\nconst MIN_SIDE_REACH = 36;\n/** A loop reaches this far plus a share of the height it spans, so a longer loop arcs outside a shorter one. */\nconst LOOP_BASE_REACH = 24;\nconst LOOP_SPAN_RATE = 0.18;\nconst MAX_LOOP_REACH = 240;\n/** The share of the gap to the next column a loop may bulge into. */\nconst LOOP_GAP_SHARE = 0.6;\n/** A cubic whose two control points share an x peaks at 3/4 of their offset. */\nconst CUBIC_PEAK = 0.75;\n/** Vertical margin kept between fanned side anchors and the node's corners. */\nconst PORT_INSET = 12;\n\nfunction unorderedPairKey(a: string, b: string): string {\n return a < b ? `${a}\\0${b}` : `${b}\\0${a}`;\n}\n\nfunction requirePosition(positions: Record<string, GraphLayoutPosition>, id: string): GraphLayoutPosition {\n const position = positions[id];\n if (!position) {\n throw new Error(`routeEdges: no layout position for node \"${id}\"`);\n }\n return position;\n}\n\nfunction requireEdge(group: readonly GraphLayoutEdge[], index: number): GraphLayoutEdge {\n const edge = group[index];\n if (!edge) {\n throw new Error(`routeEdges: expected an edge at index ${index}`);\n }\n return edge;\n}\n\n/** Point on the rectangle (centred at `center`, half-extents `halfW`/`halfH`) where the ray toward `towards` exits. */\nfunction clipToRect(\n center: GraphLayoutPosition,\n towards: GraphLayoutPosition,\n halfW: number,\n halfH: number,\n): GraphLayoutPosition {\n const dx = towards.x - center.x;\n const dy = towards.y - center.y;\n if (dx === 0 && dy === 0) return { x: center.x, y: center.y };\n\n const scaleX = dx !== 0 ? halfW / Math.abs(dx) : Number.POSITIVE_INFINITY;\n const scaleY = dy !== 0 ? halfH / Math.abs(dy) : Number.POSITIVE_INFINITY;\n const scale = Math.min(scaleX, scaleY);\n\n return { x: center.x + dx * scale, y: center.y + dy * scale };\n}\n\n/** Point at t=0.5 on the quadratic Bézier defined by p0 (start), p1 (control), p2 (end). */\nfunction quadraticMidpoint(\n p0: GraphLayoutPosition,\n p1: GraphLayoutPosition,\n p2: GraphLayoutPosition,\n): GraphLayoutPosition {\n return {\n x: 0.25 * p0.x + 0.5 * p1.x + 0.25 * p2.x,\n y: 0.25 * p0.y + 0.5 * p1.y + 0.25 * p2.y,\n };\n}\n\n/** Edges sharing an unordered node pair, in input order; throws on an edge whose node has no position. */\nfunction groupEdgesByPair(\n edges: readonly GraphLayoutEdge[],\n positions: Record<string, GraphLayoutPosition>,\n): GraphLayoutEdge[][] {\n const groups = new Map<string, GraphLayoutEdge[]>();\n for (const edge of edges) {\n if (!(edge.from in positions)) {\n throw new Error(`routeEdges: edge \"${edge.id}\" references unknown node \"${edge.from}\"`);\n }\n if (!(edge.to in positions)) {\n throw new Error(`routeEdges: edge \"${edge.id}\" references unknown node \"${edge.to}\"`);\n }\n const key = unorderedPairKey(edge.from, edge.to);\n const group = groups.get(key);\n if (group) {\n group.push(edge);\n } else {\n groups.set(key, [edge]);\n }\n }\n return [...groups.values()];\n}\n\nfunction routeCenterGroup(\n group: readonly GraphLayoutEdge[],\n positions: Record<string, GraphLayoutPosition>,\n dimensions: RouteEdgesDimensions,\n routes: Record<string, EdgeRoute>,\n): void {\n const halfW = dimensions.nodeWidth / 2;\n const halfH = dimensions.nodeHeight / 2;\n const first = requireEdge(group, 0);\n const posA = requirePosition(positions, first.from);\n const posB = requirePosition(positions, first.to);\n const dx = posB.x - posA.x;\n const dy = posB.y - posA.y;\n const len = Math.hypot(dx, dy) || 1;\n const perpX = -dy / len;\n const perpY = dx / len;\n const midX = (posA.x + posB.x) / 2;\n const midY = (posA.y + posB.y) / 2;\n\n group.forEach((edge, index) => {\n const isCurved = group.length > 1;\n const sign = index % 2 === 0 ? 1 : -1;\n const magnitude = Math.floor(index / 2) + 1;\n const offset = isCurved ? sign * magnitude * CURVE_OFFSET : 0;\n\n const control = { x: midX + perpX * offset, y: midY + perpY * offset };\n const fromCenter = requirePosition(positions, edge.from);\n const toCenter = requirePosition(positions, edge.to);\n const start = clipToRect(fromCenter, control, halfW, halfH);\n const end = clipToRect(toCenter, control, halfW, halfH);\n\n const path = isCurved\n ? `M ${start.x} ${start.y} Q ${control.x} ${control.y} ${end.x} ${end.y}`\n : `M ${start.x} ${start.y} L ${end.x} ${end.y}`;\n\n const label = isCurved\n ? quadraticMidpoint(start, control, end)\n : { x: (start.x + end.x) / 2, y: (start.y + end.y) / 2 };\n\n routes[edge.id] = { path, labelX: label.x, labelY: label.y };\n });\n}\n\n/** The point at `t` (0 at the start, 1 at the end) along a cubic Bézier. */\nexport function pointOnCurve([p0, c1, c2, p3]: CubicCurve, t: number): GraphLayoutPosition {\n const u = 1 - t;\n const weights = [u * u * u, 3 * u * u * t, 3 * u * t * t, t * t * t] as const;\n return {\n x: weights[0] * p0.x + weights[1] * c1.x + weights[2] * c2.x + weights[3] * p3.x,\n y: weights[0] * p0.y + weights[1] * c1.y + weights[2] * c2.y + weights[3] * p3.y,\n };\n}\n\nfunction cubicRoute(curve: CubicCurve): EdgeRoute {\n const [p0, c1, c2, p3] = curve;\n const label = pointOnCurve(curve, 0.5);\n return {\n path: `M ${p0.x} ${p0.y} C ${c1.x} ${c1.y} ${c2.x} ${c2.y} ${p3.x} ${p3.y}`,\n labelX: label.x,\n labelY: label.y,\n };\n}\n\ninterface LoopPlan {\n /** 1 when the column's loops bulge right of it, -1 when left. */\n side: 1 | -1;\n /** The furthest a loop's control points may sit from the column, so it stays clear of the next one. */\n maxReach: number;\n}\n\nfunction isLoop(from: GraphLayoutPosition, to: GraphLayoutPosition, nodeWidth: number): boolean {\n return Math.abs(to.x - from.x) < nodeWidth;\n}\n\n/**\n * For each column (each distinct node x), where its loops go: the side with\n * fewer edges to other columns attached, the right on a tie, and no further\n * than a share of the gap to the next column on that side.\n */\nfunction planLoops(\n edges: readonly GraphLayoutEdge[],\n positions: Record<string, GraphLayoutPosition>,\n nodeWidth: number,\n): Map<number, LoopPlan> {\n const attached = new Map<number, { left: number; right: number }>();\n for (const { x } of Object.values(positions)) attached.set(x, { left: 0, right: 0 });\n const attach = (x: number, side: \"left\" | \"right\") => {\n const tally = attached.get(x);\n if (tally) tally[side] += 1;\n };\n for (const edge of edges) {\n const from = requirePosition(positions, edge.from);\n const to = requirePosition(positions, edge.to);\n if (isLoop(from, to, nodeWidth)) continue;\n const forward = to.x > from.x;\n attach(from.x, forward ? \"right\" : \"left\");\n attach(to.x, forward ? \"left\" : \"right\");\n }\n const columns = [...attached.keys()];\n return new Map(\n columns.map((x) => {\n const tally = attached.get(x) ?? { left: 0, right: 0 };\n const side = tally.left < tally.right ? -1 : 1;\n const gaps = columns.filter((other) => (other - x) * side > 0).map((other) => Math.abs(other - x) - nodeWidth);\n const room = gaps.length === 0 ? Number.POSITIVE_INFINITY : (LOOP_GAP_SHARE * Math.min(...gaps)) / CUBIC_PEAK;\n return [x, { side, maxReach: Math.min(MAX_LOOP_REACH, Math.max(0, room)) }];\n }),\n );\n}\n\n/** Out of one side of a column and back into it: an edge inside one column, or a self-edge. */\nfunction loopRoute(\n from: GraphLayoutPosition,\n to: GraphLayoutPosition,\n options: { self: boolean; index: number; dimensions: RouteEdgesDimensions; plan: LoopPlan },\n): EdgeRoute {\n const { side, maxReach } = options.plan;\n const halfW = options.dimensions.nodeWidth / 2;\n const spread = options.self ? options.dimensions.nodeHeight / 4 : 0;\n const startY = from.y - spread;\n const endY = to.y + spread;\n const reach =\n Math.min(maxReach, Math.max(MIN_SIDE_REACH, LOOP_BASE_REACH + LOOP_SPAN_RATE * Math.abs(endY - startY))) +\n options.index * CURVE_OFFSET;\n const outer = side > 0 ? Math.max(from.x, to.x) : Math.min(from.x, to.x);\n const bulge = outer + side * (halfW + reach);\n return {\n ...cubicRoute([\n { x: from.x + side * halfW, y: startY },\n { x: bulge, y: startY },\n { x: bulge, y: endY },\n { x: to.x + side * halfW, y: endY },\n ]),\n labelAnchor: side > 0 ? \"start\" : \"end\",\n };\n}\n\nfunction routeSideGroup(\n group: readonly GraphLayoutEdge[],\n positions: Record<string, GraphLayoutPosition>,\n dimensions: RouteEdgesDimensions,\n loops: ReadonlyMap<number, LoopPlan>,\n routes: Record<string, EdgeRoute>,\n): void {\n const halfW = dimensions.nodeWidth / 2;\n const step =\n group.length > 1\n ? Math.min(CURVE_OFFSET, (dimensions.nodeHeight - PORT_INSET) / (group.length - 1))\n : 0;\n\n group.forEach((edge, index) => {\n const from = requirePosition(positions, edge.from);\n const to = requirePosition(positions, edge.to);\n if (isLoop(from, to, dimensions.nodeWidth)) {\n const plan = loops.get(from.x);\n if (!plan) throw new Error(`routeEdges: no loop plan for the column of \"${edge.from}\"`);\n routes[edge.id] = loopRoute(from, to, { self: edge.from === edge.to, index, dimensions, plan });\n return;\n }\n const direction = to.x > from.x ? 1 : -1;\n const shift = (index - (group.length - 1) / 2) * step;\n const start = { x: from.x + direction * halfW, y: from.y + shift };\n const end = { x: to.x - direction * halfW, y: to.y + shift };\n const reach = Math.max(MIN_SIDE_REACH, Math.abs(end.x - start.x) / 2);\n const curve: CubicCurve = [\n start,\n { x: start.x + direction * reach, y: start.y },\n { x: end.x - direction * reach, y: end.y },\n end,\n ];\n routes[edge.id] = { ...cubicRoute(curve), curve };\n });\n}\n\n/**\n * Routes each edge as an SVG path. Edges sharing an unordered node pair — a\n * reciprocal A→B + B→A, or literal duplicates — are always fanned apart so\n * they never overlap.\n *\n * `anchor: \"center\"` (the default) clips each edge to the source/target node\n * rectangles: a lone edge is a straight line, a fanned one a quadratic curve\n * offset from the line between the two node centres.\n *\n * `anchor: \"side\"` is for column layouts: an edge leaves the side of its\n * source facing the target and enters the facing side of the target as a\n * cubic curve. An edge between two nodes of one column, and a self-edge, is a\n * loop: it arcs out of the column and back on the side with fewer edges to\n * other columns, the further the more height it spans, so loops nest.\n *\n * Throws when an edge references a node id absent from `positions`, naming\n * the edge id, rather than silently dropping or mis-routing it.\n */\nexport function routeEdges(\n edges: readonly GraphLayoutEdge[],\n positions: Record<string, GraphLayoutPosition>,\n dimensions: RouteEdgesDimensions,\n options: RouteEdgesOptions = {},\n): Record<string, EdgeRoute> {\n const routes: Record<string, EdgeRoute> = {};\n const groups = groupEdgesByPair(edges, positions);\n if (options.anchor !== \"side\") {\n for (const group of groups) routeCenterGroup(group, positions, dimensions, routes);\n return routes;\n }\n const loops = planLoops(edges, positions, dimensions.nodeWidth);\n for (const group of groups) routeSideGroup(group, positions, dimensions, loops, routes);\n return routes;\n}\n\n/** How far the side-anchored loops of `edges` reach past the outermost columns, on each side. */\nexport function loopOverhang(\n edges: readonly GraphLayoutEdge[],\n positions: Record<string, GraphLayoutPosition>,\n dimensions: RouteEdgesDimensions,\n): { left: number; right: number } {\n const xs = Object.values(positions).map((position) => position.x);\n const loops = Object.values(routeEdges(edges, positions, dimensions, { anchor: \"side\" })).filter(\n (route) => route.labelAnchor !== undefined,\n );\n if (loops.length === 0) return { left: 0, right: 0 };\n const peaks = loops.map((route) => route.labelX);\n const halfW = dimensions.nodeWidth / 2;\n return {\n left: Math.max(0, Math.min(...xs) - halfW - Math.min(...peaks)),\n right: Math.max(0, Math.max(...peaks) - (Math.max(...xs) + halfW)),\n };\n}\n\nexport interface EdgeLabelBox {\n id: string;\n /** The label's anchor: its centre, its left edge when `anchor` is \"start\", its right edge when \"end\". */\n x: number;\n y: number;\n width: number;\n height: number;\n anchor?: \"start\" | \"end\";\n}\n\nfunction labelLeft(box: EdgeLabelBox): number {\n if (box.anchor === \"start\") return box.x;\n return box.anchor === \"end\" ? box.x - box.width : box.x - box.width / 2;\n}\n\n/**\n * Resolves the y of each edge label so no two labels cover each other: taken\n * top to bottom, a label that would overlap one already placed drops just\n * below it. Labels keep their x, and a label that overlaps nothing keeps its y.\n */\nexport function spreadLabels(boxes: readonly EdgeLabelBox[], gap = 2): Record<string, number> {\n const placed: { left: number; right: number; y: number; height: number }[] = [];\n const ys: Record<string, number> = {};\n for (const box of [...boxes].sort((a, b) => a.y - b.y)) {\n const left = labelLeft(box);\n const right = left + box.width;\n let y = box.y;\n for (let moved = true; moved; ) {\n moved = false;\n for (const other of placed) {\n const clearance = (box.height + other.height) / 2 + gap;\n if (left < other.right && other.left < right && Math.abs(y - other.y) < clearance) {\n y = other.y + clearance;\n moved = true;\n }\n }\n }\n placed.push({ left, right, y, height: box.height });\n ys[box.id] = y;\n }\n return ys;\n}\n"],"names":[],"mappings":"AAyCA,MAAM,eAAe;AACrB,MAAM,iBAAiB;AAEvB,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;AACvB,MAAM,iBAAiB;AAEvB,MAAM,iBAAiB;AAEvB,MAAM,aAAa;AAEnB,MAAM,aAAa;AAEnB,SAAS,iBAAiB,GAAW,GAAmB;AACtD,SAAO,IAAI,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,KAAK,CAAC;AAC1C;AAEA,SAAS,gBAAgB,WAAgD,IAAiC;AACxG,QAAM,WAAW,UAAU,EAAE;AAC7B,MAAI,CAAC,UAAU;AACb,UAAM,IAAI,MAAM,4CAA4C,EAAE,GAAG;AAAA,EACnE;AACA,SAAO;AACT;AAEA,SAAS,YAAY,OAAmC,OAAgC;AACtF,QAAM,OAAO,MAAM,KAAK;AACxB,MAAI,CAAC,MAAM;AACT,UAAM,IAAI,MAAM,yCAAyC,KAAK,EAAE;AAAA,EAClE;AACA,SAAO;AACT;AAGA,SAAS,WACP,QACA,SACA,OACA,OACqB;AACrB,QAAM,KAAK,QAAQ,IAAI,OAAO;AAC9B,QAAM,KAAK,QAAQ,IAAI,OAAO;AAC9B,MAAI,OAAO,KAAK,OAAO,EAAG,QAAO,EAAE,GAAG,OAAO,GAAG,GAAG,OAAO,EAAA;AAE1D,QAAM,SAAS,OAAO,IAAI,QAAQ,KAAK,IAAI,EAAE,IAAI,OAAO;AACxD,QAAM,SAAS,OAAO,IAAI,QAAQ,KAAK,IAAI,EAAE,IAAI,OAAO;AACxD,QAAM,QAAQ,KAAK,IAAI,QAAQ,MAAM;AAErC,SAAO,EAAE,GAAG,OAAO,IAAI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AI,WAAW,QAAS,QAAO,IAAI;AACvC,SAAO,IAAI,WAAW,QAAQ,IAAI,IAAI,IAAI,QAAQ,IAAI,IAAI,IAAI,QAAQ;AACxE;AAOO,SAAS,aAAa,OAAgC,MAAM,GAA2B;AAC5F,QAAM,SAAuE,CAAA;AAC7E,QAAM,KAA6B,CAAA;AACnC,aAAW,OAAO,CAAC,GAAG,KAAK,EAAE,KAAK,CAAC,GAAG,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG;AACtD,UAAM,OAAO,UAAU,GAAG;AAC1B,UAAM,QAAQ,OAAO,IAAI;AACzB,QAAI,IAAI,IAAI;AACZ,aAAS,QAAQ,MAAM,SAAS;AAC9B,cAAQ;AACR,iBAAW,SAAS,QAAQ;AAC1B,cAAM,aAAa,IAAI,SAAS,MAAM,UAAU,IAAI;AACpD,YAAI,OAAO,MAAM,SAAS,MAAM,OAAO,SAAS,KAAK,IAAI,IAAI,MAAM,CAAC,IAAI,WAAW;AACjF,cAAI,MAAM,IAAI;AACd,kBAAQ;AAAA,QACV;AAAA,MACF;AAAA,IACF;AACA,WAAO,KAAK,EAAE,MAAM,OAAO,GAAG,QAAQ,IAAI,QAAQ;AAClD,OAAG,IAAI,EAAE,IAAI;AAAA,EACf;AACA,SAAO;AACT;"}
|
|
1
|
+
{"version":3,"file":"graph-edge-routing.js","sources":["../../src/data/graph-edge-routing.ts"],"sourcesContent":["// Edge routing and label placement for GraphDiagram: pure math, no React.\n// Split from graph-layout.ts, which owns the position types and `ringLayout`\n// and re-exports this file's API.\n\nimport type { GraphLayoutPosition } from \"./graph-layout\";\n\nexport interface GraphLayoutEdge {\n id: string;\n from: string;\n to: string;\n}\n\n/** Start, two control points and end of a cubic Bézier. */\nexport type CubicCurve = readonly [GraphLayoutPosition, GraphLayoutPosition, GraphLayoutPosition, GraphLayoutPosition];\n\nexport interface EdgeRoute {\n /** SVG path `d` attribute, clipped to the node rectangle boundaries. */\n path: string;\n /** Midpoint of the rendered path, for placing an edge label. */\n labelX: number;\n labelY: number;\n /**\n * Set on a loop, whose midpoint is its outermost point: \"start\" when a label\n * should begin at the point and run right of it, \"end\" when it should end\n * there and run left. A centred label would reach back over the node.\n */\n labelAnchor?: \"start\" | \"end\";\n /** A side-anchored edge between two columns: its curve, for placing a label elsewhere than its midpoint. */\n curve?: CubicCurve;\n}\n\nexport interface RouteEdgesDimensions {\n nodeWidth: number;\n nodeHeight: number;\n /** Heights of the nodes not drawn at `nodeHeight`, by id. */\n nodeHeights?: Readonly<Record<string, number>>;\n}\n\nfunction heightOf(dimensions: RouteEdgesDimensions, id: string): number {\n return dimensions.nodeHeights?.[id] ?? dimensions.nodeHeight;\n}\n\nexport interface RouteEdgesOptions {\n /** Where edges attach: clipped toward the node centre, or at the left/right side middles. Defaults to \"center\". */\n anchor?: \"center\" | \"side\";\n}\n\nconst CURVE_OFFSET = 22;\nconst MIN_SIDE_REACH = 36;\n/** A loop reaches this far plus a share of the height it spans, so a longer loop arcs outside a shorter one. */\nconst LOOP_BASE_REACH = 24;\nconst LOOP_SPAN_RATE = 0.18;\nconst MAX_LOOP_REACH = 240;\n/** The share of the gap to the next column a loop may bulge into. */\nconst LOOP_GAP_SHARE = 0.6;\n/** A cubic whose two control points share an x peaks at 3/4 of their offset. */\nconst CUBIC_PEAK = 0.75;\n/** Vertical margin kept between fanned side anchors and the node's corners. */\nconst PORT_INSET = 12;\n\nfunction unorderedPairKey(a: string, b: string): string {\n return a < b ? `${a}\\0${b}` : `${b}\\0${a}`;\n}\n\nfunction requirePosition(positions: Record<string, GraphLayoutPosition>, id: string): GraphLayoutPosition {\n const position = positions[id];\n if (!position) {\n throw new Error(`routeEdges: no layout position for node \"${id}\"`);\n }\n return position;\n}\n\nfunction requireEdge(group: readonly GraphLayoutEdge[], index: number): GraphLayoutEdge {\n const edge = group[index];\n if (!edge) {\n throw new Error(`routeEdges: expected an edge at index ${index}`);\n }\n return edge;\n}\n\n/** Point on the rectangle (centred at `center`, half-extents `halfW`/`halfH`) where the ray toward `towards` exits. */\nfunction clipToRect(\n center: GraphLayoutPosition,\n towards: GraphLayoutPosition,\n halfW: number,\n halfH: number,\n): GraphLayoutPosition {\n const dx = towards.x - center.x;\n const dy = towards.y - center.y;\n if (dx === 0 && dy === 0) return { x: center.x, y: center.y };\n\n const scaleX = dx !== 0 ? halfW / Math.abs(dx) : Number.POSITIVE_INFINITY;\n const scaleY = dy !== 0 ? halfH / Math.abs(dy) : Number.POSITIVE_INFINITY;\n const scale = Math.min(scaleX, scaleY);\n\n return { x: center.x + dx * scale, y: center.y + dy * scale };\n}\n\n/** Point at t=0.5 on the quadratic Bézier defined by p0 (start), p1 (control), p2 (end). */\nfunction quadraticMidpoint(\n p0: GraphLayoutPosition,\n p1: GraphLayoutPosition,\n p2: GraphLayoutPosition,\n): GraphLayoutPosition {\n return {\n x: 0.25 * p0.x + 0.5 * p1.x + 0.25 * p2.x,\n y: 0.25 * p0.y + 0.5 * p1.y + 0.25 * p2.y,\n };\n}\n\n/** Edges sharing an unordered node pair, in input order; throws on an edge whose node has no position. */\nfunction groupEdgesByPair(\n edges: readonly GraphLayoutEdge[],\n positions: Record<string, GraphLayoutPosition>,\n): GraphLayoutEdge[][] {\n const groups = new Map<string, GraphLayoutEdge[]>();\n for (const edge of edges) {\n if (!(edge.from in positions)) {\n throw new Error(`routeEdges: edge \"${edge.id}\" references unknown node \"${edge.from}\"`);\n }\n if (!(edge.to in positions)) {\n throw new Error(`routeEdges: edge \"${edge.id}\" references unknown node \"${edge.to}\"`);\n }\n const key = unorderedPairKey(edge.from, edge.to);\n const group = groups.get(key);\n if (group) {\n group.push(edge);\n } else {\n groups.set(key, [edge]);\n }\n }\n return [...groups.values()];\n}\n\nfunction routeCenterGroup(\n group: readonly GraphLayoutEdge[],\n positions: Record<string, GraphLayoutPosition>,\n dimensions: RouteEdgesDimensions,\n routes: Record<string, EdgeRoute>,\n): void {\n const halfW = dimensions.nodeWidth / 2;\n const halfH = dimensions.nodeHeight / 2;\n const first = requireEdge(group, 0);\n const posA = requirePosition(positions, first.from);\n const posB = requirePosition(positions, first.to);\n const dx = posB.x - posA.x;\n const dy = posB.y - posA.y;\n const len = Math.hypot(dx, dy) || 1;\n const perpX = -dy / len;\n const perpY = dx / len;\n const midX = (posA.x + posB.x) / 2;\n const midY = (posA.y + posB.y) / 2;\n\n group.forEach((edge, index) => {\n const isCurved = group.length > 1;\n const sign = index % 2 === 0 ? 1 : -1;\n const magnitude = Math.floor(index / 2) + 1;\n const offset = isCurved ? sign * magnitude * CURVE_OFFSET : 0;\n\n const control = { x: midX + perpX * offset, y: midY + perpY * offset };\n const fromCenter = requirePosition(positions, edge.from);\n const toCenter = requirePosition(positions, edge.to);\n const start = clipToRect(fromCenter, control, halfW, halfH);\n const end = clipToRect(toCenter, control, halfW, halfH);\n\n const path = isCurved\n ? `M ${start.x} ${start.y} Q ${control.x} ${control.y} ${end.x} ${end.y}`\n : `M ${start.x} ${start.y} L ${end.x} ${end.y}`;\n\n const label = isCurved\n ? quadraticMidpoint(start, control, end)\n : { x: (start.x + end.x) / 2, y: (start.y + end.y) / 2 };\n\n routes[edge.id] = { path, labelX: label.x, labelY: label.y };\n });\n}\n\n/** The point at `t` (0 at the start, 1 at the end) along a cubic Bézier. */\nexport function pointOnCurve([p0, c1, c2, p3]: CubicCurve, t: number): GraphLayoutPosition {\n const u = 1 - t;\n const weights = [u * u * u, 3 * u * u * t, 3 * u * t * t, t * t * t] as const;\n return {\n x: weights[0] * p0.x + weights[1] * c1.x + weights[2] * c2.x + weights[3] * p3.x,\n y: weights[0] * p0.y + weights[1] * c1.y + weights[2] * c2.y + weights[3] * p3.y,\n };\n}\n\nfunction cubicRoute(curve: CubicCurve): EdgeRoute {\n const [p0, c1, c2, p3] = curve;\n const label = pointOnCurve(curve, 0.5);\n return {\n path: `M ${p0.x} ${p0.y} C ${c1.x} ${c1.y} ${c2.x} ${c2.y} ${p3.x} ${p3.y}`,\n labelX: label.x,\n labelY: label.y,\n };\n}\n\ninterface LoopPlan {\n /** 1 when the column's loops bulge right of it, -1 when left. */\n side: 1 | -1;\n /** The furthest a loop's control points may sit from the column, so it stays clear of the next one. */\n maxReach: number;\n}\n\nfunction isLoop(from: GraphLayoutPosition, to: GraphLayoutPosition, nodeWidth: number): boolean {\n return Math.abs(to.x - from.x) < nodeWidth;\n}\n\n/**\n * For each column (each distinct node x), where its loops go: the side with\n * fewer edges to other columns attached, the right on a tie, and no further\n * than a share of the gap to the next column on that side.\n */\nfunction planLoops(\n edges: readonly GraphLayoutEdge[],\n positions: Record<string, GraphLayoutPosition>,\n nodeWidth: number,\n): Map<number, LoopPlan> {\n const attached = new Map<number, { left: number; right: number }>();\n for (const { x } of Object.values(positions)) attached.set(x, { left: 0, right: 0 });\n const attach = (x: number, side: \"left\" | \"right\") => {\n const tally = attached.get(x);\n if (tally) tally[side] += 1;\n };\n for (const edge of edges) {\n const from = requirePosition(positions, edge.from);\n const to = requirePosition(positions, edge.to);\n if (isLoop(from, to, nodeWidth)) continue;\n const forward = to.x > from.x;\n attach(from.x, forward ? \"right\" : \"left\");\n attach(to.x, forward ? \"left\" : \"right\");\n }\n const columns = [...attached.keys()];\n return new Map(\n columns.map((x) => {\n const tally = attached.get(x) ?? { left: 0, right: 0 };\n const side = tally.left < tally.right ? -1 : 1;\n const gaps = columns.filter((other) => (other - x) * side > 0).map((other) => Math.abs(other - x) - nodeWidth);\n const room = gaps.length === 0 ? Number.POSITIVE_INFINITY : (LOOP_GAP_SHARE * Math.min(...gaps)) / CUBIC_PEAK;\n return [x, { side, maxReach: Math.min(MAX_LOOP_REACH, Math.max(0, room)) }];\n }),\n );\n}\n\n/** Out of one side of a column and back into it: an edge inside one column, or a self-edge. */\nfunction loopRoute(\n from: GraphLayoutPosition,\n to: GraphLayoutPosition,\n options: { self: boolean; index: number; dimensions: RouteEdgesDimensions; plan: LoopPlan; loopHeight: number },\n): EdgeRoute {\n const { side, maxReach } = options.plan;\n const halfW = options.dimensions.nodeWidth / 2;\n const spread = options.self ? options.loopHeight / 4 : 0;\n const startY = from.y - spread;\n const endY = to.y + spread;\n const reach =\n Math.min(maxReach, Math.max(MIN_SIDE_REACH, LOOP_BASE_REACH + LOOP_SPAN_RATE * Math.abs(endY - startY))) +\n options.index * CURVE_OFFSET;\n const outer = side > 0 ? Math.max(from.x, to.x) : Math.min(from.x, to.x);\n const bulge = outer + side * (halfW + reach);\n return {\n ...cubicRoute([\n { x: from.x + side * halfW, y: startY },\n { x: bulge, y: startY },\n { x: bulge, y: endY },\n { x: to.x + side * halfW, y: endY },\n ]),\n labelAnchor: side > 0 ? \"start\" : \"end\",\n };\n}\n\nfunction routeSideGroup(\n group: readonly GraphLayoutEdge[],\n positions: Record<string, GraphLayoutPosition>,\n dimensions: RouteEdgesDimensions,\n loops: ReadonlyMap<number, LoopPlan>,\n routes: Record<string, EdgeRoute>,\n): void {\n const halfW = dimensions.nodeWidth / 2;\n const first = requireEdge(group, 0);\n const shorter = Math.min(heightOf(dimensions, first.from), heightOf(dimensions, first.to));\n const step = group.length > 1 ? Math.min(CURVE_OFFSET, Math.max(0, shorter - PORT_INSET) / (group.length - 1)) : 0;\n\n group.forEach((edge, index) => {\n const from = requirePosition(positions, edge.from);\n const to = requirePosition(positions, edge.to);\n if (isLoop(from, to, dimensions.nodeWidth)) {\n const plan = loops.get(from.x);\n if (!plan) throw new Error(`routeEdges: no loop plan for the column of \"${edge.from}\"`);\n routes[edge.id] = loopRoute(from, to, { self: edge.from === edge.to, index, dimensions, plan, loopHeight: heightOf(dimensions, edge.from) });\n return;\n }\n const direction = to.x > from.x ? 1 : -1;\n const shift = (index - (group.length - 1) / 2) * step;\n const start = { x: from.x + direction * halfW, y: from.y + shift };\n const end = { x: to.x - direction * halfW, y: to.y + shift };\n const reach = Math.max(MIN_SIDE_REACH, Math.abs(end.x - start.x) / 2);\n const curve: CubicCurve = [\n start,\n { x: start.x + direction * reach, y: start.y },\n { x: end.x - direction * reach, y: end.y },\n end,\n ];\n routes[edge.id] = { ...cubicRoute(curve), curve };\n });\n}\n\n/**\n * Routes each edge as an SVG path. Edges sharing an unordered node pair — a\n * reciprocal A→B + B→A, or literal duplicates — are always fanned apart so\n * they never overlap.\n *\n * `anchor: \"center\"` (the default) clips each edge to the source/target node\n * rectangles: a lone edge is a straight line, a fanned one a quadratic curve\n * offset from the line between the two node centres.\n *\n * `anchor: \"side\"` is for column layouts: an edge leaves the side of its\n * source facing the target and enters the facing side of the target as a\n * cubic curve. An edge between two nodes of one column, and a self-edge, is a\n * loop: it arcs out of the column and back on the side with fewer edges to\n * other columns, the further the more height it spans, so loops nest.\n *\n * Throws when an edge references a node id absent from `positions`, naming\n * the edge id, rather than silently dropping or mis-routing it.\n */\nexport function routeEdges(\n edges: readonly GraphLayoutEdge[],\n positions: Record<string, GraphLayoutPosition>,\n dimensions: RouteEdgesDimensions,\n options: RouteEdgesOptions = {},\n): Record<string, EdgeRoute> {\n const routes: Record<string, EdgeRoute> = {};\n const groups = groupEdgesByPair(edges, positions);\n if (options.anchor !== \"side\") {\n for (const group of groups) routeCenterGroup(group, positions, dimensions, routes);\n return routes;\n }\n const loops = planLoops(edges, positions, dimensions.nodeWidth);\n for (const group of groups) routeSideGroup(group, positions, dimensions, loops, routes);\n return routes;\n}\n\n/** How far the side-anchored loops of `edges` reach past the outermost columns, on each side. */\nexport function loopOverhang(\n edges: readonly GraphLayoutEdge[],\n positions: Record<string, GraphLayoutPosition>,\n dimensions: RouteEdgesDimensions,\n): { left: number; right: number } {\n const xs = Object.values(positions).map((position) => position.x);\n const loops = Object.values(routeEdges(edges, positions, dimensions, { anchor: \"side\" })).filter(\n (route) => route.labelAnchor !== undefined,\n );\n if (loops.length === 0) return { left: 0, right: 0 };\n const peaks = loops.map((route) => route.labelX);\n const halfW = dimensions.nodeWidth / 2;\n return {\n left: Math.max(0, Math.min(...xs) - halfW - Math.min(...peaks)),\n right: Math.max(0, Math.max(...peaks) - (Math.max(...xs) + halfW)),\n };\n}\n\nexport interface EdgeLabelBox {\n id: string;\n /** The label's anchor: its centre, its left edge when `anchor` is \"start\", its right edge when \"end\". */\n x: number;\n y: number;\n width: number;\n height: number;\n anchor?: \"start\" | \"end\";\n}\n\nfunction labelLeft(box: EdgeLabelBox): number {\n if (box.anchor === \"start\") return box.x;\n return box.anchor === \"end\" ? box.x - box.width : box.x - box.width / 2;\n}\n\n/**\n * Resolves the y of each edge label so no two labels cover each other: taken\n * top to bottom, a label that would overlap one already placed drops just\n * below it. Labels keep their x, and a label that overlaps nothing keeps its y.\n */\nexport function spreadLabels(boxes: readonly EdgeLabelBox[], gap = 2): Record<string, number> {\n const placed: { left: number; right: number; y: number; height: number }[] = [];\n const ys: Record<string, number> = {};\n for (const box of [...boxes].sort((a, b) => a.y - b.y)) {\n const left = labelLeft(box);\n const right = left + box.width;\n let y = box.y;\n for (let moved = true; moved; ) {\n moved = false;\n for (const other of placed) {\n const clearance = (box.height + other.height) / 2 + gap;\n if (left < other.right && other.left < right && Math.abs(y - other.y) < clearance) {\n y = other.y + clearance;\n moved = true;\n }\n }\n }\n placed.push({ left, right, y, height: box.height });\n ys[box.id] = y;\n }\n return ys;\n}\n"],"names":[],"mappings":"AAsCA,SAAS,SAAS,YAAkC,IAAoB;AAAxE;AACE,WAAO,gBAAW,gBAAX,mBAAyB,QAAO,WAAW;AACpD;AAOA,MAAM,eAAe;AACrB,MAAM,iBAAiB;AAEvB,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;AACvB,MAAM,iBAAiB;AAEvB,MAAM,iBAAiB;AAEvB,MAAM,aAAa;AAEnB,MAAM,aAAa;AAEnB,SAAS,iBAAiB,GAAW,GAAmB;AACtD,SAAO,IAAI,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,KAAK,CAAC;AAC1C;AAEA,SAAS,gBAAgB,WAAgD,IAAiC;AACxG,QAAM,WAAW,UAAU,EAAE;AAC7B,MAAI,CAAC,UAAU;AACb,UAAM,IAAI,MAAM,4CAA4C,EAAE,GAAG;AAAA,EACnE;AACA,SA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aAAa,IAAI,SAAS,MAAM,UAAU,IAAI;AACpD,YAAI,OAAO,MAAM,SAAS,MAAM,OAAO,SAAS,KAAK,IAAI,IAAI,MAAM,CAAC,IAAI,WAAW;AACjF,cAAI,MAAM,IAAI;AACd,kBAAQ;AAAA,QACV;AAAA,MACF;AAAA,IACF;AACA,WAAO,KAAK,EAAE,MAAM,OAAO,GAAG,QAAQ,IAAI,QAAQ;AAClD,OAAG,IAAI,EAAE,IAAI;AAAA,EACf;AACA,SAAO;AACT;"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const react = require("react");
|
|
5
|
+
const AccordionList = require("../../components/AccordionList.cjs");
|
|
6
|
+
const Badge = require("../Badge.cjs");
|
|
7
|
+
const parseSource = require("./parse-source.cjs");
|
|
8
|
+
function JsonSource({
|
|
9
|
+
source,
|
|
10
|
+
inputFormat,
|
|
11
|
+
renderValue
|
|
12
|
+
}) {
|
|
13
|
+
const sourceId = react.useId();
|
|
14
|
+
const result = react.useMemo(
|
|
15
|
+
() => parseSource.parseJsonSource(source, inputFormat),
|
|
16
|
+
[source, inputFormat]
|
|
17
|
+
);
|
|
18
|
+
const label = inputFormat === "ndjson" ? "NDJSON" : "JSON";
|
|
19
|
+
if (result.status !== "complete" && !result.diagnostic)
|
|
20
|
+
throw new Error("JSON source status has no diagnostic");
|
|
21
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-density-2", "data-source-status": result.status, children: [
|
|
22
|
+
"value" in result && renderValue(result.value),
|
|
23
|
+
result.partialRecord && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-density-1", children: [
|
|
24
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-muted-foreground font-sans text-sm", children: [
|
|
25
|
+
"Line ",
|
|
26
|
+
result.partialRecord.line,
|
|
27
|
+
" (incomplete record)"
|
|
28
|
+
] }),
|
|
29
|
+
renderValue(result.partialRecord.value)
|
|
30
|
+
] }),
|
|
31
|
+
result.status === "incomplete" && !("value" in result) && !result.partialRecord && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-sans text-sm text-muted-foreground", children: "No completed values received." }),
|
|
32
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
33
|
+
AccordionList.AccordionList,
|
|
34
|
+
{
|
|
35
|
+
idPrefix: sourceId,
|
|
36
|
+
items: [source],
|
|
37
|
+
readOnly: true,
|
|
38
|
+
renderHeader: () => /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex min-w-0 flex-wrap items-center gap-density-2 font-sans text-sm", children: [
|
|
39
|
+
"Original source",
|
|
40
|
+
result.diagnostic && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
41
|
+
"span",
|
|
42
|
+
{
|
|
43
|
+
role: result.status === "invalid" ? "alert" : "status",
|
|
44
|
+
className: "inline-flex flex-wrap items-center gap-density-2",
|
|
45
|
+
children: [
|
|
46
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
47
|
+
Badge.Badge,
|
|
48
|
+
{
|
|
49
|
+
variant: "status",
|
|
50
|
+
status: result.status === "invalid" ? "error" : "warning",
|
|
51
|
+
size: "xs",
|
|
52
|
+
clickToCopy: false,
|
|
53
|
+
children: [
|
|
54
|
+
result.status === "invalid" ? "Invalid" : "Incomplete",
|
|
55
|
+
" ",
|
|
56
|
+
label
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
),
|
|
60
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-xs text-muted-foreground", children: [
|
|
61
|
+
"Line ",
|
|
62
|
+
result.diagnostic.line,
|
|
63
|
+
", column",
|
|
64
|
+
" ",
|
|
65
|
+
result.diagnostic.column
|
|
66
|
+
] })
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
)
|
|
70
|
+
] }),
|
|
71
|
+
renderBody: ({ item }) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-density-2", children: [
|
|
72
|
+
result.diagnostic && /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "font-sans text-sm text-muted-foreground whitespace-normal", children: [
|
|
73
|
+
result.diagnostic.message,
|
|
74
|
+
".",
|
|
75
|
+
result.status === "incomplete" && " Showing completed values only."
|
|
76
|
+
] }),
|
|
77
|
+
/* @__PURE__ */ jsxRuntime.jsx("pre", { className: "max-h-80 overflow-auto whitespace-pre-wrap break-words font-mono text-xs", children: item })
|
|
78
|
+
] })
|
|
79
|
+
}
|
|
80
|
+
)
|
|
81
|
+
] });
|
|
82
|
+
}
|
|
83
|
+
exports.JsonSource = JsonSource;
|
|
84
|
+
//# sourceMappingURL=JsonSource.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JsonSource.cjs","sources":["../../../src/data/json-view/JsonSource.tsx"],"sourcesContent":["import { useId, useMemo, type ReactNode } from \"react\";\nimport { AccordionList } from \"../../components/AccordionList\";\nimport { Badge } from \"../Badge\";\nimport { parseJsonSource } from \"./parse-source\";\n\nexport function JsonSource({\n source,\n inputFormat,\n renderValue,\n}: {\n source: string;\n inputFormat: \"json\" | \"ndjson\";\n renderValue: (value: unknown) => ReactNode;\n}) {\n const sourceId = useId();\n const result = useMemo(\n () => parseJsonSource(source, inputFormat),\n [source, inputFormat],\n );\n const label = inputFormat === \"ndjson\" ? \"NDJSON\" : \"JSON\";\n if (result.status !== \"complete\" && !result.diagnostic)\n throw new Error(\"JSON source status has no diagnostic\");\n return (\n <div className=\"space-y-density-2\" data-source-status={result.status}>\n {\"value\" in result && renderValue(result.value)}\n {result.partialRecord && (\n <div className=\"space-y-density-1\">\n <div className=\"text-muted-foreground font-sans text-sm\">\n Line {result.partialRecord.line} (incomplete record)\n </div>\n {renderValue(result.partialRecord.value)}\n </div>\n )}\n {result.status === \"incomplete\" &&\n !(\"value\" in result) &&\n !result.partialRecord && (\n <div className=\"font-sans text-sm text-muted-foreground\">\n No completed values received.\n </div>\n )}\n <AccordionList\n idPrefix={sourceId}\n items={[source]}\n readOnly\n renderHeader={() => (\n <span className=\"flex min-w-0 flex-wrap items-center gap-density-2 font-sans text-sm\">\n Original source\n {result.diagnostic && (\n <span\n role={result.status === \"invalid\" ? \"alert\" : \"status\"}\n className=\"inline-flex flex-wrap items-center gap-density-2\"\n >\n <Badge\n variant=\"status\"\n status={result.status === \"invalid\" ? \"error\" : \"warning\"}\n size=\"xs\"\n clickToCopy={false}\n >\n {result.status === \"invalid\" ? \"Invalid\" : \"Incomplete\"}{\" \"}\n {label}\n </Badge>\n <span className=\"text-xs text-muted-foreground\">\n Line {result.diagnostic.line}, column{\" \"}\n {result.diagnostic.column}\n </span>\n </span>\n )}\n </span>\n )}\n renderBody={({ item }) => (\n <div className=\"space-y-density-2\">\n {result.diagnostic && (\n <p className=\"font-sans text-sm text-muted-foreground whitespace-normal\">\n {result.diagnostic.message}.\n {result.status === \"incomplete\" &&\n \" Showing completed values only.\"}\n </p>\n )}\n <pre className=\"max-h-80 overflow-auto whitespace-pre-wrap break-words font-mono text-xs\">\n {item}\n </pre>\n </div>\n )}\n />\n </div>\n );\n}\n"],"names":["useId","useMemo","parseJsonSource","jsxs","jsx","AccordionList","Badge"],"mappings":";;;;;;;AAKO,SAAS,WAAW;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AACF,GAIG;AACD,QAAM,WAAWA,MAAAA,MAAA;AACjB,QAAM,SAASC,MAAAA;AAAAA,IACb,MAAMC,YAAAA,gBAAgB,QAAQ,WAAW;AAAA,IACzC,CAAC,QAAQ,WAAW;AAAA,EAAA;AAEtB,QAAM,QAAQ,gBAAgB,WAAW,WAAW;AACpD,MAAI,OAAO,WAAW,cAAc,CAAC,OAAO;AAC1C,UAAM,IAAI,MAAM,sCAAsC;AACxD,yCACG,OAAA,EAAI,WAAU,qBAAoB,sBAAoB,OAAO,QAC3D,UAAA;AAAA,IAAA,WAAW,UA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AEJ;AAAA,QAEF,YAAY,CAAC,EAAE,WACbA,2BAAAA,KAAC,OAAA,EAAI,WAAU,qBACZ,UAAA;AAAA,UAAA,OAAO,cACNA,gCAAC,KAAA,EAAE,WAAU,6DACV,UAAA;AAAA,YAAA,OAAO,WAAW;AAAA,YAAQ;AAAA,YAC1B,OAAO,WAAW,gBACjB;AAAA,UAAA,GACJ;AAAA,UAEFC,2BAAAA,IAAC,OAAA,EAAI,WAAU,4EACZ,UAAA,KAAA,CACH;AAAA,QAAA,EAAA,CACF;AAAA,MAAA;AAAA,IAAA;AAAA,EAEJ,GACF;AAEJ;;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
export declare function JsonSource({ source, inputFormat, renderValue, }: {
|
|
3
|
+
source: string;
|
|
4
|
+
inputFormat: "json" | "ndjson";
|
|
5
|
+
renderValue: (value: unknown) => ReactNode;
|
|
6
|
+
}): import("react").JSX.Element;
|
|
7
|
+
//# sourceMappingURL=JsonSource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JsonSource.d.ts","sourceRoot":"","sources":["../../../src/data/json-view/JsonSource.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAKvD,wBAAgB,UAAU,CAAC,EACzB,MAAM,EACN,WAAW,EACX,WAAW,GACZ,EAAE;IACD,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC/B,WAAW,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,SAAS,CAAC;CAC5C,+BAyEA"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useId, useMemo } from "react";
|
|
3
|
+
import { AccordionList } from "../../components/AccordionList.js";
|
|
4
|
+
import { Badge } from "../Badge.js";
|
|
5
|
+
import { parseJsonSource } from "./parse-source.js";
|
|
6
|
+
function JsonSource({
|
|
7
|
+
source,
|
|
8
|
+
inputFormat,
|
|
9
|
+
renderValue
|
|
10
|
+
}) {
|
|
11
|
+
const sourceId = useId();
|
|
12
|
+
const result = useMemo(
|
|
13
|
+
() => parseJsonSource(source, inputFormat),
|
|
14
|
+
[source, inputFormat]
|
|
15
|
+
);
|
|
16
|
+
const label = inputFormat === "ndjson" ? "NDJSON" : "JSON";
|
|
17
|
+
if (result.status !== "complete" && !result.diagnostic)
|
|
18
|
+
throw new Error("JSON source status has no diagnostic");
|
|
19
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-density-2", "data-source-status": result.status, children: [
|
|
20
|
+
"value" in result && renderValue(result.value),
|
|
21
|
+
result.partialRecord && /* @__PURE__ */ jsxs("div", { className: "space-y-density-1", children: [
|
|
22
|
+
/* @__PURE__ */ jsxs("div", { className: "text-muted-foreground font-sans text-sm", children: [
|
|
23
|
+
"Line ",
|
|
24
|
+
result.partialRecord.line,
|
|
25
|
+
" (incomplete record)"
|
|
26
|
+
] }),
|
|
27
|
+
renderValue(result.partialRecord.value)
|
|
28
|
+
] }),
|
|
29
|
+
result.status === "incomplete" && !("value" in result) && !result.partialRecord && /* @__PURE__ */ jsx("div", { className: "font-sans text-sm text-muted-foreground", children: "No completed values received." }),
|
|
30
|
+
/* @__PURE__ */ jsx(
|
|
31
|
+
AccordionList,
|
|
32
|
+
{
|
|
33
|
+
idPrefix: sourceId,
|
|
34
|
+
items: [source],
|
|
35
|
+
readOnly: true,
|
|
36
|
+
renderHeader: () => /* @__PURE__ */ jsxs("span", { className: "flex min-w-0 flex-wrap items-center gap-density-2 font-sans text-sm", children: [
|
|
37
|
+
"Original source",
|
|
38
|
+
result.diagnostic && /* @__PURE__ */ jsxs(
|
|
39
|
+
"span",
|
|
40
|
+
{
|
|
41
|
+
role: result.status === "invalid" ? "alert" : "status",
|
|
42
|
+
className: "inline-flex flex-wrap items-center gap-density-2",
|
|
43
|
+
children: [
|
|
44
|
+
/* @__PURE__ */ jsxs(
|
|
45
|
+
Badge,
|
|
46
|
+
{
|
|
47
|
+
variant: "status",
|
|
48
|
+
status: result.status === "invalid" ? "error" : "warning",
|
|
49
|
+
size: "xs",
|
|
50
|
+
clickToCopy: false,
|
|
51
|
+
children: [
|
|
52
|
+
result.status === "invalid" ? "Invalid" : "Incomplete",
|
|
53
|
+
" ",
|
|
54
|
+
label
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
),
|
|
58
|
+
/* @__PURE__ */ jsxs("span", { className: "text-xs text-muted-foreground", children: [
|
|
59
|
+
"Line ",
|
|
60
|
+
result.diagnostic.line,
|
|
61
|
+
", column",
|
|
62
|
+
" ",
|
|
63
|
+
result.diagnostic.column
|
|
64
|
+
] })
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
)
|
|
68
|
+
] }),
|
|
69
|
+
renderBody: ({ item }) => /* @__PURE__ */ jsxs("div", { className: "space-y-density-2", children: [
|
|
70
|
+
result.diagnostic && /* @__PURE__ */ jsxs("p", { className: "font-sans text-sm text-muted-foreground whitespace-normal", children: [
|
|
71
|
+
result.diagnostic.message,
|
|
72
|
+
".",
|
|
73
|
+
result.status === "incomplete" && " Showing completed values only."
|
|
74
|
+
] }),
|
|
75
|
+
/* @__PURE__ */ jsx("pre", { className: "max-h-80 overflow-auto whitespace-pre-wrap break-words font-mono text-xs", children: item })
|
|
76
|
+
] })
|
|
77
|
+
}
|
|
78
|
+
)
|
|
79
|
+
] });
|
|
80
|
+
}
|
|
81
|
+
export {
|
|
82
|
+
JsonSource
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=JsonSource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JsonSource.js","sources":["../../../src/data/json-view/JsonSource.tsx"],"sourcesContent":["import { useId, useMemo, type ReactNode } from \"react\";\nimport { AccordionList } from \"../../components/AccordionList\";\nimport { Badge } from \"../Badge\";\nimport { parseJsonSource } from \"./parse-source\";\n\nexport function JsonSource({\n source,\n inputFormat,\n renderValue,\n}: {\n source: string;\n inputFormat: \"json\" | \"ndjson\";\n renderValue: (value: unknown) => ReactNode;\n}) {\n const sourceId = useId();\n const result = useMemo(\n () => parseJsonSource(source, inputFormat),\n [source, inputFormat],\n );\n const label = inputFormat === \"ndjson\" ? \"NDJSON\" : \"JSON\";\n if (result.status !== \"complete\" && !result.diagnostic)\n throw new Error(\"JSON source status has no diagnostic\");\n return (\n <div className=\"space-y-density-2\" data-source-status={result.status}>\n {\"value\" in result && renderValue(result.value)}\n {result.partialRecord && (\n <div className=\"space-y-density-1\">\n <div className=\"text-muted-foreground font-sans text-sm\">\n Line {result.partialRecord.line} (incomplete record)\n </div>\n {renderValue(result.partialRecord.value)}\n </div>\n )}\n {result.status === \"incomplete\" &&\n !(\"value\" in result) &&\n !result.partialRecord && (\n <div className=\"font-sans text-sm text-muted-foreground\">\n No completed values received.\n </div>\n )}\n <AccordionList\n idPrefix={sourceId}\n items={[source]}\n readOnly\n renderHeader={() => (\n <span className=\"flex min-w-0 flex-wrap items-center gap-density-2 font-sans text-sm\">\n Original source\n {result.diagnostic && (\n <span\n role={result.status === \"invalid\" ? \"alert\" : \"status\"}\n className=\"inline-flex flex-wrap items-center gap-density-2\"\n >\n <Badge\n variant=\"status\"\n status={result.status === \"invalid\" ? \"error\" : \"warning\"}\n size=\"xs\"\n clickToCopy={false}\n >\n {result.status === \"invalid\" ? \"Invalid\" : \"Incomplete\"}{\" \"}\n {label}\n </Badge>\n <span className=\"text-xs text-muted-foreground\">\n Line {result.diagnostic.line}, column{\" \"}\n {result.diagnostic.column}\n </span>\n </span>\n )}\n </span>\n )}\n renderBody={({ item }) => (\n <div className=\"space-y-density-2\">\n {result.diagnostic && (\n <p className=\"font-sans text-sm text-muted-foreground whitespace-normal\">\n {result.diagnostic.message}.\n {result.status === \"incomplete\" &&\n \" Showing completed values only.\"}\n </p>\n )}\n <pre className=\"max-h-80 overflow-auto whitespace-pre-wrap break-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