@linkurious/ogma-annotations 1.1.3 → 1.1.5

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/index.mjs CHANGED
@@ -589,7 +589,7 @@ function Re(u, l, t) {
589
589
  function qt(u) {
590
590
  return { start: Ot(u), end: Ft(u) };
591
591
  }
592
- function wt(u, l, t, r) {
592
+ function bt(u, l, t, r) {
593
593
  l === "start" ? Ne(u, t, r) : Re(u, t, r);
594
594
  }
595
595
  const He = (u) => parseInt(u.getAttribute("data-handle-id") || "-1");
@@ -1399,7 +1399,7 @@ var Ve = { exports: {} };
1399
1399
  h = (i = e[e.length - 1]).width, i.width > o.width ? (i.value = i.value.slice(0, -1), i.width = U(i, i.font), y += i.width) : e.pop(), y -= h;
1400
1400
  e[e.length - 1] instanceof pt && e.pop(), i = e[e.length - 1] || i || {}, o.font = S(o.font, i.bold, i.italic, ""), o.href = e.length ? i.href : null, o.rel = e.length ? i.rel : null, o.target = e.length ? i.target : null, e.push(o);
1401
1401
  }
1402
- function mt(e) {
1402
+ function vt(e) {
1403
1403
  return Math.round(1e6 * e) / 1e6;
1404
1404
  }
1405
1405
  function ve(e) {
@@ -1433,7 +1433,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
1433
1433
  function gn(e, n) {
1434
1434
  var o = [], i = n.font(), h = i.size, y = i.family, w = n.align(), x = n.createElement();
1435
1435
  if (e.length) {
1436
- var b = i.height, E = n.valign(), O = n.height()(), M = n.width()(0), I = !isFinite(M) && e.length === 1, z = I ? null : n.x(), R = mt(b / h), Q = I ? null : mt(b / (1.15 * h + (b - h) / 2));
1436
+ var b = i.height, E = n.valign(), O = n.height()(), M = n.width()(0), I = !isFinite(M) && e.length === 1, z = I ? null : n.x(), R = vt(b / h), Q = I ? null : vt(b / (1.15 * h + (b - h) / 2));
1437
1437
  if (pn[E] && isFinite(O)) {
1438
1438
  var P = E === "bottom" ? 1 : 0.5;
1439
1439
  Q += (O * P - b * e.length * P) / h;
@@ -1447,21 +1447,21 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
1447
1447
  }
1448
1448
  tt = "tspan", Z = null, j = "";
1449
1449
  }, it = 0, et = e.length; it < et; it++) {
1450
- var ot = "", ut = "", st = 0, at = e[it];
1451
- if (at.length) {
1450
+ var at = "", ut = "", st = 0, lt = e[it];
1451
+ if (lt.length) {
1452
1452
  $ = [];
1453
- for (var vt = 0, It = 0, lt = void 0, W = 0, $t = at.length; W < $t; W++) {
1454
- var q = at[W], K = q.font;
1455
- q.whitespace && vt++, It += q.width, W && !q.tracking && !st && Kt(K.id, ot) && Kt(q.class, ut) && Kt(lt, q.href) ? j += q.value : (_(), j = q.value, Z = { fontFamily: K.family !== y ? K.family : null, fontSize: K.size !== h ? K.size : null, fontWeight: K.weight || null, fontStyle: K.style || null, fontVariant: K.variant !== "normal" && K.variant || null, fill: K.color || null, baselineShift: K.baseline ? 100 * K.baseline + "%" : null, className: q.class || null }, st && (Z.dx = mt(st), st = 0), q.tracking && (st = K.size * q.tracking), q.href && !lt ? (lt = q.href, tt = "a", Z.href = lt, Z.rel = q.rel, Z.target = q.target) : lt = null, ot = K.id, ut = q.class);
1453
+ for (var xt = 0, It = 0, ht = void 0, W = 0, $t = lt.length; W < $t; W++) {
1454
+ var q = lt[W], K = q.font;
1455
+ q.whitespace && xt++, It += q.width, W && !q.tracking && !st && Kt(K.id, at) && Kt(q.class, ut) && Kt(ht, q.href) ? j += q.value : (_(), j = q.value, Z = { fontFamily: K.family !== y ? K.family : null, fontSize: K.size !== h ? K.size : null, fontWeight: K.weight || null, fontStyle: K.style || null, fontVariant: K.variant !== "normal" && K.variant || null, fill: K.color || null, baselineShift: K.baseline ? 100 * K.baseline + "%" : null, className: q.class || null }, st && (Z.dx = vt(st), st = 0), q.tracking && (st = K.size * q.tracking), q.href && !ht ? (ht = q.href, tt = "a", Z.href = ht, Z.rel = q.rel, Z.target = q.target) : ht = null, at = K.id, ut = q.class);
1456
1456
  }
1457
1457
  if (_(), I)
1458
1458
  o.push.apply(o, ve($));
1459
1459
  else {
1460
- var Nt = null, _t = it === et - 1 || at[at.length - 1] instanceof nt;
1461
- L && at.length > 1 && !_t && (Nt = mt((M - It) / vt)), o.push(x.apply(void 0, ["tspan", { wordSpacing: Nt, x: z(it) + H, dy: mt(it ? R : Q) + "em" }].concat(ve($))));
1460
+ var Nt = null, _t = it === et - 1 || lt[lt.length - 1] instanceof nt;
1461
+ L && lt.length > 1 && !_t && (Nt = vt((M - It) / xt)), o.push(x.apply(void 0, ["tspan", { wordSpacing: Nt, x: z(it) + H, dy: vt(it ? R : Q) + "em" }].concat(ve($))));
1462
1462
  }
1463
1463
  } else
1464
- o.push(x("tspan", { x: z(it), dy: mt(it ? R : Q) + "em" }, " "));
1464
+ o.push(x("tspan", { x: z(it), dy: vt(it ? R : Q) + "em" }, " "));
1465
1465
  }
1466
1466
  }
1467
1467
  return x.apply(void 0, ["text", { fontFamily: y, fontSize: h, textAnchor: fn[w] || "start" }].concat(o));
@@ -1490,8 +1490,8 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
1490
1490
  var et = 0;
1491
1491
  if (E === "right" ? et += b - $ : E === "center" ? et += b / 2 - $ / 2 : E === "justify" && (j.whitespace || j instanceof nt) && (P += tt), o.fillText(j.value, P + et, L + it), j.href) {
1492
1492
  o.beginPath(), o.strokeStyle = o.fillStyle;
1493
- var ot = Math.floor(L + 0.45 * y) + 0.5;
1494
- o.moveTo(P + et, ot), o.lineTo(P + et + j.width, ot), o.stroke();
1493
+ var at = Math.floor(L + 0.45 * y) + 0.5;
1494
+ o.moveTo(P + et, at), o.lineTo(P + et + j.width, at), o.stroke();
1495
1495
  }
1496
1496
  P += j.width;
1497
1497
  });
@@ -1574,21 +1574,21 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
1574
1574
  else if (_.whitespace || $ + _.width < I(H))
1575
1575
  $ += _.width;
1576
1576
  else if (Z.length) {
1577
- var et = void 0, ot = void 0;
1577
+ var et = void 0, at = void 0;
1578
1578
  do {
1579
- ot = !0, et = Z.pop();
1579
+ at = !0, et = Z.pop();
1580
1580
  var ut = b[et.index], st = void 0;
1581
- ut instanceof pt && (st = U("-", ut.font), et.width + st > I(H) && (ot = !Z.length));
1582
- } while (!ot);
1581
+ ut instanceof pt && (st = U("-", ut.font), et.width + st > I(H) && (at = !Z.length));
1582
+ } while (!at);
1583
1583
  tt.push(et.index + 1), $ = 0, H++, L = et.index, Z = [];
1584
1584
  } else if (R === "break-word") {
1585
- var at = I(H);
1586
- if ($ + _.width > at) {
1587
- var vt = _.clone();
1585
+ var lt = I(H);
1586
+ if ($ + _.width > lt) {
1587
+ var xt = _.clone();
1588
1588
  do
1589
1589
  _.value = _.value.slice(0, -1), _.width = U(_, _.font), $ += _.width;
1590
- while (_.value && _.width > at);
1591
- vt.value = vt.value.slice(_.value.length), b.splice(L + 1, 0, new Et(), vt);
1590
+ while (_.value && _.width > lt);
1591
+ xt.value = xt.value.slice(_.value.length), b.splice(L + 1, 0, new Et(), xt);
1592
1592
  }
1593
1593
  tt.push(L + 1), $ = 0, H++;
1594
1594
  } else
@@ -1596,18 +1596,18 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
1596
1596
  L++, j = _.whitespace;
1597
1597
  }
1598
1598
  L !== tt[tt.length - 1] && tt.push(L);
1599
- var It = 0, lt = 0, W = tt.map(function(gt) {
1599
+ var It = 0, ht = 0, W = tt.map(function(gt) {
1600
1600
  for (var J, yt = It; (J = b[yt]) && (J.whitespace || !J.value); )
1601
1601
  yt++;
1602
1602
  for (var dt = gt, ne = null; dt > yt && (J = b[dt - 1]) && (J.whitespace || !(J.value || J instanceof pt)); )
1603
1603
  J instanceof nt && (ne = J), dt--;
1604
1604
  J instanceof pt && (J.value = "-", J.width = U("-", J.font)), It = gt;
1605
- var xt = b.slice(yt, dt).filter(function(ie) {
1605
+ var wt = b.slice(yt, dt).filter(function(ie) {
1606
1606
  return ie.value;
1607
1607
  });
1608
- return ne && xt.push(ne), xt.width = xt.reduce(function(ie, En) {
1608
+ return ne && wt.push(ne), wt.width = wt.reduce(function(ie, En) {
1609
1609
  return ie + En.width;
1610
- }, 0), xt.width > lt && (lt = xt.width), xt;
1610
+ }, 0), wt.width > ht && (ht = wt.width), wt;
1611
1611
  });
1612
1612
  if (W.hasLineOverflow = !1, z) {
1613
1613
  var $t = z === "ellipsis" ? "…" : z;
@@ -1625,7 +1625,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
1625
1625
  _t.font = O, _t.width = U(q, Q), me(Nt, K, _t), W.hasOverflow = !0;
1626
1626
  } else
1627
1627
  W.hasOverflow = !1;
1628
- return W.font = O, W.width = lt, W;
1628
+ return W.font = O, W.width = ht, W;
1629
1629
  }(y, this, w);
1630
1630
  return x.height = x.length * w.height, x.render = function(b) {
1631
1631
  return h.render(x, b);
@@ -2070,7 +2070,7 @@ class Bn extends Be {
2070
2070
  background: s,
2071
2071
  padding: d = 0
2072
2072
  } = t.properties.style || At, m = (g || 1) * c;
2073
- this.textArea.value = t.properties.content, this.editor.element.style.transform = `translate(${a.x}px, ${a.y}px)translate(-50%, -50%)translate(${r.width / 2 * c}px, ${r.height / 2 * c}px)`, this.editor.element.style.width = `${r.width * c}px`, this.editor.element.style.height = `${r.height * c}px`, this.textArea.style.font = `${m} ${f}`, this.textArea.style.fontFamily = f || "sans-serif", this.textArea.style.fontSize = `${m}px`, this.textArea.style.padding = `${d}px`, this.textArea.style.lineHeight = `${m}px`, this.textArea.style.boxSizing = "border-box", this.textArea.style.color = p || "black", this.textArea.style.background = s || "transparent", this.textArea.placeholder = this.placeholder, this.layer.refresh();
2073
+ this.textArea.value = t.properties.content, this.editor.element.style.transform = `translate(${a.x}px, ${a.y}px)translate(-50%, -50%)translate(${r.width / 2 * c}px, ${r.height / 2 * c}px)`, this.editor.element.style.width = `${r.width * c}px`, this.editor.element.style.height = `${r.height * c}px`, this.textArea.style.font = `${m} ${f}`, this.textArea.style.fontFamily = f || "sans-serif", this.textArea.style.fontSize = `${m}px`, this.textArea.style.padding = `${c * d}px`, this.textArea.style.lineHeight = `${m}px`, this.textArea.style.boxSizing = "border-box", this.textArea.style.color = p || "black", this.textArea.style.background = s || "transparent", this.textArea.placeholder = this.placeholder, this.layer.refresh();
2074
2074
  }
2075
2075
  select(t) {
2076
2076
  super.select(t), this.textArea.focus();
@@ -2134,7 +2134,7 @@ class Vn {
2134
2134
  Object.values(this.links).forEach(l);
2135
2135
  }
2136
2136
  }
2137
- const ht = (u) => u.properties.type === "arrow", bt = (u) => u.properties.type === "text", ze = (u) => u.type === "FeatureCollection", Un = {
2137
+ const ot = (u) => u.properties.type === "arrow", mt = (u) => u.properties.type === "text", ze = (u) => u.type === "FeatureCollection", Un = {
2138
2138
  magnetColor: "#3e8",
2139
2139
  detectMargin: 20,
2140
2140
  magnetHandleRadius: 5,
@@ -2184,31 +2184,31 @@ class Gn extends qe {
2184
2184
  });
2185
2185
  v(this, "_onFeatureDrag", (t, r) => {
2186
2186
  const a = r;
2187
- if (ht(t) && a === "line")
2187
+ if (ot(t) && a === "line")
2188
2188
  ["start", "end"].find((c) => {
2189
2189
  const f = c === "start" ? Ot(t) : Ft(t);
2190
2190
  return this._snapToText(t, a, f) || this._findAndSnapToNode(t, c, f);
2191
2191
  });
2192
- else if (ht(t) && a !== "line") {
2192
+ else if (ot(t) && a !== "line") {
2193
2193
  const c = a === "start" ? Ot(t) : Ft(t);
2194
2194
  this._snapToText(t, a, c) || this._findAndSnapToNode(t, a, c);
2195
2195
  } else
2196
- bt(t) && (this.activeLinks.forEach(({ arrow: c, side: f, connectionPoint: g }) => {
2196
+ mt(t) && (this.activeLinks.forEach(({ arrow: c, side: f, connectionPoint: g }) => {
2197
2197
  const p = this.getAnnotation(c), s = ct(t), d = ft(t), m = new G(g.x, g.y).mul({ x: s.width, y: s.height }).rotateRadians(this.ogma.view.getAngle()).add(d);
2198
2198
  p.geometry.coordinates[f === "start" ? 0 : 1] = [m.x, m.y];
2199
2199
  }), this.activeLinks.length && this.arrows.refreshLayer());
2200
2200
  this.layer.refresh(), this.emit(Bt, t, r);
2201
2201
  });
2202
2202
  v(this, "_onFeatureDragEnd", (t) => {
2203
- this.dragged !== null && ht(t) && Ot(this.dragged) && Le.forEach((r) => {
2203
+ this.dragged !== null && ot(t) && Ot(this.dragged) && Le.forEach((r) => {
2204
2204
  this.links.getArrowLink(t.id, r) && this.emit(Nn, {
2205
2205
  arrow: t,
2206
2206
  link: this.links.getArrowLink(t.id, r)
2207
2207
  });
2208
- }), (bt(t) || ht(t)) && this.onUpdate(t), this.dragged = null, this.activeLinks = [], this.textToMagnet = void 0, this.annotations.forEach((r) => r.enableDetection()), this.layer.refresh(), this.emit(St, t);
2208
+ }), (mt(t) || ot(t)) && this.onUpdate(t), this.dragged = null, this.activeLinks = [], this.textToMagnet = void 0, this.annotations.forEach((r) => r.enableDetection()), this.layer.refresh(), this.emit(St, t);
2209
2209
  });
2210
2210
  v(this, "_onFeatureDragStart", (t) => {
2211
- this.textToMagnet = void 0, ht(t) ? this.dragged = t : bt(t) && this.activeLinks.push(...this.links.getTargetLinks(t.id, "text")), this.annotations.forEach((r) => {
2211
+ this.textToMagnet = void 0, ot(t) ? this.dragged = t : mt(t) && this.activeLinks.push(...this.links.getTargetLinks(t.id, "text")), this.annotations.forEach((r) => {
2212
2212
  const a = r.getSelectedFeature();
2213
2213
  a && a !== t && r.unhover().unselect(), r.disableDetection();
2214
2214
  }), this.emit(Vt, t);
@@ -2227,7 +2227,7 @@ class Gn extends qe {
2227
2227
  g,
2228
2228
  p === "start" ? "end" : "start"
2229
2229
  ), d = t.positions.current[a], m = this.ogma.getNode(r).getAttribute("radius"), A = Ht(s, d, +m);
2230
- wt(g, p, A.x, A.y);
2230
+ bt(g, p, A.x, A.y);
2231
2231
  });
2232
2232
  }), this.arrows.refreshLayer(), this.texts.refreshLayer();
2233
2233
  });
@@ -2271,7 +2271,7 @@ class Gn extends qe {
2271
2271
  );
2272
2272
  let A = g;
2273
2273
  const T = +c.getAttribute("radius"), S = 1e-6;
2274
- (p.connectionPoint.x - (g.x - r) > S || p.connectionPoint.y - (g.y - a) > S) && (A = Ht(m, g, T)), wt(s, d, A.x, A.y);
2274
+ (p.connectionPoint.x - (g.x - r) > S || p.connectionPoint.y - (g.y - a) > S) && (A = Ht(m, g, T)), bt(s, d, A.x, A.y);
2275
2275
  });
2276
2276
  }), this.arrows.refreshLayer();
2277
2277
  }
@@ -2281,7 +2281,7 @@ class Gn extends qe {
2281
2281
  return !1;
2282
2282
  this.textToMagnet = c;
2283
2283
  const f = this.findMagnetPoint(Ce, c, a);
2284
- return f ? (wt(t, r, f.point.x, f.point.y), this.links.add(t, r, c.id, "text", f.magnet), !0) : !1;
2284
+ return f ? (bt(t, r, f.point.x, f.point.y), this.links.add(t, r, c.id, "text", f.magnet), !0) : !1;
2285
2285
  }
2286
2286
  _findAndSnapToNode(t, r, a) {
2287
2287
  const c = this.ogma.view.graphToScreenCoordinates(a), f = this.ogma.view.getElementAt(c);
@@ -2295,7 +2295,7 @@ class Gn extends qe {
2295
2295
  const S = Rt(t, r === "end" ? "start" : "end");
2296
2296
  T = Ht(S, T, g);
2297
2297
  }
2298
- wt(t, r, T.x, T.y), this.links.add(t, r, a.getId(), "node", T);
2298
+ bt(t, r, T.x, T.y), this.links.add(t, r, a.getId(), "node", T);
2299
2299
  }
2300
2300
  }
2301
2301
  refreshTextLinks() {
@@ -2305,7 +2305,7 @@ class Gn extends qe {
2305
2305
  return;
2306
2306
  t = !0;
2307
2307
  const p = this.getAnnotation(c), s = this.getAnnotation(f), d = ct(p), m = ft(p), A = new G(r.x, r.y).mul({ x: d.width, y: d.height }).rotateRadians(this.ogma.view.getAngle()).add(m);
2308
- wt(s, g, A.x, A.y);
2308
+ bt(s, g, A.x, A.y);
2309
2309
  }), t && this.arrows.refreshLayer();
2310
2310
  }
