@yh-ui/flow 0.1.56 → 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.
Files changed (70) hide show
  1. package/dist/__tests__/bpmn-engine.test.cjs +357 -0
  2. package/dist/__tests__/bpmn-engine.test.d.ts +1 -0
  3. package/dist/__tests__/bpmn-engine.test.mjs +406 -0
  4. package/dist/__tests__/bpmn-utils.test.cjs +268 -0
  5. package/dist/__tests__/bpmn-utils.test.d.ts +1 -0
  6. package/dist/__tests__/bpmn-utils.test.mjs +227 -0
  7. package/dist/__tests__/bpmn-xml.test.cjs +150 -0
  8. package/dist/__tests__/bpmn-xml.test.d.ts +1 -0
  9. package/dist/__tests__/bpmn-xml.test.mjs +112 -0
  10. package/dist/__tests__/collaboration.test.cjs +487 -0
  11. package/dist/__tests__/collaboration.test.d.ts +1 -0
  12. package/dist/__tests__/collaboration.test.mjs +424 -0
  13. package/dist/__tests__/edge-types.test.cjs +275 -0
  14. package/dist/__tests__/edge-types.test.d.ts +1 -0
  15. package/dist/__tests__/edge-types.test.mjs +234 -0
  16. package/dist/__tests__/edge-utils.test.cjs +375 -0
  17. package/dist/__tests__/edge-utils.test.d.ts +1 -0
  18. package/dist/__tests__/edge-utils.test.mjs +376 -0
  19. package/dist/__tests__/events-types.test.cjs +184 -0
  20. package/dist/__tests__/events-types.test.d.ts +1 -0
  21. package/dist/__tests__/events-types.test.mjs +184 -0
  22. package/dist/__tests__/export-image-plugin.test.cjs +142 -0
  23. package/dist/__tests__/export-image-plugin.test.d.ts +1 -0
  24. package/dist/__tests__/export-image-plugin.test.mjs +118 -0
  25. package/dist/__tests__/export.test.cjs +237 -0
  26. package/dist/__tests__/export.test.d.ts +1 -0
  27. package/dist/__tests__/export.test.mjs +171 -0
  28. package/dist/__tests__/flow-context.test.cjs +16 -0
  29. package/dist/__tests__/flow-context.test.d.ts +1 -0
  30. package/dist/__tests__/flow-context.test.mjs +16 -0
  31. package/dist/__tests__/flow-props.test.cjs +94 -0
  32. package/dist/__tests__/flow-props.test.d.ts +1 -0
  33. package/dist/__tests__/flow-props.test.mjs +92 -0
  34. package/dist/__tests__/layout-plugin.test.cjs +233 -0
  35. package/dist/__tests__/layout-plugin.test.d.ts +1 -0
  36. package/dist/__tests__/layout-plugin.test.mjs +215 -0
  37. package/dist/__tests__/node-types.test.cjs +368 -0
  38. package/dist/__tests__/node-types.test.d.ts +1 -0
  39. package/dist/__tests__/node-types.test.mjs +292 -0
  40. package/dist/__tests__/performance.test.cjs +313 -0
  41. package/dist/__tests__/performance.test.d.ts +1 -0
  42. package/dist/__tests__/performance.test.mjs +218 -0
  43. package/dist/__tests__/plugin-advanced.test.cjs +301 -0
  44. package/dist/__tests__/plugin-advanced.test.d.ts +1 -0
  45. package/dist/__tests__/plugin-advanced.test.mjs +225 -0
  46. package/dist/__tests__/plugins.test.cjs +412 -0
  47. package/dist/__tests__/plugins.test.d.ts +1 -0
  48. package/dist/__tests__/plugins.test.mjs +402 -0
  49. package/dist/__tests__/screenshot-capture.test.cjs +183 -0
  50. package/dist/__tests__/screenshot-capture.test.d.ts +1 -0
  51. package/dist/__tests__/screenshot-capture.test.mjs +124 -0
  52. package/dist/__tests__/screenshot.test.cjs +74 -0
  53. package/dist/__tests__/screenshot.test.d.ts +1 -0
  54. package/dist/__tests__/screenshot.test.mjs +69 -0
  55. package/dist/__tests__/theme.test.cjs +185 -0
  56. package/dist/__tests__/theme.test.d.ts +1 -0
  57. package/dist/__tests__/theme.test.mjs +191 -0
  58. package/dist/__tests__/transform.test.cjs +376 -50
  59. package/dist/__tests__/transform.test.mjs +229 -28
  60. package/dist/__tests__/useAlignment.test.cjs +37 -0
  61. package/dist/__tests__/useAlignment.test.mjs +20 -0
  62. package/dist/__tests__/useNodeDistribution.test.cjs +643 -0
  63. package/dist/__tests__/useNodeDistribution.test.d.ts +1 -0
  64. package/dist/__tests__/useNodeDistribution.test.mjs +297 -0
  65. package/dist/__tests__/viewport-types.test.cjs +324 -0
  66. package/dist/__tests__/viewport-types.test.d.ts +1 -0
  67. package/dist/__tests__/viewport-types.test.mjs +207 -0
  68. package/dist/utils/bpmn.cjs +27 -16
  69. package/dist/utils/bpmn.mjs +27 -19
  70. package/package.json +3 -3
