@yh-ui/flow 1.0.26 → 1.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/package.json +6 -6
  2. package/dist/__tests__/ai-workflow.ssr.test.cjs +0 -352
  3. package/dist/__tests__/ai-workflow.ssr.test.d.ts +0 -1
  4. package/dist/__tests__/ai-workflow.ssr.test.mjs +0 -283
  5. package/dist/__tests__/ai-workflow.test.cjs +0 -109
  6. package/dist/__tests__/ai-workflow.test.d.ts +0 -1
  7. package/dist/__tests__/ai-workflow.test.mjs +0 -112
  8. package/dist/__tests__/bpmn-engine.test.cjs +0 -357
  9. package/dist/__tests__/bpmn-engine.test.d.ts +0 -1
  10. package/dist/__tests__/bpmn-engine.test.mjs +0 -406
  11. package/dist/__tests__/bpmn-utils.test.cjs +0 -268
  12. package/dist/__tests__/bpmn-utils.test.d.ts +0 -1
  13. package/dist/__tests__/bpmn-utils.test.mjs +0 -227
  14. package/dist/__tests__/bpmn-xml.test.cjs +0 -150
  15. package/dist/__tests__/bpmn-xml.test.d.ts +0 -1
  16. package/dist/__tests__/bpmn-xml.test.mjs +0 -112
  17. package/dist/__tests__/bpmn.ssr.test.cjs +0 -278
  18. package/dist/__tests__/bpmn.ssr.test.d.ts +0 -1
  19. package/dist/__tests__/bpmn.ssr.test.mjs +0 -237
  20. package/dist/__tests__/bpmn.test.cjs +0 -103
  21. package/dist/__tests__/bpmn.test.d.ts +0 -1
  22. package/dist/__tests__/bpmn.test.mjs +0 -106
  23. package/dist/__tests__/collaboration.test.cjs +0 -487
  24. package/dist/__tests__/collaboration.test.d.ts +0 -1
  25. package/dist/__tests__/collaboration.test.mjs +0 -424
  26. package/dist/__tests__/custom-types.test.cjs +0 -300
  27. package/dist/__tests__/custom-types.test.d.ts +0 -1
  28. package/dist/__tests__/custom-types.test.mjs +0 -248
  29. package/dist/__tests__/edge-types.test.cjs +0 -275
  30. package/dist/__tests__/edge-types.test.d.ts +0 -1
  31. package/dist/__tests__/edge-types.test.mjs +0 -234
  32. package/dist/__tests__/edge-utils.test.cjs +0 -375
  33. package/dist/__tests__/edge-utils.test.d.ts +0 -1
  34. package/dist/__tests__/edge-utils.test.mjs +0 -376
  35. package/dist/__tests__/edge.test.cjs +0 -56
  36. package/dist/__tests__/edge.test.d.ts +0 -1
  37. package/dist/__tests__/edge.test.mjs +0 -69
  38. package/dist/__tests__/event-bus.test.cjs +0 -80
  39. package/dist/__tests__/event-bus.test.d.ts +0 -1
  40. package/dist/__tests__/event-bus.test.mjs +0 -51
  41. package/dist/__tests__/events-types.test.cjs +0 -184
  42. package/dist/__tests__/events-types.test.d.ts +0 -1
  43. package/dist/__tests__/events-types.test.mjs +0 -184
  44. package/dist/__tests__/export-image-plugin.test.cjs +0 -142
  45. package/dist/__tests__/export-image-plugin.test.d.ts +0 -1
  46. package/dist/__tests__/export-image-plugin.test.mjs +0 -118
  47. package/dist/__tests__/export.test.cjs +0 -237
  48. package/dist/__tests__/export.test.d.ts +0 -1
  49. package/dist/__tests__/export.test.mjs +0 -171
  50. package/dist/__tests__/flow-context.test.cjs +0 -16
  51. package/dist/__tests__/flow-context.test.d.ts +0 -1
  52. package/dist/__tests__/flow-context.test.mjs +0 -16
  53. package/dist/__tests__/flow-props.test.cjs +0 -94
  54. package/dist/__tests__/flow-props.test.d.ts +0 -1
  55. package/dist/__tests__/flow-props.test.mjs +0 -92
  56. package/dist/__tests__/flow.ssr.test.cjs +0 -156
  57. package/dist/__tests__/flow.ssr.test.d.ts +0 -1
  58. package/dist/__tests__/flow.ssr.test.mjs +0 -112
  59. package/dist/__tests__/geometry.test.cjs +0 -191
  60. package/dist/__tests__/geometry.test.d.ts +0 -1
  61. package/dist/__tests__/geometry.test.mjs +0 -105
  62. package/dist/__tests__/graph.test.cjs +0 -115
  63. package/dist/__tests__/graph.test.d.ts +0 -1
  64. package/dist/__tests__/graph.test.mjs +0 -85
  65. package/dist/__tests__/history-plugin.test.cjs +0 -191
  66. package/dist/__tests__/history-plugin.test.d.ts +0 -1
  67. package/dist/__tests__/history-plugin.test.mjs +0 -161
  68. package/dist/__tests__/history.test.cjs +0 -81
  69. package/dist/__tests__/history.test.d.ts +0 -1
  70. package/dist/__tests__/history.test.mjs +0 -43
  71. package/dist/__tests__/layout-plugin.test.cjs +0 -233
  72. package/dist/__tests__/layout-plugin.test.d.ts +0 -1
  73. package/dist/__tests__/layout-plugin.test.mjs +0 -215
  74. package/dist/__tests__/layout.test.cjs +0 -213
  75. package/dist/__tests__/layout.test.d.ts +0 -1
  76. package/dist/__tests__/layout.test.mjs +0 -170
  77. package/dist/__tests__/node-edit-panel.ssr.test.cjs +0 -168
  78. package/dist/__tests__/node-edit-panel.ssr.test.d.ts +0 -1
  79. package/dist/__tests__/node-edit-panel.ssr.test.mjs +0 -118
  80. package/dist/__tests__/node-group-plugin.test.cjs +0 -235
  81. package/dist/__tests__/node-group-plugin.test.d.ts +0 -1
  82. package/dist/__tests__/node-group-plugin.test.mjs +0 -187
  83. package/dist/__tests__/node-handles.test.cjs +0 -340
  84. package/dist/__tests__/node-handles.test.d.ts +0 -1
  85. package/dist/__tests__/node-handles.test.mjs +0 -230
  86. package/dist/__tests__/node-types.test.cjs +0 -368
  87. package/dist/__tests__/node-types.test.d.ts +0 -1
  88. package/dist/__tests__/node-types.test.mjs +0 -292
  89. package/dist/__tests__/performance.test.cjs +0 -313
  90. package/dist/__tests__/performance.test.d.ts +0 -1
  91. package/dist/__tests__/performance.test.mjs +0 -218
  92. package/dist/__tests__/plugin-advanced.test.cjs +0 -301
  93. package/dist/__tests__/plugin-advanced.test.d.ts +0 -1
  94. package/dist/__tests__/plugin-advanced.test.mjs +0 -225
  95. package/dist/__tests__/plugin.test.cjs +0 -151
  96. package/dist/__tests__/plugin.test.d.ts +0 -1
  97. package/dist/__tests__/plugin.test.mjs +0 -116
  98. package/dist/__tests__/plugins.test.cjs +0 -412
  99. package/dist/__tests__/plugins.test.d.ts +0 -1
  100. package/dist/__tests__/plugins.test.mjs +0 -402
  101. package/dist/__tests__/screenshot-capture.test.cjs +0 -183
  102. package/dist/__tests__/screenshot-capture.test.d.ts +0 -1
  103. package/dist/__tests__/screenshot-capture.test.mjs +0 -124
  104. package/dist/__tests__/screenshot.test.cjs +0 -74
  105. package/dist/__tests__/screenshot.test.d.ts +0 -1
  106. package/dist/__tests__/screenshot.test.mjs +0 -69
  107. package/dist/__tests__/theme.test.cjs +0 -185
  108. package/dist/__tests__/theme.test.d.ts +0 -1
  109. package/dist/__tests__/theme.test.mjs +0 -191
  110. package/dist/__tests__/transform.test.cjs +0 -384
  111. package/dist/__tests__/transform.test.d.ts +0 -1
  112. package/dist/__tests__/transform.test.mjs +0 -239
  113. package/dist/__tests__/useAlignment.test.cjs +0 -128
  114. package/dist/__tests__/useAlignment.test.d.ts +0 -1
  115. package/dist/__tests__/useAlignment.test.mjs +0 -72
  116. package/dist/__tests__/useEdges.test.cjs +0 -117
  117. package/dist/__tests__/useEdges.test.d.ts +0 -1
  118. package/dist/__tests__/useEdges.test.mjs +0 -80
  119. package/dist/__tests__/useKeyboard.test.cjs +0 -88
  120. package/dist/__tests__/useKeyboard.test.d.ts +0 -1
  121. package/dist/__tests__/useKeyboard.test.mjs +0 -56
  122. package/dist/__tests__/useNodeDistribution.test.cjs +0 -643
  123. package/dist/__tests__/useNodeDistribution.test.d.ts +0 -1
  124. package/dist/__tests__/useNodeDistribution.test.mjs +0 -297
  125. package/dist/__tests__/useNodes.test.cjs +0 -150
  126. package/dist/__tests__/useNodes.test.d.ts +0 -1
  127. package/dist/__tests__/useNodes.test.mjs +0 -80
  128. package/dist/__tests__/useSelection.test.cjs +0 -112
  129. package/dist/__tests__/useSelection.test.d.ts +0 -1
  130. package/dist/__tests__/useSelection.test.mjs +0 -76
  131. package/dist/__tests__/useViewport.test.cjs +0 -171
  132. package/dist/__tests__/useViewport.test.d.ts +0 -1
  133. package/dist/__tests__/useViewport.test.mjs +0 -82
  134. package/dist/__tests__/utils/ssr.cjs +0 -124
  135. package/dist/__tests__/utils/ssr.d.ts +0 -33
  136. package/dist/__tests__/utils/ssr.mjs +0 -129
  137. package/dist/__tests__/validation.test.cjs +0 -95
  138. package/dist/__tests__/validation.test.d.ts +0 -1
  139. package/dist/__tests__/validation.test.mjs +0 -36
  140. package/dist/__tests__/viewport-types.test.cjs +0 -324
  141. package/dist/__tests__/viewport-types.test.d.ts +0 -1
  142. package/dist/__tests__/viewport-types.test.mjs +0 -207
