@sandemo/easy-annotator 0.1.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.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +59 -0
  3. package/dist/components/AnnotatorModal.d.ts +13 -0
  4. package/dist/components/AnnotatorModal.d.ts.map +1 -0
  5. package/dist/components/EasyAnnotatorUpload.d.ts +3 -0
  6. package/dist/components/EasyAnnotatorUpload.d.ts.map +1 -0
  7. package/dist/components/FilePreviewList.d.ts +10 -0
  8. package/dist/components/FilePreviewList.d.ts.map +1 -0
  9. package/dist/components/ImageAnnotator.d.ts +17 -0
  10. package/dist/components/ImageAnnotator.d.ts.map +1 -0
  11. package/dist/components/UploadDropzone.d.ts +10 -0
  12. package/dist/components/UploadDropzone.d.ts.map +1 -0
  13. package/dist/easy-annotator.cjs +2 -0
  14. package/dist/easy-annotator.cjs.map +1 -0
  15. package/dist/easy-annotator.css +1 -0
  16. package/dist/easy-annotator.d.ts +2 -0
  17. package/dist/easy-annotator.js +709 -0
  18. package/dist/easy-annotator.js.map +1 -0
  19. package/dist/hooks/useEasyAnnotator.d.ts +29 -0
  20. package/dist/hooks/useEasyAnnotator.d.ts.map +1 -0
  21. package/dist/hooks/useObjectUrls.d.ts +5 -0
  22. package/dist/hooks/useObjectUrls.d.ts.map +1 -0
  23. package/dist/i18n/labels.d.ts +5 -0
  24. package/dist/i18n/labels.d.ts.map +1 -0
  25. package/dist/index.d.ts +12 -0
  26. package/dist/index.d.ts.map +1 -0
  27. package/dist/markerjs3-DI_cywfl.js +2669 -0
  28. package/dist/markerjs3-DI_cywfl.js.map +1 -0
  29. package/dist/markerjs3-DiaiYpgs.cjs +57 -0
  30. package/dist/markerjs3-DiaiYpgs.cjs.map +1 -0
  31. package/dist/services/defaultPayloadBuilder.d.ts +3 -0
  32. package/dist/services/defaultPayloadBuilder.d.ts.map +1 -0
  33. package/dist/styles.cjs +2 -0
  34. package/dist/styles.cjs.map +1 -0
  35. package/dist/styles.d.ts +1 -0
  36. package/dist/styles.d.ts.map +1 -0
  37. package/dist/styles.js +2 -0
  38. package/dist/styles.js.map +1 -0
  39. package/dist/types/index.d.ts +95 -0
  40. package/dist/types/index.d.ts.map +1 -0
  41. package/dist/utils/errors.d.ts +8 -0
  42. package/dist/utils/errors.d.ts.map +1 -0
  43. package/dist/utils/file.d.ts +10 -0
  44. package/dist/utils/file.d.ts.map +1 -0
  45. package/dist/utils/id.d.ts +2 -0
  46. package/dist/utils/id.d.ts.map +1 -0
  47. package/dist/utils/image.d.ts +3 -0
  48. package/dist/utils/image.d.ts.map +1 -0
  49. package/package.json +72 -0
