@html-graph/html-graph 0.1.6 → 1.0.0

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
@@ -15,23 +15,23 @@ const O = (e, t) => ({
15
15
  w,
16
16
  { x: o, y: r },
17
17
  { x: o, y: -r }
18
- ].map((l) => v(l, e, w)).map((l) => ({ x: l.x + t.x, y: l.y + t.y })), h = `M ${s[0].x} ${s[0].y}`, d = `L ${s[1].x} ${s[1].y}`, c = `L ${s[2].x} ${s[2].y}`;
19
- return `${h} ${d} ${c}`;
18
+ ].map((l) => v(l, e, w)).map((l) => ({ x: l.x + t.x, y: l.y + t.y })), h = `M ${s[0].x} ${s[0].y}`, c = `L ${s[1].x} ${s[1].y}`, d = `L ${s[2].x} ${s[2].y}`;
19
+ return `${h} ${c} ${d}`;
20
20
  }, $ = (e, t) => {
21
21
  const o = [];
22
22
  if (e.length > 0 && o.push(`M ${e[0].x} ${e[0].y}`), e.length === 2 && o.push(`L ${e[1].x} ${e[1].y}`), e.length > 2) {
23
23
  const r = e.length - 1;
24
24
  let i = 0, s = 0, h = 0;
25
- e.forEach((d, c) => {
25
+ e.forEach((c, d) => {
26
26
  let l = 0, a = 0, g = 0;
27
- const y = c > 0, x = c < r, f = y && x;
27
+ const y = d > 0, x = d < r, f = y && x;
28
28
  if (y && (l = -i, a = -s, g = h), x) {
29
- const I = e[c + 1];
30
- i = I.x - d.x, s = I.y - d.y, h = Math.sqrt(i * i + s * s);
29
+ const m = e[d + 1];
30
+ i = m.x - c.x, s = m.y - c.y, h = Math.sqrt(i * i + s * s);
31
31
  }
32
- const S = h !== 0 ? Math.min((f ? t : 0) / h, c < r - 1 ? 0.5 : 1) : 0, T = f ? { x: d.x + i * S, y: d.y + s * S } : d, P = g !== 0 ? Math.min((f ? t : 0) / g, c > 1 ? 0.5 : 1) : 0, D = f ? { x: d.x + l * P, y: d.y + a * P } : d;
33
- c > 0 && o.push(`L ${D.x} ${D.y}`), f && o.push(
34
- `C ${d.x} ${d.y} ${d.x} ${d.y} ${T.x} ${T.y}`
32
+ const E = h !== 0 ? Math.min((f ? t : 0) / h, d < r - 1 ? 0.5 : 1) : 0, T = f ? { x: c.x + i * E, y: c.y + s * E } : c, L = g !== 0 ? Math.min((f ? t : 0) / g, d > 1 ? 0.5 : 1) : 0, D = f ? { x: c.x + l * L, y: c.y + a * L } : c;
33
+ d > 0 && o.push(`L ${D.x} ${D.y}`), f && o.push(
34
+ `C ${c.x} ${c.y} ${c.x} ${c.y} ${T.x} ${T.y}`
35
35
  );
36
36
  });
37
37
  }
@@ -55,13 +55,13 @@ const O = (e, t) => ({
55
55
  }, r = {
56
56
  x: t.x + t.width / 2,
57
57
  y: t.y + t.height / 2
58
- }, i = Math.min(o.x, r.x), s = Math.min(o.y, r.y), h = Math.abs(r.x - o.x), d = Math.abs(r.y - o.y), c = o.x <= r.x ? 1 : -1, l = o.y <= r.y ? 1 : -1;
58
+ }, i = Math.min(o.x, r.x), s = Math.min(o.y, r.y), h = Math.abs(r.x - o.x), c = Math.abs(r.y - o.y), d = o.x <= r.x ? 1 : -1, l = o.y <= r.y ? 1 : -1;
59
59
  return {
60
60
  x: i,
61
61
  y: s,
62
62
  width: h,
63
- height: d,
64
- flipX: c,
63
+ height: c,
64
+ flipX: d,
65
65
  flipY: l
66
66
  };
67
67
  }, q = (e) => {
@@ -79,8 +79,8 @@ const O = (e, t) => ({
79
79
  }, i = {
80
80
  x: o.x - e.toVect.x * e.curvature,
81
81
  y: o.y - e.toVect.y * e.curvature
82
- }, s = `M ${t.x} ${t.y} C ${r.x} ${r.y}, ${i.x} ${i.y}, ${o.x} ${o.y}`, h = e.hasSourceArrow ? "" : `M ${w.x} ${w.y} L ${t.x} ${t.y} `, d = e.hasTargetArrow ? "" : ` M ${o.x} ${o.y} L ${e.to.x} ${e.to.y}`;
83
- return `${h}${s}${d}`;
82
+ }, s = `M ${t.x} ${t.y} C ${r.x} ${r.y}, ${i.x} ${i.y}, ${o.x} ${o.y}`, h = e.hasSourceArrow ? "" : `M ${w.x} ${w.y} L ${t.x} ${t.y} `, c = e.hasTargetArrow ? "" : ` M ${o.x} ${o.y} L ${e.to.x} ${e.to.y}`;
83
+ return `${h}${s}${c}`;
84
84
  }, tt = (e) => {
85
85
  const t = e.hasSourceArrow ? v(
86
86
  { x: e.arrowLength, y: w.y },
@@ -90,38 +90,38 @@ const O = (e, t) => ({
90
90
  { x: e.to.x - e.arrowLength, y: e.to.y },
91
91
  e.toVect,
92
92
  e.to
93
- ) : e.to, r = e.arrowLength, i = Math.cos(e.detourDirection) * e.detourDistance, s = Math.sin(e.detourDirection) * e.detourDistance, h = i * e.flipX, d = s * e.flipY, c = v(
93
+ ) : e.to, r = e.arrowLength, i = Math.cos(e.detourDirection) * e.detourDistance, s = Math.sin(e.detourDirection) * e.detourDistance, h = i * e.flipX, c = s * e.flipY, d = v(
94
94
  { x: r, y: w.y },
95
95
  e.fromVect,
96
96
  w
97
97
  ), l = {
98
- x: c.x + h,
99
- y: c.y + d
98
+ x: d.x + h,
99
+ y: d.y + c
100
100
  }, a = v(
101
101
  { x: e.to.x - r, y: e.to.y },
102
102
  e.toVect,
103
103
  e.to
104
104
  ), g = {
105
105
  x: a.x + h,
106
- y: a.y + d
106
+ y: a.y + c
107
107
  }, y = { x: (l.x + g.x) / 2, y: (l.y + g.y) / 2 }, x = {
108
- x: c.x + e.curvature * e.fromVect.x,
109
- y: c.y + e.curvature * e.fromVect.y
108
+ x: d.x + e.curvature * e.fromVect.x,
109
+ y: d.y + e.curvature * e.fromVect.y
110
110
  }, f = {
111
111
  x: a.x - e.curvature * e.toVect.x,
112
112
  y: a.y - e.curvature * e.toVect.y
113
113
  }, A = {
114
- x: c.x + h,
115
- y: c.y + d
116
- }, S = {
114
+ x: d.x + h,
115
+ y: d.y + c
116
+ }, E = {
117
117
  x: a.x + h,
118
- y: a.y + d
118
+ y: a.y + c
119
119
  };
120
120
  return [
121
121
  `M ${t.x} ${t.y}`,
122
- `L ${c.x} ${c.y}`,
122
+ `L ${d.x} ${d.y}`,
123
123
  `C ${x.x} ${x.y} ${A.x} ${A.y} ${y.x} ${y.y}`,
124
- `C ${S.x} ${S.y} ${f.x} ${f.y} ${a.x} ${a.y}`,
124
+ `C ${E.x} ${E.y} ${f.x} ${f.y} ${a.x} ${a.y}`,
125
125
  `L ${o.x} ${o.y}`
126
126
  ].join(" ");
127
127
  }, et = (e) => {
@@ -137,10 +137,10 @@ const O = (e, t) => ({
137
137
  { x: e.to.x - i, y: e.to.y },
138
138
  e.toVect,
139
139
  e.to
140
- ), d = Math.max((s.x + h.x) / 2, r), c = e.to.y / 2, l = { x: e.flipX > 0 ? d : -r, y: s.y }, a = { x: l.x, y: c }, g = {
141
- x: e.flipX > 0 ? e.to.x - d : e.to.x + r,
140
+ ), c = Math.max((s.x + h.x) / 2, r), d = e.to.y / 2, l = { x: e.flipX > 0 ? c : -r, y: s.y }, a = { x: l.x, y: d }, g = {
141
+ x: e.flipX > 0 ? e.to.x - c : e.to.x + r,
142
142
  y: h.y
143
- }, y = { x: g.x, y: c };
143
+ }, y = { x: g.x, y: d };
144
144
  return $(
145
145
  [t, s, l, a, y, g, h, o],
146
146
  e.roundness
@@ -158,11 +158,11 @@ const O = (e, t) => ({
158
158
  { x: r, y: w.y },
159
159
  e.fromVect,
160
160
  w
161
- ), s = Math.cos(e.detourDirection) * e.detourDistance, h = Math.sin(e.detourDirection) * e.detourDistance, d = s * e.flipX, c = h * e.flipY, l = { x: i.x + d, y: i.y + c }, a = v(
161
+ ), s = Math.cos(e.detourDirection) * e.detourDistance, h = Math.sin(e.detourDirection) * e.detourDistance, c = s * e.flipX, d = h * e.flipY, l = { x: i.x + c, y: i.y + d }, a = v(
162
162
  { x: e.to.x - r, y: e.to.y },
163
163
  e.toVect,
164
164
  e.to
165
- ), g = { x: a.x + d, y: a.y + c };
165
+ ), g = { x: a.x + c, y: a.y + d };
166
166
  return $(
167
167
  [t, i, l, g, a, o],
168
168
  e.roundness
@@ -195,10 +195,10 @@ const O = (e, t) => ({
195
195
  { x: e.to.x - i, y: e.to.y },
196
196
  e.toVect,
197
197
  e.to
198
- ), d = Math.max((s.y + h.y) / 2, r), c = e.to.x / 2, l = { x: s.x, y: e.flipY > 0 ? d : -r }, a = { x: c, y: l.y }, g = {
198
+ ), c = Math.max((s.y + h.y) / 2, r), d = e.to.x / 2, l = { x: s.x, y: e.flipY > 0 ? c : -r }, a = { x: d, y: l.y }, g = {
199
199
  x: h.x,
200
- y: e.flipY > 0 ? e.to.y - d : e.to.y + r
201
- }, y = { x: c, y: g.y };
200
+ y: e.flipY > 0 ? e.to.y - c : e.to.y + r
201
+ }, y = { x: d, y: g.y };
202
202
  return $(
203
203
  [t, s, l, a, y, g, h, o],
204
204
  e.roundness
@@ -214,20 +214,20 @@ const O = (e, t) => ({
214
214
  { x: r, y: w.y },
215
215
  { x: e.arrowLength, y: w.y }
216
216
  ].map(
217
- (c) => v(c, e.fromVect, w)
218
- ), d = `M ${w.x} ${w.y} L ${h[0].x} ${h[0].y} `;
219
- return `${e.hasSourceArrow || e.hasTargetArrow ? "" : d}${$(h, e.roundness)}`;
217
+ (d) => v(d, e.fromVect, w)
218
+ ), c = `M ${w.x} ${w.y} L ${h[0].x} ${h[0].y} `;
219
+ return `${e.hasSourceArrow || e.hasTargetArrow ? "" : c}${$(h, e.roundness)}`;
220
220
  }, it = (e) => {
221
- const t = e.smallRadius, o = e.radius, r = Math.sqrt(t * t + o * o), i = t + o, s = e.arrowLength + r * (1 - o / i), h = t * o / i, c = [
221
+ const t = e.smallRadius, o = e.radius, r = Math.sqrt(t * t + o * o), i = t + o, s = e.arrowLength + r * (1 - o / i), h = t * o / i, d = [
222
222
  { x: e.arrowLength, y: w.y },
223
223
  { x: s, y: h },
224
224
  { x: s, y: -h }
225
225
  ].map((g) => v(g, e.fromVect, w)), l = [
226
- `M ${c[0].x} ${c[0].y}`,
227
- `A ${t} ${t} 0 0 1 ${c[1].x} ${c[1].y}`,
228
- `A ${o} ${o} 0 1 0 ${c[2].x} ${c[2].y}`,
229
- `A ${t} ${t} 0 0 1 ${c[0].x} ${c[0].y}`
230
- ].join(" "), a = `M 0 0 L ${c[0].x} ${c[0].y} `;
226
+ `M ${d[0].x} ${d[0].y}`,
227
+ `A ${t} ${t} 0 0 1 ${d[1].x} ${d[1].y}`,
228
+ `A ${o} ${o} 0 1 0 ${d[2].x} ${d[2].y}`,
229
+ `A ${t} ${t} 0 0 1 ${d[0].x} ${d[0].y}`
230
+ ].join(" "), a = `M 0 0 L ${d[0].x} ${d[0].y} `;
231
231
  return `${e.hasSourceArrow || e.hasTargetArrow ? "" : a}${l}`;
232
232
  }, u = Object.freeze({
233
233
  color: "#777777",
@@ -267,37 +267,33 @@ class nt {
267
267
  this.svg.appendChild(this.group), this.line = R(o, r), this.group.appendChild(this.line), this.hasSourceArrow && (this.sourceArrow = N(o), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = N(o), this.group.appendChild(this.targetArrow));
268
268
  }
269
269
  render(t) {
270
- const { x: o, y: r, width: i, height: s, flipX: h, flipY: d } = Y(
271
- t.source,
272
- t.target
270
+ const { x: o, y: r, width: i, height: s, flipX: h, flipY: c } = Y(
271
+ t.from,
272
+ t.to
273
273
  );
274
- this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${i}px`, this.svg.style.height = `${s}px`, this.group.style.transform = `scale(${h}, ${d})`;
275
- const c = M(
276
- t.source.direction,
274
+ this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${i}px`, this.svg.style.height = `${s}px`, this.group.style.transform = `scale(${h}, ${c})`;
275
+ const d = M(
276
+ t.from.direction,
277
277
  h,
278
- d
279
- ), l = M(
280
- t.target.direction,
281
- h,
282
- d
283
- ), a = {
278
+ c
279
+ ), l = M(t.to.direction, h, c), a = {
284
280
  x: i,
285
281
  y: s
286
282
  };
287
283
  let g, y = l, x = -this.arrowLength;
288
- if (t.source.portId === t.target.portId ? (g = it({
289
- fromVect: c,
284
+ if (t.from.portId === t.to.portId ? (g = it({
285
+ fromVect: d,
290
286
  radius: this.portCycleRadius,
291
287
  smallRadius: this.portCycleSmallRadius,
292
288
  arrowLength: this.arrowLength,
293
289
  hasSourceArrow: this.hasSourceArrow,
294
290
  hasTargetArrow: this.hasTargetArrow
295
- }), y = c, x = this.arrowLength) : t.source.nodeId === t.target.nodeId ? g = tt({
291
+ }), y = d, x = this.arrowLength) : t.from.nodeId === t.to.nodeId ? g = tt({
296
292
  to: a,
297
- fromVect: c,
293
+ fromVect: d,
298
294
  toVect: l,
299
295
  flipX: h,
300
- flipY: d,
296
+ flipY: c,
301
297
  arrowLength: this.arrowLength,
302
298
  detourDirection: this.detourDirection,
303
299
  detourDistance: this.detourDistance,
@@ -306,7 +302,7 @@ class nt {
306
302
  hasTargetArrow: this.hasTargetArrow
307
303
  }) : g = q({
308
304
  to: a,
309
- fromVect: c,
305
+ fromVect: d,
310
306
  toVect: l,
311
307
  arrowLength: this.arrowLength,
312
308
  curvature: this.curvature,
@@ -314,7 +310,7 @@ class nt {
314
310
  hasTargetArrow: this.hasTargetArrow
315
311
  }), this.line.setAttribute("d", g), this.sourceArrow) {
316
312
  const f = C(
317
- c,
313
+ d,
318
314
  w,
319
315
  this.arrowLength,
320
316
  this.arrowWidth
@@ -359,38 +355,34 @@ class st {
359
355
  this.svg.appendChild(this.group), this.line = R(r, i), this.group.appendChild(this.line), this.hasSourceArrow && (this.sourceArrow = N(r), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = N(r), this.group.appendChild(this.targetArrow));
360
356
  }
361
357
  render(t) {
362
- const { x: o, y: r, width: i, height: s, flipX: h, flipY: d } = Y(
363
- t.source,
364
- t.target
358
+ const { x: o, y: r, width: i, height: s, flipX: h, flipY: c } = Y(
359
+ t.from,
360
+ t.to
365
361
  );
366
- this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${i}px`, this.svg.style.height = `${s}px`, this.group.style.transform = `scale(${h}, ${d})`;
367
- const c = M(
368
- t.source.direction,
369
- h,
370
- d
371
- ), l = M(
372
- t.target.direction,
362
+ this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${i}px`, this.svg.style.height = `${s}px`, this.group.style.transform = `scale(${h}, ${c})`;
363
+ const d = M(
364
+ t.from.direction,
373
365
  h,
374
- d
375
- ), a = {
366
+ c
367
+ ), l = M(t.to.direction, h, c), a = {
376
368
  x: i,
377
369
  y: s
378
370
  };
379
371
  let g, y = l, x = -this.arrowLength;
380
- if (t.source.portId === t.target.portId ? (g = U({
381
- fromVect: c,
372
+ if (t.from.portId === t.to.portId ? (g = U({
373
+ fromVect: d,
382
374
  arrowLength: this.arrowLength,
383
375
  side: this.cycleSquareSide,
384
376
  arrowOffset: this.arrowOffset,
385
377
  roundness: this.roundness,
386
378
  hasSourceArrow: this.hasSourceArrow,
387
379
  hasTargetArrow: this.hasTargetArrow
388
- }), y = c, x = this.arrowLength) : t.source.nodeId === t.target.nodeId ? g = G({
380
+ }), y = d, x = this.arrowLength) : t.from.nodeId === t.to.nodeId ? g = G({
389
381
  to: a,
390
- fromVect: c,
382
+ fromVect: d,
391
383
  toVect: l,
392
384
  flipX: h,
393
- flipY: d,
385
+ flipY: c,
394
386
  arrowLength: this.arrowLength,
395
387
  arrowOffset: this.arrowOffset,
396
388
  roundness: this.roundness,
@@ -400,7 +392,7 @@ class st {
400
392
  hasTargetArrow: this.hasTargetArrow
401
393
  }) : g = et({
402
394
  to: a,
403
- fromVect: c,
395
+ fromVect: d,
404
396
  toVect: l,
405
397
  flipX: h,
406
398
  arrowLength: this.arrowLength,
@@ -410,7 +402,7 @@ class st {
410
402
  hasTargetArrow: this.hasTargetArrow
411
403
  }), this.line.setAttribute("d", g), this.sourceArrow) {
412
404
  const f = C(
413
- c,
405
+ d,
414
406
  w,
415
407
  this.arrowLength,
416
408
  this.arrowWidth
@@ -455,38 +447,34 @@ class ht {
455
447
  this.svg.appendChild(this.group), this.line = R(r, i), this.group.appendChild(this.line), this.hasSourceArrow && (this.sourceArrow = N(r), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = N(r), this.group.appendChild(this.targetArrow));
456
448
  }
457
449
  render(t) {
458
- const { x: o, y: r, width: i, height: s, flipX: h, flipY: d } = Y(
459
- t.source,
460
- t.target
450
+ const { x: o, y: r, width: i, height: s, flipX: h, flipY: c } = Y(
451
+ t.from,
452
+ t.to
461
453
  );
462
- this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${i}px`, this.svg.style.height = `${s}px`, this.group.style.transform = `scale(${h}, ${d})`;
463
- const c = M(
464
- t.source.direction,
454
+ this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${i}px`, this.svg.style.height = `${s}px`, this.group.style.transform = `scale(${h}, ${c})`;
455
+ const d = M(
456
+ t.from.direction,
465
457
  h,
466
- d
467
- ), l = M(
468
- t.target.direction,
469
- h,
470
- d
471
- ), a = {
458
+ c
459
+ ), l = M(t.to.direction, h, c), a = {
472
460
  x: i,
473
461
  y: s
474
462
  };
475
463
  let g, y = l, x = -this.arrowLength;
476
- if (t.source.portId === t.target.portId ? (g = U({
477
- fromVect: c,
464
+ if (t.from.portId === t.to.portId ? (g = U({
465
+ fromVect: d,
478
466
  arrowLength: this.arrowLength,
479
467
  side: this.cycleSquareSide,
480
468
  arrowOffset: this.arrowOffset,
481
469
  roundness: this.roundness,
482
470
  hasSourceArrow: this.hasSourceArrow,
483
471
  hasTargetArrow: this.hasTargetArrow
484
- }), y = c, x = this.arrowLength) : t.source.nodeId === t.target.nodeId ? g = G({
472
+ }), y = d, x = this.arrowLength) : t.from.nodeId === t.to.nodeId ? g = G({
485
473
  to: a,
486
- fromVect: c,
474
+ fromVect: d,
487
475
  toVect: l,
488
476
  flipX: h,
489
- flipY: d,
477
+ flipY: c,
490
478
  arrowLength: this.arrowLength,
491
479
  arrowOffset: this.arrowOffset,
492
480
  roundness: this.roundness,
@@ -496,7 +484,7 @@ class ht {
496
484
  hasTargetArrow: this.hasTargetArrow
497
485
  }) : g = ot({
498
486
  to: a,
499
- fromVect: c,
487
+ fromVect: d,
500
488
  toVect: l,
501
489
  arrowLength: this.arrowLength,
502
490
  arrowOffset: this.arrowOffset,
@@ -505,7 +493,7 @@ class ht {
505
493
  hasTargetArrow: this.hasTargetArrow
506
494
  }), this.line.setAttribute("d", g), this.sourceArrow) {
507
495
  const f = C(
508
- c,
496
+ d,
509
497
  w,
510
498
  this.arrowLength,
511
499
  this.arrowWidth
@@ -523,7 +511,7 @@ class ht {
523
511
  }
524
512
  }
525
513
  }
526
- class dt {
514
+ class ct {
527
515
  constructor(t) {
528
516
  n(this, "svg", W());
529
517
  n(this, "group", F());
@@ -550,38 +538,34 @@ class dt {
550
538
  this.svg.appendChild(this.group), this.line = R(r, i), this.group.appendChild(this.line), this.hasSourceArrow && (this.sourceArrow = N(r), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = N(r), this.group.appendChild(this.targetArrow));
551
539
  }
552
540
  render(t) {
553
- const { x: o, y: r, width: i, height: s, flipX: h, flipY: d } = Y(
554
- t.source,
555
- t.target
541
+ const { x: o, y: r, width: i, height: s, flipX: h, flipY: c } = Y(
542
+ t.from,
543
+ t.to
556
544
  );
557
- this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${i}px`, this.svg.style.height = `${s}px`, this.group.style.transform = `scale(${h}, ${d})`;
558
- const c = M(
559
- t.source.direction,
560
- h,
561
- d
562
- ), l = M(
563
- t.target.direction,
545
+ this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${i}px`, this.svg.style.height = `${s}px`, this.group.style.transform = `scale(${h}, ${c})`;
546
+ const d = M(
547
+ t.from.direction,
564
548
  h,
565
- d
566
- ), a = {
549
+ c
550
+ ), l = M(t.to.direction, h, c), a = {
567
551
  x: i,
568
552
  y: s
569
553
  };
570
554
  let g, y = l, x = -this.arrowLength;
571
- if (t.source.portId === t.target.portId ? (g = U({
572
- fromVect: c,
555
+ if (t.from.portId === t.to.portId ? (g = U({
556
+ fromVect: d,
573
557
  arrowLength: this.arrowLength,
574
558
  side: this.cycleSquareSide,
575
559
  arrowOffset: this.arrowOffset,
576
560
  roundness: this.roundness,
577
561
  hasSourceArrow: this.hasSourceArrow,
578
562
  hasTargetArrow: this.hasTargetArrow
579
- }), y = c, x = this.arrowLength) : t.source.nodeId === t.target.nodeId ? g = G({
563
+ }), y = d, x = this.arrowLength) : t.from.nodeId === t.to.nodeId ? g = G({
580
564
  to: a,
581
- fromVect: c,
565
+ fromVect: d,
582
566
  toVect: l,
583
567
  flipX: h,
584
- flipY: d,
568
+ flipY: c,
585
569
  arrowLength: this.arrowLength,
586
570
  arrowOffset: this.arrowOffset,
587
571
  roundness: this.roundness,
@@ -591,9 +575,9 @@ class dt {
591
575
  hasTargetArrow: this.hasTargetArrow
592
576
  }) : g = rt({
593
577
  to: a,
594
- fromVect: c,
578
+ fromVect: d,
595
579
  toVect: l,
596
- flipY: d,
580
+ flipY: c,
597
581
  arrowLength: this.arrowLength,
598
582
  arrowOffset: this.arrowOffset,
599
583
  roundness: this.roundness,
@@ -601,7 +585,7 @@ class dt {
601
585
  hasTargetArrow: this.hasTargetArrow
602
586
  }), this.line.setAttribute("d", g), this.sourceArrow) {
603
587
  const f = C(
604
- c,
588
+ d,
605
589
  w,
606
590
  this.arrowLength,
607
591
  this.arrowWidth
@@ -619,7 +603,7 @@ class dt {
619
603
  }
620
604
  }
621
605
  }
622
- const ct = (e) => {
606
+ const dt = (e) => {
623
607
  if (typeof e == "function")
624
608
  return e;
625
609
  switch (e == null ? void 0 : e.type) {
@@ -652,7 +636,7 @@ const ct = (e) => {
652
636
  detourDirection: e.detourDirection
653
637
  });
654
638
  case "vertical":
655
- return () => new dt({
639
+ return () => new ct({
656
640
  color: e.color,
657
641
  width: e.width,
658
642
  arrowLength: e.arrowLength,
@@ -706,7 +690,7 @@ const ct = (e) => {
706
690
  direction: ((s = e == null ? void 0 : e.ports) == null ? void 0 : s.direction) ?? 0
707
691
  },
708
692
  edges: {
709
- shapeFactory: ct(((h = e == null ? void 0 : e.edges) == null ? void 0 : h.shape) ?? {}),
693
+ shapeFactory: dt(((h = e == null ? void 0 : e.edges) == null ? void 0 : h.shape) ?? {}),
710
694
  priorityFn: t.edgesPriorityFn
711
695
  }
712
696
  };
@@ -852,12 +836,12 @@ class gt {
852
836
  }
853
837
  const K = (e) => ({
854
838
  scale: 1 / e.scale,
855
- dx: -e.dx / e.scale,
856
- dy: -e.dy / e.scale
839
+ x: -e.x / e.scale,
840
+ y: -e.y / e.scale
857
841
  }), _ = {
858
842
  scale: 1,
859
- dx: 0,
860
- dy: 0
843
+ x: 0,
844
+ y: 0
861
845
  };
862
846
  class ut {
863
847
  constructor() {
@@ -873,15 +857,15 @@ class ut {
873
857
  patchViewportMatrix(t) {
874
858
  this.viewportMatrix = {
875
859
  scale: t.scale ?? this.viewportMatrix.scale,
876
- dx: t.dx ?? this.viewportMatrix.dx,
877
- dy: t.dy ?? this.viewportMatrix.dy
860
+ x: t.x ?? this.viewportMatrix.x,
861
+ y: t.y ?? this.viewportMatrix.y
878
862
  }, this.contentMatrix = K(this.viewportMatrix);
879
863
  }
880
864
  patchContentMatrix(t) {
881
865
  this.contentMatrix = {
882
866
  scale: t.scale ?? this.contentMatrix.scale,
883
- dx: t.dx ?? this.contentMatrix.dx,
884
- dy: t.dy ?? this.contentMatrix.dy
867
+ x: t.x ?? this.contentMatrix.x,
868
+ y: t.y ?? this.contentMatrix.y
885
869
  }, this.viewportMatrix = K(this.contentMatrix);
886
870
  }
887
871
  }
@@ -923,7 +907,7 @@ class xt {
923
907
  }
924
908
  applyTransform() {
925
909
  const t = this.viewportTransformer.getContentMatrix();
926
- this.container.style.transform = `matrix(${t.scale}, 0, 0, ${t.scale}, ${t.dx}, ${t.dy})`;
910
+ this.container.style.transform = `matrix(${t.scale}, 0, 0, ${t.scale}, ${t.x}, ${t.y})`;
927
911
  }
928
912
  attachNode(t) {
929
913
  const o = this.graphStore.getNode(t), r = vt();
@@ -952,8 +936,8 @@ class xt {
952
936
  this.clear(), this.detach(), this.host.removeChild(this.container);
953
937
  }
954
938
  updateNodeCoordinates(t) {
955
- const o = this.nodeIdToWrapperElementMap.get(t), r = this.graphStore.getNode(t), { width: i, height: s } = r.element.getBoundingClientRect(), h = this.viewportTransformer.getViewportMatrix().scale, d = r.centerFn(i, s), c = r.x - h * d.x, l = r.y - h * d.y;
956
- o.style.transform = `translate(${c}px, ${l}px)`;
939
+ const o = this.nodeIdToWrapperElementMap.get(t), r = this.graphStore.getNode(t), { width: i, height: s } = r.element.getBoundingClientRect(), h = this.viewportTransformer.getViewportMatrix().scale, c = r.centerFn(i, s), d = r.x - h * c.x, l = r.y - h * c.y;
940
+ o.style.transform = `translate(${d}px, ${l}px)`;
957
941
  }
958
942
  updateNodePriority(t) {
959
943
  const o = this.graphStore.getNode(t), r = this.nodeIdToWrapperElementMap.get(t);
@@ -966,32 +950,32 @@ class xt {
966
950
  this.edgeIdToElementMap.set(t, r.shape.svg), this.container.appendChild(r.shape.svg);
967
951
  }
968
952
  renderEdge(t) {
969
- const o = this.graphStore.getEdge(t), r = this.graphStore.getPort(o.from), i = this.graphStore.getPort(o.to), s = r.element.getBoundingClientRect(), h = i.element.getBoundingClientRect(), d = this.host.getBoundingClientRect(), c = this.viewportTransformer.getViewportMatrix(), l = {
970
- x: c.scale * (s.left - d.left) + c.dx,
971
- y: c.scale * (s.top - d.top) + c.dy
953
+ const o = this.graphStore.getEdge(t), r = this.graphStore.getPort(o.from), i = this.graphStore.getPort(o.to), s = r.element.getBoundingClientRect(), h = i.element.getBoundingClientRect(), c = this.host.getBoundingClientRect(), d = this.viewportTransformer.getViewportMatrix(), l = {
954
+ x: d.scale * (s.left - c.left) + d.x,
955
+ y: d.scale * (s.top - c.top) + d.y
972
956
  }, a = {
973
- x: c.scale * (h.left - d.left) + c.dx,
974
- y: c.scale * (h.top - d.top) + c.dy
957
+ x: d.scale * (h.left - c.left) + d.x,
958
+ y: d.scale * (h.top - c.top) + d.y
975
959
  }, g = {
976
960
  x: l.x,
977
961
  y: l.y,
978
- width: s.width * c.scale,
979
- height: s.height * c.scale,
962
+ width: s.width * d.scale,
963
+ height: s.height * d.scale,
980
964
  direction: r.direction,
981
965
  portId: o.from,
982
966
  nodeId: this.graphStore.getPortNodeId(o.from)
983
967
  }, y = {
984
968
  x: a.x,
985
969
  y: a.y,
986
- width: h.width * c.scale,
987
- height: h.height * c.scale,
970
+ width: h.width * d.scale,
971
+ height: h.height * d.scale,
988
972
  direction: i.direction,
989
973
  portId: o.to,
990
974
  nodeId: this.graphStore.getPortNodeId(o.to)
991
975
  };
992
976
  o.shape.render({
993
- source: g,
994
- target: y
977
+ from: g,
978
+ to: y
995
979
  });
996
980
  }
997
981
  updateEdgePriority(t) {
@@ -999,7 +983,7 @@ class xt {
999
983
  o.shape.svg.style.zIndex = `${o.priority}`;
1000
984
  }
1001
985
  }
1002
- class m {
986
+ class I {
1003
987
  constructor(t) {
1004
988
  n(this, "counter", 0);
1005
989
  this.checkExists = t;
@@ -1015,24 +999,24 @@ class m {
1015
999
  this.counter = 0;
1016
1000
  }
1017
1001
  }
1018
- class E extends Error {
1002
+ class S extends Error {
1019
1003
  constructor() {
1020
1004
  super(...arguments);
1021
1005
  n(this, "name", "HtmlGraphError");
1022
1006
  }
1023
1007
  }
1024
- class Et {
1025
- constructor(t, o, r, i, s, h, d) {
1026
- n(this, "nodeIdGenerator", new m(
1008
+ class St {
1009
+ constructor(t, o, r, i, s, h, c) {
1010
+ n(this, "nodeIdGenerator", new I(
1027
1011
  (t) => this.graphStore.getNode(t) !== void 0
1028
1012
  ));
1029
- n(this, "portIdGenerator", new m(
1013
+ n(this, "portIdGenerator", new I(
1030
1014
  (t) => this.graphStore.getPort(t) !== void 0
1031
1015
  ));
1032
- n(this, "edgeIdGenerator", new m(
1016
+ n(this, "edgeIdGenerator", new I(
1033
1017
  (t) => this.graphStore.getEdge(t) !== void 0
1034
1018
  ));
1035
- this.graphStore = t, this.htmlController = o, this.viewportTransformer = r, this.defaultNodesCenterFn = i, this.defaultPortsDirection = s, this.defaultNodesPriorityFn = h, this.defaultEdgesPriorityFn = d;
1019
+ this.graphStore = t, this.htmlController = o, this.viewportTransformer = r, this.defaultNodesCenterFn = i, this.defaultPortsDirection = s, this.defaultNodesPriorityFn = h, this.defaultEdgesPriorityFn = c;
1036
1020
  }
1037
1021
  attach(t) {
1038
1022
  this.htmlController.attach(t);
@@ -1043,7 +1027,7 @@ class Et {
1043
1027
  addNode(t) {
1044
1028
  const o = this.nodeIdGenerator.create(t.nodeId);
1045
1029
  if (this.graphStore.getNode(o) !== void 0)
1046
- throw new E("failed to add node with existing id");
1030
+ throw new S("failed to add node with existing id");
1047
1031
  this.graphStore.addNode({
1048
1032
  nodeId: o,
1049
1033
  element: t.element,
@@ -1063,9 +1047,9 @@ class Et {
1063
1047
  markPort(t) {
1064
1048
  const o = this.portIdGenerator.create(t.portId);
1065
1049
  if (this.graphStore.getPort(o) !== void 0)
1066
- throw new E("failed to add port with existing id");
1050
+ throw new S("failed to add port with existing id");
1067
1051
  if (this.graphStore.getNode(t.nodeId) === void 0)
1068
- throw new E("failed to set port on nonexisting node");
1052
+ throw new S("failed to set port on nonexisting node");
1069
1053
  this.graphStore.addPort({
1070
1054
  portId: o,
1071
1055
  element: t.element,
@@ -1076,11 +1060,11 @@ class Et {
1076
1060
  addEdge(t) {
1077
1061
  const o = this.edgeIdGenerator.create(t.edgeId);
1078
1062
  if (this.graphStore.getEdge(o) !== void 0)
1079
- throw new E("failed to add edge with existing id");
1063
+ throw new S("failed to add edge with existing id");
1080
1064
  if (this.graphStore.getPort(t.from) === void 0)
1081
- throw new E("failed to add edge from nonexisting port");
1065
+ throw new S("failed to add edge from nonexisting port");
1082
1066
  if (this.graphStore.getPort(t.to) === void 0)
1083
- throw new E("failed to add edge to nonexisting port");
1067
+ throw new S("failed to add edge to nonexisting port");
1084
1068
  this.graphStore.addEdge({
1085
1069
  edgeId: o,
1086
1070
  from: t.from,
@@ -1092,13 +1076,13 @@ class Et {
1092
1076
  updateEdge(t) {
1093
1077
  const o = this.graphStore.getEdge(t.edgeId);
1094
1078
  if (o === void 0)
1095
- throw new E("failed to update nonexisting edge");
1079
+ throw new S("failed to update nonexisting edge");
1096
1080
  t.shape !== void 0 && (o.shape = t.shape, this.htmlController.updateEdgeShape(t.edgeId)), t.priority !== void 0 && (o.priority = t.priority, this.htmlController.updateEdgePriority(t.edgeId)), t.from !== void 0 && this.graphStore.updateEdgeFrom(t.edgeId, t.from), t.to !== void 0 && this.graphStore.updateEdgeTo(t.edgeId, t.to), this.htmlController.renderEdge(t.edgeId);
1097
1081
  }
1098
1082
  updatePort(t, o) {
1099
1083
  const r = this.graphStore.getPort(t);
1100
1084
  if (r === void 0)
1101
- throw new E("failed to unset nonexisting port");
1085
+ throw new S("failed to unset nonexisting port");
1102
1086
  r.direction = o.direction ?? r.direction, this.graphStore.getPortAdjacentEdgeIds(t).forEach((s) => {
1103
1087
  this.htmlController.renderEdge(s);
1104
1088
  });
@@ -1106,26 +1090,26 @@ class Et {
1106
1090
  updateNode(t, o) {
1107
1091
  const r = this.graphStore.getNode(t);
1108
1092
  if (r === void 0)
1109
- throw new E("failed to update nonexisting node");
1093
+ throw new S("failed to update nonexisting node");
1110
1094
  r.x = (o == null ? void 0 : o.x) ?? r.x, r.y = (o == null ? void 0 : o.y) ?? r.y, r.centerFn = (o == null ? void 0 : o.centerFn) ?? r.centerFn, r.priority = (o == null ? void 0 : o.priority) ?? r.priority, this.htmlController.updateNodeCoordinates(t), this.htmlController.updateNodePriority(t), this.graphStore.getNodeAdjacentEdgeIds(t).forEach((s) => {
1111
1095
  this.htmlController.renderEdge(s);
1112
1096
  });
1113
1097
  }
1114
1098
  removeEdge(t) {
1115
1099
  if (this.graphStore.getEdge(t) === void 0)
1116
- throw new E("failed to remove nonexisting edge");
1100
+ throw new S("failed to remove nonexisting edge");
1117
1101
  this.htmlController.detachEdge(t), this.graphStore.removeEdge(t);
1118
1102
  }
1119
1103
  unmarkPort(t) {
1120
1104
  if (this.graphStore.getPort(t) === void 0)
1121
- throw new E("failed to unset nonexisting port");
1105
+ throw new S("failed to unset nonexisting port");
1122
1106
  this.graphStore.getPortAdjacentEdgeIds(t).forEach((o) => {
1123
1107
  this.removeEdge(o);
1124
1108
  }), this.graphStore.removePort(t);
1125
1109
  }
1126
1110
  removeNode(t) {
1127
1111
  if (this.graphStore.getNode(t) === void 0)
1128
- throw new E("failed to remove nonexisting node");
1112
+ throw new S("failed to remove nonexisting node");
1129
1113
  this.graphStore.getNodePortIds(t).forEach((o) => {
1130
1114
  this.unmarkPort(o);
1131
1115
  }), this.htmlController.detachNode(t), this.graphStore.removeNode(t);
@@ -1143,7 +1127,7 @@ class Et {
1143
1127
  this.clear(), this.htmlController.destroy();
1144
1128
  }
1145
1129
  }
1146
- class St {
1130
+ class Et {
1147
1131
  constructor(t) {
1148
1132
  this.graphStore = t;
1149
1133
  }
@@ -1171,7 +1155,7 @@ class St {
1171
1155
  return this.graphStore.getAllPortIds();
1172
1156
  }
1173
1157
  getNodePortIds(t) {
1174
- return this.graphStore.getNodePortIds(t);
1158
+ return this.graphStore.getNode(t) === void 0 ? null : this.graphStore.getNodePortIds(t);
1175
1159
  }
1176
1160
  getPortNodeId(t) {
1177
1161
  return this.graphStore.getPortNodeId(t) ?? null;
@@ -1184,28 +1168,28 @@ class St {
1184
1168
  return o === void 0 ? null : { from: o.from, to: o.to, priority: o.priority };
1185
1169
  }
1186
1170
  getPortIncomingEdgeIds(t) {
1187
- return this.graphStore.getPortIncomingEdgeIds(t);
1171
+ return this.graphStore.getPort(t) === void 0 ? null : this.graphStore.getPortIncomingEdgeIds(t);
1188
1172
  }
1189
1173
  getPortOutcomingEdgeIds(t) {
1190
- return this.graphStore.getPortOutcomingEdgeIds(t);
1174
+ return this.graphStore.getPort(t) === void 0 ? null : this.graphStore.getPortOutcomingEdgeIds(t);
1191
1175
  }
1192
1176
  getPortCycleEdgeIds(t) {
1193
- return this.graphStore.getPortCycleEdgeIds(t);
1177
+ return this.graphStore.getPort(t) === void 0 ? null : this.graphStore.getPortCycleEdgeIds(t);
1194
1178
  }
1195
1179
  getPortAdjacentEdgeIds(t) {
1196
- return this.graphStore.getPortAdjacentEdgeIds(t);
1180
+ return this.graphStore.getPort(t) === void 0 ? null : this.graphStore.getPortAdjacentEdgeIds(t);
1197
1181
  }
1198
1182
  getNodeIncomingEdgeIds(t) {
1199
- return this.graphStore.getNodeIncomingEdgeIds(t);
1183
+ return this.graphStore.getNode(t) === void 0 ? null : this.graphStore.getNodeIncomingEdgeIds(t);
1200
1184
  }
1201
1185
  getNodeOutcomingEdgeIds(t) {
1202
- return this.graphStore.getNodeOutcomingEdgeIds(t);
1186
+ return this.graphStore.getNode(t) === void 0 ? null : this.graphStore.getNodeOutcomingEdgeIds(t);
1203
1187
  }
1204
1188
  getNodeCycleEdgeIds(t) {
1205
- return this.graphStore.getNodeCycleEdgeIds(t);
1189
+ return this.graphStore.getNode(t) === void 0 ? null : this.graphStore.getNodeCycleEdgeIds(t);
1206
1190
  }
1207
1191
  getNodeAdjacentEdgeIds(t) {
1208
- return this.graphStore.getNodeAdjacentEdgeIds(t);
1192
+ return this.graphStore.getNode(t) === void 0 ? null : this.graphStore.getNodeAdjacentEdgeIds(t);
1209
1193
  }
1210
1194
  }
1211
1195
  class At {
@@ -1216,9 +1200,9 @@ class At {
1216
1200
  n(this, "edgeShapeFactory");
1217
1201
  this.apiOptions = t;
1218
1202
  const o = at(this.apiOptions), r = new ut(), i = new gt();
1219
- this.model = new St(i), this.transformation = new wt(r);
1203
+ this.model = new Et(i), this.transformation = new wt(r);
1220
1204
  const s = new xt(i, r);
1221
- this.canvasController = new Et(
1205
+ this.canvasController = new St(
1222
1206
  i,
1223
1207
  s,
1224
1208
  r,
@@ -1309,18 +1293,18 @@ class At {
1309
1293
  const V = (e, t, o) => {
1310
1294
  const { x: r, y: i, width: s, height: h } = e.getBoundingClientRect();
1311
1295
  return t >= r && t <= r + s && o >= i && o <= i + h;
1312
- }, b = (e, t, o) => t >= 0 && t <= e.innerWidth && o >= 0 && o <= e.innerHeight, p = (e, t) => {
1296
+ }, p = (e, t, o) => t >= 0 && t <= e.innerWidth && o >= 0 && o <= e.innerHeight, b = (e, t) => {
1313
1297
  t !== null ? e.style.cursor = t : e.style.removeProperty("cursor");
1314
1298
  }, Tt = (e) => {
1315
- var g, y, x, f, A, S;
1299
+ var g, y, x, f, A, E;
1316
1300
  const t = ((g = e == null ? void 0 : e.events) == null ? void 0 : g.onNodeDrag) ?? (() => {
1317
1301
  }), o = ((y = e == null ? void 0 : e.events) == null ? void 0 : y.onBeforeNodeDrag) ?? (() => !0), r = ((x = e == null ? void 0 : e.events) == null ? void 0 : x.onNodeDragFinished) ?? (() => {
1318
- }), i = (e == null ? void 0 : e.moveOnTop) === !1, s = (f = e == null ? void 0 : e.mouse) == null ? void 0 : f.dragCursor, h = s !== void 0 ? s : "grab", d = (A = e == null ? void 0 : e.mouse) == null ? void 0 : A.mouseDownEventValidator, c = d !== void 0 ? d : (T) => T.button === 0, l = (S = e == null ? void 0 : e.mouse) == null ? void 0 : S.mouseUpEventValidator;
1302
+ }), i = (e == null ? void 0 : e.moveOnTop) === !1, s = (f = e == null ? void 0 : e.mouse) == null ? void 0 : f.dragCursor, h = s !== void 0 ? s : "grab", c = (A = e == null ? void 0 : e.mouse) == null ? void 0 : A.mouseDownEventVerifier, d = c !== void 0 ? c : (T) => T.button === 0, l = (E = e == null ? void 0 : e.mouse) == null ? void 0 : E.mouseUpEventVerifier;
1319
1303
  return {
1320
1304
  freezePriority: i,
1321
1305
  dragCursor: h,
1322
- mouseDownEventValidator: c,
1323
- mouseUpEventValidator: l !== void 0 ? l : (T) => T.button === 0,
1306
+ mouseDownEventVerifier: d,
1307
+ mouseUpEventVerifier: l !== void 0 ? l : (T) => T.button === 0,
1324
1308
  onNodeDrag: t,
1325
1309
  onBeforeNodeDrag: o,
1326
1310
  onNodeDragFinished: r
@@ -1333,25 +1317,25 @@ class Mt {
1333
1317
  n(this, "maxNodePriority", 0);
1334
1318
  n(this, "nodes", /* @__PURE__ */ new Map());
1335
1319
  n(this, "grabbedNodeId", null);
1336
- n(this, "nodeIdGenerator", new m(
1320
+ n(this, "nodeIdGenerator", new I(
1337
1321
  (t) => this.nodes.has(t)
1338
1322
  ));
1339
1323
  n(this, "element", null);
1340
1324
  n(this, "onWindowMouseMove", (t) => {
1341
- if (this.element !== null && (!V(this.element, t.clientX, t.clientY) || !b(this.window, t.clientX, t.clientY))) {
1325
+ if (this.element !== null && (!V(this.element, t.clientX, t.clientY) || !p(this.window, t.clientX, t.clientY))) {
1342
1326
  this.cancelMouseDrag();
1343
1327
  return;
1344
1328
  }
1345
1329
  this.grabbedNodeId !== null && this.dragNode(this.grabbedNodeId, t.movementX, t.movementY);
1346
1330
  });
1347
1331
  n(this, "onWindowMouseUp", (t) => {
1348
- this.options.mouseUpEventValidator(t) && this.cancelMouseDrag();
1332
+ this.options.mouseUpEventVerifier(t) && this.cancelMouseDrag();
1349
1333
  });
1350
1334
  n(this, "onWindowTouchMove", (t) => {
1351
1335
  if (t.touches.length !== 1)
1352
1336
  return;
1353
1337
  const o = t.touches[0];
1354
- if (this.element !== null && (!V(this.element, o.clientX, o.clientY) || !b(this.window, o.clientX, o.clientY))) {
1338
+ if (this.element !== null && (!V(this.element, o.clientX, o.clientY) || !p(this.window, o.clientX, o.clientY))) {
1355
1339
  this.cancelTouchDrag();
1356
1340
  return;
1357
1341
  }
@@ -1381,7 +1365,7 @@ class Mt {
1381
1365
  const o = this.nodeIdGenerator.create(t.id);
1382
1366
  this.canvas.addNode({ ...t, id: o }), this.updateMaxNodePriority(o);
1383
1367
  const r = (s) => {
1384
- if (this.element === null || !this.options.mouseDownEventValidator(s))
1368
+ if (this.element === null || !this.options.mouseDownEventVerifier(s))
1385
1369
  return;
1386
1370
  const h = this.model.getNode(o);
1387
1371
  this.options.onBeforeNodeDrag({
@@ -1389,7 +1373,7 @@ class Mt {
1389
1373
  element: t.element,
1390
1374
  x: h.x,
1391
1375
  y: h.y
1392
- }) && (s.stopImmediatePropagation(), this.grabbedNodeId = o, p(this.element, this.options.dragCursor), this.moveNodeOnTop(o), this.window.addEventListener("mouseup", this.onWindowMouseUp), this.window.addEventListener("mousemove", this.onWindowMouseMove));
1376
+ }) && (s.stopImmediatePropagation(), this.grabbedNodeId = o, b(this.element, this.options.dragCursor), this.moveNodeOnTop(o), this.window.addEventListener("mouseup", this.onWindowMouseUp), this.window.addEventListener("mousemove", this.onWindowMouseMove));
1393
1377
  }, i = (s) => {
1394
1378
  if (s.touches.length !== 1)
1395
1379
  return;
@@ -1454,12 +1438,12 @@ class Mt {
1454
1438
  const i = this.model.getNode(t);
1455
1439
  if (i === null)
1456
1440
  return;
1457
- const s = this.canvas.transformation.getContentMatrix(), h = s.scale * i.x + s.dx, d = s.scale * i.y + s.dy, c = h + o, l = d + r, a = this.canvas.transformation.getViewportMatrix(), g = a.scale * c + a.dx, y = a.scale * l + a.dy;
1441
+ const s = this.canvas.transformation.getContentMatrix(), h = s.scale * i.x + s.x, c = s.scale * i.y + s.y, d = h + o, l = c + r, a = this.canvas.transformation.getViewportMatrix(), g = a.scale * d + a.x, y = a.scale * l + a.y;
1458
1442
  this.canvas.updateNode(t, { x: g, y }), this.options.onNodeDrag({
1459
1443
  nodeId: t,
1460
1444
  element: i.element,
1461
- x: i.x,
1462
- y: i.y
1445
+ x: g,
1446
+ y
1463
1447
  });
1464
1448
  }
1465
1449
  updateMaxNodePriority(t) {
@@ -1482,7 +1466,7 @@ class Mt {
1482
1466
  element: t.element,
1483
1467
  x: t.x,
1484
1468
  y: t.y
1485
- }), this.grabbedNodeId = null, this.element !== null && p(this.element, null), this.removeMouseDragListeners();
1469
+ }), this.grabbedNodeId = null, this.element !== null && b(this.element, null), this.removeMouseDragListeners();
1486
1470
  }
1487
1471
  removeMouseDragListeners() {
1488
1472
  this.window.removeEventListener("mouseup", this.onWindowMouseUp), this.window.removeEventListener("mousemove", this.onWindowMouseMove);
@@ -1504,35 +1488,35 @@ class Mt {
1504
1488
  const Ct = (e) => {
1505
1489
  const t = e.minX !== null ? e.minX : -1 / 0, o = e.maxX !== null ? e.maxX : 1 / 0, r = e.minY !== null ? e.minY : -1 / 0, i = e.maxY !== null ? e.maxY : 1 / 0;
1506
1490
  return (s) => {
1507
- let h = s.nextTransform.dx, d = s.nextTransform.dy;
1508
- h < t && h < s.prevTransform.dx && (h = Math.min(s.prevTransform.dx, t));
1509
- const c = s.canvasWidth * s.prevTransform.scale;
1510
- h > o - c && h > s.prevTransform.dx && (h = Math.max(s.prevTransform.dx, o - c)), d < r && d < s.prevTransform.dy && (d = Math.min(s.prevTransform.dy, r));
1511
- const l = s.canvasHeight * s.prevTransform.scale;
1512
- return d > i - l && d > s.prevTransform.dy && (d = Math.max(s.prevTransform.dy, i - l)), { scale: s.nextTransform.scale, dx: h, dy: d };
1491
+ let h = s.nextTransform.x, c = s.nextTransform.y;
1492
+ h < t && h < s.prevTransform.x && (h = Math.min(s.prevTransform.x, t));
1493
+ const d = s.canvasWidth * s.prevTransform.scale, l = o - d;
1494
+ h > l && h > s.prevTransform.x && (h = Math.max(s.prevTransform.x, l)), c < r && c < s.prevTransform.y && (c = Math.min(s.prevTransform.y, r));
1495
+ const a = s.canvasHeight * s.prevTransform.scale, g = i - a;
1496
+ return c > g && c > s.prevTransform.y && (c = Math.max(s.prevTransform.y, g)), { scale: s.nextTransform.scale, x: h, y: c };
1513
1497
  };
1514
1498
  }, Nt = (e) => {
1515
1499
  const t = e.maxContentScale, o = e.minContentScale, r = t !== null ? 1 / t : 0, i = o !== null ? 1 / o : 1 / 0;
1516
1500
  return (s) => {
1517
- const h = s.prevTransform, d = s.nextTransform;
1518
- let c = d.scale, l = d.dx, a = d.dy;
1519
- if (d.scale > i && d.scale > h.scale) {
1520
- c = Math.max(h.scale, i), l = h.dx, a = h.dy;
1521
- const g = (c - h.scale) / (d.scale - h.scale);
1522
- l = h.dx + (d.dx - h.dx) * g, a = h.dy + (d.dy - h.dy) * g;
1501
+ const h = s.prevTransform, c = s.nextTransform;
1502
+ let d = c.scale, l = c.x, a = c.y;
1503
+ if (c.scale > i && c.scale > h.scale) {
1504
+ d = Math.max(h.scale, i), l = h.x, a = h.y;
1505
+ const g = (d - h.scale) / (c.scale - h.scale);
1506
+ l = h.x + (c.x - h.x) * g, a = h.y + (c.y - h.y) * g;
1523
1507
  }
1524
- if (d.scale < r && d.scale < h.scale) {
1525
- c = Math.min(h.scale, r), l = h.dx, a = h.dy;
1526
- const g = (c - h.scale) / (d.scale - h.scale);
1527
- l = h.dx + (d.dx - h.dx) * g, a = h.dy + (d.dy - h.dy) * g;
1508
+ if (c.scale < r && c.scale < h.scale) {
1509
+ d = Math.min(h.scale, r), l = h.x, a = h.y;
1510
+ const g = (d - h.scale) / (c.scale - h.scale);
1511
+ l = h.x + (c.x - h.x) * g, a = h.y + (c.y - h.y) * g;
1528
1512
  }
1529
1513
  return {
1530
- scale: c,
1531
- dx: l,
1532
- dy: a
1514
+ scale: d,
1515
+ x: l,
1516
+ y: a
1533
1517
  };
1534
1518
  };
1535
- }, Lt = (e) => (t) => e.reduce(
1519
+ }, Pt = (e) => (t) => e.reduce(
1536
1520
  (o, r) => r({
1537
1521
  prevTransform: t.prevTransform,
1538
1522
  nextTransform: o,
@@ -1557,41 +1541,41 @@ const Ct = (e) => {
1557
1541
  maxY: e.maxY ?? 1 / 0
1558
1542
  });
1559
1543
  }
1560
- }, Pt = (e) => {
1561
- var f, A, S, T, X, P, D, I, j;
1544
+ }, Lt = (e) => {
1545
+ var f, A, E, T, X, L, D, m, j;
1562
1546
  const t = (f = e == null ? void 0 : e.scale) == null ? void 0 : f.mouseWheelSensitivity, o = t !== void 0 ? t : 1.2, r = e == null ? void 0 : e.transformPreprocessor;
1563
1547
  let i;
1564
- r !== void 0 ? Array.isArray(r) ? i = Lt(
1548
+ r !== void 0 ? Array.isArray(r) ? i = Pt(
1565
1549
  r.map(
1566
- (L) => J(L)
1550
+ (P) => J(P)
1567
1551
  )
1568
- ) : i = J(r) : i = (L) => L.nextTransform;
1569
- const s = ((A = e == null ? void 0 : e.shift) == null ? void 0 : A.cursor) !== void 0 ? e.shift.cursor : "grab", h = ((S = e == null ? void 0 : e.events) == null ? void 0 : S.onBeforeTransformChange) ?? (() => {
1570
- }), d = ((T = e == null ? void 0 : e.events) == null ? void 0 : T.onTransformChange) ?? (() => {
1571
- }), c = (X = e == null ? void 0 : e.shift) == null ? void 0 : X.mouseDownEventValidator, l = c !== void 0 ? c : (L) => L.button === 0, a = (P = e == null ? void 0 : e.shift) == null ? void 0 : P.mouseUpEventValidator, g = a !== void 0 ? a : (L) => L.button === 0, y = (D = e == null ? void 0 : e.scale) == null ? void 0 : D.mouseWheelEventValidator, x = y !== void 0 ? y : () => !0;
1552
+ ) : i = J(r) : i = (P) => P.nextTransform;
1553
+ const s = ((A = e == null ? void 0 : e.shift) == null ? void 0 : A.cursor) !== void 0 ? e.shift.cursor : "grab", h = ((E = e == null ? void 0 : e.events) == null ? void 0 : E.onBeforeTransformChange) ?? (() => {
1554
+ }), c = ((T = e == null ? void 0 : e.events) == null ? void 0 : T.onTransformChange) ?? (() => {
1555
+ }), d = (X = e == null ? void 0 : e.shift) == null ? void 0 : X.mouseDownEventVerifier, l = d !== void 0 ? d : (P) => P.button === 0, a = (L = e == null ? void 0 : e.shift) == null ? void 0 : L.mouseUpEventVerifier, g = a !== void 0 ? a : (P) => P.button === 0, y = (D = e == null ? void 0 : e.scale) == null ? void 0 : D.mouseWheelEventVerifier, x = y !== void 0 ? y : () => !0;
1572
1556
  return {
1573
1557
  wheelSensitivity: o,
1574
- onTransformStarted: ((I = e == null ? void 0 : e.events) == null ? void 0 : I.onTransformStarted) ?? (() => {
1558
+ onTransformStarted: ((m = e == null ? void 0 : e.events) == null ? void 0 : m.onTransformStarted) ?? (() => {
1575
1559
  }),
1576
1560
  onTransformFinished: ((j = e == null ? void 0 : e.events) == null ? void 0 : j.onTransformFinished) ?? (() => {
1577
1561
  }),
1578
1562
  onBeforeTransformChange: h,
1579
- onTransformChange: d,
1563
+ onTransformChange: c,
1580
1564
  transformPreprocessor: i,
1581
1565
  shiftCursor: s,
1582
- mouseDownEventValidator: l,
1583
- mouseUpEventValidator: g,
1584
- mouseWheelEventValidator: x
1566
+ mouseDownEventVerifier: l,
1567
+ mouseUpEventVerifier: g,
1568
+ mouseWheelEventVerifier: x
1585
1569
  };
1586
1570
  }, B = (e) => {
1587
1571
  const t = [], o = e.touches.length;
1588
- for (let d = 0; d < o; d++)
1589
- t.push([e.touches[d].clientX, e.touches[d].clientY]);
1572
+ for (let c = 0; c < o; c++)
1573
+ t.push([e.touches[c].clientX, e.touches[c].clientY]);
1590
1574
  const r = t.reduce(
1591
- (d, c) => [d[0] + c[0], d[1] + c[1]],
1575
+ (c, d) => [c[0] + d[0], c[1] + d[1]],
1592
1576
  [0, 0]
1593
- ), i = [r[0] / o, r[1] / o], h = t.map((d) => [d[0] - i[0], d[1] - i[1]]).reduce(
1594
- (d, c) => d + Math.sqrt(c[0] * c[0] + c[1] * c[1]),
1577
+ ), i = [r[0] / o, r[1] / o], h = t.map((c) => [c[0] - i[0], c[1] - i[1]]).reduce(
1578
+ (c, d) => c + Math.sqrt(d[0] * d[0] + d[1] * d[1]),
1595
1579
  0
1596
1580
  );
1597
1581
  return {
@@ -1603,14 +1587,14 @@ const Ct = (e) => {
1603
1587
  };
1604
1588
  }, Dt = (e, t, o) => ({
1605
1589
  scale: e.scale,
1606
- dx: e.dx + e.scale * t,
1607
- dy: e.dy + e.scale * o
1608
- }), It = (e, t, o, r) => ({
1590
+ x: e.x + e.scale * t,
1591
+ y: e.y + e.scale * o
1592
+ }), mt = (e, t, o, r) => ({
1609
1593
  scale: e.scale * t,
1610
- dx: e.scale * (1 - t) * o + e.dx,
1611
- dy: e.scale * (1 - t) * r + e.dy
1594
+ x: e.scale * (1 - t) * o + e.x,
1595
+ y: e.scale * (1 - t) * r + e.y
1612
1596
  });
1613
- class mt {
1597
+ class It {
1614
1598
  constructor(t, o) {
1615
1599
  n(this, "model");
1616
1600
  n(this, "transformation");
@@ -1618,10 +1602,10 @@ class mt {
1618
1602
  n(this, "prevTouches", null);
1619
1603
  n(this, "window", window);
1620
1604
  n(this, "onMouseDown", (t) => {
1621
- this.element === null || !this.options.mouseDownEventValidator(t) || (p(this.element, this.options.shiftCursor), this.window.addEventListener("mousemove", this.onWindowMouseMove), this.window.addEventListener("mouseup", this.onWindowMouseUp), this.options.onTransformStarted());
1605
+ this.element === null || !this.options.mouseDownEventVerifier(t) || (b(this.element, this.options.shiftCursor), this.window.addEventListener("mousemove", this.onWindowMouseMove), this.window.addEventListener("mouseup", this.onWindowMouseUp), this.options.onTransformStarted());
1622
1606
  });
1623
1607
  n(this, "onWindowMouseMove", (t) => {
1624
- if (this.element === null || !V(this.element, t.clientX, t.clientY) || !b(this.window, t.clientX, t.clientY)) {
1608
+ if (this.element === null || !V(this.element, t.clientX, t.clientY) || !p(this.window, t.clientX, t.clientY)) {
1625
1609
  this.stopMouseDrag();
1626
1610
  return;
1627
1611
  }
@@ -1629,14 +1613,14 @@ class mt {
1629
1613
  this.moveViewport(this.element, o, r);
1630
1614
  });
1631
1615
  n(this, "onWindowMouseUp", (t) => {
1632
- this.element === null || !this.options.mouseUpEventValidator(t) || this.stopMouseDrag();
1616
+ this.element === null || !this.options.mouseUpEventVerifier(t) || this.stopMouseDrag();
1633
1617
  });
1634
1618
  n(this, "onWheelScroll", (t) => {
1635
- if (!this.options.mouseWheelEventValidator(t))
1619
+ if (!this.options.mouseWheelEventVerifier(t))
1636
1620
  return;
1637
- t.preventDefault();
1638
- const { left: o, top: r } = this.element.getBoundingClientRect(), i = t.clientX - o, s = t.clientY - r, d = 1 / (t.deltaY < 0 ? this.options.wheelSensitivity : 1 / this.options.wheelSensitivity);
1639
- this.scaleViewport(this.element, d, i, s);
1621
+ t.preventDefault(), this.options.onTransformStarted();
1622
+ const { left: o, top: r } = this.element.getBoundingClientRect(), i = t.clientX - o, s = t.clientY - r, c = 1 / (t.deltaY < 0 ? this.options.wheelSensitivity : 1 / this.options.wheelSensitivity);
1623
+ this.scaleViewport(this.element, c, i, s), this.options.onTransformFinished();
1640
1624
  });
1641
1625
  n(this, "onTouchStart", (t) => {
1642
1626
  this.prevTouches = B(t), this.window.addEventListener("touchmove", this.onWindowTouchMove), this.window.addEventListener("touchend", this.onWindowTouchFinish), this.window.addEventListener("touchcancel", this.onWindowTouchFinish), this.options.onTransformStarted();
@@ -1647,7 +1631,7 @@ class mt {
1647
1631
  return;
1648
1632
  const r = B(t);
1649
1633
  if (!r.touches.every(
1650
- (s) => V(o, s[0], s[1]) && b(this.window, s[0], s[1])
1634
+ (s) => V(o, s[0], s[1]) && p(this.window, s[0], s[1])
1651
1635
  )) {
1652
1636
  this.stopTouchDrag();
1653
1637
  return;
@@ -1657,8 +1641,8 @@ class mt {
1657
1641
  -(r.x - this.prevTouches.x),
1658
1642
  -(r.y - this.prevTouches.y)
1659
1643
  ), r.touchesCnt === 2) {
1660
- const { left: s, top: h } = o.getBoundingClientRect(), d = this.prevTouches.x - s, c = this.prevTouches.y - h, a = 1 / (r.scale / this.prevTouches.scale);
1661
- this.scaleViewport(o, a, d, c);
1644
+ const { left: s, top: h } = o.getBoundingClientRect(), c = this.prevTouches.x - s, d = this.prevTouches.y - h, a = 1 / (r.scale / this.prevTouches.scale);
1645
+ this.scaleViewport(o, a, c, d);
1662
1646
  }
1663
1647
  this.prevTouches = r;
1664
1648
  });
@@ -1675,7 +1659,7 @@ class mt {
1675
1659
  this.canvas.patchViewportMatrix(i), this.options.onTransformChange();
1676
1660
  }));
1677
1661
  n(this, "options");
1678
- this.canvas = t, this.options = Pt(o), this.transformation = this.canvas.transformation, this.model = this.canvas.model;
1662
+ this.canvas = t, this.options = Lt(o), this.transformation = this.canvas.transformation, this.model = this.canvas.model;
1679
1663
  }
1680
1664
  attach(t) {
1681
1665
  return this.detach(), this.element = t, this.observer.observe(this.element), this.element.addEventListener("mousedown", this.onMouseDown), this.element.addEventListener("wheel", this.onWheelScroll), this.element.addEventListener("touchstart", this.onTouchStart), this.canvas.attach(this.element), this;
@@ -1724,26 +1708,26 @@ class mt {
1724
1708
  }
1725
1709
  moveViewport(t, o, r) {
1726
1710
  this.options.onBeforeTransformChange();
1727
- const i = this.transformation.getViewportMatrix(), s = Dt(i, o, r), { width: h, height: d } = t.getBoundingClientRect(), c = this.options.transformPreprocessor({
1711
+ const i = this.transformation.getViewportMatrix(), s = Dt(i, o, r), { width: h, height: c } = t.getBoundingClientRect(), d = this.options.transformPreprocessor({
1728
1712
  prevTransform: i,
1729
1713
  nextTransform: s,
1730
1714
  canvasWidth: h,
1731
- canvasHeight: d
1715
+ canvasHeight: c
1732
1716
  });
1733
- this.canvas.patchViewportMatrix(c), this.options.onTransformChange();
1717
+ this.canvas.patchViewportMatrix(d), this.options.onTransformChange();
1734
1718
  }
1735
1719
  scaleViewport(t, o, r, i) {
1736
1720
  this.options.onBeforeTransformChange();
1737
- const s = this.canvas.transformation.getViewportMatrix(), h = It(s, o, r, i), { width: d, height: c } = t.getBoundingClientRect(), l = this.options.transformPreprocessor({
1721
+ const s = this.canvas.transformation.getViewportMatrix(), h = mt(s, o, r, i), { width: c, height: d } = t.getBoundingClientRect(), l = this.options.transformPreprocessor({
1738
1722
  prevTransform: s,
1739
1723
  nextTransform: h,
1740
- canvasWidth: d,
1741
- canvasHeight: c
1724
+ canvasWidth: c,
1725
+ canvasHeight: d
1742
1726
  });
1743
1727
  this.canvas.patchViewportMatrix(l), this.options.onTransformChange();
1744
1728
  }
1745
1729
  stopMouseDrag() {
1746
- this.element !== null && p(this.element, null), this.removeMouseDragListeners(), this.options.onTransformFinished();
1730
+ this.element !== null && b(this.element, null), this.removeMouseDragListeners(), this.options.onTransformFinished();
1747
1731
  }
1748
1732
  removeMouseDragListeners() {
1749
1733
  this.window.removeEventListener("mousemove", this.onWindowMouseMove), this.window.removeEventListener("mouseup", this.onWindowMouseUp);
@@ -1797,7 +1781,7 @@ class Vt {
1797
1781
  n(this, "transformation");
1798
1782
  n(this, "model");
1799
1783
  n(this, "nodes", new $t());
1800
- n(this, "nodeIdGenerator", new m(
1784
+ n(this, "nodeIdGenerator", new I(
1801
1785
  (t) => this.nodes.hasKey(t)
1802
1786
  ));
1803
1787
  n(this, "nodesResizeObserver");
@@ -1866,7 +1850,7 @@ class Vt {
1866
1850
  });
1867
1851
  }
1868
1852
  }
1869
- class pt {
1853
+ class bt {
1870
1854
  constructor() {
1871
1855
  n(this, "coreOptions");
1872
1856
  n(this, "dragOptions");
@@ -1889,18 +1873,18 @@ class pt {
1889
1873
  }
1890
1874
  build() {
1891
1875
  let t = new At(this.coreOptions);
1892
- return this.hasResizeReactiveNodes && (t = new Vt(t)), this.isDraggable && (t = new Mt(t, this.dragOptions)), this.isTransformable && (t = new mt(t, this.transformOptions)), t;
1876
+ return this.hasResizeReactiveNodes && (t = new Vt(t)), this.isDraggable && (t = new Mt(t, this.dragOptions)), this.isTransformable && (t = new It(t, this.transformOptions)), t;
1893
1877
  }
1894
1878
  }
1895
1879
  export {
1896
1880
  nt as BezierEdgeShape,
1897
1881
  At as CanvasCore,
1898
1882
  st as HorizontalEdgeShape,
1899
- pt as HtmlGraphBuilder,
1900
- E as HtmlGraphError,
1883
+ bt as HtmlGraphBuilder,
1884
+ S as HtmlGraphError,
1901
1885
  Vt as ResizeReactiveNodesCanvas,
1902
1886
  ht as StraightEdgeShape,
1903
1887
  Mt as UserDraggableNodesCanvas,
1904
- mt as UserTransformableCanvas,
1905
- dt as VerticalEdgeShape
1888
+ It as UserTransformableCanvas,
1889
+ ct as VerticalEdgeShape
1906
1890
  };