@inweb/markup 26.4.0 → 26.5.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 (40) hide show
  1. package/dist/markup.js +636 -137
  2. package/dist/markup.js.map +1 -1
  3. package/dist/markup.min.js +1 -1
  4. package/dist/markup.module.js +772 -151
  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 +19 -4
  9. package/lib/markup/IMarkupImage.d.ts +15 -7
  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 +12 -5
  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/lib/markup/Utils.d.ts +7 -0
  23. package/package.json +3 -3
  24. package/src/markup/IMarkupArrow.ts +8 -8
  25. package/src/markup/IMarkupCloud.ts +10 -5
  26. package/src/markup/IMarkupEllipse.ts +15 -4
  27. package/src/markup/IMarkupImage.ts +13 -7
  28. package/src/markup/IMarkupLine.ts +2 -2
  29. package/src/markup/IMarkupObject.ts +5 -0
  30. package/src/markup/IMarkupRectangle.ts +10 -5
  31. package/src/markup/IMarkupText.ts +3 -3
  32. package/src/markup/Konva/KonvaArrow.ts +49 -4
  33. package/src/markup/Konva/KonvaCloud.ts +113 -11
  34. package/src/markup/Konva/KonvaEllipse.ts +110 -3
  35. package/src/markup/Konva/KonvaImage.ts +101 -2
  36. package/src/markup/Konva/KonvaLine.ts +97 -3
  37. package/src/markup/Konva/KonvaMarkup.ts +216 -172
  38. package/src/markup/Konva/KonvaRectangle.ts +106 -4
  39. package/src/markup/Konva/KonvaText.ts +61 -2
  40. package/src/markup/Utils.ts +3 -0
@@ -1,5 +1,30 @@
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 { IMarkupImage, IMarkupImageParams } from "../IMarkupImage";
26
+ import { IWorldTransform } from "../IWorldTransform";
27
+ import { WorldTransform } from "../WorldTransform";
3
28
 
