@html-graph/html-graph 0.0.47 → 0.0.48

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/main.js CHANGED
@@ -1,8 +1,8 @@
1
1
  var F = Object.defineProperty;
2
- var k = (n, t, e) => t in n ? F(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
3
- var r = (n, t, e) => k(n, typeof t != "symbol" ? t + "" : t, e);
2
+ var k = (s, t, e) => t in s ? F(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
+ var r = (s, t, e) => k(s, typeof t != "symbol" ? t + "" : t, e);
4
4
  class j {
5
- constructor(t, e, o, s, i) {
5
+ constructor(t, e, o, n, i) {
6
6
  r(this, "canvasWrapper", null);
7
7
  r(this, "host");
8
8
  r(this, "nodesContainer");
@@ -39,8 +39,8 @@ class j {
39
39
  },
40
40
  moveOnTop: (t) => {
41
41
  const e = this.nodeIdToWrapperElementMap.get(t);
42
- this.currentZIndex += 2, e.style.zIndex = `${this.currentZIndex}`, this.graphStore.getNodeAdjacentConnections(t).forEach((s) => {
43
- this.connectionIdToElementMap.get(s).style.zIndex = `${this.currentZIndex - 1}`;
42
+ this.currentZIndex += 2, e.style.zIndex = `${this.currentZIndex}`, this.graphStore.getNodeAdjacentConnections(t).forEach((n) => {
43
+ this.connectionIdToElementMap.get(n).style.zIndex = `${this.currentZIndex - 1}`;
44
44
  });
45
45
  }
46
46
  },
@@ -58,7 +58,7 @@ class j {
58
58
  }
59
59
  }
60
60
  });
61
- this.graphStore = t, this.viewportTransformer = e, this.publicViewportTransformer = o, this.layersMode = s, this.backgroundDrawingFn = i, this.host = this.createHost(), this.canvas = this.createCanvas(), this.nodesContainer = this.createNodesContainer(), this.connectionsContainer = this.createConnectionsContainer();
61
+ this.graphStore = t, this.viewportTransformer = e, this.publicViewportTransformer = o, this.layersMode = n, this.backgroundDrawingFn = i, this.host = this.createHost(), this.canvas = this.createCanvas(), this.nodesContainer = this.createNodesContainer(), this.connectionsContainer = this.createConnectionsContainer();
62
62
  const h = this.canvas.getContext("2d");
63
63
  if (h === null)
64
64
  throw new Error("unable to get canvas context");
@@ -75,10 +75,10 @@ class j {
75
75
  this.canvasWrapper = t, this.canvasWrapper.appendChild(this.host);
76
76
  }
77
77
  detach() {
78
- this.canvasWrapper !== null && this.canvasWrapper.removeChild(this.host);
78
+ this.canvasWrapper !== null && (this.canvasWrapper.removeChild(this.host), this.canvasWrapper = null);
79
79
  }
80
80
  destroy() {
81
- this.hostResizeObserver.disconnect(), this.nodesResizeObserver.disconnect(), this.host.removeChild(this.canvas), this.host.removeChild(this.connectionsContainer), this.host.removeChild(this.nodesContainer), this.canvasWrapper !== null && this.canvasWrapper.removeChild(this.host);
81
+ this.hostResizeObserver.disconnect(), this.nodesResizeObserver.disconnect(), this.host.removeChild(this.canvas), this.host.removeChild(this.connectionsContainer), this.host.removeChild(this.nodesContainer), this.canvasWrapper !== null && (this.canvasWrapper.removeChild(this.host), this.canvasWrapper = null);
82
82
  }
83
83
  applyTransform() {
84
84
  this.backgroundDrawingFn(this.canvasCtx, this.publicViewportTransformer);
@@ -106,10 +106,10 @@ class j {
106
106
  moveNodeOnTop(t) {
107
107
  this.layers[this.layersMode].moveOnTop(t);
108
108
  }
109
- updateNodePosition(t) {
109
+ updateNodeCoordinates(t) {
110
110
  const e = this.graphStore.getNode(t), o = this.graphStore.getNodeAdjacentConnections(t);
111
- this.updateNodeCoords(t, e.x, e.y), o.forEach((s) => {
112
- this.updateConnectionCoords(s);
111
+ this.updateNodeCoords(t, e.x, e.y), o.forEach((n) => {
112
+ this.updateConnectionCoords(n);
113
113
  });
114
114
  }
115
115
  updatePortConnections(t) {
@@ -145,8 +145,8 @@ class j {
145
145
  createNodesResizeObserver() {
146
146
  return new ResizeObserver((t) => {
147
147
  t.forEach((e) => {
148
- const o = e.target, s = this.nodeWrapperElementToIdMap.get(o), i = this.graphStore.getNode(s);
149
- this.updateNodeCoords(s, i.x, i.y), this.graphStore.getNodeAdjacentConnections(s).forEach((a) => {
148
+ const o = e.target, n = this.nodeWrapperElementToIdMap.get(o), i = this.graphStore.getNode(n);
149
+ this.updateNodeCoords(n, i.x, i.y), this.graphStore.getNodeAdjacentConnections(n).forEach((a) => {
150
150
  this.updateConnectionCoords(a);
151
151
  });
152
152
  });
@@ -157,11 +157,11 @@ class j {
157
157
  this.canvas.width = t, this.canvas.height = e;
158
158
  }
159
159
  updateNodeCoords(t, e, o) {
160
- const s = this.nodeIdToWrapperElementMap.get(t), { width: i, height: h } = s.getBoundingClientRect(), a = this.viewportTransformer.getAbsScale(), c = this.graphStore.getNode(t), [l, g] = c.centerFn(i, h);
161
- s.style.transform = `matrix(1, 0, 0, 1, ${e - a * l}, ${o - a * g})`;
160
+ const n = this.nodeIdToWrapperElementMap.get(t), { width: i, height: h } = n.getBoundingClientRect(), a = this.viewportTransformer.getAbsScale(), c = this.graphStore.getNode(t), [l, g] = c.centerFn(i, h);
161
+ n.style.transform = `matrix(1, 0, 0, 1, ${e - a * l}, ${o - a * g})`;
162
162
  }
163
163
  updateConnectionCoords(t) {
164
- const e = this.graphStore.getConnection(t), o = this.graphStore.getPort(e.from), s = this.graphStore.getPort(e.to), i = o.element.getBoundingClientRect(), h = s.element.getBoundingClientRect(), a = this.host.getBoundingClientRect(), [c, l] = this.viewportTransformer.getAbsCoords(
164
+ const e = this.graphStore.getConnection(t), o = this.graphStore.getPort(e.from), n = this.graphStore.getPort(e.to), i = o.element.getBoundingClientRect(), h = n.element.getBoundingClientRect(), a = this.host.getBoundingClientRect(), [c, l] = this.viewportTransformer.getAbsCoords(
165
165
  i.left - a.left,
166
166
  i.top - a.top
167
167
  ), [g, d] = this.viewportTransformer.getAbsCoords(
@@ -170,11 +170,11 @@ class j {
170
170
  ), m = this.viewportTransformer.getAbsScale(), [u, p] = o.centerFn(
171
171
  i.width * m,
172
172
  i.height * m
173
- ), [f, y] = s.centerFn(
173
+ ), [C, w] = n.centerFn(
174
174
  h.width * m,
175
175
  h.height * m
176
- ), S = u + c, b = p + l, N = f + g, C = y + d, w = Math.min(S, N), T = Math.min(b, C), E = Math.abs(N - S), x = Math.abs(C - b), M = this.connectionIdToElementMap.get(t), L = S <= N, V = b <= C;
177
- M.style.transform = `matrix(${L ? 1 : -1}, 0, 0, ${V ? 1 : -1}, ${w}, ${T})`, e.controller.update(w, T, E, x, o, s);
176
+ ), b = u + c, T = p + l, S = C + g, f = w + d, y = Math.min(b, S), N = Math.min(T, f), E = Math.abs(S - b), O = Math.abs(f - T), x = this.connectionIdToElementMap.get(t), L = b <= S, V = T <= f;
177
+ x.style.transform = `matrix(${L ? 1 : -1}, 0, 0, ${V ? 1 : -1}, ${y}, ${N})`, e.controller.update(y, N, E, O, o, n);
178
178
  }
179
179
  }
180
180
  class D {
@@ -185,42 +185,6 @@ class D {
185
185
  y: 0
186
186
  });
187
187
  }
188
- /**
189
- * dx2 - traslate x
190
- * dy2 - traslate y
191
- *
192
- * direct transform
193
- * s1 0 dx1 1 0 dx2
194
- * 0 s1 dy1 0 1 dy2
195
- * 0 0 1 0 0 1
196
- *
197
- * [s, dx, dy] = [s1, s * dx2 + dx1, s * dy2 + dy1]
198
- */
199
- applyShift(t, e) {
200
- this.state = {
201
- scale: this.state.scale,
202
- x: this.state.scale * t + this.state.x,
203
- y: this.state.scale * e + this.state.y
204
- };
205
- }
206
- /**
207
- * s2 - scale
208
- * cx - scale pivot x
209
- * cy - scale pivot y
210
- *
211
- * s1 0 dx1 s2 0 (1 - s2) * cx
212
- * 0 s1 dy1 0 s2 (1 - s2) * cy
213
- * 0 0 1 0 0 1
214
- *
215
- * [s, dx, dy] = [s1 * s2, s1 * (1 - s2) * cx + dx1, s1 * (1 - s2) * cy + dy1]
216
- */
217
- applyScale(t, e, o) {
218
- this.state = {
219
- scale: this.state.scale * t,
220
- x: this.state.scale * (1 - t) * e + this.state.x,
221
- y: this.state.scale * (1 - t) * o + this.state.y
222
- };
223
- }
224
188
  getViewCoords(t, e) {
225
189
  return [
226
190
  (t - this.state.x) / this.state.scale,
@@ -292,16 +256,10 @@ class R {
292
256
  r(this, "cycleConnections", /* @__PURE__ */ Object.create(null));
293
257
  }
294
258
  getAllNodes() {
295
- return Object.keys(this.nodes);
296
- }
297
- getAllPorts() {
298
- return Object.keys(this.ports);
299
- }
300
- getAllConnections() {
301
- return Object.keys(this.connections);
259
+ return this.nodes;
302
260
  }
303
- addNode(t, e, o, s, i) {
304
- this.nodes[t] = { element: e, x: o, y: s, centerFn: i }, this.nodePorts[t] = /* @__PURE__ */ Object.create(null);
261
+ addNode(t, e, o, n, i) {
262
+ this.nodes[t] = { element: e, x: o, y: n, centerFn: i }, this.nodePorts[t] = /* @__PURE__ */ Object.create(null);
305
263
  }
306
264
  hasNode(t) {
307
265
  return this.nodes[t] !== void 0;
@@ -316,16 +274,16 @@ class R {
316
274
  this.connections[t].controller = e;
317
275
  }
318
276
  removeNode(t) {
319
- this.getNodeAdjacentConnections(t).forEach((s) => {
320
- this.removeConnection(s);
277
+ this.getNodeAdjacentConnections(t).forEach((n) => {
278
+ this.removeConnection(n);
321
279
  }), delete this.nodes[t];
322
280
  const o = this.nodePorts[t];
323
- Object.keys(o).forEach((s) => {
324
- delete this.portNodeId[s];
281
+ Object.keys(o).forEach((n) => {
282
+ delete this.portNodeId[n];
325
283
  }), delete this.nodePorts[t];
326
284
  }
327
- addPort(t, e, o, s, i) {
328
- this.ports[t] = { element: e, centerFn: s, direction: i }, this.cycleConnections[t] = {}, this.incommingConnections[t] = {}, this.outcommingConnections[t] = {}, this.portNodeId[t] = o;
285
+ addPort(t, e, o, n, i) {
286
+ this.ports[t] = { element: e, centerFn: n, direction: i }, this.cycleConnections[t] = {}, this.incommingConnections[t] = {}, this.outcommingConnections[t] = {}, this.portNodeId[t] = o;
329
287
  const h = this.nodePorts[o];
330
288
  h !== void 0 && (h[t] = e);
331
289
  }
@@ -339,23 +297,23 @@ class R {
339
297
  return this.portNodeId[t] !== void 0;
340
298
  }
341
299
  removePort(t) {
342
- Object.keys(this.cycleConnections[t]).forEach((s) => {
343
- this.removeConnection(s);
344
- }), delete this.cycleConnections[t], Object.keys(this.incommingConnections[t]).forEach((s) => {
345
- this.removeConnection(s);
346
- }), delete this.incommingConnections[t], Object.keys(this.outcommingConnections[t]).forEach((s) => {
347
- this.removeConnection(s);
300
+ Object.keys(this.cycleConnections[t]).forEach((n) => {
301
+ this.removeConnection(n);
302
+ }), delete this.cycleConnections[t], Object.keys(this.incommingConnections[t]).forEach((n) => {
303
+ this.removeConnection(n);
304
+ }), delete this.incommingConnections[t], Object.keys(this.outcommingConnections[t]).forEach((n) => {
305
+ this.removeConnection(n);
348
306
  }), delete this.outcommingConnections[t];
349
307
  const e = this.portNodeId[t];
350
308
  delete this.portNodeId[t];
351
309
  const o = this.nodePorts[e];
352
310
  delete o[t], delete this.ports[t];
353
311
  }
354
- addConnection(t, e, o, s) {
312
+ addConnection(t, e, o, n) {
355
313
  this.connections[t] = {
356
314
  from: e,
357
315
  to: o,
358
- controller: s
316
+ controller: n
359
317
  }, e !== o ? (this.outcommingConnections[e][t] = !0, this.incommingConnections[o][t] = !0) : this.cycleConnections[e][t] = !0;
360
318
  }
361
319
  getConnection(t) {
@@ -365,8 +323,25 @@ class R {
365
323
  return this.connections[t] !== void 0;
366
324
  }
367
325
  removeConnection(t) {
368
- const e = this.connections[t], o = e.from, s = e.to;
369
- delete this.cycleConnections[o][t], delete this.cycleConnections[s][t], delete this.incommingConnections[o][t], delete this.incommingConnections[s][t], delete this.outcommingConnections[o][t], delete this.outcommingConnections[s][t], delete this.connections[t];
326
+ const e = this.connections[t], o = e.from, n = e.to;
327
+ delete this.cycleConnections[o][t], delete this.cycleConnections[n][t], delete this.incommingConnections[o][t], delete this.incommingConnections[n][t], delete this.outcommingConnections[o][t], delete this.outcommingConnections[n][t], delete this.connections[t];
328
+ }
329
+ getPortAdjacentConnections(t) {
330
+ return [
331
+ ...this.getPortIncomingConnections(t),
332
+ ...this.getPortOutcomingConnections(t),
333
+ ...this.getPortCycleConnections(t)
334
+ ];
335
+ }
336
+ getNodeAdjacentConnections(t) {
337
+ return [
338
+ ...this.getNodeIncomingConnections(t),
339
+ ...this.getNodeOutcomingConnections(t),
340
+ ...this.getNodeCycleConnections(t)
341
+ ];
342
+ }
343
+ clear() {
344
+ this.nodes = /* @__PURE__ */ Object.create(null), this.ports = /* @__PURE__ */ Object.create(null), this.nodePorts = /* @__PURE__ */ Object.create(null), this.portNodeId = /* @__PURE__ */ Object.create(null), this.connections = /* @__PURE__ */ Object.create(null), this.incommingConnections = /* @__PURE__ */ Object.create(null), this.outcommingConnections = /* @__PURE__ */ Object.create(null), this.cycleConnections = /* @__PURE__ */ Object.create(null);
370
345
  }
371
346
  getPortIncomingConnections(t) {
372
347
  return Object.keys(this.incommingConnections[t] ?? {});
@@ -377,44 +352,27 @@ class R {
377
352
  getPortCycleConnections(t) {
378
353
  return Object.keys(this.cycleConnections[t] ?? {});
379
354
  }
380
- getPortAdjacentConnections(t) {
381
- return [
382
- ...this.getPortIncomingConnections(t),
383
- ...this.getPortOutcomingConnections(t),
384
- ...this.getPortCycleConnections(t)
385
- ];
386
- }
387
355
  getNodeIncomingConnections(t) {
388
356
  const e = Object.keys(this.nodePorts[t]);
389
357
  let o = [];
390
- return e.forEach((s) => {
391
- o = [...o, ...this.getPortIncomingConnections(s)];
358
+ return e.forEach((n) => {
359
+ o = [...o, ...this.getPortIncomingConnections(n)];
392
360
  }), o;
393
361
  }
394
362
  getNodeOutcomingConnections(t) {
395
363
  const e = Object.keys(this.nodePorts[t]);
396
364
  let o = [];
397
- return e.forEach((s) => {
398
- o = [...o, ...this.getPortOutcomingConnections(s)];
365
+ return e.forEach((n) => {
366
+ o = [...o, ...this.getPortOutcomingConnections(n)];
399
367
  }), o;
400
368
  }
401
369
  getNodeCycleConnections(t) {
402
370
  const e = Object.keys(this.nodePorts[t]);
403
371
  let o = [];
404
- return e.forEach((s) => {
405
- o = [...o, ...this.getPortCycleConnections(s)];
372
+ return e.forEach((n) => {
373
+ o = [...o, ...this.getPortCycleConnections(n)];
406
374
  }), o;
407
375
  }
408
- getNodeAdjacentConnections(t) {
409
- return [
410
- ...this.getNodeIncomingConnections(t),
411
- ...this.getNodeOutcomingConnections(t),
412
- ...this.getNodeCycleConnections(t)
413
- ];
414
- }
415
- clear() {
416
- this.nodes = /* @__PURE__ */ Object.create(null), this.ports = /* @__PURE__ */ Object.create(null), this.nodePorts = /* @__PURE__ */ Object.create(null), this.portNodeId = /* @__PURE__ */ Object.create(null), this.connections = /* @__PURE__ */ Object.create(null), this.incommingConnections = /* @__PURE__ */ Object.create(null), this.outcommingConnections = /* @__PURE__ */ Object.create(null), this.cycleConnections = /* @__PURE__ */ Object.create(null);
417
- }
418
376
  }
419
377
  class z {
420
378
  constructor(t) {
@@ -422,62 +380,29 @@ class z {
422
380
  }
423
381
  getNode(t) {
424
382
  const e = this.graphStore.getNode(t);
425
- return e === void 0 ? null : { x: e.x, y: e.y };
426
- }
427
- getPort(t) {
428
- const e = this.graphStore.getPortNode(t);
429
- return e === void 0 ? null : { nodeId: e };
430
- }
431
- getConnection(t) {
432
- const e = this.graphStore.getConnection(t);
433
- return e === void 0 ? null : { from: e.from, to: e.to };
434
- }
435
- getAllNodes() {
436
- return this.graphStore.getAllNodes();
437
- }
438
- getAllPorts() {
439
- return this.graphStore.getAllPorts();
440
- }
441
- getAllConnections() {
442
- return this.graphStore.getAllConnections();
443
- }
444
- hasNode(t) {
445
- return this.graphStore.hasNode(t);
446
- }
447
- hasPort(t) {
448
- return this.graphStore.hasPort(t);
449
- }
450
- hasConnection(t) {
451
- return this.graphStore.hasConnection(t);
452
- }
453
- getPortIncomingConnections(t) {
454
- return this.graphStore.getPortIncomingConnections(t);
455
- }
456
- getPortOutcomingConnections(t) {
457
- return this.graphStore.getPortOutcomingConnections(t);
458
- }
459
- getPortCycleConnections(t) {
460
- return this.graphStore.getPortCycleConnections(t);
461
- }
462
- getPortAdjacentConnections(t) {
463
- return this.graphStore.getPortAdjacentConnections(t);
464
- }
465
- getNodeIncomingConnections(t) {
466
- return this.graphStore.getNodeIncomingConnections(t);
467
- }
468
- getNodeOutcomingConnections(t) {
469
- return this.graphStore.getNodeOutcomingConnections(t);
470
- }
471
- getNodeCycleConnections(t) {
472
- return this.graphStore.getNodeCycleConnections(t);
473
- }
474
- getNodeAdjacentConnections(t) {
475
- return this.graphStore.getNodeAdjacentConnections(t);
383
+ return e === void 0 ? null : { x: e.x, y: e.y, element: e.element };
384
+ }
385
+ getNodes(t) {
386
+ const e = Object.entries(this.graphStore.getAllNodes()).map(
387
+ ([o, n]) => ({
388
+ id: o,
389
+ x: n.x,
390
+ y: n.y,
391
+ element: n.element
392
+ })
393
+ );
394
+ if (t !== void 0) {
395
+ const o = /* @__PURE__ */ new Set();
396
+ return t.forEach((n) => {
397
+ o.add(n);
398
+ }), e.filter((n) => o.has(n.id));
399
+ }
400
+ return e;
476
401
  }
477
402
  }
478
403
  class v {
479
404
  static getPortCenter(t) {
480
- const { top: e, left: o, width: s, height: i } = t.element.getBoundingClientRect(), h = t.centerFn(s, i);
405
+ const { top: e, left: o, width: n, height: i } = t.element.getBoundingClientRect(), h = t.centerFn(n, i);
481
406
  return [o + h[0], e + h[1]];
482
407
  }
483
408
  static rotate(t, e, o) {
@@ -489,30 +414,30 @@ class v {
489
414
  static getDirectionVector(t, e, o) {
490
415
  return [e * Math.cos(t ?? 0), o * Math.sin(t ?? 0)];
491
416
  }
492
- static getArrowPath(t, e, o, s, i) {
417
+ static getArrowPath(t, e, o, n, i) {
493
418
  const a = [
494
419
  [0, 0],
495
- [s, i],
496
- [s, -i]
420
+ [n, i],
421
+ [n, -i]
497
422
  ].map((d) => this.rotate(d, t, [0, 0])).map((d) => [d[0] + e, d[1] + o]), c = `M ${a[0][0]} ${a[0][1]}`, l = `L ${a[1][0]} ${a[1][1]}`, g = `L ${a[2][0]} ${a[2][1]}`;
498
423
  return `${c} ${l} ${g}`;
499
424
  }
500
- static getArrowOffsetPath(t, e, o, s, i) {
425
+ static getArrowOffsetPath(t, e, o, n, i) {
501
426
  const a = [
502
- [s, 0],
503
- [s + i, 0]
427
+ [n, 0],
428
+ [n + i, 0]
504
429
  ].map((c) => this.rotate(c, t, [0, 0])).map((c) => [c[0] + e, c[1] + o]);
505
430
  return `M ${a[0][0]} ${a[0][1]} L ${a[1][0]} ${a[1][1]}`;
506
431
  }
507
432
  }
508
433
  class G {
509
- constructor(t, e, o, s, i, h, a) {
434
+ constructor(t, e, o, n, i, h, a) {
510
435
  r(this, "svg");
511
436
  r(this, "group");
512
437
  r(this, "line");
513
438
  r(this, "sourceArrow", null);
514
439
  r(this, "targetArrow", null);
515
- this.color = t, this.width = e, this.curvature = o, this.arrowLength = s, this.arrowWidth = i, this.hasSourceArrow = h, this.hasTargetArrow = a, this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"), this.svg.style.pointerEvents = "none", this.group = document.createElementNS("http://www.w3.org/2000/svg", "g"), this.svg.appendChild(this.group), this.line = document.createElementNS("http://www.w3.org/2000/svg", "path"), this.line.setAttribute("stroke", this.color), this.line.setAttribute("stroke-width", `${this.width}`), this.line.setAttribute("fill", "none"), this.group.appendChild(this.line), this.group.style.transformOrigin = "50% 50%", this.hasSourceArrow && (this.sourceArrow = document.createElementNS(
440
+ this.color = t, this.width = e, this.curvature = o, this.arrowLength = n, this.arrowWidth = i, this.hasSourceArrow = h, this.hasTargetArrow = a, this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"), this.svg.style.pointerEvents = "none", this.group = document.createElementNS("http://www.w3.org/2000/svg", "g"), this.svg.appendChild(this.group), this.line = document.createElementNS("http://www.w3.org/2000/svg", "path"), this.line.setAttribute("stroke", this.color), this.line.setAttribute("stroke-width", `${this.width}`), this.line.setAttribute("fill", "none"), this.group.appendChild(this.line), this.group.style.transformOrigin = "50% 50%", this.hasSourceArrow && (this.sourceArrow = document.createElementNS(
516
441
  "http://www.w3.org/2000/svg",
517
442
  "path"
518
443
  ), this.sourceArrow.setAttribute("fill", this.color), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = document.createElementNS(
@@ -520,8 +445,8 @@ class G {
520
445
  "path"
521
446
  ), this.targetArrow.setAttribute("fill", this.color), this.group.appendChild(this.targetArrow)), this.svg.style.overflow = "visible";
522
447
  }
523
- update(t, e, o, s, i, h) {
524
- this.svg.style.width = `${o}px`, this.svg.style.height = `${s}px`;
448
+ update(t, e, o, n, i, h) {
449
+ this.svg.style.width = `${o}px`, this.svg.style.height = `${n}px`;
525
450
  const a = v.getPortCenter(i), c = v.getPortCenter(h), l = a[0] <= c[0] ? 1 : -1, g = a[1] <= c[1] ? 1 : -1;
526
451
  this.svg.style.transform = `translate(${t}px, ${e}px)`, this.group.style.transform = `scale(${l}, ${g})`;
527
452
  const d = v.getDirectionVector(
@@ -537,55 +462,55 @@ class G {
537
462
  d,
538
463
  [0, 0]
539
464
  ), p = v.rotate(
540
- [o - this.arrowLength, s],
465
+ [o - this.arrowLength, n],
541
466
  m,
542
- [o, s]
543
- ), f = [
467
+ [o, n]
468
+ ), C = [
544
469
  u[0] + d[0] * this.curvature,
545
470
  u[1] + d[1] * this.curvature
546
- ], y = [
471
+ ], w = [
547
472
  p[0] - m[0] * this.curvature,
548
473
  p[1] - m[1] * this.curvature
549
- ], S = `M ${u[0]} ${u[1]}`, b = `C ${f[0]} ${f[1]}, ${y[0]} ${y[1]}, ${p[0]} ${p[1]}`, N = `M 0 0 L ${u[0]} ${u[1]} `, C = ` M ${p[0]} ${p[1]} L ${o} ${s}`, w = `${this.sourceArrow ? "" : N}${S} ${b}${this.targetArrow ? "" : C}`;
550
- if (this.line.setAttribute("d", w), this.sourceArrow) {
551
- const T = v.getArrowPath(
474
+ ], b = `M ${u[0]} ${u[1]}`, T = `C ${C[0]} ${C[1]}, ${w[0]} ${w[1]}, ${p[0]} ${p[1]}`, S = `M 0 0 L ${u[0]} ${u[1]} `, f = ` M ${p[0]} ${p[1]} L ${o} ${n}`, y = `${this.sourceArrow ? "" : S}${b} ${T}${this.targetArrow ? "" : f}`;
475
+ if (this.line.setAttribute("d", y), this.sourceArrow) {
476
+ const N = v.getArrowPath(
552
477
  d,
553
478
  0,
554
479
  0,
555
480
  this.arrowLength,
556
481
  this.arrowWidth
557
482
  );
558
- this.sourceArrow.setAttribute("d", T);
483
+ this.sourceArrow.setAttribute("d", N);
559
484
  }
560
485
  if (this.targetArrow) {
561
- const T = v.getArrowPath(
486
+ const N = v.getArrowPath(
562
487
  m,
563
488
  o,
564
- s,
489
+ n,
565
490
  -this.arrowLength,
566
491
  this.arrowWidth
567
492
  );
568
- this.targetArrow.setAttribute("d", T);
493
+ this.targetArrow.setAttribute("d", N);
569
494
  }
570
495
  }
571
496
  }
572
- const B = (n) => () => new G(
573
- n.color ?? "#5c5c5c",
574
- n.width ?? 1,
575
- n.curvature ?? 90,
576
- n.arrowLength ?? 15,
577
- n.arrowWidth ?? 4,
578
- n.hasSourceArrow ?? !1,
579
- n.hasTargetArrow ?? !1
497
+ const B = (s) => () => new G(
498
+ s.color ?? "#5c5c5c",
499
+ s.width ?? 1,
500
+ s.curvature ?? 90,
501
+ s.arrowLength ?? 15,
502
+ s.arrowWidth ?? 4,
503
+ s.hasSourceArrow ?? !1,
504
+ s.hasTargetArrow ?? !1
580
505
  );
581
506
  class Y {
582
- constructor(t, e, o, s, i, h, a) {
507
+ constructor(t, e, o, n, i, h, a) {
583
508
  r(this, "svg");
584
509
  r(this, "group");
585
510
  r(this, "line");
586
511
  r(this, "sourceArrow", null);
587
512
  r(this, "targetArrow", null);
588
- this.color = t, this.width = e, this.arrowLength = o, this.arrowWidth = s, this.minPortOffset = i, this.hasSourceArrow = h, this.hasTargetArrow = a, this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"), this.svg.style.pointerEvents = "none", this.group = document.createElementNS("http://www.w3.org/2000/svg", "g"), this.svg.appendChild(this.group), this.line = document.createElementNS("http://www.w3.org/2000/svg", "path"), this.line.setAttribute("stroke", this.color), this.line.setAttribute("stroke-width", `${this.width}`), this.line.setAttribute("fill", "none"), this.group.appendChild(this.line), this.group.style.transformOrigin = "50% 50%", this.hasSourceArrow && (this.sourceArrow = document.createElementNS(
513
+ this.color = t, this.width = e, this.arrowLength = o, this.arrowWidth = n, this.minPortOffset = i, this.hasSourceArrow = h, this.hasTargetArrow = a, this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"), this.svg.style.pointerEvents = "none", this.group = document.createElementNS("http://www.w3.org/2000/svg", "g"), this.svg.appendChild(this.group), this.line = document.createElementNS("http://www.w3.org/2000/svg", "path"), this.line.setAttribute("stroke", this.color), this.line.setAttribute("stroke-width", `${this.width}`), this.line.setAttribute("fill", "none"), this.group.appendChild(this.line), this.group.style.transformOrigin = "50% 50%", this.hasSourceArrow && (this.sourceArrow = document.createElementNS(
589
514
  "http://www.w3.org/2000/svg",
590
515
  "path"
591
516
  ), this.sourceArrow.setAttribute("fill", this.color), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = document.createElementNS(
@@ -593,8 +518,8 @@ class Y {
593
518
  "path"
594
519
  ), this.targetArrow.setAttribute("fill", this.color), this.group.appendChild(this.targetArrow)), this.svg.style.overflow = "visible";
595
520
  }
596
- update(t, e, o, s, i, h) {
597
- this.svg.style.width = `${o}px`, this.svg.style.height = `${s}px`;
521
+ update(t, e, o, n, i, h) {
522
+ this.svg.style.width = `${o}px`, this.svg.style.height = `${n}px`;
598
523
  const a = v.getPortCenter(i), c = v.getPortCenter(h), l = a[0] <= c[0] ? 1 : -1, g = a[1] <= c[1] ? 1 : -1;
599
524
  this.svg.style.transform = `translate(${t}px, ${e}px)`, this.group.style.transform = `scale(${l}, ${g})`;
600
525
  const d = v.getDirectionVector(
@@ -610,23 +535,23 @@ class Y {
610
535
  d,
611
536
  [0, 0]
612
537
  ), p = v.rotate(
613
- [o - this.arrowLength - this.minPortOffset, s],
538
+ [o - this.arrowLength - this.minPortOffset, n],
614
539
  m,
615
- [o, s]
616
- ), [f, y] = [o / 2, s / 2], S = l * (p[0] - u[0]) > 0 ? `M ${u[0]} ${u[1]} L ${f} ${u[1]} L ${f} ${p[1]} L ${p[0]} ${p[1]}` : `M ${u[0]} ${u[1]} L ${u[0]} ${y} L ${p[0]} ${y} L ${p[0]} ${p[1]}`, b = `M 0 0 L ${u[0]} ${u[1]} `, N = ` M ${p[0]} ${p[1]} L ${o} ${s}`, C = v.getArrowOffsetPath(
540
+ [o, n]
541
+ ), [C, w] = [o / 2, n / 2], b = l * (p[0] - u[0]) > 0 ? `M ${u[0]} ${u[1]} L ${C} ${u[1]} L ${C} ${p[1]} L ${p[0]} ${p[1]}` : `M ${u[0]} ${u[1]} L ${u[0]} ${w} L ${p[0]} ${w} L ${p[0]} ${p[1]}`, T = `M 0 0 L ${u[0]} ${u[1]} `, S = ` M ${p[0]} ${p[1]} L ${o} ${n}`, f = v.getArrowOffsetPath(
617
542
  d,
618
543
  0,
619
544
  0,
620
545
  this.arrowLength,
621
546
  this.minPortOffset
622
- ), w = v.getArrowOffsetPath(
547
+ ), y = v.getArrowOffsetPath(
623
548
  m,
624
549
  o,
625
- s,
550
+ n,
626
551
  -this.arrowLength,
627
552
  -this.minPortOffset
628
- ), T = `${this.sourceArrow ? C : b}${S}${this.targetArrow ? w : N}`;
629
- if (this.line.setAttribute("d", T), this.sourceArrow) {
553
+ ), N = `${this.sourceArrow ? f : T}${b}${this.targetArrow ? y : S}`;
554
+ if (this.line.setAttribute("d", N), this.sourceArrow) {
630
555
  const E = v.getArrowPath(
631
556
  d,
632
557
  0,
@@ -640,7 +565,7 @@ class Y {
640
565
  const E = v.getArrowPath(
641
566
  m,
642
567
  o,
643
- s,
568
+ n,
644
569
  -this.arrowLength,
645
570
  this.arrowWidth
646
571
  );
@@ -648,16 +573,16 @@ class Y {
648
573
  }
649
574
  }
650
575
  }
651
- const X = (n) => () => new Y(
652
- n.color,
653
- n.width,
654
- n.arrowLength,
655
- n.arrowWidth,
656
- n.minPortOffset,
657
- n.hasSourceArrow,
658
- n.hasTargetArrow
576
+ const X = (s) => () => new Y(
577
+ s.color,
578
+ s.width,
579
+ s.arrowLength,
580
+ s.arrowWidth,
581
+ s.minPortOffset,
582
+ s.hasSourceArrow,
583
+ s.hasTargetArrow
659
584
  );
660
- var $ = /* @__PURE__ */ ((n) => (n.Regular = "regular", n.Cycle = "cycle", n))($ || {});
585
+ var P = /* @__PURE__ */ ((s) => (s.Regular = "regular", s.Cycle = "cycle", s))(P || {});
661
586
  class A {
662
587
  constructor() {
663
588
  r(this, "counter", 0);
@@ -671,24 +596,18 @@ class A {
671
596
  }
672
597
  }
673
598
  class Z {
674
- constructor(t, e, o, s, i) {
599
+ constructor(t, e, o, n, i) {
675
600
  r(this, "nodeIdGenerator", new A());
676
601
  r(this, "portIdGenerator", new A());
677
602
  r(this, "connectionIdGenerator", new A());
678
- this.graphStore = t, this.htmlController = e, this.viewportTransformer = o, this.nodesCenterFn = s, this.portsCenterFn = i;
603
+ this.graphStore = t, this.htmlController = e, this.viewportTransformer = o, this.nodesCenterFn = n, this.portsCenterFn = i;
679
604
  }
680
605
  moveNodeOnTop(t) {
681
606
  if (!this.graphStore.hasNode(t))
682
607
  throw new Error("failed to move on top nonexisting node");
683
608
  this.htmlController.moveNodeOnTop(t);
684
609
  }
685
- dragNode(t, e, o) {
686
- if (!this.graphStore.hasNode(t))
687
- throw new Error("failed to drag nonexisting node");
688
- const s = this.graphStore.getNode(t), [i, h] = this.viewportTransformer.getViewCoords(s.x, s.y), a = i + e, c = h + o, [l, g] = this.viewportTransformer.getAbsCoords(a, c);
689
- this.graphStore.updateNodeCoords(t, l, g), this.htmlController.updateNodePosition(t);
690
- }
691
- addNode(t, e, o, s, i, h) {
610
+ addNode(t, e, o, n, i, h) {
692
611
  if (t === void 0)
693
612
  do
694
613
  t = this.nodeIdGenerator.next();
@@ -699,7 +618,7 @@ class Z {
699
618
  t,
700
619
  e,
701
620
  o,
702
- s,
621
+ n,
703
622
  h ?? this.nodesCenterFn
704
623
  ), this.htmlController.attachNode(t), i !== void 0 && Object.entries(i).forEach(([a, c]) => {
705
624
  c instanceof HTMLElement ? this.markPort(a, c, t, this.portsCenterFn, null) : this.markPort(
@@ -711,7 +630,7 @@ class Z {
711
630
  );
712
631
  });
713
632
  }
714
- markPort(t, e, o, s, i) {
633
+ markPort(t, e, o, n, i) {
715
634
  if (t === void 0)
716
635
  do
717
636
  t = this.portIdGenerator.next();
@@ -724,7 +643,7 @@ class Z {
724
643
  t,
725
644
  e,
726
645
  o,
727
- s ?? this.portsCenterFn,
646
+ n ?? this.portsCenterFn,
728
647
  i ?? null
729
648
  );
730
649
  }
@@ -740,7 +659,7 @@ class Z {
740
659
  this.removeConnection(e);
741
660
  }), this.graphStore.removePort(t);
742
661
  }
743
- addConnection(t, e, o, s) {
662
+ addConnection(t, e, o, n) {
744
663
  if (t === void 0)
745
664
  do
746
665
  t = this.connectionIdGenerator.next();
@@ -753,7 +672,7 @@ class Z {
753
672
  t,
754
673
  e,
755
674
  o,
756
- s($.Regular)
675
+ n(P.Regular)
757
676
  ), this.htmlController.attachConnection(t);
758
677
  }
759
678
  removeConnection(t) {
@@ -769,28 +688,22 @@ class Z {
769
688
  patchViewportState(t, e, o) {
770
689
  this.viewportTransformer.patchState(t, e, o), this.htmlController.applyTransform();
771
690
  }
772
- moveViewport(t, e) {
773
- this.viewportTransformer.applyShift(t, e), this.htmlController.applyTransform();
774
- }
775
- scaleContent(t, e, o) {
776
- this.viewportTransformer.applyScale(t, e, o), this.htmlController.applyTransform();
777
- }
778
691
  moveToNodes(t) {
779
692
  if (t.length === 0)
780
693
  return;
781
694
  const e = t.map((m) => this.graphStore.getNode(m)).filter((m) => m !== void 0);
782
695
  if (e.length < t.length)
783
696
  throw new Error("failed to move to nonexisting node");
784
- const [o, s] = e.reduce(
697
+ const [o, n] = e.reduce(
785
698
  (m, u) => [m[0] + u.x, m[1] + u.y],
786
699
  [0, 0]
787
- ), i = o / e.length, h = s / e.length, [a, c] = this.htmlController.getViewportDimensions(), l = this.viewportTransformer.getAbsScale(), g = i - l * a / 2, d = h - l * c / 2;
700
+ ), i = o / e.length, h = n / e.length, [a, c] = this.htmlController.getViewportDimensions(), l = this.viewportTransformer.getAbsScale(), g = i - l * a / 2, d = h - l * c / 2;
788
701
  this.patchViewportState(null, g, d);
789
702
  }
790
- updateNodeCoords(t, e, o) {
703
+ updateNodeCoordinates(t, e, o) {
791
704
  if (!this.graphStore.hasNode(t))
792
705
  throw new Error("failed to update coordinates of nonexisting node");
793
- this.graphStore.updateNodeCoords(t, e, o), this.htmlController.updateNodePosition(t);
706
+ this.graphStore.updateNodeCoords(t, e, o), this.htmlController.updateNodeCoordinates(t);
794
707
  }
795
708
  updateConnectionController(t, e) {
796
709
  if (!this.graphStore.hasConnection(t))
@@ -811,122 +724,121 @@ class Z {
811
724
  }
812
725
  }
813
726
  class H {
814
- constructor(t, e, o, s) {
815
- r(this, "htmlController");
816
- r(this, "viewportTransformer");
817
- r(this, "graphStore");
727
+ constructor(t, e, o, n) {
818
728
  r(this, "publicViewportTransformer");
819
729
  r(this, "publicGraphStore");
820
730
  r(this, "canvasController");
821
- this.viewportTransformer = new D(), this.publicViewportTransformer = new W(
822
- this.viewportTransformer
823
- ), this.graphStore = new R(), this.publicGraphStore = new z(this.graphStore), this.htmlController = new j(
824
- this.graphStore,
825
- this.viewportTransformer,
731
+ const i = new D(), h = new R();
732
+ this.publicViewportTransformer = new W(
733
+ i
734
+ ), this.publicGraphStore = new z(h);
735
+ const a = new j(
736
+ h,
737
+ i,
826
738
  this.publicViewportTransformer,
827
739
  t,
828
740
  e
829
- ), this.canvasController = new Z(
830
- this.graphStore,
831
- this.htmlController,
832
- this.viewportTransformer,
741
+ );
742
+ this.canvasController = new Z(
743
+ h,
744
+ a,
745
+ i,
833
746
  o,
834
- s
747
+ n
835
748
  );
836
749
  }
837
750
  }
838
- const P = (n, t) => [
839
- n / 2,
751
+ const $ = (s, t) => [
752
+ s / 2,
840
753
  t / 2
841
754
  ], U = () => () => {
842
- }, q = (n, t, e, o, s, i) => {
843
- n.clearRect(0, 0, n.canvas.width, n.canvas.height), n.save(), n.fillStyle = i, n.fillRect(0, 0, n.canvas.width, n.canvas.height);
755
+ }, J = (s, t, e, o, n, i) => {
756
+ s.clearRect(0, 0, s.canvas.width, s.canvas.height), s.fillStyle = i, s.fillRect(0, 0, s.canvas.width, s.canvas.height);
844
757
  const h = t.getViewCoords(0, 0), a = t.getViewScale(), c = o * a;
845
758
  let l = 0, g = 0, d = c / 2;
846
759
  do
847
- d *= 2, l = n.canvas.width / d, g = n.canvas.height / d;
760
+ d *= 2, l = s.canvas.width / d, g = s.canvas.height / d;
848
761
  while (l * g > 1e4);
849
- const m = h[0] - Math.floor(h[0] / d) * d, u = h[1] - Math.floor(h[1] / d) * d, p = s * a, f = 2 * Math.PI, y = m - d, S = u - d, b = n.canvas.width + m, N = n.canvas.height + u;
850
- n.fillStyle = e;
851
- for (let C = y; C <= b; C += d)
852
- for (let w = S; w <= N; w += d)
853
- n.beginPath(), n.arc(C, w, p, 0, f), n.closePath(), n.fill();
854
- n.restore();
855
- }, J = (n, t, e, o) => (s, i) => {
856
- q(
857
- s,
858
- i,
762
+ const m = h[0] - Math.floor(h[0] / d) * d, u = h[1] - Math.floor(h[1] / d) * d, p = n * a, C = 2 * Math.PI, w = m - d, b = u - d, T = s.canvas.width + m, S = s.canvas.height + u;
763
+ s.fillStyle = e;
764
+ for (let f = w; f <= T; f += d)
765
+ for (let y = b; y <= S; y += d)
766
+ s.beginPath(), s.arc(f, y, p, 0, C), s.closePath(), s.fill();
767
+ }, K = (s, t, e, o) => (n, i) => {
768
+ J(
859
769
  n,
770
+ i,
771
+ s,
860
772
  t,
861
773
  e,
862
774
  o
863
775
  );
864
- }, K = (n, t) => {
865
- n.fillStyle = t, n.fillRect(0, 0, n.canvas.width, n.canvas.height);
866
- }, Q = (n) => (t) => {
867
- K(t, n);
868
- }, _ = (n) => {
869
- switch (n == null ? void 0 : n.type) {
776
+ }, Q = (s, t) => {
777
+ s.fillStyle = t, s.fillRect(0, 0, s.canvas.width, s.canvas.height);
778
+ }, _ = (s) => (t) => {
779
+ Q(t, s);
780
+ }, q = (s) => {
781
+ switch (s == null ? void 0 : s.type) {
870
782
  case "custom":
871
- return n.drawingFn;
783
+ return s.drawingFn;
872
784
  case "dots":
873
- return J(
874
- n.dotColor ?? "#d8d8d8",
875
- n.dotGap ?? 25,
876
- n.dotRadius ?? 1.5,
877
- n.color ?? "#ffffff"
785
+ return K(
786
+ s.dotColor ?? "#d8d8d8",
787
+ s.dotGap ?? 25,
788
+ s.dotRadius ?? 1.5,
789
+ s.color ?? "#ffffff"
878
790
  );
879
791
  case "color":
880
- return Q(n.color ?? "#ffffff");
792
+ return _(s.color ?? "#ffffff");
881
793
  default:
882
794
  return U();
883
795
  }
884
- }, O = (n) => {
885
- switch (n == null ? void 0 : n.type) {
796
+ }, M = (s) => {
797
+ switch (s == null ? void 0 : s.type) {
886
798
  case "custom":
887
- return n.controllerFactory;
799
+ return s.controllerFactory;
888
800
  case "straight":
889
801
  return X({
890
- color: n.color ?? "#5c5c5c",
891
- width: n.width ?? 1,
892
- arrowLength: n.arrowLength ?? 15,
893
- arrowWidth: n.arrowWidth ?? 4,
894
- minPortOffset: n.minPortOffset ?? 15,
895
- hasSourceArrow: n.hasSourceArrow ?? !1,
896
- hasTargetArrow: n.hasTargetArrow ?? !1
802
+ color: s.color ?? "#5c5c5c",
803
+ width: s.width ?? 1,
804
+ arrowLength: s.arrowLength ?? 15,
805
+ arrowWidth: s.arrowWidth ?? 4,
806
+ minPortOffset: s.minPortOffset ?? 15,
807
+ hasSourceArrow: s.hasSourceArrow ?? !1,
808
+ hasTargetArrow: s.hasTargetArrow ?? !1
897
809
  });
898
810
  default:
899
811
  return B({
900
- color: n.color ?? "#5c5c5c",
901
- width: n.width ?? 1,
902
- curvature: n.curvature ?? 90,
903
- arrowLength: n.arrowLength ?? 15,
904
- arrowWidth: n.arrowWidth ?? 4,
905
- hasSourceArrow: n.hasSourceArrow ?? !1,
906
- hasTargetArrow: n.hasTargetArrow ?? !1
812
+ color: s.color ?? "#5c5c5c",
813
+ width: s.width ?? 1,
814
+ curvature: s.curvature ?? 90,
815
+ arrowLength: s.arrowLength ?? 15,
816
+ arrowWidth: s.arrowWidth ?? 4,
817
+ hasSourceArrow: s.hasSourceArrow ?? !1,
818
+ hasTargetArrow: s.hasTargetArrow ?? !1
907
819
  });
908
820
  }
909
- }, I = (n) => {
821
+ }, I = (s) => {
910
822
  var t, e, o;
911
823
  return {
912
824
  background: {
913
- drawingFn: _(
914
- n.background ?? { type: "none" }
825
+ drawingFn: q(
826
+ s.background ?? { type: "none" }
915
827
  )
916
828
  },
917
829
  nodes: {
918
- centerFn: ((t = n.nodes) == null ? void 0 : t.centerFn) ?? P
830
+ centerFn: ((t = s.nodes) == null ? void 0 : t.centerFn) ?? $
919
831
  },
920
832
  ports: {
921
- centerFn: ((e = n.ports) == null ? void 0 : e.centerFn) ?? P
833
+ centerFn: ((e = s.ports) == null ? void 0 : e.centerFn) ?? $
922
834
  },
923
835
  connections: {
924
- controllerFactory: O(
925
- n.connections ?? {}
836
+ controllerFactory: M(
837
+ s.connections ?? {}
926
838
  )
927
839
  },
928
840
  layers: {
929
- mode: ((o = n.layers) == null ? void 0 : o.mode) ?? "connections-follow-node"
841
+ mode: ((o = s.layers) == null ? void 0 : o.mode) ?? "connections-follow-node"
930
842
  }
931
843
  };
932
844
  };
@@ -977,7 +889,7 @@ class tt {
977
889
  return this.di.canvasController.unmarkPort(t), this;
978
890
  }
979
891
  addConnection(t) {
980
- const e = t.options !== void 0 ? O(t.options) : this.connectionControllerFactory;
892
+ const e = t.options !== void 0 ? M(t.options) : this.connectionControllerFactory;
981
893
  return this.di.canvasController.addConnection(
982
894
  t.id,
983
895
  t.from,
@@ -995,24 +907,11 @@ class tt {
995
907
  t.y ?? null
996
908
  ), this;
997
909
  }
998
- moveViewport(t) {
999
- return this.di.canvasController.moveViewport(
1000
- t.x ?? 0,
1001
- t.y ?? 0
1002
- ), this;
1003
- }
1004
- scaleViewport(t) {
1005
- return this.di.canvasController.scaleContent(
1006
- t.scale,
1007
- t.x ?? 0,
1008
- t.y ?? 0
1009
- ), this;
1010
- }
1011
910
  moveToNodes(t) {
1012
911
  return this.di.canvasController.moveToNodes(t), this;
1013
912
  }
1014
- updateNodeCoords(t, e, o) {
1015
- return this.di.canvasController.updateNodeCoords(t, e, o), this;
913
+ updateNodeCoordinates(t, e, o) {
914
+ return this.di.canvasController.updateNodeCoordinates(t, e, o), this;
1016
915
  }
1017
916
  updateConnection(t, e) {
1018
917
  return e.controller !== void 0 && this.di.canvasController.updateConnectionController(
@@ -1020,9 +919,6 @@ class tt {
1020
919
  e.controller
1021
920
  ), this;
1022
921
  }
1023
- dragNode(t, e, o) {
1024
- return this.di.canvasController.dragNode(t, e, o), this;
1025
- }
1026
922
  clear() {
1027
923
  return this.di.canvasController.clear(), this;
1028
924
  }
@@ -1037,22 +933,19 @@ class tt {
1037
933
  }
1038
934
  }
1039
935
  class et {
1040
- constructor(t) {
936
+ constructor(t, e) {
1041
937
  r(this, "transformation");
1042
938
  r(this, "model");
1043
939
  r(this, "nodes", /* @__PURE__ */ new Map());
1044
940
  r(this, "grabbedNodeId", null);
941
+ r(this, "onNodeDrag");
1045
942
  r(this, "nodeIdGenerator", new A());
1046
943
  r(this, "element", null);
1047
944
  r(this, "onCanvasMouseUp", () => {
1048
945
  this.setCursor(null), this.grabbedNodeId = null;
1049
946
  });
1050
947
  r(this, "onCanvasMouseMove", (t) => {
1051
- this.grabbedNodeId !== null && (t.stopPropagation(), this.canvas.dragNode(
1052
- this.grabbedNodeId,
1053
- t.movementX,
1054
- t.movementY
1055
- ));
948
+ this.grabbedNodeId !== null && (t.stopPropagation(), this.dragNode(this.grabbedNodeId, t.movementX, t.movementY));
1056
949
  });
1057
950
  r(this, "onCanvasTouchStart", (t) => {
1058
951
  this.previousTouchCoords = [
@@ -1068,16 +961,21 @@ class et {
1068
961
  t.touches[0].clientX - this.previousTouchCoords[0],
1069
962
  t.touches[0].clientY - this.previousTouchCoords[1]
1070
963
  ];
1071
- this.canvas.dragNode(this.grabbedNodeId, e, o), this.previousTouchCoords = [
964
+ this.dragNode(this.grabbedNodeId, e, o), this.previousTouchCoords = [
1072
965
  t.touches[0].clientX,
1073
966
  t.touches[0].clientY
1074
967
  ];
1075
968
  });
1076
- r(this, "onCanvasTouchEnd", () => {
1077
- this.previousTouchCoords = null, this.grabbedNodeId = null;
969
+ r(this, "onCanvasTouchEnd", (t) => {
970
+ t.touches.length > 0 ? this.previousTouchCoords = [
971
+ t.touches[0].clientX,
972
+ t.touches[0].clientY
973
+ ] : (this.previousTouchCoords = null, this.grabbedNodeId = null);
1078
974
  });
1079
975
  r(this, "previousTouchCoords", null);
1080
- this.canvas = t, this.transformation = this.canvas.transformation, this.model = this.canvas.model;
976
+ var o;
977
+ this.canvas = t, this.transformation = this.canvas.transformation, this.model = this.canvas.model, this.onNodeDrag = ((o = e == null ? void 0 : e.events) == null ? void 0 : o.onNodeDrag) ?? (() => {
978
+ });
1081
979
  }
1082
980
  addNode(t) {
1083
981
  let e = t.id;
@@ -1088,14 +986,14 @@ class et {
1088
986
  this.canvas.addNode(t);
1089
987
  const o = (i) => {
1090
988
  i.stopImmediatePropagation(), this.grabbedNodeId = e, this.setCursor("grab"), this.canvas.moveNodeOnTop(e);
1091
- }, s = (i) => {
989
+ }, n = (i) => {
1092
990
  i.touches.length === 1 && (this.grabbedNodeId = e, this.canvas.moveNodeOnTop(e));
1093
991
  };
1094
992
  return this.nodes.set(e, {
1095
993
  el: t.element,
1096
994
  onMouseDown: o,
1097
- onTouchStart: s
1098
- }), t.element.addEventListener("mousedown", o), t.element.addEventListener("touchstart", s), this;
995
+ onTouchStart: n
996
+ }), t.element.addEventListener("mousedown", o), t.element.addEventListener("touchstart", n), this;
1099
997
  }
1100
998
  removeNode(t) {
1101
999
  const e = this.nodes.get(t);
@@ -1119,24 +1017,15 @@ class et {
1119
1017
  patchViewportState(t) {
1120
1018
  return this.canvas.patchViewportState(t), this;
1121
1019
  }
1122
- moveViewport(t) {
1123
- return this.canvas.moveViewport(t), this;
1124
- }
1125
- scaleViewport(t) {
1126
- return this.canvas.scaleViewport(t), this;
1127
- }
1128
1020
  moveToNodes(t) {
1129
1021
  return this.canvas.moveToNodes(t), this;
1130
1022
  }
1131
- updateNodeCoords(t, e, o) {
1132
- return this.canvas.updateNodeCoords(t, e, o), this;
1023
+ updateNodeCoordinates(t, e, o) {
1024
+ return this.canvas.updateNodeCoordinates(t, e, o), this;
1133
1025
  }
1134
1026
  updateConnection(t, e) {
1135
1027
  return this.canvas.updateConnection(t, e), this;
1136
1028
  }
1137
- dragNode(t, e, o) {
1138
- return this.canvas.dragNode(t, e, o), this;
1139
- }
1140
1029
  moveNodeOnTop(t) {
1141
1030
  return this.canvas.moveNodeOnTop(t), this;
1142
1031
  }
@@ -1154,11 +1043,18 @@ class et {
1154
1043
  destroy() {
1155
1044
  this.detach(), this.nodes.forEach((t) => {
1156
1045
  t.el.removeEventListener("mousedown", t.onMouseDown), t.el.removeEventListener("touchstart", t.onTouchStart);
1157
- }), this.canvas.destroy();
1046
+ }), this.nodes.clear(), this.canvas.destroy();
1158
1047
  }
1159
1048
  setCursor(t) {
1160
1049
  this.element !== null && (t !== null ? this.element.style.cursor = t : this.element.style.removeProperty("cursor"));
1161
1050
  }
1051
+ dragNode(t, e, o) {
1052
+ const n = this.model.getNode(t);
1053
+ if (n === null)
1054
+ throw new Error("failed to drag nonexisting node");
1055
+ const [i, h] = this.transformation.getViewCoords(n.x, n.y), a = i + e, c = h + o, [l, g] = this.transformation.getAbsCoords(a, c);
1056
+ this.canvas.updateNodeCoordinates(t, l, g), this.onNodeDrag(t);
1057
+ }
1162
1058
  }
1163
1059
  class ot {
1164
1060
  constructor(t, e) {
@@ -1167,16 +1063,20 @@ class ot {
1167
1063
  r(this, "element", null);
1168
1064
  r(this, "isMoving", !1);
1169
1065
  r(this, "prevTouches", null);
1066
+ r(this, "onTransform");
1170
1067
  r(this, "isScalable");
1171
1068
  r(this, "isShiftable");
1172
- r(this, "minContentScale");
1173
- r(this, "maxContentScale");
1069
+ r(this, "minViewScale");
1070
+ r(this, "maxViewScale");
1174
1071
  r(this, "wheelSensitivity");
1175
1072
  r(this, "onMouseDown", () => {
1176
1073
  this.setCursor("grab"), this.isMoving = !0;
1177
1074
  });
1178
1075
  r(this, "onMouseMove", (t) => {
1179
- !this.isMoving || !this.isShiftable || this.canvas.moveViewport({ x: -t.movementX, y: -t.movementY });
1076
+ if (!this.isMoving || !this.isShiftable)
1077
+ return;
1078
+ const e = -t.movementX, o = -t.movementY;
1079
+ this.moveViewport(e, o);
1180
1080
  });
1181
1081
  r(this, "onMouseUp", () => {
1182
1082
  this.setCursor(null), this.isMoving = !1;
@@ -1185,8 +1085,8 @@ class ot {
1185
1085
  if (this.element === null || this.isScalable === !1)
1186
1086
  return;
1187
1087
  t.preventDefault();
1188
- const { left: e, top: o } = this.element.getBoundingClientRect(), s = t.clientX - e, i = t.clientY - o, h = t.deltaY < 0 ? this.wheelSensitivity : 1 / this.wheelSensitivity, a = this.canvas.transformation.getViewScale() * h;
1189
- this.checkNextScaleValid(a) && this.canvas.scaleViewport({ scale: 1 / h, x: s, y: i });
1088
+ const { left: e, top: o } = this.element.getBoundingClientRect(), n = t.clientX - e, i = t.clientY - o, a = 1 / (t.deltaY < 0 ? this.wheelSensitivity : 1 / this.wheelSensitivity);
1089
+ this.scaleViewport(a, n, i);
1190
1090
  });
1191
1091
  r(this, "onTouchStart", (t) => {
1192
1092
  this.prevTouches = this.getAverageTouch(t);
@@ -1195,22 +1095,25 @@ class ot {
1195
1095
  if (this.prevTouches === null || this.element === null || !this.isShiftable)
1196
1096
  return;
1197
1097
  const e = this.getAverageTouch(t);
1198
- if ((e.touchesCnt === 1 || e.touchesCnt === 2) && this.canvas.moveViewport({
1199
- x: -(e.x - this.prevTouches.x),
1200
- y: -(e.y - this.prevTouches.y)
1201
- }), e.touchesCnt === 2 && this.isScalable) {
1202
- const { left: o, top: s } = this.element.getBoundingClientRect(), i = this.prevTouches.x - o, h = this.prevTouches.y - s, a = e.scale / this.prevTouches.scale, c = this.canvas.transformation.getViewScale() * a;
1203
- this.checkNextScaleValid(c) && this.canvas.scaleViewport({ scale: 1 / a, x: i, y: h });
1098
+ if ((e.touchesCnt === 1 || e.touchesCnt === 2) && this.moveViewport(
1099
+ -(e.x - this.prevTouches.x),
1100
+ -(e.y - this.prevTouches.y)
1101
+ ), e.touchesCnt === 2 && this.isScalable) {
1102
+ const { left: o, top: n } = this.element.getBoundingClientRect(), i = this.prevTouches.x - o, h = this.prevTouches.y - n, c = 1 / (e.scale / this.prevTouches.scale);
1103
+ this.scaleViewport(c, i, h);
1204
1104
  }
1205
1105
  this.prevTouches = e, t.preventDefault();
1206
1106
  });
1207
- r(this, "onTouchEnd", () => {
1208
- this.prevTouches = null;
1107
+ r(this, "onTouchEnd", (t) => {
1108
+ t.touches.length > 0 ? this.prevTouches = this.getAverageTouch(t) : this.prevTouches = null;
1109
+ });
1110
+ var h, a, c, l, g, d, m, u, p, C, w;
1111
+ this.canvas = t, this.options = e, this.transformation = this.canvas.transformation, this.model = this.canvas.model;
1112
+ const o = ((a = (h = this.options) == null ? void 0 : h.scale) == null ? void 0 : a.minContent) ?? null, n = ((l = (c = this.options) == null ? void 0 : c.scale) == null ? void 0 : l.maxContent) ?? null;
1113
+ this.isScalable = ((d = (g = this.options) == null ? void 0 : g.scale) == null ? void 0 : d.enabled) !== !1, this.minViewScale = n !== null ? 1 / n : null, this.maxViewScale = o !== null ? 1 / o : null, this.isShiftable = ((u = (m = this.options) == null ? void 0 : m.shift) == null ? void 0 : u.enabled) !== !1;
1114
+ const i = (C = (p = this.options) == null ? void 0 : p.scale) == null ? void 0 : C.wheelSensitivity;
1115
+ this.wheelSensitivity = i !== void 0 ? i : 1.2, this.onTransform = ((w = e == null ? void 0 : e.events) == null ? void 0 : w.onTransform) ?? (() => {
1209
1116
  });
1210
- var s, i, h, a, c, l, g, d, m, u;
1211
- this.canvas = t, this.options = e, this.transformation = this.canvas.transformation, this.model = this.canvas.model, this.isScalable = ((i = (s = this.options) == null ? void 0 : s.scale) == null ? void 0 : i.enabled) !== !1, this.minContentScale = ((a = (h = this.options) == null ? void 0 : h.scale) == null ? void 0 : a.minContent) ?? null, this.maxContentScale = ((l = (c = this.options) == null ? void 0 : c.scale) == null ? void 0 : l.maxContent) ?? null, this.isShiftable = ((d = (g = this.options) == null ? void 0 : g.shift) == null ? void 0 : d.enabled) !== !1;
1212
- const o = (u = (m = this.options) == null ? void 0 : m.scale) == null ? void 0 : u.wheelSensitivity;
1213
- this.wheelSensitivity = o !== void 0 ? o : 1.2;
1214
1117
  }
1215
1118
  addNode(t) {
1216
1119
  return this.canvas.addNode(t), this;
@@ -1236,24 +1139,15 @@ class ot {
1236
1139
  patchViewportState(t) {
1237
1140
  return this.canvas.patchViewportState(t), this;
1238
1141
  }
1239
- moveViewport(t) {
1240
- return this.canvas.moveViewport(t), this;
1241
- }
1242
- scaleViewport(t) {
1243
- return this.canvas.scaleViewport(t), this;
1244
- }
1245
1142
  moveToNodes(t) {
1246
1143
  return this.canvas.moveToNodes(t), this;
1247
1144
  }
1248
- updateNodeCoords(t, e, o) {
1249
- return this.canvas.updateNodeCoords(t, e, o), this;
1145
+ updateNodeCoordinates(t, e, o) {
1146
+ return this.canvas.updateNodeCoordinates(t, e, o), this;
1250
1147
  }
1251
1148
  updateConnection(t, e) {
1252
1149
  return this.canvas.updateConnection(t, e), this;
1253
1150
  }
1254
- dragNode(t, e, o) {
1255
- return this.canvas.dragNode(t, e, o), this;
1256
- }
1257
1151
  moveNodeOnTop(t) {
1258
1152
  return this.canvas.moveNodeOnTop(t), this;
1259
1153
  }
@@ -1273,26 +1167,35 @@ class ot {
1273
1167
  const e = [], o = t.touches.length;
1274
1168
  for (let c = 0; c < o; c++)
1275
1169
  e.push([t.touches[c].clientX, t.touches[c].clientY]);
1276
- const s = e.reduce(
1170
+ const n = e.reduce(
1277
1171
  (c, l) => [c[0] + l[0], c[1] + l[1]],
1278
1172
  [0, 0]
1279
- ), i = [s[0] / o, s[1] / o], a = e.map((c) => [c[0] - i[0], c[1] - i[1]]).reduce(
1173
+ ), i = [n[0] / o, n[1] / o], a = e.map((c) => [c[0] - i[0], c[1] - i[1]]).reduce(
1280
1174
  (c, l) => c + Math.sqrt(l[0] * l[0] + l[1] * l[1]),
1281
1175
  0
1282
1176
  );
1283
1177
  return { x: i[0], y: i[1], scale: a / o, touchesCnt: o };
1284
1178
  }
1285
- checkNextScaleValid(t) {
1286
- const e = this.canvas.transformation.getViewScale();
1287
- return !(this.maxContentScale !== null && t > this.maxContentScale && t > e || this.minContentScale !== null && t < this.minContentScale && t < e);
1288
- }
1289
1179
  setCursor(t) {
1290
1180
  this.element !== null && (t !== null ? this.element.style.cursor = t : this.element.style.removeProperty("cursor"));
1291
1181
  }
1182
+ moveViewport(t, e) {
1183
+ const [o, n] = this.transformation.getAbsCoords(0, 0), i = this.canvas.transformation.getAbsScale();
1184
+ this.canvas.patchViewportState({
1185
+ scale: i,
1186
+ x: o + i * t,
1187
+ y: n + i * e
1188
+ }), this.onTransform();
1189
+ }
1190
+ scaleViewport(t, e, o) {
1191
+ const [n, i] = this.canvas.transformation.getAbsCoords(0, 0), h = this.canvas.transformation.getAbsScale(), a = h * t, c = h * (1 - t) * e + n, l = h * (1 - t) * o + i;
1192
+ this.maxViewScale !== null && a > this.maxViewScale && a > h || this.minViewScale !== null && a < this.minViewScale && a < h || (this.canvas.patchViewportState({ scale: a, x: c, y: l }), this.onTransform());
1193
+ }
1292
1194
  }
1293
1195
  class st {
1294
1196
  constructor() {
1295
1197
  r(this, "coreOptions");
1198
+ r(this, "dragOptions");
1296
1199
  r(this, "transformOptions");
1297
1200
  r(this, "isDraggable", !1);
1298
1201
  r(this, "isTransformable", !1);
@@ -1300,21 +1203,21 @@ class st {
1300
1203
  setOptions(t) {
1301
1204
  return this.coreOptions = t, this;
1302
1205
  }
1303
- setDraggableNodes() {
1304
- return this.isDraggable = !0, this;
1206
+ setDraggableNodes(t) {
1207
+ return this.isDraggable = !0, this.dragOptions = t, this;
1305
1208
  }
1306
1209
  setTransformableCanvas(t) {
1307
1210
  return this.isTransformable = !0, this.transformOptions = t, this;
1308
1211
  }
1309
1212
  build() {
1310
1213
  let t = new tt(this.coreOptions);
1311
- return this.isDraggable && (t = new et(t)), this.isTransformable && (t = new ot(t, this.transformOptions)), t;
1214
+ return this.isDraggable && (t = new et(t, this.dragOptions)), this.isTransformable && (t = new ot(t, this.transformOptions)), t;
1312
1215
  }
1313
1216
  }
1314
1217
  export {
1315
1218
  G as BezierConnectionController,
1316
1219
  tt as CanvasCore,
1317
- $ as ConnectionType,
1220
+ P as ConnectionType,
1318
1221
  v as ConnectionUtils,
1319
1222
  et as DraggableNodesCanvas,
1320
1223
  st as HtmlGraphBuilder,