@yh-ui/flow 1.0.25 → 1.0.30

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 (143) hide show
  1. package/package.json +13 -11
  2. package/LICENSE +0 -21
  3. package/dist/__tests__/ai-workflow.ssr.test.cjs +0 -352
  4. package/dist/__tests__/ai-workflow.ssr.test.d.ts +0 -1
  5. package/dist/__tests__/ai-workflow.ssr.test.mjs +0 -283
  6. package/dist/__tests__/ai-workflow.test.cjs +0 -109
  7. package/dist/__tests__/ai-workflow.test.d.ts +0 -1
  8. package/dist/__tests__/ai-workflow.test.mjs +0 -112
  9. package/dist/__tests__/bpmn-engine.test.cjs +0 -357
  10. package/dist/__tests__/bpmn-engine.test.d.ts +0 -1
  11. package/dist/__tests__/bpmn-engine.test.mjs +0 -406
  12. package/dist/__tests__/bpmn-utils.test.cjs +0 -268
  13. package/dist/__tests__/bpmn-utils.test.d.ts +0 -1
  14. package/dist/__tests__/bpmn-utils.test.mjs +0 -227
  15. package/dist/__tests__/bpmn-xml.test.cjs +0 -150
  16. package/dist/__tests__/bpmn-xml.test.d.ts +0 -1
  17. package/dist/__tests__/bpmn-xml.test.mjs +0 -112
  18. package/dist/__tests__/bpmn.ssr.test.cjs +0 -278
  19. package/dist/__tests__/bpmn.ssr.test.d.ts +0 -1
  20. package/dist/__tests__/bpmn.ssr.test.mjs +0 -237
  21. package/dist/__tests__/bpmn.test.cjs +0 -103
  22. package/dist/__tests__/bpmn.test.d.ts +0 -1
  23. package/dist/__tests__/bpmn.test.mjs +0 -106
  24. package/dist/__tests__/collaboration.test.cjs +0 -487
  25. package/dist/__tests__/collaboration.test.d.ts +0 -1
  26. package/dist/__tests__/collaboration.test.mjs +0 -424
  27. package/dist/__tests__/custom-types.test.cjs +0 -300
  28. package/dist/__tests__/custom-types.test.d.ts +0 -1
  29. package/dist/__tests__/custom-types.test.mjs +0 -248
  30. package/dist/__tests__/edge-types.test.cjs +0 -275
  31. package/dist/__tests__/edge-types.test.d.ts +0 -1
  32. package/dist/__tests__/edge-types.test.mjs +0 -234
  33. package/dist/__tests__/edge-utils.test.cjs +0 -375
  34. package/dist/__tests__/edge-utils.test.d.ts +0 -1
  35. package/dist/__tests__/edge-utils.test.mjs +0 -376
  36. package/dist/__tests__/edge.test.cjs +0 -56
  37. package/dist/__tests__/edge.test.d.ts +0 -1
  38. package/dist/__tests__/edge.test.mjs +0 -69
  39. package/dist/__tests__/event-bus.test.cjs +0 -80
  40. package/dist/__tests__/event-bus.test.d.ts +0 -1
  41. package/dist/__tests__/event-bus.test.mjs +0 -51
  42. package/dist/__tests__/events-types.test.cjs +0 -184
  43. package/dist/__tests__/events-types.test.d.ts +0 -1
  44. package/dist/__tests__/events-types.test.mjs +0 -184
  45. package/dist/__tests__/export-image-plugin.test.cjs +0 -142
  46. package/dist/__tests__/export-image-plugin.test.d.ts +0 -1
  47. package/dist/__tests__/export-image-plugin.test.mjs +0 -118
  48. package/dist/__tests__/export.test.cjs +0 -237
  49. package/dist/__tests__/export.test.d.ts +0 -1
  50. package/dist/__tests__/export.test.mjs +0 -171
  51. package/dist/__tests__/flow-context.test.cjs +0 -16
  52. package/dist/__tests__/flow-context.test.d.ts +0 -1
  53. package/dist/__tests__/flow-context.test.mjs +0 -16
  54. package/dist/__tests__/flow-props.test.cjs +0 -94
  55. package/dist/__tests__/flow-props.test.d.ts +0 -1
  56. package/dist/__tests__/flow-props.test.mjs +0 -92
  57. package/dist/__tests__/flow.ssr.test.cjs +0 -156
  58. package/dist/__tests__/flow.ssr.test.d.ts +0 -1
  59. package/dist/__tests__/flow.ssr.test.mjs +0 -112
  60. package/dist/__tests__/geometry.test.cjs +0 -191
  61. package/dist/__tests__/geometry.test.d.ts +0 -1
  62. package/dist/__tests__/geometry.test.mjs +0 -105
  63. package/dist/__tests__/graph.test.cjs +0 -115
  64. package/dist/__tests__/graph.test.d.ts +0 -1
  65. package/dist/__tests__/graph.test.mjs +0 -85
  66. package/dist/__tests__/history-plugin.test.cjs +0 -191
  67. package/dist/__tests__/history-plugin.test.d.ts +0 -1
  68. package/dist/__tests__/history-plugin.test.mjs +0 -161
  69. package/dist/__tests__/history.test.cjs +0 -81
  70. package/dist/__tests__/history.test.d.ts +0 -1
  71. package/dist/__tests__/history.test.mjs +0 -43
  72. package/dist/__tests__/layout-plugin.test.cjs +0 -233
  73. package/dist/__tests__/layout-plugin.test.d.ts +0 -1
  74. package/dist/__tests__/layout-plugin.test.mjs +0 -215
  75. package/dist/__tests__/layout.test.cjs +0 -213
  76. package/dist/__tests__/layout.test.d.ts +0 -1
  77. package/dist/__tests__/layout.test.mjs +0 -170
  78. package/dist/__tests__/node-edit-panel.ssr.test.cjs +0 -168
  79. package/dist/__tests__/node-edit-panel.ssr.test.d.ts +0 -1
  80. package/dist/__tests__/node-edit-panel.ssr.test.mjs +0 -118
  81. package/dist/__tests__/node-group-plugin.test.cjs +0 -235
  82. package/dist/__tests__/node-group-plugin.test.d.ts +0 -1
  83. package/dist/__tests__/node-group-plugin.test.mjs +0 -187
  84. package/dist/__tests__/node-handles.test.cjs +0 -340
  85. package/dist/__tests__/node-handles.test.d.ts +0 -1
  86. package/dist/__tests__/node-handles.test.mjs +0 -230
  87. package/dist/__tests__/node-types.test.cjs +0 -368
  88. package/dist/__tests__/node-types.test.d.ts +0 -1
  89. package/dist/__tests__/node-types.test.mjs +0 -292
  90. package/dist/__tests__/performance.test.cjs +0 -313
  91. package/dist/__tests__/performance.test.d.ts +0 -1
  92. package/dist/__tests__/performance.test.mjs +0 -218
  93. package/dist/__tests__/plugin-advanced.test.cjs +0 -301
  94. package/dist/__tests__/plugin-advanced.test.d.ts +0 -1
  95. package/dist/__tests__/plugin-advanced.test.mjs +0 -225
  96. package/dist/__tests__/plugin.test.cjs +0 -151
  97. package/dist/__tests__/plugin.test.d.ts +0 -1
  98. package/dist/__tests__/plugin.test.mjs +0 -116
  99. package/dist/__tests__/plugins.test.cjs +0 -412
  100. package/dist/__tests__/plugins.test.d.ts +0 -1
  101. package/dist/__tests__/plugins.test.mjs +0 -402
  102. package/dist/__tests__/screenshot-capture.test.cjs +0 -183
  103. package/dist/__tests__/screenshot-capture.test.d.ts +0 -1
  104. package/dist/__tests__/screenshot-capture.test.mjs +0 -124
  105. package/dist/__tests__/screenshot.test.cjs +0 -74
  106. package/dist/__tests__/screenshot.test.d.ts +0 -1
  107. package/dist/__tests__/screenshot.test.mjs +0 -69
  108. package/dist/__tests__/theme.test.cjs +0 -185
  109. package/dist/__tests__/theme.test.d.ts +0 -1
  110. package/dist/__tests__/theme.test.mjs +0 -191
  111. package/dist/__tests__/transform.test.cjs +0 -384
  112. package/dist/__tests__/transform.test.d.ts +0 -1
  113. package/dist/__tests__/transform.test.mjs +0 -239
  114. package/dist/__tests__/useAlignment.test.cjs +0 -128
  115. package/dist/__tests__/useAlignment.test.d.ts +0 -1
  116. package/dist/__tests__/useAlignment.test.mjs +0 -72
  117. package/dist/__tests__/useEdges.test.cjs +0 -117
  118. package/dist/__tests__/useEdges.test.d.ts +0 -1
  119. package/dist/__tests__/useEdges.test.mjs +0 -80
  120. package/dist/__tests__/useKeyboard.test.cjs +0 -88
  121. package/dist/__tests__/useKeyboard.test.d.ts +0 -1
  122. package/dist/__tests__/useKeyboard.test.mjs +0 -56
  123. package/dist/__tests__/useNodeDistribution.test.cjs +0 -643
  124. package/dist/__tests__/useNodeDistribution.test.d.ts +0 -1
  125. package/dist/__tests__/useNodeDistribution.test.mjs +0 -297
  126. package/dist/__tests__/useNodes.test.cjs +0 -150
  127. package/dist/__tests__/useNodes.test.d.ts +0 -1
  128. package/dist/__tests__/useNodes.test.mjs +0 -80
  129. package/dist/__tests__/useSelection.test.cjs +0 -112
  130. package/dist/__tests__/useSelection.test.d.ts +0 -1
  131. package/dist/__tests__/useSelection.test.mjs +0 -76
  132. package/dist/__tests__/useViewport.test.cjs +0 -171
  133. package/dist/__tests__/useViewport.test.d.ts +0 -1
  134. package/dist/__tests__/useViewport.test.mjs +0 -82
  135. package/dist/__tests__/utils/ssr.cjs +0 -124
  136. package/dist/__tests__/utils/ssr.d.ts +0 -33
  137. package/dist/__tests__/utils/ssr.mjs +0 -129
  138. package/dist/__tests__/validation.test.cjs +0 -95
  139. package/dist/__tests__/validation.test.d.ts +0 -1
  140. package/dist/__tests__/validation.test.mjs +0 -36
  141. package/dist/__tests__/viewport-types.test.cjs +0 -324
  142. package/dist/__tests__/viewport-types.test.d.ts +0 -1
  143. package/dist/__tests__/viewport-types.test.mjs +0 -207
