@inweb/viewer-visualize 25.4.4 → 25.4.7

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 (42) hide show
  1. package/dist/viewer-visualize.js +158 -19
  2. package/dist/viewer-visualize.js.map +1 -1
  3. package/dist/viewer-visualize.min.js +1 -1
  4. package/dist/viewer-visualize.module.js +84 -18
  5. package/dist/viewer-visualize.module.js.map +1 -1
  6. package/lib/Viewer/Markup/Api/IMarkupArrow.d.ts +31 -0
  7. package/lib/Viewer/Markup/Api/IMarkupCloud.d.ts +36 -0
  8. package/lib/Viewer/Markup/Api/IMarkupColorable.d.ts +11 -0
  9. package/lib/Viewer/Markup/Api/IMarkupEllipse.d.ts +36 -0
  10. package/lib/Viewer/Markup/Api/IMarkupImage.d.ts +36 -0
  11. package/lib/Viewer/Markup/Api/IMarkupLine.d.ts +27 -0
  12. package/lib/Viewer/Markup/Api/IMarkupObject.d.ts +37 -1
  13. package/lib/Viewer/Markup/Api/IMarkupRectangle.d.ts +36 -0
  14. package/lib/Viewer/Markup/Api/IMarkupText.d.ts +28 -0
  15. package/lib/Viewer/Markup/IMarkup.d.ts +85 -0
  16. package/lib/Viewer/Markup/Impl/Konva/MarkupColor.d.ts +17 -0
  17. package/lib/Viewer/Markup/Impl/Visualize/VisualizeMarkup.d.ts +0 -1
  18. package/lib/Viewer/Markup/MarkupFactory.d.ts +6 -0
  19. package/lib/Viewer/Viewer.d.ts +2 -0
  20. package/package.json +4 -4
  21. package/src/Viewer/Markup/Api/IMarkupArrow.ts +57 -0
  22. package/src/Viewer/Markup/Api/IMarkupCloud.ts +63 -0
  23. package/src/Viewer/Markup/Api/IMarkupColorable.ts +35 -0
  24. package/src/Viewer/Markup/Api/IMarkupEllipse.ts +63 -0
  25. package/src/Viewer/Markup/Api/IMarkupImage.ts +63 -0
  26. package/src/Viewer/Markup/Api/IMarkupLine.ts +52 -0
  27. package/src/Viewer/Markup/Api/IMarkupObject.ts +65 -2
  28. package/src/Viewer/Markup/Api/IMarkupRectangle.ts +63 -0
  29. package/src/Viewer/Markup/Api/IMarkupText.ts +54 -0
  30. package/src/Viewer/Markup/Api/Impl/Konva/KonvaArrow.ts +30 -0
  31. package/src/Viewer/Markup/Api/Impl/Konva/KonvaCloud.ts +6 -4
  32. package/src/Viewer/Markup/Api/Impl/Konva/KonvaEllipse.ts +21 -2
  33. package/src/Viewer/Markup/Api/Impl/Konva/KonvaImage.ts +19 -9
  34. package/src/Viewer/Markup/Api/Impl/Konva/KonvaLine.ts +6 -0
  35. package/src/Viewer/Markup/Api/Impl/Konva/KonvaRectangle.ts +19 -0
  36. package/src/Viewer/Markup/Api/Impl/Konva/KonvaText.ts +19 -0
  37. package/src/Viewer/Markup/IMarkup.ts +120 -0
  38. package/src/Viewer/Markup/Impl/Konva/KonvaMarkup.ts +29 -4
  39. package/src/Viewer/Markup/Impl/Konva/MarkupColor.ts +40 -0
  40. package/src/Viewer/Markup/Impl/Visualize/VisualizeMarkup.ts +0 -4
  41. package/src/Viewer/Markup/MarkupFactory.ts +29 -0
  42. package/src/Viewer/Viewer.ts +4 -2
@@ -36,6 +36,25 @@ export class KonvaEllipse implements IMarkupEllipse, IMarkupColorable {
36
36
  strokeScaleEnabled: false,
37
37
  });
