@inweb/markup 26.4.0 → 26.4.2

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 (38) hide show
  1. package/dist/markup.js +561 -126
  2. package/dist/markup.js.map +1 -1
  3. package/dist/markup.min.js +1 -1
  4. package/dist/markup.module.js +672 -138
  5. package/dist/markup.module.js.map +1 -1
  6. package/lib/markup/IMarkupArrow.d.ts +8 -8
  7. package/lib/markup/IMarkupCloud.d.ts +12 -5
  8. package/lib/markup/IMarkupEllipse.d.ts +4 -4
  9. package/lib/markup/IMarkupImage.d.ts +3 -3
  10. package/lib/markup/IMarkupLine.d.ts +2 -2
  11. package/lib/markup/IMarkupObject.d.ts +4 -0
  12. package/lib/markup/IMarkupRectangle.d.ts +10 -3
  13. package/lib/markup/IMarkupText.d.ts +3 -3
  14. package/lib/markup/Konva/KonvaArrow.d.ts +4 -1
  15. package/lib/markup/Konva/KonvaCloud.d.ts +4 -1
  16. package/lib/markup/Konva/KonvaEllipse.d.ts +4 -1
  17. package/lib/markup/Konva/KonvaImage.d.ts +4 -1
  18. package/lib/markup/Konva/KonvaLine.d.ts +4 -1
  19. package/lib/markup/Konva/KonvaMarkup.d.ts +2 -2
  20. package/lib/markup/Konva/KonvaRectangle.d.ts +4 -1
  21. package/lib/markup/Konva/KonvaText.d.ts +4 -1
  22. package/package.json +3 -3
  23. package/src/markup/IMarkupArrow.ts +8 -8
  24. package/src/markup/IMarkupCloud.ts +10 -5
  25. package/src/markup/IMarkupEllipse.ts +4 -4
  26. package/src/markup/IMarkupImage.ts +3 -3
  27. package/src/markup/IMarkupLine.ts +2 -2
  28. package/src/markup/IMarkupObject.ts +5 -0
  29. package/src/markup/IMarkupRectangle.ts +8 -3
  30. package/src/markup/IMarkupText.ts +3 -3
  31. package/src/markup/Konva/KonvaArrow.ts +49 -4
  32. package/src/markup/Konva/KonvaCloud.ts +110 -11
  33. package/src/markup/Konva/KonvaEllipse.ts +102 -2
  34. package/src/markup/Konva/KonvaImage.ts +60 -2
  35. package/src/markup/Konva/KonvaLine.ts +97 -3
  36. package/src/markup/Konva/KonvaMarkup.ts +182 -166
  37. package/src/markup/Konva/KonvaRectangle.ts +103 -4
  38. package/src/markup/Konva/KonvaText.ts +61 -2
@@ -1,17 +1,70 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance").
3
+ // All rights reserved.
4
+ //
5
+ // This software and its documentation and related materials are owned by
6
+ // the Alliance. The software may only be incorporated into application
7
+ // programs owned by members of the Alliance, subject to a signed
8
+ // Membership Agreement and Supplemental Software License Agreement with the
9
+ // Alliance. The structure and organization of this software are the valuable
10
+ // trade secrets of the Alliance and its suppliers. The software is also
11
+ // protected by copyright law and international treaty provisions. Application
12
+ // programs incorporating this software must include the following statement
13
+ // with their copyright notices:
14
+ //
15
+ // This application incorporates Open Design Alliance software pursuant to a
16
+ // license agreement with Open Design Alliance.
17
+ // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance.
18
+ // All rights reserved.
19
+ //
20
+ // By use of this software, its documentation or related materials, you
21
+ // acknowledge and accept the above terms.
22
+ ///////////////////////////////////////////////////////////////////////////////
23
+
1
24
  import Konva from "konva";
2
25
  import { IMarkupRectangle, IMarkupRectangleParams } from "../IMarkupRectangle";
26
+ import { IWorldTransform } from "../IWorldTransform";
27
+ import { WorldTransform } from "../WorldTransform";
3
28
 