@@ -1,384 +0,0 @@
1
- "use strict";
2
-
3
- var _vitest = require("vitest");
4
- var _transform = require("../utils/transform.cjs");
5
- (0, _vitest.describe)("flow/utils/transform", () => {
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
- });
382
- });
383
- });
384
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,239 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import {
3
- screenToCanvas,
4
- canvasToScreen,
5
- projectNodePosition,
6
- getElementPosition,
7
- getElementCanvasPosition,
8
- distanceBetweenPoints,
9
- getVector,
10
- getVectorMagnitude,
11
- normalizeVector,
12
- snapToGrid,
13
- snapPositionToGrid
14
- } from "../utils/transform.mjs";
15
- describe("flow/utils/transform", () => {
16
- describe("screenToCanvas", () => {
17
- it("should convert screen coordinates to canvas coordinates", () => {
18
- const transform = { x: 100, y: 50, zoom: 2 };
19
- const canvas = screenToCanvas(300, 250, transform);
20
- expect(canvas.x).toBe(100);
21
- expect(canvas.y).toBe(100);
22
- });
23
- it("should handle zoom of 1", () => {
24
- const transform = { x: 0, y: 0, zoom: 1 };
25
- const canvas = screenToCanvas(100, 200, transform);
26
- expect(canvas.x).toBe(100);
27
- expect(canvas.y).toBe(200);
28
- });
29
- it("should handle negative transform offsets", () => {
30
- const transform = { x: -100, y: -50, zoom: 1 };
31
- const canvas = screenToCanvas(50, 100, transform);
32
- expect(canvas.x).toBe(150);
33
- expect(canvas.y).toBe(150);
34
- });
35
- it("should handle fractional zoom", () => {
36
- const transform = { x: 0, y: 0, zoom: 0.5 };
37
- const canvas = screenToCanvas(100, 200, transform);
38
- expect(canvas.x).toBe(200);
39
- expect(canvas.y).toBe(400);
40
- });
41
- });
42
- describe("canvasToScreen", () => {
43
- it("should convert canvas coordinates to screen coordinates", () => {
44
- const transform = { x: 100, y: 50, zoom: 2 };
45
- const screen = canvasToScreen(100, 100, transform);
46
- expect(screen.x).toBe(300);
47
- expect(screen.y).toBe(250);
48
- });
49
- it("should handle zoom of 1", () => {
50
- const transform = { x: 0, y: 0, zoom: 1 };
51
- const screen = canvasToScreen(100, 200, transform);
52
- expect(screen.x).toBe(100);
53
- expect(screen.y).toBe(200);
54
- });
55
- it("should be inverse of screenToCanvas", () => {
56
- const transform = { x: 100, y: 50, zoom: 2 };
57
- const original = { x: 300, y: 250 };
58
- const canvas = screenToCanvas(original.x, original.y, transform);
59
- const back = canvasToScreen(canvas.x, canvas.y, transform);
60
- expect(back.x).toBeCloseTo(original.x);
61
- expect(back.y).toBeCloseTo(original.y);
62
- });
63
- });
64
- describe("projectNodePosition", () => {
65
- it("should transform position between viewports", () => {
66
- const from = { x: 100, y: 50, zoom: 2 };
67
- const to = { x: -50, y: 100, zoom: 1 };
68
- const position = { x: 300, y: 250 };
69
- const projected = projectNodePosition(position, from, to);
70
- expect(projected).toHaveProperty("x");
71
- expect(projected).toHaveProperty("y");
72
- });
73
- it("should handle identical viewports", () => {
74
- const transform = { x: 0, y: 0, zoom: 1 };
75
- const position = { x: 100, y: 200 };
76
- const projected = projectNodePosition(position, transform, transform);
77
- expect(projected).toEqual(position);
78
- });
79
- });
80
- describe("getElementPosition", () => {
81
- it("should calculate element position relative to container", () => {
82
- const mockElement = {
83
- getBoundingClientRect: () => ({ left: 100, top: 50 })
84
- };
85
- const mockContainer = {
86
- getBoundingClientRect: () => ({ left: 50, top: 25 })
87
- };
88
- const pos = getElementPosition(mockElement, mockContainer);
89
- expect(pos.x).toBe(50);
90
- expect(pos.y).toBe(25);
91
- });
92
- it("should handle element at container origin", () => {
93
- const mockElement = {
94
- getBoundingClientRect: () => ({ left: 100, top: 100 })
95
- };
96
- const mockContainer = {
97
- getBoundingClientRect: () => ({ left: 100, top: 100 })
98
- };
99
- const pos = getElementPosition(mockElement, mockContainer);
100
- expect(pos.x).toBe(0);
101
- expect(pos.y).toBe(0);
102
- });
103
- });
104
- describe("getElementCanvasPosition", () => {
105
- it("should get element position in canvas coordinates", () => {
106
- const mockElement = {
107
- getBoundingClientRect: () => ({ left: 200, top: 150 })
108
- };
109
- const mockContainer = {
110
- getBoundingClientRect: () => ({ left: 100, y: 50 })
111
- };
112
- const transform = { x: 0, y: 0, zoom: 1 };
113
- const pos = getElementCanvasPosition(mockElement, mockContainer, transform);
114
- expect(pos).toHaveProperty("x");
115
- expect(pos).toHaveProperty("y");
116
- });
117
- });
118
- describe("distanceBetweenPoints", () => {
119
- it("should calculate distance between two points", () => {
120
- const p1 = { x: 0, y: 0 };
121
- const p2 = { x: 3, y: 4 };
122
- expect(distanceBetweenPoints(p1, p2)).toBe(5);
123
- });
124
- it("should return 0 for same point", () => {
125
- const p = { x: 100, y: 100 };
126
- expect(distanceBetweenPoints(p, p)).toBe(0);
127
- });
128
- it("should handle negative coordinates", () => {
129
- const p1 = { x: -3, y: -4 };
130
- const p2 = { x: 0, y: 0 };
131
- expect(distanceBetweenPoints(p1, p2)).toBe(5);
132
- });
133
- });
134
- describe("getVector", () => {
135
- it("should calculate vector from source to target", () => {
136
- const source = { x: 10, y: 20 };
137
- const target = { x: 30, y: 50 };
138
- const vector = getVector(source, target);
139
- expect(vector).toEqual({ x: 20, y: 30 });
140
- });
141
- it("should handle zero vector", () => {
142
- const source = { x: 100, y: 100 };
143
- const target = { x: 100, y: 100 };
144
- const vector = getVector(source, target);
145
- expect(vector).toEqual({ x: 0, y: 0 });
146
- });
147
- it("should handle negative results", () => {
148
- const source = { x: 50, y: 50 };
149
- const target = { x: 30, y: 20 };
150
- const vector = getVector(source, target);
151
- expect(vector).toEqual({ x: -20, y: -30 });
152
- });
153
- });
154
- describe("getVectorMagnitude", () => {
155
- it("should calculate magnitude of vector", () => {
156
- const vector = { x: 3, y: 4 };
157
- expect(getVectorMagnitude(vector)).toBe(5);
158
- });
159
- it("should return 0 for zero vector", () => {
160
- const vector = { x: 0, y: 0 };
161
- expect(getVectorMagnitude(vector)).toBe(0);
162
- });
163
- it("should handle negative components", () => {
164
- const vector = { x: -3, y: -4 };
165
- expect(getVectorMagnitude(vector)).toBe(5);
166
- });
167
- });
168
- describe("normalizeVector", () => {
169
- it("should normalize a unit vector", () => {
170
- const vector = { x: 3, y: 4 };
171
- const normalized = normalizeVector(vector);
172
- expect(normalized.x).toBeCloseTo(0.6);
173
- expect(normalized.y).toBeCloseTo(0.8);
174
- });
175
- it("should return zero vector for zero magnitude", () => {
176
- const vector = { x: 0, y: 0 };
177
- const normalized = normalizeVector(vector);
178
- expect(normalized).toEqual({ x: 0, y: 0 });
179
- });
180
- it("should produce unit magnitude vector", () => {
181
- const vector = { x: 5, y: 12 };
182
- const normalized = normalizeVector(vector);
183
- const magnitude = getVectorMagnitude(normalized);
184
- expect(magnitude).toBeCloseTo(1);
185
- });
186
- it("should handle negative components", () => {
187
- const vector = { x: -5, y: 0 };
188
- const normalized = normalizeVector(vector);
189
- expect(normalized.x).toBe(-1);
190
- expect(normalized.y).toBe(0);
191
- });
192
- });
193
- describe("snapToGrid", () => {
194
- it("should snap value to nearest grid point", () => {
195
- expect(snapToGrid(0, 10)).toBe(0);
196
- expect(snapToGrid(5, 10)).toBe(10);
197
- expect(snapToGrid(10, 10)).toBe(10);
198
- expect(snapToGrid(15, 10)).toBe(20);
199
- });
200
- it("should snap negative values toward zero", () => {
201
- expect(snapToGrid(-15, 10)).toBe(-10);
202
- expect(snapToGrid(-25, 10)).toBe(-20);
203
- expect(snapToGrid(-55, 10)).toBe(-50);
204
- });
205
- it("should snap very small negative values to zero", () => {
206
- const result = snapToGrid(-5, 10);
207
- expect(Object.is(result, -0) || result === 0).toBe(true);
208
- });
209
- it("should handle fractional values", () => {
210
- expect(snapToGrid(2.5, 10)).toBe(0);
211
- expect(snapToGrid(7.5, 10)).toBe(10);
212
- });
213
- it("should handle non-10 grid size", () => {
214
- expect(snapToGrid(5, 5)).toBe(5);
215
- expect(snapToGrid(7, 5)).toBe(5);
216
- expect(snapToGrid(8, 5)).toBe(10);
217
- });
218
- });
219
- describe("snapPositionToGrid", () => {
220
- it("should snap x and y independently", () => {
221
- const pos = { x: 17, y: 23 };
222
- const grid = [10, 5];
223
- const snapped = snapPositionToGrid(pos, grid);
224
- expect(snapped).toEqual({ x: 20, y: 25 });
225
- });
226
- it("should handle zero coordinates", () => {
227
- const pos = { x: 0, y: 0 };
228
- const grid = [10, 5];
229
- const snapped = snapPositionToGrid(pos, grid);
230
- expect(snapped).toEqual({ x: 0, y: 0 });
231
- });
232
- it("should handle different grid sizes for x and y", () => {
233
- const pos = { x: 100, y: 200 };
234
- const grid = [20, 25];
235
- const snapped = snapPositionToGrid(pos, grid);
236
- expect(snapped).toEqual({ x: 100, y: 200 });
237
- });
238
- });
239
- });