38
38
 
39
+ this._ref.on("transform", (e) => {
40
+ const attrs = e.target.attrs;
41
+
42
+ if (attrs.rotation !== this.getRotation()) this.setRotation(attrs.rotation);
43
+
44
+ const newRadiusX = this._ref.radiusX() * attrs.scaleX;
45
+ const newRadiusY = this._ref.radiusY() * attrs.scaleY;
46
+
47
+ if (Math.abs(attrs.scaleX - 1) > 10e-6) {
48
+ this.setRadiusX(newRadiusX);
49
+ }
50
+
51
+ if (Math.abs(attrs.scaleY - 1) > 10e-6) {
52
+ this.setRadiusY(newRadiusY);
53
+ }
54
+
55
+ this._ref.scale({ x: 1, y: 1 });
56
+ });
57
+
39
58
  this._ref.id(this._ref._id.toString());
40
59
  }
41
60
 
@@ -52,7 +71,7 @@ export class KonvaEllipse implements IMarkupEllipse, IMarkupColorable {
52
71
  }
53
72
 
54
73
  setRadiusX(r: number) {
55
- this._ref.radius({ x: r, y: this._ref.radiusY() });
74
+ this._ref.radiusX(r);
56
75
  }
57
76
 
58
77
  getRadiusY(): number {
@@ -60,7 +79,7 @@ export class KonvaEllipse implements IMarkupEllipse, IMarkupColorable {
60
79
  }
61
80
 
62
81
  setRadiusY(r: number) {
63
- this._ref.radius({ x: this._ref.radiusX(), y: r });
82
+ this._ref.radiusY(r);
64
83
  }
65
84
 
66
85
  getLineWidth(): number {
@@ -40,6 +40,25 @@ export class KonvaImage implements IMarkupImage {
40
40
 
41
41
  this._canvasImage.src = params.src;
42
42
 
43
+ this._ref.on("transform", (e) => {
44
+ const attrs = e.target.attrs;
45
+
46
+ if (attrs.rotation !== this.getRotation()) this.setRotation(attrs.rotation);
47
+
48
+ const newWidth = this._ref.width() * attrs.scaleX;
49
+ const newHeight = this._ref.height() * attrs.scaleY;
50
+
51
+ if (Math.abs(attrs.scaleX - 1) > 10e-6) {
52
+ this.setWidth(newWidth);
53
+ }
54
+
55
+ if (Math.abs(attrs.scaleY - 1) > 10e-6) {
56
+ this.setHeight(newHeight);
57
+ }
58
+
59
+ this._ref.scale({ x: 1, y: 1 });
60
+ });
61
+
43
62
  this._ref.id(this._ref._id.toString());
44
63
  }
45
64
 
@@ -85,15 +104,6 @@ export class KonvaImage implements IMarkupImage {
85
104
  return "image";
86
105
  }
87
106
 
88
- // we can break Liskov Substitution Principle, need to use separate IColorable
89
- // getColor(): string {
90
- // return this._ref.fill();
91
- // }
92
-
93
- // setColor(hex: string) {
94
- // this._ref.fill(hex);
95
- // }
96
-
97
107
  getRotation(): number {
98
108
  return this._ref.rotation();
99
109
  }
@@ -38,6 +38,12 @@ export class KonvaLine implements IMarkupLine, IMarkupColorable {
38
38
  dash: LineTypeSpecs.get(params.type) || [],
39
39
  });
40
40
 
41
+ this._ref.on("transform", (e) => {
42
+ const attrs = e.target.attrs;
43
+
44
+ if (attrs.rotation !== this.getRotation()) this.setRotation(attrs.rotation);
45
+ });
46
+
41
47
  this._ref.id(this._ref._id.toString());
42
48
  }
43
49
 
@@ -37,6 +37,25 @@ export class KonvaRectangle implements IMarkupRectangle, IMarkupColorable {
37
37
  strokeScaleEnabled: false,
38
38
  });
39
39
 