@@ -1,95 +0,0 @@
1
- "use strict";
2
-
3
- var _vitest = require("vitest");
4
- var _validation = require("../utils/validation.cjs");
5
- (0, _vitest.describe)("flow/utils/validation", () => {
6
- const nodeA = {
7
- id: "A",
8
- type: "default",
9
- position: {
10
- x: 0,
11
- y: 0
12
- },
13
- data: {}
14
- };
15
- const nodeB = {
16
- id: "B",
17
- type: "default",
18
- position: {
19
- x: 0,
20
- y: 0
21
- },
22
- data: {}
23
- };
24
- (0, _vitest.it)("isValidConnection should fail when source/target missing", () => {
25
- (0, _vitest.expect)((0, _validation.isValidConnection)(void 0, nodeB, {
26
- source: "A",
27
- target: "B"
28
- }).isValid).toBe(false);
29
- (0, _vitest.expect)((0, _validation.isValidConnection)(nodeA, void 0, {
30
- source: "A",
31
- target: "B"
32
- }).isValid).toBe(false);
33
- });
34
- (0, _vitest.it)("isValidConnection should reject self connection", () => {
35
- const r = (0, _validation.isValidConnection)(nodeA, nodeA, {
36
- source: "A",
37
- target: "A"
38
- });
39
- (0, _vitest.expect)(r.isValid).toBe(false);
40
- });
41
- (0, _vitest.it)("createConnectionValidator should allow when no rules", () => {
42
- const v = (0, _validation.createConnectionValidator)();
43
- (0, _vitest.expect)(v({
44
- source: "a",
45
- target: "b"
46
- })).toBe(true);
47
- });
48
- (0, _vitest.it)("createConnectionValidator should match by exact id / wildcard", () => {
49
- const v = (0, _validation.createConnectionValidator)([{
50
- source: "A",
51
- target: "*"
52
- }]);
53
- (0, _vitest.expect)(v({
54
- source: "A",
55
- target: "B"
56
- })).toBe(true);
57
- (0, _vitest.expect)(v({
58
- source: "X",
59
- target: "B"
60
- })).toBe(false);
61
- });
62
- (0, _vitest.it)("createConnectionValidator should match by regex string", () => {
63
- const v = (0, _validation.createConnectionValidator)([{
64
- source: "^node-\\d+$",
65
- target: "^node-\\d+$"
66
- }]);
67
- (0, _vitest.expect)(v({
68
- source: "node-1",
69
- target: "node-2"
70
- })).toBe(true);
71
- (0, _vitest.expect)(v({
72
- source: "A",
73
- target: "node-2"
74
- })).toBe(false);
75
- });
76
- (0, _vitest.it)("detectCycles should detect cycles after adding edge", () => {
77
- const edges = [{
78
- id: "e1",
79
- source: "A",
80
- target: "B"
81
- }, {
82
- id: "e2",
83
- source: "B",
84
- target: "C"
85
- }];
86
- (0, _vitest.expect)((0, _validation.detectCycles)(edges, {
87
- source: "C",
88
- target: "A"
89
- })).toBe(true);
90
- (0, _vitest.expect)((0, _validation.detectCycles)(edges, {
91
- source: "C",
92
- target: "D"
93
- })).toBe(false);
94
- });
95
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,36 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { createConnectionValidator, detectCycles, isValidConnection } from "../utils/validation.mjs";
3
- describe("flow/utils/validation", () => {
4
- const nodeA = { id: "A", type: "default", position: { x: 0, y: 0 }, data: {} };
5
- const nodeB = { id: "B", type: "default", position: { x: 0, y: 0 }, data: {} };
6
- it("isValidConnection should fail when source/target missing", () => {
7
- expect(isValidConnection(void 0, nodeB, { source: "A", target: "B" }).isValid).toBe(false);
8
- expect(isValidConnection(nodeA, void 0, { source: "A", target: "B" }).isValid).toBe(false);
9
- });
10
- it("isValidConnection should reject self connection", () => {
11
- const r = isValidConnection(nodeA, nodeA, { source: "A", target: "A" });
12
- expect(r.isValid).toBe(false);
13
- });
14
- it("createConnectionValidator should allow when no rules", () => {
15
- const v = createConnectionValidator();
16
- expect(v({ source: "a", target: "b" })).toBe(true);
17
- });
18
- it("createConnectionValidator should match by exact id / wildcard", () => {
19
- const v = createConnectionValidator([{ source: "A", target: "*" }]);
20
- expect(v({ source: "A", target: "B" })).toBe(true);
21
- expect(v({ source: "X", target: "B" })).toBe(false);
22
- });
23
- it("createConnectionValidator should match by regex string", () => {
24
- const v = createConnectionValidator([{ source: "^node-\\d+$", target: "^node-\\d+$" }]);
25
- expect(v({ source: "node-1", target: "node-2" })).toBe(true);
26
- expect(v({ source: "A", target: "node-2" })).toBe(false);
27
- });
28
- it("detectCycles should detect cycles after adding edge", () => {
29
- const edges = [
30
- { id: "e1", source: "A", target: "B" },
31
- { id: "e2", source: "B", target: "C" }
32
- ];
33
- expect(detectCycles(edges, { source: "C", target: "A" })).toBe(true);
34
- expect(detectCycles(edges, { source: "C", target: "D" })).toBe(false);
35
- });
36
- });
@@ -1,324 +0,0 @@
1
- "use strict";
2
-
3
- var _vitest = require("vitest");
4
- var _viewport = require("../types/viewport.cjs");
5
- (0, _vitest.describe)("flow/types/viewport", () => {
6
- (0, _vitest.describe)("ViewportTransform", () => {
7
- (0, _vitest.it)("should define viewport with x, y, zoom", () => {
8
- const transform = {
9
- x: 100,
10
- y: 50,
11
- zoom: 1.5
12
- };
13
- (0, _vitest.expect)(transform.x).toBe(100);
14
- (0, _vitest.expect)(transform.y).toBe(50);
15
- (0, _vitest.expect)(transform.zoom).toBe(1.5);
16
- });
17
- (0, _vitest.it)("should allow negative coordinates", () => {
18
- const transform = {
19
- x: -100,
20
- y: -50,
21
- zoom: 0.5
22
- };
23
- (0, _vitest.expect)(transform.x).toBe(-100);
24
- (0, _vitest.expect)(transform.y).toBe(-50);
25
- });
26
- (0, _vitest.it)("should allow zoom less than 1", () => {
27
- const transform = {
28
- x: 0,
29
- y: 0,
30
- zoom: 0.1
31
- };
32
- (0, _vitest.expect)(transform.zoom).toBe(0.1);
33
- });
34
- (0, _vitest.it)("should allow zoom greater than 1", () => {
35
- const transform = {
36
- x: 0,
37
- y: 0,
38
- zoom: 5
39
- };
40
- (0, _vitest.expect)(transform.zoom).toBe(5);
41
- });
42
- });
43
- (0, _vitest.describe)("ViewportOptions", () => {
44
- (0, _vitest.it)("should define full viewport options", () => {
45
- const options = {
46
- minZoom: 0.1,
47
- maxZoom: 5,
48
- translateExtent: [[0, 0], [1e3, 1e3]],
49
- zoomStep: 0.1,
50
- panZoomSpeed: 1,
51
- zoomInMultiplier: 1.2,
52
- zoomOutMultiplier: 0.8,
53
- panning: true,
54
- zooming: true,
55
- zoomOnScroll: true,
56
- zoomOnPinch: true,
57
- panOnScroll: true,
58
- panOnDrag: true,
59
- fitViewOnInit: true,
60
- fitViewOnInitOptions: {
61
- padding: 0.2
62
- }
63
- };
64
- (0, _vitest.expect)(options.minZoom).toBe(0.1);
65
- (0, _vitest.expect)(options.maxZoom).toBe(5);
66
- (0, _vitest.expect)(options.fitViewOnInit).toBe(true);
67
- });
68
- (0, _vitest.it)("should allow partial options", () => {
69
- const options = {
70
- minZoom: 0.2,
71
- maxZoom: 3
72
- };
73
- (0, _vitest.expect)(options.minZoom).toBe(0.2);
74
- (0, _vitest.expect)(options.maxZoom).toBe(3);
75
- });
76
- });
77
- (0, _vitest.describe)("FitViewOptions", () => {
78
- (0, _vitest.it)("should define fit view options", () => {
79
- const options = {
80
- padding: 0.3,
81
- includeHiddenNodes: false,
82
- minZoom: 0.5,
83
- maxZoom: 2
84
- };
85
- (0, _vitest.expect)(options.padding).toBe(0.3);
86
- (0, _vitest.expect)(options.includeHiddenNodes).toBe(false);
87
- });
88
- });
89
- (0, _vitest.describe)("ScreenToFlowPositionOptions", () => {
90
- (0, _vitest.it)("should define screen to flow position options", () => {
91
- const options = {
92
- offset: {
93
- x: 10,
94
- y: 20
95
- },
96
- snapToGrid: true,
97
- gridSize: 15
98
- };
99
- (0, _vitest.expect)(options.offset?.x).toBe(10);
100
- (0, _vitest.expect)(options.snapToGrid).toBe(true);
101
- (0, _vitest.expect)(options.gridSize).toBe(15);
102
- });
103
- });
104
- (0, _vitest.describe)("getViewportForBounds", () => {
105
- (0, _vitest.it)("should calculate viewport to fit bounds within container", () => {
106
- const bounds = {
107
- x: 0,
108
- y: 0,
109
- width: 200,
110
- height: 200
111
- };
112
- const viewport = (0, _viewport.getViewportForBounds)(bounds, 800, 600, 0.1, 5, 0.2);
113
- (0, _vitest.expect)(viewport).toHaveProperty("x");
114
- (0, _vitest.expect)(viewport).toHaveProperty("y");
115
- (0, _vitest.expect)(viewport).toHaveProperty("zoom");
116
- (0, _vitest.expect)(viewport.zoom).toBeGreaterThanOrEqual(0.1);
117
- (0, _vitest.expect)(viewport.zoom).toBeLessThanOrEqual(5);
118
- });
119
- (0, _vitest.it)("should use default padding of 0.2", () => {
120
- const bounds = {
121
- x: 100,
122
- y: 100,
123
- width: 100,
124
- height: 100
125
- };
126
- const viewport1 = (0, _viewport.getViewportForBounds)(bounds, 400, 300, 0.1, 5);
127
- const viewport2 = (0, _viewport.getViewportForBounds)(bounds, 400, 300, 0.1, 5, 0.2);
128
- (0, _vitest.expect)(viewport1.zoom).toBe(viewport2.zoom);
129
- });
130
- (0, _vitest.it)("should handle bounds at origin", () => {
131
- const bounds = {
132
- x: 0,
133
- y: 0,
134
- width: 100,
135
- height: 50
136
- };
137
- const viewport = (0, _viewport.getViewportForBounds)(bounds, 800, 400, 0.1, 5, 0.1);
138
- (0, _vitest.expect)(viewport.zoom).toBeGreaterThan(0);
139
- });
140
- (0, _vitest.it)("should respect minZoom constraint", () => {
141
- const bounds = {
142
- x: 0,
143
- y: 0,
144
- width: 1e4,
145
- height: 1e4
146
- };
147
- const viewport = (0, _viewport.getViewportForBounds)(bounds, 800, 600, 0.5, 5, 0.2);
148
- (0, _vitest.expect)(viewport.zoom).toBeGreaterThanOrEqual(0.5);
149
- });
150
- (0, _vitest.it)("should respect maxZoom constraint", () => {
151
- const bounds = {
152
- x: 0,
153
- y: 0,
154
- width: 10,
155
- height: 10
156
- };
157
- const viewport = (0, _viewport.getViewportForBounds)(bounds, 800, 600, 0.1, 2, 0.2);
158
- (0, _vitest.expect)(viewport.zoom).toBeLessThanOrEqual(2);
159
- });
160
- });
161
- (0, _vitest.describe)("project", () => {
162
- (0, _vitest.it)("should project screen coordinates to canvas coordinates", () => {
163
- const transform = {
164
- x: 100,
165
- y: 50,
166
- zoom: 2
167
- };
168
- const screenPos = {
169
- x: 300,
170
- y: 250
171
- };
172
- const canvasPos = (0, _viewport.project)(screenPos, transform);
173
- (0, _vitest.expect)(canvasPos).toEqual({
174
- x: 100,
175
- y: 100
176
- });
177
- });
178
- (0, _vitest.it)("should handle zoom of 1", () => {
179
- const transform = {
180
- x: 0,
181
- y: 0,
182
- zoom: 1
183
- };
184
- const screenPos = {
185
- x: 100,
186
- y: 200
187
- };
188
- const canvasPos = (0, _viewport.project)(screenPos, transform);
189
- (0, _vitest.expect)(canvasPos).toEqual({
190
- x: 100,
191
- y: 200
192
- });
193
- });
194
- (0, _vitest.it)("should handle negative viewport offset", () => {
195
- const transform = {
196
- x: -100,
197
- y: -50,
198
- zoom: 1
199
- };
200
- const screenPos = {
201
- x: 0,
202
- y: 0
203
- };
204
- const canvasPos = (0, _viewport.project)(screenPos, transform);
205
- (0, _vitest.expect)(canvasPos.x).toBe(100);
206
- (0, _vitest.expect)(canvasPos.y).toBe(50);
207
- });
208
- (0, _vitest.it)("should handle fractional zoom", () => {
209
- const transform = {
210
- x: 0,
211
- y: 0,
212
- zoom: 0.5
213
- };
214
- const screenPos = {
215
- x: 100,
216
- y: 100
217
- };
218
- const canvasPos = (0, _viewport.project)(screenPos, transform);
219
- (0, _vitest.expect)(canvasPos.x).toBe(200);
220
- (0, _vitest.expect)(canvasPos.y).toBe(200);
221
- });
222
- });
223
- (0, _vitest.describe)("unproject", () => {
224
- (0, _vitest.it)("should unproject canvas coordinates to screen coordinates", () => {
225
- const transform = {
226
- x: 100,
227
- y: 50,
228
- zoom: 2
229
- };
230
- const canvasPos = {
231
- x: 100,
232
- y: 100
233
- };
234
- const screenPos = (0, _viewport.unproject)(canvasPos, transform);
235
- (0, _vitest.expect)(screenPos).toEqual({
236
- x: 300,
237
- y: 250
238
- });
239
- });
240
- (0, _vitest.it)("should be inverse of project", () => {
241
- const transform = {
242
- x: 100,
243
- y: 50,
244
- zoom: 2
245
- };
246
- const originalScreen = {
247
- x: 500,
248
- y: 300
249
- };
250
- const canvas = (0, _viewport.project)(originalScreen, transform);
251
- const restored = (0, _viewport.unproject)(canvas, transform);
252
- (0, _vitest.expect)(restored).toEqual(originalScreen);
253
- });
254
- });
255
- (0, _vitest.describe)("isNodeVisible", () => {
256
- const transform = {
257
- x: 0,
258
- y: 0,
259
- zoom: 1
260
- };
261
- const viewportWidth = 800;
262
- const viewportHeight = 600;
263
- (0, _vitest.it)("should return true for node within viewport", () => {
264
- const node = {
265
- position: {
266
- x: 100,
267
- y: 100
268
- },
269
- width: 100,
270
- height: 100
271
- };
272
- (0, _vitest.expect)((0, _viewport.isNodeVisible)(node, transform, viewportWidth, viewportHeight)).toBe(true);
273
- });
274
- (0, _vitest.it)("should return true for node at viewport edge", () => {
275
- const node = {
276
- position: {
277
- x: 0,
278
- y: 0
279
- },
280
- width: 100,
281
- height: 100
282
- };
283
- (0, _vitest.expect)((0, _viewport.isNodeVisible)(node, transform, viewportWidth, viewportHeight)).toBe(true);
284
- });
285
- (0, _vitest.it)("should return false for node completely outside viewport", () => {
286
- const node = {
287
- position: {
288
- x: 2e3,
289
- y: 2e3
290
- },
291
- width: 100,
292
- height: 100
293
- };
294
- (0, _vitest.expect)((0, _viewport.isNodeVisible)(node, transform, viewportWidth, viewportHeight)).toBe(false);
295
- });
296
- (0, _vitest.it)("should return true for node with zero dimensions", () => {
297
- const node = {
298
- position: {
299
- x: 100,
300
- y: 100
301
- },
302
- width: 0,
303
- height: 0
304
- };
305
- (0, _vitest.expect)((0, _viewport.isNodeVisible)(node, transform, viewportWidth, viewportHeight)).toBe(true);
306
- });
307
- (0, _vitest.it)("should handle zoomed viewport", () => {
308
- const zoomedTransform = {
309
- x: 0,
310
- y: 0,
311
- zoom: 2
312
- };
313
- const node = {
314
- position: {
315
- x: 100,
316
- y: 100
317
- },
318
- width: 100,
319
- height: 100
320
- };
321
- (0, _vitest.expect)((0, _viewport.isNodeVisible)(node, zoomedTransform, viewportWidth, viewportHeight)).toBe(true);
322
- });
323
- });
324
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,207 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import {
3
- getViewportForBounds,
4
- project,
5
- unproject,
6
- isNodeVisible
7
- } from "../types/viewport.mjs";
8
- describe("flow/types/viewport", () => {
9
- describe("ViewportTransform", () => {
10
- it("should define viewport with x, y, zoom", () => {
11
- const transform = { x: 100, y: 50, zoom: 1.5 };
12
- expect(transform.x).toBe(100);
13
- expect(transform.y).toBe(50);
14
- expect(transform.zoom).toBe(1.5);
15
- });
16
- it("should allow negative coordinates", () => {
17
- const transform = { x: -100, y: -50, zoom: 0.5 };
18
- expect(transform.x).toBe(-100);
19
- expect(transform.y).toBe(-50);
20
- });
21
- it("should allow zoom less than 1", () => {
22
- const transform = { x: 0, y: 0, zoom: 0.1 };
23
- expect(transform.zoom).toBe(0.1);
24
- });
25
- it("should allow zoom greater than 1", () => {
26
- const transform = { x: 0, y: 0, zoom: 5 };
27
- expect(transform.zoom).toBe(5);
28
- });
29
- });
30
- describe("ViewportOptions", () => {
31
- it("should define full viewport options", () => {
32
- const options = {
33
- minZoom: 0.1,
34
- maxZoom: 5,
35
- translateExtent: [[0, 0], [1e3, 1e3]],
36
- zoomStep: 0.1,
37
- panZoomSpeed: 1,
38
- zoomInMultiplier: 1.2,
39
- zoomOutMultiplier: 0.8,
40
- panning: true,
41
- zooming: true,
42
- zoomOnScroll: true,
43
- zoomOnPinch: true,
44
- panOnScroll: true,
45
- panOnDrag: true,
46
- fitViewOnInit: true,
47
- fitViewOnInitOptions: { padding: 0.2 }
48
- };
49
- expect(options.minZoom).toBe(0.1);
50
- expect(options.maxZoom).toBe(5);
51
- expect(options.fitViewOnInit).toBe(true);
52
- });
53
- it("should allow partial options", () => {
54
- const options = {
55
- minZoom: 0.2,
56
- maxZoom: 3
57
- };
58
- expect(options.minZoom).toBe(0.2);
59
- expect(options.maxZoom).toBe(3);
60
- });
61
- });
62
- describe("FitViewOptions", () => {
63
- it("should define fit view options", () => {
64
- const options = {
65
- padding: 0.3,
66
- includeHiddenNodes: false,
67
- minZoom: 0.5,
68
- maxZoom: 2
69
- };
70
- expect(options.padding).toBe(0.3);
71
- expect(options.includeHiddenNodes).toBe(false);
72
- });
73
- });
74
- describe("ScreenToFlowPositionOptions", () => {
75
- it("should define screen to flow position options", () => {
76
- const options = {
77
- offset: { x: 10, y: 20 },
78
- snapToGrid: true,
79
- gridSize: 15
80
- };
81
- expect(options.offset?.x).toBe(10);
82
- expect(options.snapToGrid).toBe(true);
83
- expect(options.gridSize).toBe(15);
84
- });
85
- });
86
- describe("getViewportForBounds", () => {
87
- it("should calculate viewport to fit bounds within container", () => {
88
- const bounds = { x: 0, y: 0, width: 200, height: 200 };
89
- const viewport = getViewportForBounds(bounds, 800, 600, 0.1, 5, 0.2);
90
- expect(viewport).toHaveProperty("x");
91
- expect(viewport).toHaveProperty("y");
92
- expect(viewport).toHaveProperty("zoom");
93
- expect(viewport.zoom).toBeGreaterThanOrEqual(0.1);
94
- expect(viewport.zoom).toBeLessThanOrEqual(5);
95
- });
96
- it("should use default padding of 0.2", () => {
97
- const bounds = { x: 100, y: 100, width: 100, height: 100 };
98
- const viewport1 = getViewportForBounds(bounds, 400, 300, 0.1, 5);
99
- const viewport2 = getViewportForBounds(bounds, 400, 300, 0.1, 5, 0.2);
100
- expect(viewport1.zoom).toBe(viewport2.zoom);
101
- });
102
- it("should handle bounds at origin", () => {
103
- const bounds = { x: 0, y: 0, width: 100, height: 50 };
104
- const viewport = getViewportForBounds(bounds, 800, 400, 0.1, 5, 0.1);
105
- expect(viewport.zoom).toBeGreaterThan(0);
106
- });
107
- it("should respect minZoom constraint", () => {
108
- const bounds = { x: 0, y: 0, width: 1e4, height: 1e4 };
109
- const viewport = getViewportForBounds(bounds, 800, 600, 0.5, 5, 0.2);
110
- expect(viewport.zoom).toBeGreaterThanOrEqual(0.5);
111
- });
112
- it("should respect maxZoom constraint", () => {
113
- const bounds = { x: 0, y: 0, width: 10, height: 10 };
114
- const viewport = getViewportForBounds(bounds, 800, 600, 0.1, 2, 0.2);
115
- expect(viewport.zoom).toBeLessThanOrEqual(2);
116
- });
117
- });
118
- describe("project", () => {
119
- it("should project screen coordinates to canvas coordinates", () => {
120
- const transform = { x: 100, y: 50, zoom: 2 };
121
- const screenPos = { x: 300, y: 250 };
122
- const canvasPos = project(screenPos, transform);
123
- expect(canvasPos).toEqual({ x: 100, y: 100 });
124
- });
125
- it("should handle zoom of 1", () => {
126
- const transform = { x: 0, y: 0, zoom: 1 };
127
- const screenPos = { x: 100, y: 200 };
128
- const canvasPos = project(screenPos, transform);
129
- expect(canvasPos).toEqual({ x: 100, y: 200 });
130
- });
131
- it("should handle negative viewport offset", () => {
132
- const transform = { x: -100, y: -50, zoom: 1 };
133
- const screenPos = { x: 0, y: 0 };
134
- const canvasPos = project(screenPos, transform);
135
- expect(canvasPos.x).toBe(100);
136
- expect(canvasPos.y).toBe(50);
137
- });
138
- it("should handle fractional zoom", () => {
139
- const transform = { x: 0, y: 0, zoom: 0.5 };
140
- const screenPos = { x: 100, y: 100 };
141
- const canvasPos = project(screenPos, transform);
142
- expect(canvasPos.x).toBe(200);
143
- expect(canvasPos.y).toBe(200);
144
- });
145
- });
146
- describe("unproject", () => {
147
- it("should unproject canvas coordinates to screen coordinates", () => {
148
- const transform = { x: 100, y: 50, zoom: 2 };
149
- const canvasPos = { x: 100, y: 100 };
150
- const screenPos = unproject(canvasPos, transform);
151
- expect(screenPos).toEqual({ x: 300, y: 250 });
152
- });
153
- it("should be inverse of project", () => {
154
- const transform = { x: 100, y: 50, zoom: 2 };
155
- const originalScreen = { x: 500, y: 300 };
156
- const canvas = project(originalScreen, transform);
157
- const restored = unproject(canvas, transform);
158
- expect(restored).toEqual(originalScreen);
159
- });
160
- });
161
- describe("isNodeVisible", () => {
162
- const transform = { x: 0, y: 0, zoom: 1 };
163
- const viewportWidth = 800;
164
- const viewportHeight = 600;
165
- it("should return true for node within viewport", () => {
166
- const node = {
167
- position: { x: 100, y: 100 },
168
- width: 100,
169
- height: 100
170
- };
171
- expect(isNodeVisible(node, transform, viewportWidth, viewportHeight)).toBe(true);
172
- });
173
- it("should return true for node at viewport edge", () => {
174
- const node = {
175
- position: { x: 0, y: 0 },
176
- width: 100,
177
- height: 100
178
- };
179
- expect(isNodeVisible(node, transform, viewportWidth, viewportHeight)).toBe(true);
180
- });
181
- it("should return false for node completely outside viewport", () => {
182
- const node = {
183
- position: { x: 2e3, y: 2e3 },
184
- width: 100,
185
- height: 100
186
- };
187
- expect(isNodeVisible(node, transform, viewportWidth, viewportHeight)).toBe(false);
188
- });
189
- it("should return true for node with zero dimensions", () => {
190
- const node = {
191
- position: { x: 100, y: 100 },
192
- width: 0,
193
- height: 0
194
- };
195
- expect(isNodeVisible(node, transform, viewportWidth, viewportHeight)).toBe(true);
196
- });
197
- it("should handle zoomed viewport", () => {
198
- const zoomedTransform = { x: 0, y: 0, zoom: 2 };
199
- const node = {
200
- position: { x: 100, y: 100 },
201
- width: 100,
202
- height: 100
203
- };
204
- expect(isNodeVisible(node, zoomedTransform, viewportWidth, viewportHeight)).toBe(true);
205
- });
206
- });
207
- });