4
29
  export class KonvaRectangle implements IMarkupRectangle {
5
30
  private _ref: Konva.Rect;
31
+ private _worldTransformer: IWorldTransform;
32
+
33
+ constructor(params: IMarkupRectangleParams, ref = null, worldTransformer = new WorldTransform()) {
34
+ this._worldTransformer = worldTransformer;
6
35
 
7
- constructor(params: IMarkupRectangleParams, ref = null) {
8
36
  if (ref) {
9
37
  this._ref = ref;
38
+ const wcsStart = this._ref.getAttr("wcsStart");
39
+ const wcsEnd = this._ref.getAttr("wcsEnd");
40
+
41
+ if (!wcsStart) {
42
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({ x: ref.x(), y: ref.y() }));
43
+ }
44
+ if (!wcsEnd) {
45
+ const rightBottomPoint = { x: ref.x() + ref.width(), y: ref.y() + ref.height() };
46
+ this._ref.setAttr(
47
+ "wcsEnd",
48
+ this._worldTransformer.screenToWorld({ x: rightBottomPoint.x, y: rightBottomPoint.y })
49
+ );
50
+ }
10
51
  return;
11
52
  }
12
53
 
13
54
  if (!params) params = {};
14
55
  if (!params.position) params.position = { x: 0, y: 0 };
56
+ if (params.position2) {
57
+ params.width = params.position.x - params.position2.x;
58
+ params.height = params.position.y - params.position2.y;
59
+ } else {
60
+ if (!params.width || !params.height) {
61
+ params.position2 = { x: 200, y: 200 };
62
+ params.width = 200;
63
+ params.height = 200;
64
+ } else {
65
+ params.position2 = { x: params.position.x + params.width, y: params.position.y + params.height };
66
+ }
67
+ }
15
68
 
16
69
  this._ref = new Konva.Rect({
17
70
  stroke: params.color ?? "#ff0000",
@@ -27,11 +80,11 @@ export class KonvaRectangle implements IMarkupRectangle {
27
80
  strokeScaleEnabled: false,
28
81
  });
29
82
 
83
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({ x: params.position.x, y: params.position.y }));
84
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({ x: params.position2.x, y: params.position2.y }));
85
+
30
86
  this._ref.on("transform", (e) => {
31
87
  const attrs = e.target.attrs;
32
-
33
- if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
34
-
35
88
  const scaleByX = Math.abs(attrs.scaleX - 1) > 10e-6;
36
89
  const scaleByY = Math.abs(attrs.scaleY - 1) > 10e-6;
37
90
 
@@ -57,6 +110,29 @@ export class KonvaRectangle implements IMarkupRectangle {
57
110
  this._ref.scale({ x: 1, y: 1 });
58
111
  });
59
112
 
113
+ this._ref.on("transformend", (e) => {
114
+ const attrs = e.target.attrs;
115
+ if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
116
+
117
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
118
+ const position = absoluteTransform.point({ x: this._ref.x(), y: this._ref.y() });
119
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
120
+ this._ref.setAttr(
121
+ "wcsEnd",
122
+ this._worldTransformer.screenToWorld({ x: position.x + this._ref.width(), y: position.y + this._ref.height() })
123
+ );
124
+ });
125
+
126
+ this._ref.on("dragend", (e) => {
127
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
128
+ const position = absoluteTransform.point({ x: this._ref.x(), y: this._ref.y() });
129
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
130
+ this._ref.setAttr(
131
+ "wcsEnd",
132
+ this._worldTransformer.screenToWorld({ x: position.x + this._ref.width(), y: position.y + this._ref.height() })
133
+ );
134
+ });
135
+
60
136
  this._ref.id(this._ref._id.toString());
61
137
  }
62
138
 
@@ -74,14 +150,23 @@ export class KonvaRectangle implements IMarkupRectangle {
74
150
 
75
151
  setWidth(w: number): void {
76
152
  this._ref.width(w);
153
+
154
+ const rightLowerPoint = { x: this._ref.x() + w, y: this._ref.y() + this._ref.height() };
155
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
156
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
77
157
  }
78
158
 
79
159
  setHeight(h: number): void {
80
160
  this._ref.height(h);
161
+
162
+ const rightLowerPoint = { x: this._ref.x() + this._ref.width(), y: this._ref.y() + h };
163
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
164
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
81
165
  }
82
166
 
83
167
  setPosition(x: number, y: number): void {
84
168
  this._ref.setPosition({ x, y });
169
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({ x, y }));
85
170
  }
86
171
 
87
172
  ref() {
@@ -136,4 +221,18 @@ export class KonvaRectangle implements IMarkupRectangle {
136
221
  getLineWidth(): number {
137
222
  return this._ref.strokeWidth();
138
223
  }
224
+
225
+ updateScreenCoordinates(): void {
226
+ let screenPositionStart = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart"));
227
+ let screenPositionEnd = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));
228
+
229
+ let invert = this._ref.getStage().getAbsoluteTransform().copy();
230
+ invert = invert.invert();
231
+ const positionStart = invert.point(screenPositionStart);
232
+ const positionEnd = invert.point(screenPositionEnd);
233
+
234
+ this._ref.position({ x: positionStart.x, y: positionStart.y });
235
+ this._ref.width(Math.abs(positionEnd.x - positionStart.x));
236
+ this._ref.height(Math.abs(positionEnd.y - positionStart.y));
237
+ }
139
238
  }
