@inweb/markup 25.8.11 → 25.8.13

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.
@@ -146,7 +146,7 @@ export class KonvaCloud implements IMarkupCloud {
146
146
  }
147
147
 
148
148
  type(): string {
149
- return "cloud";
149
+ return "Cloud";
150
150
  }
151
151
 
152
152
  getColor(): string {
@@ -115,7 +115,7 @@ export class KonvaEllipse implements IMarkupEllipse {
115
115
  }
116
116
 
117
117
  type(): string {
118
- return "ellipse";
118
+ return "Ellipse";
119
119
  }
120
120
 
121
121
  getColor(): string {
@@ -122,7 +122,7 @@ export class KonvaImage implements IMarkupImage {
122
122
  }
123
123
 
124
124
  type(): string {
125
- return "image";
125
+ return "Image";
126
126
  }
127
127
 
128
128
  getRotation(): number {
@@ -64,7 +64,7 @@ export class KonvaLine implements IMarkupLine {
64
64
  }
65
65
 
66
66
  type(): string {
67
- return "line";
67
+ return "Line";
68
68
  }
69
69
 
70
70
  getColor(): string {
@@ -58,7 +58,6 @@ const MarkupMode2Konva = {
58
58
  Line: {
59
59
  name: "Line",
60
60
  initializer: (ref: any, params = null) => new KonvaLine(params, ref),
61
- zIndex: 1,
62
61
  },
63
62
  Text: {
64
63
  name: "Text",
@@ -67,27 +66,22 @@ const MarkupMode2Konva = {
67
66
  Rectangle: {
68
67
  name: "Rect",
69
68
  initializer: (ref: any, params = null) => new KonvaRectangle(params, ref),
70
- zIndex: 1,
71
69
  },
72
70
  Ellipse: {
73
71
  name: "Ellipse",
74
72
  initializer: (ref: any, params = null) => new KonvaEllipse(params, ref),
75
- zIndex: 1,
76
73
  },
77
74
  Arrow: {
78
75
  name: "Arrow",
79
76
  initializer: (ref: any, params = null) => new KonvaArrow(params, ref),
80
- zIndex: 1,
81
77
  },
82
78
  Image: {
83
79
  name: "Image",
84
80
  initializer: (ref: any, params = null) => new KonvaImage(params, ref),
85
- zIndex: 0,
86
81
  },
87
82
  Cloud: {
88
83
  name: "Cloud",
89
84
  initializer: (ref: any, params = null) => new KonvaCloud(params, ref),
90
- zIndex: 1,
91
85
  },
92
86
  };
93
87
 
@@ -113,7 +107,9 @@ export class KonvaMarkup implements IMarkup {
113
107
  private _imageInputPos: Konva.Vector2d;
114
108
  private _markupContainer: HTMLDivElement;
115
109
  private _resizeObserver: ResizeObserver;
116
- private _zIndex = 1;
110
+ private _groupImages: Konva.Group;
111
+ private _groupGeometry: Konva.Group;
112
+ private _groupTexts: Konva.Group;
117
113
 
118
114
  public lineWidth = 4;
119
115
  public lineType: MarkupLineType = "solid";
@@ -246,6 +242,10 @@ export class KonvaMarkup implements IMarkup {
246
242
  }
247
243
 
248
244
  setViewpoint(viewpoint: IViewpoint): void {
245
+ this.clearSelected();
246
+ this.removeTextInput();
247
+ this.removeImageInput();
248
+
249
249
  const markupColor = viewpoint.custom_fields?.markup_color || { r: 255, g: 0, b: 0 };
250
250
  this.setMarkupColor(markupColor.r, markupColor.g, markupColor.b);
251
251
 
@@ -312,6 +312,8 @@ export class KonvaMarkup implements IMarkup {
312
312
  enableEditMode(mode: MarkupMode | false): this {
313
313
  if (!mode || !MarkupMode2Konva[mode]) {
314
314
  this.clearSelected();
315
+ this.removeTextInput();
316
+ this.removeImageInput();
315
317
  this._markupIsActive = false;
316
318
  } else {
317
319
  this._markupMode = mode;
@@ -328,11 +330,6 @@ export class KonvaMarkup implements IMarkup {
328
330
  const object = konvaShape.initializer(null, params);
329
331
  this.addObject(object);
330
332
 
331
- // Set zIndex only when shape has been added to Layer else we will get
332
- // "Konva warning: Node has no parent. zIndex parameter is ignored."
333
- object.setZIndex(konvaShape.zIndex ?? this._zIndex);
334
- this._zIndex++;
335
-
336
333
  return object;
337
334
  }
338
335
 
@@ -370,7 +367,9 @@ export class KonvaMarkup implements IMarkup {
370
367
  }
371
368
 
372
369
  private addObject(object: IMarkupObject): void {
373
- if (this._konvaLayer) this._konvaLayer.add(object.ref());
370
+ if (object.type() === "Image") this._groupImages.add(object.ref());
371
+ else if (object.type() === "Text") this._groupTexts.add(object.ref());
372
+ else this._groupGeometry.add(object.ref());
374
373
  }
375
374
 
376
375
  private konvaLayerFind(type: string): any {
@@ -380,7 +379,15 @@ export class KonvaMarkup implements IMarkup {
380
379
  if (!konvaShape || !konvaShape.initializer) return [];
381
380
 
382
381
  // for "draggable" Konva uses Rectangles in Transformer. We need only Shapes from layer.
383
- return this._konvaLayer.find(konvaShape.name).filter((ref) => ref.parent === this._konvaLayer);
382
+ return this._konvaLayer
383
+ .find(konvaShape.name)
384
+ .filter(
385
+ (ref) =>
386
+ ref.parent === this._konvaLayer ||
387
+ ref.parent === this._groupImages ||
388
+ ref.parent === this._groupGeometry ||
389
+ ref.parent === this._groupTexts
390
+ );
384
391
  }
385
392
 
386
393
  private initializeKonva(): any {
@@ -394,6 +401,14 @@ export class KonvaMarkup implements IMarkup {
394
401
 
395
402
  const layer = new Konva.Layer({ pixelRation: window.devicePixelRatio });
396
403
  stage.add(layer);
404
+
405
+ this._groupImages = new Konva.Group();
406
+ layer.add(this._groupImages);
407
+ this._groupGeometry = new Konva.Group();
408
+ layer.add(this._groupGeometry);
409
+ this._groupTexts = new Konva.Group();
410
+ layer.add(this._groupTexts);
411
+
397
412
  this._konvaLayer = layer;
398
413
 
399
414
  const transformer = new Konva.Transformer({
@@ -561,7 +576,11 @@ export class KonvaMarkup implements IMarkup {
561
576
  }
562
577
  }
563
578
 
564
- if (transformer.nodes().filter((x) => x.className === "Cloud").length > 0 || e.target.className === "Cloud") {
579
+ if (
580
+ transformer.nodes().filter((x) => x.className === "Cloud" || x.className === "Image").length > 0 ||
581
+ e.target.className === "Cloud" ||
582
+ e.target.className === "Image"
583
+ ) {
565
584
  transformer.rotateEnabled(false);
566
585
  } else {
567
586
  transformer.rotateEnabled(true);
@@ -607,10 +626,15 @@ export class KonvaMarkup implements IMarkup {
607
626
  }
608
627
 
609
628
  private destroyKonva() {
629
+ this.removeTextInput();
630
+ this.removeImageInput();
610
631
  this.clearOverlay();
611
632
 
612
633
  this._konvaStage?.destroy();
613
634
 
635
+ this._groupImages = undefined;
636
+ this._groupGeometry = undefined;
637
+ this._groupTexts = undefined;
614
638
  this._konvaLayer = undefined;
615
639
  this._konvaTransformer = undefined;
616
640
  this._konvaStage = undefined;
@@ -845,6 +869,10 @@ export class KonvaMarkup implements IMarkup {
845
869
  this._textInputRef.style.display = "block";
846
870
  this._textInputRef.style.top = inputY + "px";
847
871
  this._textInputRef.style.left = inputX + "px";
872
+ this._textInputRef.style.fontSize = `${this.fontSize}px`;
873
+ this._textInputRef.style.color = `${this._markupColor.HexColor}`;
874
+ this._textInputRef.style.fontFamily = "Calibri";
875
+
848
876
  this._textInputRef.onkeydown = (event) => {
849
877
  if (event.key === "Enter" && !event.shiftKey) {
850
878
  event.preventDefault();
@@ -106,7 +106,7 @@ export class KonvaRectangle implements IMarkupRectangle {
106
106
  }
107
107
 
108
108
  type(): string {
109
- return "rectangle";
109
+ return "Rectangle";
110
110
  }
111
111
 
112
112
  getColor(): string {
@@ -82,7 +82,7 @@ export class KonvaText implements IMarkupText {
82
82
  }
83
83
 
84
84
  type(): string {
85
- return "text";
85
+ return "Text";
86
86
  }
87
87
 
88
88
  getColor(): string {