40
+ this._ref.on("transform", (e) => {
41
+ const attrs = e.target.attrs;
42
+
43
+ if (attrs.rotation !== this.getRotation()) this.setRotation(attrs.rotation);
44
+
45
+ const newWidth = this._ref.width() * attrs.scaleX;
46
+ const newHeight = this._ref.height() * attrs.scaleY;
47
+
48
+ if (Math.abs(attrs.scaleX - 1) > 10e-6) {
49
+ this.setWidth(newWidth);
50
+ }
51
+
52
+ if (Math.abs(attrs.scaleY - 1) > 10e-6) {
53
+ this.setHeight(newHeight);
54
+ }
55
+
56
+ this._ref.scale({ x: 1, y: 1 });
57
+ });
58
+
40
59
  this._ref.id(this._ref._id.toString());
41
60
  }
42
61
 
@@ -36,6 +36,25 @@ export class KonvaText implements IMarkupText, IMarkupColorable {
36
36
  rotation: params.rotation ?? 0,
37
37
  });
38
38
 
39
+ this._ref.on("transform", (e) => {
40
+ const attrs = e.target.attrs;
41
+
42
+ if (attrs.rotation !== this.getRotation()) this.setRotation(attrs.rotation);
43
+
44
+ const newWidth = this._ref.width() * attrs.scaleX;
45
+ const newHeight = this._ref.height() * attrs.scaleY;
46
+
47
+ if (Math.abs(attrs.scaleX - 1) > 10e-6) {
48
+ this.setFontSize(Math.round((this.getFontSize() * newWidth) / this._ref.width()));
49
+ }
50
+
51
+ if (Math.abs(attrs.scaleY - 1) > 10e-6) {
52
+ this.setFontSize(Math.round((this.getFontSize() * newHeight) / this._ref.height()));
53
+ }
54
+
55
+ this._ref.scale({ x: 1, y: 1 });
56
+ });
57
+
39
58
  this._ref.id(this._ref._id.toString());
40
59
  }
41
60
 
@@ -1,15 +1,45 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2002-2024, 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-2024 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 { IViewpoint } from "@inweb/viewer-core";
2
25
 
3
26
  import { OdBaseDragger } from "../Draggers/Common/OdBaseDragger";
4
27
  import { Viewer } from "../Viewer";
5
28
  import { IMarkupObject } from "./Api/IMarkupObject";
6
29
 
30
+ /**
31
+ * Version of the markup support. Old = "Visualize", New = "Konva"
32
+ */
7
33
  export enum MarkupType {
8
34
  Unknown,
9
35
  Konva = "Konva",
10
36
  Visualize = "Visualize",
11
37
  }
12
38
 