@@ -1,13 +1,45 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance").
3
+ // All rights reserved.
4
+ //
5
+ // This software and its documentation and related materials are owned by
6
+ // the Alliance. The software may only be incorporated into application
7
+ // programs owned by members of the Alliance, subject to a signed
8
+ // Membership Agreement and Supplemental Software License Agreement with the
9
+ // Alliance. The structure and organization of this software are the valuable
10
+ // trade secrets of the Alliance and its suppliers. The software is also
11
+ // protected by copyright law and international treaty provisions. Application
12
+ // programs incorporating this software must include the following statement
13
+ // with their copyright notices:
14
+ //
15
+ // This application incorporates Open Design Alliance software pursuant to a
16
+ // license agreement with Open Design Alliance.
17
+ // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance.
18
+ // All rights reserved.
19
+ //
20
+ // By use of this software, its documentation or related materials, you
21
+ // acknowledge and accept the above terms.
22
+ ///////////////////////////////////////////////////////////////////////////////
23
+
1
24
  import Konva from "konva";
2
25
  import { IMarkupText, IMarkupTextParams } from "../IMarkupText";
26
+ import { IWorldTransform } from "../IWorldTransform";
27
+ import { WorldTransform } from "../WorldTransform";
3
28
 
4
29
  export class KonvaText implements IMarkupText {
5
30
  private _ref: Konva.Text;
31
+ private _worldTransformer: IWorldTransform;
6
32
  private readonly TEXT_FONT_FAMILY = "Calibri";
7
33
 
8
- constructor(params: IMarkupTextParams, ref = null) {
34
+ constructor(params: IMarkupTextParams, ref = null, worldTransformer = new WorldTransform()) {
35
+ this._worldTransformer = worldTransformer;
36
+
9
37
  if (ref) {
10
38
  this._ref = ref;
39
+ const wcsStart = this._ref.getAttr("wcsStart");
40
+ if (!wcsStart) {
41
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({ x: ref.x(), y: ref.y() }));
42
+ }
11
43
  return;
12
44
  }
13
45
 
@@ -28,6 +60,7 @@ export class KonvaText implements IMarkupText {
28
60
  });
29
61
 
30
62
  this._ref.width(this._ref.getTextWidth());
63
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({ x: params.position.x, y: params.position.y }));
31
64
 
32
65
  this._ref.on("transform", (e) => {
33
66
  const attrs = e.target.attrs;
@@ -58,6 +91,21 @@ export class KonvaText implements IMarkupText {
58
91
  this._ref.scale({ x: 1, y: 1 });
59
92
  });
60
93
 
94
+ this._ref.on("transformend", (e) => {
95
+ const attrs = e.target.attrs;
96
+ if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
97
+
98
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
99
+ const position = absoluteTransform.point({ x: this._ref.x(), y: this._ref.y() });
100
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
101
+ });
102
+
103
+ this._ref.on("dragend", (e) => {
104
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
105
+ const position = absoluteTransform.point({ x: this._ref.x(), y: this._ref.y() });
106
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
107
+ });
108
+
61
109
  this._ref.id(this._ref._id.toString());
62
110
  }
63
111
 
@@ -101,7 +149,7 @@ export class KonvaText implements IMarkupText {
101
149
  this._ref.zIndex(zIndex);
102
150
  }
103
151
 
104
- delete() {
152
+ delete(): void {
105
153
  this._ref.destroy();
106
154
  this._ref = null;
107
155
  }
@@ -120,6 +168,7 @@ export class KonvaText implements IMarkupText {
120
168
 
121
169
  setPosition(x: number, y: number): void {
122
170
  this._ref.setPosition({ x, y });
171
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({ x, y }));
123
172
  }
124
173
 
125
174
  getFontSize(): number {
@@ -129,4 +178,14 @@ export class KonvaText implements IMarkupText {
129
178
  setFontSize(size: number): void {
130
179
  this._ref.fontSize(size);
131
180
  }
181
+
182
+ updateScreenCoordinates(): void {
183
+ let screenPositionStart = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart"));
184
+
185
+ let invert = this._ref.getStage().getAbsoluteTransform().copy();
186
+ invert = invert.invert();
187
+ const positionStart = invert.point(screenPositionStart);
188
+
189
+ this._ref.position({ x: positionStart.x, y: positionStart.y });
190
+ }
132
191
  }