@yh-ui/flow 1.0.1 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/bpmn-engine.test.cjs +357 -0
- package/dist/__tests__/bpmn-engine.test.d.ts +1 -0
- package/dist/__tests__/bpmn-engine.test.mjs +406 -0
- package/dist/__tests__/bpmn-utils.test.cjs +268 -0
- package/dist/__tests__/bpmn-utils.test.d.ts +1 -0
- package/dist/__tests__/bpmn-utils.test.mjs +227 -0
- package/dist/__tests__/bpmn-xml.test.cjs +150 -0
- package/dist/__tests__/bpmn-xml.test.d.ts +1 -0
- package/dist/__tests__/bpmn-xml.test.mjs +112 -0
- package/dist/__tests__/collaboration.test.cjs +487 -0
- package/dist/__tests__/collaboration.test.d.ts +1 -0
- package/dist/__tests__/collaboration.test.mjs +424 -0
- package/dist/__tests__/edge-types.test.cjs +275 -0
- package/dist/__tests__/edge-types.test.d.ts +1 -0
- package/dist/__tests__/edge-types.test.mjs +234 -0
- package/dist/__tests__/edge-utils.test.cjs +375 -0
- package/dist/__tests__/edge-utils.test.d.ts +1 -0
- package/dist/__tests__/edge-utils.test.mjs +376 -0
- package/dist/__tests__/events-types.test.cjs +184 -0
- package/dist/__tests__/events-types.test.d.ts +1 -0
- package/dist/__tests__/events-types.test.mjs +184 -0
- package/dist/__tests__/export-image-plugin.test.cjs +142 -0
- package/dist/__tests__/export-image-plugin.test.d.ts +1 -0
- package/dist/__tests__/export-image-plugin.test.mjs +118 -0
- package/dist/__tests__/export.test.cjs +237 -0
- package/dist/__tests__/export.test.d.ts +1 -0
- package/dist/__tests__/export.test.mjs +171 -0
- package/dist/__tests__/flow-context.test.cjs +16 -0
- package/dist/__tests__/flow-context.test.d.ts +1 -0
- package/dist/__tests__/flow-context.test.mjs +16 -0
- package/dist/__tests__/flow-props.test.cjs +94 -0
- package/dist/__tests__/flow-props.test.d.ts +1 -0
- package/dist/__tests__/flow-props.test.mjs +92 -0
- package/dist/__tests__/layout-plugin.test.cjs +233 -0
- package/dist/__tests__/layout-plugin.test.d.ts +1 -0
- package/dist/__tests__/layout-plugin.test.mjs +215 -0
- package/dist/__tests__/node-types.test.cjs +368 -0
- package/dist/__tests__/node-types.test.d.ts +1 -0
- package/dist/__tests__/node-types.test.mjs +292 -0
- package/dist/__tests__/performance.test.cjs +313 -0
- package/dist/__tests__/performance.test.d.ts +1 -0
- package/dist/__tests__/performance.test.mjs +218 -0
- package/dist/__tests__/plugin-advanced.test.cjs +301 -0
- package/dist/__tests__/plugin-advanced.test.d.ts +1 -0
- package/dist/__tests__/plugin-advanced.test.mjs +225 -0
- package/dist/__tests__/plugins.test.cjs +412 -0
- package/dist/__tests__/plugins.test.d.ts +1 -0
- package/dist/__tests__/plugins.test.mjs +402 -0
- package/dist/__tests__/screenshot-capture.test.cjs +183 -0
- package/dist/__tests__/screenshot-capture.test.d.ts +1 -0
- package/dist/__tests__/screenshot-capture.test.mjs +124 -0
- package/dist/__tests__/screenshot.test.cjs +74 -0
- package/dist/__tests__/screenshot.test.d.ts +1 -0
- package/dist/__tests__/screenshot.test.mjs +69 -0
- package/dist/__tests__/theme.test.cjs +185 -0
- package/dist/__tests__/theme.test.d.ts +1 -0
- package/dist/__tests__/theme.test.mjs +191 -0
- package/dist/__tests__/transform.test.cjs +376 -50
- package/dist/__tests__/transform.test.mjs +229 -28
- package/dist/__tests__/useAlignment.test.cjs +37 -0
- package/dist/__tests__/useAlignment.test.mjs +20 -0
- package/dist/__tests__/useNodeDistribution.test.cjs +643 -0
- package/dist/__tests__/useNodeDistribution.test.d.ts +1 -0
- package/dist/__tests__/useNodeDistribution.test.mjs +297 -0
- package/dist/__tests__/viewport-types.test.cjs +324 -0
- package/dist/__tests__/viewport-types.test.d.ts +1 -0
- package/dist/__tests__/viewport-types.test.mjs +207 -0
- package/dist/utils/bpmn.cjs +27 -16
- package/dist/utils/bpmn.mjs +27 -19
- package/package.json +3 -3
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
import { ref } from "vue";
|
|
3
|
+
import { useNodeDistribution } from "../core/useNodeDistribution.mjs";
|
|
4
|
+
function createMockFlowInstance() {
|
|
5
|
+
const nodes = ref([]);
|
|
6
|
+
const edges = ref([]);
|
|
7
|
+
const viewport = ref({ x: 0, y: 0, zoom: 1 });
|
|
8
|
+
const draggingNodeId = ref(null);
|
|
9
|
+
return {
|
|
10
|
+
nodes,
|
|
11
|
+
edges,
|
|
12
|
+
viewport,
|
|
13
|
+
draggingNodeId,
|
|
14
|
+
addNode: vi.fn(),
|
|
15
|
+
removeNode: vi.fn(),
|
|
16
|
+
updateNode: vi.fn(),
|
|
17
|
+
getNode: vi.fn(),
|
|
18
|
+
addEdge: vi.fn(),
|
|
19
|
+
removeEdge: vi.fn(),
|
|
20
|
+
updateEdge: vi.fn(),
|
|
21
|
+
getEdge: vi.fn(),
|
|
22
|
+
setViewport: vi.fn(),
|
|
23
|
+
fitView: vi.fn(),
|
|
24
|
+
zoomIn: vi.fn(),
|
|
25
|
+
zoomOut: vi.fn(),
|
|
26
|
+
centerView: vi.fn(),
|
|
27
|
+
selectNode: vi.fn(),
|
|
28
|
+
selectEdge: vi.fn(),
|
|
29
|
+
clearSelection: vi.fn(),
|
|
30
|
+
getNodes: vi.fn(() => nodes.value),
|
|
31
|
+
getEdges: vi.fn(() => edges.value),
|
|
32
|
+
getViewport: vi.fn(() => viewport.value),
|
|
33
|
+
screenToCanvas: vi.fn(),
|
|
34
|
+
canvasToScreen: vi.fn(),
|
|
35
|
+
on: vi.fn(),
|
|
36
|
+
off: vi.fn(),
|
|
37
|
+
emit: vi.fn(),
|
|
38
|
+
isValidConnection: vi.fn(() => true),
|
|
39
|
+
$el: void 0,
|
|
40
|
+
usePlugin: vi.fn(),
|
|
41
|
+
removePlugin: vi.fn()
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
describe("flow/core/useNodeDistribution", () => {
|
|
45
|
+
it("should return all distribution functions", () => {
|
|
46
|
+
const flow = createMockFlowInstance();
|
|
47
|
+
const {
|
|
48
|
+
distributeHorizontally,
|
|
49
|
+
distributeVertically,
|
|
50
|
+
alignNodesHorizontal,
|
|
51
|
+
alignNodesVertical
|
|
52
|
+
} = useNodeDistribution({ nodes: flow.nodes });
|
|
53
|
+
expect(typeof distributeHorizontally).toBe("function");
|
|
54
|
+
expect(typeof distributeVertically).toBe("function");
|
|
55
|
+
expect(typeof alignNodesHorizontal).toBe("function");
|
|
56
|
+
expect(typeof alignNodesVertical).toBe("function");
|
|
57
|
+
});
|
|
58
|
+
describe("distributeHorizontally", () => {
|
|
59
|
+
it("should not distribute when fewer than 3 nodes", () => {
|
|
60
|
+
const flow = createMockFlowInstance();
|
|
61
|
+
flow.nodes.value = [
|
|
62
|
+
{ id: "1", type: "default", position: { x: 0, y: 0 }, data: {} },
|
|
63
|
+
{ id: "2", type: "default", position: { x: 100, y: 0 }, data: {} }
|
|
64
|
+
];
|
|
65
|
+
const { distributeHorizontally } = useNodeDistribution({ nodes: flow.nodes });
|
|
66
|
+
distributeHorizontally(["1", "2"]);
|
|
67
|
+
expect(flow.nodes.value[0].position.x).toBe(0);
|
|
68
|
+
expect(flow.nodes.value[1].position.x).toBe(100);
|
|
69
|
+
});
|
|
70
|
+
it("should distribute 3 nodes horizontally with custom gap", () => {
|
|
71
|
+
const flow = createMockFlowInstance();
|
|
72
|
+
flow.nodes.value = [
|
|
73
|
+
{ id: "1", type: "default", position: { x: 0, y: 0 }, data: {}, width: 50, height: 50 },
|
|
74
|
+
{ id: "2", type: "default", position: { x: 50, y: 0 }, data: {}, width: 50, height: 50 },
|
|
75
|
+
{ id: "3", type: "default", position: { x: 100, y: 0 }, data: {}, width: 50, height: 50 }
|
|
76
|
+
];
|
|
77
|
+
const { distributeHorizontally } = useNodeDistribution({ nodes: flow.nodes });
|
|
78
|
+
distributeHorizontally(["1", "2", "3"], 100);
|
|
79
|
+
const positions = flow.nodes.value.map((n) => n.position.x);
|
|
80
|
+
expect(positions[0]).toBe(0);
|
|
81
|
+
expect(positions[1]).toBe(150);
|
|
82
|
+
expect(positions[2]).toBe(300);
|
|
83
|
+
});
|
|
84
|
+
it("should distribute nodes that are too close", () => {
|
|
85
|
+
const flow = createMockFlowInstance();
|
|
86
|
+
flow.nodes.value = [
|
|
87
|
+
{ id: "1", type: "default", position: { x: 0, y: 0 }, data: {}, width: 50, height: 50 },
|
|
88
|
+
{ id: "2", type: "default", position: { x: 10, y: 0 }, data: {}, width: 50, height: 50 },
|
|
89
|
+
{ id: "3", type: "default", position: { x: 20, y: 0 }, data: {}, width: 50, height: 50 }
|
|
90
|
+
];
|
|
91
|
+
const { distributeHorizontally } = useNodeDistribution({ nodes: flow.nodes });
|
|
92
|
+
distributeHorizontally(["1", "2", "3"], 50);
|
|
93
|
+
const positions = flow.nodes.value.map((n) => n.position.x);
|
|
94
|
+
expect(positions[0]).toBe(0);
|
|
95
|
+
expect(positions[1]).toBeGreaterThan(positions[0]);
|
|
96
|
+
expect(positions[2]).toBeGreaterThan(positions[1]);
|
|
97
|
+
});
|
|
98
|
+
it("should use selected nodes when no nodeIds provided", () => {
|
|
99
|
+
const flow = createMockFlowInstance();
|
|
100
|
+
flow.nodes.value = [
|
|
101
|
+
{
|
|
102
|
+
id: "1",
|
|
103
|
+
type: "default",
|
|
104
|
+
position: { x: 0, y: 0 },
|
|
105
|
+
data: {},
|
|
106
|
+
width: 50,
|
|
107
|
+
height: 50,
|
|
108
|
+
selected: true
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
id: "2",
|
|
112
|
+
type: "default",
|
|
113
|
+
position: { x: 50, y: 0 },
|
|
114
|
+
data: {},
|
|
115
|
+
width: 50,
|
|
116
|
+
height: 50,
|
|
117
|
+
selected: true
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
id: "3",
|
|
121
|
+
type: "default",
|
|
122
|
+
position: { x: 100, y: 0 },
|
|
123
|
+
data: {},
|
|
124
|
+
width: 50,
|
|
125
|
+
height: 50,
|
|
126
|
+
selected: true
|
|
127
|
+
}
|
|
128
|
+
];
|
|
129
|
+
const { distributeHorizontally } = useNodeDistribution({ nodes: flow.nodes });
|
|
130
|
+
distributeHorizontally(void 0, 50);
|
|
131
|
+
const positions = flow.nodes.value.map((n) => n.position.x);
|
|
132
|
+
expect(positions[0]).toBe(0);
|
|
133
|
+
expect(positions[1]).toBe(100);
|
|
134
|
+
expect(positions[2]).toBe(200);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
describe("distributeVertically", () => {
|
|
138
|
+
it("should not distribute when fewer than 3 nodes", () => {
|
|
139
|
+
const flow = createMockFlowInstance();
|
|
140
|
+
flow.nodes.value = [
|
|
141
|
+
{ id: "1", type: "default", position: { x: 0, y: 0 }, data: {} },
|
|
142
|
+
{ id: "2", type: "default", position: { x: 0, y: 100 }, data: {} }
|
|
143
|
+
];
|
|
144
|
+
const { distributeVertically } = useNodeDistribution({ nodes: flow.nodes });
|
|
145
|
+
distributeVertically(["1", "2"]);
|
|
146
|
+
expect(flow.nodes.value[0].position.y).toBe(0);
|
|
147
|
+
expect(flow.nodes.value[1].position.y).toBe(100);
|
|
148
|
+
});
|
|
149
|
+
it("should distribute 3 nodes vertically", () => {
|
|
150
|
+
const flow = createMockFlowInstance();
|
|
151
|
+
flow.nodes.value = [
|
|
152
|
+
{ id: "1", type: "default", position: { x: 0, y: 0 }, data: {}, width: 50, height: 50 },
|
|
153
|
+
{ id: "2", type: "default", position: { x: 0, y: 50 }, data: {}, width: 50, height: 50 },
|
|
154
|
+
{ id: "3", type: "default", position: { x: 0, y: 100 }, data: {}, width: 50, height: 50 }
|
|
155
|
+
];
|
|
156
|
+
const { distributeVertically } = useNodeDistribution({ nodes: flow.nodes });
|
|
157
|
+
distributeVertically(["1", "2", "3"], 100);
|
|
158
|
+
const positions = flow.nodes.value.map((n) => n.position.y);
|
|
159
|
+
expect(positions[0]).toBe(0);
|
|
160
|
+
expect(positions[1]).toBe(150);
|
|
161
|
+
expect(positions[2]).toBe(300);
|
|
162
|
+
});
|
|
163
|
+
it("should distribute nodes that are too close vertically", () => {
|
|
164
|
+
const flow = createMockFlowInstance();
|
|
165
|
+
flow.nodes.value = [
|
|
166
|
+
{ id: "1", type: "default", position: { x: 0, y: 0 }, data: {}, width: 50, height: 50 },
|
|
167
|
+
{ id: "2", type: "default", position: { x: 0, y: 10 }, data: {}, width: 50, height: 50 },
|
|
168
|
+
{ id: "3", type: "default", position: { x: 0, y: 20 }, data: {}, width: 50, height: 50 }
|
|
169
|
+
];
|
|
170
|
+
const { distributeVertically } = useNodeDistribution({ nodes: flow.nodes });
|
|
171
|
+
distributeVertically(["1", "2", "3"], 50);
|
|
172
|
+
const positions = flow.nodes.value.map((n) => n.position.y);
|
|
173
|
+
expect(positions[0]).toBe(0);
|
|
174
|
+
expect(positions[1]).toBeGreaterThan(positions[0]);
|
|
175
|
+
expect(positions[2]).toBeGreaterThan(positions[1]);
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
describe("alignNodesHorizontal", () => {
|
|
179
|
+
it("should not align when fewer than 2 nodes", () => {
|
|
180
|
+
const flow = createMockFlowInstance();
|
|
181
|
+
flow.nodes.value = [
|
|
182
|
+
{ id: "1", type: "default", position: { x: 0, y: 0 }, data: {}, width: 100, height: 50 }
|
|
183
|
+
];
|
|
184
|
+
const { alignNodesHorizontal } = useNodeDistribution({ nodes: flow.nodes });
|
|
185
|
+
alignNodesHorizontal(["1"]);
|
|
186
|
+
expect(flow.nodes.value[0].position.x).toBe(0);
|
|
187
|
+
});
|
|
188
|
+
it("should align to left edge", () => {
|
|
189
|
+
const flow = createMockFlowInstance();
|
|
190
|
+
flow.nodes.value = [
|
|
191
|
+
{ id: "1", type: "default", position: { x: 0, y: 0 }, data: {}, width: 100, height: 50 },
|
|
192
|
+
{ id: "2", type: "default", position: { x: 50, y: 50 }, data: {}, width: 100, height: 50 },
|
|
193
|
+
{ id: "3", type: "default", position: { x: 100, y: 100 }, data: {}, width: 100, height: 50 }
|
|
194
|
+
];
|
|
195
|
+
const { alignNodesHorizontal } = useNodeDistribution({ nodes: flow.nodes });
|
|
196
|
+
alignNodesHorizontal(["1", "2", "3"], "left");
|
|
197
|
+
expect(flow.nodes.value[0].position.x).toBe(0);
|
|
198
|
+
expect(flow.nodes.value[1].position.x).toBe(0);
|
|
199
|
+
expect(flow.nodes.value[2].position.x).toBe(0);
|
|
200
|
+
});
|
|
201
|
+
it("should align to right edge", () => {
|
|
202
|
+
const flow = createMockFlowInstance();
|
|
203
|
+
flow.nodes.value = [
|
|
204
|
+
{ id: "1", type: "default", position: { x: 0, y: 0 }, data: {}, width: 100, height: 50 },
|
|
205
|
+
{ id: "2", type: "default", position: { x: 50, y: 50 }, data: {}, width: 100, height: 50 }
|
|
206
|
+
];
|
|
207
|
+
const { alignNodesHorizontal } = useNodeDistribution({ nodes: flow.nodes });
|
|
208
|
+
alignNodesHorizontal(["1", "2"], "right");
|
|
209
|
+
expect(flow.nodes.value[0].position.x).toBe(50);
|
|
210
|
+
expect(flow.nodes.value[1].position.x).toBe(50);
|
|
211
|
+
});
|
|
212
|
+
it("should align to center", () => {
|
|
213
|
+
const flow = createMockFlowInstance();
|
|
214
|
+
flow.nodes.value = [
|
|
215
|
+
{ id: "1", type: "default", position: { x: 0, y: 0 }, data: {}, width: 100, height: 50 },
|
|
216
|
+
{ id: "2", type: "default", position: { x: 50, y: 50 }, data: {}, width: 200, height: 50 }
|
|
217
|
+
];
|
|
218
|
+
const { alignNodesHorizontal } = useNodeDistribution({ nodes: flow.nodes });
|
|
219
|
+
alignNodesHorizontal(["1", "2"], "center");
|
|
220
|
+
expect(flow.nodes.value[0].position.x).toBe(50);
|
|
221
|
+
expect(flow.nodes.value[1].position.x).toBe(0);
|
|
222
|
+
});
|
|
223
|
+
it("should use selected nodes when no nodeIds provided", () => {
|
|
224
|
+
const flow = createMockFlowInstance();
|
|
225
|
+
flow.nodes.value = [
|
|
226
|
+
{
|
|
227
|
+
id: "1",
|
|
228
|
+
type: "default",
|
|
229
|
+
position: { x: 0, y: 0 },
|
|
230
|
+
data: {},
|
|
231
|
+
width: 100,
|
|
232
|
+
height: 50,
|
|
233
|
+
selected: true
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
id: "2",
|
|
237
|
+
type: "default",
|
|
238
|
+
position: { x: 50, y: 0 },
|
|
239
|
+
data: {},
|
|
240
|
+
width: 100,
|
|
241
|
+
height: 50,
|
|
242
|
+
selected: true
|
|
243
|
+
}
|
|
244
|
+
];
|
|
245
|
+
const { alignNodesHorizontal } = useNodeDistribution({ nodes: flow.nodes });
|
|
246
|
+
alignNodesHorizontal(void 0, "left");
|
|
247
|
+
expect(flow.nodes.value[0].position.x).toBe(0);
|
|
248
|
+
expect(flow.nodes.value[1].position.x).toBe(0);
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
describe("alignNodesVertical", () => {
|
|
252
|
+
it("should not align when fewer than 2 nodes", () => {
|
|
253
|
+
const flow = createMockFlowInstance();
|
|
254
|
+
flow.nodes.value = [
|
|
255
|
+
{ id: "1", type: "default", position: { x: 0, y: 0 }, data: {}, width: 100, height: 50 }
|
|
256
|
+
];
|
|
257
|
+
const { alignNodesVertical } = useNodeDistribution({ nodes: flow.nodes });
|
|
258
|
+
alignNodesVertical(["1"]);
|
|
259
|
+
expect(flow.nodes.value[0].position.y).toBe(0);
|
|
260
|
+
});
|
|
261
|
+
it("should align to top edge", () => {
|
|
262
|
+
const flow = createMockFlowInstance();
|
|
263
|
+
flow.nodes.value = [
|
|
264
|
+
{ id: "1", type: "default", position: { x: 0, y: 0 }, data: {}, width: 100, height: 50 },
|
|
265
|
+
{ id: "2", type: "default", position: { x: 0, y: 50 }, data: {}, width: 100, height: 50 },
|
|
266
|
+
{ id: "3", type: "default", position: { x: 0, y: 100 }, data: {}, width: 100, height: 50 }
|
|
267
|
+
];
|
|
268
|
+
const { alignNodesVertical } = useNodeDistribution({ nodes: flow.nodes });
|
|
269
|
+
alignNodesVertical(["1", "2", "3"], "top");
|
|
270
|
+
expect(flow.nodes.value[0].position.y).toBe(0);
|
|
271
|
+
expect(flow.nodes.value[1].position.y).toBe(0);
|
|
272
|
+
expect(flow.nodes.value[2].position.y).toBe(0);
|
|
273
|
+
});
|
|
274
|
+
it("should align to bottom edge", () => {
|
|
275
|
+
const flow = createMockFlowInstance();
|
|
276
|
+
flow.nodes.value = [
|
|
277
|
+
{ id: "1", type: "default", position: { x: 0, y: 0 }, data: {}, width: 100, height: 50 },
|
|
278
|
+
{ id: "2", type: "default", position: { x: 0, y: 50 }, data: {}, width: 100, height: 50 }
|
|
279
|
+
];
|
|
280
|
+
const { alignNodesVertical } = useNodeDistribution({ nodes: flow.nodes });
|
|
281
|
+
alignNodesVertical(["1", "2"], "bottom");
|
|
282
|
+
expect(flow.nodes.value[0].position.y).toBe(50);
|
|
283
|
+
expect(flow.nodes.value[1].position.y).toBe(50);
|
|
284
|
+
});
|
|
285
|
+
it("should align to middle", () => {
|
|
286
|
+
const flow = createMockFlowInstance();
|
|
287
|
+
flow.nodes.value = [
|
|
288
|
+
{ id: "1", type: "default", position: { x: 0, y: 0 }, data: {}, width: 100, height: 50 },
|
|
289
|
+
{ id: "2", type: "default", position: { x: 0, y: 50 }, data: {}, width: 100, height: 100 }
|
|
290
|
+
];
|
|
291
|
+
const { alignNodesVertical } = useNodeDistribution({ nodes: flow.nodes });
|
|
292
|
+
alignNodesVertical(["1", "2"], "middle");
|
|
293
|
+
expect(flow.nodes.value[0].position.y).toBe(37.5);
|
|
294
|
+
expect(flow.nodes.value[1].position.y).toBe(12.5);
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
});
|
|
@@ -0,0 +1,324 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|