39
+ /**
40
+ * Defines type of markup object. For old Visualize markup ({@link MarkupType}) only "Line" and
41
+ * "Text" markup objects are supported.
42
+ */
13
43
  export enum MarkupMode {
14
44
  Line = "Line",
15
45
  Text = "Text",
@@ -20,24 +50,114 @@ export enum MarkupMode {
20
50
  Cloud = "Cloud",
21
51
  }
22
52
 
53
+ /**
54
+ * Specifies parameters and methods of the Markup object
55
+ */
23
56
  export interface IMarkup {
57
+ /**
58
+ * Width of the markup object line
59
+ */
24
60
  lineWidth: number;
25
61
 
62
+ /**
63
+ * Start method to init Markup support for the Viewer instance.
64
+ *
65
+ * @param {Viewer} viewer - current {@link Viewer} object
66
+ * @param canvas - {@link HTMLCanvasElement} of the Viewer
67
+ * @param canvasEvents - list of used events of the Viewer
68
+ */
26
69
  initialize(viewer: Viewer, canvas: HTMLCanvasElement, canvasEvents: string[]): void;
70
+
71
+ /**
72
+ * Releases all resources allocated by this `Markup` instance. Call this method before
73
+ * release the `Markup` instance.
74
+ */
27
75
  dispose(): void;
28
76
 
77
+ /**
78
+ * Provide Javascript Map with all {@link OdBaseDragger} draggers used by Markup. We need this
79
+ * map to register in {@link Viewer.registerDragger}
80
+ */
29
81
  getDraggers(): Map<string, typeof OdBaseDragger>;
82
+
83
+ /**
84
+ * Remove markup overlay.
85
+ */
30
86
  clearOverlay(): void;
87
+
88
+ /**
89
+ * Set markup color.
90
+ *
91
+ * @param r - `Red` part of color.
92
+ * @param g - `Green` part of color.
93
+ * @param b - `Blue` part of color.
94
+ */
31
95
  setMarkupColor(r: number, g: number, b: number): void;
96
+
97
+ /**
98
+ * Get markup color.
99
+ *
100
+ * @returns Color with `RGB` values.
101
+ */
32
102
  getMarkupColor(): { r: number; g: number; b: number };
103
+
104
+ /**
105
+ * Colorize all markup entities with the specified color.
106
+ *
107
+ * @param r - `Red` part of color.
108
+ * @param g - `Green` part of color.
109
+ * @param b - `Blue` part of color.
110
+ */
33
111
  colorizeAllMarkup(r: number, g: number, b: number): void;
112
+
113
+ /**
114
+ * Colorize all selected markup entities with the specified color.
115
+ *
116
+ * @param r - `Red` part of color.
117
+ * @param g - `Green` part of color.
118
+ * @param b - `Blue` part of color.
119
+ */
34
120
  colorizeSelectedMarkups(r: number, g: number, b: number): void;
121
+
122
+ /**
123
+ * Draw a viewpoint. To get a list of available model viewpoints, use the
124
+ *
125
+ * @param viewpoint - Viewpoint data.
126
+ */
35
127
  setViewpoint(viewpoint: IViewpoint): void;
128
+
129
+ /**
130
+ * Create a {@link IViewpoint} viewpoint
131
+ */
36
132
  getViewpoint(): IViewpoint;
37
133
 
134
+ /**
135
+ * Create a Markup object
136
+ *
137
+ * @param type - string identificator of Markup type
138
+ * @param params - object with parameters of Markup
139
+ */
38
140
  createObject(type: string, params: any): IMarkupObject;
141
+
142
+ /**
143
+ * Get array of all existed Markup objects
144
+ */
39
145
  getObjects(): IMarkupObject[];
146
+
147
+ /**
148
+ * Get array of currently selected Markup objects
149
+ */
40
150
  getSelectedObjects(): IMarkupObject[];
151
+
152
+ /**
153
+ * Select list of Markup objects
154
+ *
155
+ * @param objects
156
+ */
41
157
  selectObjects(objects: IMarkupObject[]): void;
158
+
159
+ /**
160
+ * Clear list of currently selected Markup objects
161
+ */
42
162
  clearSelected(): void;
43
163
  }
@@ -1,3 +1,26 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2002-2024, 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-2024 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 { ChangeActiveDraggerEvent, IViewpoint, LineType, PanEvent } from "@inweb/viewer-core";
3
26
 
@@ -295,7 +318,7 @@ export class KonvaMarkup implements IMarkup {
295
318
  let zIndex = this._zIndex;
296
319
 
297
320
  // TODO: factory?
298
- switch (type) {
321
+ switch (type.toLocaleLowerCase()) {
299
322
  case "line":
300
323
  object = new KonvaLine(params);
301
324
  zIndex = 1;
@@ -1269,11 +1292,13 @@ export class KonvaMarkup implements IMarkup {
1269
1292
  width?: number,
1270
1293
  height?: number,
1271
1294
  id?: string
1272
- ): void {
1295
+ ): IMarkupImage | void {
1273
1296
  if (!position) return;
1274
1297
 
1298
+ let konvaImage: IMarkupImage;
1299
+
1275
1300
  if (src) {
1276
- const konvaImage = new KonvaImage({
1301
+ konvaImage = new KonvaImage({
1277
1302
  position,
1278
1303
  src,
1279
1304
  width,
@@ -1294,6 +1319,6 @@ export class KonvaMarkup implements IMarkup {
1294
1319
 
1295
1320
  this.removeImageInput();
1296
1321
 
1297
- return;
1322
+ return konvaImage;
1298
1323
  }
1299
1324
  }
@@ -1,3 +1,26 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2002-2024, 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-2024 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
  export class MarkupColor {
2
25
  public R: number;
3
26
  public G: number;
@@ -12,14 +35,31 @@ export class MarkupColor {
12
35
  return "#" + this._hex;
13
36
  }
14
37
 
38
+ /**
39
+ * Color as object with r,g,b properties
40
+ */
15
41
  get RGB(): { r: number; g: number; b: number } {
16
42
  return { r: this.R, g: this.G, b: this.B };
17
43
  }
18
44
 
45
+ /**
46
+ * Create an instance of Color
47
+ *
48
+ * @param r - Red color in [0,255] range
49
+ * @param g - Green color in [0,255] range
50
+ * @param b - Blue color in [0,255] range
51
+ */
19
52
  constructor(r: number, g: number, b: number) {
20
53
  this.setColor(r, g, b);
21
54
  }
22
55
 
56
+ /**
57
+ * Set Color for current instance
58
+ *
59
+ * @param r - Red color in [0,255] range
60
+ * @param g - Green color in [0,255] range
61
+ * @param b - Blue color in [0,255] range
62
+ */
23
63
  public setColor(r: number, g: number, b: number): void {
24
64
  this.R = r;
25
65
  this.G = g;
@@ -207,10 +207,6 @@ export class VisualizeMarkup implements IMarkup {
207
207
  return viewpoint;
208
208
  }
209
209
 
210
- getLayer(): any {
211
- throw new Error("Not implemented yet");
212
- }
213
-
214
210
  createObject(type: string, params: any): IMarkupObject {
215
211
  throw new Error("Not implemented yet");
216
212
  }
@@ -1,8 +1,37 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2002-2024, 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-2024 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 { IMarkup, MarkupType } from "./IMarkup";
2
25
  import { KonvaMarkup } from "./Impl/Konva/KonvaMarkup";
3
26
  import { VisualizeMarkup } from "./Impl/Visualize/VisualizeMarkup";
4
27
 
5
28
  export class MarkupFactory {
29
+ /**
30
+ * Initialize {@link IMarkup} instance
31
+ *
32
+ * @param markupType - Specifies version of the markup support. Two variants of markup
33
+ * support are implemented: old "Visualize" and new "Konva". Default is "Konva". {@link MarkupType}
34
+ */
6
35
  public static createMarkup(markupType: MarkupType): IMarkup {
7
36
  let markup;
8
37
  switch (markupType) {
@@ -1,5 +1,5 @@
1
1
  ///////////////////////////////////////////////////////////////////////////////
2
- // Copyright (C) 2002-2023, Open Design Alliance (the "Alliance").
2
+ // Copyright (C) 2002-2024, Open Design Alliance (the "Alliance").
3
3
  // All rights reserved.
4
4
  //
5
5
  // This software and its documentation and related materials are owned by
@@ -14,7 +14,7 @@
14
14
  //
15
15
  // This application incorporates Open Design Alliance software pursuant to a
16
16
  // license agreement with Open Design Alliance.
17
- // Open Design Alliance Copyright (C) 2002-2021 by Open Design Alliance.
17
+ // Open Design Alliance Copyright (C) 2002-2024 by Open Design Alliance.
18
18
  // All rights reserved.
19
19
  //
20
20
  // By use of this software, its documentation or related materials, you
@@ -104,6 +104,8 @@ export class Viewer extends EventEmitter2<ViewerEventMap & OptionsEventMap> impl
104
104
  * @param params.enableAutoUpdate - Enable auto-update of the viewer after any changes. If
105
105
  * the auto-update is disabled, you need to update the `VisualizeJS` viewer and the active
106
106
  * dragger manually using the `update` event. Default is `true`.
107
+ * @param params.markupType - Specifies version of the markup support. Two variants of markup
108
+ * support are implemented: old "Visualize" and new "Konva". Default is "Konva". {@link MarkupType}
107
109
  */
108
110
  constructor(
109
111
  client?: Client,