2311
2311
  /**
@@ -2350,23 +2350,27 @@ class Gn extends qe {
2350
2350
  */
2351
2351
  select(t) {
2352
2352
  const r = this.getAnnotations().features.find((a) => a.id === t);
2353
- return r ? (ht(r) ? this.arrows.select(r.id) : bt(r) && this.texts.select(r.id), this) : this;
2353
+ return r ? (ot(r) ? this.arrows.select(r.id) : mt(r) && this.texts.select(r.id), this) : this;
2354
2354
  }
2355
2355
  /**
2356
2356
  * Unselects the currently selected annotation
2357
2357
  */
2358
2358
  unselect() {
2359
- return this.selected ? (ht(this.selected) ? this.arrows.unselect() : bt(this.selected) && this.texts.unselect(), this) : this;
2359
+ return this.selected ? (ot(this.selected) ? this.arrows.unselect() : mt(this.selected) && this.texts.unselect(), this) : this;
2360
2360
  }
2361
2361
  /**
2362
2362
  * Add an annotation to the controller
2363
2363
  * @param annotation The annotation to add
2364
2364
  */
2365
2365
  add(t) {
2366
- if (ze(t))
2367
- return t.features.forEach(
2368
- (r) => this.add(r)
2366
+ if (ze(t)) {
2367
+ const [r, a] = t.features.reduce((c, f) => (ot(f) ? c[1].push(f) : mt(f) && c[0].push(f), c), [[], []]);
2368
+ return r.forEach(
2369
+ (c) => this.add(c)
2370
+ ), a.forEach(
2371
+ (c) => this.add(c)
2369
2372
  ), this.arrows.refreshLayer(), this;
2373
+ }
2370
2374
  switch (t.properties.type) {
2371
2375
  case "text":
2372
2376
  this.texts.add(t);
@@ -2384,7 +2388,7 @@ class Gn extends qe {
2384
2388
  remove(t) {
2385
2389
  return ze(t) ? (t.features.forEach(
2386
2390
  (r) => this.remove(r)
2387
- ), this) : (ht(t) ? (this.links.remove(t, "start"), this.links.remove(t, "end"), this.arrows.remove(t.id)) : this.texts.remove(t.id), this);
2391
+ ), this) : (ot(t) ? (this.links.remove(t, "start"), this.links.remove(t, "end"), this.arrows.remove(t.id)) : this.texts.remove(t.id), this);
2388
2392
  }
2389
2393
  loadLink(t) {
2390
2394
  if (t.properties.link)
@@ -2392,15 +2396,16 @@ class Gn extends qe {
2392
2396
  const a = t.properties.link[r];
2393
2397
  if (!a)
2394
2398
  continue;
2395
- if (this.getAnnotation(a.id))
2399
+ const c = this.getAnnotation(a.id);
2400
+ if (a.type === "text" && c)
2396
2401
  this.links.add(t, r, a.id, a.type, a.magnet);
2397
- else {
2402
+ else if (a.type === "node") {
2398
2403
  const f = this.ogma.getNode(a.id);
2399
2404
  if (!f)
2400
2405
  continue;
2401
2406
  this.links.add(t, r, a.id, a.type, a.magnet);
2402
2407
  const g = f.getPosition(), p = f.getAttribute("radius") || 0, s = Rt(t, r === "start" ? "end" : "start"), d = Ht(s, g, +p);
2403
- wt(t, r, d.x, d.y);
2408
+ bt(t, r, d.x, d.y);
2404
2409
  }
2405
2410
  }
2406
2411
  }
@@ -2435,7 +2440,7 @@ class Gn extends qe {
2435
2440
  */
2436
2441
  updateStyle(t, r) {
2437
2442
  const a = this.getAnnotations().features.find((c) => c.id === t);
2438
- return a ? (ht(a) ? this.arrows.updateStyle(a, r) : bt(a) && this.texts.updateStyle(a, r), this.onUpdate(a), this) : this;
2443
+ return a ? (ot(a) ? this.arrows.updateStyle(a, r) : mt(a) && this.texts.updateStyle(a, r), this.onUpdate(a), this) : this;
2439
2444
  }
2440
2445
  /**
2441
2446
  *
@@ -2488,10 +2493,10 @@ export {
2488
2493
  ft as getTextPosition,
2489
2494
  ct as getTextSize,
2490
2495
  ze as isAnnotationCollection,
2491
- ht as isArrow,
2492
- bt as isText,
2496
+ ot as isArrow,
2497
+ mt as isText,
2493
2498
  Re as setArrowEnd,
2494
- wt as setArrowEndPoint,
2499
+ bt as setArrowEndPoint,
2495
2500
  Ne as setArrowStart,
2496
2501
  zn as setTextBbox,
2497
2502
  Mn as updateTextBbox