@inweb/markup 25.7.7 → 25.7.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inweb/markup",
3
- "version": "25.7.7",
3
+ "version": "25.7.9",
4
4
  "description": "JavaScript 2D markups",
5
5
  "homepage": "https://cloud.opendesign.com/docs/index.html",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -26,8 +26,8 @@
26
26
  "docs": "typedoc"
27
27
  },
28
28
  "dependencies": {
29
- "@inweb/eventemitter2": "~25.7.7",
30
- "@inweb/viewer-core": "~25.7.7"
29
+ "@inweb/eventemitter2": "~25.7.9",
30
+ "@inweb/viewer-core": "~25.7.9"
31
31
  },
32
32
  "devDependencies": {
33
33
  "canvas": "^2.11.2",
@@ -27,9 +27,10 @@ import { ChangeActiveDraggerEvent, IViewpoint, PanEvent } from "@inweb/viewer-co
27
27
 
28
28
  import { IMarkup } from "../IMarkup";
29
29
  import { IWorldTransform } from "../IWorldTransform";
30
- import { MarkupColor } from "./MarkupColor";
31
30
  import { IMarkupObject } from "../IMarkupObject";
32
31
  import { IMarkupColorable } from "../IMarkupColorable";
32
+ import { MarkupLineType } from "../IMarkupLine";
33
+ import { MarkupColor } from "./MarkupColor";
33
34
  import { KonvaLine } from "./KonvaLine";
34
35
  import { KonvaText } from "./KonvaText";
35
36
  import { KonvaRectangle } from "./KonvaRectangle";
@@ -37,13 +38,6 @@ import { KonvaEllipse } from "./KonvaEllipse";
37
38
  import { KonvaArrow } from "./KonvaArrow";
38
39
  import { KonvaImage } from "./KonvaImage";
39
40
  import { KonvaCloud } from "./KonvaCloud";
40
- import { IMarkupLine, MarkupLineType } from "../IMarkupLine";
41
- import { IMarkupArrow } from "../IMarkupArrow";
42
- import { IMarkupEllipse } from "../IMarkupEllipse";
43
- import { IMarkupRectangle } from "../IMarkupRectangle";
44
- import { IMarkupCloud } from "../IMarkupCloud";
45
- import { IMarkupImage } from "../IMarkupImage";
46
- import { IMarkupText } from "../IMarkupText";
47
41
 
48
42
  const MarkupMode2Konva = {
49
43
  SelectMarkup: {
@@ -102,6 +96,7 @@ export class KonvaMarkup implements IMarkup {
102
96
  private _imageInputRef: HTMLInputElement;
103
97
  private _imageInputPos: Konva.Vector2d;
104
98
  private _markupContainer: HTMLDivElement;
99
+ private _resizeObserver: ResizeObserver;
105
100
  private _zIndex = 1;
106
101
 
107
102
  private readonly _markupContainerName = "markupContainer";
@@ -137,15 +132,15 @@ export class KonvaMarkup implements IMarkup {
137
132
  const parentDiv = this._container.parentElement;
138
133
  parentDiv.appendChild(this._markupContainer);
139
134
 
135
+ this._resizeObserver = new ResizeObserver(this.resizeContainer);
136
+ this._resizeObserver.observe(parentDiv);
137
+
140
138
  this._markupColor.setColor(255, 0, 0);
141
139
 
142
140
  this.initializeKonva();
143
- this.resize();
144
141
 
145
142
  if (this._viewer) {
146
143
  this._pointerEvents.forEach((x) => this._markupContainer.addEventListener(x, this.redirectToViewer));
147
-
148
- this._viewer.addEventListener("resize", this.resize);
149
144
  this._viewer.addEventListener("changeactivedragger", this.changeActiveDragger);
150
145
  this._viewer.addEventListener("pan", this.pan);
151
146
  }
@@ -159,13 +154,15 @@ export class KonvaMarkup implements IMarkup {
159
154
  if (this._viewer) {
160
155
  this._viewer.removeEventListener("pan", this.pan);
161
156
  this._viewer.removeEventListener("changeactivedragger", this.changeActiveDragger);
162
- this._viewer.removeEventListener("resize", this.resize);
163
157
  }
164
158
 
165
159
  this._pointerEvents.forEach((x) => this._markupContainer.removeEventListener(x, this.redirectToViewer));
166
160
 
167
161
  this.destroyKonva();
168
162
 
163
+ this._resizeObserver.disconnect();
164
+ this._resizeObserver = undefined;
165
+
169
166
  this._markupContainer.remove();
170
167
  this._markupContainer = undefined;
171
168
 
@@ -200,9 +197,13 @@ export class KonvaMarkup implements IMarkup {
200
197
  }
201
198
  };
202
199
 
203
- resize = () => {
204
- this._konvaStage?.width(this._container.clientWidth);
205
- this._konvaStage?.height(this._container.clientHeight);
200
+ resizeContainer = (entries: ResizeObserverEntry[]) => {
201
+ const { width, height } = entries[0].contentRect;
202
+
203
+ if (!width || !height) return; // <- invisible container, or container with parent removed
204
+
205
+ this._konvaStage?.width(width);
206
+ this._konvaStage?.height(height);
206
207
  };
207
208
 
208
209
  pan = (event: PanEvent) => {
@@ -939,8 +940,9 @@ export class KonvaMarkup implements IMarkup {
939
940
  type?: MarkupLineType,
940
941
  width?: number,
941
942
  id?: string
942
- ): IMarkupLine | void {
943
+ ): KonvaLine | void {
943
944
  if (!linePoints || linePoints.length === 0) return;
945
+
944
946
  const points: { x: number; y: number }[] = [];
945
947
  for (let i = 0; i < linePoints.length; i += 2) {
946
948
  points.push({ x: linePoints[i], y: linePoints[i + 1] });
@@ -1051,7 +1053,7 @@ export class KonvaMarkup implements IMarkup {
1051
1053
  textSize?: number,
1052
1054
  fontSize?: number,
1053
1055
  id?: string
1054
- ): IMarkupText | void {
1056
+ ): KonvaText | void {
1055
1057
  const trNodes = this._konvaTransformer.nodes();
1056
1058
  if (trNodes.length > 0) {
1057
1059
  // in case of edit - remove old Konva.Text object
@@ -1092,7 +1094,7 @@ export class KonvaMarkup implements IMarkup {
1092
1094
  lineWidth?: number,
1093
1095
  color?: string,
1094
1096
  id?: string
1095
- ): IMarkupRectangle | void {
1097
+ ): KonvaRectangle | void {
1096
1098
  if (!position) return;
1097
1099
 
1098
1100
  const konvaRectangle = new KonvaRectangle({
@@ -1115,7 +1117,7 @@ export class KonvaMarkup implements IMarkup {
1115
1117
  lineWidth?: number,
1116
1118
  color?: string,
1117
1119
  id?: string
1118
- ): IMarkupEllipse | void {
1120
+ ): KonvaEllipse | void {
1119
1121
  if (!position) return;
1120
1122
 
1121
1123
  const konvaEllipse = new KonvaEllipse({
@@ -1136,7 +1138,7 @@ export class KonvaMarkup implements IMarkup {
1136
1138
  end: { x: number; y: number },
1137
1139
  color?: string,
1138
1140
  id?: string
1139
- ): IMarkupArrow | void {
1141
+ ): KonvaArrow | void {
1140
1142
  if (!start || !end) return;
1141
1143
 
1142
1144
  const konvaArrow = new KonvaArrow({
@@ -1158,7 +1160,7 @@ export class KonvaMarkup implements IMarkup {
1158
1160
  lineWidth?: number,
1159
1161
  color?: string,
1160
1162
  id?: string
1161
- ): IMarkupCloud | void {
1163
+ ): KonvaCloud | void {
1162
1164
  if (!position || !width || !height) return;
1163
1165
 
1164
1166
  const konvaCloud = new KonvaCloud({
@@ -1181,10 +1183,10 @@ export class KonvaMarkup implements IMarkup {
1181
1183
  width?: number,
1182
1184
  height?: number,
1183
1185
  id?: string
1184
- ): IMarkupImage | void {
1186
+ ): KonvaImage | void {
1185
1187
  if (!position) return;
1186
1188
 
1187
- let konvaImage: IMarkupImage;
1189
+ let konvaImage: KonvaImage;
1188
1190
 
1189
1191
  if (src) {
1190
1192
  konvaImage = new KonvaImage({