@inweb/markup 25.8.16 → 25.8.19

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.
@@ -3,7 +3,7 @@ import { IViewpoint } from "@inweb/viewer-core";
3
3
  import { IWorldTransform } from "./IWorldTransform";
4
4
  import { IMarkupObject } from "./IMarkupObject";
5
5
  /**
6
- * Markup edit mode. Matches the type of markup object being created or object selecting mode.
6
+ * Defines the markup edit mode. Matches the type of markup object being created.
7
7
  */
8
8
  export type MarkupMode = "SelectMarkup" | "Line" | "Text" | "Rectangle" | "Ellipse" | "Arrow" | "Image" | "Cloud";
9
9
  /**
@@ -11,30 +11,35 @@ export type MarkupMode = "SelectMarkup" | "Line" | "Text" | "Rectangle" | "Ellip
11
11
  */
12
12
  export interface IMarkup {
13
13
  /**
14
- * Line width of the markup objects. Default is 4.
14
+ * Line width of new markup objects.
15
+ *
16
+ * @default 4
15
17
  */
16
18
  lineWidth: number;
17
19
  /**
18
- * Type of the markup line. Available types: `solid`, `dot`, `dash`. Default is `solid`.
20
+ * Line type of new markup objects. Can be `solid`, `dot` or `dash`.
21
+ *
22
+ * @default `solid`
19
23
  */
20
24
  lineType: string;
21
25
  /**
22
- * Font size of the markup text. Default is 34 px.
26
+ * Font size of new markup text, in pixels.
27
+ *
28
+ * @default 34
23
29
  */
24
30
  fontSize: number;
25
31
  /**
26
- * Initializes the markup instance.
32
+ * Initializes the markup instance. Call {@link dispose | dispose()} to release allocated resources.
27
33
  *
28
- * @param container - Container element used to operate on. This is usually a `canvas` or
29
- * `div` on top of which the markup is drawn. If the `container` is an element of type
30
- * {@link https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement | HTMLCanvasElement},
34
+ * @param container - Container element used to operate on. This is usually a `<canvas>` or
35
+ * `<div>` on top of which the markup is drawn. If the `container` is a `<canvas>` element,
31
36
  * its content will be combined with the markup in the viewpoint snapshot.
32
37
  * @param pointerEvents - List of pointing device events that the markup should redirect to
33
38
  * the `viewer`.
34
39
  * @param viewer - `Viewer` instance that receives pointing device events.
35
40
  * @param worldTransformer - Transformer of screen space into the `viewer` world space and
36
- * vice versa. If a transformer is defined, viewpoint objects will be stored in world
37
- * coordinates, otherwise in screen coordinates.
41
+ * vice versa. If a transformer is defined, markup objects will be stored at the viewpoint
42
+ * in world coordinates, otherwise in screen coordinates.
38
43
  */
39
44
  initialize(container: HTMLElement, pointerEvents?: string[], viewer?: IEventEmitter, worldTransformer?: IWorldTransform): void;
40
45
  /**
@@ -42,15 +47,15 @@ export interface IMarkup {
42
47
  */
43
48
  dispose(): void;
44
49
  /**
45
- * Create markup overlay.
50
+ * Creates the markup overlay.
46
51
  */
47
52
  syncOverlay(): void;
48
53
  /**
49
- * Clear markup overlay.
54
+ * Deletes all markup objects and clears the markup overlay.
50
55
  */
51
56
  clearOverlay(): void;
52
57
  /**
53
- * Set markup color.
58
+ * Sets the color of new markup objects.
54
59
  *
55
60
  * @param r - `Red` part of color.
56
61
  * @param g - `Green` part of color.
@@ -58,9 +63,7 @@ export interface IMarkup {
58
63
  */
59
64
  setMarkupColor(r: number, g: number, b: number): void;
60
65
  /**
61
- * Get markup color.
62
- *
63
- * @returns Color with `RGB` values.
66
+ * Returns the color of new markup objects.
64
67
  */
65
68
  getMarkupColor(): {
66
69
  r: number;
@@ -68,7 +71,7 @@ export interface IMarkup {
68
71
  b: number;
69
72
  };
70
73
  /**
71
- * Colorize all markup entities with the specified color.
74
+ * Colors all markup objects with the specified color.
72
75
  *
73
76
  * @param r - `Red` part of color.
74
77
  * @param g - `Green` part of color.
@@ -76,7 +79,7 @@ export interface IMarkup {
76
79
  */
77
80
  colorizeAllMarkup(r: number, g: number, b: number): void;
78
81
  /**
79
- * Colorize all selected markup entities with the specified color.
82
+ * Colors selected markup objects with the specified color.
80
83
  *
81
84
  * @param r - `Red` part of color.
82
85
  * @param g - `Green` part of color.
@@ -84,45 +87,46 @@ export interface IMarkup {
84
87
  */
85
88
  colorizeSelectedMarkups(r: number, g: number, b: number): void;
86
89
  /**
87
- * Draw a viewpoint. To get a list of available model viewpoints, use the
90
+ * Sets the markup state to the specified viewpoint.
88
91
  *
89
92
  * @param viewpoint - Viewpoint data.
90
93
  */
91
94
  setViewpoint(viewpoint: IViewpoint): void;
92
95
  /**
93
- * Create a viewpoint.
96
+ * Saves the markup state at the viewpoint.
94
97
  */
95
98
  getViewpoint(): IViewpoint;
96
99
  /**
97
100
  * Enables mouse interactions to select or draw markups.
98
101
  *
99
- * @param mode - Edit mode. Matches the type of markup object being created or object
100
- * selecting mode. To exit edit mode provide this to `false`.
102
+ * @param mode - Edit mode. Matches the type of markup object being created. Specify `false`
103
+ * to exit edit mode.
101
104
  */
102
105
  enableEditMode(mode: MarkupMode | false): this;
103
106
  /**
104
- * Create a Markup object.
107
+ * Creates a markup object.
105
108
  *
106
- * @param type - string identificator of Markup object type.
109
+ * @param type - Markup object type. Can be `Line`, `Text`, `Rectangle`, `Ellipse`, `Arrow`,
110
+ * `Image` or `Cloud`.
107
111
  * @param params - Markup object parameters.
108
112
  */
109
113
  createObject(type: string, params: any): IMarkupObject;
110
114
  /**
111
- * Get Markup objects.
115
+ * Returns the list of all markup objects.
112
116
  */
113
117
  getObjects(): IMarkupObject[];
114
118
  /**
115
- * Get selected Markup objects.
119
+ * Returns the list of selected markup objects.
116
120
  */
117
121
  getSelectedObjects(): IMarkupObject[];
118
122
  /**
119
- * Select Markup objects.
123
+ * Selects specified markup objects.
120
124
  *
121
- * @param objects
125
+ * @param objects - The list of markup objects.
122
126
  */
123
127
  selectObjects(objects: IMarkupObject[]): void;
124
128
  /**
125
- * Clear Markup objects selection.
129
+ * Clears the markup objects selection.
126
130
  */
127
131
  clearSelected(): void;
128
132
  }
@@ -1,7 +1,7 @@
1
1
  import { IMarkupObject } from "./IMarkupObject";
2
2
  import { IMarkupColorable } from "./IMarkupColorable";
3
3
  /**
4
- * Type of the markup line.
4
+ * Defines the type of the markup line.
5
5
  */
6
6
  export type MarkupLineType = "solid" | "dot" | "dash";
7
7
  /**
@@ -5,7 +5,7 @@ export interface IWorldTransform {
5
5
  /**
6
6
  * Transforms `position` from screen space into world space.
7
7
  *
8
- * @param position - screen position in pixels.
8
+ * @param position - Screen position in pixels.
9
9
  */
10
10
  screenToWorld(position: {
11
11
  x: number;
@@ -18,7 +18,7 @@ export interface IWorldTransform {
18
18
  /**
19
19
  * Transforms `position` from world space into screen space.
20
20
  *
21
- * @param position - position in world space coordinates.
21
+ * @param position - Position in world space coordinates.
22
22
  */
23
23
  worldToScreen(position: {
24
24
  x: number;
@@ -3,6 +3,7 @@ export declare class KonvaImage implements IMarkupImage {
3
3
  private _ref;
4
4
  private _canvasImage;
5
5
  private _ratio;
6
+ private readonly EPSILON;
6
7
  constructor(params: {
7
8
  position: {
8
9
  x: number;
@@ -11,6 +12,8 @@ export declare class KonvaImage implements IMarkupImage {
11
12
  src: string;
12
13
  width?: number;
13
14
  height?: number;
15
+ maxWidth?: number;
16
+ maxHeight?: number;
14
17
  id?: string;
15
18
  }, ref?: any);
16
19
  getSrc(): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inweb/markup",
3
- "version": "25.8.16",
3
+ "version": "25.8.19",
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.8.16",
30
- "@inweb/viewer-core": "~25.8.16"
29
+ "@inweb/eventemitter2": "~25.8.19",
30
+ "@inweb/viewer-core": "~25.8.19"
31
31
  },
32
32
  "devDependencies": {
33
33
  "konva": "^9.2.0"
@@ -27,7 +27,7 @@ import { IWorldTransform } from "./IWorldTransform";
27
27
  import { IMarkupObject } from "./IMarkupObject";
28
28
 
29
29
  /**
30
- * Markup edit mode. Matches the type of markup object being created or object selecting mode.
30
+ * Defines the markup edit mode. Matches the type of markup object being created.
31
31
  */
32
32
  export type MarkupMode = "SelectMarkup" | "Line" | "Text" | "Rectangle" | "Ellipse" | "Arrow" | "Image" | "Cloud";
33
33
 
@@ -36,33 +36,38 @@ export type MarkupMode = "SelectMarkup" | "Line" | "Text" | "Rectangle" | "Ellip
36
36
  */
37
37
  export interface IMarkup {
38
38
  /**
39
- * Line width of the markup objects. Default is 4.
39
+ * Line width of new markup objects.
40
+ *
41
+ * @default 4
40
42
  */
41
43
  lineWidth: number;
42
44
 
43
45
  /**
44
- * Type of the markup line. Available types: `solid`, `dot`, `dash`. Default is `solid`.
46
+ * Line type of new markup objects. Can be `solid`, `dot` or `dash`.
47
+ *
48
+ * @default `solid`
45
49
  */
46
50
  lineType: string;
47
51
 
48
52
  /**
49
- * Font size of the markup text. Default is 34 px.
53
+ * Font size of new markup text, in pixels.
54
+ *
55
+ * @default 34
50
56
  */
51
57
  fontSize: number;
52
58
 
53
59
  /**
54
- * Initializes the markup instance.
60
+ * Initializes the markup instance. Call {@link dispose | dispose()} to release allocated resources.
55
61
  *
56
- * @param container - Container element used to operate on. This is usually a `canvas` or
57
- * `div` on top of which the markup is drawn. If the `container` is an element of type
58
- * {@link https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement | HTMLCanvasElement},
62
+ * @param container - Container element used to operate on. This is usually a `<canvas>` or
63
+ * `<div>` on top of which the markup is drawn. If the `container` is a `<canvas>` element,
59
64
  * its content will be combined with the markup in the viewpoint snapshot.
60
65
  * @param pointerEvents - List of pointing device events that the markup should redirect to
61
66
  * the `viewer`.
62
67
  * @param viewer - `Viewer` instance that receives pointing device events.
63
68
  * @param worldTransformer - Transformer of screen space into the `viewer` world space and
64
- * vice versa. If a transformer is defined, viewpoint objects will be stored in world
65
- * coordinates, otherwise in screen coordinates.
69
+ * vice versa. If a transformer is defined, markup objects will be stored at the viewpoint
70
+ * in world coordinates, otherwise in screen coordinates.
66
71
  */
67
72
  initialize(
68
73
  container: HTMLElement,
@@ -77,17 +82,17 @@ export interface IMarkup {
77
82
  dispose(): void;
78
83
 
79
84
  /**
80
- * Create markup overlay.
85
+ * Creates the markup overlay.
81
86
  */
82
87
  syncOverlay(): void;
83
88
 
84
89
  /**
85
- * Clear markup overlay.
90
+ * Deletes all markup objects and clears the markup overlay.
86
91
  */
87
92
  clearOverlay(): void;
88
93
 
89
94
  /**
90
- * Set markup color.
95
+ * Sets the color of new markup objects.
91
96
  *
92
97
  * @param r - `Red` part of color.
93
98
  * @param g - `Green` part of color.
@@ -96,14 +101,12 @@ export interface IMarkup {
96
101
  setMarkupColor(r: number, g: number, b: number): void;
97
102
 
98
103
  /**
99
- * Get markup color.
100
- *
101
- * @returns Color with `RGB` values.
104
+ * Returns the color of new markup objects.
102
105
  */
103
106
  getMarkupColor(): { r: number; g: number; b: number };
104
107
 
105
108
  /**
106
- * Colorize all markup entities with the specified color.
109
+ * Colors all markup objects with the specified color.
107
110
  *
108
111
  * @param r - `Red` part of color.
109
112
  * @param g - `Green` part of color.
@@ -112,7 +115,7 @@ export interface IMarkup {
112
115
  colorizeAllMarkup(r: number, g: number, b: number): void;
113
116
 
114
117
  /**
115
- * Colorize all selected markup entities with the specified color.
118
+ * Colors selected markup objects with the specified color.
116
119
  *
117
120
  * @param r - `Red` part of color.
118
121
  * @param g - `Green` part of color.
@@ -121,52 +124,53 @@ export interface IMarkup {
121
124
  colorizeSelectedMarkups(r: number, g: number, b: number): void;
122
125
 
123
126
  /**
124
- * Draw a viewpoint. To get a list of available model viewpoints, use the
127
+ * Sets the markup state to the specified viewpoint.
125
128
  *
126
129
  * @param viewpoint - Viewpoint data.
127
130
  */
128
131
  setViewpoint(viewpoint: IViewpoint): void;
129
132
 
130
133
  /**
131
- * Create a viewpoint.
134
+ * Saves the markup state at the viewpoint.
132
135
  */
133
136
  getViewpoint(): IViewpoint;
134
137
 
135
138
  /**
136
139
  * Enables mouse interactions to select or draw markups.
137
140
  *
138
- * @param mode - Edit mode. Matches the type of markup object being created or object
139
- * selecting mode. To exit edit mode provide this to `false`.
141
+ * @param mode - Edit mode. Matches the type of markup object being created. Specify `false`
142
+ * to exit edit mode.
140
143
  */
141
144
  enableEditMode(mode: MarkupMode | false): this;
142
145
 
143
146
  /**
144
- * Create a Markup object.
147
+ * Creates a markup object.
145
148
  *
146
- * @param type - string identificator of Markup object type.
149
+ * @param type - Markup object type. Can be `Line`, `Text`, `Rectangle`, `Ellipse`, `Arrow`,
150
+ * `Image` or `Cloud`.
147
151
  * @param params - Markup object parameters.
148
152
  */
149
153
  createObject(type: string, params: any): IMarkupObject;
150
154
 
151
155
  /**
152
- * Get Markup objects.
156
+ * Returns the list of all markup objects.
153
157
  */
154
158
  getObjects(): IMarkupObject[];
155
159
 
156
160
  /**
157
- * Get selected Markup objects.
161
+ * Returns the list of selected markup objects.
158
162
  */
159
163
  getSelectedObjects(): IMarkupObject[];
160
164
 
161
165
  /**
162
- * Select Markup objects.
166
+ * Selects specified markup objects.
163
167
  *
164
- * @param objects
168
+ * @param objects - The list of markup objects.
165
169
  */
166
170
  selectObjects(objects: IMarkupObject[]): void;
167
171
 
168
172
  /**
169
- * Clear Markup objects selection.
173
+ * Clears the markup objects selection.
170
174
  */
171
175
  clearSelected(): void;
172
176
  }
@@ -25,7 +25,7 @@ import { IMarkupObject } from "./IMarkupObject";
25
25
  import { IMarkupColorable } from "./IMarkupColorable";
26
26
 
27
27
  /**
28
- * Type of the markup line.
28
+ * Defines the type of the markup line.
29
29
  */
30
30
  export type MarkupLineType = "solid" | "dot" | "dash";
31
31
 
@@ -28,14 +28,14 @@ export interface IWorldTransform {
28
28
  /**
29
29
  * Transforms `position` from screen space into world space.
30
30
  *
31
- * @param position - screen position in pixels.
31
+ * @param position - Screen position in pixels.
32
32
  */
33
33
  screenToWorld(position: { x: number; y: number }): { x: number; y: number; z: number };
34
34
 
35
35
  /**
36
36
  * Transforms `position` from world space into screen space.
37
37
  *
38
- * @param position - position in world space coordinates.
38
+ * @param position - Position in world space coordinates.
39
39
  */
40
40
  worldToScreen(position: { x: number; y: number; z: number }): { x: number; y: number };
41
41
 
@@ -5,6 +5,7 @@ export class KonvaImage implements IMarkupImage {
5
5
  private _ref: Konva.Image;
6
6
  private _canvasImage: HTMLImageElement;
7
7
  private _ratio = 1;
8
+ private readonly EPSILON = 10e-6;
8
9
 
9
10
  constructor(
10
11
  params: {
@@ -12,6 +13,8 @@ export class KonvaImage implements IMarkupImage {
12
13
  src: string;
13
14
  width?: number;
14
15
  height?: number;
16
+ maxWidth?: number;
17
+ maxHeight?: number;
15
18
  id?: string;
16
19
  },
17
20
  ref = null
@@ -21,7 +24,10 @@ export class KonvaImage implements IMarkupImage {
21
24
 
22
25
  this._ref = ref;
23
26
  this._canvasImage = ref.image();
24
- this._ratio = this._ref.height() === 0 || this._ref.width() === 0 ? 1 : this._ref.height() / this._ref.width();
27
+ this._ratio =
28
+ this._ref.height() <= this.EPSILON || this._ref.width() <= this.EPSILON
29
+ ? 1
30
+ : this._ref.height() / this._ref.width();
25
31
  return;
26
32
  }
27
33
 
@@ -40,9 +46,32 @@ export class KonvaImage implements IMarkupImage {
40
46
 
41
47
  this._canvasImage.onload = () => {
42
48
  this._ref.image(this._canvasImage);
43
- if (this._ref.height() === 0) this._ref.height(this._canvasImage.height);
44
- if (this._ref.width() === 0) this._ref.width(this._canvasImage.width);
45
- this._ratio = this._ref.height() === 0 || this._ref.width() === 0 ? 1 : this._ref.height() / this._ref.width();
49
+ if (this._ref.height() <= this.EPSILON) this._ref.height(this._canvasImage.height);
50
+ if (this._ref.width() <= this.EPSILON) this._ref.width(this._canvasImage.width);
51
+
52
+ this._ratio =
53
+ this._ref.height() <= this.EPSILON || this._ref.width() <= this.EPSILON
54
+ ? 1
55
+ : this._ref.height() / this._ref.width();
56
+
57
+ // need to rescale only if input width and height are 0 - we do not loading Viewpoint with existing params
58
+ if (
59
+ (params.width <= this.EPSILON || params.height <= this.EPSILON) &&
60
+ (params.maxWidth >= this.EPSILON || params.maxWidth >= this.EPSILON)
61
+ ) {
62
+ const heightOutOfCanvas = params.maxHeight - this._canvasImage.height;
63
+ const widthOutOfCanvas = params.maxWidth - this._canvasImage.width;
64
+
65
+ if (heightOutOfCanvas <= this.EPSILON || widthOutOfCanvas <= this.EPSILON) {
66
+ if (widthOutOfCanvas <= this.EPSILON && widthOutOfCanvas < heightOutOfCanvas / this._ratio) {
67
+ this._ref.height(params.maxWidth * this._ratio);
68
+ this._ref.width(params.maxWidth);
69
+ } else {
70
+ this._ref.width(params.maxHeight / this._ratio);
71
+ this._ref.height(params.maxHeight);
72
+ }
73
+ }
74
+ }
46
75
  };
47
76
 
48
77
  this._canvasImage.src = params.src;
@@ -1103,6 +1103,8 @@ export class KonvaMarkup implements IMarkup {
1103
1103
  src,
1104
1104
  width,
1105
1105
  height,
1106
+ maxWidth: this._konvaStage.width() - position.x,
1107
+ maxHeight: this._konvaStage.height() - position.y,
1106
1108
  id,
1107
1109
  });
1108
1110