4
29
  export class KonvaImage implements IMarkupImage {
5
30
  private _ref: Konva.Image;
@@ -9,8 +34,11 @@ export class KonvaImage implements IMarkupImage {
9
34
  private readonly BASE64_HEADER_START = "data:image/";
10
35
  private readonly BASE64_NOT_FOUND =
11
36
  "data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAADsAAAA7AF5KHG9AAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAmhJREFUWIXtlr9rVEEQxz+H8RQUJIdeIopYm0vkCg0GBBtbG1NF7Kxt7dR/IGIw/uhTaBNLERURg2kCEUyCYCPi70b0InjGS57FzOZN3r19d+9HJIVfWO52dma/s7Mz8xa2KAaBCWAR+AkECWOmSOIdwC1gtQOpHc+NfQ8wClQ8+1d0vcdH/lQ3bSIRGAZ2pTjAqNovANXIWlXlAXA2zvi2Ln4AjqYgtagYEutENSLvjRoOImFv5iB32Ae8UrLXwFBk3h9ndF0VJnKSO9gTu3yKu5Z1LKnS8YIcABgw5Ks692JZFXcXRJ46Aq6kikCnHNi/mQ50WwVtfaIoBzL3gRk2drSscJ2wrc4VvUoe2wn/41/iBfoVLRnBGnDSY3AAKacy8AmYR+o7K1zCl6wgrgpOAc/MuhvfgMuk+1JGHQgSBcAloKXy78AjYBppJk5/noTulseBMZ23iD/piHFkEdgTQzKk+5wHjmHC3cmBg0BD5xcSTrFXyQPgIWFtDwMvab+2N8DpbhyY1v/3E8gdDgNfVX9SCVZ0/gW4B0wB71S2BpxLcuCM/jaQSHSDEeAX4VMuAG4gTzyHbcAVXXO6GxxwIX+vvxe7JHcYQ07nHqklj96UIW/YhSWzMKcep8VVtf8B1Dw6h4DfhB+sdbgn2R+gnoEc5NR3dZ+3QJ9H74HqXLPCGlJyTfI9y3YCs0owq3OLOpKkLeBI1HhSDT/mdKIPiUCARMTlQx34TMLjtww8IczmO8AJ/N/2JNSQXAiQ671JePePge0+wzJSQq4FFzlaenIvucUAkiQLhC/mLGNZ9xgn5s63BP4CCk0QDtm4BhoAAAAASUVORK5CYII=";
37
+ private _worldTransformer: IWorldTransform;
38
+
39
+ constructor(params: IMarkupImageParams, ref = null, worldTransformer = new WorldTransform()) {
40
+ this._worldTransformer = worldTransformer;
12
41
 
13
- constructor(params: IMarkupImageParams, ref = null) {
14
42
  if (ref) {
15
43
  if (!ref.src || !ref.src.startsWith(this.BASE64_HEADER_START)) ref.src = this.BASE64_NOT_FOUND;
16
44
  if (ref.height() <= this.EPSILON) ref.height(32);
@@ -23,12 +51,29 @@ export class KonvaImage implements IMarkupImage {
23
51
  ? 1
24
52
  : this._ref.height() / this._ref.width();
25
53
 
54
+ const wcsStart = this._ref.getAttr("wcsStart");
55
+ const wcsEnd = this._ref.getAttr("wcsEnd");
56
+ if (!wcsStart) {
57
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({ x: ref.x(), y: ref.y() }));
58
+ }
59
+ if (!wcsEnd) {
60
+ const rightBottomPoint = { x: ref.x() + ref.width(), y: ref.y() + ref.height() };
61
+ this._ref.setAttr(
62
+ "wcsEnd",
63
+ this._worldTransformer.screenToWorld({ x: rightBottomPoint.x, y: rightBottomPoint.y })
64
+ );
65
+ }
66
+
26
67
  return;
27
68
  }
28
69
 
29
70
  if (!params) params = {};
30
71
  if (!params.position) params.position = { x: 0, y: 0 };
31
72
  if (!params.src || !params.src.startsWith(this.BASE64_HEADER_START)) params.src = this.BASE64_NOT_FOUND;
73
+ if (params.position2) {
74
+ params.width = params.position2.x - params.position.x;
75
+ params.height = params.position2.y - params.position.y;
76
+ }
32
77
 
33
78
  this._canvasImage = new Image();
34
79
 
@@ -58,6 +103,12 @@ export class KonvaImage implements IMarkupImage {
58
103
  this._ref.width(params.maxHeight / this._ratio);
59
104
  this._ref.height(params.maxHeight);
60
105
  }
106
+
107
+ const wcsEnd = this._worldTransformer.screenToWorld({
108
+ x: params.position.x + this._ref.width(),
109
+ y: params.position.y + this._ref.height(),
110
+ });
111
+ this._ref.setAttr("wcsEnd", wcsEnd);
61
112
  }
62
113
  }
63
114
  };
@@ -78,6 +129,8 @@ export class KonvaImage implements IMarkupImage {
78
129
  draggable: true,
79
130
  });
80
131
 
132
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({ x: params.position.x, y: params.position.y }));
133
+
81
134
  this._ref.on("transform", (e) => {
82
135
  const attrs = e.target.attrs;
83
136
 
@@ -111,6 +164,26 @@ export class KonvaImage implements IMarkupImage {
111
164
  this._ref.scale({ x: 1, y: 1 });
112
165
  });
113
166
 
167
+ this._ref.on("transformend", (e) => {
168
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
169
+ const position = absoluteTransform.point({ x: this._ref.x(), y: this._ref.y() });
170
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
171
+ this._ref.setAttr(
172
+ "wcsEnd",
173
+ this._worldTransformer.screenToWorld({ x: position.x + this._ref.width(), y: position.y + this._ref.height() })
174
+ );
175
+ });
176
+
177
+ this._ref.on("dragend", (e) => {
178
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
179
+ const position = absoluteTransform.point({ x: this._ref.x(), y: this._ref.y() });
180
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
181
+ this._ref.setAttr(
182
+ "wcsEnd",
183
+ this._worldTransformer.screenToWorld({ x: position.x + this._ref.width(), y: position.y + this._ref.height() })
184
+ );
185
+ });
186
+
114
187
  this._ref.id(this._ref._id.toString());
115
188
  }
116
189
 
