@yh-ui/flow 0.1.21
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/LICENSE +21 -0
- package/README.md +234 -0
- package/dist/Flow.d.vue.ts +306 -0
- package/dist/Flow.vue +959 -0
- package/dist/Flow.vue.d.ts +306 -0
- package/dist/__tests__/ai-workflow.ssr.test.cjs +352 -0
- package/dist/__tests__/ai-workflow.ssr.test.d.ts +1 -0
- package/dist/__tests__/ai-workflow.ssr.test.mjs +283 -0
- package/dist/__tests__/ai-workflow.test.cjs +109 -0
- package/dist/__tests__/ai-workflow.test.d.ts +1 -0
- package/dist/__tests__/ai-workflow.test.mjs +112 -0
- package/dist/__tests__/bpmn.ssr.test.cjs +278 -0
- package/dist/__tests__/bpmn.ssr.test.d.ts +1 -0
- package/dist/__tests__/bpmn.ssr.test.mjs +237 -0
- package/dist/__tests__/bpmn.test.cjs +103 -0
- package/dist/__tests__/bpmn.test.d.ts +1 -0
- package/dist/__tests__/bpmn.test.mjs +106 -0
- package/dist/__tests__/custom-types.test.cjs +300 -0
- package/dist/__tests__/custom-types.test.d.ts +1 -0
- package/dist/__tests__/custom-types.test.mjs +248 -0
- package/dist/__tests__/edge.test.cjs +56 -0
- package/dist/__tests__/edge.test.d.ts +1 -0
- package/dist/__tests__/edge.test.mjs +69 -0
- package/dist/__tests__/event-bus.test.cjs +80 -0
- package/dist/__tests__/event-bus.test.d.ts +1 -0
- package/dist/__tests__/event-bus.test.mjs +51 -0
- package/dist/__tests__/flow.ssr.test.cjs +156 -0
- package/dist/__tests__/flow.ssr.test.d.ts +1 -0
- package/dist/__tests__/flow.ssr.test.mjs +112 -0
- package/dist/__tests__/geometry.test.cjs +191 -0
- package/dist/__tests__/geometry.test.d.ts +1 -0
- package/dist/__tests__/geometry.test.mjs +105 -0
- package/dist/__tests__/graph.test.cjs +115 -0
- package/dist/__tests__/graph.test.d.ts +1 -0
- package/dist/__tests__/graph.test.mjs +85 -0
- package/dist/__tests__/history-plugin.test.cjs +191 -0
- package/dist/__tests__/history-plugin.test.d.ts +1 -0
- package/dist/__tests__/history-plugin.test.mjs +161 -0
- package/dist/__tests__/history.test.cjs +81 -0
- package/dist/__tests__/history.test.d.ts +1 -0
- package/dist/__tests__/history.test.mjs +43 -0
- package/dist/__tests__/layout.test.cjs +213 -0
- package/dist/__tests__/layout.test.d.ts +1 -0
- package/dist/__tests__/layout.test.mjs +170 -0
- package/dist/__tests__/node-edit-panel.ssr.test.cjs +168 -0
- package/dist/__tests__/node-edit-panel.ssr.test.d.ts +1 -0
- package/dist/__tests__/node-edit-panel.ssr.test.mjs +118 -0
- package/dist/__tests__/node-group-plugin.test.cjs +235 -0
- package/dist/__tests__/node-group-plugin.test.d.ts +1 -0
- package/dist/__tests__/node-group-plugin.test.mjs +187 -0
- package/dist/__tests__/node-handles.test.cjs +340 -0
- package/dist/__tests__/node-handles.test.d.ts +1 -0
- package/dist/__tests__/node-handles.test.mjs +230 -0
- package/dist/__tests__/plugin.test.cjs +151 -0
- package/dist/__tests__/plugin.test.d.ts +1 -0
- package/dist/__tests__/plugin.test.mjs +116 -0
- package/dist/__tests__/transform.test.cjs +58 -0
- package/dist/__tests__/transform.test.d.ts +1 -0
- package/dist/__tests__/transform.test.mjs +38 -0
- package/dist/__tests__/useAlignment.test.cjs +91 -0
- package/dist/__tests__/useAlignment.test.d.ts +1 -0
- package/dist/__tests__/useAlignment.test.mjs +52 -0
- package/dist/__tests__/useEdges.test.cjs +117 -0
- package/dist/__tests__/useEdges.test.d.ts +1 -0
- package/dist/__tests__/useEdges.test.mjs +80 -0
- package/dist/__tests__/useKeyboard.test.cjs +88 -0
- package/dist/__tests__/useKeyboard.test.d.ts +1 -0
- package/dist/__tests__/useKeyboard.test.mjs +56 -0
- package/dist/__tests__/useNodes.test.cjs +150 -0
- package/dist/__tests__/useNodes.test.d.ts +1 -0
- package/dist/__tests__/useNodes.test.mjs +80 -0
- package/dist/__tests__/useSelection.test.cjs +112 -0
- package/dist/__tests__/useSelection.test.d.ts +1 -0
- package/dist/__tests__/useSelection.test.mjs +76 -0
- package/dist/__tests__/useViewport.test.cjs +171 -0
- package/dist/__tests__/useViewport.test.d.ts +1 -0
- package/dist/__tests__/useViewport.test.mjs +82 -0
- package/dist/__tests__/utils/ssr.cjs +124 -0
- package/dist/__tests__/utils/ssr.d.ts +33 -0
- package/dist/__tests__/utils/ssr.mjs +129 -0
- package/dist/__tests__/validation.test.cjs +95 -0
- package/dist/__tests__/validation.test.d.ts +1 -0
- package/dist/__tests__/validation.test.mjs +36 -0
- package/dist/components/AiNodeEditPanel.d.vue.ts +13 -0
- package/dist/components/AiNodeEditPanel.vue +413 -0
- package/dist/components/AiNodeEditPanel.vue.d.ts +13 -0
- package/dist/components/EdgeEditPanel.d.vue.ts +14 -0
- package/dist/components/EdgeEditPanel.vue +205 -0
- package/dist/components/EdgeEditPanel.vue.d.ts +14 -0
- package/dist/components/NodeEditPanel.d.vue.ts +13 -0
- package/dist/components/NodeEditPanel.vue +214 -0
- package/dist/components/NodeEditPanel.vue.d.ts +13 -0
- package/dist/components/edges/BaseEdge.d.vue.ts +23 -0
- package/dist/components/edges/BaseEdge.vue +55 -0
- package/dist/components/edges/BaseEdge.vue.d.ts +23 -0
- package/dist/components/edges/BezierEdge.d.vue.ts +22 -0
- package/dist/components/edges/BezierEdge.vue +57 -0
- package/dist/components/edges/BezierEdge.vue.d.ts +22 -0
- package/dist/components/edges/DataFlowEdge.d.vue.ts +41 -0
- package/dist/components/edges/DataFlowEdge.vue +211 -0
- package/dist/components/edges/DataFlowEdge.vue.d.ts +41 -0
- package/dist/components/edges/SmoothEdge.d.vue.ts +22 -0
- package/dist/components/edges/SmoothEdge.vue +53 -0
- package/dist/components/edges/SmoothEdge.vue.d.ts +22 -0
- package/dist/components/edges/StepEdge.d.vue.ts +22 -0
- package/dist/components/edges/StepEdge.vue +42 -0
- package/dist/components/edges/StepEdge.vue.d.ts +22 -0
- package/dist/components/edges/index.cjs +41 -0
- package/dist/components/edges/index.d.ts +5 -0
- package/dist/components/edges/index.mjs +5 -0
- package/dist/components/nodes/BaseNode.d.vue.ts +25 -0
- package/dist/components/nodes/BaseNode.vue +93 -0
- package/dist/components/nodes/BaseNode.vue.d.ts +25 -0
- package/dist/components/nodes/CustomNode.d.vue.ts +36 -0
- package/dist/components/nodes/CustomNode.vue +44 -0
- package/dist/components/nodes/CustomNode.vue.d.ts +36 -0
- package/dist/components/nodes/DatabaseNode.d.vue.ts +19 -0
- package/dist/components/nodes/DatabaseNode.vue +62 -0
- package/dist/components/nodes/DatabaseNode.vue.d.ts +19 -0
- package/dist/components/nodes/DiamondNode.d.vue.ts +19 -0
- package/dist/components/nodes/DiamondNode.vue +62 -0
- package/dist/components/nodes/DiamondNode.vue.d.ts +19 -0
- package/dist/components/nodes/GroupNode.d.vue.ts +31 -0
- package/dist/components/nodes/GroupNode.vue +48 -0
- package/dist/components/nodes/GroupNode.vue.d.ts +31 -0
- package/dist/components/nodes/InputNode.d.vue.ts +23 -0
- package/dist/components/nodes/InputNode.vue +63 -0
- package/dist/components/nodes/InputNode.vue.d.ts +23 -0
- package/dist/components/nodes/NodeResizer.d.vue.ts +27 -0
- package/dist/components/nodes/NodeResizer.vue +89 -0
- package/dist/components/nodes/NodeResizer.vue.d.ts +27 -0
- package/dist/components/nodes/NodeToolbar.d.vue.ts +32 -0
- package/dist/components/nodes/NodeToolbar.vue +101 -0
- package/dist/components/nodes/NodeToolbar.vue.d.ts +32 -0
- package/dist/components/nodes/OutputNode.d.vue.ts +21 -0
- package/dist/components/nodes/OutputNode.vue +53 -0
- package/dist/components/nodes/OutputNode.vue.d.ts +21 -0
- package/dist/components/nodes/ai-workflow/AiAgentNode.d.vue.ts +20 -0
- package/dist/components/nodes/ai-workflow/AiAgentNode.vue +59 -0
- package/dist/components/nodes/ai-workflow/AiAgentNode.vue.d.ts +20 -0
- package/dist/components/nodes/ai-workflow/AiConditionNode.d.vue.ts +19 -0
- package/dist/components/nodes/ai-workflow/AiConditionNode.vue +65 -0
- package/dist/components/nodes/ai-workflow/AiConditionNode.vue.d.ts +19 -0
- package/dist/components/nodes/ai-workflow/AiEndNode.d.vue.ts +19 -0
- package/dist/components/nodes/ai-workflow/AiEndNode.vue +47 -0
- package/dist/components/nodes/ai-workflow/AiEndNode.vue.d.ts +19 -0
- package/dist/components/nodes/ai-workflow/AiLlmNode.d.vue.ts +19 -0
- package/dist/components/nodes/ai-workflow/AiLlmNode.vue +64 -0
- package/dist/components/nodes/ai-workflow/AiLlmNode.vue.d.ts +19 -0
- package/dist/components/nodes/ai-workflow/AiMemoryNode.d.vue.ts +19 -0
- package/dist/components/nodes/ai-workflow/AiMemoryNode.vue +59 -0
- package/dist/components/nodes/ai-workflow/AiMemoryNode.vue.d.ts +19 -0
- package/dist/components/nodes/ai-workflow/AiPromptNode.d.vue.ts +19 -0
- package/dist/components/nodes/ai-workflow/AiPromptNode.vue +61 -0
- package/dist/components/nodes/ai-workflow/AiPromptNode.vue.d.ts +19 -0
- package/dist/components/nodes/ai-workflow/AiStartNode.d.vue.ts +19 -0
- package/dist/components/nodes/ai-workflow/AiStartNode.vue +47 -0
- package/dist/components/nodes/ai-workflow/AiStartNode.vue.d.ts +19 -0
- package/dist/components/nodes/ai-workflow/AiToolNode.d.vue.ts +19 -0
- package/dist/components/nodes/ai-workflow/AiToolNode.vue +59 -0
- package/dist/components/nodes/ai-workflow/AiToolNode.vue.d.ts +19 -0
- package/dist/components/nodes/ai-workflow/index.cjs +109 -0
- package/dist/components/nodes/ai-workflow/index.d.ts +23 -0
- package/dist/components/nodes/ai-workflow/index.mjs +37 -0
- package/dist/components/nodes/bpmn/BpmnEndEvent.d.vue.ts +19 -0
- package/dist/components/nodes/bpmn/BpmnEndEvent.vue +50 -0
- package/dist/components/nodes/bpmn/BpmnEndEvent.vue.d.ts +19 -0
- package/dist/components/nodes/bpmn/BpmnExclusiveGateway.d.vue.ts +19 -0
- package/dist/components/nodes/bpmn/BpmnExclusiveGateway.vue +60 -0
- package/dist/components/nodes/bpmn/BpmnExclusiveGateway.vue.d.ts +19 -0
- package/dist/components/nodes/bpmn/BpmnInclusiveGateway.d.vue.ts +19 -0
- package/dist/components/nodes/bpmn/BpmnInclusiveGateway.vue +60 -0
- package/dist/components/nodes/bpmn/BpmnInclusiveGateway.vue.d.ts +19 -0
- package/dist/components/nodes/bpmn/BpmnParallelGateway.d.vue.ts +19 -0
- package/dist/components/nodes/bpmn/BpmnParallelGateway.vue +60 -0
- package/dist/components/nodes/bpmn/BpmnParallelGateway.vue.d.ts +19 -0
- package/dist/components/nodes/bpmn/BpmnServiceTask.d.vue.ts +19 -0
- package/dist/components/nodes/bpmn/BpmnServiceTask.vue +55 -0
- package/dist/components/nodes/bpmn/BpmnServiceTask.vue.d.ts +19 -0
- package/dist/components/nodes/bpmn/BpmnStartEvent.d.vue.ts +19 -0
- package/dist/components/nodes/bpmn/BpmnStartEvent.vue +50 -0
- package/dist/components/nodes/bpmn/BpmnStartEvent.vue.d.ts +19 -0
- package/dist/components/nodes/bpmn/BpmnTask.d.vue.ts +19 -0
- package/dist/components/nodes/bpmn/BpmnTask.vue +54 -0
- package/dist/components/nodes/bpmn/BpmnTask.vue.d.ts +19 -0
- package/dist/components/nodes/bpmn/BpmnUserTask.d.vue.ts +19 -0
- package/dist/components/nodes/bpmn/BpmnUserTask.vue +55 -0
- package/dist/components/nodes/bpmn/BpmnUserTask.vue.d.ts +19 -0
- package/dist/components/nodes/bpmn/index.cjs +109 -0
- package/dist/components/nodes/bpmn/index.d.ts +23 -0
- package/dist/components/nodes/bpmn/index.mjs +37 -0
- package/dist/components/nodes/index.cjs +246 -0
- package/dist/components/nodes/index.d.ts +13 -0
- package/dist/components/nodes/index.mjs +44 -0
- package/dist/core/FlowContext.cjs +21 -0
- package/dist/core/FlowContext.d.ts +10 -0
- package/dist/core/FlowContext.mjs +13 -0
- package/dist/core/index.cjs +104 -0
- package/dist/core/index.d.ts +9 -0
- package/dist/core/index.mjs +9 -0
- package/dist/core/useAlignment.cjs +81 -0
- package/dist/core/useAlignment.d.ts +33 -0
- package/dist/core/useAlignment.mjs +71 -0
- package/dist/core/useEdges.cjs +132 -0
- package/dist/core/useEdges.d.ts +29 -0
- package/dist/core/useEdges.mjs +89 -0
- package/dist/core/useFlow.cjs +40 -0
- package/dist/core/useFlow.d.ts +31 -0
- package/dist/core/useFlow.mjs +32 -0
- package/dist/core/useHistory.cjs +63 -0
- package/dist/core/useHistory.d.ts +15 -0
- package/dist/core/useHistory.mjs +54 -0
- package/dist/core/useKeyboard.cjs +54 -0
- package/dist/core/useKeyboard.d.ts +18 -0
- package/dist/core/useKeyboard.mjs +45 -0
- package/dist/core/useNodeDistribution.cjs +171 -0
- package/dist/core/useNodeDistribution.d.ts +12 -0
- package/dist/core/useNodeDistribution.mjs +145 -0
- package/dist/core/useNodes.cjs +146 -0
- package/dist/core/useNodes.d.ts +26 -0
- package/dist/core/useNodes.mjs +101 -0
- package/dist/core/useSelection.cjs +83 -0
- package/dist/core/useSelection.d.ts +18 -0
- package/dist/core/useSelection.mjs +53 -0
- package/dist/core/useViewport.cjs +157 -0
- package/dist/core/useViewport.d.ts +65 -0
- package/dist/core/useViewport.mjs +125 -0
- package/dist/flow.cjs +240 -0
- package/dist/flow.d.ts +276 -0
- package/dist/flow.mjs +230 -0
- package/dist/index.cjs +378 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.mjs +50 -0
- package/dist/plugins/index.cjs +96 -0
- package/dist/plugins/index.d.ts +34 -0
- package/dist/plugins/index.mjs +47 -0
- package/dist/plugins/plugin.cjs +117 -0
- package/dist/plugins/plugin.d.ts +72 -0
- package/dist/plugins/plugin.mjs +110 -0
- package/dist/plugins/plugins/controls.cjs +38 -0
- package/dist/plugins/plugins/controls.d.ts +12 -0
- package/dist/plugins/plugins/controls.mjs +28 -0
- package/dist/plugins/plugins/export.cjs +102 -0
- package/dist/plugins/plugins/export.d.ts +12 -0
- package/dist/plugins/plugins/export.mjs +89 -0
- package/dist/plugins/plugins/grid.cjs +36 -0
- package/dist/plugins/plugins/grid.d.ts +11 -0
- package/dist/plugins/plugins/grid.mjs +26 -0
- package/dist/plugins/plugins/history.cjs +140 -0
- package/dist/plugins/plugins/history.d.ts +53 -0
- package/dist/plugins/plugins/history.mjs +132 -0
- package/dist/plugins/plugins/index.cjs +104 -0
- package/dist/plugins/plugins/index.d.ts +9 -0
- package/dist/plugins/plugins/index.mjs +9 -0
- package/dist/plugins/plugins/keyboard.cjs +27 -0
- package/dist/plugins/plugins/keyboard.d.ts +10 -0
- package/dist/plugins/plugins/keyboard.mjs +18 -0
- package/dist/plugins/plugins/layout.cjs +275 -0
- package/dist/plugins/plugins/layout.d.ts +34 -0
- package/dist/plugins/plugins/layout.mjs +246 -0
- package/dist/plugins/plugins/minimap.cjs +60 -0
- package/dist/plugins/plugins/minimap.d.ts +25 -0
- package/dist/plugins/plugins/minimap.mjs +50 -0
- package/dist/plugins/plugins/node-group.cjs +209 -0
- package/dist/plugins/plugins/node-group.d.ts +26 -0
- package/dist/plugins/plugins/node-group.mjs +178 -0
- package/dist/plugins/plugins/snap.cjs +36 -0
- package/dist/plugins/plugins/snap.d.ts +12 -0
- package/dist/plugins/plugins/snap.mjs +26 -0
- package/dist/renderer/AlignmentLines.d.vue.ts +5 -0
- package/dist/renderer/AlignmentLines.vue +113 -0
- package/dist/renderer/AlignmentLines.vue.d.ts +5 -0
- package/dist/renderer/Background.d.vue.ts +7 -0
- package/dist/renderer/Background.vue +86 -0
- package/dist/renderer/Background.vue.d.ts +7 -0
- package/dist/renderer/Controls.d.vue.ts +13 -0
- package/dist/renderer/Controls.vue +82 -0
- package/dist/renderer/Controls.vue.d.ts +13 -0
- package/dist/renderer/EdgeHandlesRenderer.d.vue.ts +11 -0
- package/dist/renderer/EdgeHandlesRenderer.vue +75 -0
- package/dist/renderer/EdgeHandlesRenderer.vue.d.ts +11 -0
- package/dist/renderer/EdgeRenderer.d.vue.ts +39 -0
- package/dist/renderer/EdgeRenderer.vue +204 -0
- package/dist/renderer/EdgeRenderer.vue.d.ts +39 -0
- package/dist/renderer/FlowBackground.d.vue.ts +11 -0
- package/dist/renderer/FlowBackground.vue +82 -0
- package/dist/renderer/FlowBackground.vue.d.ts +11 -0
- package/dist/renderer/Minimap.d.vue.ts +30 -0
- package/dist/renderer/Minimap.vue +290 -0
- package/dist/renderer/Minimap.vue.d.ts +30 -0
- package/dist/renderer/NodeRenderer.d.vue.ts +56 -0
- package/dist/renderer/NodeRenderer.vue +328 -0
- package/dist/renderer/NodeRenderer.vue.d.ts +56 -0
- package/dist/renderer/SelectionBox.d.vue.ts +11 -0
- package/dist/renderer/SelectionBox.vue +28 -0
- package/dist/renderer/SelectionBox.vue.d.ts +11 -0
- package/dist/types/edge.cjs +13 -0
- package/dist/types/edge.d.ts +65 -0
- package/dist/types/edge.mjs +6 -0
- package/dist/types/events.cjs +1 -0
- package/dist/types/events.d.ts +115 -0
- package/dist/types/events.mjs +0 -0
- package/dist/types/index.cjs +1 -0
- package/dist/types/index.d.ts +366 -0
- package/dist/types/index.mjs +0 -0
- package/dist/types/node.cjs +9 -0
- package/dist/types/node.d.ts +90 -0
- package/dist/types/node.mjs +3 -0
- package/dist/types/viewport.cjs +42 -0
- package/dist/types/viewport.d.ts +62 -0
- package/dist/types/viewport.mjs +36 -0
- package/dist/utils/bpmn-engine.cjs +390 -0
- package/dist/utils/bpmn-engine.d.ts +164 -0
- package/dist/utils/bpmn-engine.mjs +378 -0
- package/dist/utils/bpmn.cjs +492 -0
- package/dist/utils/bpmn.d.ts +53 -0
- package/dist/utils/bpmn.mjs +430 -0
- package/dist/utils/collaboration.cjs +537 -0
- package/dist/utils/collaboration.d.ts +189 -0
- package/dist/utils/collaboration.mjs +521 -0
- package/dist/utils/custom-types.cjs +138 -0
- package/dist/utils/custom-types.d.ts +78 -0
- package/dist/utils/custom-types.mjs +108 -0
- package/dist/utils/edge.cjs +235 -0
- package/dist/utils/edge.d.ts +79 -0
- package/dist/utils/edge.mjs +172 -0
- package/dist/utils/event-bus.cjs +91 -0
- package/dist/utils/event-bus.d.ts +39 -0
- package/dist/utils/event-bus.mjs +82 -0
- package/dist/utils/geometry.cjs +178 -0
- package/dist/utils/geometry.d.ts +186 -0
- package/dist/utils/geometry.mjs +144 -0
- package/dist/utils/graph.cjs +158 -0
- package/dist/utils/graph.d.ts +40 -0
- package/dist/utils/graph.mjs +147 -0
- package/dist/utils/index.cjs +137 -0
- package/dist/utils/index.d.ts +12 -0
- package/dist/utils/index.mjs +12 -0
- package/dist/utils/performance.cjs +94 -0
- package/dist/utils/performance.d.ts +18 -0
- package/dist/utils/performance.mjs +82 -0
- package/dist/utils/screenshot.cjs +87 -0
- package/dist/utils/screenshot.d.ts +22 -0
- package/dist/utils/screenshot.mjs +66 -0
- package/dist/utils/theme.cjs +228 -0
- package/dist/utils/theme.d.ts +92 -0
- package/dist/utils/theme.mjs +217 -0
- package/dist/utils/transform.cjs +76 -0
- package/dist/utils/transform.d.ts +45 -0
- package/dist/utils/transform.mjs +57 -0
- package/dist/utils/validation.cjs +107 -0
- package/dist/utils/validation.d.ts +29 -0
- package/dist/utils/validation.mjs +85 -0
- package/package.json +61 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _vitest = require("vitest");
|
|
4
|
+
var _geometry = require("../utils/geometry.cjs");
|
|
5
|
+
(0, _vitest.describe)("flow/utils/geometry", () => {
|
|
6
|
+
(0, _vitest.it)("isPointInRect", () => {
|
|
7
|
+
(0, _vitest.expect)((0, _geometry.isPointInRect)({
|
|
8
|
+
x: 50,
|
|
9
|
+
y: 50
|
|
10
|
+
}, {
|
|
11
|
+
x: 0,
|
|
12
|
+
y: 0,
|
|
13
|
+
width: 100,
|
|
14
|
+
height: 100
|
|
15
|
+
})).toBe(true);
|
|
16
|
+
(0, _vitest.expect)((0, _geometry.isPointInRect)({
|
|
17
|
+
x: 150,
|
|
18
|
+
y: 50
|
|
19
|
+
}, {
|
|
20
|
+
x: 0,
|
|
21
|
+
y: 0,
|
|
22
|
+
width: 100,
|
|
23
|
+
height: 100
|
|
24
|
+
})).toBe(false);
|
|
25
|
+
});
|
|
26
|
+
(0, _vitest.it)("rectIntersect", () => {
|
|
27
|
+
(0, _vitest.expect)((0, _geometry.rectIntersect)({
|
|
28
|
+
x: 0,
|
|
29
|
+
y: 0,
|
|
30
|
+
width: 50,
|
|
31
|
+
height: 50
|
|
32
|
+
}, {
|
|
33
|
+
x: 25,
|
|
34
|
+
y: 25,
|
|
35
|
+
width: 50,
|
|
36
|
+
height: 50
|
|
37
|
+
})).toBe(true);
|
|
38
|
+
(0, _vitest.expect)((0, _geometry.rectIntersect)({
|
|
39
|
+
x: 0,
|
|
40
|
+
y: 0,
|
|
41
|
+
width: 10,
|
|
42
|
+
height: 10
|
|
43
|
+
}, {
|
|
44
|
+
x: 20,
|
|
45
|
+
y: 20,
|
|
46
|
+
width: 10,
|
|
47
|
+
height: 10
|
|
48
|
+
})).toBe(false);
|
|
49
|
+
});
|
|
50
|
+
(0, _vitest.it)("getRectIntersection", () => {
|
|
51
|
+
const r = (0, _geometry.getRectIntersection)({
|
|
52
|
+
x: 0,
|
|
53
|
+
y: 0,
|
|
54
|
+
width: 100,
|
|
55
|
+
height: 100
|
|
56
|
+
}, {
|
|
57
|
+
x: 50,
|
|
58
|
+
y: 50,
|
|
59
|
+
width: 100,
|
|
60
|
+
height: 100
|
|
61
|
+
});
|
|
62
|
+
(0, _vitest.expect)(r).not.toBeNull();
|
|
63
|
+
(0, _vitest.expect)(r.x).toBe(50);
|
|
64
|
+
(0, _vitest.expect)(r.y).toBe(50);
|
|
65
|
+
(0, _vitest.expect)(r.width).toBe(50);
|
|
66
|
+
(0, _vitest.expect)(r.height).toBe(50);
|
|
67
|
+
});
|
|
68
|
+
(0, _vitest.it)("getBoundingBox empty returns zeros", () => {
|
|
69
|
+
const box = (0, _geometry.getBoundingBox)([]);
|
|
70
|
+
(0, _vitest.expect)(box).toEqual({
|
|
71
|
+
x: 0,
|
|
72
|
+
y: 0,
|
|
73
|
+
width: 0,
|
|
74
|
+
height: 0
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
(0, _vitest.it)("getBoundingBox multiple points", () => {
|
|
78
|
+
const box = (0, _geometry.getBoundingBox)([{
|
|
79
|
+
x: 10,
|
|
80
|
+
y: 20
|
|
81
|
+
}, {
|
|
82
|
+
x: 30,
|
|
83
|
+
y: 5
|
|
84
|
+
}]);
|
|
85
|
+
(0, _vitest.expect)(box.x).toBe(10);
|
|
86
|
+
(0, _vitest.expect)(box.y).toBe(5);
|
|
87
|
+
(0, _vitest.expect)(box.width).toBe(20);
|
|
88
|
+
(0, _vitest.expect)(box.height).toBe(15);
|
|
89
|
+
});
|
|
90
|
+
(0, _vitest.it)("getNodeBounds", () => {
|
|
91
|
+
const nodes = [{
|
|
92
|
+
position: {
|
|
93
|
+
x: 0,
|
|
94
|
+
y: 0
|
|
95
|
+
},
|
|
96
|
+
width: 50,
|
|
97
|
+
height: 50
|
|
98
|
+
}, {
|
|
99
|
+
position: {
|
|
100
|
+
x: 100,
|
|
101
|
+
y: 100
|
|
102
|
+
},
|
|
103
|
+
width: 50,
|
|
104
|
+
height: 50
|
|
105
|
+
}];
|
|
106
|
+
const bounds = (0, _geometry.getNodeBounds)(nodes);
|
|
107
|
+
(0, _vitest.expect)(bounds.x).toBe(0);
|
|
108
|
+
(0, _vitest.expect)(bounds.y).toBe(0);
|
|
109
|
+
(0, _vitest.expect)(bounds.width).toBe(150);
|
|
110
|
+
(0, _vitest.expect)(bounds.height).toBe(150);
|
|
111
|
+
});
|
|
112
|
+
(0, _vitest.it)("pointToLineDistance", () => {
|
|
113
|
+
const d = (0, _geometry.pointToLineDistance)({
|
|
114
|
+
x: 0,
|
|
115
|
+
y: 0
|
|
116
|
+
}, {
|
|
117
|
+
x: 10,
|
|
118
|
+
y: 0
|
|
119
|
+
}, {
|
|
120
|
+
x: 10,
|
|
121
|
+
y: 10
|
|
122
|
+
});
|
|
123
|
+
(0, _vitest.expect)(d).toBeGreaterThanOrEqual(0);
|
|
124
|
+
});
|
|
125
|
+
(0, _vitest.it)("pointToPointDistance", () => {
|
|
126
|
+
(0, _vitest.expect)((0, _geometry.pointToPointDistance)({
|
|
127
|
+
x: 0,
|
|
128
|
+
y: 0
|
|
129
|
+
}, {
|
|
130
|
+
x: 3,
|
|
131
|
+
y: 4
|
|
132
|
+
})).toBe(5);
|
|
133
|
+
});
|
|
134
|
+
(0, _vitest.it)("degToRad and radToDeg", () => {
|
|
135
|
+
(0, _vitest.expect)((0, _geometry.degToRad)(180)).toBeCloseTo(Math.PI);
|
|
136
|
+
(0, _vitest.expect)((0, _geometry.radToDeg)(Math.PI)).toBeCloseTo(180);
|
|
137
|
+
});
|
|
138
|
+
(0, _vitest.it)("getLineIntersection", () => {
|
|
139
|
+
const p = (0, _geometry.getLineIntersection)({
|
|
140
|
+
x: 0,
|
|
141
|
+
y: 0
|
|
142
|
+
}, {
|
|
143
|
+
x: 10,
|
|
144
|
+
y: 10
|
|
145
|
+
}, {
|
|
146
|
+
x: 0,
|
|
147
|
+
y: 10
|
|
148
|
+
}, {
|
|
149
|
+
x: 10,
|
|
150
|
+
y: 0
|
|
151
|
+
});
|
|
152
|
+
(0, _vitest.expect)(p).not.toBeNull();
|
|
153
|
+
(0, _vitest.expect)(typeof p.x).toBe("number");
|
|
154
|
+
(0, _vitest.expect)(typeof p.y).toBe("number");
|
|
155
|
+
});
|
|
156
|
+
(0, _vitest.it)("getAngle", () => {
|
|
157
|
+
const a = (0, _geometry.getAngle)({
|
|
158
|
+
x: 0,
|
|
159
|
+
y: 0
|
|
160
|
+
}, {
|
|
161
|
+
x: 1,
|
|
162
|
+
y: 0
|
|
163
|
+
});
|
|
164
|
+
(0, _vitest.expect)(a).toBe(0);
|
|
165
|
+
});
|
|
166
|
+
(0, _vitest.it)("pointToRectDistance", () => {
|
|
167
|
+
const d = (0, _geometry.pointToRectDistance)({
|
|
168
|
+
x: -10,
|
|
169
|
+
y: 50
|
|
170
|
+
}, {
|
|
171
|
+
x: 0,
|
|
172
|
+
y: 0,
|
|
173
|
+
width: 100,
|
|
174
|
+
height: 100
|
|
175
|
+
});
|
|
176
|
+
(0, _vitest.expect)(d).toBe(10);
|
|
177
|
+
});
|
|
178
|
+
(0, _vitest.it)("viewportIntersectsBounds", () => {
|
|
179
|
+
(0, _vitest.expect)((0, _geometry.viewportIntersectsBounds)({
|
|
180
|
+
x: 0,
|
|
181
|
+
y: 0,
|
|
182
|
+
width: 800,
|
|
183
|
+
height: 600
|
|
184
|
+
}, {
|
|
185
|
+
x: 0,
|
|
186
|
+
y: 0,
|
|
187
|
+
width: 1e3,
|
|
188
|
+
height: 1e3
|
|
189
|
+
}, 1)).toBe(true);
|
|
190
|
+
});
|
|
191
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
isPointInRect,
|
|
4
|
+
rectIntersect,
|
|
5
|
+
getRectIntersection,
|
|
6
|
+
getBoundingBox,
|
|
7
|
+
getNodeBounds,
|
|
8
|
+
pointToLineDistance,
|
|
9
|
+
pointToPointDistance,
|
|
10
|
+
degToRad,
|
|
11
|
+
radToDeg,
|
|
12
|
+
getLineIntersection,
|
|
13
|
+
getAngle,
|
|
14
|
+
pointToRectDistance,
|
|
15
|
+
viewportIntersectsBounds
|
|
16
|
+
} from "../utils/geometry.mjs";
|
|
17
|
+
describe("flow/utils/geometry", () => {
|
|
18
|
+
it("isPointInRect", () => {
|
|
19
|
+
expect(isPointInRect({ x: 50, y: 50 }, { x: 0, y: 0, width: 100, height: 100 })).toBe(true);
|
|
20
|
+
expect(isPointInRect({ x: 150, y: 50 }, { x: 0, y: 0, width: 100, height: 100 })).toBe(false);
|
|
21
|
+
});
|
|
22
|
+
it("rectIntersect", () => {
|
|
23
|
+
expect(
|
|
24
|
+
rectIntersect({ x: 0, y: 0, width: 50, height: 50 }, { x: 25, y: 25, width: 50, height: 50 })
|
|
25
|
+
).toBe(true);
|
|
26
|
+
expect(
|
|
27
|
+
rectIntersect({ x: 0, y: 0, width: 10, height: 10 }, { x: 20, y: 20, width: 10, height: 10 })
|
|
28
|
+
).toBe(false);
|
|
29
|
+
});
|
|
30
|
+
it("getRectIntersection", () => {
|
|
31
|
+
const r = getRectIntersection(
|
|
32
|
+
{ x: 0, y: 0, width: 100, height: 100 },
|
|
33
|
+
{ x: 50, y: 50, width: 100, height: 100 }
|
|
34
|
+
);
|
|
35
|
+
expect(r).not.toBeNull();
|
|
36
|
+
expect(r.x).toBe(50);
|
|
37
|
+
expect(r.y).toBe(50);
|
|
38
|
+
expect(r.width).toBe(50);
|
|
39
|
+
expect(r.height).toBe(50);
|
|
40
|
+
});
|
|
41
|
+
it("getBoundingBox empty returns zeros", () => {
|
|
42
|
+
const box = getBoundingBox([]);
|
|
43
|
+
expect(box).toEqual({ x: 0, y: 0, width: 0, height: 0 });
|
|
44
|
+
});
|
|
45
|
+
it("getBoundingBox multiple points", () => {
|
|
46
|
+
const box = getBoundingBox([
|
|
47
|
+
{ x: 10, y: 20 },
|
|
48
|
+
{ x: 30, y: 5 }
|
|
49
|
+
]);
|
|
50
|
+
expect(box.x).toBe(10);
|
|
51
|
+
expect(box.y).toBe(5);
|
|
52
|
+
expect(box.width).toBe(20);
|
|
53
|
+
expect(box.height).toBe(15);
|
|
54
|
+
});
|
|
55
|
+
it("getNodeBounds", () => {
|
|
56
|
+
const nodes = [
|
|
57
|
+
{ position: { x: 0, y: 0 }, width: 50, height: 50 },
|
|
58
|
+
{ position: { x: 100, y: 100 }, width: 50, height: 50 }
|
|
59
|
+
];
|
|
60
|
+
const bounds = getNodeBounds(nodes);
|
|
61
|
+
expect(bounds.x).toBe(0);
|
|
62
|
+
expect(bounds.y).toBe(0);
|
|
63
|
+
expect(bounds.width).toBe(150);
|
|
64
|
+
expect(bounds.height).toBe(150);
|
|
65
|
+
});
|
|
66
|
+
it("pointToLineDistance", () => {
|
|
67
|
+
const d = pointToLineDistance({ x: 0, y: 0 }, { x: 10, y: 0 }, { x: 10, y: 10 });
|
|
68
|
+
expect(d).toBeGreaterThanOrEqual(0);
|
|
69
|
+
});
|
|
70
|
+
it("pointToPointDistance", () => {
|
|
71
|
+
expect(pointToPointDistance({ x: 0, y: 0 }, { x: 3, y: 4 })).toBe(5);
|
|
72
|
+
});
|
|
73
|
+
it("degToRad and radToDeg", () => {
|
|
74
|
+
expect(degToRad(180)).toBeCloseTo(Math.PI);
|
|
75
|
+
expect(radToDeg(Math.PI)).toBeCloseTo(180);
|
|
76
|
+
});
|
|
77
|
+
it("getLineIntersection", () => {
|
|
78
|
+
const p = getLineIntersection(
|
|
79
|
+
{ x: 0, y: 0 },
|
|
80
|
+
{ x: 10, y: 10 },
|
|
81
|
+
{ x: 0, y: 10 },
|
|
82
|
+
{ x: 10, y: 0 }
|
|
83
|
+
);
|
|
84
|
+
expect(p).not.toBeNull();
|
|
85
|
+
expect(typeof p.x).toBe("number");
|
|
86
|
+
expect(typeof p.y).toBe("number");
|
|
87
|
+
});
|
|
88
|
+
it("getAngle", () => {
|
|
89
|
+
const a = getAngle({ x: 0, y: 0 }, { x: 1, y: 0 });
|
|
90
|
+
expect(a).toBe(0);
|
|
91
|
+
});
|
|
92
|
+
it("pointToRectDistance", () => {
|
|
93
|
+
const d = pointToRectDistance({ x: -10, y: 50 }, { x: 0, y: 0, width: 100, height: 100 });
|
|
94
|
+
expect(d).toBe(10);
|
|
95
|
+
});
|
|
96
|
+
it("viewportIntersectsBounds", () => {
|
|
97
|
+
expect(
|
|
98
|
+
viewportIntersectsBounds(
|
|
99
|
+
{ x: 0, y: 0, width: 800, height: 600 },
|
|
100
|
+
{ x: 0, y: 0, width: 1e3, height: 1e3 },
|
|
101
|
+
1
|
|
102
|
+
)
|
|
103
|
+
).toBe(true);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _vitest = require("vitest");
|
|
4
|
+
var _graph = require("../utils/graph.cjs");
|
|
5
|
+
(0, _vitest.describe)("flow/utils/graph", () => {
|
|
6
|
+
(0, _vitest.it)("hasCycle should detect cycle", () => {
|
|
7
|
+
const edges = [{
|
|
8
|
+
source: "A",
|
|
9
|
+
target: "B"
|
|
10
|
+
}, {
|
|
11
|
+
source: "B",
|
|
12
|
+
target: "C"
|
|
13
|
+
}, {
|
|
14
|
+
source: "C",
|
|
15
|
+
target: "A"
|
|
16
|
+
}];
|
|
17
|
+
(0, _vitest.expect)((0, _graph.hasCycle)(edges, "A")).toBe(true);
|
|
18
|
+
});
|
|
19
|
+
(0, _vitest.it)("hasCycle should return false for DAG", () => {
|
|
20
|
+
const edges = [{
|
|
21
|
+
source: "A",
|
|
22
|
+
target: "B"
|
|
23
|
+
}, {
|
|
24
|
+
source: "B",
|
|
25
|
+
target: "C"
|
|
26
|
+
}];
|
|
27
|
+
(0, _vitest.expect)((0, _graph.hasCycle)(edges, "A")).toBe(false);
|
|
28
|
+
});
|
|
29
|
+
(0, _vitest.it)("topologicalSort should return order for DAG", () => {
|
|
30
|
+
const nodes = [{
|
|
31
|
+
id: "A"
|
|
32
|
+
}, {
|
|
33
|
+
id: "B"
|
|
34
|
+
}, {
|
|
35
|
+
id: "C"
|
|
36
|
+
}];
|
|
37
|
+
const edges = [{
|
|
38
|
+
source: "A",
|
|
39
|
+
target: "B"
|
|
40
|
+
}, {
|
|
41
|
+
source: "B",
|
|
42
|
+
target: "C"
|
|
43
|
+
}];
|
|
44
|
+
const order = (0, _graph.topologicalSort)(nodes, edges);
|
|
45
|
+
(0, _vitest.expect)(order).toHaveLength(3);
|
|
46
|
+
const ai = order.indexOf("A");
|
|
47
|
+
const bi = order.indexOf("B");
|
|
48
|
+
const ci = order.indexOf("C");
|
|
49
|
+
(0, _vitest.expect)(ai).toBeLessThan(bi);
|
|
50
|
+
(0, _vitest.expect)(bi).toBeLessThan(ci);
|
|
51
|
+
});
|
|
52
|
+
(0, _vitest.it)("findAllPaths should return paths between two nodes", () => {
|
|
53
|
+
const edges = [{
|
|
54
|
+
source: "1",
|
|
55
|
+
target: "2"
|
|
56
|
+
}, {
|
|
57
|
+
source: "1",
|
|
58
|
+
target: "3"
|
|
59
|
+
}, {
|
|
60
|
+
source: "2",
|
|
61
|
+
target: "4"
|
|
62
|
+
}, {
|
|
63
|
+
source: "3",
|
|
64
|
+
target: "4"
|
|
65
|
+
}];
|
|
66
|
+
const paths = (0, _graph.findAllPaths)(edges, "1", "4");
|
|
67
|
+
(0, _vitest.expect)(paths.length).toBeGreaterThanOrEqual(1);
|
|
68
|
+
(0, _vitest.expect)(paths.every(p => p[0] === "1" && p[p.length - 1] === "4")).toBe(true);
|
|
69
|
+
});
|
|
70
|
+
(0, _vitest.it)("findConnectedComponents should return components", () => {
|
|
71
|
+
const nodes = [{
|
|
72
|
+
id: "A"
|
|
73
|
+
}, {
|
|
74
|
+
id: "B"
|
|
75
|
+
}, {
|
|
76
|
+
id: "C"
|
|
77
|
+
}, {
|
|
78
|
+
id: "D"
|
|
79
|
+
}];
|
|
80
|
+
const edges = [{
|
|
81
|
+
source: "A",
|
|
82
|
+
target: "B"
|
|
83
|
+
}, {
|
|
84
|
+
source: "C",
|
|
85
|
+
target: "D"
|
|
86
|
+
}];
|
|
87
|
+
const components = (0, _graph.findConnectedComponents)(nodes, edges);
|
|
88
|
+
(0, _vitest.expect)(components).toHaveLength(2);
|
|
89
|
+
(0, _vitest.expect)(components.some(c => c.includes("A") && c.includes("B"))).toBe(true);
|
|
90
|
+
(0, _vitest.expect)(components.some(c => c.includes("C") && c.includes("D"))).toBe(true);
|
|
91
|
+
});
|
|
92
|
+
(0, _vitest.it)("bfs should traverse in breadth order", () => {
|
|
93
|
+
const adj = /* @__PURE__ */new Map();
|
|
94
|
+
adj.set("1", ["2", "3"]);
|
|
95
|
+
adj.set("2", ["4"]);
|
|
96
|
+
adj.set("3", []);
|
|
97
|
+
adj.set("4", []);
|
|
98
|
+
const result = (0, _graph.bfs)(adj, "1");
|
|
99
|
+
(0, _vitest.expect)(result).toContain("1");
|
|
100
|
+
(0, _vitest.expect)(result).toContain("2");
|
|
101
|
+
(0, _vitest.expect)(result).toContain("3");
|
|
102
|
+
(0, _vitest.expect)(result).toContain("4");
|
|
103
|
+
(0, _vitest.expect)(result[0]).toBe("1");
|
|
104
|
+
});
|
|
105
|
+
(0, _vitest.it)("dfs should traverse in depth order", () => {
|
|
106
|
+
const adj = /* @__PURE__ */new Map();
|
|
107
|
+
adj.set("1", ["2", "3"]);
|
|
108
|
+
adj.set("2", ["4"]);
|
|
109
|
+
adj.set("3", []);
|
|
110
|
+
adj.set("4", []);
|
|
111
|
+
const result = (0, _graph.dfs)(adj, "1");
|
|
112
|
+
(0, _vitest.expect)(result).toHaveLength(4);
|
|
113
|
+
(0, _vitest.expect)(result[0]).toBe("1");
|
|
114
|
+
});
|
|
115
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
hasCycle,
|
|
4
|
+
topologicalSort,
|
|
5
|
+
findAllPaths,
|
|
6
|
+
findConnectedComponents,
|
|
7
|
+
bfs,
|
|
8
|
+
dfs
|
|
9
|
+
} from "../utils/graph.mjs";
|
|
10
|
+
describe("flow/utils/graph", () => {
|
|
11
|
+
it("hasCycle should detect cycle", () => {
|
|
12
|
+
const edges = [
|
|
13
|
+
{ source: "A", target: "B" },
|
|
14
|
+
{ source: "B", target: "C" },
|
|
15
|
+
{ source: "C", target: "A" }
|
|
16
|
+
];
|
|
17
|
+
expect(hasCycle(edges, "A")).toBe(true);
|
|
18
|
+
});
|
|
19
|
+
it("hasCycle should return false for DAG", () => {
|
|
20
|
+
const edges = [
|
|
21
|
+
{ source: "A", target: "B" },
|
|
22
|
+
{ source: "B", target: "C" }
|
|
23
|
+
];
|
|
24
|
+
expect(hasCycle(edges, "A")).toBe(false);
|
|
25
|
+
});
|
|
26
|
+
it("topologicalSort should return order for DAG", () => {
|
|
27
|
+
const nodes = [{ id: "A" }, { id: "B" }, { id: "C" }];
|
|
28
|
+
const edges = [
|
|
29
|
+
{ source: "A", target: "B" },
|
|
30
|
+
{ source: "B", target: "C" }
|
|
31
|
+
];
|
|
32
|
+
const order = topologicalSort(nodes, edges);
|
|
33
|
+
expect(order).toHaveLength(3);
|
|
34
|
+
const ai = order.indexOf("A");
|
|
35
|
+
const bi = order.indexOf("B");
|
|
36
|
+
const ci = order.indexOf("C");
|
|
37
|
+
expect(ai).toBeLessThan(bi);
|
|
38
|
+
expect(bi).toBeLessThan(ci);
|
|
39
|
+
});
|
|
40
|
+
it("findAllPaths should return paths between two nodes", () => {
|
|
41
|
+
const edges = [
|
|
42
|
+
{ source: "1", target: "2" },
|
|
43
|
+
{ source: "1", target: "3" },
|
|
44
|
+
{ source: "2", target: "4" },
|
|
45
|
+
{ source: "3", target: "4" }
|
|
46
|
+
];
|
|
47
|
+
const paths = findAllPaths(edges, "1", "4");
|
|
48
|
+
expect(paths.length).toBeGreaterThanOrEqual(1);
|
|
49
|
+
expect(paths.every((p) => p[0] === "1" && p[p.length - 1] === "4")).toBe(true);
|
|
50
|
+
});
|
|
51
|
+
it("findConnectedComponents should return components", () => {
|
|
52
|
+
const nodes = [{ id: "A" }, { id: "B" }, { id: "C" }, { id: "D" }];
|
|
53
|
+
const edges = [
|
|
54
|
+
{ source: "A", target: "B" },
|
|
55
|
+
{ source: "C", target: "D" }
|
|
56
|
+
];
|
|
57
|
+
const components = findConnectedComponents(nodes, edges);
|
|
58
|
+
expect(components).toHaveLength(2);
|
|
59
|
+
expect(components.some((c) => c.includes("A") && c.includes("B"))).toBe(true);
|
|
60
|
+
expect(components.some((c) => c.includes("C") && c.includes("D"))).toBe(true);
|
|
61
|
+
});
|
|
62
|
+
it("bfs should traverse in breadth order", () => {
|
|
63
|
+
const adj = /* @__PURE__ */ new Map();
|
|
64
|
+
adj.set("1", ["2", "3"]);
|
|
65
|
+
adj.set("2", ["4"]);
|
|
66
|
+
adj.set("3", []);
|
|
67
|
+
adj.set("4", []);
|
|
68
|
+
const result = bfs(adj, "1");
|
|
69
|
+
expect(result).toContain("1");
|
|
70
|
+
expect(result).toContain("2");
|
|
71
|
+
expect(result).toContain("3");
|
|
72
|
+
expect(result).toContain("4");
|
|
73
|
+
expect(result[0]).toBe("1");
|
|
74
|
+
});
|
|
75
|
+
it("dfs should traverse in depth order", () => {
|
|
76
|
+
const adj = /* @__PURE__ */ new Map();
|
|
77
|
+
adj.set("1", ["2", "3"]);
|
|
78
|
+
adj.set("2", ["4"]);
|
|
79
|
+
adj.set("3", []);
|
|
80
|
+
adj.set("4", []);
|
|
81
|
+
const result = dfs(adj, "1");
|
|
82
|
+
expect(result).toHaveLength(4);
|
|
83
|
+
expect(result[0]).toBe("1");
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _vitest = require("vitest");
|
|
4
|
+
var _vue = require("vue");
|
|
5
|
+
var _history = require("../plugins/plugins/history.cjs");
|
|
6
|
+
function createMockFlow() {
|
|
7
|
+
const nodes = (0, _vue.ref)([{
|
|
8
|
+
id: "1",
|
|
9
|
+
type: "default",
|
|
10
|
+
position: {
|
|
11
|
+
x: 0,
|
|
12
|
+
y: 0
|
|
13
|
+
},
|
|
14
|
+
data: {
|
|
15
|
+
label: "A"
|
|
16
|
+
}
|
|
17
|
+
}]);
|
|
18
|
+
const edges = (0, _vue.ref)([]);
|
|
19
|
+
const eventHandlers = {};
|
|
20
|
+
const flow = {
|
|
21
|
+
nodes,
|
|
22
|
+
edges,
|
|
23
|
+
viewport: (0, _vue.ref)({
|
|
24
|
+
x: 0,
|
|
25
|
+
y: 0,
|
|
26
|
+
zoom: 1
|
|
27
|
+
}),
|
|
28
|
+
addNode: _vitest.vi.fn(),
|
|
29
|
+
removeNode: _vitest.vi.fn(),
|
|
30
|
+
updateNode: _vitest.vi.fn(),
|
|
31
|
+
getNode: _vitest.vi.fn(),
|
|
32
|
+
addEdge: _vitest.vi.fn(),
|
|
33
|
+
removeEdge: _vitest.vi.fn(),
|
|
34
|
+
updateEdge: _vitest.vi.fn(),
|
|
35
|
+
getEdge: _vitest.vi.fn(),
|
|
36
|
+
setViewport: _vitest.vi.fn(),
|
|
37
|
+
fitView: _vitest.vi.fn(),
|
|
38
|
+
zoomIn: _vitest.vi.fn(),
|
|
39
|
+
zoomOut: _vitest.vi.fn(),
|
|
40
|
+
centerView: _vitest.vi.fn(),
|
|
41
|
+
selectNode: _vitest.vi.fn(),
|
|
42
|
+
selectEdge: _vitest.vi.fn(),
|
|
43
|
+
clearSelection: _vitest.vi.fn(),
|
|
44
|
+
getNodes: () => nodes.value,
|
|
45
|
+
getEdges: () => edges.value,
|
|
46
|
+
getViewport: () => ({
|
|
47
|
+
x: 0,
|
|
48
|
+
y: 0,
|
|
49
|
+
zoom: 1
|
|
50
|
+
}),
|
|
51
|
+
screenToCanvas: _vitest.vi.fn().mockReturnValue({
|
|
52
|
+
x: 0,
|
|
53
|
+
y: 0
|
|
54
|
+
}),
|
|
55
|
+
canvasToScreen: _vitest.vi.fn().mockReturnValue({
|
|
56
|
+
x: 0,
|
|
57
|
+
y: 0
|
|
58
|
+
}),
|
|
59
|
+
on: _vitest.vi.fn((event, handler) => {
|
|
60
|
+
if (!eventHandlers[event]) eventHandlers[event] = [];
|
|
61
|
+
eventHandlers[event].push(handler);
|
|
62
|
+
}),
|
|
63
|
+
off: _vitest.vi.fn(),
|
|
64
|
+
emit: _vitest.vi.fn(),
|
|
65
|
+
isValidConnection: _vitest.vi.fn().mockReturnValue(true),
|
|
66
|
+
$el: void 0,
|
|
67
|
+
draggingNodeId: (0, _vue.ref)(null),
|
|
68
|
+
draggingPosition: (0, _vue.ref)(null),
|
|
69
|
+
usePlugin: _vitest.vi.fn(),
|
|
70
|
+
removePlugin: _vitest.vi.fn()
|
|
71
|
+
};
|
|
72
|
+
return flow;
|
|
73
|
+
}
|
|
74
|
+
(0, _vitest.describe)("createHistoryPlugin", () => {
|
|
75
|
+
(0, _vitest.it)("should be created with correct metadata", () => {
|
|
76
|
+
const plugin = (0, _history.createHistoryPlugin)();
|
|
77
|
+
(0, _vitest.expect)(plugin.id).toBe("history");
|
|
78
|
+
(0, _vitest.expect)(plugin.name).toBe("History");
|
|
79
|
+
(0, _vitest.expect)(plugin.version).toBe("1.0.0");
|
|
80
|
+
});
|
|
81
|
+
(0, _vitest.it)("should install and expose undo/redo on flow instance", () => {
|
|
82
|
+
const flow = createMockFlow();
|
|
83
|
+
const plugin = (0, _history.createHistoryPlugin)();
|
|
84
|
+
plugin.install(flow);
|
|
85
|
+
(0, _vitest.expect)(typeof flow.undo).toBe("function");
|
|
86
|
+
(0, _vitest.expect)(typeof flow.redo).toBe("function");
|
|
87
|
+
(0, _vitest.expect)(typeof flow.saveSnapshot).toBe("function");
|
|
88
|
+
(0, _vitest.expect)(typeof flow.clearHistory).toBe("function");
|
|
89
|
+
(0, _vitest.expect)(typeof flow.jumpToStep).toBe("function");
|
|
90
|
+
(0, _vitest.expect)(typeof flow.getHistory).toBe("function");
|
|
91
|
+
});
|
|
92
|
+
(0, _vitest.it)("should save initial snapshot on install", () => {
|
|
93
|
+
const flow = createMockFlow();
|
|
94
|
+
const plugin = (0, _history.createHistoryPlugin)();
|
|
95
|
+
plugin.install(flow);
|
|
96
|
+
const history = plugin.getHistory();
|
|
97
|
+
(0, _vitest.expect)(history.length).toBe(1);
|
|
98
|
+
(0, _vitest.expect)(history[0].description).toBe("initial");
|
|
99
|
+
});
|
|
100
|
+
(0, _vitest.it)("should correctly undo and redo node position changes", () => {
|
|
101
|
+
const flow = createMockFlow();
|
|
102
|
+
const plugin = (0, _history.createHistoryPlugin)();
|
|
103
|
+
plugin.install(flow);
|
|
104
|
+
flow.nodes.value[0].position.x = 100;
|
|
105
|
+
plugin.saveSnapshot("move node");
|
|
106
|
+
(0, _vitest.expect)(plugin.canUndo.value).toBe(true);
|
|
107
|
+
(0, _vitest.expect)(plugin.canRedo.value).toBe(false);
|
|
108
|
+
plugin.undo();
|
|
109
|
+
(0, _vitest.expect)(flow.nodes.value[0].position.x).toBe(0);
|
|
110
|
+
(0, _vitest.expect)(plugin.canRedo.value).toBe(true);
|
|
111
|
+
plugin.redo();
|
|
112
|
+
(0, _vitest.expect)(flow.nodes.value[0].position.x).toBe(100);
|
|
113
|
+
});
|
|
114
|
+
(0, _vitest.it)("should clear redo stack when new snapshot is pushed after undo", () => {
|
|
115
|
+
const flow = createMockFlow();
|
|
116
|
+
const plugin = (0, _history.createHistoryPlugin)();
|
|
117
|
+
plugin.install(flow);
|
|
118
|
+
flow.nodes.value[0].position.x = 50;
|
|
119
|
+
plugin.saveSnapshot("step1");
|
|
120
|
+
flow.nodes.value[0].position.x = 100;
|
|
121
|
+
plugin.saveSnapshot("step2");
|
|
122
|
+
plugin.undo();
|
|
123
|
+
(0, _vitest.expect)(flow.nodes.value[0].position.x).toBe(50);
|
|
124
|
+
(0, _vitest.expect)(plugin.canRedo.value).toBe(true);
|
|
125
|
+
flow.nodes.value[0].position.x = 200;
|
|
126
|
+
plugin.saveSnapshot("step3");
|
|
127
|
+
(0, _vitest.expect)(plugin.canRedo.value).toBe(false);
|
|
128
|
+
});
|
|
129
|
+
(0, _vitest.it)("should respect maxHistory limit", () => {
|
|
130
|
+
const flow = createMockFlow();
|
|
131
|
+
const plugin = (0, _history.createHistoryPlugin)({
|
|
132
|
+
maxHistory: 3
|
|
133
|
+
});
|
|
134
|
+
plugin.install(flow);
|
|
135
|
+
for (let i = 1; i <= 5; i++) {
|
|
136
|
+
flow.nodes.value[0].position.x = i * 10;
|
|
137
|
+
plugin.saveSnapshot(`step${i}`);
|
|
138
|
+
}
|
|
139
|
+
(0, _vitest.expect)(plugin.getHistory().length).toBe(3);
|
|
140
|
+
});
|
|
141
|
+
(0, _vitest.it)("should clear history", () => {
|
|
142
|
+
const flow = createMockFlow();
|
|
143
|
+
const plugin = (0, _history.createHistoryPlugin)();
|
|
144
|
+
plugin.install(flow);
|
|
145
|
+
flow.nodes.value[0].position.x = 100;
|
|
146
|
+
plugin.saveSnapshot("move");
|
|
147
|
+
plugin.clearHistory();
|
|
148
|
+
(0, _vitest.expect)(plugin.getHistory().length).toBe(0);
|
|
149
|
+
(0, _vitest.expect)(plugin.canUndo.value).toBe(false);
|
|
150
|
+
(0, _vitest.expect)(plugin.canRedo.value).toBe(false);
|
|
151
|
+
});
|
|
152
|
+
(0, _vitest.it)("should call onHistoryChange callback", () => {
|
|
153
|
+
const onHistoryChange = _vitest.vi.fn();
|
|
154
|
+
const flow = createMockFlow();
|
|
155
|
+
const plugin = (0, _history.createHistoryPlugin)({
|
|
156
|
+
onHistoryChange
|
|
157
|
+
});
|
|
158
|
+
plugin.install(flow);
|
|
159
|
+
(0, _vitest.expect)(onHistoryChange).toHaveBeenCalled();
|
|
160
|
+
});
|
|
161
|
+
(0, _vitest.it)("should jump to a specific step", () => {
|
|
162
|
+
const flow = createMockFlow();
|
|
163
|
+
const plugin = (0, _history.createHistoryPlugin)();
|
|
164
|
+
plugin.install(flow);
|
|
165
|
+
flow.nodes.value[0].position.x = 100;
|
|
166
|
+
plugin.saveSnapshot("step1");
|
|
167
|
+
flow.nodes.value[0].position.x = 200;
|
|
168
|
+
plugin.saveSnapshot("step2");
|
|
169
|
+
plugin.jumpToStep(0);
|
|
170
|
+
(0, _vitest.expect)(flow.nodes.value[0].position.x).toBe(0);
|
|
171
|
+
});
|
|
172
|
+
(0, _vitest.it)("should not undo below 0 or redo beyond end", () => {
|
|
173
|
+
const flow = createMockFlow();
|
|
174
|
+
const plugin = (0, _history.createHistoryPlugin)();
|
|
175
|
+
plugin.install(flow);
|
|
176
|
+
(0, _vitest.expect)(plugin.canUndo.value).toBe(false);
|
|
177
|
+
plugin.undo();
|
|
178
|
+
(0, _vitest.expect)(plugin.canRedo.value).toBe(false);
|
|
179
|
+
plugin.redo();
|
|
180
|
+
});
|
|
181
|
+
(0, _vitest.it)("should destroy and cleanup", () => {
|
|
182
|
+
const removeEventListener = _vitest.vi.spyOn(window, "removeEventListener");
|
|
183
|
+
const flow = createMockFlow();
|
|
184
|
+
const plugin = (0, _history.createHistoryPlugin)({
|
|
185
|
+
enableKeyboard: true
|
|
186
|
+
});
|
|
187
|
+
plugin.install(flow);
|
|
188
|
+
plugin.destroy?.();
|
|
189
|
+
(0, _vitest.expect)(removeEventListener).toHaveBeenCalledWith("keydown", _vitest.expect.any(Function));
|
|
190
|
+
});
|
|
191
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|