@linkurious/ogma-annotations-react 1.1.27 → 2.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/index.mjs CHANGED
@@ -1,1961 +1,8 @@
1
- import Wr, { createContext as Ye, useContext as Ur, useReducer as Xr, useState as Et, useEffect as he } from "react";
2
- import { useOgma as Gr } from "@linkurious/ogma-react";
3
- var Vr = Object.defineProperty, Zr = (l, t, i) => t in l ? Vr(l, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : l[t] = i, m = (l, t, i) => Zr(l, typeof t != "symbol" ? t + "" : t, i);
4
- let Jt = (l = 21) => crypto.getRandomValues(new Uint8Array(l)).reduce((t, i) => (i &= 63, i < 36 ? t += i.toString(36) : i < 62 ? t += (i - 26).toString(36).toUpperCase() : i > 62 ? t += "-" : t += "_", t), "");
5
- const Pt = {
6
- strokeType: "plain",
7
- strokeColor: "#202020",
8
- strokeWidth: 1,
9
- head: "none",
10
- tail: "none"
11
- }, $e = {
12
- id: 0,
13
- type: "Feature",
14
- properties: {
15
- type: "arrow",
16
- style: {
17
- ...Pt
18
- }
19
- },
20
- geometry: {
21
- type: "LineString",
22
- coordinates: [
23
- [0, 0],
24
- [100, 100]
25
- ]
26
- }
27
- // type: 'arrow',
28
- // stroke: {
29
- // type: 'plain',
30
- // color: 'black',
31
- // width: 1
32
- // },
33
- // head: 'none',
34
- // tail: 'arrow-plain',
35
- // start: { x: 0, y: 0 },
36
- // end: { x: 100, y: 100 }
37
- }, Yr = (l = 0, t = 0, i = 0, r = 0, a = { ...Pt }) => ({
38
- id: Jt(),
39
- type: "Feature",
40
- properties: {
41
- type: "arrow",
42
- style: {
43
- ...Pt,
44
- ...a
45
- }
46
- },
47
- geometry: {
48
- type: "LineString",
49
- coordinates: [
50
- [l, t],
51
- [i, r]
52
- ]
53
- }
54
- }), Jr = "http://www.w3.org/2000/svg";
55
- function wt(l) {
56
- return document.createElementNS(Jr, l);
57
- }
58
- function Je(l) {
59
- return l.geometry.bbox || Kr(l), l.geometry.bbox;
60
- }
61
- function ft(l) {
62
- const t = Je(l);
63
- return {
64
- width: t[2] - t[0],
65
- height: t[3] - t[1]
66
- };
67
- }
68
- function dt(l) {
69
- const t = Je(l);
70
- return { x: t[0], y: t[1] };
71
- }
72
- function Kr(l) {
73
- const [t, i] = l.geometry.coordinates[0][0], [r, a] = l.geometry.coordinates[0][2];
74
- l.geometry.bbox = [t, i, r, a];
75
- }
76
- function Qr(l, t, i, r, a) {
77
- l.geometry.bbox = [t, i, t + r, i + a], l.geometry.coordinates = [
78
- [
79
- [t, i],
80
- [t + r, i],
81
- [t + r, i + a],
82
- [t, i + a],
83
- [t, i]
84
- ]
85
- ];
86
- }
87
- function zt(l) {
88
- const [t, i] = l.geometry.coordinates[0];
89
- return { x: t, y: i };
90
- }
91
- function Rt(l, t) {
92
- const [i, r] = l.geometry.coordinates[t === "start" ? 0 : 1];
93
- return { x: i, y: r };
94
- }
95
- function Xt(l) {
96
- const [t, i] = l.geometry.coordinates[1];
97
- return { x: t, y: i };
98
- }
99
- function Ke(l, t, i) {
100
- l.geometry.coordinates[0] = [t, i];
101
- }
102
- function Qe(l, t, i) {
103
- l.geometry.coordinates[1] = [t, i];
104
- }
105
- function Gt(l) {
106
- return { start: zt(l), end: Xt(l) };
107
- }
108
- function St(l, t, i, r) {
109
- t === "start" ? Ke(l, i, r) : Qe(l, i, r);
110
- }
111
- const tr = (l) => parseInt(l.getAttribute("data-handle-id") || "-1");
112
- function tn(l) {
113
- return Array.isArray(l) && l.length === 2 && l.every(isFinite);
114
- }
115
- function en(l, t, i, r) {
116
- for (let a = 0; a < l.coordinates.length; a++) {
117
- const h = l.coordinates[a];
118
- if (tn(h))
119
- h[0] = i + (h[0] - i) * t, h[1] = r + (h[1] - r) * t;
120
- else
121
- for (let c = 0; c < h.length; c++) {
122
- const d = h[c];
123
- d[0] = i + (d[0] - i) * t, d[1] = r + (d[1] - r) * t;
124
- }
125
- }
126
- return l;
127
- }
128
- function Wt(l, t, i) {
129
- const r = Math.atan2(l.y - t.y, l.x - t.x);
130
- return {
131
- x: t.x + i * Math.cos(r),
132
- y: t.y + i * Math.sin(r)
133
- };
134
- }
135
- function Vt(l, t) {
136
- if (!t) return { x: l.clientX, y: l.clientY };
137
- const i = t.getBoundingClientRect();
138
- return {
139
- x: l.clientX - i.left - t.clientLeft,
140
- y: l.clientY - i.top - t.clientTop
141
- };
142
- }
143
- const xt = (l, t) => ({
144
- x: l.x - t.x,
145
- y: l.y - t.y
146
- }), _t = (l) => Math.sqrt(l.x * l.x + l.y * l.y), er = (l) => ({
147
- x: -l.x,
148
- y: -l.y
149
- }), rr = (l) => {
150
- const t = _t(l);
151
- return t === 0 ? { x: 0, y: 0 } : {
152
- x: l.x / t,
153
- y: l.y / t
154
- };
155
- }, Ct = (l, t) => ({
156
- x: l.x + t.x,
157
- y: l.y + t.y
158
- }), nr = (l, t) => ({
159
- x: l.x * t,
160
- y: l.y * t
161
- }), Ut = (l, t) => ({
162
- x: l.x * t.x,
163
- y: l.y * t.y
164
- }), nt = (l, t) => {
165
- const i = Math.sin(t), r = Math.cos(t);
166
- return {
167
- x: l.x * r - l.y * i,
168
- y: l.x * i + l.y * r
169
- };
170
- }, rn = (l, t) => ({
171
- x: l.x / t,
172
- y: l.y / t
173
- }), Ie = (l, t) => l.x * t.x + l.y * t.y, nn = 0.5;
174
- function ir(l, t = 5, i = 30) {
175
- var r;
176
- const { start: a, end: h } = Gt(l), c = xt(h, a), d = l.properties.style && l.properties.style.strokeWidth ? (r = l.properties.style) == null ? void 0 : r.strokeWidth : 0;
177
- return Math.min(i, Math.max(3 * d, _t(c) * 0.01, t));
178
- }
179
- function Me(l, t, i, r) {
180
- const a = nr(er(rr(t)), r);
181
- if (!i || i !== "arrow" && i !== "arrow-plain") return "";
182
- const h = Ct(l, nt(a, Math.PI / 10)), c = Ct(l, nt(a, -Math.PI / 10)), d = `${l.x} ${l.y}`;
183
- return `M ${h.x} ${h.y} L ${d} ${c.x} ${c.y} ${i === "arrow" ? "" : `${h.x} ${h.y}`}`;
184
- }
185
- function sn(l, t, i, r, a) {
186
- const { start: h, end: c } = Gt(l), {
187
- tail: d,
188
- head: f,
189
- strokeColor: g,
190
- strokeWidth: p = 0
191
- } = l.properties.style || i, w = xt(c, h), b = ir(l, r, a), A = wt("g"), E = wt("path");
192
- A.setAttribute("data-annotation", `${l.id}`), A.setAttribute("data-annotation-type", "arrow");
193
- const k = f === "arrow-plain" || d === "arrow", L = g || "none";
194
- E.setAttribute("stroke", L), E.setAttribute("stroke-width", `${p}`), E.setAttribute("fill", k ? g || "" : "none"), E.setAttribute("stroke-linecap", "round"), E.setAttribute("stroke-linejoin", "round");
195
- const M = Me(h, er(w), d, b), C = Me(c, w, f, b), N = M + `M ${h.x} ${h.y} ${c.x} ${c.y}` + C;
196
- E.setAttribute("d", N), A.appendChild(E), Oe(A, h, L, d, p), Oe(A, c, L, f, p), t.appendChild(A);
197
- }
198
- function Oe(l, t, i, r, a) {
199
- r === "halo-dot" && ze(
200
- l,
201
- t,
202
- on(i),
203
- nn,
204
- a * 4
205
- ), (r === "dot" || r === "halo-dot") && ze(l, t, i, 1, a * 2);
206
- }
207
- function on(l) {
208
- return l === "none" ? "none" : l;
209
- }
210
- function ze(l, t, i, r, a) {
211
- const h = wt("circle");
212
- h.setAttribute("cx", `${t.x}`), h.setAttribute("cy", `${t.y}`), h.setAttribute("r", `${a}`), h.setAttribute("fill-opacity", `${r}`), h.setAttribute("fill", i), l.appendChild(h);
213
- }
214
- const U = -1, Zt = "dragging", Yt = "dragstart", Lt = "dragend", fe = "select", ge = "unselect", an = "hover", ln = "unhover", pe = "remove", ye = "add", hn = "cancelDrawing", me = "update", un = "link";
215
- function sr(l) {
216
- return l && l.__esModule && Object.prototype.hasOwnProperty.call(l, "default") ? l.default : l;
217
- }
218
- var Pe = { exports: {} }, Fe;
219
- function cn() {
220
- return Fe || (Fe = 1, function(l) {
221
- var t = Object.prototype.hasOwnProperty, i = "~";
222
- function r() {
223
- }
224
- Object.create && (r.prototype = /* @__PURE__ */ Object.create(null), new r().__proto__ || (i = !1));
225
- function a(f, g, p) {
226
- this.fn = f, this.context = g, this.once = p || !1;
227
- }
228
- function h(f, g, p, w, b) {
229
- if (typeof p != "function")
230
- throw new TypeError("The listener must be a function");
231
- var A = new a(p, w || f, b), E = i ? i + g : g;
232
- return f._events[E] ? f._events[E].fn ? f._events[E] = [f._events[E], A] : f._events[E].push(A) : (f._events[E] = A, f._eventsCount++), f;
233
- }
234
- function c(f, g) {
235
- --f._eventsCount === 0 ? f._events = new r() : delete f._events[g];
236
- }
237
- function d() {
238
- this._events = new r(), this._eventsCount = 0;
239
- }
240
- d.prototype.eventNames = function() {
241
- var f = [], g, p;
242
- if (this._eventsCount === 0) return f;
243
- for (p in g = this._events)
244
- t.call(g, p) && f.push(i ? p.slice(1) : p);
245
- return Object.getOwnPropertySymbols ? f.concat(Object.getOwnPropertySymbols(g)) : f;
246
- }, d.prototype.listeners = function(f) {
247
- var g = i ? i + f : f, p = this._events[g];
248
- if (!p) return [];
249
- if (p.fn) return [p.fn];
250
- for (var w = 0, b = p.length, A = new Array(b); w < b; w++)
251
- A[w] = p[w].fn;
252
- return A;
253
- }, d.prototype.listenerCount = function(f) {
254
- var g = i ? i + f : f, p = this._events[g];
255
- return p ? p.fn ? 1 : p.length : 0;
256
- }, d.prototype.emit = function(f, g, p, w, b, A) {
257
- var E = i ? i + f : f;
258
- if (!this._events[E]) return !1;
259
- var k = this._events[E], L = arguments.length, M, C;
260
- if (k.fn) {
261
- switch (k.once && this.removeListener(f, k.fn, void 0, !0), L) {
262
- case 1:
263
- return k.fn.call(k.context), !0;
264
- case 2:
265
- return k.fn.call(k.context, g), !0;
266
- case 3:
267
- return k.fn.call(k.context, g, p), !0;
268
- case 4:
269
- return k.fn.call(k.context, g, p, w), !0;
270
- case 5:
271
- return k.fn.call(k.context, g, p, w, b), !0;
272
- case 6:
273
- return k.fn.call(k.context, g, p, w, b, A), !0;
274
- }
275
- for (C = 1, M = new Array(L - 1); C < L; C++)
276
- M[C - 1] = arguments[C];
277
- k.fn.apply(k.context, M);
278
- } else {
279
- var N = k.length, P;
280
- for (C = 0; C < N; C++)
281
- switch (k[C].once && this.removeListener(f, k[C].fn, void 0, !0), L) {
282
- case 1:
283
- k[C].fn.call(k[C].context);
284
- break;
285
- case 2:
286
- k[C].fn.call(k[C].context, g);
287
- break;
288
- case 3:
289
- k[C].fn.call(k[C].context, g, p);
290
- break;
291
- case 4:
292
- k[C].fn.call(k[C].context, g, p, w);
293
- break;
294
- default:
295
- if (!M) for (P = 1, M = new Array(L - 1); P < L; P++)
296
- M[P - 1] = arguments[P];
297
- k[C].fn.apply(k[C].context, M);
298
- }
299
- }
300
- return !0;
301
- }, d.prototype.on = function(f, g, p) {
302
- return h(this, f, g, p, !1);
303
- }, d.prototype.once = function(f, g, p) {
304
- return h(this, f, g, p, !0);
305
- }, d.prototype.removeListener = function(f, g, p, w) {
306
- var b = i ? i + f : f;
307
- if (!this._events[b]) return this;
308
- if (!g)
309
- return c(this, b), this;
310
- var A = this._events[b];
311
- if (A.fn)
312
- A.fn === g && (!w || A.once) && (!p || A.context === p) && c(this, b);
313
- else {
314
- for (var E = 0, k = [], L = A.length; E < L; E++)
315
- (A[E].fn !== g || w && !A[E].once || p && A[E].context !== p) && k.push(A[E]);
316
- k.length ? this._events[b] = k.length === 1 ? k[0] : k : c(this, b);
317
- }
318
- return this;
319
- }, d.prototype.removeAllListeners = function(f) {
320
- var g;
321
- return f ? (g = i ? i + f : f, this._events[g] && c(this, g)) : (this._events = new r(), this._eventsCount = 0), this;
322
- }, d.prototype.off = d.prototype.removeListener, d.prototype.addListener = d.prototype.on, d.prefixed = i, d.EventEmitter = d, l.exports = d;
323
- }(Pe)), Pe.exports;
324
- }
325
- var dn = cn();
326
- const or = /* @__PURE__ */ sr(dn);
327
- class ar extends or {
328
- constructor(t, i) {
329
- super(), m(this, "ogma"), m(this, "elements"), m(this, "layer"), m(this, "editor"), m(this, "selectedId", U), m(this, "hoveredId", U), m(this, "ogmaOptions"), m(this, "shouldDetect"), m(this, "isDragging"), m(this, "showeditorOnHover"), m(this, "_onKeyUp", (r) => {
330
- r.code === 27 && this.selectedId !== U ? this.unselect() : (r.code === 46 || r.code === 8) && this.selectedId !== U && this._canRemove() && this.remove(this.selectedId);
331
- }), m(this, "_onClickMouseMove", (r) => {
332
- if (!r.domEvent || this.isDragging || !this.shouldDetect || r.domEvent.type !== "mousemove" && r.domEvent.target && r.domEvent.target.tagName === "a")
333
- return;
334
- const a = this.ogma.view.screenToGraphCoordinates(r), h = this.shouldDetect || !this.shouldDetect && +this.selectedId > -1 ? this.detect(a, 0) : void 0;
335
- r.domEvent.type === "mousemove" ? h ? this.hover(h.id) : this.hoveredId !== U && this.unhover() : h ? this.select(h.id) : this.selectedId !== U && this.unselect();
336
- }), this.ogma = t, this.elements = [], this.shouldDetect = !0, this.isDragging = !1, this.showeditorOnHover = !0, this.ogmaOptions = t.getOptions(), t.events.on(["click", "mousemove"], this._onClickMouseMove).on("keyup", this._onKeyUp).on("frame", () => {
337
- this.refreshEditor(), this.refreshDrawing();
338
- }), this.layer = t.layers.addSVGLayer({
339
- draw: (r) => this.draw(r)
340
- }), this.layer.moveToTop(), this.editor = t.layers.addLayer(i), this.editor.hide();
341
- }
342
- _canRemove() {
343
- return !0;
344
- }
345
- /**
346
- * @method add
347
- * @param options Params for the annotation (merged with default)
348
- * @returns the added annotation
349
- */
350
- add(t) {
351
- const i = this.getDefaultOptions(), r = Object.assign(t, {
352
- id: t.id === void 0 ? Jt() : t.id,
353
- type: t.type,
354
- properties: {
355
- ...i.properties,
356
- ...t.properties || {},
357
- // styles need to be merged
358
- style: { ...i.properties.style, ...t.properties.style || {} }
359
- },
360
- geometry: {
361
- ...i.geometry,
362
- ...t.geometry
363
- }
364
- });
365
- return this.elements.push(r), this.layer.refresh(), this.emit(ye, r), r;
366
- }
367
- updateStyle(t, i) {
368
- this.updateAnnotation(t, {
369
- properties: {
370
- style: i
371
- }
372
- });
373
- }
374
- updateGeometry(t, i) {
375
- this.updateAnnotation(t, {
376
- geometry: i
377
- });
378
- }
379
- scale(t, i, r, a) {
380
- this.updateGeometry(
381
- t,
382
- en(t.geometry, i, r, a)
383
- );
384
- }
385
- /**
386
- * @method update
387
- * Updates an annotation (position, color etc)
388
- * @param id Id of the annotation to update
389
- * @param element params of the annotation
390
- */
391
- update(t, i) {
392
- const r = this.getById(t);
393
- this.updateAnnotation(r, i);
394
- }
395
- updateAnnotation(t, i) {
396
- if (!t) return;
397
- const r = t.id;
398
- Object.keys(i).forEach((a) => {
399
- if (a !== "id")
400
- if (a === "properties") {
401
- const h = i.properties || { style: {} };
402
- t.properties = {
403
- ...t.properties || {},
404
- ...h || {},
405
- style: {
406
- ...t.properties.style || {},
407
- ...h.style || {}
408
- }
409
- };
410
- } else a === "geometry" ? t.geometry = {
411
- ...t.geometry,
412
- ...i.geometry
413
- } : t[a] = i[a];
414
- }), r === this.selectedId && this.refreshEditor(), this.layer.refresh();
415
- }
416
- getById(t) {
417
- const i = Number(t);
418
- for (let r = 0; r < this.elements.length; r++) {
419
- const a = this.elements[r];
420
- if (!(a.id !== t && a.id !== i))
421
- return a;
422
- }
423
- }
424
- /**
425
- * @method select
426
- * @param id id of the element to select
427
- * Select element, show editor, disable Ogma dragging and fire event
428
- */
429
- select(t) {
430
- const i = this.getById(t);
431
- i && (this.editor.show(), this.selectedId = t, this.refreshEditor(), this.layer.refresh(), this.emit(fe, i));
432
- }
433
- hover(t) {
434
- const i = this.getById(t);
435
- i && (this.showeditorOnHover && this.editor.show(), this.hoveredId = t, this.refreshEditor(), this.layer.refresh(), this.emit(an, i));
436
- }
437
- getSelectedFeature() {
438
- return this.selectedId === U ? null : this.getById(this.selectedId);
439
- }
440
- unselect() {
441
- const t = this.getById(this.selectedId);
442
- return t && this.emit(ge, t), this.selectedId = U, this.hoveredId === U && this.editor.hide(), this.layer.refresh(), this;
443
- }
444
- unhover() {
445
- const t = this.getById(this.hoveredId);
446
- return this.emit(ln, t), this.hoveredId = U, this.selectedId === U && this.editor.hide(), this.layer.refresh(), this;
447
- }
448
- /**
449
- * @method remove
450
- * @param id Id of the annotation to remove
451
- * Removes annotation with the given id
452
- */
453
- remove(t) {
454
- const i = this.getById(t);
455
- t === this.hoveredId && this.unhover(), t === this.selectedId && this.unselect(), this.elements = this.elements.filter((r) => r.id !== t), i && this.emit(pe, i), this.layer.refresh();
456
- }
457
- /**
458
- * @method disableDragging
459
- * Prevents Ogma from dragging elements or moving the view while dragging an annotation
460
- */
461
- disableDragging() {
462
- this.ogma.setOptions({
463
- interactions: {
464
- drag: { enabled: !1 },
465
- pan: { enabled: !1 }
466
- },
467
- detect: {
468
- nodes: !1,
469
- edges: !1,
470
- nodeTexts: !1,
471
- edgeTexts: !1
472
- }
473
- });
474
- }
475
- /**
476
- * @method restoreDragging
477
- * restore ogma options as they were before we start dragging an annotation
478
- */
479
- restoreDragging() {
480
- this.ogma.setOptions(this.ogmaOptions);
481
- }
482
- enableDetection() {
483
- this.shouldDetect = !0;
484
- }
485
- /**
486
- * @method disableDetection
487
- * Disables the hover behaviour, used by controller to avoid hovering
488
- * arrows while dragging texts and vice versa
489
- */
490
- disableDetection() {
491
- this.shouldDetect = !1;
492
- }
493
- refreshLayer() {
494
- this.layer.refresh();
495
- }
496
- refreshDrawing() {
497
- }
498
- getElements() {
499
- return [...this.elements];
500
- }
501
- destroy() {
502
- this.ogma.events.off(this._onClickMouseMove).off(this._onKeyUp), this.layer.destroy();
503
- }
504
- }
505
- const He = "handle-line", Ne = "handle-start", je = "handle-end";
506
- class fn extends ar {
507
- constructor(t, i = {}) {
508
- super(
509
- t,
510
- `
511
- <div class="arrow-handle">
512
- <div id="${He}" data-handle-id="0" class="handle line"></div>
513
- <div id="${Ne}" data-handle-id="1" class="handle point"></div>
514
- <div id="${je}" data-handle-id="2" class="handle point"></div>
515
- </div>
516
- `
517
- ), m(this, "draggedHandle", U), m(this, "start", { x: 0, y: 0 }), m(this, "end", { x: 0, y: 0 }), m(this, "arrow", { ...$e }), m(this, "startX", 0), m(this, "startY", 0), m(this, "minArrowHeight", 0), m(this, "maxArrowHeight", 0), m(this, "handles", []), m(this, "onHandleMouseDown", (r) => {
518
- const a = this.getById(this.selectedId) || this.getById(this.hoveredId);
519
- if (!a) return;
520
- const { x: h, y: c } = Vt(r, this.ogma.getContainer());
521
- this.startDragging(a, h, c), this.draggedHandle = tr(r.target);
522
- }), m(this, "onMouseUp", () => {
523
- this.draggedHandle !== -1 && (this.restoreDragging(), this.isDragging = !1, this.draggedHandle = U, this.emit(Lt, this.arrow));
524
- }), m(this, "onMouseMove", (r) => {
525
- if (!this.isDragging || this.draggedHandle === U) return;
526
- const { x: a, y: h } = Vt(r, this.ogma.getContainer()), c = this.handles[this.draggedHandle], d = this.ogma.view.getAngle(), { x: f, y: g } = nt(
527
- rn(
528
- { x: a - this.startX, y: h - this.startY },
529
- this.ogma.view.getZoom()
530
- ),
531
- d
532
- ), p = c.id === He, w = c.id === Ne, b = c.id === je;
533
- (p || w) && Ke(this.arrow, this.start.x + f, this.start.y + g), (p || b) && Qe(this.arrow, this.end.x + f, this.end.y + g), this.emit(
534
- Zt,
535
- this.arrow,
536
- p ? "line" : w ? "start" : "end"
537
- ), this.refreshEditor(), this.layer.refresh();
538
- }), this.minArrowHeight = i.minArrowHeight || 0, this.maxArrowHeight = i.maxArrowHeight || 1e6, this.handles = Array.prototype.slice.call(
539
- this.editor.element.querySelectorAll(".arrow-handle>.handle")
540
- ), this.handles.forEach(
541
- (r) => r.addEventListener("mousedown", this.onHandleMouseDown)
542
- ), document.addEventListener("mousemove", this.onMouseMove, !0), document.addEventListener("mouseup", this.onMouseUp);
543
- }
544
- /**
545
- * Start drawing a new arrow, it will also be added as a new annotation
546
- * @param x
547
- * @param y
548
- * @param arrow
549
- */
550
- startDrawing(t, i, r = Yr(t, i, t, i, Pt)) {
551
- var a;
552
- this.disableDragging(), this.add(r), this.hoveredId = r.id;
553
- const h = this.ogma.view.graphToScreenCoordinates({ x: t, y: i }), c = ((a = this.ogma.getContainer()) == null ? void 0 : a.getBoundingClientRect()) || {
554
- left: 0,
555
- top: 0
556
- };
557
- this.startDragging(
558
- this.getById(r.id),
559
- h.x + (c == null ? void 0 : c.left),
560
- h.y + c.top
561
- ), this.draggedHandle = 2;
562
- }
563
- cancelDrawing() {
564
- this.isDragging && (this.remove(this.arrow.id), this.emit(Lt, this.arrow), this.restoreDragging(), this.isDragging = !1, this.draggedHandle = U);
565
- }
566
- startDragging(t, i, r) {
567
- this.selectedId !== t.id && this.select(this.hoveredId), this.arrow = t, this.startX = i, this.startY = r, this.start = zt(this.arrow), this.end = Xt(this.arrow), this.disableDragging(), this.emit(Yt, this.arrow), this.isDragging = !0;
568
- }
569
- detect(t, i = 0) {
570
- return this.elements.find((r) => {
571
- const { start: a, end: h } = Gt(r), c = xt(t, {
572
- x: (a.x + h.x) / 2,
573
- y: (a.y + h.y) / 2
574
- }), d = xt(h, a), f = _t(d), g = rr(d), p = ir(r);
575
- return Math.abs(Ie(g, c)) < f / 2 + i && Math.abs(Ie(nt(g, Math.PI / 2), c)) < p / 2 + i;
576
- });
577
- }
578
- refreshEditor() {
579
- if (+this.selectedId < 0 && +this.hoveredId < 0) return;
580
- const t = this.selectedId !== U ? this.getById(this.selectedId) : this.getById(this.hoveredId), i = Gt(t), r = this.ogma.view.graphToScreenCoordinates(i.start), a = this.ogma.view.graphToScreenCoordinates(i.end), [h, c, d] = Array.prototype.slice.call(
581
- this.editor.element.querySelectorAll(".handle")
582
- );
583
- c.style.transform = `translate(${r.x}px, ${r.y}px) translate(-50%, -50%)`, d.style.transform = `translate(${a.x}px, ${a.y}px) translate(-50%, -50%)`;
584
- const f = {
585
- x: (a.x + r.x) / 2,
586
- y: (a.y + r.y) / 2
587
- }, g = xt(a, r), p = nr(g, 1 / _t(g)), w = Math.atan2(p.y, p.x);
588
- h.style.width = `${_t(g)}px`, h.style.left = `${f.x}px`, h.style.top = `${f.y}px`, h.style.transform = `translate(-50%, -50%) rotate(${w}rad)`;
589
- }
590
- getDefaultOptions() {
591
- return $e;
592
- }
593
- draw(t) {
594
- t.innerHTML = "";
595
- const i = wt("g"), r = this.ogma.view.getAngle();
596
- r !== 0 && i.setAttribute("transform", `rotate(${-r * (180 / Math.PI)})`), this.elements.forEach(
597
- (a) => sn(a, i, Pt, this.minArrowHeight, this.maxArrowHeight)
598
- ), t.appendChild(i);
599
- }
600
- refreshDrawing() {
601
- const t = this.ogma.view.getAngle();
602
- this.layer.element !== null && t !== 0 && this.layer.element.children[0].setAttribute(
603
- "transform",
604
- `rotate(${-t * (180 / Math.PI)})`
605
- );
606
- }
607
- destroy() {
608
- super.destroy(), document.removeEventListener("mousemove", this.onMouseMove, !0), document.removeEventListener("mouseup", this.onMouseUp);
609
- }
610
- }
611
- const Dt = {
612
- font: "sans-serif",
613
- fontSize: 18,
614
- color: "#505050",
615
- background: "#f5f5f5",
616
- strokeWidth: 0,
617
- borderRadius: 8,
618
- padding: 16,
619
- strokeType: "plain"
620
- }, ue = {
621
- id: 0,
622
- type: "Feature",
623
- properties: {
624
- type: "text",
625
- content: "",
626
- style: { ...Dt }
627
- },
628
- geometry: {
629
- type: "Polygon",
630
- coordinates: [
631
- [
632
- [0, 0],
633
- [100, 0],
634
- [100, 50],
635
- [0, 50],
636
- [0, 0]
637
- ]
638
- ]
639
- }
640
- // position: { x: 0, y: 0 },
641
- // size: { width: 100, height: 50 }
642
- }, Be = {
643
- handleSize: 3.5,
644
- placeholder: "Your text..."
645
- }, gn = (l = 0, t = 0, i = 100, r = 50, a = "", h = { ...Dt }) => ({
646
- id: Jt(),
647
- type: "Feature",
648
- properties: {
649
- type: "text",
650
- content: a,
651
- style: { ...Dt, ...h }
652
- },
653
- geometry: {
654
- type: "Polygon",
655
- coordinates: [
656
- [
657
- [l, t],
658
- [l + i, t],
659
- [l + i, t + r],
660
- [l, t + r],
661
- [l, t]
662
- ]
663
- ]
664
- }
665
- });
666
- var ve = { exports: {} }, pn = ve.exports, qe;
667
- function yn() {
668
- return qe || (qe = 1, function(l, t) {
669
- (function(i, r) {
670
- l.exports = r();
671
- })(pn, () => (() => {
672
- var i = { d: (e, n) => {
673
- for (var o in n) i.o(n, o) && !i.o(e, o) && Object.defineProperty(e, o, { enumerable: !0, get: n[o] });
674
- }, o: (e, n) => Object.prototype.hasOwnProperty.call(e, n) }, r = {};
675
- function a(e) {
676
- return a = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(n) {
677
- return typeof n;
678
- } : function(n) {
679
- return n && typeof Symbol == "function" && n.constructor === Symbol && n !== Symbol.prototype ? "symbol" : typeof n;
680
- }, a(e);
681
- }
682
- i.d(r, { default: () => qr });
683
- var h = /^((?:[a-z\d-]+\s+)*)([\d.]+(%|em|px)|(?:x+-)?large|(?:x+-)?small|medium)(?:\s*\/\s*(normal|[\d.]+(%|px|em)?))?(\s.+)?$/, c = /\bsmall-caps\b/, d = /\b(?:italic|oblique)\b/, f = /\bbold(?:er)?\b/, g = 13.3333333, p = { "xx-small": 9, "x-small": 10, smaller: 13.3333, small: 13, medium: 16, large: 18, larger: 19.2, "x-large": 24, "xx-large": 32 };
684
- function w(e) {
685
- var n = "", o = this;
686
- return o.style && o.style !== "normal" && (n += o.style), o.variant && o.variant !== "normal" && (n += (n ? " " : "") + o.variant), o.weight && o.weight !== "normal" && (n += (n ? " " : "") + o.weight), o.size && (n += (n ? " " : "") + o.size + "px", o.height !== o.size && (n += "/" + o.height + "px")), o.family && (n += (n ? " " : "") + o.family), e && (n += "::" + o.baseline), e && (n += "::" + o.color), n;
687
- }
688
- var b = { id: "", family: "sans-serif", height: 14, size: 12, variant: "", style: "", weight: "", baseline: "", color: null, toString: w, valueOf: w };
689
- function A(e) {
690
- var n = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, o = h.exec(e);
691
- n.family = (o[6] || "").trim();
692
- var s = p[o[2]] || parseFloat(o[2]);
693
- o[3] === "%" ? s *= 0.16 : o[3] === "em" ? s *= 16 : o[3] === "pt" && (s *= g), n.size = s;
694
- var u = parseFloat(o[4]);
695
- if (u !== "normal" && u !== "inherit" && u ? o[5] && o[5] !== "em" ? o[5] === "pt" ? n.height = u * g : o[5] === "%" ? n.height = 0.01 * s : n.height = u : n.height = u * s : n.height = Math.round(s * (7 / 6)), c.test(o[1]) && (n.variant = "small-caps"), d.test(o[1]) && (n.style = "italic"), f.test(o[1])) n.weight = "bold";
696
- else {
697
- var y = parseInt(/\b(\d+)\b/.exec(o[1]), 10);
698
- y >= 100 && y !== 400 && (n.weight = y);
699
- }
700
- return n;
701
- }
702
- function E() {
703
- var e, n, o, s = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "12px/14px sans-serif", u = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, y = 14, x = 12, v = null, S = null, _ = "";
704
- if (s && s.nodeType) {
705
- var $ = s && (s.ownerDocument && s.ownerDocument.defaultView || s.document && s || s.defaultView), I = $.getComputedStyle(s, null);
706
- e = I.getPropertyValue("font-family") || "", x = parseFloat(I.getPropertyValue("font-size")), y = I.getPropertyValue("line-height"), v = I.getPropertyValue("font-weight"), S = I.getPropertyValue("font-style"), _ = I.getPropertyValue("font-variant") || "";
707
- } else if (typeof s == "string") {
708
- var D = A(s);
709
- e = D.family, x = D.size, y = D.height, _ = D.variant, S = D.style, v = D.weight;
710
- } else a(s) === "object" && (e = s.family, x = s.size, y = s.height, _ = s.variant, v = s.weight, S = s.style, n = s.baseline, o = s.color);
711
- u.size && u.size < 3 && (x *= u.size), y = y !== "normal" && y ? parseFloat(y) : x * (7 / 6), u.height && u.height < 3 && (y *= u.height);
712
- var O = Object.create(b);
713
- return O.family = u.family || e || "sans-serif", O.height = y ?? 14, O.size = x ?? 12, O.variant = u.variant || _ || "", O.style = u.style || S || "", O.weight = u.weight || v || "", O.baseline = n || 0, u.baseline != null && (O.baseline = u.baseline), O.color = u.color || o || "", O.id = w.call(O, !0), O;
714
- }
715
- const k = { "\n": 0.28, "\r": 0.28, " ": 0.28, " ": 0.28, " ": 0.28, "᠎": 0, " ": 0.5, " ": 1, " ": 0.5, " ": 1, " ": 0.33, " ": 0.25, " ": 0.16, " ": 0.56, " ": 0.28, " ": 0.2, " ": 0.15, "​": 0, " ": 0.16, " ": 0.22, " ": 1, "\uFEFF": 0 };
716
- var L, M = function(e) {
717
- var n = typeof OffscreenCanvas < "u" && new OffscreenCanvas(100, 100) || e && e.createElement("canvas");
718
- if (n && n.getContext) {
719
- var o = n.getContext("2d");
720
- if (o && typeof o.measureText == "function") return function(s, u) {
721
- return o.font = String(u), o.measureText(s).width;
722
- };
723
- }
724
- }(typeof document < "u" ? document : null) || (L = {}, function(e, n) {
725
- if (!L[n]) {
726
- var o = E(n);
727
- L[n] = o, /\bmonospace\b/.test(o.family) ? o.size *= 0.6 : (o.size *= 0.45, o.weight && (o.size *= 1.18));
728
- }
729
- return e.length * L[n].size;
730
- }), C = {}, N = { trim: !0, collapse: !0 };
731
- function P(e, n, o) {
732
- var s = Object.assign({}, N, o), u = String(e);
733
- if (!u) return 0;
734
- if (u in k) {
735
- var y = n.id + "/" + u;
736
- return y in C || (C[y] = M("_".concat(u, "_"), n) - M("__", n)), C[y];
737
- }
738
- return s.trim && s.collapse ? s.trim ? u = u.trim() : s.collapse && (u = u.replace(/\s+/g, " ")) : u = u.replace(/\n/g, " "), M(u, n) + n.size * (e.tracking || 0);
739
- }
740
- function tt(e) {
741
- return tt = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(n) {
742
- return typeof n;
743
- } : function(n) {
744
- return n && typeof Symbol == "function" && n.constructor === Symbol && n !== Symbol.prototype ? "symbol" : typeof n;
745
- }, tt(e);
746
- }
747
- function it(e, n) {
748
- if (typeof n != "function" && n !== null) throw new TypeError("Super expression must either be null or a function");
749
- e.prototype = Object.create(n && n.prototype, { constructor: { value: e, writable: !0, configurable: !0 } }), Object.defineProperty(e, "prototype", { writable: !1 }), n && Kt(e, n);
750
- }
751
- function Kt(e, n) {
752
- return Kt = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(o, s) {
753
- return o.__proto__ = s, o;
754
- }, Kt(e, n);
755
- }
756
- function Qt(e) {
757
- var n = function() {
758
- if (typeof Reflect > "u" || !Reflect.construct || Reflect.construct.sham) return !1;
759
- if (typeof Proxy == "function") return !0;
760
- try {
761
- return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {
762
- })), !0;
763
- } catch {
764
- return !1;
765
- }
766
- }();
767
- return function() {
768
- var o, s = Ft(e);
769
- if (n) {
770
- var u = Ft(this).constructor;
771
- o = Reflect.construct(s, arguments, u);
772
- } else o = s.apply(this, arguments);
773
- return ur(this, o);
774
- };
775
- }
776
- function ur(e, n) {
777
- if (n && (tt(n) === "object" || typeof n == "function")) return n;
778
- if (n !== void 0) throw new TypeError("Derived constructors may only return object or undefined");
779
- return function(o) {
780
- if (o === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
781
- return o;
782
- }(e);
783
- }
784
- function Ft(e) {
785
- return Ft = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function(n) {
786
- return n.__proto__ || Object.getPrototypeOf(n);
787
- }, Ft(e);
788
- }
789
- function Ht(e, n) {
790
- if (!(e instanceof n)) throw new TypeError("Cannot call a class as a function");
791
- }
792
- function cr(e, n) {
793
- for (var o = 0; o < n.length; o++) {
794
- var s = n[o];
795
- s.enumerable = s.enumerable || !1, s.configurable = !0, "value" in s && (s.writable = !0), Object.defineProperty(e, (u = function(y, x) {
796
- if (tt(y) !== "object" || y === null) return y;
797
- var v = y[Symbol.toPrimitive];
798
- if (v !== void 0) {
799
- var S = v.call(y, x);
800
- if (tt(S) !== "object") return S;
801
- throw new TypeError("@@toPrimitive must return a primitive value.");
802
- }
803
- return String(y);
804
- }(s.key, "string"), tt(u) === "symbol" ? u : String(u)), s);
805
- }
806
- var u;
807
- }
808
- function Nt(e, n, o) {
809
- return n && cr(e.prototype, n), Object.defineProperty(e, "prototype", { writable: !1 }), e;
810
- }
811
- var j = function() {
812
- function e() {
813
- var n = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "";
814
- Ht(this, e), this.value = n, this.weight = null, this.style = null, this.font = null, this.href = null, this.sub = !1, this.sup = !1;
815
- }
816
- return Nt(e, [{ key: "clone", value: function() {
817
- var n = new e(this.value);
818
- return n.value = this.value, n.weight = this.weight, n.style = this.style, n.font = this.font, n.href = this.href, n.sub = this.sub, n.sup = this.sup, n;
819
- } }, { key: "valueOf", value: function() {
820
- return this.value;
821
- } }, { key: "toString", value: function() {
822
- return this.value;
823
- } }]), e;
824
- }(), Tt = function(e) {
825
- it(o, e);
826
- var n = Qt(o);
827
- function o() {
828
- return Ht(this, o), n.apply(this, arguments);
829
- }
830
- return Nt(o);
831
- }(j), et = function(e) {
832
- it(o, e);
833
- var n = Qt(o);
834
- function o() {
835
- return Ht(this, o), n.apply(this, arguments);
836
- }
837
- return Nt(o);
838
- }(j), yt = function(e) {
839
- it(o, e);
840
- var n = Qt(o);
841
- function o() {
842
- return Ht(this, o), n.apply(this, arguments);
843
- }
844
- return Nt(o);
845
- }(j), te = /^[\n\r\t\x20\xA0\u2000-\u200B\u205F\u3000]/, dr = /^[^\n\r\t\u0020\u2000-\u200B\u205F\u3000]{2,}/, we = /^[\xA0\u2011\u202F\u2060\uFEFF]/, fr = /^(?:[;\xAD%?…]|,(?!\d))/, gr = /^[´±°¢£¤$¥\u2212]/;
846
- function jt(e, n) {
847
- n !== !1 && (e = e.trim());
848
- for (var o, s, u = [], y = e.charAt(0), x = 0, v = 1, S = e.length; v < S; v++) {
849
- o = e.charAt(v), s = e.charAt(v + 1);
850
- var _ = te.test(y), $ = te.test(o), I = $ || _, D = void 0;
851
- if ((gr.test(o) && !we.test(y) || fr.test(y + s) && !we.test(o)) && (I = !0), y !== "-" && y !== "‐" && y !== "–" && y !== "—" || ((D = te.test(e.charAt(v - 2))) && !$ && (I = !1), !D && dr.test(o + s) && (I = !0)), I) {
852
- var O = e.slice(x, v);
853
- /\u00AD$/.test(O) ? (u.push(new j(O.slice(0, -1))), u.push(new yt())) : (u.push(new j(O)), u.push(new Tt())), x = v;
854
- }
855
- y = o;
856
- }
857
- return u.push(new j(e.slice(x))), u;
858
- }
859
- const xe = { nbsp: " ", iexcl: "¡", cent: "¢", pound: "£", curren: "¤", yen: "¥", brvbar: "¦", sect: "§", uml: "¨", copy: "©", ordf: "ª", laquo: "«", not: "¬", shy: "­", reg: "®", macr: "¯", deg: "°", plusmn: "±", sup2: "²", sup3: "³", acute: "´", micro: "µ", para: "¶", middot: "·", cedil: "¸", sup1: "¹", ordm: "º", raquo: "»", frac14: "¼", frac12: "½", frac34: "¾", iquest: "¿", Agrave: "À", Aacute: "Á", Acirc: "Â", Atilde: "Ã", Auml: "Ä", Aring: "Å", AElig: "Æ", Ccedil: "Ç", Egrave: "È", Eacute: "É", Ecirc: "Ê", Euml: "Ë", Igrave: "Ì", Iacute: "Í", Icirc: "Î", Iuml: "Ï", ETH: "Ð", Ntilde: "Ñ", Ograve: "Ò", Oacute: "Ó", Ocirc: "Ô", Otilde: "Õ", Ouml: "Ö", times: "×", Oslash: "Ø", Ugrave: "Ù", Uacute: "Ú", Ucirc: "Û", Uuml: "Ü", Yacute: "Ý", THORN: "Þ", szlig: "ß", agrave: "à", aacute: "á", acirc: "â", atilde: "ã", auml: "ä", aring: "å", aelig: "æ", ccedil: "ç", egrave: "è", eacute: "é", ecirc: "ê", euml: "ë", igrave: "ì", iacute: "í", icirc: "î", iuml: "ï", eth: "ð", ntilde: "ñ", ograve: "ò", oacute: "ó", ocirc: "ô", otilde: "õ", ouml: "ö", divide: "÷", oslash: "ø", ugrave: "ù", uacute: "ú", ucirc: "û", uuml: "ü", yacute: "ý", thorn: "þ", yuml: "ÿ", fnof: "ƒ", Alpha: "Α", Beta: "Β", Gamma: "Γ", Delta: "Δ", Epsilon: "Ε", Zeta: "Ζ", Eta: "Η", Theta: "Θ", Iota: "Ι", Kappa: "Κ", Lambda: "Λ", Mu: "Μ", Nu: "Ν", Xi: "Ξ", Omicron: "Ο", Pi: "Π", Rho: "Ρ", Sigma: "Σ", Tau: "Τ", Upsilon: "Υ", Phi: "Φ", Chi: "Χ", Psi: "Ψ", Omega: "Ω", alpha: "α", beta: "β", gamma: "γ", delta: "δ", epsilon: "ε", zeta: "ζ", eta: "η", theta: "θ", iota: "ι", kappa: "κ", lambda: "λ", mu: "μ", nu: "ν", xi: "ξ", omicron: "ο", pi: "π", rho: "ρ", sigmaf: "ς", sigma: "σ", tau: "τ", upsilon: "υ", phi: "φ", chi: "χ", psi: "ψ", omega: "ω", thetasym: "ϑ", upsih: "ϒ", piv: "ϖ", bull: "•", hellip: "…", prime: "′", Prime: "″", oline: "‾", frasl: "⁄", weierp: "℘", image: "ℑ", real: "ℜ", trade: "™", alefsym: "ℵ", larr: "←", uarr: "↑", rarr: "→", darr: "↓", harr: "↔", crarr: "↵", lArr: "⇐", uArr: "⇑", rArr: "⇒", dArr: "⇓", hArr: "⇔", forall: "∀", part: "∂", exist: "∃", empty: "∅", nabla: "∇", isin: "∈", notin: "∉", ni: "∋", prod: "∏", sum: "∑", minus: "−", lowast: "∗", radic: "√", prop: "∝", infin: "∞", ang: "∠", and: "⊥", or: "⊦", cap: "∩", cup: "∪", int: "∫", there4: "∴", sim: "∼", cong: "≅", asymp: "≈", ne: "≠", equiv: "≡", le: "≤", ge: "≥", sub: "⊂", sup: "⊃", nsub: "⊄", sube: "⊆", supe: "⊇", oplus: "⊕", otimes: "⊗", perp: "⊥", sdot: "⋅", lceil: "⌈", rceil: "⌉", lfloor: "⌊", rfloor: "⌋", lang: "〈", rang: "〉", loz: "◊", spades: "♠", clubs: "♣", hearts: "♥", diams: "♦", quot: '"', amp: "&", lt: "<", gt: ">", OElig: "Œ", oelig: "œ", Scaron: "Š", scaron: "š", Yuml: "Ÿ", circ: "ˆ", tilde: "˜", ensp: " ", emsp: " ", thinsp: " ", zwnj: "‌", zwj: "‍", lrm: "‎", rlm: "‏", ndash: "–", mdash: "—", lsquo: "‘", rsquo: "’", sbquo: "‚", ldquo: "“", rdquo: "”", bdquo: "„", dagger: "†", Dagger: "‡", permil: "‰", lsaquo: "‹", rsaquo: "›" };
860
- var pr = /^[\n\r\x20\u2000-\u200B\u205F\u3000]/, yr = /^<\/([a-zA-Z0-9]+)([^>]*)>/, mr = /^<([a-zA-Z0-9]+)((?:\s[^=\s/]+(?:\s*=\s*(?:"[^"]+"|'[^']+'|[^>\\s]+))?)+)?\s*(\/?)>(\n*)/, vr = /^<!--(.+?)-->/, wr = /&(?:#(\d\d{2,})|#x([\da-fA-F]{2,})|([a-zA-Z][a-zA-Z1-4]{1,8}));/g, be = { b: function(e) {
861
- e.weight = "bold";
862
- }, strong: function(e) {
863
- e.weight = "bold";
864
- }, i: function(e) {
865
- e.style = "italic";
866
- }, em: function(e) {
867
- e.style = "italic";
868
- }, dfn: function(e) {
869
- e.style = "italic";
870
- }, cite: function(e) {
871
- e.style = "italic";
872
- }, code: function(e) {
873
- e.family = "monospace";
874
- }, kbd: function(e) {
875
- e.family = "monospace";
876
- }, samp: function(e) {
877
- e.family = "monospace";
878
- }, var: function(e) {
879
- e.family = "monospace";
880
- }, tt: function(e) {
881
- e.family = "monospace";
882
- }, sub: function(e) {
883
- e.sub = !0;
884
- }, sup: function(e) {
885
- e.sup = !0;
886
- } }, xr = { div: 1, li: 1, blockquote: 2, h1: 2, h2: 2, h3: 2, h4: 2, h5: 2, h6: 2, ul: 2, ol: 2, hr: 2, p: 2 };
887
- function Ae(e) {
888
- return e.replace(wr, function(n, o, s, u) {
889
- if (o || s) {
890
- var y = o ? 10 : 16;
891
- return String.fromCharCode(parseInt(o || s, y));
892
- }
893
- return u in xe ? xe[u] : n;
894
- });
895
- }
896
- function br(e) {
897
- return e && e.length > 1 && (e[0] === '"' && e[e.length - 1] === '"' || e[0] === "'" && e[e.length - 1] === "'") ? e.slice(1, -1) : e;
898
- }
899
- var Ar = /^\s*([^=\s&]+)(?:\s*=\s*("[^"]+"|'[^']+'|[^>\s]+))?/;
900
- function kr(e) {
901
- var n, o = {};
902
- if (e) {
903
- do
904
- if (n = Ar.exec(e)) {
905
- var s = Ae(br(n[2] || "")).replace(/[ \r\n\t]+/g, " ").trim();
906
- if (o[n[1]] = s, (e = e.slice(n[0].length)).length && /^\S/.test(e[0])) throw new Error("Attribute error");
907
- }
908
- while (n && e.length);
909
- if (/\S/.test(e)) throw new Error("Attribute error");
910
- }
911
- return o;
912
- }
913
- const ke = { copyright: "©", textcopyright: "©", dag: "†", textdagger: "†", ddag: "‡", textdaggerdbl: "‡", guillemotleft: "«", guillemotright: "»", guilsinglleft: "‹", guilsinglright: "›", ldots: "…", dots: "…", textellipsis: "…", lq: "‘", P: "¶", textparagraph: "¶", pounds: "£", textsterling: "£", quotedblbase: "„", quotesinglbase: "‚", rq: "’", S: "§", sim: "~", textasciicircum: "^", textasciitilde: "˜", texttildelow: "~", textasteriskcentered: "*", textbackslash: "'", textbar: "|", textbardbl: "╎", textbigcircle: "◯", textbraceleft: "{", textbraceright: "}", textbullet: "•", textdollar: "$", textemdash: "—", textendash: "—", texteuro: "€", eurosym: "€", euro: "€", textexclamdown: "¡", textgreater: ">", textless: "<", textordfeminine: "ª", textordmasculine: "º", textperiodcentered: "·", cdot: "·", textquestiondown: "¿", textquotedblleft: "“", textquotedblright: "”", textquoteleft: "‘", textquoteright: "’", textquotestraightbase: "‚", textquotestraightdblbase: "„", textregistered: "®", textthreequartersemdash: "-", texttrademark: "™", texttwelveudash: "-", textunderscore: "_", textvisiblespace: "␣", gets: "←", textleftarrow: "←", to: "→", textrightarrow: "→", textdegree: "°", infty: "∞", triangle: "△", triangledown: "▽", blacktriangle: "▲", blacktriangledown: "▼", angle: "∠", sphericalangle: "∢", aleph: "ℵ", hbar: "ħ", imath: "𝚤", jmath: "𝚥", ell: "ℓ", wp: "℘", Re: "ℜ", Im: "ℑ", mho: "℧", prime: "′", emptyset: "∅", nabla: "∇", surd: "√", partial: "∂", top: "⟙", bot: "⟂", vdash: "⟝", dashv: "⟞", forall: "∀", exists: "∃", nexists: "∄", neg: "¬", lnot: "¬", flat: "♭", natural: "♮", sharp: "♯", backslash: "\\", Box: "□", Diamond: "♢", clubsuit: "♣", diamondsuit: "♦", heartsuit: "♥", spadesuit: "♠", Join: "⨝", blacksquare: "■", bigstar: "★", diagdown: "╲", diagup: "╱", blacklozenge: "⧫", rfloor: "⌋", lfloor: "⌊", rceil: "⌉", lceil: "⌈", rangle: "⟩", langle: "⟨", sum: "∑", int: "∫", oint: "∮", prod: "∏", coprod: "∏", bigcap: "∩", bigcup: "∪", bigsqcup: "⊔", bigvee: "∨", bigwedge: "∧", bigodot: "⊙", bigotimes: "⊗", bigoplus: "⊕", biguplus: "⊎", alpha: "α", beta: "β", chi: "χ", delta: "δ", epsilon: "ε", eta: "η", gamma: "γ", iota: "ι", kappa: "κ", lambda: "λ", mu: "μ", nu: "ν", omega: "ω", phi: "φ", pi: "π", psi: "ψ", rho: "ρ", sigma: "σ", tau: "τ", theta: "θ", upsilon: "υ", xi: "ξ", zeta: "ζ", Alpha: "Α", Beta: "Β", Chi: "Χ", Delta: "Δ", Epsilon: "Ε", Eta: "Η", Gamma: "Γ", Iota: "Ι", Kappa: "Κ", Lambda: "Λ", Mu: "Μ", Nu: "Ν", Omega: "Ω", Phi: "Φ", Pi: "Π", Psi: "Ψ", Rho: "Ρ", Sigma: "Σ", Tau: "Τ", Theta: "Θ", Upsilon: "Υ", Xi: "Ξ", Zeta: "Ζ", aa: "å", AA: "Å", ae: "æ", AE: "Æ", dh: "ð", DH: "Ð", dj: "đ", DJ: "Đ", ij: "ij", IJ: "IJ", l: "ł", L: "Ł", ng: "ŋ", NG: "Ŋ", o: "ø", O: "Ø", oe: "œ", OE: "Œ", ss: "ß", SS: "SS", th: "þ", TH: "Þ" };
914
- var Er = /^(\^|_|\\[^#$%&~_^\\{}()\s]+)(\{)?/, Sr = /^%[^\n]+(?:\n|$)/, Cr = /^[^#$%&~_^\\{}]+/, _r = /^\\([&{}$%#_])/, Dr = /(?:\\[\\@,!:;-]|-{2,3}|[!?]`|``?|,,|''?|~|<<|>>)/g, Lr = { "---": "—", "--": "–", "!`": "¡", "?`": "¿", "``": "“", ",,": "„", "''": "”", "`": "‘", "'": "’", "<<": "«", ">>": "»", "~": " ", "\\-": "­", "\\,": " ", "\\;": " ", "\\:": " ", "\\!": " ", "\\@": "\uFEFF", "\\\\": "\\newline{}" }, X = { bf: function(e) {
915
- e.weight = "bold";
916
- }, it: function(e) {
917
- e.style = "italic";
918
- }, sl: function(e) {
919
- e.style = "italic";
920
- }, color: function(e, n) {
921
- e.color = n;
922
- }, href: function(e, n) {
923
- e.href = n;
924
- }, "^": function(e) {
925
- e.sup = !0;
926
- }, _: function(e) {
927
- e.sub = !0;
928
- }, par: function(e) {
929
- this.tokens.push(new et(), new et());
930
- }, newline: function(e) {
931
- this.tokens.push(new et());
932
- }, url: function(e, n) {
933
- this.open_context().href = n, this.add_token(new j(n)), this.close_context();
934
- } };
935
- X.textsuperscript = X["^"], X.textsubscript = X._, X.textsl = X.sl, X.mathbf = X.bf, X.mathit = X.it, X.textbf = X.bf, X.textit = X.it, X.textcolor = X.color;
936
- var Tr = /[\r\n\xA0]+/g;
937
- function $r(e, n) {
938
- e.sup && (e.baseline = 0.45, e.size = 0.7), e.sub && (e.baseline = -0.3, e.size = 0.7);
939
- var o = n;
940
- return (e.style || e.weight || e.baseline || e.color || e.size || e.family) && (o = E(n, e)), o;
941
- }
942
- function Ee(e, n, o) {
943
- for (var s, u, y = e.width; y + o.width > n && e.length; ) u = (s = e[e.length - 1]).width, s.width > o.width ? (s.value = s.value.slice(0, -1), s.width = P(s, s.font), y += s.width) : e.pop(), y -= u;
944
- e[e.length - 1] instanceof yt && e.pop(), s = e[e.length - 1] || s || {}, o.font = E(o.font, s.bold, s.italic, ""), o.href = e.length ? s.href : null, o.rel = e.length ? s.rel : null, o.target = e.length ? s.target : null, e.push(o);
945
- }
946
- function bt(e) {
947
- return Math.round(1e6 * e) / 1e6;
948
- }
949
- function Se(e) {
950
- return function(n) {
951
- if (Array.isArray(n)) return ee(n);
952
- }(e) || function(n) {
953
- if (typeof Symbol < "u" && n[Symbol.iterator] != null || n["@@iterator"] != null) return Array.from(n);
954
- }(e) || function(n, o) {
955
- if (n) {
956
- if (typeof n == "string") return ee(n, o);
957
- var s = Object.prototype.toString.call(n).slice(8, -1);
958
- return s === "Object" && n.constructor && (s = n.constructor.name), s === "Map" || s === "Set" ? Array.from(n) : s === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(s) ? ee(n, o) : void 0;
959
- }
960
- }(e) || function() {
961
- throw new TypeError(`Invalid attempt to spread non-iterable instance.
962
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`);
963
- }();
964
- }
965
- function ee(e, n) {
966
- (n == null || n > e.length) && (n = e.length);
967
- for (var o = 0, s = new Array(n); o < n; o++) s[o] = e[o];
968
- return s;
969
- }
970
- var Ir = { center: "middle", right: "end" }, Mr = { middle: 0.5, center: 0.5, bottom: 1, end: 1 }, re = function(e, n) {
971
- return !e && !n || e === n;
972
- };
973
- function Or(e, n) {
974
- var o = [], s = n.font(), u = s.size, y = s.family, x = n.align(), v = n.createElement();
975
- if (e.length) {
976
- var S = s.height, _ = n.valign(), $ = n.height()(), I = n.width()(0), D = !isFinite(I) && e.length === 1, O = D ? null : n.x(), B = bt(S / u), J = D ? null : bt(S / (1.15 * u + (S - u) / 2));
977
- if (Mr[_] && isFinite($)) {
978
- var F = _ === "bottom" ? 1 : 0.5;
979
- J += ($ * F - S * e.length * F) / u;
980
- }
981
- var z = x === "justify", q = 0;
982
- x === "right" ? q = I : x === "center" && (q = I / 2);
983
- for (var H = [], K = "tspan", G = null, R = "", T = function() {
984
- if (R) {
985
- var mt = v(K, G, R);
986
- H.push(mt);
987
- }
988
- K = "tspan", G = null, R = "";
989
- }, rt = 0, Q = e.length; rt < Q; rt++) {
990
- var lt = "", gt = "", at = 0, ht = e[rt];
991
- if (ht.length) {
992
- H = [];
993
- for (var At = 0, Mt = 0, ut = void 0, V = 0, Bt = ht.length; V < Bt; V++) {
994
- var W = ht[V], Z = W.font;
995
- W.whitespace && At++, Mt += W.width, V && !W.tracking && !at && re(Z.id, lt) && re(W.class, gt) && re(ut, W.href) ? R += W.value : (T(), R = W.value, G = { fontFamily: Z.family !== y ? Z.family : null, fontSize: Z.size !== u ? Z.size : null, fontWeight: Z.weight || null, fontStyle: Z.style || null, fontVariant: Z.variant !== "normal" && Z.variant || null, fill: Z.color || null, baselineShift: Z.baseline ? 100 * Z.baseline + "%" : null, className: W.class || null }, at && (G.dx = bt(at), at = 0), W.tracking && (at = Z.size * W.tracking), W.href && !ut ? (ut = W.href, K = "a", G.href = ut, G.rel = W.rel, G.target = W.target) : ut = null, lt = Z.id, gt = W.class);
996
- }
997
- if (T(), D) o.push.apply(o, Se(H));
998
- else {
999
- var qt = null, Ot = rt === Q - 1 || ht[ht.length - 1] instanceof et;
1000
- z && ht.length > 1 && !Ot && (qt = bt((I - Mt) / At)), o.push(v.apply(void 0, ["tspan", { wordSpacing: qt, x: O(rt) + q, dy: bt(rt ? B : J) + "em" }].concat(Se(H))));
1001
- }
1002
- } else o.push(v("tspan", { x: O(rt), dy: bt(rt ? B : J) + "em" }, " "));
1003
- }
1004
- }
1005
- return v.apply(void 0, ["text", { fontFamily: y, fontSize: u, textAnchor: Ir[x] || "start" }].concat(o));
1006
- }
1007
- var zr = { middle: 0.5, center: 0.5, bottom: 1, end: 1 };
1008
- function Pr(e, n, o) {
1009
- if (e.length) {
1010
- o.textBaseline = "middle";
1011
- var s = n.font(), u = s.height, y = s.size, x = n.valign(), v = n.height()(), S = n.width()(0), _ = n.align(), $ = _ === "justify", I = 0.5 * u, D = zr[x];
1012
- if (D && isFinite(v)) {
1013
- var O = e.length * u;
1014
- I += v * D - O * D;
1015
- }
1016
- e.forEach(function(B, J) {
1017
- var F = n.x()(J), z = J * u + I, q = 0, H = 0;
1018
- B.forEach(function(R) {
1019
- R.whitespace && q++, H += R.width;
1020
- });
1021
- var K = 0, G = J === e.length - 1 || B[B.length - 1] instanceof et;
1022
- $ && B.length > 1 && !G && (K = (S - H) / q), B.forEach(function(R) {
1023
- o.font = R.font;
1024
- var T = R.font, rt = T.baseline ? y * -T.baseline + 0.15 * y : 0;
1025
- o.fillStyle = function(gt, at) {
1026
- return gt.color ? gt.color : at.href ? "#00C" : "#000";
1027
- }(T, R);
1028
- var Q = 0;
1029
- if (_ === "right" ? Q += S - H : _ === "center" ? Q += S / 2 - H / 2 : _ === "justify" && (R.whitespace || R instanceof et) && (F += K), o.fillText(R.value, F + Q, z + rt), R.href) {
1030
- o.beginPath(), o.strokeStyle = o.fillStyle;
1031
- var lt = Math.floor(z + 0.45 * y) + 0.5;
1032
- o.moveTo(F + Q, lt), o.lineTo(F + Q + R.width, lt), o.stroke();
1033
- }
1034
- F += R.width;
1035
- });
1036
- });
1037
- }
1038
- }
1039
- function ne(e) {
1040
- return ne = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(n) {
1041
- return typeof n;
1042
- } : function(n) {
1043
- return n && typeof Symbol == "function" && n.constructor === Symbol && n !== Symbol.prototype ? "symbol" : typeof n;
1044
- }, ne(e);
1045
- }
1046
- function Ce(e) {
1047
- for (var n = {}, o = 0; o < e.length; o++) {
1048
- var s = e[o];
1049
- typeof s != "number" && s != null && (typeof s == "string" ? n.text = s : typeof s == "function" ? n.fn = s : ne(s) === "object" && s._groups ? n.d3 = s : s && s.nodeType && s.getContext ? n.ctx = s.getContext("2d") : s && s.fillText && s.beginPath ? n.ctx = s : s && (n.text = s));
1050
- }
1051
- return n;
1052
- }
1053
- function $t(e) {
1054
- return $t = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(n) {
1055
- return typeof n;
1056
- } : function(n) {
1057
- return n && typeof Symbol == "function" && n.constructor === Symbol && n !== Symbol.prototype ? "symbol" : typeof n;
1058
- }, $t(e);
1059
- }
1060
- function Fr(e, n) {
1061
- for (var o = 0; o < n.length; o++) {
1062
- var s = n[o];
1063
- s.enumerable = s.enumerable || !1, s.configurable = !0, "value" in s && (s.writable = !0), Object.defineProperty(e, (u = function(y, x) {
1064
- if ($t(y) !== "object" || y === null) return y;
1065
- var v = y[Symbol.toPrimitive];
1066
- if (v !== void 0) {
1067
- var S = v.call(y, x);
1068
- if ($t(S) !== "object") return S;
1069
- throw new TypeError("@@toPrimitive must return a primitive value.");
1070
- }
1071
- return String(y);
1072
- }(s.key, "string"), $t(u) === "symbol" ? u : String(u)), s);
1073
- }
1074
- var u;
1075
- }
1076
- var Hr = E(), ie = function(e) {
1077
- return typeof e == "function" ? e : function() {
1078
- return e;
1079
- };
1080
- }, st = function() {
1081
- function e(s) {
1082
- if (function(y, x) {
1083
- if (!(y instanceof x)) throw new TypeError("Cannot call a class as a function");
1084
- }(this, e), this.props = { overflow: "ellipsis", lineclamp: null, align: "left", wordBreak: null, valign: "top", width: function() {
1085
- return 1 / 0;
1086
- }, height: function() {
1087
- return 1 / 0;
1088
- }, x: function() {
1089
- return 0;
1090
- }, font: null, tAnchor: 0, parser: e.defaultparser }, s) for (var u in s) typeof this[u] == "function" && this[u](s[u]);
1091
- }
1092
- var n, o;
1093
- return n = e, o = [{ key: "linebreak", value: function(s) {
1094
- var u = this, y = this.props.parser(String(s)), x = this.font(), v = function(S, _, $) {
1095
- if (!S.length) return [];
1096
- var I = _.height(), D = _.width(), O = _.overflowLine(), B = _.overflowWrap(), J = E($, !0, !1), F = isFinite(I()) ? Math.floor(I() / $.height) : 1 / 0;
1097
- if (!I() && !D(0) || !F) return [];
1098
- for (var z = 0, q = 0, H = 0, K = [], G = [], R = !1; z < S.length && q < F; ) {
1099
- var T = S[z], rt = $r(T, $);
1100
- if (T.width = P(T, rt), T.font = rt, T.line = q, T.whitespace = T.value in k, T.value && (T.value = T.value.replace(Tr, " ")), !(!H && T.whitespace || R && T.whitespace)) if (T instanceof et) H = 0, G = [], K.push(z + 1), q++;
1101
- else if (T instanceof Tt || T instanceof yt) G.push({ index: z, width: H });
1102
- else if (T.whitespace || H + T.width < D(q)) H += T.width;
1103
- else if (G.length) {
1104
- var Q = void 0, lt = void 0;
1105
- do {
1106
- lt = !0, Q = G.pop();
1107
- var gt = S[Q.index], at = void 0;
1108
- gt instanceof yt && (at = P("-", gt.font), Q.width + at > D(q) && (lt = !G.length));
1109
- } while (!lt);
1110
- K.push(Q.index + 1), H = 0, q++, z = Q.index, G = [];
1111
- } else if (B === "break-word") {
1112
- var ht = D(q);
1113
- if (H + T.width > ht) {
1114
- var At = T.clone();
1115
- do
1116
- T.value = T.value.slice(0, -1), T.width = P(T, T.font), H += T.width;
1117
- while (T.value && T.width > ht);
1118
- At.value = At.value.slice(T.value.length), S.splice(z + 1, 0, new Tt(), At);
1119
- }
1120
- K.push(z + 1), H = 0, q++;
1121
- } else H += T.width;
1122
- z++, R = T.whitespace;
1123
- }
1124
- z !== K[K.length - 1] && K.push(z);
1125
- var Mt = 0, ut = 0, V = K.map(function(mt) {
1126
- for (var Y, vt = Mt; (Y = S[vt]) && (Y.whitespace || !Y.value); ) vt++;
1127
- for (var pt = mt, ae = null; pt > vt && (Y = S[pt - 1]) && (Y.whitespace || !(Y.value || Y instanceof yt)); ) Y instanceof et && (ae = Y), pt--;
1128
- Y instanceof yt && (Y.value = "-", Y.width = P("-", Y.font)), Mt = mt;
1129
- var kt = S.slice(vt, pt).filter(function(le) {
1130
- return le.value;
1131
- });
1132
- return ae && kt.push(ae), kt.width = kt.reduce(function(le, Rr) {
1133
- return le + Rr.width;
1134
- }, 0), kt.width > ut && (ut = kt.width), kt;
1135
- });
1136
- if (V.hasLineOverflow = !1, O) {
1137
- var Bt = O === "ellipsis" ? "…" : O;
1138
- V.forEach(function(mt, Y) {
1139
- var vt = D(Y);
1140
- if (mt.width > vt) {
1141
- var pt = new j(Bt);
1142
- pt.font = $, pt.width = P(Bt, J), Ee(mt, vt, pt), V.hasLineOverflow = !0;
1143
- }
1144
- });
1145
- }
1146
- var W = _.overflow() === "ellipsis" ? "…" : _.overflow();
1147
- if (W && z !== S.length) {
1148
- var Z = D(V.length - 1), qt = V[V.length - 1], Ot = new j(W);
1149
- Ot.font = $, Ot.width = P(W, J), Ee(qt, Z, Ot), V.hasOverflow = !0;
1150
- } else V.hasOverflow = !1;
1151
- return V.font = $, V.width = ut, V;
1152
- }(y, this, x);
1153
- return v.height = v.length * x.height, v.render = function(S) {
1154
- return u.render(v, S);
1155
- }, v.svg = v.render, v.draw = v.render, v;
1156
- } }, { key: "font", value: function(s) {
1157
- return arguments.length ? (this.props.font = E(s), this) : this.props.font || E(Hr);
1158
- } }, { key: "overflow", value: function(s) {
1159
- return arguments.length ? (this.props.overflow = String(s), this) : this.props.overflow;
1160
- } }, { key: "overflowLine", value: function(s) {
1161
- return arguments.length ? (this.props.lineclamp = String(s), this) : this.props.lineclamp;
1162
- } }, { key: "valign", value: function(s) {
1163
- return arguments.length ? (this.props.valign = s, this) : this.props.valign;
1164
- } }, { key: "align", value: function(s) {
1165
- if (!arguments.length) return this.props.align;
1166
- var u = String(s).toLowerCase();
1167
- return u === "left" || u === "start" ? (this.props.align = "left", this.props.tAnchor = 0) : u === "center" || u === "middle" ? (this.props.align = "center", this.props.tAnchor = -0.5) : u === "end" || u === "right" ? (this.props.align = "right", this.props.tAnchor = -1) : u === "justify" && (this.props.align = s, this.props.tAnchor = 0), this;
1168
- } }, { key: "overflowWrap", value: function(s) {
1169
- if (!arguments.length) return this.props.overflowWrap || "normal";
1170
- var u = String(s).toLowerCase();
1171
- return u === "break-word" ? this.props.overflowWrap = "break-word" : u !== "normal" && s != null || (this.props.overflowWrap = null), this;
1172
- } }, { key: "width", value: function(s) {
1173
- return arguments.length ? (this.props.width = ie(s), this) : this.props.width;
1174
- } }, { key: "height", value: function(s) {
1175
- return arguments.length ? (this.props.height = ie(s), this) : this.props.height;
1176
- } }, { key: "x", value: function(s) {
1177
- return arguments.length ? (this.props.x = ie(s), this) : this.props.x;
1178
- } }, { key: "parser", value: function(s) {
1179
- if (!arguments.length) return this.props.parser;
1180
- if (typeof s == "string") {
1181
- var u = e[s] || e[s + "parser"];
1182
- typeof u == "function" && (s = u);
1183
- }
1184
- if (typeof s != "function") throw new Error("Unknown parser: " + s);
1185
- return this.props.parser = s, this;
1186
- } }, { key: "createElement", value: function(s) {
1187
- return arguments.length ? (this.props.createElement = s, this) : this.props.createElement || e.createElement;
1188
- } }, { key: "render", value: function() {
1189
- var s = Ce(arguments);
1190
- return typeof s.text == "string" && (s.text = this.linebreak(s.text)), s.ctx ? Pr(s.text, this, s.ctx) : Or(s.text, this);
1191
- } }], o && Fr(n.prototype, o), Object.defineProperty(n, "prototype", { writable: !1 }), e;
1192
- }();
1193
- function It(e) {
1194
- return It = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(n) {
1195
- return typeof n;
1196
- } : function(n) {
1197
- return n && typeof Symbol == "function" && n.constructor === Symbol && n !== Symbol.prototype ? "symbol" : typeof n;
1198
- }, It(e);
1199
- }
1200
- function se(e, n) {
1201
- (n == null || n > e.length) && (n = e.length);
1202
- for (var o = 0, s = new Array(n); o < n; o++) s[o] = e[o];
1203
- return s;
1204
- }
1205
- function Nr(e, n) {
1206
- for (var o = 0; o < n.length; o++) {
1207
- var s = n[o];
1208
- s.enumerable = s.enumerable || !1, s.configurable = !0, "value" in s && (s.writable = !0), Object.defineProperty(e, (u = function(y, x) {
1209
- if (It(y) !== "object" || y === null) return y;
1210
- var v = y[Symbol.toPrimitive];
1211
- if (v !== void 0) {
1212
- var S = v.call(y, x);
1213
- if (It(S) !== "object") return S;
1214
- throw new TypeError("@@toPrimitive must return a primitive value.");
1215
- }
1216
- return String(y);
1217
- }(s.key, "string"), It(u) === "symbol" ? u : String(u)), s);
1218
- }
1219
- var u;
1220
- }
1221
- var _e = function(e) {
1222
- return typeof e == "function" ? e : function() {
1223
- return e;
1224
- };
1225
- }, De = function() {
1226
- function e(s) {
1227
- if (function(y, x) {
1228
- if (!(y instanceof x)) throw new TypeError("Cannot call a class as a function");
1229
- }(this, e), this.props = { width: function() {
1230
- return 1 / 0;
1231
- }, height: function() {
1232
- return 1 / 0;
1233
- }, rotation: 0, vAnchor: 0, hAnchor: 0 }, s) for (var u in s) typeof this[u] == "function" && this[u](s[u]);
1234
- this.render = this.render.bind(this);
1235
- }
1236
- var n, o;
1237
- return n = e, o = [{ key: "anchor", value: function(s) {
1238
- var u = this.props, y = u.hAnchor, x = u.vAnchor, v = u.width, S = u.height;
1239
- if (!arguments.length) return [y * v(0), x * S(0)];
1240
- if (typeof s == "string") {
1241
- var _ = this.props;
1242
- s.toLowerCase().trim().split(/\s+/).forEach(function($) {
1243
- $ === "top" && (_.vAnchor = -0), $ === "middle" && (_.vAnchor = -0.5), $ === "bottom" && (_.vAnchor = -1), $ === "left" && (_.hAnchor = -0), $ === "center" && (_.hAnchor = -0.5), $ === "right" && (_.hAnchor = -1);
1244
- });
1245
- }
1246
- return this;
1247
- } }, { key: "width", value: function(s) {
1248
- return arguments.length ? (this.props.width = _e(s), this) : this.props.width;
1249
- } }, { key: "height", value: function(s) {
1250
- return arguments.length ? (this.props.height = _e(s), this) : this.props.height;
1251
- } }, { key: "rotate", value: function(s) {
1252
- return arguments.length ? (this.props.rotation = s, this) : this.props.rotation;
1253
- } }, { key: "createElement", value: function(s) {
1254
- return arguments.length ? (this.props.createElement = s, this) : this.props.createElement || e.createElement;
1255
- } }, { key: "canvas", value: function(s, u) {
1256
- var y, x = s.getContext ? s.getContext("2d") : s;
1257
- return x.save(), x.rotate(this.rotate() * Math.PI / 180), x.translate.apply(x, function(v) {
1258
- if (Array.isArray(v)) return se(v);
1259
- }(y = this.anchor()) || function(v) {
1260
- if (typeof Symbol < "u" && v[Symbol.iterator] != null || v["@@iterator"] != null) return Array.from(v);
1261
- }(y) || function(v, S) {
1262
- if (v) {
1263
- if (typeof v == "string") return se(v, S);
1264
- var _ = Object.prototype.toString.call(v).slice(8, -1);
1265
- return _ === "Object" && v.constructor && (_ = v.constructor.name), _ === "Map" || _ === "Set" ? Array.from(v) : _ === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(_) ? se(v, S) : void 0;
1266
- }
1267
- }(y) || function() {
1268
- throw new TypeError(`Invalid attempt to spread non-iterable instance.
1269
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`);
1270
- }()), u(x), x.restore(), x;
1271
- } }, { key: "render", value: function() {
1272
- var s = Ce(arguments);
1273
- if (s.d3) return s.d3.attr("transform", "rotate(".concat(this.rotate(), ") translate(").concat(this.anchor(), ")"));
1274
- if (s.ctx) return this.canvas(s.ctx, s.fn);
1275
- if (s.text) {
1276
- var u = typeof s.text.render == "function" ? s.text.render() : s.text;
1277
- return this.createElement()("g", { transform: "rotate(".concat(this.rotate(), ") translate(").concat(this.anchor(), ")") }, u);
1278
- }
1279
- } }], o && Nr(n.prototype, o), Object.defineProperty(n, "prototype", { writable: !1 }), e;
1280
- }(), jr = Object.prototype.hasOwnProperty, oe = {};
1281
- function Br(e) {
1282
- return oe[e] || (oe[e] = e.replace(/([a-z])([A-Z])/g, function(n, o, s) {
1283
- return o + "-" + s.toLowerCase();
1284
- })), oe[e];
1285
- }
1286
- function Le(e, n) {
1287
- if (Array.isArray(n)) return n.forEach(function(o) {
1288
- return Le(e, o);
1289
- });
1290
- typeof n == "string" && (n = document.createTextNode(n)), e.appendChild(n);
1291
- }
1292
- function Te(e, n) {
1293
- if (typeof document < "u") {
1294
- var o = typeof e == "string" ? document.createElementNS("http://www.w3.org/2000/svg", e) : e;
1295
- if (n && o.setAttribute) for (var s in n) jr.call(n, s) && n[s] != null && o.setAttribute(s === "className" ? "class" : Br(s), n[s]);
1296
- for (var u = arguments.length, y = new Array(u > 2 ? u - 2 : 0), x = 2; x < u; x++) y[x - 2] = arguments[x];
1297
- return y != null && y.length && y.forEach(function(v) {
1298
- Le(o, v);
1299
- }), o;
1300
- }
1301
- }
1302
- st.createElement = Te, st.textparser = jt, st.defaultparser = jt, st.htmlparser = function(e) {
1303
- e = String(e || "").trim();
1304
- for (var n, o, s = { weight: null, style: null, sub: !1, sup: !1, href: null, color: null, rel: null, target: null }, u = [], y = [], x = function(I) {
1305
- for (var D in s) s[D] && (I[D] = s[D]);
1306
- u.push(I);
1307
- }, v = function(I) {
1308
- var D = u.length, O = xr[I];
1309
- if (D && O) {
1310
- for (var B = D - 1; u[B] && (u[B] instanceof Tt || pr.test(u[B].value)); ) B--;
1311
- for (; O && u[B] && u[B] instanceof et; ) B--, O--;
1312
- for (; O-- > 0; ) u.push(new et());
1313
- }
1314
- }; e.length; ) {
1315
- if (n = /^[^<]+/.exec(e)) jt(Ae(n[0]), !1).forEach(x);
1316
- else if (!(n = vr.exec(e))) if (n = yr.exec(e)) y.length && (s = y.pop()), v(n[1]);
1317
- else if (n = mr.exec(e)) {
1318
- var S = n[1];
1319
- v(S), y.push(s), s = Object.create(s), be[S] && be[S](s, "");
1320
- var _ = kr(n[2]);
1321
- S === "a" && (_.href && (s.href = _.href), _.rel && (s.rel = _.rel), _.target && (s.target = _.target)), _.class && (s.class = s.class ? s.class + " " + _.class : _.class), _.style && (o = /(?:^|\s|;)color\s*:\s*([^;\s"']+)/.exec(_.style)) && o[1] && (s.color = o[1]), S === "br" && u.push(new et());
1322
- } else n = [e.slice(0, 1)], x(new j(n[0]));
1323
- e = e.slice(n[0].length);
1324
- }
1325
- for (var $ = u[u.length - 1]; $ instanceof et; ) u.pop(), $ = u[u.length - 1];
1326
- return u;
1327
- }, st.latexparser = function(e) {
1328
- e = String(e || "").trim();
1329
- var n = [0];
1330
- e = e.replace(/\\verb,(.*?),/, function(F, z) {
1331
- return n.push(z), "\\verb," + (n.length - 1) + ",";
1332
- }).replace(/\\\\\n/g, function() {
1333
- return "\\\\";
1334
- }).replace(Dr, function(F, z, q) {
1335
- return q.charAt(z - 1) === "\\" ? F : Lr[F];
1336
- }).replace(/\n\s+/g, function(F) {
1337
- return /\n/.test(F.slice(1)) ? "\\par " : F;
1338
- }).replace(/\\symbol\{(\d+)\}/, function(F, z, q, H) {
1339
- return H.charAt(q - 1) === "\\" ? F : String.fromCharCode(1 * z);
1340
- }).replace(/(^|[^\\])(\^|_)(\d|[^{]\S*)/g, function(F, z, q, H) {
1341
- return z + q + "{" + H + "}";
1342
- }).replace(/\\verb,(.*?),/, function(F, z) {
1343
- return "\\verb,".concat(n[+z], ",");
1344
- });
1345
- for (var o, s = { weight: null, italic: null, variant: null, sub: !1, sup: !1, href: null }, u = [], y = [], x = function(F) {
1346
- for (var z in s) s[z] && (F[z] = s[z]);
1347
- return u.push(F), F;
1348
- }, v = function() {
1349
- y.push(s), s = Object.create(s);
1350
- }, S = function() {
1351
- if (!y.length) throw new Error("Unexpected }");
1352
- s = y.pop();
1353
- }, _ = { tokens: u, open_context: v, close_context: S, add_token: x }; e.length; ) {
1354
- if (o = Cr.exec(e)) jt(o[0], !1).forEach(x);
1355
- else if (o = _r.exec(e)) x(new j(o[1]));
1356
- else if (!(o = Sr.exec(e))) {
1357
- if (o = /^\{/.exec(e)) v();
1358
- else if (o = /^\}/.exec(e)) S();
1359
- else if (!(o = /^\$/.exec(e))) if (o = /^\\verb,([^,]+),/.exec(e)) x(new j(o[1]));
1360
- else if (o = Er.exec(e)) {
1361
- var $ = o[1].slice(1) || o[1], I = !!o[2];
1362
- if (/^(La)?TeX$/i.test($)) {
1363
- v(), s.family = "serif";
1364
- var D = void 0;
1365
- $ === "LaTeX" && ((D = x(new j("L"))).tracking = -0.25, (D = x(new j("A"))).size = 0.7, D.baseline = 0.3, D.tracking = -0.1), (D = x(new j("T"))).tracking = -0.17, (D = x(new j("E"))).baseline = -0.22, D.tracking = -0.13, D = x(new j("X")), S();
1366
- } else if ($ in ke) x(new j(ke[$])), I && v();
1367
- else if ($ in X) {
1368
- var O = [], B = X[$].length - 1, J = void 0;
1369
- if (B) {
1370
- for (I = !1, e = e.slice(o[0].length - 1); B--; ) {
1371
- if (!(J = /^\{([^}]+)\}/.exec(e))) throw new Error($ + " is missing an argument");
1372
- O.push(J[1]), e = e.slice(J[0].length);
1373
- }
1374
- o[0] = /^\{/.exec(e) ? "{" : "", I = !!o[0];
1375
- }
1376
- I && v(), X[$].apply(_, [s].concat(O));
1377
- } else console.warn("unknown latex command", $), x(new j(o[1])), I && v();
1378
- } else o = [e.slice(0, 1)], x(new j(o[0]));
1379
- }
1380
- e = e.slice(o[0].length);
1381
- }
1382
- return u;
1383
- }, st.measureText = function(e, n, o) {
1384
- return P(e, E(n), o);
1385
- }, st.Token = j, st.Break = Tt, st.LineBreak = et, st.SoftHyphen = yt, st.Rotator = De, De.createElement = Te;
1386
- const qr = st;
1387
- return r.default;
1388
- })());
1389
- }(ve)), ve.exports;
1390
- }
1391
- var mn = yn();
1392
- const Re = /* @__PURE__ */ sr(mn);
1393
- function ce(l) {
1394
- return l.replace(/…$/, "");
1395
- }
1396
- function de(l) {
1397
- return l.children[0].innerHTML;
1398
- }
1399
- function vn(l, t) {
1400
- const i = ft(l), { fontSize: r, font: a, padding: h = 0 } = l.properties.style || {};
1401
- if (i.width === i.height && i.width === 0) return;
1402
- const c = new Re({
1403
- font: `${r}px/${r}px ${a}`.replace(/(px)+/g, "px"),
1404
- width: i.width - h * 2,
1405
- height: i.height - h * 2,
1406
- align: "left",
1407
- valign: "top",
1408
- x: 0,
1409
- overflow: "ellipsis",
1410
- parser: "html",
1411
- createElement: Re.createElement
1412
- });
1413
- c.overflowWrap("break-word");
1414
- const d = c.linebreak(
1415
- l.properties.content.replaceAll(`
1416
- `, "<br>")
1417
- ).render(), f = [...d.children];
1418
- let g = 0;
1419
- const p = [];
1420
- l.properties.content.split(`
1421
- `).forEach((A) => {
1422
- let E = A;
1423
- for (; E.length && g < f.length; ) {
1424
- if (f[g].innerHTML === "&nbsp;") {
1425
- E.startsWith(`
1426
- `) || p.push(g), g++;
1427
- break;
1428
- }
1429
- const k = ce(de(f[g]));
1430
- E.startsWith(k) && (E = E.slice(k.length).trim()), g++;
1431
- }
1432
- }), p.forEach((A) => d.removeChild(f[A]));
1433
- const w = l.properties.content.match(/(https?:\/\/.*)/gm), b = w ? w.map((A) => A.split(" ")[0]) : [];
1434
- d.setAttribute("transform", `translate(${h}, ${h})`), b.forEach((A) => {
1435
- let E = A;
1436
- const k = [];
1437
- for (; E.length > 0; ) {
1438
- const L = f.find(
1439
- (C) => !!C.children[0] && C.children[0].tagName === "tspan" && E.startsWith(ce(de(C)))
1440
- );
1441
- if (!L) break;
1442
- k.push(L);
1443
- const M = ce(L.children[0].innerHTML).length;
1444
- if (!M) break;
1445
- E = E.slice(M);
1446
- }
1447
- k.forEach((L) => {
1448
- const M = document.createElementNS("http://www.w3.org/2000/svg", "a");
1449
- M.setAttribute("href", A), M.setAttribute("target", "_blank"), M.innerHTML = de(L), L.children[0].innerHTML = "", L.children[0].appendChild(M);
1450
- });
1451
- }), t.appendChild(d);
1452
- }
1453
- const We = 20;
1454
- class wn extends ar {
1455
- constructor(t, i = {}) {
1456
- super(
1457
- t,
1458
- `
1459
- <div class="annotation-text-handle" data-handle-id="8">
1460
- <span class="handle line-handle top" data-handle-id="0"></span>
1461
- <span class="handle line-handle bottom" data-handle-id="1"></span>
1462
- <span class="handle line-handle left" data-handle-id="2"></span>
1463
- <span class="handle line-handle right" data-handle-id="3"></span>
1464
- <span class="handle top right point-handle top-right" data-handle-id="4"></span>
1465
- <span class="handle left top point-handle top-left" data-handle-id="5"></span>
1466
- <span class="handle bottom right point-handle bottom-right" data-handle-id="6"></span>
1467
- <span class="handle left bottom left-handle point-handle bottom-left" data-handle-id="7"></span>
1468
- <textarea wrap="on"></textarea>
1469
- </div>
1470
- `
1471
- ), m(this, "textArea"), m(this, "handleSize"), m(this, "rect", { x: 0, y: 0, width: 0, height: 0 }), m(this, "annotation", { ...ue }), m(this, "startX", 0), m(this, "startY", 0), m(this, "handles", []), m(this, "draggedHandle", U), m(this, "isFocused", !1), m(this, "placeholder", "Type your text here..."), m(this, "_onFocus", () => {
1472
- this.textArea.value === this.placeholder && (this.textArea.value = ""), this.isFocused = !0;
1473
- }), m(this, "_onBlur", () => {
1474
- this.isFocused = !1;
1475
- }), m(this, "startDrawing", (a, h, c = gn(a, h, 0, 0, "", Dt)) => {
1476
- this.add(c);
1477
- const d = this.ogma.view.graphToScreenCoordinates({ x: a, y: h });
1478
- this.select(c.id), this.startDragging(this.getById(c.id), d.x, d.y), this.draggedHandle = 6;
1479
- }), m(this, "cancelDrawing", () => {
1480
- this.isDragging && (this.remove(this.annotation.id), this.annotation = { ...ue }, this.draggedHandle = U, this.isDragging = !1, this.emit(Lt, this.annotation));
1481
- }), m(this, "startDragging", (a, h, c) => {
1482
- this.annotation = a;
1483
- const d = dt(this.annotation), f = ft(this.annotation);
1484
- this.rect.x = d.x, this.rect.y = d.y, this.rect.width = f.width, this.rect.height = f.height, this.startX = h, this.startY = c, this.disableDragging(), this.textArea.classList.add("noevents"), this.textArea.setAttribute("disabled", "disabled"), this.emit(Yt, this.annotation), this.isDragging = !0;
1485
- }), m(this, "onHandleMouseDown", (a) => {
1486
- const h = this.getById(this.selectedId) || this.getById(this.hoveredId);
1487
- if (!h) return;
1488
- this.selectedId !== h.id && this.select(this.hoveredId);
1489
- const { x: c, y: d } = Vt(a, this.ogma.getContainer());
1490
- this.startDragging(h, c, d), this.draggedHandle = tr(a.target);
1491
- }), m(this, "onMouseMove", (a) => {
1492
- requestAnimationFrame(() => this._onMouseMove(a));
1493
- }), m(this, "_onMouseMove", (a) => {
1494
- if (!this.isDragging) return;
1495
- a.stopPropagation(), a.preventDefault();
1496
- const h = this.handles[this.draggedHandle];
1497
- let c = h.classList.contains("top");
1498
- const d = h.classList.contains("left"), f = h.classList.contains("right"), g = h.classList.contains("bottom");
1499
- let p = h.classList.contains("line-handle");
1500
- !p && !c && !g && !d && !f && (c = !0, p = !0);
1501
- const { x: w, y: b } = Vt(
1502
- a,
1503
- this.ogma.getContainer()
1504
- );
1505
- let A = this.rect.x, E = this.rect.y, k = Math.max(this.rect.width, We), L = Math.max(this.rect.height, We);
1506
- const M = this.ogma.view.getZoom(), C = (w - this.startX) / M, N = (b - this.startY) / M, P = this.ogma.view.getAngle(), tt = nt({ x: C, y: N }, P), it = nt({ x: C, y: N }, -P);
1507
- p ? (A = this.rect.x + tt.x, E = this.rect.y + tt.y) : d && c ? (A += tt.x, E += tt.y, k -= C, L -= N) : f && g ? (k += C, L += N) : d && g ? (A += it.x, k -= it.x, L += it.y) : f && c && (E += it.y, k += it.x, L -= it.y), Qr(this.annotation, A, E, k, L), this.emit(Zt, this.annotation, "text"), this.refreshEditor(), this.layer.refresh();
1508
- }), m(this, "onMouseUp", () => {
1509
- !this.isDragging || this.draggedHandle === U || (this.restoreDragging(), this.textArea.classList.remove("noevents"), this.textArea.removeAttribute("disabled"), this.emit(Lt, this.annotation), this.isDragging = !1, this.draggedHandle = U);
1510
- }), m(this, "_onMousedown", (a) => {
1511
- a.stopPropagation();
1512
- }), m(this, "onViewChanged", () => {
1513
- const a = Math.max(2, this.handleSize / this.ogma.view.getZoom());
1514
- document.documentElement.style.setProperty("--handle-scale", `${1 / a}`), this.ogma.view.getAngle() === 0 ? this.editor.element.classList.remove("rotated") : this.editor.element.classList.add("rotated");
1515
- }), m(this, "_onInput", () => {
1516
- const a = this.getById(this.selectedId);
1517
- a && (this.textArea.value = this.textArea.value.replace(/ +(?= )/g, ""), this.textArea.focus(), a.properties.content = this.textArea.value, this.emit(me, a), this.layer.refresh());
1518
- }), this.showeditorOnHover = !1, this.handleSize = Be.handleSize, this.placeholder = Be.placeholder;
1519
- const r = this.textArea = this.editor.element.querySelector("textarea");
1520
- r.addEventListener("input", this._onInput), r.addEventListener("focus", this._onFocus), r.addEventListener("blur", this._onBlur), r.addEventListener("mousedown", this._onMousedown), r.spellcheck = !1, this.handles = Array.prototype.slice.call(
1521
- this.editor.element.querySelectorAll(".annotation-text-handle > .handle")
1522
- ), this.handles.push(this.editor.element), this.handles.forEach(
1523
- (a) => a.addEventListener("mousedown", this.onHandleMouseDown)
1524
- ), document.addEventListener("mouseup", this.onMouseUp), document.addEventListener("mousemove", this.onMouseMove, !0), t.events.on(["viewChanged", "zoom"], this.onViewChanged);
1525
- }
1526
- _canRemove() {
1527
- return !this.isFocused;
1528
- }
1529
- detect({ x: t, y: i }, r = 0) {
1530
- const a = { x: t, y: i }, h = this.ogma.view.getAngle();
1531
- return this.elements.find((c) => {
1532
- const { x: d, y: f } = dt(c), { width: g, height: p } = ft(c), w = { x: d, y: f }, { x: b, y: A } = nt(xt(a, w), -h);
1533
- return b > -r && b < g + r && A > -r && A < p + r;
1534
- });
1535
- }
1536
- draw(t) {
1537
- t.innerHTML = "";
1538
- const i = "", r = this.ogma.view.getAngle();
1539
- for (let h = 0; h < this.elements.length; h++) {
1540
- const c = this.elements[h], d = `class${h}`, f = ft(c), g = dt(c);
1541
- if (c.id === this.selectedId) continue;
1542
- const {
1543
- color: p,
1544
- fontSize: w,
1545
- font: b,
1546
- strokeColor: A,
1547
- strokeWidth: E,
1548
- strokeType: k,
1549
- background: L,
1550
- borderRadius: M
1551
- } = c.properties.style || Dt, C = wt("g");
1552
- C.classList.add("annotation-text"), C.setAttribute("fill", `${p}`), C.setAttribute("font-size", `${w}px`), C.setAttribute("font-family", `${b}`);
1553
- const N = wt("rect");
1554
- M && (N.setAttribute("rx", `${M}`), N.setAttribute("ry", `${M}`));
1555
- let P = !1;
1556
- k && k !== "none" && (P = !0, N.setAttribute("stroke", A || "black"), N.setAttribute("stroke-width", `${E}`), k === "dashed" && N.setAttribute("stroke-dasharray", "5,5")), (L && L.length || P) && (P = !0, N.setAttribute("fill", L || "transparent")), P && (N.setAttribute("width", `${f.width}`), N.setAttribute("height", `${f.height}`)), C.appendChild(N), vn(c, C);
1557
- const { x: tt, y: it } = nt(g, -r);
1558
- C.setAttribute("transform", `translate(${tt},${it})`), C.classList.add(d), C.setAttribute("data-annotation", `${c.id}`), C.setAttribute("data-annotation-type", "text"), t.appendChild(C);
1559
- }
1560
- const a = wt("style");
1561
- a.innerHTML = i, t.firstChild && t.insertBefore(a, t.firstChild);
1562
- }
1563
- refreshDrawing() {
1564
- const t = this.ogma.view.getAngle(), i = this.layer.element.children;
1565
- for (let r = 0; r < i.length; r++) {
1566
- const a = i[r];
1567
- if (!a.hasAttribute("data-annotation")) continue;
1568
- const h = a.getAttribute("data-annotation"), c = dt(this.getById(h)), { x: d, y: f } = nt(c, -t);
1569
- a.setAttribute("transform", `translate(${d},${f})`);
1570
- }
1571
- }
1572
- getDefaultOptions() {
1573
- return ue;
1574
- }
1575
- refreshEditor() {
1576
- if (+this.selectedId < 0 && +this.hoveredId < 0) return;
1577
- const t = this.getById(this.selectedId) || this.getById(this.hoveredId), i = ft(t), r = this.ogma.view.graphToScreenCoordinates(
1578
- dt(t)
1579
- ), a = this.ogma.view.getZoom(), {
1580
- font: h,
1581
- fontSize: c,
1582
- color: d,
1583
- background: f,
1584
- padding: g = 0
1585
- } = t.properties.style || Dt, p = (c || 1) * a;
1586
- this.textArea.value = t.properties.content;
1587
- const w = this.editor.element.style;
1588
- w.transform = `translate(${r.x}px, ${r.y}px)translate(-50%, -50%)translate(${i.width / 2 * a}px, ${i.height / 2 * a}px)`, w.width = `${i.width * a}px`, w.height = `${i.height * a}px`;
1589
- const b = this.textArea.style;
1590
- b.font = `${p} ${h}`, b.fontFamily = h || "sans-serif", b.fontSize = `${p}px`, b.padding = `${a * g}px`, b.lineHeight = `${p}px`, b.boxSizing = "border-box", b.color = d || "black", b.background = f || "transparent", this.textArea.placeholder = this.placeholder, this.layer.refresh();
1591
- }
1592
- select(t) {
1593
- super.select(t), this.textArea.classList.add("noevents");
1594
- }
1595
- destroy() {
1596
- super.destroy(), document.removeEventListener("mouseup", this.onMouseUp), document.removeEventListener("mousemove", this.onMouseMove, !0), this.ogma.events.off(this.onViewChanged);
1597
- }
1598
- }
1599
- class xn {
1600
- constructor() {
1601
- m(this, "links", {}), m(this, "linksByTargetId", {}), m(this, "linksByArrowId", {});
1602
- }
1603
- add(t, i, r, a, h) {
1604
- const c = Jt(), d = t.id, f = {
1605
- id: c,
1606
- arrow: d,
1607
- target: r,
1608
- targetType: a,
1609
- connectionPoint: h,
1610
- side: i
1611
- };
1612
- return this.links[c] = f, this.linksByTargetId[r] || (this.linksByTargetId[r] = []), this.linksByTargetId[r].push(c), this.linksByArrowId[d] || (this.linksByArrowId[d] = {}), this.linksByArrowId[d][i] = c, t.properties.link = t.properties.link || {}, t.properties.link[i] = {
1613
- id: r,
1614
- side: i,
1615
- type: a,
1616
- magnet: h
1617
- }, this;
1618
- }
1619
- arrowIsLinked(t, i) {
1620
- var r;
1621
- return !!((r = this.linksByArrowId[t]) != null && r[i]);
1622
- }
1623
- // remove the link between the arrow and the target by arrow id and side
1624
- remove(t, i) {
1625
- var r, a;
1626
- const h = t.id, c = (r = this.linksByArrowId[h]) == null ? void 0 : r[i];
1627
- if ((a = t.properties.link) == null || delete a[i], !c) return this;
1628
- const d = this.links[c];
1629
- delete this.links[c];
1630
- const f = this.linksByTargetId[d.target];
1631
- for (let g = 0; g < f.length; g++)
1632
- if (f[g] === c) {
1633
- f.splice(g, 1);
1634
- break;
1635
- }
1636
- return delete this.linksByArrowId[h][i], this;
1637
- }
1638
- getArrowLink(t, i) {
1639
- var r;
1640
- const a = (r = this.linksByArrowId[t]) == null ? void 0 : r[i];
1641
- return a ? this.links[a] : null;
1642
- }
1643
- getTargetLinks(t, i) {
1644
- var r;
1645
- return ((r = this.linksByTargetId[t]) == null ? void 0 : r.map((a) => this.links[a]).filter((a) => a.targetType === i)) ?? [];
1646
- }
1647
- forEach(t) {
1648
- Object.values(this.links).forEach(t);
1649
- }
1650
- }
1651
- const ot = (l) => l.properties.type === "arrow", ct = (l) => l.properties.type === "text", Ue = (l) => l.type === "FeatureCollection", bn = {
1652
- magnetColor: "#3e8",
1653
- detectMargin: 20,
1654
- magnetHandleRadius: 5,
1655
- magnetRadius: 10,
1656
- textPlaceholder: "Type here",
1657
- arrowHandleSize: 3.5,
1658
- textHandleSize: 3.5,
1659
- minArrowHeight: 20,
1660
- maxArrowHeight: 30
1661
- }, Xe = ["start", "end"], Ge = [
1662
- { x: 0, y: 0 },
1663
- { x: 0.5, y: 0 },
1664
- { x: 1, y: 0 },
1665
- { x: 0, y: 0.5 },
1666
- { x: 1, y: 0.5 },
1667
- { x: 0, y: 1 },
1668
- { x: 0.5, y: 1 },
1669
- { x: 1, y: 1 }
1670
- ];
1671
- class An extends or {
1672
- constructor(t, i = {}) {
1673
- super(), m(this, "arrows"), m(this, "texts"), m(this, "links", new xn()), m(this, "layer"), m(this, "annotations"), m(this, "ogma"), m(this, "options"), m(this, "selected", null), m(this, "updateTimeout", 0), m(this, "hoveredNode", null), m(this, "dragged", null), m(this, "textToMagnet"), m(this, "activeLinks", []), m(this, "_render", (r) => {
1674
- if (!this.dragged || this.textToMagnet === void 0) return;
1675
- r.beginPath(), r.fillStyle = "green";
1676
- const a = this.ogma.view.getZoom();
1677
- Ge.forEach((h) => {
1678
- if (!this.textToMagnet) return;
1679
- const c = ft(this.textToMagnet), d = dt(this.textToMagnet), f = Ut(h, { x: c.width, y: c.height }), g = nt(f, this.ogma.view.getAngle()), { x: p, y: w } = Ct(g, d);
1680
- r.moveTo(p, w), r.arc(p, w, this.options.magnetHandleRadius / a, 0, Math.PI * 2);
1681
- }), r.fill(), r.closePath();
1682
- }), m(this, "_onFeatureDrag", (r, a) => {
1683
- const h = a;
1684
- if (ot(r) && h === "line")
1685
- ["start", "end"].find((c) => {
1686
- const d = c === "start" ? zt(r) : Xt(r);
1687
- return this._snapToText(r, h, d) || this._findAndSnapToNode(r, c, d);
1688
- });
1689
- else if (ot(r) && h !== "line") {
1690
- const c = h === "start" ? zt(r) : Xt(r);
1691
- this._snapToText(r, h, c) || this._findAndSnapToNode(r, h, c);
1692
- } else ct(r) && (this.activeLinks.forEach(({ arrow: c, side: d, connectionPoint: f }) => {
1693
- const g = this.getAnnotation(c), p = ft(r), w = dt(r), b = Ut(f, { x: p.width, y: p.height }), A = nt(b, this.ogma.view.getAngle()), E = Ct(A, w);
1694
- g.geometry.coordinates[d === "start" ? 0 : 1] = [E.x, E.y];
1695
- }), this.activeLinks.length && this.arrows.refreshLayer());
1696
- this.layer.refresh(), this.emit(Zt, r, a);
1697
- }), m(this, "_onFeatureDragEnd", (r) => {
1698
- this.dragged !== null && ot(r) && zt(this.dragged) && Xe.forEach((a) => {
1699
- this.links.getArrowLink(r.id, a) && this.emit(un, {
1700
- arrow: r,
1701
- link: this.links.getArrowLink(r.id, a)
1702
- });
1703
- }), (ct(r) || ot(r)) && this.onUpdate(r), this.dragged = null, this.activeLinks = [], this.textToMagnet = void 0, this.annotations.forEach((a) => a.enableDetection()), this.layer.refresh(), this.emit(Lt, r);
1704
- }), m(this, "_onFeatureDragStart", (r) => {
1705
- this.textToMagnet = void 0, ot(r) ? this.dragged = r : ct(r) && this.activeLinks.push(...this.links.getTargetLinks(r.id, "text")), this.annotations.forEach((a) => {
1706
- const h = a.getSelectedFeature();
1707
- h && h !== r && a.unhover().unselect(), a.disableDetection();
1708
- }), this.emit(Yt, r);
1709
- }), m(this, "_onNodesDragStart", () => {
1710
- this.arrows.unhover().unselect(), this.texts.unhover().unselect();
1711
- }), m(this, "_onNodesDrag", (r) => {
1712
- const { dx: a, dy: h } = r;
1713
- this._moveNodes(r.nodes, a, h);
1714
- }), m(this, "_onLayoutEnd", (r) => {
1715
- r.ids.forEach((a, h) => {
1716
- this.links.getTargetLinks(a, "node").forEach((c) => {
1717
- const d = this.getAnnotation(c.arrow), f = c.side, g = Rt(
1718
- d,
1719
- f === "start" ? "end" : "start"
1720
- ), p = r.positions.current[h], w = this.ogma.getNode(a).getAttribute("radius"), b = Wt(g, p, +w);
1721
- St(d, f, b.x, b.y);
1722
- });
1723
- }), this.arrows.refreshLayer(), this.texts.refreshLayer();
1724
- }), m(this, "_onAdded", (r) => {
1725
- this.emit(ye, r);
1726
- }), m(this, "_onRemoved", (r) => {
1727
- this.emit(pe, r);
1728
- }), m(this, "_onUnselect", (r) => {
1729
- this.selected = null, this.emit(ge, r);
1730
- }), m(this, "_onSelect", (r) => {
1731
- this.selected !== r && (this.selected = r, this.emit(fe, this.selected));
1732
- }), m(this, "onUpdate", (r) => {
1733
- cancelAnimationFrame(this.updateTimeout), this.updateTimeout = requestAnimationFrame(
1734
- () => this._onUpdate(r)
1735
- );
1736
- }), m(this, "_onUpdate", (r) => {
1737
- this.emit(me, r);
1738
- }), this.options = this.setOptions({ ...bn, ...i }), this.ogma = t, this.arrows = new fn(t, this.options), this.texts = new wn(t, this.options), this.annotations = [this.arrows, this.texts], this.annotations.forEach((r) => {
1739
- r.on(Yt, this._onFeatureDragStart).on(Zt, this._onFeatureDrag).on(Lt, this._onFeatureDragEnd).on(me, this.onUpdate).on(ge, this._onUnselect).on(fe, this._onSelect).on(ye, this._onAdded).on(pe, this._onRemoved);
1740
- }), this.ogma.events.on("nodesDragStart", this._onNodesDragStart).on("nodesDragProgress", this._onNodesDrag).on("layoutEnd", this._onLayoutEnd).on(["viewChanged", "rotate"], () => {
1741
- this.refreshTextLinks();
1742
- }), this.layer = t.layers.addCanvasLayer(this._render), this.layer.moveToBottom();
1743
- }
1744
- _moveNodes(t, i, r) {
1745
- t.forEach((a) => {
1746
- const h = this.links.getTargetLinks(a.getId(), "node"), c = a.getPosition();
1747
- h.forEach((d) => {
1748
- const f = this.getAnnotation(d.arrow), g = d.side, p = Rt(
1749
- f,
1750
- g === "start" ? "end" : "start"
1751
- );
1752
- let w = c;
1753
- const b = +a.getAttribute("radius"), A = 1e-6;
1754
- (d.connectionPoint.x - (c.x - i) > A || d.connectionPoint.y - (c.y - r) > A) && (w = Wt(p, c, b)), St(f, g, w.x, w.y);
1755
- });
1756
- }), this.arrows.refreshLayer();
1757
- }
1758
- _snapToText(t, i, r) {
1759
- const a = this.texts.detect(r, this.options.detectMargin);
1760
- if (this.links.remove(t, i), !a) return !1;
1761
- this.textToMagnet = a;
1762
- const h = this.findMagnetPoint(Ge, a, r);
1763
- return h ? (St(t, i, h.point.x, h.point.y), this.links.add(t, i, a.id, "text", h.magnet), !0) : !1;
1764
- }
1765
- _findAndSnapToNode(t, i, r) {
1766
- var a, h;
1767
- const c = this.ogma.view.graphToScreenCoordinates(r), d = this.ogma.view.getElementAt(c);
1768
- this.links.remove(t, i), d && d.isNode ? ((a = this.hoveredNode) == null || a.setSelected(!1), this.hoveredNode = d, d.setSelected(!0), this._snapToNode(t, i, d, c)) : ((h = this.hoveredNode) == null || h.setSelected(!1), this.hoveredNode = null);
1769
- }
1770
- _snapToNode(t, i, r, a) {
1771
- const h = r.getPositionOnScreen(), c = +r.getAttribute("radius"), d = c * this.ogma.view.getZoom(), f = a.x - h.x, g = a.y - h.y, p = Math.sqrt(f * f + g * g), w = r.getPosition();
1772
- if (p < d + this.options.detectMargin) {
1773
- let b = w;
1774
- if (p > d / 2) {
1775
- const A = Rt(t, i === "end" ? "start" : "end");
1776
- b = Wt(A, b, c);
1777
- }
1778
- St(t, i, b.x, b.y), this.links.add(t, i, r.getId(), "node", b);
1779
- }
1780
- }
1781
- refreshTextLinks() {
1782
- let t = !1;
1783
- this.links.forEach(
1784
- ({ connectionPoint: i, targetType: r, target: a, arrow: h, side: c }) => {
1785
- if (r !== "text") return;
1786
- t = !0;
1787
- const d = this.getAnnotation(a), f = this.getAnnotation(h), g = ft(d), p = dt(d), w = Ut(i, { x: g.width, y: g.height }), b = nt(w, this.ogma.view.getAngle()), A = Ct(b, p);
1788
- St(f, c, A.x, A.y);
1789
- }
1790
- ), t && this.arrows.refreshLayer();
1791
- }
1792
- /**
1793
- * @returns the currently selected annotation
1794
- */
1795
- getSelected() {
1796
- return this.selected;
1797
- }
1798
- findMagnetPoint(t, i, r) {
1799
- let a;
1800
- for (const h of t) {
1801
- const c = ft(i), d = dt(i), f = Ut(h, { x: c.width, y: c.height }), g = nt(f, this.ogma.view.getAngle()), p = Ct(g, d), w = _t(xt(p, r)), b = Math.min(
1802
- this.options.magnetRadius * this.ogma.view.getZoom(),
1803
- // when really zoomed in: avoid to snap on too far away magnets
1804
- c.width / 2,
1805
- c.height / 2
1806
- );
1807
- if (w < Math.max(b, this.options.magnetHandleRadius)) {
1808
- a = {
1809
- point: p,
1810
- magnet: h
1811
- };
1812
- break;
1813
- }
1814
- }
1815
- return a;
1816
- }
1817
- /**
1818
- * Set the options for the controller
1819
- * @param options new Options
1820
- * @returns the updated options
1821
- */
1822
- setOptions(t = {}) {
1823
- return this.options = {
1824
- ...this.options || {},
1825
- ...t
1826
- }, this.options;
1827
- }
1828
- /**
1829
- * Selects the annotation with the given id
1830
- * @param id the id of the annotation to select
1831
- */
1832
- select(t) {
1833
- const i = this.getAnnotations().features.find((r) => r.id === t);
1834
- return i ? (ot(i) ? this.arrows.select(i.id) : ct(i) && this.texts.select(i.id), this) : this;
1835
- }
1836
- /**
1837
- * Unselects the currently selected annotation
1838
- */
1839
- unselect() {
1840
- return this.selected ? (ot(this.selected) ? this.arrows.unselect() : ct(this.selected) && this.texts.unselect(), this) : this;
1841
- }
1842
- /**
1843
- * Add an annotation to the controller
1844
- * @param annotation The annotation to add
1845
- */
1846
- add(t) {
1847
- if (Ue(t)) {
1848
- const [i, r] = t.features.reduce(
1849
- (a, h) => (ot(h) ? a[1].push(h) : ct(h) && a[0].push(h), a),
1850
- [[], []]
1851
- );
1852
- return i.forEach((a) => this.add(a)), r.forEach((a) => this.add(a)), this.arrows.refreshLayer(), this;
1853
- }
1854
- switch (t.properties.type) {
1855
- case "text":
1856
- this.texts.add(t);
1857
- break;
1858
- // more to follow
1859
- default:
1860
- this.arrows.add(t), this.loadLink(t);
1861
- break;
1862
- }
1863
- return this;
1864
- }
1865
- /**
1866
- * Remove an annotation or an array of annotations from the controller
1867
- * @param annotation The annotation(s) to remove
1868
- */
1869
- remove(t) {
1870
- return Ue(t) ? (t.features.forEach(
1871
- (i) => this.remove(i)
1872
- ), this) : (ot(t) ? (this.links.remove(t, "start"), this.links.remove(t, "end"), this.arrows.remove(t.id)) : this.texts.remove(t.id), this);
1873
- }
1874
- loadLink(t) {
1875
- if (t.properties.link)
1876
- for (const i of Xe) {
1877
- const r = t.properties.link[i];
1878
- if (!r) continue;
1879
- const a = this.getAnnotation(r.id);
1880
- if (r.type === "text" && a)
1881
- this.links.add(t, i, r.id, r.type, r.magnet);
1882
- else if (r.type === "node") {
1883
- const h = this.ogma.getNode(r.id);
1884
- if (!h) continue;
1885
- this.links.add(t, i, r.id, r.type, r.magnet);
1886
- const c = h.getPosition(), d = h.getAttribute("radius") || 0, f = Rt(
1887
- t,
1888
- i === "start" ? "end" : "start"
1889
- ), g = Wt(f, c, +d);
1890
- St(t, i, g.x, g.y);
1891
- }
1892
- }
1893
- }
1894
- /**
1895
- * Start adding an arrow (add it, and give control to the user)
1896
- * @param x coord of the first point
1897
- * @param y coord of the first point
1898
- * @param arrow The arrow to add
1899
- */
1900
- startArrow(t, i, r) {
1901
- this.cancelDrawing(), this.arrows.startDrawing(t, i, r);
1902
- }
1903
- /**
1904
- * Start adding a text (add it, and give control to the user)
1905
- * @param x coord of the top left point
1906
- * @param y coord of the top left point
1907
- * @param text The text to add
1908
- */
1909
- startText(t, i, r) {
1910
- this.cancelDrawing(), this.texts.startDrawing(t, i, r);
1911
- }
1912
- /**
1913
- * Cancel drawing on the current frame
1914
- */
1915
- cancelDrawing() {
1916
- this.annotations.forEach((t) => t.cancelDrawing()), this.emit(hn);
1917
- }
1918
- /**
1919
- * Update the style of the annotation with the given id
1920
- * @param id The id of the annotation to update
1921
- * @param style The new style
1922
- */
1923
- updateStyle(t, i) {
1924
- const r = this.getAnnotations().features.find((a) => a.id === t);
1925
- return r ? (ot(r) ? this.arrows.updateStyle(r, i) : ct(r) && this.texts.updateStyle(r, i), this.onUpdate(r), this) : this;
1926
- }
1927
- setScale(t, i, r, a) {
1928
- const h = this.getAnnotations().features.find((c) => c.id === t);
1929
- return h ? (ot(h) ? this.arrows.scale(h, i, r, a) : ct(h) && this.texts.scale(h, i, r, a), this.onUpdate(h), this) : this;
1930
- }
1931
- /**
1932
- * @returns the annotations in the controller
1933
- */
1934
- getAnnotations() {
1935
- const t = {
1936
- type: "FeatureCollection",
1937
- features: []
1938
- };
1939
- return this.annotations.forEach((i) => {
1940
- t.features = [...t.features, ...i.getElements()];
1941
- }), t;
1942
- }
1943
- /**
1944
- * Retrieve the annotation with the given id
1945
- * @param id the id of the annotation to get
1946
- * @returns The annotation with the given id
1947
- */
1948
- getAnnotation(t) {
1949
- return this.getAnnotations().features.find((i) => i.id === t);
1950
- }
1951
- /**
1952
- * Destroy the controller and its elements
1953
- */
1954
- destroy() {
1955
- this.annotations.forEach((t) => t.destroy()), this.layer.destroy();
1956
- }
1957
- }
1958
- const Ve = [8, 10, 12, 14, 16, 24, 32, 48, 64, 72], Ze = "none", lr = "#333333", Tn = [
1
+ import { Control as V, EVT_SELECT as B, isArrow as H, isText as N, EVT_UNSELECT as _, EVT_ADD as k, EVT_REMOVE as z, EVT_UPDATE as W, EVT_HISTORY as U } from "@linkurious/ogma-annotations";
2
+ import { createBox as ae, createComment as ce, createPolygon as le, getAnnotationsBounds as ie, isBox as ue, isComment as fe, isPolygon as Ce } from "@linkurious/ogma-annotations";
3
+ import { useOgma as I } from "@linkurious/ogma-react";
4
+ import M, { useContext as O, createContext as F, useState as a, useEffect as g } from "react";
5
+ const y = [8, 10, 12, 14, 16, 24, 32, 48, 64, 72], x = "none", S = "#333333", X = [
1959
6
  "#FFFFFF",
1960
7
  "#F44E3B",
1961
8
  "#FE9200",
@@ -1968,7 +15,7 @@ const Ve = [8, 10, 12, 14, 16, 24, 32, 48, 64, 72], Ze = "none", lr = "#333333",
1968
15
  "#333333",
1969
16
  "#808080",
1970
17
  "#cccccc"
1971
- ], $n = [
18
+ ], Z = [
1972
19
  "Roboto",
1973
20
  "Helvetica Neue",
1974
21
  "Helvetica",
@@ -1980,125 +27,132 @@ const Ve = [8, 10, 12, 14, 16, 24, 32, 48, 64, 72], Ze = "none", lr = "#333333",
1980
27
  "Consolas",
1981
28
  "Courier New",
1982
29
  "monospace"
1983
- ].sort((l, t) => l.toLocaleLowerCase().localeCompare(t.toLocaleLowerCase())), kn = {
30
+ ].sort((r, o) => r.toLocaleLowerCase().localeCompare(o.toLocaleLowerCase())), G = {
1984
31
  head: "arrow",
1985
- strokeColor: lr,
32
+ strokeColor: S,
1986
33
  strokeWidth: 5
1987
- }, En = 0.25, Sn = {
34
+ }, K = 0.25, Y = {
1988
35
  font: "Roboto",
1989
- fontSize: Ve[2],
1990
- padding: Ve[2] * En,
1991
- color: lr,
1992
- strokeType: Ze,
1993
- background: Ze
1994
- };
1995
- function Cn(l) {
1996
- return l.reduce((t, i) => t + i, 0) / l.length;
36
+ fontSize: y[2],
37
+ padding: y[2] * K,
38
+ color: S,
39
+ strokeType: x,
40
+ background: x
41
+ }, T = F(
42
+ void 0
43
+ ), $ = () => O(T);
44
+ function ee() {
45
+ return F(null);
1997
46
  }
1998
- function In(l, t = 0, i = 1) {
1999
- return t + (i - t) * l;
47
+ function j(r) {
48
+ return r.reduce((o, s) => o + s, 0) / r.length;
2000
49
  }
2001
- function Mn(l, t = 0, i = 1) {
2002
- return (l - t) / (i - t);
50
+ function te(r, o = 0, s = 1) {
51
+ return o + (s - o) * r;
2003
52
  }
2004
- function On() {
2005
- return Ye(null);
53
+ function oe(r, o = 0, s = 1) {
54
+ return (r - o) / (s - o);
2006
55
  }
2007
- const hr = Ye(
2008
- void 0
2009
- ), zn = () => Ur(hr), _n = (l, t) => {
2010
- switch (t.type) {
2011
- case "add":
2012
- return {
2013
- ...l,
2014
- features: [...l.features, t.payload]
2015
- };
2016
- case "remove":
2017
- return {
2018
- ...l,
2019
- features: l.features.filter((i) => i.id !== t.payload.id)
2020
- };
2021
- case "update":
2022
- return {
2023
- ...l,
2024
- features: l.features.map(
2025
- (i) => i.id === t.payload.id ? t.payload : i
2026
- )
2027
- };
2028
- default:
2029
- return l;
2030
- }
2031
- }, Pn = ({
2032
- children: l,
2033
- annotations: t
56
+ const ne = ({
57
+ children: r,
58
+ annotations: o
2034
59
  }) => {
2035
- const i = Gr(), [r, a] = Xr(
2036
- _n,
2037
- t || {
60
+ const s = I(), [D, i] = a(
61
+ o || {
2038
62
  type: "FeatureCollection",
2039
63
  features: []
2040
64
  }
2041
- ), [h, c] = Et(null), [d, f] = Et(kn), [g, p] = Et(Sn), [w, b] = Et(), [A, E] = Et(1), [k, L] = Et(1);
2042
- return he(() => {
2043
- if (!i) return;
2044
- const M = new An(i, {
65
+ ), [n, u] = a(null), [l, f] = a(G), [C, E] = a(Y), [e, d] = a(), [w, A] = a(1), [R, m] = a(1), [b, h] = a(!1), [P, v] = a(!1);
66
+ return g(() => {
67
+ if (!s) return;
68
+ const t = new V(s, {
2045
69
  minArrowHeight: 1
2046
- }), C = Cn(i.getNodes().getAttribute("radius")) / 5, N = A;
70
+ }), L = j(s.getNodes().getAttribute("radius")) / 5, p = w;
2047
71
  return f({
2048
- ...d,
2049
- strokeWidth: (d.strokeWidth || 1) * N
2050
- }), E(N), L(C), M.on("select", (P) => {
2051
- ot(P) ? f({
2052
- ...P.properties.style || {}
2053
- }) : ct(P) && p({
2054
- ...P.properties.style || {}
2055
- }), c(P);
2056
- }).on("unselect", () => {
2057
- c(null);
2058
- }), b(M), t && M.add(t), () => {
2059
- M.destroy();
72
+ ...l,
73
+ strokeWidth: (l.strokeWidth || 1) * p
74
+ }), A(p), m(L), t.on(B, () => {
75
+ t.getSelectedAnnotations().features.forEach((c) => {
76
+ c && (H(c) ? f({
77
+ ...c.properties.style || {}
78
+ }) : N(c) && E({
79
+ ...c.properties.style || {}
80
+ }), u(c));
81
+ });
82
+ }).on(_, () => {
83
+ u(null);
84
+ }).on(k, () => {
85
+ i(t.getAnnotations());
86
+ }).on(z, () => {
87
+ i(t.getAnnotations());
88
+ }).on(W, () => {
89
+ i(t.getAnnotations());
90
+ }).on(U, () => {
91
+ h(t.canUndo()), v(t.canRedo());
92
+ }), d(t), o && (t.add(o), t.clearHistory()), () => {
93
+ t.destroy();
2060
94
  };
2061
- }, [i]), he(() => {
2062
- w && h && (h == null ? void 0 : h.properties.type) === "arrow" && w.updateStyle(h.id, d);
2063
- }, [w, d, h]), he(() => {
2064
- w && h && (h == null ? void 0 : h.properties.type) === "text" && w.updateStyle(h.id, g);
2065
- }, [w, g, h]), /* @__PURE__ */ Wr.createElement(
2066
- hr.Provider,
95
+ }, [s]), g(() => {
96
+ e && n && (n == null ? void 0 : n.properties.type) === "arrow" && e.updateStyle(n.id, l);
97
+ }, [e, l, n]), g(() => {
98
+ e && n && (n == null ? void 0 : n.properties.type) === "text" && e.updateStyle(n.id, C);
99
+ }, [e, C, n]), /* @__PURE__ */ M.createElement(
100
+ T.Provider,
2067
101
  {
2068
102
  value: {
2069
- annotations: r,
2070
- updateAnnotations: a,
2071
- currentAnnotation: h,
2072
- setCurrentAnnotation: c,
2073
- textStyle: g,
2074
- setTextStyle: p,
2075
- arrowStyle: d,
103
+ annotations: D,
104
+ currentAnnotation: n,
105
+ setCurrentAnnotation: u,
106
+ textStyle: C,
107
+ setTextStyle: E,
108
+ arrowStyle: l,
2076
109
  setArrowStyle: f,
2077
- arrowWidthFactor: A,
2078
- setArrowWidthFactor: E,
2079
- textSizeFactor: k,
2080
- setTextSizeFactor: L,
2081
- editor: w,
2082
- setEditor: b
110
+ arrowWidthFactor: w,
111
+ setArrowWidthFactor: A,
112
+ textSizeFactor: R,
113
+ setTextSizeFactor: m,
114
+ editor: e,
115
+ setEditor: d,
116
+ // History management
117
+ canUndo: b,
118
+ canRedo: P,
119
+ undo: () => (e == null ? void 0 : e.undo()) || !1,
120
+ redo: () => (e == null ? void 0 : e.redo()) || !1,
121
+ clearHistory: () => e == null ? void 0 : e.clearHistory(),
122
+ // Annotation management
123
+ add: (t) => e == null ? void 0 : e.add(t),
124
+ remove: (t) => e == null ? void 0 : e.remove(t),
125
+ cancelDrawing: () => e == null ? void 0 : e.cancelDrawing(),
126
+ select: (t) => e == null ? void 0 : e.select(t),
127
+ // Drawing methods
128
+ enableBoxDrawing: (t) => e == null ? void 0 : e.enableBoxDrawing(t),
129
+ enablePolygonDrawing: (t) => e == null ? void 0 : e.enablePolygonDrawing(t),
130
+ enableCommentDrawing: (t) => e == null ? void 0 : e.enableCommentDrawing(t)
2083
131
  }
2084
132
  },
2085
- l
133
+ r
2086
134
  );
2087
135
  };
2088
136
  export {
2089
- hr as AnnotationsContext,
2090
- Pn as AnnotationsContextProvider,
2091
- lr as BLACK,
2092
- En as RELATIVE_PADDING,
2093
- Ze as TRANSPARENT,
2094
- On as createAnnotationsContext,
2095
- kn as defaultArrowStyle,
2096
- Tn as defaultColors,
2097
- Sn as defaultTextStyle,
2098
- Ve as fontSizes,
2099
- $n as fonts,
2100
- In as interpolate,
2101
- Cn as mean,
2102
- Mn as normalize,
2103
- zn as useAnnotationsContext
137
+ ne as AnnotationsContextProvider,
138
+ S as BLACK,
139
+ K as RELATIVE_PADDING,
140
+ x as TRANSPARENT,
141
+ ee as createAnnotationsContext,
142
+ ae as createBox,
143
+ ce as createComment,
144
+ le as createPolygon,
145
+ G as defaultArrowStyle,
146
+ X as defaultColors,
147
+ Y as defaultTextStyle,
148
+ y as fontSizes,
149
+ Z as fonts,
150
+ ie as getAnnotationsBounds,
151
+ te as interpolate,
152
+ ue as isBox,
153
+ fe as isComment,
154
+ Ce as isPolygon,
155
+ j as mean,
156
+ oe as normalize,
157
+ $ as useAnnotationsContext
2104
158
  };