@@ -3,56 +3,382 @@
3
3
  var _vitest = require("vitest");
4
4
  var _transform = require("../utils/transform.cjs");
5
5
  (0, _vitest.describe)("flow/utils/transform", () => {
6
- (0, _vitest.it)("screenToCanvas and canvasToScreen should be inverse (basic)", () => {
7
- const t = {
8
- x: 100,
9
- y: 50,
10
- zoom: 2
11
- };
12
- const screen = {
13
- x: 300,
14
- y: 250
15
- };
16
- const canvas = (0, _transform.screenToCanvas)(screen.x, screen.y, t);
17
- const back = (0, _transform.canvasToScreen)(canvas.x, canvas.y, t);
18
- (0, _vitest.expect)(back.x).toBe(screen.x);
19
- (0, _vitest.expect)(back.y).toBe(screen.y);
20
- });
21
- (0, _vitest.it)("projectNodePosition should transform between viewports", () => {
22
- const from = {
23
- x: 10,
24
- y: 20,
25
- zoom: 2
26
- };
27
- const to = {
28
- x: -5,
29
- y: 15,
30
- zoom: 1
31
- };
32
- const p = {
33
- x: 110,
34
- y: 220
35
- };
36
- const projected = (0, _transform.projectNodePosition)(p, from, to);
37
- const canvas = (0, _transform.screenToCanvas)(p.x, p.y, from);
38
- const expected = (0, _transform.canvasToScreen)(canvas.x, canvas.y, to);
39
- (0, _vitest.expect)(projected).toEqual(expected);
40
- });
41
- (0, _vitest.it)("snapToGrid should round to nearest grid", () => {
42
- (0, _vitest.expect)((0, _transform.snapToGrid)(0, 10)).toBe(0);
43
- (0, _vitest.expect)((0, _transform.snapToGrid)(4, 10)).toBe(0);
44
- (0, _vitest.expect)((0, _transform.snapToGrid)(5, 10)).toBe(10);
45
- (0, _vitest.expect)((0, _transform.snapToGrid)(14, 10)).toBe(10);
46
- (0, _vitest.expect)((0, _transform.snapToGrid)(15, 10)).toBe(20);
47
- });
48
- (0, _vitest.it)("snapPositionToGrid should snap x/y independently", () => {
49
- const p = (0, _transform.snapPositionToGrid)({
50
- x: 17,
51
- y: 23
52
- }, [10, 5]);
53
- (0, _vitest.expect)(p).toEqual({
54
- x: 20,
55
- y: 25
6
+ (0, _vitest.describe)("screenToCanvas", () => {
7
+ (0, _vitest.it)("should convert screen coordinates to canvas coordinates", () => {
8
+ const transform = {
9
+ x: 100,
10
+ y: 50,
11
+ zoom: 2
12
+ };
13
+ const canvas = (0, _transform.screenToCanvas)(300, 250, transform);
14
+ (0, _vitest.expect)(canvas.x).toBe(100);
15
+ (0, _vitest.expect)(canvas.y).toBe(100);
16
+ });
17
+ (0, _vitest.it)("should handle zoom of 1", () => {
18
+ const transform = {
19
+ x: 0,
20
+ y: 0,
21
+ zoom: 1
22
+ };
23
+ const canvas = (0, _transform.screenToCanvas)(100, 200, transform);
24
+ (0, _vitest.expect)(canvas.x).toBe(100);
25
+ (0, _vitest.expect)(canvas.y).toBe(200);
26
+ });
27
+ (0, _vitest.it)("should handle negative transform offsets", () => {
28
+ const transform = {
29
+ x: -100,
30
+ y: -50,
31
+ zoom: 1
32
+ };
33
+ const canvas = (0, _transform.screenToCanvas)(50, 100, transform);
34
+ (0, _vitest.expect)(canvas.x).toBe(150);
35
+ (0, _vitest.expect)(canvas.y).toBe(150);
36
+ });
37
+ (0, _vitest.it)("should handle fractional zoom", () => {
38
+ const transform = {
39
+ x: 0,
40
+ y: 0,
41
+ zoom: 0.5
42
+ };
43
+ const canvas = (0, _transform.screenToCanvas)(100, 200, transform);
44
+ (0, _vitest.expect)(canvas.x).toBe(200);
45
+ (0, _vitest.expect)(canvas.y).toBe(400);
46
+ });
47
+ });
48
+ (0, _vitest.describe)("canvasToScreen", () => {
49
+ (0, _vitest.it)("should convert canvas coordinates to screen coordinates", () => {
50
+ const transform = {
51
+ x: 100,
52
+ y: 50,
53
+ zoom: 2
54
+ };
55
+ const screen = (0, _transform.canvasToScreen)(100, 100, transform);
56
+ (0, _vitest.expect)(screen.x).toBe(300);
57
+ (0, _vitest.expect)(screen.y).toBe(250);
58
+ });
59
+ (0, _vitest.it)("should handle zoom of 1", () => {
60
+ const transform = {
61
+ x: 0,
62
+ y: 0,
63
+ zoom: 1
64
+ };
65
+ const screen = (0, _transform.canvasToScreen)(100, 200, transform);
66
+ (0, _vitest.expect)(screen.x).toBe(100);
67
+ (0, _vitest.expect)(screen.y).toBe(200);
68
+ });
69
+ (0, _vitest.it)("should be inverse of screenToCanvas", () => {
70
+ const transform = {
71
+ x: 100,
72
+ y: 50,
73
+ zoom: 2
74
+ };
75
+ const original = {
76
+ x: 300,
77
+ y: 250
78
+ };
79
+ const canvas = (0, _transform.screenToCanvas)(original.x, original.y, transform);
80
+ const back = (0, _transform.canvasToScreen)(canvas.x, canvas.y, transform);
81
+ (0, _vitest.expect)(back.x).toBeCloseTo(original.x);
82
+ (0, _vitest.expect)(back.y).toBeCloseTo(original.y);
83
+ });
84
+ });
85
+ (0, _vitest.describe)("projectNodePosition", () => {
86
+ (0, _vitest.it)("should transform position between viewports", () => {
87
+ const from = {
88
+ x: 100,
89
+ y: 50,
90
+ zoom: 2
91
+ };
92
+ const to = {
93
+ x: -50,
94
+ y: 100,
95
+ zoom: 1
96
+ };
97
+ const position = {
98
+ x: 300,
99
+ y: 250
100
+ };
101
+ const projected = (0, _transform.projectNodePosition)(position, from, to);
102
+ (0, _vitest.expect)(projected).toHaveProperty("x");
103
+ (0, _vitest.expect)(projected).toHaveProperty("y");
104
+ });
105
+ (0, _vitest.it)("should handle identical viewports", () => {
106
+ const transform = {
107
+ x: 0,
108
+ y: 0,
109
+ zoom: 1
110
+ };
111
+ const position = {
112
+ x: 100,
113
+ y: 200
114
+ };
115
+ const projected = (0, _transform.projectNodePosition)(position, transform, transform);
116
+ (0, _vitest.expect)(projected).toEqual(position);
117
+ });
118
+ });
119
+ (0, _vitest.describe)("getElementPosition", () => {
120
+ (0, _vitest.it)("should calculate element position relative to container", () => {
121
+ const mockElement = {
122
+ getBoundingClientRect: () => ({
123
+ left: 100,
124
+ top: 50
125
+ })
126
+ };
127
+ const mockContainer = {
128
+ getBoundingClientRect: () => ({
129
+ left: 50,
130
+ top: 25
131
+ })
132
+ };
133
+ const pos = (0, _transform.getElementPosition)(mockElement, mockContainer);
134
+ (0, _vitest.expect)(pos.x).toBe(50);
135
+ (0, _vitest.expect)(pos.y).toBe(25);
136
+ });
137
+ (0, _vitest.it)("should handle element at container origin", () => {
138
+ const mockElement = {
139
+ getBoundingClientRect: () => ({
140
+ left: 100,
141
+ top: 100
142
+ })
143
+ };
144
+ const mockContainer = {
145
+ getBoundingClientRect: () => ({
146
+ left: 100,
147
+ top: 100
148
+ })
149
+ };
150
+ const pos = (0, _transform.getElementPosition)(mockElement, mockContainer);
151
+ (0, _vitest.expect)(pos.x).toBe(0);
152
+ (0, _vitest.expect)(pos.y).toBe(0);
153
+ });
154
+ });
155
+ (0, _vitest.describe)("getElementCanvasPosition", () => {
156
+ (0, _vitest.it)("should get element position in canvas coordinates", () => {
157
+ const mockElement = {
158
+ getBoundingClientRect: () => ({
159
+ left: 200,
160
+ top: 150
161
+ })
162
+ };
163
+ const mockContainer = {
164
+ getBoundingClientRect: () => ({
165
+ left: 100,
166
+ y: 50
167
+ })
168
+ };
169
+ const transform = {
170
+ x: 0,
171
+ y: 0,
172
+ zoom: 1
173
+ };
174
+ const pos = (0, _transform.getElementCanvasPosition)(mockElement, mockContainer, transform);
175
+ (0, _vitest.expect)(pos).toHaveProperty("x");
176
+ (0, _vitest.expect)(pos).toHaveProperty("y");
177
+ });
178
+ });
179
+ (0, _vitest.describe)("distanceBetweenPoints", () => {
180
+ (0, _vitest.it)("should calculate distance between two points", () => {
181
+ const p1 = {
182
+ x: 0,
183
+ y: 0
184
+ };
185
+ const p2 = {
186
+ x: 3,
187
+ y: 4
188
+ };
189
+ (0, _vitest.expect)((0, _transform.distanceBetweenPoints)(p1, p2)).toBe(5);
190
+ });
191
+ (0, _vitest.it)("should return 0 for same point", () => {
192
+ const p = {
193
+ x: 100,
194
+ y: 100
195
+ };
196
+ (0, _vitest.expect)((0, _transform.distanceBetweenPoints)(p, p)).toBe(0);
197
+ });
198
+ (0, _vitest.it)("should handle negative coordinates", () => {
199
+ const p1 = {
200
+ x: -3,
201
+ y: -4
202
+ };
203
+ const p2 = {
204
+ x: 0,
205
+ y: 0
206
+ };
207
+ (0, _vitest.expect)((0, _transform.distanceBetweenPoints)(p1, p2)).toBe(5);
208
+ });
209
+ });
210
+ (0, _vitest.describe)("getVector", () => {
211
+ (0, _vitest.it)("should calculate vector from source to target", () => {
212
+ const source = {
213
+ x: 10,
214
+ y: 20
215
+ };
216
+ const target = {
217
+ x: 30,
218
+ y: 50
219
+ };
220
+ const vector = (0, _transform.getVector)(source, target);
221
+ (0, _vitest.expect)(vector).toEqual({
222
+ x: 20,
223
+ y: 30
224
+ });
225
+ });
226
+ (0, _vitest.it)("should handle zero vector", () => {
227
+ const source = {
228
+ x: 100,
229
+ y: 100
230
+ };
231
+ const target = {
232
+ x: 100,
233
+ y: 100
234
+ };
235
+ const vector = (0, _transform.getVector)(source, target);
236
+ (0, _vitest.expect)(vector).toEqual({
237
+ x: 0,
238
+ y: 0
239
+ });
240
+ });
241
+ (0, _vitest.it)("should handle negative results", () => {
242
+ const source = {
243
+ x: 50,
244
+ y: 50
245
+ };
246
+ const target = {
247
+ x: 30,
248
+ y: 20
249
+ };
250
+ const vector = (0, _transform.getVector)(source, target);
251
+ (0, _vitest.expect)(vector).toEqual({
252
+ x: -20,
253
+ y: -30
254
+ });
255
+ });
256
+ });
257
+ (0, _vitest.describe)("getVectorMagnitude", () => {
258
+ (0, _vitest.it)("should calculate magnitude of vector", () => {
259
+ const vector = {
260
+ x: 3,
261
+ y: 4
262
+ };
263
+ (0, _vitest.expect)((0, _transform.getVectorMagnitude)(vector)).toBe(5);
264
+ });
265
+ (0, _vitest.it)("should return 0 for zero vector", () => {
266
+ const vector = {
267
+ x: 0,
268
+ y: 0
269
+ };
270
+ (0, _vitest.expect)((0, _transform.getVectorMagnitude)(vector)).toBe(0);
271
+ });
272
+ (0, _vitest.it)("should handle negative components", () => {
273
+ const vector = {
274
+ x: -3,
275
+ y: -4
276
+ };
277
+ (0, _vitest.expect)((0, _transform.getVectorMagnitude)(vector)).toBe(5);
278
+ });
279
+ });
280
+ (0, _vitest.describe)("normalizeVector", () => {
281
+ (0, _vitest.it)("should normalize a unit vector", () => {
282
+ const vector = {
283
+ x: 3,
284
+ y: 4
285
+ };
286
+ const normalized = (0, _transform.normalizeVector)(vector);
287
+ (0, _vitest.expect)(normalized.x).toBeCloseTo(0.6);
288
+ (0, _vitest.expect)(normalized.y).toBeCloseTo(0.8);
289
+ });
290
+ (0, _vitest.it)("should return zero vector for zero magnitude", () => {
291
+ const vector = {
292
+ x: 0,
293
+ y: 0
294
+ };
295
+ const normalized = (0, _transform.normalizeVector)(vector);
296
+ (0, _vitest.expect)(normalized).toEqual({
297
+ x: 0,
298
+ y: 0
299
+ });
300
+ });
301
+ (0, _vitest.it)("should produce unit magnitude vector", () => {
302
+ const vector = {
303
+ x: 5,
304
+ y: 12
305
+ };
306
+ const normalized = (0, _transform.normalizeVector)(vector);
307
+ const magnitude = (0, _transform.getVectorMagnitude)(normalized);
308
+ (0, _vitest.expect)(magnitude).toBeCloseTo(1);
309
+ });
310
+ (0, _vitest.it)("should handle negative components", () => {
311
+ const vector = {
312
+ x: -5,
313
+ y: 0
314
+ };
315
+ const normalized = (0, _transform.normalizeVector)(vector);
316
+ (0, _vitest.expect)(normalized.x).toBe(-1);
317
+ (0, _vitest.expect)(normalized.y).toBe(0);
318
+ });
319
+ });
320
+ (0, _vitest.describe)("snapToGrid", () => {
321
+ (0, _vitest.it)("should snap value to nearest grid point", () => {
322
+ (0, _vitest.expect)((0, _transform.snapToGrid)(0, 10)).toBe(0);
323
+ (0, _vitest.expect)((0, _transform.snapToGrid)(5, 10)).toBe(10);
324
+ (0, _vitest.expect)((0, _transform.snapToGrid)(10, 10)).toBe(10);
325
+ (0, _vitest.expect)((0, _transform.snapToGrid)(15, 10)).toBe(20);
326
+ });
327
+ (0, _vitest.it)("should snap negative values toward zero", () => {
328
+ (0, _vitest.expect)((0, _transform.snapToGrid)(-15, 10)).toBe(-10);
329
+ (0, _vitest.expect)((0, _transform.snapToGrid)(-25, 10)).toBe(-20);
330
+ (0, _vitest.expect)((0, _transform.snapToGrid)(-55, 10)).toBe(-50);
331
+ });
332
+ (0, _vitest.it)("should snap very small negative values to zero", () => {
333
+ const result = (0, _transform.snapToGrid)(-5, 10);
334
+ (0, _vitest.expect)(Object.is(result, -0) || result === 0).toBe(true);
335
+ });
336
+ (0, _vitest.it)("should handle fractional values", () => {
337
+ (0, _vitest.expect)((0, _transform.snapToGrid)(2.5, 10)).toBe(0);
338
+ (0, _vitest.expect)((0, _transform.snapToGrid)(7.5, 10)).toBe(10);
339
+ });
340
+ (0, _vitest.it)("should handle non-10 grid size", () => {
341
+ (0, _vitest.expect)((0, _transform.snapToGrid)(5, 5)).toBe(5);
342
+ (0, _vitest.expect)((0, _transform.snapToGrid)(7, 5)).toBe(5);
343
+ (0, _vitest.expect)((0, _transform.snapToGrid)(8, 5)).toBe(10);
344
+ });
345
+ });
346
+ (0, _vitest.describe)("snapPositionToGrid", () => {
347
+ (0, _vitest.it)("should snap x and y independently", () => {
348
+ const pos = {
349
+ x: 17,
350
+ y: 23
351
+ };
352
+ const grid = [10, 5];
353
+ const snapped = (0, _transform.snapPositionToGrid)(pos, grid);
354
+ (0, _vitest.expect)(snapped).toEqual({
355
+ x: 20,
356
+ y: 25
357
+ });
358
+ });
359
+ (0, _vitest.it)("should handle zero coordinates", () => {
360
+ const pos = {
361
+ x: 0,
362
+ y: 0
363
+ };
364
+ const grid = [10, 5];
365
+ const snapped = (0, _transform.snapPositionToGrid)(pos, grid);
366
+ (0, _vitest.expect)(snapped).toEqual({
367
+ x: 0,
368
+ y: 0
369
+ });
370
+ });
371
+ (0, _vitest.it)("should handle different grid sizes for x and y", () => {
372
+ const pos = {
373
+ x: 100,
374
+ y: 200
375
+ };
376
+ const grid = [20, 25];
377
+ const snapped = (0, _transform.snapPositionToGrid)(pos, grid);
378
+ (0, _vitest.expect)(snapped).toEqual({
379
+ x: 100,
380
+ y: 200
381
+ });
56
382
  });
57
383
  });
58
384
  });