@@ -129,6 +202,10 @@ export class KonvaImage implements IMarkupImage {
129
202
  setWidth(w: number): void {
130
203
  this._ref.width(w);
131
204
  this._ref.height(w * this._ratio);
205
+
206
+ const rightLowerPoint = { x: this._ref.x() + w, y: this._ref.y() + this._ref.height() };
207
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
208
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
132
209
  }
133
210
 
134
211
  getHeight(): number {
@@ -138,6 +215,10 @@ export class KonvaImage implements IMarkupImage {
138
215
  setHeight(h: number): void {
139
216
  this._ref.height(h);
140
217
  this._ref.width(h / this._ratio);
218
+
219
+ const rightLowerPoint = { x: this._ref.x() + this._ref.width(), y: this._ref.y() + h };
220
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
221
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
141
222
  }
142
223
 
143
224
  ref() {
@@ -172,7 +253,7 @@ export class KonvaImage implements IMarkupImage {
172
253
  this._ref.zIndex(zIndex);
173
254
  }
174
255
 
175
- delete() {
256
+ delete(): void {
176
257
  this._ref.destroy();
177
258
  this._ref = null;
178
259
  }
@@ -183,5 +264,23 @@ export class KonvaImage implements IMarkupImage {
183
264
 
184
265
  setPosition(x: number, y: number): void {
185
266
  this._ref.setPosition({ x, y });
267
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({ x, y }));
268
+ const rightLowerPoint = { x: x + this._ref.width(), y: y + this._ref.y() };
269
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
270
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
271
+ }
272
+
273
+ updateScreenCoordinates(): void {
274
+ let screenPositionStart = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart"));
275
+ let screenPositionEnd = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));
276
+
277
+ let invert = this._ref.getStage().getAbsoluteTransform().copy();
278
+ invert = invert.invert();
279
+ const positionStart = invert.point(screenPositionStart);
280
+ const positionEnd = invert.point(screenPositionEnd);
281
+
282
+ this._ref.position({ x: positionStart.x, y: positionStart.y });
283
+ this._ref.width(Math.abs(positionEnd.x - positionStart.x));
284
+ this._ref.height(Math.abs(positionEnd.y - positionStart.y));
186
285
  }
187
286
  }
@@ -1,5 +1,30 @@
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 { IMarkupLine, IMarkupLineParams, MarkupLineType } from "../IMarkupLine";
26
+ import { IWorldTransform } from "../IWorldTransform";
27
+ import { WorldTransform } from "../WorldTransform";
3
28
 
4
29
  const LineTypeSpecs = new Map<string, number[]>([
5
30
  ["solid", []],
@@ -9,10 +34,24 @@ const LineTypeSpecs = new Map<string, number[]>([
9
34
 
10
35
  export class KonvaLine implements IMarkupLine {
11
36
  private _ref: Konva.Line;
37
+ private _worldTransformer: IWorldTransform;
38
+
39
+ constructor(params: IMarkupLineParams, ref = null, worldTransformer = new WorldTransform()) {
40
+ this._worldTransformer = worldTransformer;
12
41
 
13
- constructor(params: IMarkupLineParams, ref = null) {
14
42
  if (ref) {
15
43
  this._ref = ref;
44
+ let wcsPoints = this._ref.getAttr("wcsPoints");
45
+ if (!wcsPoints) {
46
+ wcsPoints = [];
47
+ let points = this._ref.points();
48
+ let wcsPoint;
49
+ for (let i = 0; i < points.length; i += 2) {
50
+ wcsPoint = this._worldTransformer.screenToWorld({ x: points[i], y: points[i + 1] });
51
+ wcsPoints.push({ x: wcsPoint.x, y: wcsPoint.y, z: wcsPoint.z });
52
+ }
53
+ this._ref.setAttr("wcsPoints", wcsPoints);
54
+ }
16
55
  return;
17
56
  }
18
57
 
@@ -24,7 +63,12 @@ export class KonvaLine implements IMarkupLine {
24
63
  ];
25
64
 
26
65
  const konvaPoints = [];
27
- params.points.forEach((point) => konvaPoints.push(point.x, point.y));
66
+ const wcsPoints = [];
67
+ params.points.forEach((point) => {
68
+ konvaPoints.push(point.x, point.y);
69
+ let wcsPoint = this._worldTransformer.screenToWorld({ x: point.x, y: point.y });
70
+ wcsPoints.push({ x: wcsPoint.x, y: wcsPoint.y, z: wcsPoint.z });
71
+ });
28
72
 
29
73
  this._ref = new Konva.Line({
30
74
  stroke: params.color ?? "#ff0000",
@@ -38,12 +82,42 @@ export class KonvaLine implements IMarkupLine {
38
82
  dash: LineTypeSpecs.get(params.type) || [],
39
83
  });
40
84
 
85
+ this._ref.setAttr("wcsPoints", wcsPoints);
86
+
41
87
  this._ref.on("transform", (e) => {
42
88
  const attrs = e.target.attrs;
43
89
 
44
90
  if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
45
91
  });
46
92
 
93
+ this._ref.on("transformend", (e) => {
94
+ const absoluteTransform = this._ref.getAbsoluteTransform();
95
+
96
+ let wcsPoints = [];
97
+ let points = this._ref.points();
98
+ let wcsPoint;
99
+ for (let i = 0; i < points.length; i += 2) {
100
+ const position = absoluteTransform.point({ x: points[i], y: points[i + 1] });
101
+ wcsPoint = this._worldTransformer.screenToWorld({ x: position.x, y: position.y });
102
+ wcsPoints.push({ x: wcsPoint.x, y: wcsPoint.y, z: wcsPoint.z });
103
+ }
104
+ this._ref.setAttr("wcsPoints", wcsPoints);
105
+ });
106
+
107
+ this._ref.on("dragend", (e) => {
108
+ const absoluteTransform = this._ref.getAbsoluteTransform();
109
+
110
+ let wcsPoints = [];
111
+ let points = this._ref.points();
112
+ let wcsPoint;
113
+ for (let i = 0; i < points.length; i += 2) {
114
+ const position = absoluteTransform.point({ x: points[i], y: points[i + 1] });
115
+ wcsPoint = this._worldTransformer.screenToWorld({ x: position.x, y: position.y });
116
+ wcsPoints.push({ x: wcsPoint.x, y: wcsPoint.y, z: wcsPoint.z });
117
+ }
118
+ this._ref.setAttr("wcsPoints", wcsPoints);
119
+ });
120
+
47
121
  this._ref.id(this._ref._id.toString());
48
122
  }
49
123
 
@@ -87,7 +161,7 @@ export class KonvaLine implements IMarkupLine {
87
161
  this._ref.zIndex(zIndex);
88
162
  }
89
163
 
90
- delete() {
164
+ delete(): void {
91
165
  this._ref.destroy();
92
166
  this._ref = null;
93
167
  }
@@ -128,10 +202,30 @@ export class KonvaLine implements IMarkupLine {
128
202
 
129
203
  addPoints(points: [{ x: number; y: number }]) {
130
204
  let newPoints = this._ref.points();
205
+ let wcsPoints = this._ref.getAttr("wcsPoints");
131
206
  points.forEach((point) => {
132
207
  newPoints = newPoints.concat([point.x, point.y]);
208
+ let wcsPoint = this._worldTransformer.screenToWorld(point);
209
+ wcsPoints.push(wcsPoint);
133
210
  });
134
211
 
135
212
  this._ref.points(newPoints);
136
213
  }
214
+
215
+ updateScreenCoordinates(): void {
216
+ let wcsPoints = this._ref.getAttr("wcsPoints");
217
+ let points = [];
218
+ let invert = this._ref.getAbsoluteTransform().copy();
219
+ invert = invert.invert();
220
+ wcsPoints.forEach((point) => {
221
+ let screenPoint = this._worldTransformer.worldToScreen(point);
222
+ screenPoint = invert.point({ x: screenPoint.x, y: screenPoint.y });
223
+ points.push(screenPoint.x);
224
+ points.push(screenPoint.y);
225
+ });
226
+
227
+ this._ref.points([]);
228
+ this._ref.points(points);
229
+ this._ref.clearCache();
230
+ }
137
231
  }