@@ -0,0 +1,2669 @@
1
+ class r {
2
+ static createDefs() {
3
+ return document.createElementNS("http://www.w3.org/2000/svg", "defs");
4
+ }
5
+ static setAttributes(t, i) {
6
+ for (const [e, s] of i) t.setAttribute(e, s);
7
+ }
8
+ static createRect(t, i, e) {
9
+ const s = document.createElementNS("http://www.w3.org/2000/svg", "rect");
10
+ return s.setAttribute("width", t.toString()), s.setAttribute("height", i.toString()), e && r.setAttributes(s, e), s;
11
+ }
12
+ static createLine(t, i, e, s, a) {
13
+ const h = document.createElementNS("http://www.w3.org/2000/svg", "line");
14
+ return h.setAttribute("x1", t.toString()), h.setAttribute("y1", i.toString()), h.setAttribute("x2", e.toString()), h.setAttribute("y2", s.toString()), a && r.setAttributes(h, a), h;
15
+ }
16
+ static createPolygon(t, i) {
17
+ const e = document.createElementNS("http://www.w3.org/2000/svg", "polygon");
18
+ return e.setAttribute("points", t), i && r.setAttributes(e, i), e;
19
+ }
20
+ static createCircle(t, i) {
21
+ const e = document.createElementNS("http://www.w3.org/2000/svg", "circle");
22
+ return e.setAttribute("cx", (t / 2).toString()), e.setAttribute("cy", (t / 2).toString()), e.setAttribute("r", t.toString()), i && r.setAttributes(e, i), e;
23
+ }
24
+ static createEllipse(t, i, e) {
25
+ const s = document.createElementNS("http://www.w3.org/2000/svg", "ellipse");
26
+ return s.setAttribute("cx", (t / 2).toString()), s.setAttribute("cy", (i / 2).toString()), s.setAttribute("rx", (t / 2).toString()), s.setAttribute("ry", (i / 2).toString()), e && r.setAttributes(s, e), s;
27
+ }
28
+ static createGroup(t) {
29
+ const i = document.createElementNS("http://www.w3.org/2000/svg", "g");
30
+ return t && r.setAttributes(i, t), i;
31
+ }
32
+ static createTransform() {
33
+ return document.createElementNS("http://www.w3.org/2000/svg", "svg").createSVGTransform();
34
+ }
35
+ static createMarker(t, i, e, s, a, h, o) {
36
+ const n = document.createElementNS("http://www.w3.org/2000/svg", "marker");
37
+ return r.setAttributes(n, [["id", t], ["orient", i], ["markerWidth", e.toString()], ["markerHeight", s.toString()], ["refX", a.toString()], ["refY", h.toString()]]), n.appendChild(o), n;
38
+ }
39
+ static createText(t) {
40
+ const i = document.createElementNS("http://www.w3.org/2000/svg", "text");
41
+ return i.setAttribute("x", "0"), i.setAttribute("y", "0"), t && r.setAttributes(i, t), i;
42
+ }
43
+ static createTSpan(t, i) {
44
+ const e = document.createElementNS("http://www.w3.org/2000/svg", "tspan");
45
+ return e.textContent = t, i && r.setAttributes(e, i), e;
46
+ }
47
+ static createImage(t) {
48
+ const i = document.createElementNS("http://www.w3.org/2000/svg", "image");
49
+ return t && r.setAttributes(i, t), i;
50
+ }
51
+ static createPoint(t, i) {
52
+ const e = document.createElementNS("http://www.w3.org/2000/svg", "svg").createSVGPoint();
53
+ return e.x = t, e.y = i, e;
54
+ }
55
+ static createPath(t, i) {
56
+ const e = document.createElementNS("http://www.w3.org/2000/svg", "path");
57
+ return e.setAttribute("d", t), i && r.setAttributes(e, i), e;
58
+ }
59
+ static createForeignObject(t) {
60
+ const i = document.createElementNS("http://www.w3.org/2000/svg", "foreignObject");
61
+ return i.setAttribute("x", "0"), i.setAttribute("y", "0"), t && r.setAttributes(i, t), i;
62
+ }
63
+ static clientToLocalCoordinates(t, i, e, s = 1) {
64
+ if (t) {
65
+ const a = t.getBoundingClientRect();
66
+ return { x: (i - a.left) / s, y: (e - a.top) / s };
67
+ }
68
+ return { x: i, y: e };
69
+ }
70
+ static createSvgFromString(t) {
71
+ const i = document.createElementNS("http://www.w3.org/2000/svg", "svg");
72
+ return i.innerHTML = t, i;
73
+ }
74
+ static createFilter(t, i, e) {
75
+ const s = document.createElementNS("http://www.w3.org/2000/svg", "filter");
76
+ return s.id = t, i && r.setAttributes(s, i), e && (s.innerHTML = e), s;
77
+ }
78
+ }
79
+ class c {
80
+ static addKey(t, i) {
81
+ c.keys.set(t, i), c.keyAddListeners.forEach((e) => {
82
+ e();
83
+ });
84
+ }
85
+ static addKeyAddListener(t) {
86
+ c.keyAddListeners.push(t);
87
+ }
88
+ static removeKeyAddListener(t) {
89
+ const i = c.keyAddListeners.indexOf(t);
90
+ i > -1 && c.keyAddListeners.splice(i, 1);
91
+ }
92
+ static isLicensed(t) {
93
+ if (c.keys.has(t)) {
94
+ const i = new RegExp(`${t}-[A-Z][0-9]{3}-[A-Z][0-9]{3}-[0-9]{4}`, "i"), e = c.keys.get(t);
95
+ return e !== void 0 && i.test(e);
96
+ }
97
+ return !1;
98
+ }
99
+ }
100
+ c.keys = /* @__PURE__ */ new Map(), c.keyAddListeners = new Array();
101
+ class b {
102
+ get typeName() {
103
+ return Object.getPrototypeOf(this).constructor.typeName;
104
+ }
105
+ get container() {
106
+ return this._container;
107
+ }
108
+ get strokeColor() {
109
+ return this._strokeColor;
110
+ }
111
+ set strokeColor(t) {
112
+ this._strokeColor = t, this.applyStrokeColor();
113
+ }
114
+ applyStrokeColor() {
115
+ }
116
+ get fillColor() {
117
+ return this._fillColor;
118
+ }
119
+ set fillColor(t) {
120
+ this._fillColor = t, this.applyFillColor();
121
+ }
122
+ applyFillColor() {
123
+ }
124
+ get strokeWidth() {
125
+ return this._strokeWidth;
126
+ }
127
+ set strokeWidth(t) {
128
+ this._strokeWidth = t, this.applyStrokeWidth();
129
+ }
130
+ applyStrokeWidth() {
131
+ }
132
+ get strokeDasharray() {
133
+ return this._strokeDasharray;
134
+ }
135
+ set strokeDasharray(t) {
136
+ this._strokeDasharray = t, this.applyStrokeDasharray();
137
+ }
138
+ applyStrokeDasharray() {
139
+ }
140
+ get opacity() {
141
+ return this._opacity;
142
+ }
143
+ set opacity(t) {
144
+ this._opacity = t, this.applyOpacity();
145
+ }
146
+ applyOpacity() {
147
+ }
148
+ constructor(t) {
149
+ this.defaultSize = { width: 50, height: 20 }, this.stage = "normal", this._strokeColor = "transparent", this._fillColor = "transparent", this._strokeWidth = 0, this._strokeDasharray = "", this._opacity = 1, this._container = t, this.applyFillColor = this.applyFillColor.bind(this), this.applyStrokeColor = this.applyStrokeColor.bind(this), this.applyStrokeWidth = this.applyStrokeWidth.bind(this), this.applyStrokeDasharray = this.applyStrokeDasharray.bind(this), this.applyOpacity = this.applyOpacity.bind(this), this.getBBox = this.getBBox.bind(this);
150
+ }
151
+ ownsTarget(t) {
152
+ return !1;
153
+ }
154
+ dispose() {
155
+ }
156
+ addMarkerVisualToContainer(t) {
157
+ this.container.childNodes.length > 0 ? this.container.insertBefore(t, this.container.childNodes[0]) : this.container.appendChild(t);
158
+ }
159
+ getOutline() {
160
+ return "";
161
+ }
162
+ getState() {
163
+ return { typeName: Object.getPrototypeOf(this).constructor.typeName, notes: this.notes, strokeColor: this._strokeColor, strokeWidth: this._strokeWidth, strokeDasharray: this._strokeDasharray, opacity: this._opacity };
164
+ }
165
+ restoreState(t) {
166
+ var i, e, s, a;
167
+ this.notes = t.notes, this._strokeColor = (i = t.strokeColor) !== null && i !== void 0 ? i : this._strokeColor, this._strokeWidth = (e = t.strokeWidth) !== null && e !== void 0 ? e : this._strokeWidth, this._strokeDasharray = (s = t.strokeDasharray) !== null && s !== void 0 ? s : this._strokeDasharray, this._opacity = (a = t.opacity) !== null && a !== void 0 ? a : this._opacity;
168
+ }
169
+ scale(t, i) {
170
+ }
171
+ getBBox() {
172
+ return this.container.getBBox();
173
+ }
174
+ }
175
+ b.typeName = "MarkerBase", b.applyDefaultFilter = !0;
176
+ class I {
177
+ static toITransformMatrix(t) {
178
+ return { a: t.a, b: t.b, c: t.c, d: t.d, e: t.e, f: t.f };
179
+ }
180
+ static toSVGMatrix(t, i) {
181
+ return t.a = i.a, t.b = i.b, t.c = i.c, t.d = i.d, t.e = i.e, t.f = i.f, t;
182
+ }
183
+ }
184
+ class R extends b {
185
+ get centerX() {
186
+ return this.left + this.width / 2;
187
+ }
188
+ get centerY() {
189
+ return this.top + this.height / 2;
190
+ }
191
+ get visual() {
192
+ return this._visual;
193
+ }
194
+ set visual(t) {
195
+ this._visual = t;
196
+ const i = r.createTransform();
197
+ this._visual.transform.baseVal.appendItem(i);
198
+ }
199
+ constructor(t) {
200
+ super(t), this.left = 0, this.top = 0, this.width = 0, this.height = 0, this.rotationAngle = 0, this.rotatePoint = this.rotatePoint.bind(this), this.unrotatePoint = this.unrotatePoint.bind(this), this.container.transform.baseVal.appendItem(r.createTransform());
201
+ }
202
+ moveVisual(t) {
203
+ this.visual && (this.visual.style.transform = `translate(${t.x}px, ${t.y}px)`);
204
+ }
205
+ setSize() {
206
+ this.moveVisual({ x: this.left, y: this.top });
207
+ }
208
+ rotate(t) {
209
+ if (Math.abs(t.x - this.centerX) > 0.1) {
210
+ const i = Math.sign(t.x - this.centerX);
211
+ this.rotationAngle = 180 * Math.atan((t.y - this.centerY) / (t.x - this.centerX)) / Math.PI + 90 * i, this.applyRotation();
212
+ }
213
+ }
214
+ applyRotation() {
215
+ const t = this.container.transform.baseVal.getItem(0);
216
+ t.setRotate(this.rotationAngle, this.centerX, this.centerY), this.container.transform.baseVal.replaceItem(t, 0);
217
+ }
218
+ rotatePoint(t) {
219
+ if (this.rotationAngle === 0) return t;
220
+ const i = this.container.getCTM();
221
+ if (i === null) return t;
222
+ let e = r.createPoint(t.x, t.y);
223
+ return e = e.matrixTransform(i), { x: e.x, y: e.y };
224
+ }
225
+ unrotatePoint(t) {
226
+ if (this.rotationAngle === 0) return t;
227
+ let i = this.container.getCTM();
228
+ if (i === null) return t;
229
+ i = i.inverse();
230
+ let e = r.createPoint(t.x, t.y);
231
+ return e = e.matrixTransform(i), { x: e.x, y: e.y };
232
+ }
233
+ getOutline() {
234
+ return `M 0 0
235
+ H ${this.defaultSize}
236
+ V ${this.defaultSize}
237
+ H 0
238
+ V 0 Z`;
239
+ }
240
+ getState() {
241
+ return Object.assign({ left: this.left, top: this.top, width: this.width, height: this.height, rotationAngle: this.rotationAngle, visualTransformMatrix: I.toITransformMatrix(this.visual.transform.baseVal.getItem(0).matrix), containerTransformMatrix: I.toITransformMatrix(this.container.transform.baseVal.getItem(0).matrix) }, super.getState());
242
+ }
243
+ restoreState(t) {
244
+ super.restoreState(t);
245
+ const i = t;
246
+ this.left = i.left, this.top = i.top, this.width = i.width, this.height = i.height, this.rotationAngle = i.rotationAngle, this.moveVisual({ x: this.left, y: this.top }), i.visualTransformMatrix && i.containerTransformMatrix ? (this.visual.transform.baseVal.getItem(0).setMatrix(I.toSVGMatrix(this.visual.transform.baseVal.getItem(0).matrix, i.visualTransformMatrix)), this.container.transform.baseVal.getItem(0).setMatrix(I.toSVGMatrix(this.container.transform.baseVal.getItem(0).matrix, i.containerTransformMatrix))) : this.applyRotation();
247
+ }
248
+ scale(t, i) {
249
+ super.scale(t, i);
250
+ const e = this.rotatePoint({ x: this.left, y: this.top }), s = this.unrotatePoint({ x: e.x * t, y: e.y * i });
251
+ this.left = s.x, this.top = s.y, this.width = this.width * t, this.height = this.height * i;
252
+ }
253
+ getBBox() {
254
+ const t = this.rotatePoint({ x: this.left, y: this.top }), i = this.rotatePoint({ x: this.left + this.width, y: this.top }), e = this.rotatePoint({ x: this.left, y: this.top + this.height }), s = this.rotatePoint({ x: this.left + this.width, y: this.top + this.height }), a = { x: Math.min(t.x, i.x, e.x, s.x), y: Math.min(t.y, i.y, e.y, s.y) }, h = Math.max(t.x, i.x, e.x, s.x), o = Math.max(t.y, i.y, e.y, s.y);
255
+ return new DOMRect(a.x, a.y, h - a.x, o - a.y);
256
+ }
257
+ }
258
+ class j extends R {
259
+ applyStrokeColor() {
260
+ this.visual && r.setAttributes(this.visual, [["stroke", this._strokeColor]]);
261
+ }
262
+ applyStrokeWidth() {
263
+ this.visual && r.setAttributes(this.visual, [["stroke-width", this._strokeWidth.toString()]]);
264
+ }
265
+ applyStrokeDasharray() {
266
+ this.visual && r.setAttributes(this.visual, [["stroke-dasharray", this._strokeDasharray]]);
267
+ }
268
+ applyOpacity() {
269
+ this.visual && r.setAttributes(this.visual, [["opacity", this._opacity.toString()]]);
270
+ }
271
+ constructor(t) {
272
+ super(t), this.createVisual = this.createVisual.bind(this);
273
+ }
274
+ ownsTarget(t) {
275
+ return !(!super.ownsTarget(t) && t !== this.visual);
276
+ }
277
+ getPath(t = this.width, i = this.height) {
278
+ return "M0,0";
279
+ }
280
+ getOutline() {
281
+ return this.getPath(this.defaultSize.width, this.defaultSize.height);
282
+ }
283
+ createVisual() {
284
+ this.visual = r.createPath(this.getPath(), [["fill", "transparent"], ["stroke", this._strokeColor], ["stroke-width", this._strokeWidth.toString()], ["stroke-dasharray", this._strokeDasharray], ["opacity", this._opacity.toString()]]), this.addMarkerVisualToContainer(this.visual);
285
+ }
286
+ adjustVisual() {
287
+ this.visual && r.setAttributes(this.visual, [["d", this.getPath()], ["fill", "transparent"], ["stroke", this._strokeColor], ["stroke-width", this._strokeWidth.toString()], ["stroke-dasharray", this._strokeDasharray], ["opacity", this._opacity.toString()]]);
288
+ }
289
+ setSize() {
290
+ super.setSize(), this.visual && r.setAttributes(this.visual, [["d", this.getPath()]]);
291
+ }
292
+ restoreState(t) {
293
+ this.createVisual(), super.restoreState(t), this.adjustVisual();
294
+ }
295
+ scale(t, i) {
296
+ super.scale(t, i), this.strokeWidth *= (t + i) / 2, this.setSize();
297
+ }
298
+ }
299
+ j.title = "Shape outline marker";
300
+ class $ extends j {
301
+ applyFillColor() {
302
+ this.visual && r.setAttributes(this.visual, [["fill", this._fillColor]]);
303
+ }
304
+ constructor(t) {
305
+ super(t), this._fillColor = "transparent", this.createVisual = this.createVisual.bind(this);
306
+ }
307
+ createVisual() {
308
+ super.createVisual(), this.visual && r.setAttributes(this.visual, [["fill", this._fillColor]]);
309
+ }
310
+ getState() {
311
+ return Object.assign({ fillColor: this._fillColor }, super.getState());
312
+ }
313
+ restoreState(t) {
314
+ const i = t;
315
+ super.restoreState(t), this.fillColor = i.fillColor, this.setSize();
316
+ }
317
+ }
318
+ $.title = "Shape marker";
319
+ class k extends j {
320
+ constructor(t) {
321
+ super(t), this.strokeColor = "#ff0000", this.strokeWidth = 3;
322
+ }
323
+ getPath(t = this.width, i = this.height) {
324
+ return `M 0 0
325
+ H ${t}
326
+ V ${i}
327
+ H 0
328
+ V 0 Z`;
329
+ }
330
+ }
331
+ k.typeName = "FrameMarker", k.title = "Frame marker";
332
+ class et extends b {
333
+ applyStrokeColor() {
334
+ this.lineVisual && r.setAttributes(this.lineVisual, [["stroke", this._strokeColor]]), this.startTerminatorVisual && this.endTerminatorVisual && (r.setAttributes(this.startTerminatorVisual, [["stroke", this._strokeColor], ["fill", this._strokeColor]]), r.setAttributes(this.endTerminatorVisual, [["stroke", this._strokeColor], ["fill", this._strokeColor]]));
335
+ }
336
+ applyStrokeWidth() {
337
+ this.lineVisual && r.setAttributes(this.lineVisual, [["stroke-width", this._strokeWidth.toString()]]), this.selectorVisual && r.setAttributes(this.selectorVisual, [["stroke-width", Math.max(this._strokeWidth, 8).toString()]]);
338
+ }
339
+ applyStrokeDasharray() {
340
+ this.lineVisual && r.setAttributes(this.lineVisual, [["stroke-dasharray", this._strokeDasharray]]);
341
+ }
342
+ applyOpacity() {
343
+ this.visibleVisual && r.setAttributes(this.visibleVisual, [["opacity", this._opacity.toString()]]);
344
+ }
345
+ constructor(t) {
346
+ super(t), this.x1 = 0, this.y1 = 0, this.x2 = 0, this.y2 = 0, this.adjustVisual = this.adjustVisual.bind(this), this.getState = this.getState.bind(this), this.restoreState = this.restoreState.bind(this), this.scale = this.scale.bind(this);
347
+ }
348
+ ownsTarget(t) {
349
+ return !(!super.ownsTarget(t) && t !== this.visual && t !== this.selectorVisual && t !== this.visibleVisual && t !== this.lineVisual && t !== this.startTerminatorVisual && t !== this.endTerminatorVisual);
350
+ }
351
+ getPath() {
352
+ return "M0,0";
353
+ }
354
+ getStartTerminatorPath() {
355
+ return "";
356
+ }
357
+ getEndTerminatorPath() {
358
+ return "";
359
+ }
360
+ createVisual() {
361
+ this.visual = r.createGroup(), this.selectorVisual = r.createPath(this.getPath(), [["stroke", "transparent"], ["fill", "transparent"], ["stroke-width", Math.max(this.strokeWidth, 8).toString()]]), this.visibleVisual = r.createGroup([["opacity", this.opacity.toString()]]), this.lineVisual = r.createPath(this.getPath(), [["stroke", this.strokeColor], ["fill", this.strokeColor], ["stroke-width", this.strokeWidth.toString()], ["stroke-linejoin", "round"], ["stroke-dasharray", this.strokeDasharray.toString()]]), this.startTerminatorVisual = r.createPath(this.getStartTerminatorPath(), [["stroke", this.strokeColor], ["fill", this.strokeColor], ["stroke-width", this.strokeWidth.toString()], ["stroke-linejoin", "round"]]), this.endTerminatorVisual = r.createPath(this.getEndTerminatorPath(), [["stroke", this.strokeColor], ["fill", this.strokeColor], ["stroke-width", this.strokeWidth.toString()], ["stroke-linejoin", "round"]]), this.visibleVisual.appendChild(this.lineVisual), this.visibleVisual.appendChild(this.startTerminatorVisual), this.visibleVisual.appendChild(this.endTerminatorVisual), this.visual.appendChild(this.selectorVisual), this.visual.appendChild(this.visibleVisual), this.addMarkerVisualToContainer(this.visual);
362
+ }
363
+ adjustVisual() {
364
+ this.selectorVisual && this.visibleVisual && this.lineVisual && this.startTerminatorVisual && this.endTerminatorVisual && (r.setAttributes(this.selectorVisual, [["d", this.getPath()]]), r.setAttributes(this.visibleVisual, [["opacity", this.opacity.toString()]]), r.setAttributes(this.lineVisual, [["d", this.getPath()], ["stroke", this.strokeColor], ["fill", this.fillColor], ["stroke-width", this.strokeWidth.toString()], ["stroke-dasharray", this.strokeDasharray.toString()]]), r.setAttributes(this.startTerminatorVisual, [["d", this.getStartTerminatorPath()], ["stroke", this.strokeColor], ["fill", this.strokeColor], ["stroke-width", this.strokeWidth.toString()]]), r.setAttributes(this.endTerminatorVisual, [["d", this.getEndTerminatorPath()], ["stroke", this.strokeColor], ["fill", this.strokeColor], ["stroke-width", this.strokeWidth.toString()]]));
365
+ }
366
+ getState() {
367
+ return Object.assign({ x1: this.x1, y1: this.y1, x2: this.x2, y2: this.y2 }, super.getState());
368
+ }
369
+ restoreState(t) {
370
+ super.restoreState(t);
371
+ const i = t;
372
+ this.x1 = i.x1, this.y1 = i.y1, this.x2 = i.x2, this.y2 = i.y2, this.createVisual(), this.adjustVisual();
373
+ }
374
+ scale(t, i) {
375
+ super.scale(t, i), this.x1 = this.x1 * t, this.y1 = this.y1 * i, this.x2 = this.x2 * t, this.y2 = this.y2 * i, this.strokeWidth *= (t + i) / 2, this.adjustVisual();
376
+ }
377
+ }
378
+ class v extends et {
379
+ constructor(t) {
380
+ super(t), this.strokeColor = "#ff0000", this.strokeWidth = 3, this.createVisual = this.createVisual.bind(this);
381
+ }
382
+ getPath() {
383
+ return `M ${this.x1} ${this.y1} L ${this.x2} ${this.y2}`;
384
+ }
385
+ }
386
+ v.typeName = "LineMarker", v.title = "Line marker";
387
+ class f extends v {
388
+ get arrowType() {
389
+ return this._arrowType;
390
+ }
391
+ set arrowType(t) {
392
+ this._arrowType = t, this.adjustVisual();
393
+ }
394
+ constructor(t) {
395
+ super(t), this._arrowType = "end", this.getArrowProperties = this.getArrowProperties.bind(this), this.getStartTerminatorPath = this.getStartTerminatorPath.bind(this), this.getEndTerminatorPath = this.getEndTerminatorPath.bind(this);
396
+ }
397
+ getArrowProperties() {
398
+ const t = 10 + 2 * this.strokeWidth, i = Math.min(Math.max(5, 2 * this.strokeWidth), this.strokeWidth + 5), e = this.x2 - this.x1, s = this.y2 - this.y1;
399
+ return { arrowHeight: t, arrowDipFactor: 0.7, angle: Math.atan2(s, e), arrowWidth: i };
400
+ }
401
+ getStartTerminatorPath() {
402
+ const { arrowHeight: t, arrowDipFactor: i, angle: e, arrowWidth: s } = this.getArrowProperties(), a = this.x1 + t * i * Math.cos(e), h = this.y1 + t * i * Math.sin(e), o = this.x1 + t * Math.cos(e), n = this.y1 + t * Math.sin(e), l = o + s * Math.sin(e), u = n - s * Math.cos(e), p = o - s * Math.sin(e), _ = n + s * Math.cos(e);
403
+ return this.arrowType === "start" || this.arrowType === "both" ? `M ${a} ${h}
404
+ L ${l} ${u} L ${this.x1} ${this.y1} L ${p} ${_} L ${a} ${h}
405
+ L ${a} ${h}` : "";
406
+ }
407
+ getEndTerminatorPath() {
408
+ const { arrowHeight: t, arrowDipFactor: i, angle: e, arrowWidth: s } = this.getArrowProperties(), a = this.x2 - t * i * Math.cos(e), h = this.y2 - t * i * Math.sin(e), o = this.x2 - t * Math.cos(e), n = this.y2 - t * Math.sin(e), l = o + s * Math.sin(e), u = n - s * Math.cos(e), p = o - s * Math.sin(e), _ = n + s * Math.cos(e);
409
+ return this.arrowType === "end" || this.arrowType === "both" ? `M ${a} ${h}
410
+ L ${l} ${u} L ${this.x2} ${this.y2} L ${p} ${_} L ${a} ${h} Z` : "";
411
+ }
412
+ applyStrokeWidth() {
413
+ super.applyStrokeWidth(), this.adjustVisual();
414
+ }
415
+ getState() {
416
+ const t = Object.assign({ arrowType: this.arrowType }, super.getState());
417
+ return t.typeName = f.typeName, t;
418
+ }
419
+ restoreState(t) {
420
+ const i = t;
421
+ this.arrowType = i.arrowType, super.restoreState(t);
422
+ }
423
+ }
424
+ f.typeName = "ArrowMarker", f.title = "Arrow marker";
425
+ class M extends v {
426
+ constructor(t) {
427
+ super(t);
428
+ }
429
+ getStartTerminatorPath() {
430
+ const { tipLength: t, angle: i } = this.getTerminatorProperties();
431
+ return `M ${this.x1 + t * Math.sin(i)} ${this.y1 - t * Math.cos(i)}
432
+ L ${this.x1 - t * Math.sin(i)} ${this.y1 + t * Math.cos(i)}`;
433
+ }
434
+ getEndTerminatorPath() {
435
+ const { tipLength: t, angle: i } = this.getTerminatorProperties();
436
+ return `M ${this.x2 + t * Math.sin(i)} ${this.y2 - t * Math.cos(i)} L ${this.x2 - t * Math.sin(i)} ${this.y2 + t * Math.cos(i)}`;
437
+ }
438
+ getTerminatorProperties() {
439
+ const t = 5 + 3 * this.strokeWidth, i = this.x2 - this.x1, e = this.y2 - this.y1;
440
+ return { tipLength: t, angle: Math.atan2(e, i) };
441
+ }
442
+ applyStrokeWidth() {
443
+ super.applyStrokeWidth(), this.adjustVisual();
444
+ }
445
+ }
446
+ M.typeName = "MeasurementMarker", M.title = "Measurement marker";
447
+ class x extends b {
448
+ applyStrokeColor() {
449
+ this.visibleVisual && r.setAttributes(this.visibleVisual, [["stroke", this._strokeColor]]);
450
+ }
451
+ applyFillColor() {
452
+ this.visibleVisual && r.setAttributes(this.visibleVisual, [["fill", this._fillColor]]);
453
+ }
454
+ applyStrokeWidth() {
455
+ this.visibleVisual && r.setAttributes(this.visibleVisual, [["stroke-width", this._strokeWidth.toString()]]), this.selectorVisual && r.setAttributes(this.selectorVisual, [["stroke-width", Math.max(this._strokeWidth, 8).toString()]]);
456
+ }
457
+ applyStrokeDasharray() {
458
+ this.visibleVisual && r.setAttributes(this.visibleVisual, [["stroke-dasharray", this._strokeDasharray]]);
459
+ }
460
+ applyOpacity() {
461
+ this.visibleVisual && r.setAttributes(this.visibleVisual, [["opacity", this._opacity.toString()]]);
462
+ }
463
+ constructor(t) {
464
+ super(t), this.points = [], this.selectorVisualLines = [], this.strokeColor = "#ff0000", this.strokeWidth = 3, this.createVisual = this.createVisual.bind(this), this.adjustVisual = this.adjustVisual.bind(this), this.getState = this.getState.bind(this), this.restoreState = this.restoreState.bind(this), this.scale = this.scale.bind(this);
465
+ }
466
+ ownsTarget(t) {
467
+ return !(!super.ownsTarget(t) && t !== this.visual && t !== this.selectorVisual && t !== this.visibleVisual && !this.selectorVisualLines.some((i) => i === t));
468
+ }
469
+ getPath() {
470
+ return this.points.length > 1 ? this.points.map((t, i) => `${i === 0 ? "M" : "L"}${t.x},${t.y}`).join(" ") + (this.stage !== "creating" ? " Z" : "") : "M0,0";
471
+ }
472
+ createVisual() {
473
+ this.visual = r.createGroup(), this.visibleVisual = r.createPath(this.getPath(), [["stroke", this.strokeColor], ["fill", this.fillColor], ["stroke-width", this.strokeWidth.toString()], ["opacity", this.opacity.toString()]]), this.visual.appendChild(this.visibleVisual), this.createSelectorVisual(), this.addMarkerVisualToContainer(this.visual);
474
+ }
475
+ createSelectorVisual() {
476
+ this.visual && (this.selectorVisual = r.createGroup(), this.visual.appendChild(this.selectorVisual), this.points.forEach(() => {
477
+ this.addSelectorLine();
478
+ }));
479
+ }
480
+ adjustVisual() {
481
+ this.selectorVisual && this.visibleVisual && (r.setAttributes(this.visibleVisual, [["d", this.getPath()], ["stroke", this.strokeColor], ["stroke-width", this.strokeWidth.toString()], ["stroke-dasharray", this.strokeDasharray.toString()], ["fill", this.fillColor], ["opacity", this.opacity.toString()]]), this.adjustSelectorVisual());
482
+ }
483
+ adjustSelectorVisual() {
484
+ if (this.selectorVisual) {
485
+ const t = this.points.length - this.selectorVisualLines.length;
486
+ if (t > 0) for (let i = 0; i < t; i++) this.addSelectorLine();
487
+ else if (t < 0) for (let i = 0; i < -t; i++) this.selectorVisual.removeChild(this.selectorVisualLines.pop());
488
+ this.selectorVisualLines.forEach((i, e) => {
489
+ r.setAttributes(i, [["x1", this.points[e].x.toString()], ["y1", this.points[e].y.toString()], ["x2", this.points[(e + 1) % this.points.length].x.toString()], ["y2", this.points[(e + 1) % this.points.length].y.toString()]]);
490
+ });
491
+ }
492
+ }
493
+ addSelectorLine() {
494
+ const t = r.createLine(0, 0, 0, 0, [["stroke", "transparent"], ["stroke-width", Math.max(this.strokeWidth, 8).toString()]]);
495
+ this.selectorVisual.appendChild(t), this.selectorVisualLines.push(t);
496
+ }
497
+ getState() {
498
+ const t = Object.assign({ points: this.points, fillColor: this.fillColor }, super.getState());
499
+ return t.typeName = x.typeName, t;
500
+ }
501
+ restoreState(t) {
502
+ super.restoreState(t);
503
+ const i = t;
504
+ this.points = i.points, i.fillColor !== void 0 && (this.fillColor = i.fillColor), this.createVisual(), this.adjustVisual();
505
+ }
506
+ scale(t, i) {
507
+ super.scale(t, i), this.points.forEach((e) => {
508
+ e.x = e.x * t, e.y = e.y * i;
509
+ }), this.adjustVisual();
510
+ }
511
+ }
512
+ x.typeName = "PolygonMarker", x.title = "Polygon marker";
513
+ class y extends b {
514
+ applyStrokeColor() {
515
+ this.visibleVisual && r.setAttributes(this.visibleVisual, [["stroke", this._strokeColor]]);
516
+ }
517
+ applyStrokeWidth() {
518
+ this.visibleVisual && r.setAttributes(this.visibleVisual, [["stroke-width", this._strokeWidth.toString()]]), this.selectorVisual && r.setAttributes(this.selectorVisual, [["stroke-width", Math.max(this._strokeWidth, 8).toString()]]);
519
+ }
520
+ applyStrokeDasharray() {
521
+ this.visibleVisual && r.setAttributes(this.visibleVisual, [["stroke-dasharray", this._strokeDasharray]]);
522
+ }
523
+ applyOpacity() {
524
+ this.visibleVisual && r.setAttributes(this.visibleVisual, [["opacity", this._opacity.toString()]]);
525
+ }
526
+ constructor(t) {
527
+ super(t), this.points = [], this.strokeColor = "#ff0000", this.strokeWidth = 3, this.createVisual = this.createVisual.bind(this), this.adjustVisual = this.adjustVisual.bind(this), this.getState = this.getState.bind(this), this.restoreState = this.restoreState.bind(this), this.scale = this.scale.bind(this);
528
+ }
529
+ ownsTarget(t) {
530
+ return !(!super.ownsTarget(t) && t !== this.visual && t !== this.selectorVisual && t !== this.visibleVisual);
531
+ }
532
+ getPath() {
533
+ return this.points.length > 1 ? this.points.map((t, i) => `${i === 0 ? "M" : "L"}${t.x},${t.y}`).join(" ") : "M0,0";
534
+ }
535
+ createVisual() {
536
+ this.visual = r.createGroup(), this.selectorVisual = r.createPath(this.getPath(), [["stroke", "transparent"], ["fill", "transparent"], ["stroke-width", Math.max(this.strokeWidth, 8).toString()]]), this.visibleVisual = r.createPath(this.getPath(), [["stroke", this.strokeColor], ["fill", "transparent"], ["stroke-width", this.strokeWidth.toString()], ["opacity", this.opacity.toString()]]), this.visual.appendChild(this.selectorVisual), this.visual.appendChild(this.visibleVisual), this.addMarkerVisualToContainer(this.visual);
537
+ }
538
+ adjustVisual() {
539
+ if (this.selectorVisual && this.visibleVisual) {
540
+ const t = this.getPath();
541
+ r.setAttributes(this.selectorVisual, [["d", t]]), r.setAttributes(this.visibleVisual, [["d", t]]), r.setAttributes(this.visibleVisual, [["stroke", this.strokeColor], ["stroke-width", this.strokeWidth.toString()], ["stroke-dasharray", this.strokeDasharray.toString()], ["stroke-dasharray", this.strokeDasharray.toString()], ["opacity", this.opacity.toString()]]);
542
+ }
543
+ }
544
+ getState() {
545
+ return Object.assign({ points: this.points }, super.getState());
546
+ }
547
+ restoreState(t) {
548
+ super.restoreState(t);
549
+ const i = t;
550
+ this.points = i.points, this.createVisual(), this.adjustVisual();
551
+ }
552
+ scale(t, i) {
553
+ super.scale(t, i), this.points.forEach((e) => {
554
+ e.x = e.x * t, e.y = e.y * i;
555
+ }), this.adjustVisual();
556
+ }
557
+ }
558
+ function Q(d, t, i, e) {
559
+ return new (i || (i = Promise))(function(s, a) {
560
+ function h(l) {
561
+ try {
562
+ n(e.next(l));
563
+ } catch (u) {
564
+ a(u);
565
+ }
566
+ }
567
+ function o(l) {
568
+ try {
569
+ n(e.throw(l));
570
+ } catch (u) {
571
+ a(u);
572
+ }
573
+ }
574
+ function n(l) {
575
+ var u;
576
+ l.done ? s(l.value) : (u = l.value, u instanceof i ? u : new i(function(p) {
577
+ p(u);
578
+ })).then(h, o);
579
+ }
580
+ n((e = e.apply(d, [])).next());
581
+ });
582
+ }
583
+ y.typeName = "FreehandMarker", y.title = "Freehand marker", y.applyDefaultFilter = !1, typeof SuppressedError == "function" && SuppressedError;
584
+ class st {
585
+ get text() {
586
+ return this._text;
587
+ }
588
+ set text(t) {
589
+ this._text = t, this.renderText();
590
+ }
591
+ get boundingBox() {
592
+ return this._boundingBox;
593
+ }
594
+ set boundingBox(t) {
595
+ this._boundingBox = t, this.renderText();
596
+ }
597
+ get labelBackground() {
598
+ return this._labelBackground;
599
+ }
600
+ get textElement() {
601
+ return this._textElement;
602
+ }
603
+ set color(t) {
604
+ this.textElement && r.setAttributes(this._textElement, [["fill", t]]), this._color = t;
605
+ }
606
+ get color() {
607
+ return this._color;
608
+ }
609
+ get fontFamily() {
610
+ return this._fontFamily;
611
+ }
612
+ set fontFamily(t) {
613
+ this._textElement && (this._textElement.style.fontFamily = t), this._fontFamily = t, this.positionText();
614
+ }
615
+ get fontSize() {
616
+ return this._fontSize;
617
+ }
618
+ set fontSize(t) {
619
+ this._textElement && (this._textElement.style.fontSize = `${t.value}${t.units}`), this._fontSize = t, this.positionText();
620
+ }
621
+ constructor(t) {
622
+ this._text = "", this.offsetX = 0, this.offsetY = 0, this._boundingBox = new DOMRect(), this._labelBackground = r.createRect(10, 10, [["fill", "white"]]), this._textElement = r.createText(), this._color = "transparent", this._fontFamily = "", this._fontSize = { value: 1, units: "rem", step: 0.1 }, this.wordWrap = !1, this.prevWrappedText = "", this.setupTextElement(), t !== void 0 && (this.text = t), this.setupTextElement = this.setupTextElement.bind(this), this.renderText = this.renderText.bind(this), this.positionText = this.positionText.bind(this), this.ownsTarget = this.ownsTarget.bind(this), this.show = this.show.bind(this), this.hide = this.hide.bind(this), this.showControlBox = this.showControlBox.bind(this), this.hideControlBox = this.hideControlBox.bind(this), this.applyFontStyles = this.applyFontStyles.bind(this), this.wrapText = this.wrapText.bind(this);
623
+ }
624
+ ownsTarget(t) {
625
+ if (t === this._textElement) return !0;
626
+ {
627
+ let i = !1;
628
+ return this._textElement.childNodes.forEach((e) => {
629
+ e === t && (i = !0);
630
+ }), i;
631
+ }
632
+ }
633
+ setupTextElement() {
634
+ this._textElement.style.fontSize = `${this.fontSize.value}${this.fontSize.units}`, this._textElement.style.textAnchor = "middle", this._textElement.style.userSelect = "none", this._labelBackground.style.stroke = "#aaa", this._labelBackground.style.strokeDasharray = "2 2", this._labelBackground.style.strokeWidth = "1", this._labelBackground.style.strokeOpacity = "0";
635
+ }
636
+ wrapText() {
637
+ function t(i) {
638
+ let e = i[0].length;
639
+ return i.forEach((s) => {
640
+ s.length > e && (e = s.length);
641
+ }), 0.35 * e / i.length;
642
+ }
643
+ if (this.text !== "") {
644
+ const i = this.text.split(/\r\n|[\n\v\f\r\x85\u2028\u2029]/), e = 1 * this.boundingBox.width / this.boundingBox.height;
645
+ let s = new Array(...i), a = t(s), h = Number.MAX_VALUE;
646
+ for (; a > e; ) {
647
+ let o = s[0];
648
+ s.forEach((n) => {
649
+ n.length > o.length && (o = n);
650
+ }), h = o.lastIndexOf(" ", h - 1), h > 0 ? (s = [], i.forEach((n) => {
651
+ let l = n;
652
+ for (; l.length > h; ) {
653
+ let u = l.lastIndexOf(" ", h);
654
+ u < 0 && (u = l.indexOf(" ")), u > 0 ? (s.push(l.substring(0, u)), l = l.substring(u).trim()) : (s.push(l), l = "");
655
+ }
656
+ s.push(l);
657
+ }), a = t(s)) : a = -1;
658
+ }
659
+ return s.join(`\r
660
+ `);
661
+ }
662
+ return this.text;
663
+ }
664
+ renderText() {
665
+ return Q(this, void 0, void 0, function* () {
666
+ if (this._textElement) {
667
+ const t = this.wordWrap ? this.wrapText() : this.text;
668
+ if (this.prevWrappedText === t) return void this.positionText();
669
+ for (this.prevWrappedText = t; this._textElement.lastChild; ) this._textElement.removeChild(this._textElement.lastChild);
670
+ t.split(/\r\n|[\n\v\f\r\x85\u2028\u2029]/).forEach((i, e) => {
671
+ this._textElement.appendChild(r.createTSpan(i.trim() === "" ? " " : i.trim(), [["dy", e > 0 ? "1em" : "0"]]));
672
+ }), this.textElement.style.opacity = "0", yield new Promise((i) => requestAnimationFrame(i)), this.positionText(this);
673
+ }
674
+ });
675
+ }
676
+ applyFontStyles() {
677
+ this._textElement.childNodes.forEach((t) => {
678
+ const i = t;
679
+ i.style.fontFamily = this._textElement.style.fontFamily, i.style.fontSize = this._textElement.style.fontSize;
680
+ });
681
+ }
682
+ get textSize() {
683
+ return this._textSize;
684
+ }
685
+ positionText(t) {
686
+ const i = t === void 0 ? this : t;
687
+ i.applyFontStyles(), i._textSize = i._textElement.getBBox();
688
+ const e = i.boundingBox.x + i._textSize.width / 2 + i.offsetX, s = i._textElement.childNodes.length, a = i._textSize.height / s, h = s > 1 ? -a * (s - 2) / 2 : a / 3, o = i.boundingBox.y + i._textSize.height / 2 + h + i.offsetY;
689
+ i._textElement.childNodes.forEach((l, u) => {
690
+ const p = l;
691
+ r.setAttributes(p, [["x", `${e}`], ["dy", u > 0 ? "1em" : "0"]]);
692
+ }), r.setAttributes(i._textElement, [["x", `${e}`]]), r.setAttributes(i._textElement, [["y", `${o}`]]), i._textSize = i._textElement.getBBox();
693
+ const n = 1.2;
694
+ r.setAttributes(i.labelBackground, [["width", (i._textSize.width * n).toString()], ["height", (i._textSize.height * n).toString()], ["x", (e - i._textSize.width * n / 2).toString()], ["y", (i._textSize.y - n).toString()]]), i.onTextSizeChanged && i.onTextSizeChanged(i), this.textElement.style.opacity = "1";
695
+ }
696
+ show() {
697
+ this._textElement.style.display = "", this._labelBackground.style.display = "";
698
+ }
699
+ hide() {
700
+ this._textElement.style.display = "none", this._labelBackground.style.display = "none";
701
+ }
702
+ showControlBox() {
703
+ this.labelBackground.style.strokeOpacity = "1";
704
+ }
705
+ hideControlBox() {
706
+ this.labelBackground.style.strokeOpacity = "0";
707
+ }
708
+ }
709
+ class m extends R {
710
+ get color() {
711
+ return this._color;
712
+ }
713
+ set color(t) {
714
+ this._color = t, this.textBlock.color = t;
715
+ }
716
+ get fontFamily() {
717
+ return this._fontFamily;
718
+ }
719
+ set fontFamily(t) {
720
+ this._fontFamily = t, this.textBlock.fontFamily = t;
721
+ }
722
+ get fontSize() {
723
+ return this._fontSize;
724
+ }
725
+ set fontSize(t) {
726
+ this._fontSize = t, this.textBlock.fontSize = t;
727
+ }
728
+ getDefaultText() {
729
+ return Object.getPrototypeOf(this).constructor.DEFAULT_TEXT;
730
+ }
731
+ get text() {
732
+ return this.textBlock.text;
733
+ }
734
+ set text(t) {
735
+ this._text = t, this.textBlock.text = this._text;
736
+ }
737
+ constructor(t) {
738
+ super(t), this._color = "black", this._fontFamily = "Helvetica, Arial, sans-serif", this._fontSize = { value: 1, units: "rem", step: 0.1 }, this._text = this.getDefaultText(), this.padding = 2, this.textBlock = new st(this.getDefaultText()), this.setColor = this.setColor.bind(this), this.setFont = this.setFont.bind(this), this.setFontSize = this.setFontSize.bind(this), this.setSize = this.setSize.bind(this), this.textSizeChanged = this.textSizeChanged.bind(this), this.setSizeFromTextSize = this.setSizeFromTextSize.bind(this), this.createVisual = this.createVisual.bind(this), this.adjustVisual = this.adjustVisual.bind(this), this.textBoundingBox = new DOMRect();
739
+ }
740
+ applyOpacity() {
741
+ this.visual && r.setAttributes(this.visual, [["opacity", this.opacity.toString()]]);
742
+ }
743
+ createVisual() {
744
+ this.textBlock.fontFamily = this.fontFamily, this.textBlock.fontSize = this.fontSize, this.textBlock.color = this.color, this.textBlock.offsetX = this.padding, this.textBlock.offsetY = this.padding, this.textBlock.onTextSizeChanged = this.textSizeChanged, this.visual = r.createGroup(), r.setAttributes(this.visual, [["opacity", this._opacity.toString()]]), this.visual.appendChild(this.textBlock.textElement), this.addMarkerVisualToContainer(this.visual), this.textBlock.text = this._text;
745
+ }
746
+ adjustVisual() {
747
+ this.visual && r.setAttributes(this.visual, [["opacity", this._opacity.toString()]]), this.setSize();
748
+ }
749
+ ownsTarget(t) {
750
+ return !(!super.ownsTarget(t) && t !== this.visual && !this.textBlock.ownsTarget(t));
751
+ }
752
+ setTextBoundingBox() {
753
+ this.textBoundingBox.x = this.padding, this.textBoundingBox.y = this.padding, this.textBoundingBox.width = Number.MAX_VALUE, this.textBoundingBox.height = Number.MAX_VALUE;
754
+ }
755
+ setSize() {
756
+ const [t, i] = [this.width, this.height];
757
+ super.setSize(), this.setSizeFromTextSize(), t === this.width && i === this.height || !this.onSizeChanged || this.onSizeChanged(this), this.setTextBoundingBox();
758
+ }
759
+ setSizeFromTextSize() {
760
+ this.textBlock.textSize && (this.width = this.textBlock.textSize.width + 2 * this.padding, this.height = this.textBlock.textSize.height + 2 * this.padding), this.textBlock.offsetX = this.padding, this.textBlock.offsetY = this.padding;
761
+ }
762
+ textSizeChanged() {
763
+ this.adjustVisual();
764
+ }
765
+ setColor(t) {
766
+ this.color = t;
767
+ }
768
+ setFont(t) {
769
+ this.fontFamily = t;
770
+ }
771
+ setFontSize(t) {
772
+ this.fontSize = t;
773
+ }
774
+ hideVisual() {
775
+ this.visual && (this.visual.style.visibility = "hidden");
776
+ }
777
+ showVisual() {
778
+ this.visual && (this.visual.style.visibility = "visible", this.textBlock.renderText());
779
+ }
780
+ getState() {
781
+ return Object.assign({ color: this.color, fontFamily: this.fontFamily, fontSize: this.fontSize, text: this.text, padding: this.padding }, super.getState());
782
+ }
783
+ restoreState(t) {
784
+ const i = t;
785
+ this.color = i.color, this.fontFamily = i.fontFamily, this.fontSize = i.fontSize, this.text = i.text, i.padding !== void 0 && (this.padding = i.padding), this.createVisual(), super.restoreState(t), this.adjustVisual();
786
+ }
787
+ scale(t, i) {
788
+ super.scale(t, i);
789
+ const e = Object.assign(Object.assign({}, this.fontSize), { value: this.fontSize.value * Math.min(t, i) });
790
+ this.fontSize = e, this.padding = this.padding * Math.min(t, i), this.adjustVisual();
791
+ }
792
+ }
793
+ m.typeName = "TextMarker", m.title = "Text marker", m.DEFAULT_TEXT = "Text";
794
+ class C extends $ {
795
+ constructor(t) {
796
+ super(t), this.fillColor = "#000000", this.strokeColor = "transparent", this.strokeWidth = 0;
797
+ }
798
+ getPath(t = this.width, i = this.height) {
799
+ return `M 0 0
800
+ H ${t}
801
+ V ${i}
802
+ H 0
803
+ V 0 Z`;
804
+ }
805
+ }
806
+ C.typeName = "CoverMarker", C.title = "Cover marker", C.applyDefaultFilter = !1;
807
+ class S extends $ {
808
+ constructor(t) {
809
+ super(t), this.fillColor = "#ffff00", this.opacity = 0.5, this.strokeColor = "transparent", this.strokeWidth = 0;
810
+ }
811
+ getPath(t = this.width, i = this.height) {
812
+ return `M 0 0
813
+ H ${t}
814
+ V ${i}
815
+ H 0
816
+ V 0 Z`;
817
+ }
818
+ }
819
+ S.typeName = "HighlightMarker", S.title = "Highlight marker", S.applyDefaultFilter = !1;
820
+ class T extends m {
821
+ get tipPosition() {
822
+ return this._tipPosition;
823
+ }
824
+ set tipPosition(t) {
825
+ this._tipPosition = t, this.adjustVisual();
826
+ }
827
+ constructor(t) {
828
+ super(t), this._tipPosition = { x: 0, y: 0 }, this.tipBase1Position = { x: 0, y: 0 }, this.tipBase2Position = { x: 0, y: 0 }, this._calloutVisual = r.createPath("M0,0"), this.color = "#ffffff", this.fillColor = "#ff0000", this.strokeColor = "#ffffff", this.strokeWidth = 3, this.padding = 20, this.createVisual = this.createVisual.bind(this), this.adjustVisual = this.adjustVisual.bind(this), this.getPath = this.getPath.bind(this), this.setTipPoints = this.setTipPoints.bind(this);
829
+ }
830
+ applyStrokeColor() {
831
+ r.setAttributes(this._calloutVisual, [["stroke", this._strokeColor]]);
832
+ }
833
+ applyStrokeWidth() {
834
+ r.setAttributes(this._calloutVisual, [["stroke-width", this._strokeWidth.toString()]]);
835
+ }
836
+ applyStrokeDasharray() {
837
+ r.setAttributes(this._calloutVisual, [["stroke-dasharray", this._strokeDasharray]]);
838
+ }
839
+ applyOpacity() {
840
+ this.visual && r.setAttributes(this.visual, [["opacity", this._opacity.toString()]]);
841
+ }
842
+ applyFillColor() {
843
+ r.setAttributes(this._calloutVisual, [["fill", this._fillColor]]);
844
+ }
845
+ getPath() {
846
+ return this.setTipPoints(), `M 5 0
847
+ ${this.tipBase1Position.y === 0 ? `H ${this.tipBase1Position.x} L ${this.tipPosition.x} ${this.tipPosition.y} L ${this.tipBase2Position.x} 0` : ""}
848
+ H ${this.width - 5}
849
+ A 5 5 0 0 1 ${this.width} 5
850
+ ${this.tipBase1Position.x === this.width ? `V ${this.tipBase1Position.y} L ${this.tipPosition.x} ${this.tipPosition.y} L ${this.tipBase2Position.x} ${this.tipBase2Position.y}` : ""}
851
+ V ${this.height - 5}
852
+ A 5 5 0 0 1 ${this.width - 5} ${this.height}
853
+ ${this.tipBase1Position.y === this.height ? `H ${this.tipBase2Position.x} L ${this.tipPosition.x} ${this.tipPosition.y} L ${this.tipBase1Position.x} ${this.height}` : ""}
854
+ H 5
855
+ A 5 5 0 0 1 0 ${this.height - 5}
856
+ ${this.tipBase1Position.x === 0 ? `V ${this.tipBase2Position.y} L ${this.tipPosition.x} ${this.tipPosition.y} L ${this.tipBase1Position.x} ${this.tipBase1Position.y}` : ""}
857
+ V 5
858
+ A 5 5 0 0 1 5 0
859
+ Z`;
860
+ }
861
+ setTipPoints() {
862
+ let t = Math.min(this.height / 2, 15), i = this.height / 5;
863
+ const e = Math.atan(this.height / 2 / (this.width / 2));
864
+ this.tipPosition.x < this.width / 2 && this.tipPosition.y < this.height / 2 ? e < Math.atan((this.height / 2 - this.tipPosition.y) / (this.width / 2 - this.tipPosition.x)) ? (i = this.width / 5, t = Math.min(this.width / 2, 15), this.tipBase1Position = { x: t, y: 0 }, this.tipBase2Position = { x: t + i, y: 0 }) : (this.tipBase1Position = { x: 0, y: t }, this.tipBase2Position = { x: 0, y: t + i }) : this.tipPosition.x >= this.width / 2 && this.tipPosition.y < this.height / 2 ? e < Math.atan((this.height / 2 - this.tipPosition.y) / (this.tipPosition.x - this.width / 2)) ? (i = this.width / 5, t = Math.min(this.width / 2, 15), this.tipBase1Position = { x: this.width - t - i, y: 0 }, this.tipBase2Position = { x: this.width - t, y: 0 }) : (this.tipBase1Position = { x: this.width, y: t }, this.tipBase2Position = { x: this.width, y: t + i }) : this.tipPosition.x >= this.width / 2 && this.tipPosition.y >= this.height / 2 ? e < Math.atan((this.tipPosition.y - this.height / 2) / (this.tipPosition.x - this.width / 2)) ? (i = this.width / 5, t = Math.min(this.width / 2, 15), this.tipBase1Position = { x: this.width - t - i, y: this.height }, this.tipBase2Position = { x: this.width - t, y: this.height }) : (this.tipBase1Position = { x: this.width, y: this.height - t - i }, this.tipBase2Position = { x: this.width, y: this.height - t }) : e < Math.atan((this.tipPosition.y - this.height / 2) / (this.width / 2 - this.tipPosition.x)) ? (i = this.width / 5, t = Math.min(this.width / 2, 15), this.tipBase1Position = { x: t, y: this.height }, this.tipBase2Position = { x: t + i, y: this.height }) : (this.tipBase1Position = { x: 0, y: this.height - t - i }, this.tipBase2Position = { x: 0, y: this.height - t });
865
+ }
866
+ createVisual() {
867
+ var t;
868
+ super.createVisual(), this._tipPosition = { x: this.width / 4, y: this.height + 20 }, this._calloutVisual = r.createPath(this.getPath(), [["fill", this._fillColor], ["stroke", this._strokeColor], ["stroke-width", this._strokeWidth.toString()], ["stroke-dasharray", this._strokeDasharray]]), (t = this.visual) === null || t === void 0 || t.insertBefore(this._calloutVisual, this.textBlock.textElement);
869
+ }
870
+ adjustVisual() {
871
+ super.adjustVisual(), this._calloutVisual && r.setAttributes(this._calloutVisual, [["d", this.getPath()], ["fill", this._fillColor], ["stroke", this._strokeColor], ["stroke-width", this._strokeWidth.toString()], ["stroke-dasharray", this._strokeDasharray]]);
872
+ }
873
+ ownsTarget(t) {
874
+ return !(!super.ownsTarget(t) && this._calloutVisual !== t);
875
+ }
876
+ getState() {
877
+ return Object.assign({ fillColor: this.fillColor, tipPosition: this.tipPosition }, super.getState());
878
+ }
879
+ restoreState(t) {
880
+ const i = t;
881
+ super.restoreState(t), this.fillColor = i.fillColor, this.tipPosition = i.tipPosition, this.adjustVisual();
882
+ }
883
+ scale(t, i) {
884
+ super.scale(t, i), this.strokeWidth *= (t + i) / 2, this._tipPosition = { x: this._tipPosition.x * t, y: this._tipPosition.y * i }, this.adjustVisual();
885
+ }
886
+ }
887
+ T.typeName = "CalloutMarker", T.title = "Callout marker";
888
+ class P extends j {
889
+ constructor(t) {
890
+ super(t), this.strokeColor = "#ff0000", this.strokeWidth = 3;
891
+ }
892
+ getPath(t = this.width, i = this.height) {
893
+ return `M ${t / 2} 0
894
+ a ${t / 2} ${i / 2} 0 1 0 0 ${i}
895
+ a ${t / 2} ${i / 2} 0 1 0 0 -${i} z`;
896
+ }
897
+ }
898
+ P.typeName = "EllipseFrameMarker", P.title = "Ellipse frame marker";
899
+ class V extends $ {
900
+ constructor(t) {
901
+ super(t), this.fillColor = "#ff0000", this.strokeColor = "#ff0000";
902
+ }
903
+ getPath(t = this.width, i = this.height) {
904
+ return `M ${t / 2} 0
905
+ a ${t / 2} ${i / 2} 0 1 0 0 ${i}
906
+ a ${t / 2} ${i / 2} 0 1 0 0 -${i} z`;
907
+ }
908
+ }
909
+ V.typeName = "EllipseMarker", V.title = "Ellipse marker";
910
+ class F extends R {
911
+ get svgString() {
912
+ return this._svgString;
913
+ }
914
+ set svgString(t) {
915
+ this._svgString = t, this.SVGImage && this.imageType === "svg" && (this.SVGImage.outerHTML = t !== void 0 ? t : "");
916
+ }
917
+ get imageSrc() {
918
+ return this._imageSrc;
919
+ }
920
+ set imageSrc(t) {
921
+ this._imageSrc = t, this.SVGImage && this.imageType === "bitmap" && (t !== void 0 ? r.setAttributes(this.SVGImage, [["href", t]]) : r.setAttributes(this.SVGImage, [["href", ""]]));
922
+ }
923
+ constructor(t) {
924
+ super(t), this.imageType = "svg", this.naturalWidth = 24, this.naturalHeight = 24, this.defaultSize = { width: this.naturalWidth, height: this.naturalHeight }, this.createImage = this.createImage.bind(this), this.createVisual = this.createVisual.bind(this), this.adjustVisual = this.adjustVisual.bind(this), this.adjustImage = this.adjustImage.bind(this);
925
+ }
926
+ applyOpacity() {
927
+ this.visual && r.setAttributes(this.visual, [["opacity", this.opacity.toString()]]);
928
+ }
929
+ createImage() {
930
+ var t;
931
+ if (this._svgString !== void 0) {
932
+ this.imageType = "svg";
933
+ const i = new DOMParser().parseFromString(this._svgString, "image/svg+xml").documentElement;
934
+ if (!(i instanceof SVGSVGElement)) throw new Error("Invalid SVG string");
935
+ const e = i;
936
+ this.SVGImage = this.container.ownerDocument.importNode(e, !0);
937
+ } else this.imageType = "bitmap", this.SVGImage = r.createImage([["href", (t = this._imageSrc) !== null && t !== void 0 ? t : ""]]);
938
+ }
939
+ createVisual() {
940
+ this.createImage(), this.SVGImage !== void 0 && (this.visual = r.createGroup(), this.imageType === "svg" && r.setAttributes(this.visual, [["viewBox", `0 0 ${this.naturalWidth} ${this.naturalHeight}`], ["fill", this._fillColor], ["stroke", this._strokeColor], ["color", this._strokeColor], ["stroke-width", this.strokeWidth.toString()], ["stroke-dasharray", this.strokeDasharray], ["opacity", this.opacity.toString()], ["pointer-events", "bounding-box"]]), this.adjustImage(), this.visual.appendChild(this.SVGImage), this.addMarkerVisualToContainer(this.visual));
941
+ }
942
+ adjustVisual() {
943
+ this.visual && r.setAttributes(this.visual, [["opacity", this._opacity.toString()]]);
944
+ }
945
+ adjustImage() {
946
+ this.SVGImage !== void 0 && (this.SVGImage.setAttribute("x", "0px"), this.SVGImage.setAttribute("y", "0px"), this.SVGImage.setAttribute("width", `${this.width}px`), this.SVGImage.setAttribute("height", `${this.height}px`));
947
+ }
948
+ isDescendant(t, i) {
949
+ if (t === i) return !0;
950
+ for (let e = 0; e < t.children.length; e++) if (this.isDescendant(t.children[e], i)) return !0;
951
+ return !1;
952
+ }
953
+ ownsTarget(t) {
954
+ return super.ownsTarget(t) || this.SVGImage !== void 0 && this.isDescendant(this.SVGImage, t);
955
+ }
956
+ setSize() {
957
+ super.setSize(), this.visual && (r.setAttributes(this.visual, [["width", `${this.width}px`], ["height", `${this.height}px`]]), this.adjustImage());
958
+ }
959
+ getState() {
960
+ return Object.assign({ imageType: this.imageType, svgString: this.svgString, imageSrc: this.imageSrc }, super.getState());
961
+ }
962
+ applyStrokeColor() {
963
+ this.visual && r.setAttributes(this.visual, [["color", this._strokeColor]]);
964
+ }
965
+ restoreState(t) {
966
+ const i = t;
967
+ i.imageType !== void 0 && (this.imageType = i.imageType), i.svgString !== void 0 && (this._svgString = i.svgString), i.imageSrc !== void 0 && (this._imageSrc = i.imageSrc), this.createVisual(), super.restoreState(t), this.setSize(), this.adjustVisual();
968
+ }
969
+ scale(t, i) {
970
+ super.scale(t, i), this.setSize();
971
+ }
972
+ }
973
+ F.title = "Image marker";
974
+ class B extends F {
975
+ }
976
+ B.typeName = "CustomImageMarker", B.title = "Custom image marker";
977
+ class L extends F {
978
+ constructor(t) {
979
+ super(t), this._svgString = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M21.801 10A10 10 0 1 1 17 3.335"/><path d="m9 11l3 3L22 4"/></g></svg>', this.strokeColor = "#008000";
980
+ }
981
+ }
982
+ L.typeName = "CheckImageMarker", L.title = "Check image marker";
983
+ class z extends F {
984
+ constructor(t) {
985
+ super(t), this._svgString = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><circle cx="12" cy="12" r="10"/><path d="m15 9l-6 6m0-6l6 6"/></g></svg>', this.strokeColor = "#d00000";
986
+ }
987
+ }
988
+ z.typeName = "XImageMarker", z.title = "X image marker";
989
+ class G extends m {
990
+ constructor(t) {
991
+ super(t), this._outerFrameVisual = r.createPath("M0,0"), this._captionFrameVisual = r.createPath("M0,0"), this._frameVisual = r.createGroup(), this.color = "#ffffff", this.fillColor = "#ff0000", this.strokeColor = "#ff0000", this.strokeWidth = 3, this.padding = 5, this.createVisual = this.createVisual.bind(this), this.adjustVisual = this.adjustVisual.bind(this), this.adjustFrameVisual = this.adjustFrameVisual.bind(this), this.getPaths = this.getPaths.bind(this);
992
+ }
993
+ applyStrokeColor() {
994
+ r.setAttributes(this._outerFrameVisual, [["stroke", this._strokeColor]]), r.setAttributes(this._captionFrameVisual, [["stroke", this._strokeColor]]);
995
+ }
996
+ applyStrokeWidth() {
997
+ r.setAttributes(this._outerFrameVisual, [["stroke-width", this._strokeWidth.toString()]]), r.setAttributes(this._captionFrameVisual, [["stroke-width", this._strokeWidth.toString()]]), this.adjustTextPosition(), this.adjustFrameVisual();
998
+ }
999
+ applyStrokeDasharray() {
1000
+ r.setAttributes(this._outerFrameVisual, [["stroke-dasharray", this._strokeDasharray]]), r.setAttributes(this._captionFrameVisual, [["stroke-dasharray", this._strokeDasharray]]);
1001
+ }
1002
+ applyOpacity() {
1003
+ this.visual && r.setAttributes(this.visual, [["opacity", this._opacity.toString()]]);
1004
+ }
1005
+ applyFillColor() {
1006
+ r.setAttributes(this._captionFrameVisual, [["fill", this._fillColor]]);
1007
+ }
1008
+ getPaths(t = this.width, i = this.height) {
1009
+ var e, s;
1010
+ return { frame: `M 0 0
1011
+ V ${i}
1012
+ H ${t}
1013
+ V 0
1014
+ Z`, caption: `M 0 0
1015
+ H ${t}
1016
+ V ${((s = (e = this.textBlock.textSize) === null || e === void 0 ? void 0 : e.height) !== null && s !== void 0 ? s : 40) + 2 * this.padding + this.strokeWidth}
1017
+ H 0
1018
+ Z` };
1019
+ }
1020
+ createVisual() {
1021
+ var t;
1022
+ super.createVisual();
1023
+ const i = this.getPaths();
1024
+ this.visual && r.setAttributes(this.visual, [["opacity", this._opacity.toString()]]), this._outerFrameVisual = r.createPath(i.frame, [["fill", "transparent"], ["stroke", this._strokeColor], ["stroke-width", this._strokeWidth.toString()], ["stroke-dasharray", this._strokeDasharray]]), this._captionFrameVisual = r.createPath(i.caption, [["fill", "this._fillColor"], ["fill-rule", "evenodd"], ["stroke", this._strokeColor], ["stroke-width", this._strokeWidth.toString()], ["stroke-dasharray", this._strokeDasharray]]), this._frameVisual.appendChild(this._outerFrameVisual), this._frameVisual.appendChild(this._captionFrameVisual), (t = this.visual) === null || t === void 0 || t.insertBefore(this._frameVisual, this.textBlock.textElement);
1025
+ }
1026
+ adjustVisual() {
1027
+ super.adjustVisual(), this.adjustTextPosition(), this.adjustFrameVisual();
1028
+ }
1029
+ adjustTextPosition() {
1030
+ var t;
1031
+ this.textBlock.textSize && (this.textBlock.textElement.style.transform = `translate(${this.width / 2 - ((t = this.textBlock.textSize) === null || t === void 0 ? void 0 : t.width) / 2 - this.padding}px, ${this.strokeWidth / 2}px)`);
1032
+ }
1033
+ adjustFrameVisual() {
1034
+ const t = this.getPaths();
1035
+ this.visual && r.setAttributes(this.visual, [["opacity", this._opacity.toString()]]), this._outerFrameVisual && r.setAttributes(this._outerFrameVisual, [["d", t.frame], ["stroke", this._strokeColor], ["stroke-width", this._strokeWidth.toString()], ["stroke-dasharray", this._strokeDasharray]]), this._captionFrameVisual && r.setAttributes(this._captionFrameVisual, [["d", t.caption], ["fill", this._fillColor], ["stroke", this._strokeColor], ["stroke-width", this._strokeWidth.toString()], ["stroke-dasharray", this._strokeDasharray]]);
1036
+ }
1037
+ ownsTarget(t) {
1038
+ return !(!super.ownsTarget(t) && this._outerFrameVisual !== t && this._captionFrameVisual !== t);
1039
+ }
1040
+ setSize() {
1041
+ super.setSize(), this.adjustTextPosition(), this.adjustFrameVisual();
1042
+ }
1043
+ setSizeFromTextSize() {
1044
+ }
1045
+ hideVisual() {
1046
+ this.textBlock.hide();
1047
+ }
1048
+ showVisual() {
1049
+ this.textBlock.show(), this.textBlock.renderText();
1050
+ }
1051
+ getState() {
1052
+ return Object.assign({ fillColor: this.fillColor }, super.getState());
1053
+ }
1054
+ restoreState(t) {
1055
+ const i = t;
1056
+ super.restoreState(t), this.fillColor = i.fillColor, this.adjustVisual();
1057
+ }
1058
+ scale(t, i) {
1059
+ super.scale(t, i), this.strokeWidth *= (t + i) / 2, this.setSize();
1060
+ }
1061
+ }
1062
+ G.typeName = "CaptionFrameMarker", G.title = "Caption frame marker";
1063
+ class A extends v {
1064
+ constructor(t) {
1065
+ super(t), this.curveX = 0, this.curveY = 0, this.fillColor = "transparent";
1066
+ }
1067
+ getPath() {
1068
+ return `M ${this.x1} ${this.y1} Q ${this.curveX} ${this.curveY}, ${this.x2} ${this.y2}`;
1069
+ }
1070
+ getState() {
1071
+ return Object.assign({ curveX: this.curveX, curveY: this.curveY }, super.getState());
1072
+ }
1073
+ restoreState(t) {
1074
+ this.curveX = t.curveX, this.curveY = t.curveY, super.restoreState(t);
1075
+ }
1076
+ scale(t, i) {
1077
+ super.scale(t, i), this.curveX = this.curveX * t, this.curveY = this.curveY * i, this.adjustVisual();
1078
+ }
1079
+ }
1080
+ A.typeName = "CurveMarker", A.title = "Curve marker";
1081
+ class w extends y {
1082
+ constructor(t) {
1083
+ super(t), this.opacity = 0.5, this.strokeColor = "#ffff00", this.strokeWidth = 20;
1084
+ }
1085
+ }
1086
+ w.typeName = "HighlighterMarker", w.title = "Highlighter marker", w.applyDefaultFilter = !1;
1087
+ class Y {
1088
+ static getDefaultFilterSet() {
1089
+ return [r.createFilter("dropShadow", [["x", "-20%"], ["y", "-20%"], ["width", "140%"], ["height", "140%"]], '<feDropShadow dx="2" dy="2" stdDeviation="2" flood-color="rgba(0,0,0,0.8)"/>'), r.createFilter("outline", [["x", "-5%"], ["y", "-5%"], ["width", "110%"], ["height", "110%"]], `<feMorphology operator="dilate" radius="2" in="SourceAlpha" result="expanded"/>
1090
+ <feFlood flood-color="white" flood-opacity="1"/>
1091
+ <feComposite in2="expanded" operator="in"/>
1092
+ <feComposite in="SourceGraphic" operator="over"/>`), r.createFilter("glow", [["x", "-50%"], ["y", "-50%"], ["width", "200%"], ["height", "200%"]], `<feGaussianBlur in="SourceGraphic" stdDeviation="3" result="blur"/>
1093
+ <feFlood flood-color="#ffffff" flood-opacity="1"/>
1094
+ <feComposite in2="blur" operator="in"/>
1095
+ <feMerge>
1096
+ <feMergeNode/>
1097
+ <feMergeNode in="SourceGraphic"/>
1098
+ </feMerge>`)];
1099
+ }
1100
+ }
1101
+ class H {
1102
+ get creationStyle() {
1103
+ return this._creationStyle;
1104
+ }
1105
+ is(t) {
1106
+ return this instanceof t;
1107
+ }
1108
+ get marker() {
1109
+ return this._marker;
1110
+ }
1111
+ get container() {
1112
+ return this._container;
1113
+ }
1114
+ get overlayContainer() {
1115
+ return this._overlayContainer;
1116
+ }
1117
+ get state() {
1118
+ return this._state;
1119
+ }
1120
+ set state(t) {
1121
+ this._state = t;
1122
+ }
1123
+ get isSelected() {
1124
+ return this._isSelected;
1125
+ }
1126
+ get continuousCreation() {
1127
+ return this._continuousCreation;
1128
+ }
1129
+ set strokeColor(t) {
1130
+ this.marker.strokeColor = t;
1131
+ }
1132
+ get strokeColor() {
1133
+ return this.marker.strokeColor;
1134
+ }
1135
+ set strokeWidth(t) {
1136
+ this.marker.strokeWidth = t, this.adjustControlBox(), this.stateChanged();
1137
+ }
1138
+ get strokeWidth() {
1139
+ return this.marker.strokeWidth;
1140
+ }
1141
+ set strokeDasharray(t) {
1142
+ this.marker.strokeDasharray = t, this.stateChanged();
1143
+ }
1144
+ get strokeDasharray() {
1145
+ return this.marker.strokeDasharray;
1146
+ }
1147
+ set fillColor(t) {
1148
+ this.marker.fillColor = t;
1149
+ }
1150
+ get fillColor() {
1151
+ return this.marker.fillColor;
1152
+ }
1153
+ set opacity(t) {
1154
+ this.marker.opacity = t;
1155
+ }
1156
+ get opacity() {
1157
+ return this.marker.opacity;
1158
+ }
1159
+ set notes(t) {
1160
+ this.marker.notes = t;
1161
+ }
1162
+ get notes() {
1163
+ return this.marker.notes;
1164
+ }
1165
+ get zoomLevel() {
1166
+ return this._zoomLevel;
1167
+ }
1168
+ set zoomLevel(t) {
1169
+ this._zoomLevel = t, this.adjustControlBox();
1170
+ }
1171
+ constructor(t) {
1172
+ var i;
1173
+ this._creationStyle = "draw", this._state = "new", this._isSelected = !1, this._continuousCreation = !1, this._zoomLevel = 1, this.isMultiSelected = !1, this._container = t.container, this._overlayContainer = t.overlayContainer, this._markerType = t.markerType, this._marker = (i = t.marker) !== null && i !== void 0 ? i : new t.markerType(t.container), this.select = this.select.bind(this), this.deselect = this.deselect.bind(this), this.ownsTarget = this.ownsTarget.bind(this), this.adjustControlBox = this.adjustControlBox.bind(this), this.stateChanged = this.stateChanged.bind(this), this.scale = this.scale.bind(this), this.dispose = this.dispose.bind(this), this.pointerDown = this.pointerDown.bind(this), this.pointerUp = this.pointerUp.bind(this), this.manipulate = this.manipulate.bind(this), this.dblClick = this.dblClick.bind(this);
1174
+ }
1175
+ ownsTarget(t) {
1176
+ var i;
1177
+ let e = !1;
1178
+ return t !== null && (!((i = this._marker) === null || i === void 0) && i.ownsTarget(t)) && (e = !0), e;
1179
+ }
1180
+ select(t = !1) {
1181
+ this.isMultiSelected = t, this.container.style.cursor = "move", this._isSelected = !0, this.manipulationStartState = JSON.stringify(this._marker.getState());
1182
+ }
1183
+ deselect() {
1184
+ this.container.style.cursor = "default", this._isSelected = !1, this.stateChanged();
1185
+ }
1186
+ pointerDown(t, i, e) {
1187
+ }
1188
+ dblClick(t, i, e) {
1189
+ }
1190
+ manipulate(t, i) {
1191
+ }
1192
+ pointerUp(t, i) {
1193
+ }
1194
+ dispose() {
1195
+ }
1196
+ adjustControlBox() {
1197
+ }
1198
+ scale(t, i) {
1199
+ this._marker.scale(t, i), this.adjustControlBox();
1200
+ }
1201
+ stateChanged() {
1202
+ if (this.onStateChanged && this.state !== "creating" && this.state !== "new") {
1203
+ const t = JSON.stringify(this._marker.getState());
1204
+ this.manipulationStartState != t && (this.manipulationStartState = t, this.onStateChanged(this));
1205
+ }
1206
+ }
1207
+ hide() {
1208
+ this.container.style.display = "none";
1209
+ }
1210
+ show() {
1211
+ this.container.style.display = "block";
1212
+ }
1213
+ getState() {
1214
+ return this.marker.getState();
1215
+ }
1216
+ restoreState(t) {
1217
+ this._state = "select", this.marker.restoreState(t), this.adjustControlBox();
1218
+ }
1219
+ }
1220
+ class tt {
1221
+ get visual() {
1222
+ return this._visual || this.createVisual(), this._visual;
1223
+ }
1224
+ get zoomLevel() {
1225
+ return this._zoomLevel;
1226
+ }
1227
+ set zoomLevel(t) {
1228
+ this._zoomLevel = t, this.adjustVisual();
1229
+ }
1230
+ constructor() {
1231
+ this.gripSize = 5, this._zoomLevel = 1, this.fillColor = "rgba(255,255,255,0.9)", this.strokeColor = "#0ea5e9", this.createVisual = this.createVisual.bind(this), this.adjustVisual = this.adjustVisual.bind(this);
1232
+ }
1233
+ createVisual() {
1234
+ this._visual = r.createGroup(), this._selectorElement = r.createCircle(2 * this.gripSize, [["fill", "transparent"], ["cx", (this.gripSize / 2).toString()], ["cy", (this.gripSize / 2).toString()]]), this._visual.appendChild(this._selectorElement), this._visibleElement = r.createCircle(this.gripSize, [["fill-opacity", "1"], ["stroke-width", "1"], ["stroke-opacity", "1"]]), this._visibleElement.style.fill = `var(--mjs-grip-fill, ${this.fillColor})`, this._visibleElement.style.stroke = `var(--mjs-grip-stroke, ${this.strokeColor})`, this._visibleElement.style.filter = "drop-shadow(0px 0px 2px rgba(0, 0, 0, .7))", this._visual.appendChild(this._visibleElement);
1235
+ }
1236
+ adjustVisual() {
1237
+ this._selectorElement && this._visibleElement && (this._selectorElement.setAttribute("r", (2 * this.gripSize / this.zoomLevel).toString()), this._visibleElement.setAttribute("r", (this.gripSize / this.zoomLevel).toString()), this._visibleElement.setAttribute("stroke-width", (1 / this.zoomLevel).toString()));
1238
+ }
1239
+ ownsTarget(t) {
1240
+ var i;
1241
+ if (t === this._visual) return !0;
1242
+ {
1243
+ let e = !1;
1244
+ return (i = this._visual) === null || i === void 0 || i.childNodes.forEach((s) => {
1245
+ s === t && (e = !0);
1246
+ }), e;
1247
+ }
1248
+ }
1249
+ }
1250
+ class g extends tt {
1251
+ }
1252
+ class rt extends H {
1253
+ constructor(t) {
1254
+ super(t), this.defaultLength = 50, this.manipulationStartX = 0, this.manipulationStartY = 0, this.manipulationBox = r.createGroup(), this.grips = [], this.ownsTarget = this.ownsTarget.bind(this), this.setupControlBox = this.setupControlBox.bind(this), this.adjustControlBox = this.adjustControlBox.bind(this), this.adjustControlGrips = this.adjustControlGrips.bind(this), this.createGrip = this.createGrip.bind(this), this.positionGrip = this.positionGrip.bind(this), this.positionGrips = this.positionGrips.bind(this), this.resize = this.resize.bind(this), this.manipulate = this.manipulate.bind(this), this.pointerDown = this.pointerDown.bind(this), this.pointerUp = this.pointerUp.bind(this);
1255
+ }
1256
+ ownsTarget(t) {
1257
+ return !(!super.ownsTarget(t) && !this.marker.ownsTarget(t)) || !!this.grips.some((i) => i.ownsTarget(t));
1258
+ }
1259
+ pointerDown(t, i, e) {
1260
+ super.pointerDown(t, i, e), this.manipulationStartX = t.x, this.manipulationStartY = t.y, this.adjustControlBox(), this.controlBox.style.display = "", this.state === "new" ? this.startCreation(t) : this._state === "creating" ? this.grips.length > 0 && i && this.grips[0].ownsTarget(i) ? this.finishCreation() : this.addNewPointWhileCreating(t) : (this.select(this.isMultiSelected), this.activeGrip = i && this.grips.find((s) => s.ownsTarget(i)), this.activeGrip ? this._state = "resize" : this._state = "move");
1261
+ }
1262
+ startCreation(t) {
1263
+ this.marker.stage = "creating", this.marker.points.push(t), this.marker.points.push(t), this.marker.createVisual(), this.marker.adjustVisual(), this.adjustControlGrips(), this.controlBox && (this.controlBox.style.display = ""), this.activeGrip = this.grips.at(-1), this.activeGrip && (this.activeGrip.visual.style.pointerEvents = "none"), this._state = "creating";
1264
+ }
1265
+ addNewPointWhileCreating(t) {
1266
+ this.marker.points.push(t), this.marker.adjustVisual(), this.adjustControlGrips(), this.activeGrip = this.grips.at(-1), this.activeGrip && (this.activeGrip.visual.style.pointerEvents = "none");
1267
+ }
1268
+ finishCreation() {
1269
+ this.marker.stage = "normal", this.marker.points.splice(0, 1), this.marker.points.length === 1 && this.marker.points.splice(0, 1), this.marker.adjustVisual(), this.adjustControlGrips(), this.grips.forEach((t) => {
1270
+ t.visual.style.pointerEvents = "";
1271
+ }), this._state = "select", this.marker.points.length > 0 && this.onMarkerCreated && this.onMarkerCreated(this);
1272
+ }
1273
+ pointerUp(t, i) {
1274
+ super.pointerUp(t, i), this.manipulate(t, i), this._state !== "creating" && (this._state = "select"), this.stateChanged();
1275
+ }
1276
+ manipulate(t, i) {
1277
+ this.state === "creating" ? this.resize(t) : this.state === "move" ? (this.marker.points.forEach((e) => {
1278
+ e.x += t.x - this.manipulationStartX, e.y += t.y - this.manipulationStartY;
1279
+ }), this.manipulationStartX = t.x, this.manipulationStartY = t.y, this.marker.adjustVisual(), this.adjustControlBox()) : this.state === "resize" && this.resize(t);
1280
+ }
1281
+ resize(t) {
1282
+ const i = this.activeGrip ? this.grips.indexOf(this.activeGrip) : -1;
1283
+ i >= 0 && (this.marker.points[i] = t, this.marker.adjustVisual(), this.adjustControlBox());
1284
+ }
1285
+ dblClick(t, i, e) {
1286
+ if (i && this.state === "select") {
1287
+ const s = this.marker.selectorVisualLines.findIndex((a) => a === i);
1288
+ if (s > -1) this.marker.points.splice(s + 1, 0, t), this.marker.adjustVisual(), this.adjustControlGrips();
1289
+ else {
1290
+ const a = this.grips.findIndex((h) => h.ownsTarget(i));
1291
+ a > -1 && (this.marker.points.splice(a, 1), this.marker.adjustVisual(), this.adjustControlGrips());
1292
+ }
1293
+ }
1294
+ }
1295
+ setupControlBox() {
1296
+ this.controlBox || (this.controlBox = r.createGroup(), this.container.appendChild(this.controlBox), this.manipulationBox = r.createGroup(), this.controlBox.appendChild(this.manipulationBox), this.adjustControlGrips(), this.controlBox.style.display = "none");
1297
+ }
1298
+ adjustControlBox() {
1299
+ this.controlBox || this.setupControlBox(), this.adjustControlGrips();
1300
+ }
1301
+ adjustControlGrips() {
1302
+ const t = this.marker.points.length - this.grips.length;
1303
+ if (t > 0) for (let i = 0; i < t; i++) this.grips.push(this.createGrip());
1304
+ else if (t < 0) for (let i = 0; i < -t; i++) {
1305
+ const e = this.grips.pop();
1306
+ e && this.manipulationBox.removeChild(e.visual);
1307
+ }
1308
+ this.positionGrips();
1309
+ }
1310
+ createGrip() {
1311
+ const t = new g();
1312
+ return t.zoomLevel = this.zoomLevel, t.visual.transform.baseVal.appendItem(r.createTransform()), this.manipulationBox.appendChild(t.visual), t;
1313
+ }
1314
+ positionGrips() {
1315
+ this.grips.forEach((t, i) => {
1316
+ t.zoomLevel = this.zoomLevel;
1317
+ const e = this.marker.points[i];
1318
+ this.positionGrip(t.visual, e.x - t.gripSize / 2, e.y - t.gripSize / 2);
1319
+ });
1320
+ }
1321
+ positionGrip(t, i, e) {
1322
+ const s = t.transform.baseVal.getItem(0);
1323
+ s.setTranslate(i, e), t.transform.baseVal.replaceItem(s, 0);
1324
+ }
1325
+ select(t = !1) {
1326
+ super.select(t), this.adjustControlBox(), this.manipulationBox.style.display = t ? "none" : "", this.controlBox.style.display = "";
1327
+ }
1328
+ deselect() {
1329
+ super.deselect(), this.controlBox && (this.controlBox.style.display = "none"), this.state === "creating" && this.finishCreation();
1330
+ }
1331
+ }
1332
+ class W extends H {
1333
+ constructor(t) {
1334
+ super(t), this.defaultLength = 50, this.manipulationStartX = 0, this.manipulationStartY = 0, this.manipulationStartX1 = 0, this.manipulationStartY1 = 0, this.manipulationStartX2 = 0, this.manipulationStartY2 = 0, this.manipulationBox = r.createGroup(), this.ownsTarget = this.ownsTarget.bind(this), this.setupControlBox = this.setupControlBox.bind(this), this.adjustControlBox = this.adjustControlBox.bind(this), this.addControlGrips = this.addControlGrips.bind(this), this.createGrip = this.createGrip.bind(this), this.positionGrip = this.positionGrip.bind(this), this.positionGrips = this.positionGrips.bind(this), this.resize = this.resize.bind(this), this.manipulate = this.manipulate.bind(this), this.pointerDown = this.pointerDown.bind(this), this.pointerUp = this.pointerUp.bind(this);
1335
+ }
1336
+ ownsTarget(t) {
1337
+ var i, e;
1338
+ return !(!super.ownsTarget(t) && !this.marker.ownsTarget(t)) || !(!(!((i = this.grip1) === null || i === void 0) && i.ownsTarget(t)) && !(!((e = this.grip2) === null || e === void 0) && e.ownsTarget(t)));
1339
+ }
1340
+ pointerDown(t, i, e) {
1341
+ var s, a;
1342
+ super.pointerDown(t, i, e), this.manipulationStartX = t.x, this.manipulationStartY = t.y, this.state === "new" && (this.setupControlBox(), this.marker.x1 = t.x, this.marker.y1 = t.y, this.marker.x2 = t.x, this.marker.y2 = t.y), this.manipulationStartX1 = this.marker.x1, this.manipulationStartY1 = this.marker.y1, this.manipulationStartX2 = this.marker.x2, this.manipulationStartY2 = this.marker.y2, this.state === "new" ? (this.marker.createVisual(), this.marker.adjustVisual(), this._state = "creating") : (this.select(this.isMultiSelected), i && (!((s = this.grip1) === null || s === void 0) && s.ownsTarget(i)) ? this.activeGrip = this.grip1 : i && (!((a = this.grip2) === null || a === void 0) && a.ownsTarget(i)) ? this.activeGrip = this.grip2 : this.activeGrip = void 0, this.activeGrip ? this._state = "resize" : this._state = "move");
1343
+ }
1344
+ pointerUp(t, i) {
1345
+ const e = this.state;
1346
+ super.pointerUp(t, i), this.state === "creating" && Math.abs(this.marker.x1 - this.marker.x2) < 10 && Math.abs(this.marker.y1 - this.marker.y2) < 10 ? (this.marker.x2 = this.marker.x1 + this.defaultLength, this.marker.adjustVisual(), this.adjustControlBox()) : this.manipulate(t, i), this._state = "select", e === "creating" && this.onMarkerCreated && this.onMarkerCreated(this), this.stateChanged();
1347
+ }
1348
+ manipulate(t, i) {
1349
+ this.state === "creating" ? this.resize(t) : this.state === "move" ? (this.marker.x1 = this.manipulationStartX1 + t.x - this.manipulationStartX, this.marker.y1 = this.manipulationStartY1 + t.y - this.manipulationStartY, this.marker.x2 = this.manipulationStartX2 + t.x - this.manipulationStartX, this.marker.y2 = this.manipulationStartY2 + t.y - this.manipulationStartY, this.marker.adjustVisual(), this.adjustControlBox()) : this.state === "resize" && this.resize(t);
1350
+ }
1351
+ resize(t) {
1352
+ switch (this.activeGrip) {
1353
+ case this.grip1:
1354
+ this.marker.x1 = t.x, this.marker.y1 = t.y;
1355
+ break;
1356
+ case this.grip2:
1357
+ case void 0:
1358
+ this.marker.x2 = t.x, this.marker.y2 = t.y;
1359
+ }
1360
+ this.marker.adjustVisual(), this.adjustControlBox();
1361
+ }
1362
+ setupControlBox() {
1363
+ this._controlBox || (this._controlBox = r.createGroup(), this.container.appendChild(this._controlBox), this.manipulationBox = r.createGroup(), this._controlBox.appendChild(this.manipulationBox), this.addControlGrips(), this._controlBox.style.display = "none");
1364
+ }
1365
+ adjustControlBox() {
1366
+ this._controlBox || this.setupControlBox(), this.positionGrips();
1367
+ }
1368
+ addControlGrips() {
1369
+ this.grip1 = this.createGrip(), this.grip2 = this.createGrip(), this.positionGrips();
1370
+ }
1371
+ createGrip() {
1372
+ const t = new g();
1373
+ return t.zoomLevel = this.zoomLevel, t.visual.transform.baseVal.appendItem(r.createTransform()), this.manipulationBox.appendChild(t.visual), t;
1374
+ }
1375
+ positionGrips() {
1376
+ if (this.grip1 && this.grip2) {
1377
+ const t = this.grip1.gripSize;
1378
+ this.positionGrip(this.grip1.visual, this.marker.x1 - t / 2, this.marker.y1 - t / 2), this.positionGrip(this.grip2.visual, this.marker.x2 - t / 2, this.marker.y2 - t / 2), this.grip1.zoomLevel = this.zoomLevel, this.grip2.zoomLevel = this.zoomLevel;
1379
+ }
1380
+ }
1381
+ positionGrip(t, i, e) {
1382
+ const s = t.transform.baseVal.getItem(0);
1383
+ s.setTranslate(i, e), t.transform.baseVal.replaceItem(s, 0);
1384
+ }
1385
+ select(t = !1) {
1386
+ super.select(t), this.adjustControlBox(), this.manipulationBox.style.display = t ? "none" : "", this._controlBox.style.display = "";
1387
+ }
1388
+ deselect() {
1389
+ super.deselect(), this._controlBox && (this._controlBox.style.display = "none");
1390
+ }
1391
+ }
1392
+ class K {
1393
+ constructor() {
1394
+ this.grips = /* @__PURE__ */ new Map([["topleft", new g()], ["topcenter", new g()], ["topright", new g()], ["leftcenter", new g()], ["rightcenter", new g()], ["bottomleft", new g()], ["bottomcenter", new g()], ["bottomright", new g()]]), this.findGripByVisual = this.findGripByVisual.bind(this);
1395
+ }
1396
+ findGripByVisual(t) {
1397
+ for (const i of this.grips.values()) if (i.ownsTarget(t)) return i;
1398
+ }
1399
+ getGrip(t) {
1400
+ return this.grips.get(t);
1401
+ }
1402
+ }
1403
+ class at extends tt {
1404
+ constructor() {
1405
+ super();
1406
+ const t = this.fillColor;
1407
+ this.fillColor = this.strokeColor, this.strokeColor = t;
1408
+ }
1409
+ }
1410
+ class q extends H {
1411
+ constructor() {
1412
+ super(...arguments), this.manipulationStartLeft = 0, this.manipulationStartTop = 0, this.manipulationStartWidth = 0, this.manipulationStartHeight = 0, this.manipulationStartX = 0, this.manipulationStartY = 0, this.offsetX = 0, this.offsetY = 0, this.manipulationBox = r.createGroup(), this.CB_DISTANCE = 0, this.controlGrips = new K(), this.disabledResizeGrips = [], this.disableRotation = !1, this._suppressMarkerCreateEvent = !1;
1413
+ }
1414
+ ownsTarget(t) {
1415
+ var i;
1416
+ return !(!super.ownsTarget(t) && !this._marker.ownsTarget(t)) || !!(((i = this.controlGrips) === null || i === void 0 ? void 0 : i.findGripByVisual(t)) !== void 0 || this.rotatorGrip !== void 0 && this.rotatorGrip.ownsTarget(t));
1417
+ }
1418
+ pointerDown(t, i, e) {
1419
+ var s;
1420
+ super.pointerDown(t, i, e), this.setupControlBox(), this.state === "new" && (this.marker.left = t.x, this.marker.top = t.y), this.manipulationStartLeft = this.marker.left, this.manipulationStartTop = this.marker.top, this.manipulationStartWidth = this.marker.width, this.manipulationStartHeight = this.marker.height;
1421
+ const a = this.marker.unrotatePoint(t);
1422
+ if (this.manipulationStartX = a.x, this.manipulationStartY = a.y, this.offsetX = a.x - this.marker.left, this.offsetY = a.y - this.marker.top, this.state !== "new") if (this.select(this.isMultiSelected), this.activeGrip = (s = this.controlGrips) === null || s === void 0 ? void 0 : s.findGripByVisual(i), this.activeGrip !== void 0) this._state = "resize";
1423
+ else if (this.rotatorGrip !== void 0 && i !== void 0 && this.rotatorGrip.ownsTarget(i)) {
1424
+ this.activeGrip = this.rotatorGrip;
1425
+ const h = this.marker.rotatePoint({ x: this.marker.centerX, y: this.marker.centerY });
1426
+ this.marker.left = h.x - this.marker.width / 2, this.marker.top = h.y - this.marker.height / 2, this.marker.moveVisual({ x: this.marker.left, y: this.marker.top });
1427
+ const o = this.container.transform.baseVal.getItem(0);
1428
+ o.setRotate(this.marker.rotationAngle, this.marker.centerX, this.marker.centerY), this.container.transform.baseVal.replaceItem(o, 0), this.adjustControlBox(), this._state = "rotate";
1429
+ } else this._state = "move";
1430
+ }
1431
+ pointerUp(t, i) {
1432
+ const e = this.state;
1433
+ super.pointerUp(t, i), this.state === "creating" && this.marker.width < 10 && this.marker.height < 10 ? (this.marker.width = this.marker.defaultSize.width, this.marker.height = this.marker.defaultSize.height) : this.manipulate(t, i), this._state = "select", e === "creating" && this.onMarkerCreated && this._suppressMarkerCreateEvent === !1 && this.onMarkerCreated(this), this.stateChanged();
1434
+ }
1435
+ manipulate(t, i) {
1436
+ const e = this.marker.unrotatePoint(t);
1437
+ this.state === "creating" ? this.resize(t, i == null ? void 0 : i.shiftKey) : this.state === "move" ? (this.marker.left = this.manipulationStartLeft + (e.x - this.manipulationStartLeft) - this.offsetX, this.marker.top = this.manipulationStartTop + (e.y - this.manipulationStartTop) - this.offsetY, this.marker.moveVisual({ x: this.marker.left, y: this.marker.top }), this.adjustControlBox()) : this.state === "resize" ? this.resize(e, i == null ? void 0 : i.shiftKey) : this.state === "rotate" && this.marker.rotate(t);
1438
+ }
1439
+ resize(t, i = !1) {
1440
+ let e = this.manipulationStartLeft, s = this.manipulationStartWidth, a = this.manipulationStartTop, h = this.manipulationStartHeight;
1441
+ const o = t.x - this.manipulationStartX, n = t.y - this.manipulationStartY;
1442
+ if (i) {
1443
+ const l = this.manipulationStartWidth !== 0 && this.manipulationStartHeight !== 0 ? this.manipulationStartWidth / this.manipulationStartHeight : 1;
1444
+ switch (this.activeGrip) {
1445
+ case this.controlGrips.getGrip("bottomright"):
1446
+ case void 0:
1447
+ s = this.manipulationStartWidth + Math.max(o, n), h = this.manipulationStartHeight + Math.max(o, n) / l;
1448
+ break;
1449
+ case this.controlGrips.getGrip("bottomcenter"):
1450
+ s = this.manipulationStartWidth + n, h = this.manipulationStartHeight + n / l, e = this.manipulationStartLeft - n / 2;
1451
+ break;
1452
+ case this.controlGrips.getGrip("bottomleft"):
1453
+ s = this.manipulationStartWidth + Math.max(-o, n), h = this.manipulationStartHeight + Math.max(-o, n) / l, e = this.manipulationStartLeft - Math.max(-o, n);
1454
+ break;
1455
+ case this.controlGrips.getGrip("leftcenter"):
1456
+ s = this.manipulationStartWidth - o, h = this.manipulationStartHeight - o / l, e = this.manipulationStartLeft + o, a = this.manipulationStartTop + o / l / 2;
1457
+ break;
1458
+ case this.controlGrips.getGrip("topleft"):
1459
+ s = this.manipulationStartWidth + Math.max(-o, -n), h = this.manipulationStartHeight + Math.max(-o, -n) / l, e = this.manipulationStartLeft - Math.max(-o, -n), a = this.manipulationStartTop - Math.max(-o, -n) / l;
1460
+ break;
1461
+ case this.controlGrips.getGrip("topcenter"):
1462
+ s = this.manipulationStartWidth - n, h = this.manipulationStartHeight - n / l, e = this.manipulationStartLeft + n / 2, a = this.manipulationStartTop + n / l;
1463
+ break;
1464
+ case this.controlGrips.getGrip("topright"):
1465
+ s = this.manipulationStartWidth + Math.max(o, -n), h = this.manipulationStartHeight + Math.max(o, -n) / l, a = this.manipulationStartTop - Math.max(o, -n) / l;
1466
+ break;
1467
+ case this.controlGrips.getGrip("rightcenter"):
1468
+ s = this.manipulationStartWidth + o, h = this.manipulationStartHeight + o / l, a = this.manipulationStartTop - o / l / 2;
1469
+ }
1470
+ } else {
1471
+ switch (this.activeGrip) {
1472
+ case this.controlGrips.getGrip("bottomleft"):
1473
+ case this.controlGrips.getGrip("leftcenter"):
1474
+ case this.controlGrips.getGrip("topleft"):
1475
+ e = this.manipulationStartLeft + t.x - this.manipulationStartX, s = this.manipulationStartWidth + this.manipulationStartLeft - e;
1476
+ break;
1477
+ case this.controlGrips.getGrip("bottomright"):
1478
+ case this.controlGrips.getGrip("rightcenter"):
1479
+ case this.controlGrips.getGrip("topright"):
1480
+ case void 0:
1481
+ s = this.manipulationStartWidth + t.x - this.manipulationStartX;
1482
+ }
1483
+ switch (this.activeGrip) {
1484
+ case this.controlGrips.getGrip("topcenter"):
1485
+ case this.controlGrips.getGrip("topleft"):
1486
+ case this.controlGrips.getGrip("topright"):
1487
+ a = this.manipulationStartTop + t.y - this.manipulationStartY, h = this.manipulationStartHeight + this.manipulationStartTop - a;
1488
+ break;
1489
+ case this.controlGrips.getGrip("bottomcenter"):
1490
+ case this.controlGrips.getGrip("bottomleft"):
1491
+ case this.controlGrips.getGrip("bottomright"):
1492
+ case void 0:
1493
+ h = this.manipulationStartHeight + t.y - this.manipulationStartY;
1494
+ }
1495
+ }
1496
+ s >= 0 ? (this.marker.left = e, this.marker.width = s) : (this.marker.left = e + s, this.marker.width = -s), h >= 0 ? (this.marker.top = a, this.marker.height = h) : (this.marker.top = a + h, this.marker.height = -h), this.setSize();
1497
+ }
1498
+ setSize() {
1499
+ this.marker.setSize(), this.adjustControlBox();
1500
+ }
1501
+ select(t = !1) {
1502
+ super.select(t), this.adjustControlBox(), this.manipulationBox.style.display = t ? "none" : "", this.controlBox && (this.controlBox.style.display = "");
1503
+ }
1504
+ deselect() {
1505
+ super.deselect(), this.controlBox && (this.controlBox.style.display = "none");
1506
+ }
1507
+ setupControlBox() {
1508
+ if (this.controlBox) return;
1509
+ this.controlBox = r.createGroup();
1510
+ const t = r.createTransform();
1511
+ t.setTranslate(-this.CB_DISTANCE / 2, -this.CB_DISTANCE / 2), this.controlBox.transform.baseVal.appendItem(t), this.container.appendChild(this.controlBox), this.manipulationBox = r.createGroup(), this.controlBox.appendChild(this.manipulationBox), this.controlRect = r.createRect(this.marker.width + this.CB_DISTANCE, this.marker.height + this.CB_DISTANCE, [["stroke", "black"], ["stroke-width", (1 / this.zoomLevel).toString()], ["stroke-opacity", "0.5"], ["stroke-dasharray", "3, 2"], ["fill", "transparent"], ["pointer-events", "none"]]), this.controlBox.appendChild(this.controlRect), this.disableRotation !== !0 && (this.rotatorGripLine = r.createLine((this.marker.width + 2 * this.CB_DISTANCE) / 2, this.marker.top - this.CB_DISTANCE, (this.marker.width + 2 * this.CB_DISTANCE) / 2, this.marker.top - 3 * this.CB_DISTANCE, [["stroke", "black"], ["stroke-width", (1 / this.zoomLevel).toString()], ["stroke-opacity", "0.5"], ["stroke-dasharray", "3, 2"]]), this.rotatorGripLine.style.filter = "drop-shadow(rgba(255, 255, 255, 0.7) 0px 2px 0px)", this.manipulationBox.appendChild(this.rotatorGripLine)), this.controlGrips = new K(), this.addControlGrips(), this.controlBox.style.display = "none";
1512
+ }
1513
+ adjustControlBox() {
1514
+ var t, i, e;
1515
+ if (this.controlBox || this.setupControlBox(), this.controlBox) {
1516
+ const s = this.controlBox.transform.baseVal.getItem(0);
1517
+ s.setTranslate(this.marker.left - this.CB_DISTANCE / 2, this.marker.top - this.CB_DISTANCE / 2), this.controlBox.transform.baseVal.replaceItem(s, 0), (t = this.controlRect) === null || t === void 0 || t.setAttribute("width", (this.marker.width + this.CB_DISTANCE).toString()), (i = this.controlRect) === null || i === void 0 || i.setAttribute("height", (this.marker.height + this.CB_DISTANCE).toString()), (e = this.controlRect) === null || e === void 0 || e.setAttribute("stroke-width", (1 / this.zoomLevel).toString()), this.rotatorGripLine !== void 0 && (this.rotatorGripLine.setAttribute("x1", ((this.marker.width + this.CB_DISTANCE) / 2).toString()), this.rotatorGripLine.setAttribute("y1", (-this.CB_DISTANCE / 2).toString()), this.rotatorGripLine.setAttribute("x2", ((this.marker.width + this.CB_DISTANCE) / 2).toString()), this.rotatorGripLine.setAttribute("y2", (-Math.max(3 * this.CB_DISTANCE, 30)).toString()), this.rotatorGripLine.setAttribute("stroke-width", (1 / this.zoomLevel).toString())), this.positionGrips();
1518
+ }
1519
+ }
1520
+ addControlGrips() {
1521
+ for (const t of this.controlGrips.grips.values()) t.visual.transform.baseVal.appendItem(r.createTransform()), this.manipulationBox.appendChild(t.visual), this.manipulationBox.appendChild(t.visual);
1522
+ this.disableRotation !== !0 && (this.rotatorGrip = this.createRotateGrip()), this.positionGrips();
1523
+ }
1524
+ createRotateGrip() {
1525
+ const t = new at();
1526
+ return t.visual.transform.baseVal.appendItem(r.createTransform()), this.manipulationBox.appendChild(t.visual), t;
1527
+ }
1528
+ positionGrips() {
1529
+ var t, i;
1530
+ if (this.controlGrips !== void 0) {
1531
+ const e = (t = this.controlGrips.getGrip("topleft").gripSize) !== null && t !== void 0 ? t : 0, s = -e / 2, a = s, h = (this.marker.width + this.CB_DISTANCE) / 2 - e / 2, o = (this.marker.height + this.CB_DISTANCE) / 2 - e / 2, n = this.marker.height + this.CB_DISTANCE - e / 2, l = this.marker.width + this.CB_DISTANCE - e / 2;
1532
+ if (this.positionGrip(this.controlGrips.getGrip("topleft").visual, s, a), this.positionGrip(this.controlGrips.getGrip("topcenter").visual, h, a), this.positionGrip(this.controlGrips.getGrip("topright").visual, l, a), this.positionGrip(this.controlGrips.getGrip("leftcenter").visual, s, o), this.positionGrip(this.controlGrips.getGrip("rightcenter").visual, l, o), this.positionGrip(this.controlGrips.getGrip("bottomleft").visual, s, n), this.positionGrip(this.controlGrips.getGrip("bottomcenter").visual, h, n), this.positionGrip(this.controlGrips.getGrip("bottomright").visual, l, n), this.controlGrips.grips.forEach((u) => {
1533
+ u.zoomLevel = this.zoomLevel;
1534
+ }), this.rotatorGrip !== void 0) {
1535
+ this.rotatorGrip.zoomLevel = this.zoomLevel;
1536
+ const u = (i = this.rotatorGrip.gripSize) !== null && i !== void 0 ? i : 0, p = -u / 2, _ = (this.marker.width + this.CB_DISTANCE) / 2 - u / 2;
1537
+ this.positionGrip(this.rotatorGrip.visual, _, p - Math.max(Math.max(3 * this.CB_DISTANCE, 30), 15 / this.zoomLevel));
1538
+ }
1539
+ }
1540
+ this.adjustGripVisibility();
1541
+ }
1542
+ positionGrip(t, i, e) {
1543
+ if (t !== void 0) {
1544
+ const s = t.transform.baseVal.getItem(0);
1545
+ s.setTranslate(i, e), t.transform.baseVal.replaceItem(s, 0);
1546
+ }
1547
+ }
1548
+ hideControlBox() {
1549
+ this.controlBox && (this.controlBox.style.display = "none");
1550
+ }
1551
+ showControlBox() {
1552
+ this.controlBox && (this.controlBox.style.display = "");
1553
+ }
1554
+ adjustGripVisibility() {
1555
+ for (const t of this.disabledResizeGrips) {
1556
+ const i = this.controlGrips.getGrip(t);
1557
+ i !== void 0 && (i.visual.style.display = "none");
1558
+ }
1559
+ }
1560
+ scale(t, i) {
1561
+ super.scale(t, i), this.adjustControlBox();
1562
+ }
1563
+ }
1564
+ class X extends q {
1565
+ constructor(t) {
1566
+ super(t), this._creationStyle = "draw";
1567
+ }
1568
+ pointerDown(t, i, e) {
1569
+ super.pointerDown(t, i, e), this.state === "new" && (this.marker.createVisual(), this.marker.moveVisual(t), this._state = "creating");
1570
+ }
1571
+ resize(t, i = !1) {
1572
+ super.resize(t, i), this.setSize();
1573
+ }
1574
+ pointerUp(t, i) {
1575
+ super.pointerUp(t, i), this.setSize();
1576
+ }
1577
+ }
1578
+ class ht {
1579
+ constructor() {
1580
+ this.undoStack = [], this.redoStack = [];
1581
+ }
1582
+ get isUndoPossible() {
1583
+ return this.undoStack.length > 1;
1584
+ }
1585
+ get isRedoPossible() {
1586
+ return this.redoStack.length > 0;
1587
+ }
1588
+ get undoStepCount() {
1589
+ return this.undoStack.length;
1590
+ }
1591
+ get redoStepCount() {
1592
+ return this.redoStack.length;
1593
+ }
1594
+ addUndoStep(t) {
1595
+ return (this.undoStack.length === 0 || JSON.stringify(this.undoStack[this.undoStack.length - 1]) !== JSON.stringify(t)) && (this.undoStack.push(JSON.parse(JSON.stringify(t))), JSON.stringify(this.lastRedoStep) !== JSON.stringify(t) && this.redoStack.splice(0, this.redoStack.length), !0);
1596
+ }
1597
+ replaceLastUndoStep(t) {
1598
+ this.undoStack.length > 0 && (this.undoStack[this.undoStack.length - 1] = JSON.parse(JSON.stringify(t)));
1599
+ }
1600
+ getLastUndoStep() {
1601
+ return this.undoStack.length > 0 ? this.undoStack[this.undoStack.length - 1] : void 0;
1602
+ }
1603
+ undo() {
1604
+ if (this.undoStack.length > 1) {
1605
+ const t = this.undoStack.pop();
1606
+ return t !== void 0 && this.redoStack.push(t), this.undoStack.length > 0 ? this.undoStack[this.undoStack.length - 1] : void 0;
1607
+ }
1608
+ }
1609
+ redo() {
1610
+ return this.lastRedoStep = this.redoStack.pop(), this.lastRedoStep !== void 0 && this.undoStack.push(this.lastRedoStep), this.lastRedoStep;
1611
+ }
1612
+ }
1613
+ class D extends H {
1614
+ constructor(t) {
1615
+ super(t), this.manipulationStartX = 0, this.manipulationStartY = 0, this._continuousCreation = !0, this.ownsTarget = this.ownsTarget.bind(this), this.setupControlBox = this.setupControlBox.bind(this), this.adjustControlBox = this.adjustControlBox.bind(this), this.manipulate = this.manipulate.bind(this), this.pointerDown = this.pointerDown.bind(this), this.pointerUp = this.pointerUp.bind(this);
1616
+ }
1617
+ ownsTarget(t) {
1618
+ return !(!super.ownsTarget(t) && !this.marker.ownsTarget(t) && t !== this.controlRect);
1619
+ }
1620
+ pointerDown(t, i, e) {
1621
+ super.pointerDown(t, i, e), this.manipulationStartX = t.x, this.manipulationStartY = t.y, this.state === "new" ? (this.setupControlBox(), this.startCreation(t)) : this.state !== "move" && (this.select(), this._state = "move");
1622
+ }
1623
+ startCreation(t) {
1624
+ this.marker.stage = "creating", this.marker.points.push(t), this.marker.createVisual(), this.marker.adjustVisual(), this._state = "creating";
1625
+ }
1626
+ addNewPointWhileCreating(t) {
1627
+ this.marker.points.push(t), this.marker.adjustVisual();
1628
+ }
1629
+ finishCreation() {
1630
+ this.marker.stage = "normal", this.marker.adjustVisual(), this._state = "select", this.onMarkerCreated && this.onMarkerCreated(this);
1631
+ }
1632
+ pointerUp(t, i) {
1633
+ super.pointerUp(t, i), this.manipulate(t, i), this._state === "creating" && this.finishCreation(), this.state = "select", this.stateChanged();
1634
+ }
1635
+ manipulate(t, i) {
1636
+ this.state === "creating" ? this.addNewPointWhileCreating(t) : this.state === "move" && (this.marker.points.forEach((e) => {
1637
+ e.x += t.x - this.manipulationStartX, e.y += t.y - this.manipulationStartY;
1638
+ }), this.manipulationStartX = t.x, this.manipulationStartY = t.y, this.marker.adjustVisual(), this.adjustControlBox());
1639
+ }
1640
+ setupControlBox() {
1641
+ this.controlBox || (this.controlBox = r.createGroup(), this.container.appendChild(this.controlBox), this.controlRect = r.createRect(0, 0, [["stroke", "black"], ["stroke-width", "1"], ["stroke-opacity", "0.5"], ["stroke-dasharray", "3, 2"], ["fill", "transparent"]]), this.controlBox.appendChild(this.controlRect), this.controlBox.style.display = "none");
1642
+ }
1643
+ adjustControlBox() {
1644
+ if (this.controlBox || this.setupControlBox(), this.marker.points.length > 0) {
1645
+ const t = Math.min(...this.marker.points.map((a) => a.x)), i = Math.min(...this.marker.points.map((a) => a.y)), e = Math.max(...this.marker.points.map((a) => a.x)), s = Math.max(...this.marker.points.map((a) => a.y));
1646
+ this.controlRect && r.setAttributes(this.controlRect, [["x", (t - this.strokeWidth).toString()], ["y", (i - this.strokeWidth).toString()], ["width", (e - t + 2 * this.strokeWidth).toString()], ["height", (s - i + 2 * this.strokeWidth).toString()]]);
1647
+ }
1648
+ }
1649
+ select() {
1650
+ super.select(), this.adjustControlBox(), this.controlBox && (this.controlBox.style.display = "");
1651
+ }
1652
+ deselect() {
1653
+ super.deselect(), this.controlBox && (this.controlBox.style.display = "none");
1654
+ }
1655
+ }
1656
+ class ot {
1657
+ get width() {
1658
+ return this._width;
1659
+ }
1660
+ set width(t) {
1661
+ this._width = t, this.textEditor.style.width = `${this.width}px`;
1662
+ }
1663
+ get height() {
1664
+ return this._height;
1665
+ }
1666
+ set height(t) {
1667
+ this._height = t, this.textEditor.style.height = `${this.height}px`;
1668
+ }
1669
+ get left() {
1670
+ return this._left;
1671
+ }
1672
+ set left(t) {
1673
+ this._left = t, this.textEditor.style.left = `${this.left}px`;
1674
+ }
1675
+ get top() {
1676
+ return this._top;
1677
+ }
1678
+ set top(t) {
1679
+ this._top = t, this.textEditor.style.top = `${this.top}px`;
1680
+ }
1681
+ get text() {
1682
+ return this._text;
1683
+ }
1684
+ set text(t) {
1685
+ this._text = t;
1686
+ }
1687
+ get fontFamily() {
1688
+ return this._fontFamily;
1689
+ }
1690
+ set fontFamily(t) {
1691
+ this._fontFamily = t, this.textEditor.style.fontFamily = this._fontFamily;
1692
+ }
1693
+ get fontSize() {
1694
+ return this._fontSize;
1695
+ }
1696
+ set fontSize(t) {
1697
+ this._fontSize = t, this.textEditor.style.fontSize = this._fontSize;
1698
+ }
1699
+ get textColor() {
1700
+ return this._textColor;
1701
+ }
1702
+ set textColor(t) {
1703
+ this._textColor = t, this.textEditor.style.color = this.textColor;
1704
+ }
1705
+ get bgColor() {
1706
+ return this._bgColor;
1707
+ }
1708
+ set bgColor(t) {
1709
+ this._bgColor = t, this.textEditor.style.backgroundColor = this.bgColor;
1710
+ }
1711
+ constructor() {
1712
+ this.isInFocus = !1, this._width = 0, this._height = 0, this._left = 0, this._top = 0, this._text = "", this._fontFamily = "sans-serif", this._fontSize = "1rem", this._textColor = "#000", this._bgColor = "transparent", this.isSetupCompleted = !1, this.textEditor = document.createElement("textarea"), this.getEditorUi = this.getEditorUi.bind(this), this.focus = this.focus.bind(this), this.setup = this.setup.bind(this);
1713
+ }
1714
+ setup() {
1715
+ this.textEditor.style.pointerEvents = "auto", this.textEditor.style.width = `${this._width}px`, this.textEditor.style.height = `${this._height}px`, this.textEditor.style.overflow = "hidden", this.textEditor.style.textAlign = "center", this.textEditor.style.alignContent = "center", this.textEditor.style.padding = "0px", this.textEditor.style.margin = "0px", this.textEditor.style.fontFamily = this._fontFamily, this.textEditor.style.fontSize = this._fontSize, this.textEditor.style.lineHeight = "1em", this.textEditor.style.outline = "none", this.textEditor.style.border = "none", this.textEditor.style.resize = "none", this.textEditor.value = this._text, this.textEditor.style.color = this._textColor, this.textEditor.style.whiteSpace = "pre", this.textEditor.addEventListener("pointerdown", (t) => {
1716
+ t.stopPropagation();
1717
+ }), this.textEditor.addEventListener("pointerup", (t) => {
1718
+ t.stopPropagation();
1719
+ }), this.textEditor.addEventListener("keydown", (t) => {
1720
+ t.key === "Escape" && (t.preventDefault(), this.textEditor.blur());
1721
+ }), this.textEditor.addEventListener("keyup", (t) => {
1722
+ t.cancelBubble = !0, this._text = this.textEditor.value, this.onTextChanged !== void 0 && this.onTextChanged(this._text);
1723
+ }), this.textEditor.addEventListener("blur", () => {
1724
+ this._text = this.textEditor.value, this.onTextChanged !== void 0 && this.onTextChanged(this._text), this.onBlur !== void 0 && this.onBlur();
1725
+ }), this.isSetupCompleted = !0;
1726
+ }
1727
+ getEditorUi() {
1728
+ return this.isSetupCompleted || this.setup(), this.textEditor;
1729
+ }
1730
+ focus() {
1731
+ this.textEditor.focus();
1732
+ }
1733
+ blur() {
1734
+ this.textEditor.blur();
1735
+ }
1736
+ }
1737
+ class Z extends q {
1738
+ set color(t) {
1739
+ this.marker.color = t, this.stateChanged();
1740
+ }
1741
+ get color() {
1742
+ return this.marker.color;
1743
+ }
1744
+ set fontFamily(t) {
1745
+ this.marker.fontFamily = t, this.stateChanged();
1746
+ }
1747
+ get fontFamily() {
1748
+ return this.marker.fontFamily;
1749
+ }
1750
+ set fontSize(t) {
1751
+ this.marker.fontSize = t, this.stateChanged();
1752
+ }
1753
+ get fontSize() {
1754
+ return this.marker.fontSize;
1755
+ }
1756
+ constructor(t) {
1757
+ super(t), this.textBlockEditorContainer = r.createForeignObject(), this._pointerDownTime = Number.MAX_VALUE, this._pointerDownPoint = { x: 0, y: 0 }, this.markerSizeChanged = () => {
1758
+ this.setSize();
1759
+ }, this.disabledResizeGrips = ["topleft", "topcenter", "topright", "bottomleft", "bottomcenter", "bottomright", "leftcenter", "rightcenter"], this._creationStyle = "drop", this.textBlockEditor = new ot(), this.marker.onSizeChanged = this.markerSizeChanged, this.showEditor = this.showEditor.bind(this), this.hideEditor = this.hideEditor.bind(this), this.pointerDown = this.pointerDown.bind(this), this.pointerUp = this.pointerUp.bind(this), this.resize = this.resize.bind(this), this.markerSizeChanged = this.markerSizeChanged.bind(this);
1760
+ }
1761
+ pointerDown(t, i, e) {
1762
+ super.pointerDown(t, i, e), this._pointerDownTime = Date.now(), this._pointerDownPoint = t, this.state === "new" && (this.marker.createVisual(), this.marker.moveVisual(t), this._state = "creating");
1763
+ }
1764
+ dblClick(t, i, e) {
1765
+ super.dblClick(t, i, e), this.state !== "edit" && this.showEditor();
1766
+ }
1767
+ setSize() {
1768
+ super.setSize(), this.textBlockEditorContainer.style.display = "flex", this.textBlockEditorContainer.style.transform = `translate(${this.marker.left}px, ${this.marker.top}px)`, this.textBlockEditorContainer.style.width = `${this.marker.width}px`, this.textBlockEditorContainer.setAttribute("width", `${this.marker.width}`), this.textBlockEditorContainer.style.height = `${this.marker.height}px`, this.textBlockEditorContainer.setAttribute("height", `${this.marker.height}`), this.textBlockEditor.width = this.marker.width, this.textBlockEditor.height = this.marker.height;
1769
+ }
1770
+ resize(t, i = !1) {
1771
+ super.resize(t, i), this.setSize();
1772
+ }
1773
+ pointerUp(t, i) {
1774
+ const e = this.state;
1775
+ super.pointerUp(t, i), this.setSize(), (e === "creating" || Date.now() - this._pointerDownTime > 500 && Math.abs(this._pointerDownPoint.x - t.x) < 5 && Math.abs(this._pointerDownPoint.y - t.y) < 5) && this.showEditor(), this.adjustControlBox();
1776
+ }
1777
+ showEditor() {
1778
+ this.textBlockEditor.text = this.marker.text, this.textBlockEditor.textColor = this.marker.color, this.textBlockEditor.bgColor = this.marker.fillColor, this.textBlockEditor.fontFamily = this.marker.fontFamily, this.textBlockEditor.fontSize = `${this.marker.fontSize.value}${this.marker.fontSize.units}`, this.textBlockEditor.onTextChanged === void 0 && (this.textBlockEditor.onTextChanged = (t) => {
1779
+ this.marker.text = t;
1780
+ }), this.textBlockEditor.onBlur === void 0 && (this.textBlockEditor.onBlur = () => {
1781
+ this.hideEditor(), this.deselect();
1782
+ }), this.textBlockEditorContainer.appendChild(this.textBlockEditor.getEditorUi()), this.container.appendChild(this.textBlockEditorContainer), this.marker.hideVisual(), this.hideControlBox(), this.textBlockEditor.focus();
1783
+ }
1784
+ hideEditor() {
1785
+ this.marker.text = this.textBlockEditor.text, this.marker.showVisual(), this.showControlBox(), this.state = "select", this.container.removeChild(this.textBlockEditorContainer);
1786
+ }
1787
+ }
1788
+ var it = '<svg viewBox="0 0 64 64" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2"><path style="fill:none" d="M413.33 667.848h305.294v148.981H413.33z" transform="matrix(.20963 0 0 .42959 -86.648 -286.898)"/><path d="m909.846 1031.18-62.778-1.78v-15.82l62.778-2.92v20.52Z" style="fill:#ffe862" transform="matrix(.83313 0 0 .79653 -699.87 -771.183)"/><path d="M771.747 702.002v-6.3h1.248v1.344l-.228.144a2.03 2.03 0 0 1 .306-.6c.14-.192.312-.362.516-.51.204-.148.424-.266.66-.354.236-.088.478-.132.726-.132.36 0 .676.06.948.18.272.12.496.3.672.54.176.24.304.54.384.9l-.192-.048.084-.204c.088-.184.21-.358.366-.522a2.863 2.863 0 0 1 1.17-.738 2.15 2.15 0 0 1 .66-.108c.472 0 .862.096 1.17.288.308.192.54.484.696.876.156.392.234.88.234 1.464v3.78h-1.248v-3.708c0-.36-.046-.654-.138-.882a1.021 1.021 0 0 0-.414-.51c-.184-.112-.42-.168-.708-.168-.224 0-.434.038-.63.114a1.55 1.55 0 0 0-.51.318 1.446 1.446 0 0 0-.456 1.068v3.768h-1.248v-3.732c0-.328-.048-.606-.144-.834a1.123 1.123 0 0 0-.42-.522 1.204 1.204 0 0 0-.672-.18 1.68 1.68 0 0 0-.624.114 1.62 1.62 0 0 0-.504.312 1.398 1.398 0 0 0-.456 1.05v3.792h-1.248Z" style="fill:#e60076;fill-rule:nonzero" transform="matrix(4.60055 0 0 4.60055 -3539.456 -3186.295)"/></svg>';
1789
+ class N extends X {
1790
+ }
1791
+ class nt extends W {
1792
+ set arrowType(t) {
1793
+ this.marker.arrowType = t;
1794
+ }
1795
+ get arrowType() {
1796
+ return this.marker.arrowType;
1797
+ }
1798
+ }
1799
+ class lt extends Z {
1800
+ constructor(t) {
1801
+ super(t), this.manipulationStartTipPositionX = 0, this.manipulationStartTipPositionY = 0;
1802
+ }
1803
+ addControlGrips() {
1804
+ this.tipGrip = this.createTipGrip(), super.addControlGrips();
1805
+ }
1806
+ createTipGrip() {
1807
+ const t = new g();
1808
+ return t.zoomLevel = this.zoomLevel, t.visual.transform.baseVal.appendItem(r.createTransform()), this.manipulationBox.appendChild(t.visual), t;
1809
+ }
1810
+ positionGrips() {
1811
+ var t;
1812
+ if (super.positionGrips(), this.tipGrip) {
1813
+ this.tipGrip.zoomLevel = this.zoomLevel;
1814
+ const i = (t = this.tipGrip.gripSize) !== null && t !== void 0 ? t : 0;
1815
+ this.positionGrip(this.tipGrip.visual, this.marker.tipPosition.x - i / 2, this.marker.tipPosition.y - i / 2);
1816
+ }
1817
+ }
1818
+ ownsTarget(t) {
1819
+ var i;
1820
+ return !(!super.ownsTarget(t) && !(!((i = this.tipGrip) === null || i === void 0) && i.ownsTarget(t)));
1821
+ }
1822
+ pointerDown(t, i, e) {
1823
+ super.pointerDown(t, i, e), this.manipulationStartTipPositionX = this.marker.tipPosition.x, this.manipulationStartTipPositionY = this.marker.tipPosition.y, this.tipGrip !== void 0 && i !== void 0 && this.tipGrip.ownsTarget(i) && (this.activeGrip = this.tipGrip, this._state = "resize");
1824
+ }
1825
+ resize(t, i = !1) {
1826
+ const e = this.manipulationStartTipPositionX + t.x - this.manipulationStartX, s = this.manipulationStartTipPositionY + t.y - this.manipulationStartY;
1827
+ this.activeGrip === this.tipGrip ? (this.marker.tipPosition = { x: e, y: s }, this.adjustControlBox()) : super.resize(t, i);
1828
+ }
1829
+ }
1830
+ class U extends q {
1831
+ constructor(t) {
1832
+ super(t), this._creationStyle = "drop", this.disabledResizeGrips = ["topcenter", "bottomcenter", "leftcenter", "rightcenter"], this.pointerDown = this.pointerDown.bind(this), this.pointerUp = this.pointerUp.bind(this), this.resize = this.resize.bind(this);
1833
+ }
1834
+ pointerDown(t, i, e) {
1835
+ super.pointerDown(t, i, e), this.state === "new" && (this.marker.createVisual(), this.marker.moveVisual(t), this._state = "creating");
1836
+ }
1837
+ pointerUp(t, i) {
1838
+ super.pointerUp(t, i), this.setSize(), this.adjustControlBox();
1839
+ }
1840
+ }
1841
+ class dt extends Z {
1842
+ constructor(t) {
1843
+ super(t), this.disabledResizeGrips = [], this._creationStyle = "draw";
1844
+ }
1845
+ setSize() {
1846
+ if (super.setSize(), this.textBlockEditorContainer.style.transform = `translate(${this.marker.left}px, ${this.marker.top + this.marker.strokeWidth / 2}px)`, this.marker.textBlock.textSize) {
1847
+ const t = this.marker.textBlock.textSize.height + 2 * this.marker.padding;
1848
+ this.textBlockEditorContainer.style.width = `${this.marker.width}px`, this.textBlockEditorContainer.style.height = `${t}px`, this.textBlockEditor.width = this.marker.width, this.textBlockEditor.height = t;
1849
+ }
1850
+ }
1851
+ }
1852
+ class ut extends W {
1853
+ constructor() {
1854
+ super(...arguments), this.manipulationStartCurveX = 0, this.manipulationStartCurveY = 0;
1855
+ }
1856
+ ownsTarget(t) {
1857
+ var i;
1858
+ return !(!super.ownsTarget(t) && !(!((i = this.curveGrip) === null || i === void 0) && i.ownsTarget(t)));
1859
+ }
1860
+ pointerDown(t, i, e) {
1861
+ var s;
1862
+ this.state === "new" && (this.marker.curveX = t.x, this.marker.curveY = t.y), this.manipulationStartCurveX = this.marker.curveX, this.manipulationStartCurveY = this.marker.curveY, super.pointerDown(t, i, e), this.state !== "new" && this.state !== "creating" && (i && (!((s = this.curveGrip) === null || s === void 0) && s.ownsTarget(i)) && (this.activeGrip = this.curveGrip), this.activeGrip ? this._state = "resize" : this._state = "move");
1863
+ }
1864
+ resize(t) {
1865
+ super.resize(t), this.activeGrip === this.curveGrip && (this.marker.curveX = t.x, this.marker.curveY = t.y, this.marker.adjustVisual(), this.adjustControlBox()), this.state === "creating" && (this.marker.curveX = this.marker.x1 + (this.marker.x2 - this.marker.x1) / 2, this.marker.curveY = this.marker.y1 + (this.marker.y2 - this.marker.y1) / 2);
1866
+ }
1867
+ manipulate(t, i) {
1868
+ this.state === "move" && (this.marker.curveX = this.manipulationStartCurveX + t.x - this.manipulationStartX, this.marker.curveY = this.manipulationStartCurveY + t.y - this.manipulationStartY), super.manipulate(t, i);
1869
+ }
1870
+ setupControlBox() {
1871
+ super.setupControlBox();
1872
+ const t = 1 / this.zoomLevel;
1873
+ this.curveControlLine1 = r.createLine(this.marker.x1, this.marker.y1, this.marker.curveX, this.marker.curveY, [["stroke", "black"], ["stroke-width", t.toString()], ["stroke-opacity", "0.5"], ["stroke-dasharray", "3, 2"], ["fill", "transparent"], ["pointer-events", "none"]]), this.curveControlLine2 = r.createLine(this.marker.x2, this.marker.y2, this.marker.curveX, this.marker.curveY, [["stroke", "black"], ["stroke-width", t.toString()], ["stroke-opacity", "0.5"], ["stroke-dasharray", "3, 2"], ["fill", "transparent"], ["pointer-events", "none"]]), this._controlBox.insertBefore(this.curveControlLine1, this._controlBox.firstChild), this._controlBox.insertBefore(this.curveControlLine2, this._controlBox.firstChild);
1874
+ }
1875
+ adjustControlBox() {
1876
+ super.adjustControlBox();
1877
+ const t = 1 / this.zoomLevel;
1878
+ this.curveControlLine1 && this.curveControlLine2 && this.curveGrip && (this.curveControlLine1.setAttribute("x1", this.marker.x1.toString()), this.curveControlLine1.setAttribute("y1", this.marker.y1.toString()), this.curveControlLine1.setAttribute("x2", this.marker.curveX.toString()), this.curveControlLine1.setAttribute("y2", this.marker.curveY.toString()), this.curveControlLine1.setAttribute("stroke-width", t.toString()), this.curveControlLine2.setAttribute("x1", this.marker.x2.toString()), this.curveControlLine2.setAttribute("y1", this.marker.y2.toString()), this.curveControlLine2.setAttribute("x2", this.marker.curveX.toString()), this.curveControlLine2.setAttribute("y2", this.marker.curveY.toString()), this.curveControlLine2.setAttribute("stroke-width", t.toString()), this.curveGrip.zoomLevel = this.zoomLevel);
1879
+ }
1880
+ addControlGrips() {
1881
+ super.addControlGrips(), this.curveGrip = this.createGrip(), this.curveGrip.zoomLevel = this.zoomLevel, this.positionGrips();
1882
+ }
1883
+ positionGrips() {
1884
+ if (super.positionGrips(), this.curveGrip) {
1885
+ const t = this.curveGrip.gripSize;
1886
+ this.positionGrip(this.curveGrip.visual, this.marker.curveX - t / 2, this.marker.curveY - t / 2);
1887
+ }
1888
+ }
1889
+ }
1890
+ class ct extends HTMLElement {
1891
+ get targetWidth() {
1892
+ return this._targetWidth;
1893
+ }
1894
+ set targetWidth(t) {
1895
+ this._targetWidth = t, this.setMainCanvasSize();
1896
+ }
1897
+ get targetHeight() {
1898
+ return this._targetHeight;
1899
+ }
1900
+ set targetHeight(t) {
1901
+ this._targetHeight = t, this.setMainCanvasSize();
1902
+ }
1903
+ get currentMarkerEditor() {
1904
+ return this._currentMarkerEditor;
1905
+ }
1906
+ get selectedMarkerEditors() {
1907
+ return this._selectedMarkerEditors;
1908
+ }
1909
+ get targetImage() {
1910
+ return this._targetImage;
1911
+ }
1912
+ set targetImage(t) {
1913
+ this._targetImage = t, this._targetImageLoaded = !1, t !== void 0 && this.addTargetImage();
1914
+ }
1915
+ get zoomLevel() {
1916
+ return this._zoomLevel;
1917
+ }
1918
+ set zoomLevel(t) {
1919
+ const i = this._zoomLevel;
1920
+ this._zoomLevel = t, this._canvasContainer && this._contentContainer && this._mainCanvas && this._overlayContainer && (this._panX = this._panX * t / i, this._panY = this._panY * t / i, this.applyTransform(), this.adjustEditorsZoom());
1921
+ }
1922
+ autoZoom() {
1923
+ if (!this._autoZoomIn && !this._autoZoomOut || !this._canvasContainer || this._targetWidth <= 0 || this._targetHeight <= 0) return;
1924
+ const t = this._canvasContainer.clientWidth, i = this._canvasContainer.clientHeight;
1925
+ if (t <= 0 || i <= 0) return;
1926
+ const e = t / this._targetWidth, s = i / this._targetHeight, a = Math.min(e, s);
1927
+ (a > 1 && this._autoZoomIn || a < 1 && this._autoZoomOut) && (this._panX = 0, this._panY = 0, this.zoomLevel = a);
1928
+ }
1929
+ applyTransform() {
1930
+ this._transformContainer && (this._transformContainer.style.transform = `translate(${this._panX}px, ${this._panY}px) scale(${this._zoomLevel})`);
1931
+ }
1932
+ panTo(t) {
1933
+ this._panX -= this.prevPanPoint.x - t.x, this._panY -= this.prevPanPoint.y - t.y, this.applyTransform(), this.prevPanPoint = t;
1934
+ }
1935
+ getPinchDistance() {
1936
+ const t = Array.from(this.activePointers.values());
1937
+ if (t.length < 2) return 0;
1938
+ const i = t[1].x - t[0].x, e = t[1].y - t[0].y;
1939
+ return Math.sqrt(i * i + e * e);
1940
+ }
1941
+ getPinchMidpoint() {
1942
+ const t = Array.from(this.activePointers.values());
1943
+ return t.length < 2 ? { x: 0, y: 0 } : { x: (t[0].x + t[1].x) / 2, y: (t[0].y + t[1].y) / 2 };
1944
+ }
1945
+ get defaultFilter() {
1946
+ return this._defaultFilter;
1947
+ }
1948
+ set defaultFilter(t) {
1949
+ this._defaultFilter = t;
1950
+ }
1951
+ get autoZoomIn() {
1952
+ return this._autoZoomIn;
1953
+ }
1954
+ set autoZoomIn(t) {
1955
+ this._autoZoomIn = t;
1956
+ }
1957
+ get autoZoomOut() {
1958
+ return this._autoZoomOut;
1959
+ }
1960
+ set autoZoomOut(t) {
1961
+ this._autoZoomOut = t;
1962
+ }
1963
+ constructor() {
1964
+ super(), this.width = 0, this.height = 0, this._targetWidth = -1, this._targetHeight = -1, this.mode = "select", this._isInitialized = !1, this._selectedMarkerEditors = [], this._newMarkerOutline = r.createPath("", [["stroke", "#333"], ["stroke-width", "0.5"], ["stroke-dasharray", "2 5"], ["fill", "rgba(200,200,200,0.5)"], ["pointer-events", "none"]]), this._targetImageLoaded = !1, this.markerEditors = /* @__PURE__ */ new Map(), this.editors = [], this._zoomLevel = 1, this._panX = 0, this._panY = 0, this.prevPanPoint = { x: 0, y: 0 }, this.undoRedoManager = new ht(), this._autoZoomIn = !1, this._autoZoomOut = !1, this._defs = [], this.touchPoints = 0, this.isDragging = !1, this.isSelecting = !1, this.isPanning = !1, this.activePointers = /* @__PURE__ */ new Map(), this.isPinching = !1, this.prevPinchDistance = 0, this.prevPinchMidpoint = { x: 0, y: 0 }, this._marqueeSelectOutline = r.createRect(0, 0, [["stroke", "rgb(35, 35, 255)"], ["stroke-width", "1"], ["fill", "rgba(129, 129, 255, 0.3)"], ["pointer-events", "none"], ["cursor", "move"]]), this._marqueeSelectRect = new DOMRect(0, 0, 0, 0), this._manipulationStartX = 0, this._manipulationStartY = 0, this._stateToRestoreAddUndoStep = !0, this.markerEditors.set(k, X), this.markerEditors.set(P, X), this.markerEditors.set(v, W), this.markerEditors.set(x, rt), this.markerEditors.set(y, D), this.markerEditors.set(m, Z), this.markerEditors.set(C, N), this.markerEditors.set(S, N), this.markerEditors.set(V, N), this.markerEditors.set(f, nt), this.markerEditors.set(M, W), this.markerEditors.set(T, lt), this.markerEditors.set(B, U), this.markerEditors.set(L, U), this.markerEditors.set(z, U), this.markerEditors.set(G, dt), this.markerEditors.set(A, ut), this.markerEditors.set(w, D), this.connectedCallback = this.connectedCallback.bind(this), this.disconnectedCallback = this.disconnectedCallback.bind(this), this.createLayout = this.createLayout.bind(this), this.addMainCanvas = this.addMainCanvas.bind(this), this.setMainCanvasSize = this.setMainCanvasSize.bind(this), this.setEditingTargetSize = this.setEditingTargetSize.bind(this), this.initOverlay = this.initOverlay.bind(this), this.addTargetImage = this.addTargetImage.bind(this), this.attachEvents = this.attachEvents.bind(this), this.attachWindowEvents = this.attachWindowEvents.bind(this), this.detachEvents = this.detachEvents.bind(this), this.detachWindowEvents = this.detachWindowEvents.bind(this), this.onCanvasPointerDown = this.onCanvasPointerDown.bind(this), this.onCanvasDblClick = this.onCanvasDblClick.bind(this), this.onKeyUp = this.onKeyUp.bind(this), this.onPointerMove = this.onPointerMove.bind(this), this.onPointerOut = this.onPointerOut.bind(this), this.onPointerUp = this.onPointerUp.bind(this), this.createMarker = this.createMarker.bind(this), this.addNewMarker = this.addNewMarker.bind(this), this.markerCreated = this.markerCreated.bind(this), this.markerStateChanged = this.markerStateChanged.bind(this), this.deleteMarker = this.deleteMarker.bind(this), this.deleteSelectedMarkers = this.deleteSelectedMarkers.bind(this), this.switchToSelectMode = this.switchToSelectMode.bind(this), this.showOutline = this.showOutline.bind(this), this.hideOutline = this.hideOutline.bind(this), this.scaleMarkers = this.scaleMarkers.bind(this), this.adjustEditorsZoom = this.adjustEditorsZoom.bind(this), this.autoZoom = this.autoZoom.bind(this), this.getState = this.getState.bind(this), this.restoreState = this.restoreState.bind(this), this.undo = this.undo.bind(this), this.addUndoStep = this.addUndoStep.bind(this), this.undoStep = this.undoStep.bind(this), this.redo = this.redo.bind(this), this.redoStep = this.redoStep.bind(this), this.toggleLogo = this.toggleLogo.bind(this), this.addLogo = this.addLogo.bind(this), this.removeLogo = this.removeLogo.bind(this), this.adjustMarqueeSelectOutline = this.adjustMarqueeSelectOutline.bind(this), this.hideMarqueeSelectOutline = this.hideMarqueeSelectOutline.bind(this), this.addDefs = this.addDefs.bind(this), this.addDefaultFilterDefs = this.addDefaultFilterDefs.bind(this), this.attachShadow({ mode: "open" });
1965
+ }
1966
+ connectedCallback() {
1967
+ this.dispatchEvent(new CustomEvent("areainit", { detail: { markerArea: this } })), c.addKeyAddListener(this.toggleLogo), this.createLayout(), this.addMainCanvas(), this.initOverlay(), this.attachEvents(), this._isInitialized = !0, this.targetImage !== void 0 && this.addTargetImage(), this.setMainCanvasSize(), this.addDefaultFilterDefs(), this.toggleLogo(), this.addUndoStep(), this.dispatchEvent(new CustomEvent("areashow", { detail: { markerArea: this } }));
1968
+ }
1969
+ disconnectedCallback() {
1970
+ this.detachEvents();
1971
+ }
1972
+ createLayout() {
1973
+ var t;
1974
+ this.style.display = "flex", this.style.width = this.style.width !== "" ? this.style.width : "100%", this.style.height = this.style.height !== "" ? this.style.height : "100%", this.style.position = "relative", this._contentContainer = document.createElement("div"), this._contentContainer.style.display = "flex", this._contentContainer.style.position = "relative", this._contentContainer.style.flexGrow = "2", this._contentContainer.style.flexShrink = "1", this._contentContainer.style.overflow = "hidden", this._canvasContainer = document.createElement("div"), this._canvasContainer.style.touchAction = "none", this._canvasContainer.className = "canvas-container", this._canvasContainer.style.display = "flex", this._canvasContainer.style.flexGrow = "2", this._canvasContainer.style.flexShrink = "2", this._canvasContainer.style.justifyContent = "center", this._canvasContainer.style.alignItems = "center", this._canvasContainer.style.overflow = "hidden", this._canvasContainer.style.userSelect = "none", this._canvasContainer.addEventListener("wheel", (i) => {
1975
+ i.preventDefault(), this._panX -= i.deltaX, this._panY -= i.deltaY, this.applyTransform();
1976
+ }, { passive: !1 }), this._transformContainer = document.createElement("div"), this._transformContainer.style.display = "grid", this._transformContainer.style.gridTemplateColumns = "1fr", this._canvasContainer.appendChild(this._transformContainer), this._contentContainer.appendChild(this._canvasContainer), (t = this.shadowRoot) === null || t === void 0 || t.appendChild(this._contentContainer);
1977
+ }
1978
+ addMainCanvas() {
1979
+ var t, i;
1980
+ this.width = ((t = this._contentContainer) === null || t === void 0 ? void 0 : t.clientWidth) || 0, this.height = ((i = this._contentContainer) === null || i === void 0 ? void 0 : i.clientHeight) || 0, this._mainCanvas = document.createElementNS("http://www.w3.org/2000/svg", "svg"), this._mainCanvas.setAttribute("xmlns", "http://www.w3.org/2000/svg"), this.setMainCanvasSize(), this._mainCanvas.style.gridColumnStart = "1", this._mainCanvas.style.gridRowStart = "1", this._mainCanvas.style.pointerEvents = "auto", this.addDefsToMainCanvas(), this._groupLayer = r.createGroup(), this._mainCanvas.appendChild(this._groupLayer), this._transformContainer.appendChild(this._mainCanvas);
1981
+ }
1982
+ addDefsToMainCanvas() {
1983
+ var t;
1984
+ this._defsElement = r.createDefs(), (t = this._mainCanvas) === null || t === void 0 || t.appendChild(this._defsElement), this._defsElement.append(...this._defs);
1985
+ }
1986
+ setMainCanvasSize() {
1987
+ this._mainCanvas !== void 0 && this._targetHeight > 0 && this._targetWidth > 0 && (this._mainCanvas.style.width = `${this._targetWidth}px`, this._mainCanvas.style.height = `${this._targetHeight}px`, this._mainCanvas.setAttribute("width", `${this._targetWidth}`), this._mainCanvas.setAttribute("height", `${this._targetHeight}`), this._mainCanvas.setAttribute("viewBox", "0 0 " + this._targetWidth.toString() + " " + this._targetHeight.toString()), this.setEditingTargetSize());
1988
+ }
1989
+ setEditingTargetSize() {
1990
+ this._editingTarget !== void 0 && (this._editingTarget.width = this._targetWidth, this._editingTarget.height = this._targetHeight, this._editingTarget.style.width = `${this._targetWidth}px`, this._editingTarget.style.height = `${this._targetHeight}px`);
1991
+ }
1992
+ initOverlay() {
1993
+ this._overlayContainer = document.createElement("div"), this._overlayContainer.style.pointerEvents = "none", this._overlayContainer.style.display = "flex", this._overlayContainer.style.alignItems = "center", this._overlayContainer.style.justifyContent = "center", this._overlayContainer.style.gridRowStart = "1", this._overlayContainer.style.gridColumnStart = "1", this._transformContainer.appendChild(this._overlayContainer), this._overlayContentContainer = document.createElement("div"), this._overlayContentContainer.style.position = "relative", this._overlayContentContainer.style.display = "flex", this._overlayContainer.appendChild(this._overlayContentContainer);
1994
+ }
1995
+ addTargetImage() {
1996
+ this._isInitialized && this._editingTarget === void 0 && this.targetImage !== void 0 && this._canvasContainer !== void 0 && this._mainCanvas !== void 0 && (this._editingTarget = document.createElement("img"), this._targetWidth = this._targetWidth > 0 ? this._targetWidth : this.targetImage.clientWidth, this._targetHeight = this._targetHeight > 0 ? this._targetHeight : this.targetImage.clientHeight, this._editingTarget.addEventListener("load", (t) => {
1997
+ if (this._editingTarget !== void 0) {
1998
+ if (this._targetHeight <= 0 || this._targetWidth <= 0) {
1999
+ const i = t.target, e = i.naturalWidth / i.naturalHeight, s = this._targetWidth > 0 ? this._targetWidth : this._targetHeight > 0 ? this._targetHeight * e : i.clientWidth > 0 ? i.clientWidth : i.naturalWidth, a = this._targetHeight > 0 ? this._targetHeight : this._targetWidth > 0 ? this._targetWidth / e : i.clientHeight > 0 ? i.clientHeight : i.naturalHeight;
2000
+ this._targetWidth = s, this._targetHeight = a;
2001
+ }
2002
+ this._editingTarget.width = this._targetWidth, this._editingTarget.height = this._targetHeight, this._editingTarget.style.width = `${this._targetWidth}px`, this._editingTarget.style.height = `${this._targetHeight}px`, this._editingTarget.style.gridColumnStart = "1", this._editingTarget.style.gridRowStart = "1", this.setMainCanvasSize(), this._targetImageLoaded = !0, this._stateToRestore !== void 0 && this.restoreState(this._stateToRestore, this._stateToRestoreAddUndoStep);
2003
+ }
2004
+ this.zoomLevel = this._zoomLevel, this.autoZoom();
2005
+ }), this._editingTarget.src = this.targetImage.src, this._transformContainer.insertBefore(this._editingTarget, this._mainCanvas));
2006
+ }
2007
+ addDefaultFilterDefs() {
2008
+ this.addDefs(...Y.getDefaultFilterSet());
2009
+ }
2010
+ registerMarkerType(t, i) {
2011
+ this.markerEditors.set(t, i);
2012
+ }
2013
+ createMarker(t) {
2014
+ let i = k;
2015
+ i = typeof t == "string" ? this.getMarkerTypeByName(t) || k : t;
2016
+ const e = this.markerEditors.get(i);
2017
+ return e && this._mainCanvas && (this.setCurrentEditor(), this.deselectEditor(), this.addUndoStep(), this._currentMarkerEditor = this.addNewMarker(e, i), this._currentMarkerEditor.onMarkerCreated = this.markerCreated, this._currentMarkerEditor.onStateChanged = this.markerStateChanged, this._currentMarkerEditor.creationStyle === "drop" ? this._mainCanvas.style.cursor = "move" : this._mainCanvas.style.cursor = "crosshair", this.dispatchEvent(new CustomEvent("markercreating", { detail: { markerArea: this, markerEditor: this._currentMarkerEditor } }))), this._currentMarkerEditor;
2018
+ }
2019
+ addNewMarker(t, i) {
2020
+ if (this._mainCanvas === void 0) throw new Error("Main canvas is not initialized.");
2021
+ const e = r.createGroup();
2022
+ this.defaultFilter && i.applyDefaultFilter && e.setAttribute("filter", this.defaultFilter), this._mainCanvas.appendChild(e);
2023
+ const s = new t({ container: e, overlayContainer: this._overlayContentContainer, markerType: i });
2024
+ return s.zoomLevel = this.zoomLevel, s;
2025
+ }
2026
+ markerCreated(t) {
2027
+ if (this._mainCanvas) {
2028
+ if (this.mode = "select", this.editors.push(t), this.setCurrentEditor(t), t.continuousCreation) {
2029
+ const i = this.createMarker(t.marker.typeName);
2030
+ t.is(D) && (i != null && i.is(D)) && (i.strokeColor = t.strokeColor, i.strokeWidth = t.strokeWidth, i.strokeDasharray = t.strokeDasharray);
2031
+ } else this._mainCanvas.style.cursor = "default";
2032
+ this.addUndoStep(), this.dispatchEvent(new CustomEvent("markercreate", { detail: { markerArea: this, markerEditor: t } }));
2033
+ }
2034
+ }
2035
+ markerStateChanged(t) {
2036
+ this.addUndoStep(), this.dispatchEvent(new CustomEvent("markerchange", { detail: { markerArea: this, markerEditor: t } }));
2037
+ }
2038
+ deleteMarker(t, i = !1) {
2039
+ var e;
2040
+ this.editors.indexOf(t) >= 0 && (this.dispatchEvent(new CustomEvent("markerbeforedelete", { detail: { markerArea: this, markerEditor: t } })), (e = this._mainCanvas) === null || e === void 0 || e.removeChild(t.container), t.dispose(), this.editors.splice(this.editors.indexOf(t), 1), this._selectedMarkerEditors.splice(this._selectedMarkerEditors.indexOf(t), 1), i || this.addUndoStep(), this.dispatchEvent(new CustomEvent("markerdelete", { detail: { markerArea: this, markerEditor: t } })));
2041
+ }
2042
+ deleteSelectedMarkers() {
2043
+ const t = [...this._selectedMarkerEditors];
2044
+ t.forEach((i, e) => this.deleteMarker(i, e !== t.length - 1)), this.hideMarqueeSelectOutline();
2045
+ }
2046
+ setCurrentEditor(t) {
2047
+ this._currentMarkerEditor !== t && this._currentMarkerEditor !== void 0 && this.deselectEditor(this._currentMarkerEditor), this._currentMarkerEditor = t, this._currentMarkerEditor === void 0 || this._currentMarkerEditor.isSelected || this._currentMarkerEditor.state !== "new" && (this.selectEditor(this._currentMarkerEditor), this._currentMarkerEditor.select(!1));
2048
+ }
2049
+ selectEditor(t) {
2050
+ this._selectedMarkerEditors.indexOf(t) < 0 && (this._selectedMarkerEditors.length > 0 && this._selectedMarkerEditors[0].select(!0), this._selectedMarkerEditors.push(t), t.select(!0), this.dispatchEvent(new CustomEvent("markerselect", { detail: { markerArea: this, markerEditor: t } })));
2051
+ }
2052
+ deselectEditor(t) {
2053
+ const i = this._selectedMarkerEditors.length;
2054
+ if (t && t.state === "creating" && t.deselect(), i > 0) {
2055
+ const e = t ?? this._selectedMarkerEditors[this._selectedMarkerEditors.length - 1];
2056
+ if (t === void 0) this._selectedMarkerEditors.forEach((s) => s.deselect()), this._selectedMarkerEditors.splice(0);
2057
+ else {
2058
+ const s = this._selectedMarkerEditors.indexOf(t);
2059
+ s >= 0 && (this._selectedMarkerEditors.splice(s, 1), t.deselect());
2060
+ }
2061
+ this.dispatchEvent(new CustomEvent("markerdeselect", { detail: { markerArea: this, markerEditor: e } }));
2062
+ }
2063
+ }
2064
+ onCanvasPointerDown(t) {
2065
+ var i;
2066
+ if (this.activePointers.set(t.pointerId, { x: t.clientX, y: t.clientY }), this._manipulationStartX = t.clientX, this._manipulationStartY = t.clientY, this.touchPoints++, this.touchPoints === 1 && (this.leadPointerId = t.pointerId), t.pointerType === "touch" && this.touchPoints === 1 || t.pointerType !== "touch" && t.button === 0 && !t.altKey) if (this._currentMarkerEditor === void 0 || this._currentMarkerEditor.state !== "new" && this._currentMarkerEditor.state !== "creating") {
2067
+ if (this.mode === "select") {
2068
+ const e = r.clientToLocalCoordinates(this._mainCanvas, t.clientX, t.clientY, this.zoomLevel), s = this.editors.find((a) => a.ownsTarget(t.target));
2069
+ s !== void 0 ? (this.isDragging = !0, t.shiftKey ? (this.selectEditor(s), this.initializeMarqueeSelection(e)) : s.isSelected || (this.deselectEditor(), this.setCurrentEditor(s)), this._selectedMarkerEditors.forEach((a) => {
2070
+ var h;
2071
+ return a.pointerDown(e, (h = t.target) !== null && h !== void 0 ? h : void 0, t);
2072
+ })) : t.target === this._marqueeSelectOutline && this._selectedMarkerEditors.length > 1 ? (this.isDragging = !0, this._selectedMarkerEditors.forEach((a) => {
2073
+ var h;
2074
+ return a.pointerDown(e, (h = t.target) !== null && h !== void 0 ? h : void 0, t);
2075
+ })) : (this.setCurrentEditor(), this.deselectEditor(), this.isSelecting = !0, this.isDragging = !0, this.initializeMarqueeSelection(e), this.prevPanPoint = { x: t.clientX, y: t.clientY });
2076
+ }
2077
+ } else this.isDragging = !0, this._currentMarkerEditor.pointerDown(r.clientToLocalCoordinates(this._mainCanvas, t.clientX, t.clientY, this.zoomLevel), (i = t.target) !== null && i !== void 0 ? i : void 0, t);
2078
+ else t.pointerType !== "touch" && (t.button === 0 && t.altKey || t.button === 1) ? (this.isDragging = !0, this.isPanning = !0, this.prevPanPoint = { x: t.clientX, y: t.clientY }, this._mainCanvas && (this._mainCanvas.style.cursor = "grabbing")) : t.pointerType === "touch" && this.touchPoints === 2 && (this.isPinching = !0, this.prevPinchDistance = this.getPinchDistance(), this.prevPinchMidpoint = this.getPinchMidpoint());
2079
+ }
2080
+ initializeMarqueeSelection(t) {
2081
+ this._marqueeSelectRect.x = t.x, this._marqueeSelectRect.y = t.y, this._marqueeSelectRect.width = 0, this._marqueeSelectRect.height = 0, r.setAttributes(this._marqueeSelectOutline, [["x", t.x.toString()], ["y", t.y.toString()], ["width", "0"], ["height", "0"]]), this._groupLayer && !this._groupLayer.contains(this._marqueeSelectOutline) && this._groupLayer.appendChild(this._marqueeSelectOutline);
2082
+ }
2083
+ onCanvasDblClick(t) {
2084
+ var i;
2085
+ if (this.mode === "select") {
2086
+ const e = this.editors.find((s) => s.ownsTarget(t.target));
2087
+ e !== void 0 && e !== this._currentMarkerEditor && this.setCurrentEditor(e), this._currentMarkerEditor !== void 0 ? this._currentMarkerEditor.dblClick(r.clientToLocalCoordinates(this._mainCanvas, t.clientX, t.clientY, this.zoomLevel), (i = t.target) !== null && i !== void 0 ? i : void 0, t) : this.setCurrentEditor();
2088
+ }
2089
+ }
2090
+ onPointerMove(t) {
2091
+ var i;
2092
+ if (this.activePointers.set(t.pointerId, { x: t.clientX, y: t.clientY }), t.pointerType === "touch" && this.touchPoints === 1 || t.pointerType !== "touch" && this.isDragging && !t.altKey) {
2093
+ const e = r.clientToLocalCoordinates(this._mainCanvas, t.clientX, t.clientY, this.zoomLevel);
2094
+ if (this._currentMarkerEditor !== void 0 || this._selectedMarkerEditors.length > 0) this._currentMarkerEditor !== void 0 && this._currentMarkerEditor.state === "edit" || t.preventDefault(), this._currentMarkerEditor !== void 0 || this._selectedMarkerEditors.length > 0 ? (this.showOutline(e), this._selectedMarkerEditors.length > 0 ? this._selectedMarkerEditors.forEach((s) => s.manipulate(e, t)) : (i = this._currentMarkerEditor) === null || i === void 0 || i.manipulate(e, t)) : this.zoomLevel > 1 && this.panTo({ x: t.clientX, y: t.clientY }), this.adjustMarqueeSelectOutline();
2095
+ else if (this.isSelecting) {
2096
+ const s = r.clientToLocalCoordinates(this._mainCanvas, this._manipulationStartX, this._manipulationStartY, this.zoomLevel);
2097
+ this._marqueeSelectRect.x = Math.min(e.x, s.x), this._marqueeSelectRect.y = Math.min(e.y, s.y), this._marqueeSelectRect.width = Math.abs(t.clientX - this._manipulationStartX) / this.zoomLevel, this._marqueeSelectRect.height = Math.abs(t.clientY - this._manipulationStartY) / this.zoomLevel, r.setAttributes(this._marqueeSelectOutline, [["x", `${this._marqueeSelectRect.x}`], ["y", `${this._marqueeSelectRect.y}`], ["width", `${this._marqueeSelectRect.width}`], ["height", `${this._marqueeSelectRect.height}`]]);
2098
+ }
2099
+ } else if (t.pointerType !== "touch" && this.isPanning) this.panTo({ x: t.clientX, y: t.clientY });
2100
+ else if (t.pointerType === "touch" && this.touchPoints === 2 && this.isPinching) {
2101
+ const e = this.getPinchDistance(), s = this.getPinchMidpoint();
2102
+ if (this._panX += s.x - this.prevPinchMidpoint.x, this._panY += s.y - this.prevPinchMidpoint.y, this.prevPinchDistance > 0 && this._canvasContainer) {
2103
+ const a = e / this.prevPinchDistance, h = Math.max(0.1, Math.min(10, this._zoomLevel * a)), o = h / this._zoomLevel, n = this._canvasContainer.getBoundingClientRect(), l = s.x - (n.left + n.width / 2), u = s.y - (n.top + n.height / 2);
2104
+ this._panX = l * (1 - o) + this._panX * o, this._panY = u * (1 - o) + this._panY * o, this._zoomLevel = h, this.applyTransform(), this.adjustEditorsZoom();
2105
+ }
2106
+ this.prevPinchDistance = e, this.prevPinchMidpoint = Object.assign({}, s);
2107
+ }
2108
+ }
2109
+ showOutline(t) {
2110
+ if (this._currentMarkerEditor && this._currentMarkerEditor.creationStyle === "drop" && this._currentMarkerEditor.state === "new") {
2111
+ this._mainCanvas === void 0 || this._mainCanvas.contains(this._newMarkerOutline) || this._mainCanvas.appendChild(this._newMarkerOutline);
2112
+ const i = this._currentMarkerEditor.marker.defaultSize;
2113
+ r.setAttributes(this._newMarkerOutline, [["d", this._currentMarkerEditor.marker.getOutline()]]), this._newMarkerOutline.style.transform = `translate(${t.x - i.width / 2}px, ${t.y - i.height / 2}px)`;
2114
+ }
2115
+ }
2116
+ hideOutline() {
2117
+ var t;
2118
+ !((t = this._mainCanvas) === null || t === void 0) && t.contains(this._newMarkerOutline) && this._mainCanvas.removeChild(this._newMarkerOutline);
2119
+ }
2120
+ onPointerUp(t) {
2121
+ var i;
2122
+ if (this.activePointers.delete(t.pointerId), this.touchPoints > 0 && (this.touchPoints--, this.touchPoints === 0 && (this.leadPointerId = void 0)), this.touchPoints < 2 && (this.isPinching = !1, this.prevPinchDistance = 0), this.touchPoints === 1 && this.activePointers.size === 1 && (this.prevPanPoint = Array.from(this.activePointers.values())[0]), this.touchPoints === 0) {
2123
+ if (this._mainCanvas && (this._mainCanvas.style.cursor = "default"), this.isDragging && (this._currentMarkerEditor !== void 0 || this._selectedMarkerEditors.length > 0)) {
2124
+ const e = r.clientToLocalCoordinates(this._mainCanvas, t.clientX, t.clientY, this.zoomLevel);
2125
+ this._selectedMarkerEditors.length > 1 ? (this._selectedMarkerEditors.forEach((s) => s.pointerUp(e, t)), this.adjustMarqueeSelectOutline()) : (i = this._currentMarkerEditor) === null || i === void 0 || i.pointerUp(e, t), this.hideOutline(), this.addUndoStep();
2126
+ } else if (this.isSelecting && (this.finishMarqueeSelection(), this._selectedMarkerEditors.length < 2 && (this.hideMarqueeSelectOutline(), this._selectedMarkerEditors.length === 1))) {
2127
+ const e = this._selectedMarkerEditors[0];
2128
+ this.deselectEditor(), this.setCurrentEditor(e);
2129
+ }
2130
+ }
2131
+ this.isDragging = !1, this.isSelecting = !1, this.isPanning = !1, this.touchPoints === 0 && (this.isPinching = !1, this.prevPinchDistance = 0);
2132
+ }
2133
+ finishMarqueeSelection() {
2134
+ this.deselectEditor(), this.editors.forEach((t) => {
2135
+ const i = t.marker.getBBox();
2136
+ i.x < this._marqueeSelectRect.x + this._marqueeSelectRect.width && i.x + i.width > this._marqueeSelectRect.x && i.y < this._marqueeSelectRect.y + this._marqueeSelectRect.height && i.y + i.height > this._marqueeSelectRect.y && this.selectEditor(t);
2137
+ }), this.adjustMarqueeSelectOutline();
2138
+ }
2139
+ adjustMarqueeSelectOutline() {
2140
+ let t = Number.MAX_VALUE, i = Number.MAX_VALUE, e = 0, s = 0;
2141
+ this._selectedMarkerEditors.forEach((a) => {
2142
+ const h = a.marker.getBBox();
2143
+ t = Math.min(t, h.x), i = Math.min(i, h.y), e = Math.max(e, h.x + h.width), s = Math.max(s, h.y + h.height);
2144
+ }), this._selectedMarkerEditors.length > 1 ? (this._marqueeSelectRect.x = t, this._marqueeSelectRect.y = i, this._marqueeSelectRect.width = e - t, this._marqueeSelectRect.height = s - i, r.setAttributes(this._marqueeSelectOutline, [["x", `${this._marqueeSelectRect.x}`], ["y", `${this._marqueeSelectRect.y}`], ["width", `${this._marqueeSelectRect.width}`], ["height", `${this._marqueeSelectRect.height}`], ["pointer-events", ""]])) : this.hideMarqueeSelectOutline();
2145
+ }
2146
+ hideMarqueeSelectOutline() {
2147
+ this._groupLayer && this._groupLayer.contains(this._marqueeSelectOutline) && this._groupLayer.removeChild(this._marqueeSelectOutline);
2148
+ }
2149
+ onPointerOut(t) {
2150
+ this.activePointers.delete(t.pointerId), this.touchPoints > 0 && this.touchPoints--, this.hideOutline();
2151
+ }
2152
+ onKeyUp(t) {
2153
+ this._currentMarkerEditor !== void 0 && (t.key === "Delete" || t.key);
2154
+ }
2155
+ attachEvents() {
2156
+ var t, i, e;
2157
+ this.hasAttribute("tabindex") || this.setAttribute("tabindex", "0"), (t = this._mainCanvas) === null || t === void 0 || t.addEventListener("pointerdown", this.onCanvasPointerDown), (i = this._mainCanvas) === null || i === void 0 || i.addEventListener("touchmove", (s) => s.preventDefault()), (e = this._mainCanvas) === null || e === void 0 || e.addEventListener("dblclick", this.onCanvasDblClick), this._marqueeSelectOutline.addEventListener("dblclick", (s) => {
2158
+ s.preventDefault(), s.stopPropagation(), this.deselectEditor(), this.hideMarqueeSelectOutline();
2159
+ }), this.attachWindowEvents();
2160
+ }
2161
+ attachWindowEvents() {
2162
+ window.addEventListener("pointermove", this.onPointerMove), window.addEventListener("pointerup", this.onPointerUp), window.addEventListener("pointerleave", this.onPointerUp), window.addEventListener("pointercancel", this.onPointerOut), window.addEventListener("pointerout", this.onPointerOut), window.addEventListener("keyup", this.onKeyUp);
2163
+ }
2164
+ detachEvents() {
2165
+ this.detachWindowEvents();
2166
+ }
2167
+ detachWindowEvents() {
2168
+ }
2169
+ getMarkerTypeByName(t) {
2170
+ let i;
2171
+ return this.markerEditors.forEach((e, s) => {
2172
+ s.typeName === t && (i = s);
2173
+ }), i;
2174
+ }
2175
+ switchToSelectMode() {
2176
+ this.setCurrentEditor(), this._mainCanvas && (this._mainCanvas.style.cursor = "default");
2177
+ }
2178
+ getState() {
2179
+ const t = { version: 3, width: this.targetWidth, height: this.targetHeight, defaultFilter: this.defaultFilter, markers: this.editors.map((i) => i.getState()) };
2180
+ return JSON.parse(JSON.stringify(t));
2181
+ }
2182
+ restoreState(t, i = !0) {
2183
+ if (!this._targetImageLoaded) return this._stateToRestore = t, void (this._stateToRestoreAddUndoStep = i);
2184
+ this._stateToRestore = void 0, this._stateToRestoreAddUndoStep = !0;
2185
+ const e = JSON.parse(JSON.stringify(t));
2186
+ if (this.editors.splice(0), this._mainCanvas && this._groupLayer) {
2187
+ for (this.hideMarqueeSelectOutline(), this.deselectEditor(); this._mainCanvas.lastChild; ) this._mainCanvas.removeChild(this._mainCanvas.lastChild);
2188
+ this.addDefsToMainCanvas(), this._mainCanvas.appendChild(this._groupLayer);
2189
+ }
2190
+ this.defaultFilter === void 0 && e.defaultFilter && (this.defaultFilter = e.defaultFilter), e.markers.forEach((s) => {
2191
+ const a = this.getMarkerTypeByName(s.typeName);
2192
+ if (a !== void 0) {
2193
+ const h = this.markerEditors.get(a);
2194
+ if (h !== void 0) {
2195
+ const o = this.addNewMarker(h, a);
2196
+ o.restoreState(s), this.editors.push(o);
2197
+ }
2198
+ }
2199
+ }), e.width && e.height && (e.width !== this.targetWidth || e.height !== this.targetHeight) && this.scaleMarkers(this.targetWidth / e.width, this.targetHeight / e.height), i && this.addUndoStep(!0), this.dispatchEvent(new CustomEvent("arearestorestate", { detail: { markerArea: this } }));
2200
+ }
2201
+ scaleMarkers(t, i) {
2202
+ let e;
2203
+ e = this._currentMarkerEditor, this.setCurrentEditor(), this.editors.forEach((s) => {
2204
+ s !== this._currentMarkerEditor && s.scale(t, i);
2205
+ }), e !== void 0 && this.setCurrentEditor(e);
2206
+ }
2207
+ adjustEditorsZoom() {
2208
+ this.editors.forEach((t) => {
2209
+ t.zoomLevel = this._zoomLevel;
2210
+ });
2211
+ }
2212
+ toggleLogo() {
2213
+ c.isLicensed("MJS3E") || c.isLicensed("MJS3") ? this.removeLogo() : this.addLogo();
2214
+ }
2215
+ addLogo() {
2216
+ var t, i;
2217
+ this._logoUI !== void 0 && ((t = this._contentContainer) === null || t === void 0 || t.removeChild(this._logoUI)), this._logoUI = document.createElement("div"), this._logoUI.style.display = "inline-block", this._logoUI.style.margin = "0px", this._logoUI.style.padding = "0px", this._logoUI.style.fill = "#333333", this._logoUI.style.opacity = "0.5";
2218
+ const e = this._logoUI;
2219
+ this._logoUI.addEventListener("mouseenter", () => {
2220
+ e.style.opacity = "1";
2221
+ }), this._logoUI.addEventListener("mouseleave", () => {
2222
+ e.style.opacity = "0.5";
2223
+ });
2224
+ const s = document.createElement("a");
2225
+ s.href = "https://markerjs.com/?utm_source=markerjs3&utm_medium=logo&utm_content=marker_area", s.target = "_blank", s.innerHTML = it, s.title = "Powered by marker.js", s.style.display = "grid", s.style.alignItems = "center", s.style.justifyItems = "center", s.style.padding = "3px", s.style.width = "20px", s.style.height = "20px", s.style.cursor = "pointer", this._logoUI.appendChild(s), (i = this._contentContainer) === null || i === void 0 || i.appendChild(this._logoUI), this._logoUI.style.position = "absolute", this._logoUI.style.pointerEvents = "all", this.positionLogo();
2226
+ }
2227
+ removeLogo() {
2228
+ this._contentContainer && this._logoUI !== void 0 && this._contentContainer.contains(this._logoUI) && this._contentContainer.removeChild(this._logoUI);
2229
+ }
2230
+ positionLogo() {
2231
+ this._logoUI && this._contentContainer && (this._logoUI.style.left = "20px", this._logoUI.style.bottom = "20px");
2232
+ }
2233
+ get isUndoPossible() {
2234
+ return !(!this.undoRedoManager || !this.undoRedoManager.isUndoPossible);
2235
+ }
2236
+ get isRedoPossible() {
2237
+ return !(!this.undoRedoManager || !this.undoRedoManager.isRedoPossible);
2238
+ }
2239
+ addUndoStep(t = !1) {
2240
+ if (this._currentMarkerEditor === void 0 || this._currentMarkerEditor.state !== "edit") {
2241
+ const i = this.getState(), e = this.undoRedoManager.getLastUndoStep();
2242
+ t || !e || e.width === i.width && e.height === i.height ? this.undoRedoManager.addUndoStep(i) && this.dispatchEvent(new CustomEvent("areastatechange", { detail: { markerArea: this } })) : (this.undoRedoManager.replaceLastUndoStep(i), this.dispatchEvent(new CustomEvent("areastatechange", { detail: { markerArea: this } })));
2243
+ }
2244
+ }
2245
+ undo() {
2246
+ this.undoStep();
2247
+ }
2248
+ undoStep() {
2249
+ const t = this.undoRedoManager.undo();
2250
+ t !== void 0 && this.restoreState(t, !1);
2251
+ }
2252
+ redo() {
2253
+ this.redoStep();
2254
+ }
2255
+ redoStep() {
2256
+ const t = this.undoRedoManager.redo();
2257
+ t !== void 0 && (this.restoreState(t, !1), this.dispatchEvent(new CustomEvent("areastatechange", { detail: { markerArea: this } })));
2258
+ }
2259
+ addDefs(...t) {
2260
+ this._defs.push(...t), this._defsElement && this._defsElement.append(...t);
2261
+ }
2262
+ addEventListener(t, i, e) {
2263
+ super.addEventListener(t, i, e);
2264
+ }
2265
+ removeEventListener(t, i, e) {
2266
+ super.removeEventListener(t, i, e);
2267
+ }
2268
+ }
2269
+ window && window.customElements && window.customElements.get("mjs-marker-area") === void 0 && window.customElements.define("mjs-marker-area", ct);
2270
+ class pt extends HTMLElement {
2271
+ get targetWidth() {
2272
+ return this._targetWidth;
2273
+ }
2274
+ set targetWidth(t) {
2275
+ this._targetWidth = t, this.setMainCanvasSize();
2276
+ }
2277
+ get targetHeight() {
2278
+ return this._targetHeight;
2279
+ }
2280
+ set targetHeight(t) {
2281
+ this._targetHeight = t, this.setMainCanvasSize();
2282
+ }
2283
+ get targetImage() {
2284
+ return this._targetImage;
2285
+ }
2286
+ set targetImage(t) {
2287
+ this._targetImage = t, this._targetImageLoaded = !1, t !== void 0 && this.addTargetImage();
2288
+ }
2289
+ get zoomLevel() {
2290
+ return this._zoomLevel;
2291
+ }
2292
+ set zoomLevel(t) {
2293
+ const i = this._zoomLevel;
2294
+ this._zoomLevel = t, this._canvasContainer && this._contentContainer && this._mainCanvas && (this._panX = this._panX * t / i, this._panY = this._panY * t / i, this.applyTransform());
2295
+ }
2296
+ autoZoom() {
2297
+ if (!this._autoZoomIn && !this._autoZoomOut || !this._canvasContainer || this._targetWidth <= 0 || this._targetHeight <= 0) return;
2298
+ const t = this._canvasContainer.clientWidth, i = this._canvasContainer.clientHeight;
2299
+ if (t <= 0 || i <= 0) return;
2300
+ const e = t / this._targetWidth, s = i / this._targetHeight, a = Math.min(e, s);
2301
+ (a > 1 && this._autoZoomIn || a < 1 && this._autoZoomOut) && (this._panX = 0, this._panY = 0, this.zoomLevel = a);
2302
+ }
2303
+ get defaultFilter() {
2304
+ return this._defaultFilter;
2305
+ }
2306
+ set defaultFilter(t) {
2307
+ this._defaultFilter = t;
2308
+ }
2309
+ get autoZoomIn() {
2310
+ return this._autoZoomIn;
2311
+ }
2312
+ set autoZoomIn(t) {
2313
+ this._autoZoomIn = t;
2314
+ }
2315
+ get autoZoomOut() {
2316
+ return this._autoZoomOut;
2317
+ }
2318
+ set autoZoomOut(t) {
2319
+ this._autoZoomOut = t;
2320
+ }
2321
+ applyTransform() {
2322
+ this._transformContainer && (this._transformContainer.style.transform = `translate(${this._panX}px, ${this._panY}px) scale(${this._zoomLevel})`);
2323
+ }
2324
+ constructor() {
2325
+ super(), this.width = 0, this.height = 0, this._targetWidth = -1, this._targetHeight = -1, this._targetImageLoaded = !1, this.markerTypes = [], this.markers = [], this._zoomLevel = 1, this._autoZoomIn = !1, this._autoZoomOut = !1, this._isInitialized = !1, this._defs = [], this._panX = 0, this._panY = 0, this.prevPanPoint = { x: 0, y: 0 }, this.touchPoints = 0, this.activePointers = /* @__PURE__ */ new Map(), this.isPinching = !1, this.prevPinchDistance = 0, this.prevPinchMidpoint = { x: 0, y: 0 }, this.markerTypes = [k, v, f, M, x, y, m, C, S, T, P, V, B, L, z, G, A, w], this.connectedCallback = this.connectedCallback.bind(this), this.disconnectedCallback = this.disconnectedCallback.bind(this), this.createLayout = this.createLayout.bind(this), this.addMainCanvas = this.addMainCanvas.bind(this), this.setMainCanvasSize = this.setMainCanvasSize.bind(this), this.setEditingTargetSize = this.setEditingTargetSize.bind(this), this.addTargetImage = this.addTargetImage.bind(this), this.attachMarkerEvents = this.attachMarkerEvents.bind(this), this.attachEvents = this.attachEvents.bind(this), this.attachWindowEvents = this.attachWindowEvents.bind(this), this.detachEvents = this.detachEvents.bind(this), this.detachWindowEvents = this.detachWindowEvents.bind(this), this.onCanvasPointerDown = this.onCanvasPointerDown.bind(this), this.onPointerMove = this.onPointerMove.bind(this), this.onPointerUp = this.onPointerUp.bind(this), this.onPointerOut = this.onPointerOut.bind(this), this.addNewMarker = this.addNewMarker.bind(this), this.show = this.show.bind(this), this.scaleMarkers = this.scaleMarkers.bind(this), this.autoZoom = this.autoZoom.bind(this), this.toggleLogo = this.toggleLogo.bind(this), this.addLogo = this.addLogo.bind(this), this.removeLogo = this.removeLogo.bind(this), this.addDefs = this.addDefs.bind(this), this.addDefaultFilterDefs = this.addDefaultFilterDefs.bind(this), this.attachShadow({ mode: "open" });
2326
+ }
2327
+ connectedCallback() {
2328
+ this.dispatchEvent(new CustomEvent("viewinit", { detail: { markerView: this } })), c.addKeyAddListener(this.toggleLogo), this.createLayout(), this.addMainCanvas(), this.attachEvents(), this._isInitialized = !0, this.targetImage !== void 0 && this.addTargetImage(), this.setMainCanvasSize(), this.addDefaultFilterDefs(), this.toggleLogo(), this.dispatchEvent(new CustomEvent("viewshow", { detail: { markerView: this } }));
2329
+ }
2330
+ disconnectedCallback() {
2331
+ this.detachEvents();
2332
+ }
2333
+ createLayout() {
2334
+ var t;
2335
+ this.style.display = "flex", this.style.width = this.style.width !== "" ? this.style.width : "100%", this.style.height = this.style.height !== "" ? this.style.height : "100%", this.style.position = "relative", this._contentContainer = document.createElement("div"), this._contentContainer.style.display = "flex", this._contentContainer.style.position = "relative", this._contentContainer.style.flexGrow = "2", this._contentContainer.style.flexShrink = "1", this._contentContainer.style.overflow = "hidden", this._canvasContainer = document.createElement("div"), this._canvasContainer.style.touchAction = "none", this._canvasContainer.className = "canvas-container", this._canvasContainer.style.display = "flex", this._canvasContainer.style.flexGrow = "2", this._canvasContainer.style.flexShrink = "2", this._canvasContainer.style.justifyContent = "center", this._canvasContainer.style.alignItems = "center", this._canvasContainer.style.overflow = "hidden", this._canvasContainer.addEventListener("wheel", (i) => {
2336
+ i.preventDefault(), this._panX -= i.deltaX, this._panY -= i.deltaY, this.applyTransform();
2337
+ }, { passive: !1 }), this._transformContainer = document.createElement("div"), this._transformContainer.style.display = "grid", this._transformContainer.style.gridTemplateColumns = "1fr", this._canvasContainer.appendChild(this._transformContainer), this._contentContainer.appendChild(this._canvasContainer), (t = this.shadowRoot) === null || t === void 0 || t.appendChild(this._contentContainer);
2338
+ }
2339
+ addMainCanvas() {
2340
+ var t, i;
2341
+ this.width = ((t = this._contentContainer) === null || t === void 0 ? void 0 : t.clientWidth) || 0, this.height = ((i = this._contentContainer) === null || i === void 0 ? void 0 : i.clientHeight) || 0, this._mainCanvas = document.createElementNS("http://www.w3.org/2000/svg", "svg"), this._mainCanvas.setAttribute("xmlns", "http://www.w3.org/2000/svg"), this.setMainCanvasSize(), this._mainCanvas.style.gridColumnStart = "1", this._mainCanvas.style.gridRowStart = "1", this._mainCanvas.style.pointerEvents = "auto", this.addDefsToMainCanvas(), this._groupLayer = r.createGroup(), this._mainCanvas.appendChild(this._groupLayer), this._transformContainer.appendChild(this._mainCanvas);
2342
+ }
2343
+ addDefsToMainCanvas() {
2344
+ var t;
2345
+ this._defsElement = r.createDefs(), (t = this._mainCanvas) === null || t === void 0 || t.appendChild(this._defsElement), this._defsElement.append(...this._defs);
2346
+ }
2347
+ setMainCanvasSize() {
2348
+ this._mainCanvas !== void 0 && this._targetHeight > 0 && this._targetWidth > 0 && (this._mainCanvas.style.width = `${this._targetWidth}px`, this._mainCanvas.style.height = `${this._targetHeight}px`, this._mainCanvas.setAttribute("width", `${this._targetWidth}`), this._mainCanvas.setAttribute("height", `${this._targetHeight}`), this._mainCanvas.setAttribute("viewBox", "0 0 " + this._targetWidth.toString() + " " + this._targetHeight.toString()), this.setEditingTargetSize());
2349
+ }
2350
+ setEditingTargetSize() {
2351
+ this._editingTarget !== void 0 && (this._editingTarget.width = this._targetWidth, this._editingTarget.height = this._targetHeight, this._editingTarget.style.width = `${this._targetWidth}px`, this._editingTarget.style.height = `${this._targetHeight}px`);
2352
+ }
2353
+ addTargetImage() {
2354
+ this._isInitialized && this._editingTarget === void 0 && this.targetImage !== void 0 && this._canvasContainer !== void 0 && this._mainCanvas !== void 0 && (this._editingTarget = document.createElement("img"), this._targetWidth = this._targetWidth > 0 ? this._targetWidth : this.targetImage.clientWidth, this._targetHeight = this._targetHeight > 0 ? this._targetHeight : this.targetImage.clientHeight, this._editingTarget.addEventListener("load", (t) => {
2355
+ if (this._editingTarget !== void 0) {
2356
+ if (this._targetHeight <= 0 || this._targetWidth <= 0) {
2357
+ const i = t.target, e = i.naturalWidth / i.naturalHeight, s = this._targetWidth > 0 ? this._targetWidth : this._targetHeight > 0 ? this._targetHeight * e : i.clientWidth > 0 ? i.clientWidth : i.naturalWidth, a = this._targetHeight > 0 ? this._targetHeight : this._targetWidth > 0 ? this._targetWidth / e : i.clientHeight > 0 ? i.clientHeight : i.naturalHeight;
2358
+ this._targetWidth = s, this._targetHeight = a;
2359
+ }
2360
+ this._editingTarget.width = this._targetWidth, this._editingTarget.height = this._targetHeight, this._editingTarget.style.width = `${this._targetWidth}px`, this._editingTarget.style.height = `${this._targetHeight}px`, this._editingTarget.style.gridColumnStart = "1", this._editingTarget.style.gridRowStart = "1", this.setMainCanvasSize(), this._targetImageLoaded = !0, this._stateToRestore !== void 0 && this.show(this._stateToRestore);
2361
+ }
2362
+ this.zoomLevel = this._zoomLevel, this.autoZoom();
2363
+ }), this._editingTarget.src = this.targetImage.src, this._transformContainer.insertBefore(this._editingTarget, this._mainCanvas));
2364
+ }
2365
+ addDefaultFilterDefs() {
2366
+ this.addDefs(...Y.getDefaultFilterSet());
2367
+ }
2368
+ addNewMarker(t) {
2369
+ if (this._mainCanvas === void 0) throw new Error("Main canvas is not initialized.");
2370
+ const i = r.createGroup();
2371
+ this.defaultFilter && t.applyDefaultFilter && i.setAttribute("filter", this.defaultFilter), this._mainCanvas.appendChild(i);
2372
+ const e = new t(i);
2373
+ return this.attachMarkerEvents(e), e;
2374
+ }
2375
+ attachMarkerEvents(t) {
2376
+ t.container.addEventListener("click", () => {
2377
+ this.dispatchEvent(new CustomEvent("markerclick", { detail: { marker: t, markerView: this } }));
2378
+ }), t.container.addEventListener("pointerover", () => {
2379
+ this.dispatchEvent(new CustomEvent("markerover", { detail: { marker: t, markerView: this } }));
2380
+ }), t.container.addEventListener("pointerdown", () => {
2381
+ this.dispatchEvent(new CustomEvent("markerpointerdown", { detail: { marker: t, markerView: this } }));
2382
+ }), t.container.addEventListener("pointermove", () => {
2383
+ this.dispatchEvent(new CustomEvent("markerpointermove", { detail: { marker: t, markerView: this } }));
2384
+ }), t.container.addEventListener("pointerup", () => {
2385
+ this.dispatchEvent(new CustomEvent("markerpointerup", { detail: { marker: t, markerView: this } }));
2386
+ }), t.container.addEventListener("pointerenter", () => {
2387
+ this.dispatchEvent(new CustomEvent("markerpointerenter", { detail: { marker: t, markerView: this } }));
2388
+ }), t.container.addEventListener("pointerleave", () => {
2389
+ this.dispatchEvent(new CustomEvent("markerpointerleave", { detail: { marker: t, markerView: this } }));
2390
+ });
2391
+ }
2392
+ attachEvents() {
2393
+ var t, i;
2394
+ this.hasAttribute("tabindex") || this.setAttribute("tabindex", "0"), (t = this._mainCanvas) === null || t === void 0 || t.addEventListener("pointerdown", this.onCanvasPointerDown), (i = this._mainCanvas) === null || i === void 0 || i.addEventListener("touchmove", (e) => e.preventDefault()), this.attachWindowEvents();
2395
+ }
2396
+ attachWindowEvents() {
2397
+ window.addEventListener("pointermove", this.onPointerMove), window.addEventListener("pointerup", this.onPointerUp), window.addEventListener("pointerleave", this.onPointerUp), window.addEventListener("pointercancel", this.onPointerOut), window.addEventListener("pointerout", this.onPointerOut);
2398
+ }
2399
+ detachEvents() {
2400
+ this.detachWindowEvents();
2401
+ }
2402
+ detachWindowEvents() {
2403
+ }
2404
+ onCanvasPointerDown(t) {
2405
+ this.activePointers.set(t.pointerId, { x: t.clientX, y: t.clientY }), this.touchPoints++, this.touchPoints === 1 ? (this.leadPointerId = t.pointerId, this.prevPanPoint = { x: t.clientX, y: t.clientY }, this._mainCanvas && (this._mainCanvas.style.cursor = "grabbing")) : this.touchPoints === 2 && (this.isPinching = !0, this.prevPinchDistance = this.getPinchDistance(), this.prevPinchMidpoint = this.getPinchMidpoint());
2406
+ }
2407
+ onPointerMove(t) {
2408
+ if (this.activePointers.set(t.pointerId, { x: t.clientX, y: t.clientY }), this.touchPoints === 2 && this.isPinching) {
2409
+ const i = this.getPinchDistance(), e = this.getPinchMidpoint();
2410
+ if (this._panX += e.x - this.prevPinchMidpoint.x, this._panY += e.y - this.prevPinchMidpoint.y, this.prevPinchDistance > 0 && this._canvasContainer) {
2411
+ const s = i / this.prevPinchDistance, a = Math.max(0.1, Math.min(10, this._zoomLevel * s)), h = a / this._zoomLevel, o = this._canvasContainer.getBoundingClientRect(), n = e.x - (o.left + o.width / 2), l = e.y - (o.top + o.height / 2);
2412
+ this._panX = n * (1 - h) + this._panX * h, this._panY = l * (1 - h) + this._panY * h, this._zoomLevel = a, this.applyTransform();
2413
+ }
2414
+ this.prevPinchDistance = i, this.prevPinchMidpoint = Object.assign({}, e);
2415
+ } else this.touchPoints > 0 && this.leadPointerId === t.pointerId && this.panTo({ x: t.clientX, y: t.clientY });
2416
+ }
2417
+ onPointerUp(t) {
2418
+ this.activePointers.delete(t.pointerId), this.touchPoints > 0 && (this.touchPoints--, this.touchPoints === 0 && (this.leadPointerId = void 0), this._mainCanvas && (this._mainCanvas.style.cursor = "default")), this.touchPoints < 2 && (this.isPinching = !1, this.prevPinchDistance = 0), this.touchPoints === 1 && this.activePointers.size === 1 && (this.prevPanPoint = Array.from(this.activePointers.values())[0]);
2419
+ }
2420
+ onPointerOut(t) {
2421
+ this.activePointers.delete(t.pointerId), this.touchPoints > 0 && this.touchPoints--;
2422
+ }
2423
+ getMarkerTypeByName(t) {
2424
+ let i;
2425
+ return this.markerTypes.forEach((e) => {
2426
+ e.typeName === t && (i = e);
2427
+ }), i;
2428
+ }
2429
+ registerMarkerType(t) {
2430
+ this.markerTypes.indexOf(t) < 0 && this.markerTypes.push(t);
2431
+ }
2432
+ show(t) {
2433
+ var i;
2434
+ if (!this._targetImageLoaded) return void (this._stateToRestore = t);
2435
+ this._stateToRestore = void 0;
2436
+ const e = JSON.parse(JSON.stringify(t));
2437
+ for (this.markers.splice(0); !((i = this._mainCanvas) === null || i === void 0) && i.lastChild; ) this._mainCanvas.removeChild(this._mainCanvas.lastChild);
2438
+ this.addDefsToMainCanvas(), this.defaultFilter === void 0 && e.defaultFilter && (this.defaultFilter = e.defaultFilter), e.markers.forEach((s) => {
2439
+ const a = this.getMarkerTypeByName(s.typeName);
2440
+ if (a !== void 0) {
2441
+ const h = this.addNewMarker(a);
2442
+ h.restoreState(s), this.markers.push(h);
2443
+ }
2444
+ }), e.width && e.height && (e.width !== this.targetWidth || e.height !== this.targetHeight) && this.scaleMarkers(this.targetWidth / e.width, this.targetHeight / e.height), this.dispatchEvent(new CustomEvent("viewrestorestate", { detail: { markerView: this } }));
2445
+ }
2446
+ scaleMarkers(t, i) {
2447
+ this.markers.forEach((e) => {
2448
+ e.scale(t, i);
2449
+ });
2450
+ }
2451
+ panTo(t) {
2452
+ this._panX -= this.prevPanPoint.x - t.x, this._panY -= this.prevPanPoint.y - t.y, this.applyTransform(), this.prevPanPoint = t;
2453
+ }
2454
+ getPinchDistance() {
2455
+ const t = Array.from(this.activePointers.values());
2456
+ if (t.length < 2) return 0;
2457
+ const i = t[1].x - t[0].x, e = t[1].y - t[0].y;
2458
+ return Math.sqrt(i * i + e * e);
2459
+ }
2460
+ getPinchMidpoint() {
2461
+ const t = Array.from(this.activePointers.values());
2462
+ return t.length < 2 ? { x: 0, y: 0 } : { x: (t[0].x + t[1].x) / 2, y: (t[0].y + t[1].y) / 2 };
2463
+ }
2464
+ toggleLogo() {
2465
+ c.isLicensed("MJS3V") || c.isLicensed("MJS3") ? this.removeLogo() : this.addLogo();
2466
+ }
2467
+ addLogo() {
2468
+ var t, i;
2469
+ this._logoUI !== void 0 && ((t = this._contentContainer) === null || t === void 0 || t.removeChild(this._logoUI)), this._logoUI = document.createElement("div"), this._logoUI.style.display = "inline-block", this._logoUI.style.margin = "0px", this._logoUI.style.padding = "0px", this._logoUI.style.fill = "#333333", this._logoUI.style.opacity = "0.5";
2470
+ const e = this._logoUI;
2471
+ this._logoUI.addEventListener("mouseenter", () => {
2472
+ e.style.opacity = "1";
2473
+ }), this._logoUI.addEventListener("mouseleave", () => {
2474
+ e.style.opacity = "0.5";
2475
+ });
2476
+ const s = document.createElement("a");
2477
+ s.href = "https://markerjs.com/?utm_source=markerjs3&utm_medium=logo&utm_content=marker_view", s.target = "_blank", s.innerHTML = it, s.title = "Powered by marker.js", s.style.display = "grid", s.style.alignItems = "center", s.style.justifyItems = "center", s.style.padding = "3px", s.style.width = "20px", s.style.height = "20px", s.style.cursor = "pointer", this._logoUI.appendChild(s), (i = this._contentContainer) === null || i === void 0 || i.appendChild(this._logoUI), this._logoUI.style.position = "absolute", this._logoUI.style.pointerEvents = "all", this.positionLogo();
2478
+ }
2479
+ removeLogo() {
2480
+ this._contentContainer && this._logoUI !== void 0 && this._contentContainer.contains(this._logoUI) && this._contentContainer.removeChild(this._logoUI);
2481
+ }
2482
+ positionLogo() {
2483
+ this._logoUI && this._contentContainer && (this._logoUI.style.left = "20px", this._logoUI.style.bottom = "20px");
2484
+ }
2485
+ addDefs(...t) {
2486
+ this._defs.push(...t), this._defsElement && this._defsElement.append(...t);
2487
+ }
2488
+ addEventListener(t, i, e) {
2489
+ super.addEventListener(t, i, e);
2490
+ }
2491
+ removeEventListener(t, i, e) {
2492
+ super.removeEventListener(t, i, e);
2493
+ }
2494
+ }
2495
+ window && window.customElements && window.customElements.get("mjs-marker-view") === void 0 && window.customElements.define("mjs-marker-view", pt);
2496
+ class gt {
2497
+ get targetWidth() {
2498
+ return this._targetWidth;
2499
+ }
2500
+ set targetWidth(t) {
2501
+ this._targetWidth = t, this.setMainCanvasSize();
2502
+ }
2503
+ get targetHeight() {
2504
+ return this._targetHeight;
2505
+ }
2506
+ set targetHeight(t) {
2507
+ this._targetHeight = t, this.setMainCanvasSize();
2508
+ }
2509
+ get targetImage() {
2510
+ return this._targetImage;
2511
+ }
2512
+ set targetImage(t) {
2513
+ this._targetImageLoaded = !1, this._targetImage = t, t !== void 0 && this.addTargetImage();
2514
+ }
2515
+ get defaultFilter() {
2516
+ return this._defaultFilter;
2517
+ }
2518
+ set defaultFilter(t) {
2519
+ this._defaultFilter = t;
2520
+ }
2521
+ get targetImageLoadTimeout() {
2522
+ return this._targetImageLoadTimeout;
2523
+ }
2524
+ set targetImageLoadTimeout(t) {
2525
+ this._targetImageLoadTimeout = t;
2526
+ }
2527
+ constructor() {
2528
+ this._targetWidth = -1, this._targetHeight = -1, this._targetImageLoaded = !1, this.markerTypes = [], this.markers = [], this._isInitialized = !1, this.naturalSize = !1, this.imageType = "image/png", this.markersOnly = !1, this._targetImageLoadTimeout = 1e4, this._defs = [], this.markerTypes = [k, v, f, M, x, y, m, C, S, T, P, V, B, L, z, G, A, w], this.init = this.init.bind(this), this.addMainCanvas = this.addMainCanvas.bind(this), this.setMainCanvasSize = this.setMainCanvasSize.bind(this), this.setEditingTargetSize = this.setEditingTargetSize.bind(this), this.addTargetImage = this.addTargetImage.bind(this), this.addNewMarker = this.addNewMarker.bind(this), this.restoreState = this.restoreState.bind(this), this.scaleMarkers = this.scaleMarkers.bind(this), this.addDefs = this.addDefs.bind(this), this.addDefaultFilterDefs = this.addDefaultFilterDefs.bind(this);
2529
+ }
2530
+ init() {
2531
+ this.addMainCanvas(), this._isInitialized = !0, this.targetImage !== void 0 && this.addTargetImage(), this.setMainCanvasSize(), this.addDefaultFilterDefs();
2532
+ }
2533
+ addMainCanvas() {
2534
+ this._mainCanvas = document.createElementNS("http://www.w3.org/2000/svg", "svg"), this._mainCanvas.setAttribute("xmlns", "http://www.w3.org/2000/svg"), this.setMainCanvasSize(), this._mainCanvas.style.gridColumnStart = "1", this._mainCanvas.style.gridRowStart = "1", this._mainCanvas.style.pointerEvents = "auto", this._mainCanvas.style.visibility = "hidden", this.addDefsToMainCanvas(), this._renderHelperContainer = document.createElement("div"), this._renderHelperContainer.style.position = "absolute", this._renderHelperContainer.style.top = "0px", this._renderHelperContainer.style.left = "0px", this._renderHelperContainer.style.width = "10px", this._renderHelperContainer.style.height = "10px", this._renderHelperContainer.style.overflow = "hidden", this._renderHelperContainer.style.visibility = "hidden", this._renderHelperContainer.appendChild(this._mainCanvas), document.body.appendChild(this._renderHelperContainer);
2535
+ }
2536
+ addDefsToMainCanvas() {
2537
+ var t;
2538
+ this._defsElement = r.createDefs(), (t = this._mainCanvas) === null || t === void 0 || t.appendChild(this._defsElement), this._defsElement.append(...this._defs);
2539
+ }
2540
+ setMainCanvasSize() {
2541
+ this._mainCanvas !== void 0 && this._targetHeight > 0 && this._targetWidth > 0 && (this._mainCanvas.style.width = `${this._targetWidth}px`, this._mainCanvas.style.height = `${this._targetHeight}px`, this._mainCanvas.setAttribute("width", `${this._targetWidth}`), this._mainCanvas.setAttribute("height", `${this._targetHeight}`), this._mainCanvas.setAttribute("viewBox", "0 0 " + this._targetWidth.toString() + " " + this._targetHeight.toString()), this.setEditingTargetSize());
2542
+ }
2543
+ setEditingTargetSize() {
2544
+ this._editingTarget !== void 0 && (this._editingTarget.width = this._targetWidth, this._editingTarget.height = this._targetHeight, this._editingTarget.style.width = `${this._targetWidth}px`, this._editingTarget.style.height = `${this._targetHeight}px`);
2545
+ }
2546
+ addTargetImage() {
2547
+ var t;
2548
+ this._isInitialized && this._editingTarget === void 0 && this.targetImage !== void 0 && this._mainCanvas !== void 0 && (this._editingTarget = document.createElement("img"), this._targetWidth = this._targetWidth > 0 ? this._targetWidth : this.targetImage.clientWidth, this._targetHeight = this._targetHeight > 0 ? this._targetHeight : this.targetImage.clientHeight, this._editingTarget.addEventListener("load", (i) => {
2549
+ if (this._editingTarget !== void 0) {
2550
+ if (this._targetHeight <= 0 || this._targetWidth <= 0) {
2551
+ const e = i.target, s = e.naturalWidth / e.naturalHeight, a = this._targetWidth > 0 ? this._targetWidth : this._targetHeight > 0 ? this._targetHeight * s : e.naturalWidth, h = this._targetHeight > 0 ? this._targetHeight : this._targetWidth > 0 ? this._targetWidth / s : e.naturalHeight;
2552
+ this._targetWidth = a, this._targetHeight = h;
2553
+ }
2554
+ this._editingTarget.width = this._targetWidth, this._editingTarget.height = this._targetHeight, this._editingTarget.style.width = `${this._targetWidth}px`, this._editingTarget.style.height = `${this._targetHeight}px`, this._editingTarget.style.gridColumnStart = "1", this._editingTarget.style.gridRowStart = "1", this._targetImageLoaded = !0, this.setMainCanvasSize();
2555
+ }
2556
+ }), this._editingTarget.style.visibility = "hidden", this._editingTarget.src = this.targetImage.src, (t = this._renderHelperContainer) === null || t === void 0 || t.insertBefore(this._editingTarget, this._mainCanvas));
2557
+ }
2558
+ addDefaultFilterDefs() {
2559
+ this.addDefs(...Y.getDefaultFilterSet());
2560
+ }
2561
+ addNewMarker(t) {
2562
+ if (this._mainCanvas === void 0) throw new Error("Main canvas is not initialized.");
2563
+ const i = r.createGroup();
2564
+ return this.defaultFilter && t.applyDefaultFilter && i.setAttribute("filter", this.defaultFilter), this._mainCanvas.appendChild(i), new t(i);
2565
+ }
2566
+ getMarkerTypeByName(t) {
2567
+ let i;
2568
+ return this.markerTypes.forEach((e) => {
2569
+ e.typeName === t && (i = e);
2570
+ }), i;
2571
+ }
2572
+ registerMarkerType(t) {
2573
+ this.markerTypes.indexOf(t) < 0 && this.markerTypes.push(t);
2574
+ }
2575
+ restoreState(t) {
2576
+ var i;
2577
+ const e = JSON.parse(JSON.stringify(t));
2578
+ for (this.markers.splice(0); !((i = this._mainCanvas) === null || i === void 0) && i.lastChild; ) this._mainCanvas.removeChild(this._mainCanvas.lastChild);
2579
+ this.addDefsToMainCanvas(), this.defaultFilter === void 0 && e.defaultFilter && (this.defaultFilter = e.defaultFilter), e.markers.forEach((s) => {
2580
+ const a = this.getMarkerTypeByName(s.typeName);
2581
+ if (a !== void 0) {
2582
+ const h = this.addNewMarker(a);
2583
+ h.restoreState(s), this.markers.push(h);
2584
+ }
2585
+ }), e.width && e.height && (e.width !== this.targetWidth || e.height !== this.targetHeight) && this.scaleMarkers(this.targetWidth / e.width, this.targetHeight / e.height);
2586
+ }
2587
+ scaleMarkers(t, i) {
2588
+ this.markers.forEach((e) => {
2589
+ e.scale(t, i);
2590
+ });
2591
+ }
2592
+ rasterize(t, i) {
2593
+ var e, s;
2594
+ return Q(this, void 0, void 0, function* () {
2595
+ if (!this.naturalSize && this.targetWidth <= 0 && this.targetHeight <= 0 && (this._targetWidth = t.width, this._targetHeight = t.height), this.init(), this._mainCanvas === void 0 || this.targetImage === void 0) throw new Error("Not properly initialized.");
2596
+ let a = 0;
2597
+ for (; !this._targetImageLoaded && (this._targetImageLoadTimeout === 0 || a++ < this._targetImageLoadTimeout / 100); ) yield new Promise((E) => setTimeout(E, 100));
2598
+ this.restoreState(t);
2599
+ const h = i !== void 0 ? i : document.createElement("canvas");
2600
+ this.targetImage === null && (this.markersOnly = !0, this.naturalSize = !1);
2601
+ const o = document.createElementNS("http://www.w3.org/2000/svg", "svg");
2602
+ o.setAttribute("xmlns", "http://www.w3.org/2000/svg"), o.setAttribute("width", this._mainCanvas.width.baseVal.valueAsString), o.setAttribute("height", this._mainCanvas.height.baseVal.valueAsString), o.setAttribute("viewBox", "0 0 " + this._mainCanvas.viewBox.baseVal.width.toString() + " " + this._mainCanvas.viewBox.baseVal.height.toString()), yield new Promise((E) => setTimeout(E, 200)), o.innerHTML = this._mainCanvas.innerHTML, this.naturalSize === !0 ? (o.width.baseVal.value = this.targetImage.naturalWidth, o.height.baseVal.value = this.targetImage.naturalHeight) : this.width !== void 0 && this.height !== void 0 && (o.width.baseVal.value = this.width, o.height.baseVal.value = this.height), h.width = o.width.baseVal.value, h.height = o.height.baseVal.value;
2603
+ const n = o.outerHTML, l = h.getContext("2d");
2604
+ if (l === null) throw new Error("Canvas 2D context is not available.");
2605
+ this.markersOnly !== !0 && l.drawImage(this.targetImage, 0, 0, h.width, h.height);
2606
+ const u = window.URL, p = new Image(h.width, h.height);
2607
+ p.setAttribute("crossOrigin", "anonymous");
2608
+ const _ = new Blob([n], { type: "image/svg+xml" }), J = u.createObjectURL(_);
2609
+ let O = "";
2610
+ for (p.onload = () => {
2611
+ l.drawImage(p, 0, 0), u.revokeObjectURL(J), O = h.toDataURL(this.imageType, this.imageQuality);
2612
+ }, p.src = J, a = 0; !O && a++ < 100; ) yield new Promise((E) => setTimeout(E, 100));
2613
+ return this._editingTarget && ((e = this._renderHelperContainer) === null || e === void 0 || e.removeChild(this._editingTarget)), (s = this._renderHelperContainer) === null || s === void 0 || s.removeChild(this._mainCanvas), document.body.removeChild(this._renderHelperContainer), O;
2614
+ });
2615
+ }
2616
+ addDefs(...t) {
2617
+ this._defs.push(...t), this._defsElement && this._defsElement.append(...t);
2618
+ }
2619
+ }
2620
+ export {
2621
+ c as Activator,
2622
+ f as ArrowMarker,
2623
+ nt as ArrowMarkerEditor,
2624
+ T as CalloutMarker,
2625
+ lt as CalloutMarkerEditor,
2626
+ G as CaptionFrameMarker,
2627
+ dt as CaptionFrameMarkerEditor,
2628
+ L as CheckImageMarker,
2629
+ C as CoverMarker,
2630
+ A as CurveMarker,
2631
+ ut as CurveMarkerEditor,
2632
+ B as CustomImageMarker,
2633
+ P as EllipseFrameMarker,
2634
+ V as EllipseMarker,
2635
+ k as FrameMarker,
2636
+ y as FreehandMarker,
2637
+ D as FreehandMarkerEditor,
2638
+ tt as Grip,
2639
+ S as HighlightMarker,
2640
+ w as HighlighterMarker,
2641
+ F as ImageMarkerBase,
2642
+ U as ImageMarkerEditor,
2643
+ v as LineMarker,
2644
+ et as LinearMarkerBase,
2645
+ W as LinearMarkerEditor,
2646
+ ct as MarkerArea,
2647
+ b as MarkerBase,
2648
+ H as MarkerBaseEditor,
2649
+ pt as MarkerView,
2650
+ M as MeasurementMarker,
2651
+ x as PolygonMarker,
2652
+ rt as PolygonMarkerEditor,
2653
+ R as RectangularBoxMarkerBase,
2654
+ gt as Renderer,
2655
+ g as ResizeGrip,
2656
+ at as RotateGrip,
2657
+ $ as ShapeMarkerBase,
2658
+ N as ShapeMarkerEditor,
2659
+ j as ShapeOutlineMarkerBase,
2660
+ X as ShapeOutlineMarkerEditor,
2661
+ Y as SvgFilters,
2662
+ r as SvgHelper,
2663
+ st as TextBlock,
2664
+ ot as TextBlockEditor,
2665
+ m as TextMarker,
2666
+ Z as TextMarkerEditor,
2667
+ z as XImageMarker
2668
+ };
2669
+ //# sourceMappingURL=markerjs3-DI_cywfl.js.map