@inweb/markup 25.7.6 → 25.7.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.
@@ -23,21 +23,22 @@ export interface IMarkup {
23
23
  */
24
24
  fontSize: number;
25
25
  /**
26
- * Start method to init Markup support for the Viewer instance.
26
+ * Initializes the markup instance.
27
27
  *
28
- * @param canvas -
29
- * {@link https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement | HTMLCanvasElement}
30
- * used to operate on.
31
- * @param canvasEvents - List of `canvas` events that the markup should redirect to the `viewer`.
32
- * @param viewer - `Viewer` instance viewer that receives `canvas` events.
33
- * @param worldTransformer - Transformer of screen space into world space and vice versa. If
34
- * a transformer is defined, viewpoint objects will be stored in world coordinates,
35
- * otherwise in screen coordinates.
36
- */
37
- initialize(canvas: HTMLCanvasElement, canvasEvents: string[], viewer?: IEventEmitter, worldTransformer?: IWorldTransform): void;
38
- /**
39
- * Releases all resources allocated by this `Markup` instance. Call this method before
40
- * release the `Markup` instance.
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},
31
+ * its content will be combined with the markup in the viewpoint snapshot.
32
+ * @param pointerEvents - List of pointing device events that the markup should redirect to
33
+ * the `viewer`.
34
+ * @param viewer - `Viewer` instance that receives pointing device events.
35
+ * @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.
38
+ */
39
+ initialize(container: HTMLElement, pointerEvents?: string[], viewer?: IEventEmitter, worldTransformer?: IWorldTransform): void;
40
+ /**
41
+ * Releases all resources allocated by this markup instance.
41
42
  */
42
43
  dispose(): void;
43
44
  /**
@@ -11,8 +11,8 @@ export declare class KonvaMarkup implements IMarkup {
11
11
  private _isInitialized;
12
12
  private _viewer;
13
13
  private _worldTransformer;
14
- private _canvasOriginal;
15
- private _canvasEvents;
14
+ private _container;
15
+ private _pointerEvents;
16
16
  private _markupIsActive;
17
17
  private _markupMode;
18
18
  private _markupColor;
@@ -30,7 +30,7 @@ export declare class KonvaMarkup implements IMarkup {
30
30
  lineWidth: number;
31
31
  lineType: MarkupLineType;
32
32
  fontSize: number;
33
- initialize(canvas: HTMLCanvasElement, canvasEvents: string[], viewer?: IEventEmitter, worldTransformer?: IWorldTransform): void;
33
+ initialize(container: HTMLElement, pointerEvents?: string[], viewer?: IEventEmitter, worldTransformer?: IWorldTransform): void;
34
34
  dispose(): void;
35
35
  changeActiveDragger: (event: ChangeActiveDraggerEvent) => void;
36
36
  resize: () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inweb/markup",
3
- "version": "25.7.6",
3
+ "version": "25.7.7",
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.6",
30
- "@inweb/viewer-core": "~25.7.6"
29
+ "@inweb/eventemitter2": "~25.7.7",
30
+ "@inweb/viewer-core": "~25.7.7"
31
31
  },
32
32
  "devDependencies": {
33
33
  "canvas": "^2.11.2",
@@ -51,27 +51,28 @@ export interface IMarkup {
51
51
  fontSize: number;
52
52
 
53
53
  /**
54
- * Start method to init Markup support for the Viewer instance.
54
+ * Initializes the markup instance.
55
55
  *
56
- * @param canvas -
57
- * {@link https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement | HTMLCanvasElement}
58
- * used to operate on.
59
- * @param canvasEvents - List of `canvas` events that the markup should redirect to the `viewer`.
60
- * @param viewer - `Viewer` instance viewer that receives `canvas` events.
61
- * @param worldTransformer - Transformer of screen space into world space and vice versa. If
62
- * a transformer is defined, viewpoint objects will be stored in world coordinates,
63
- * otherwise in screen coordinates.
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},
59
+ * its content will be combined with the markup in the viewpoint snapshot.
60
+ * @param pointerEvents - List of pointing device events that the markup should redirect to
61
+ * the `viewer`.
62
+ * @param viewer - `Viewer` instance that receives pointing device events.
63
+ * @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.
64
66
  */
65
67
  initialize(
66
- canvas: HTMLCanvasElement,
67
- canvasEvents: string[],
68
+ container: HTMLElement,
69
+ pointerEvents?: string[],
68
70
  viewer?: IEventEmitter,
69
71
  worldTransformer?: IWorldTransform
70
72
  ): void;
71
73
 
72
74
  /**
73
- * Releases all resources allocated by this `Markup` instance. Call this method before
74
- * release the `Markup` instance.
75
+ * Releases all resources allocated by this markup instance.
75
76
  */
76
77
  dispose(): void;
77
78
 
@@ -87,8 +87,8 @@ export class KonvaMarkup implements IMarkup {
87
87
  private _isInitialized = false;
88
88
  private _viewer: IEventEmitter;
89
89
  private _worldTransformer: IWorldTransform;
90
- private _canvasOriginal: HTMLCanvasElement;
91
- private _canvasEvents: string[];
90
+ private _container: HTMLElement;
91
+ private _pointerEvents: string[];
92
92
  private _markupIsActive = false;
93
93
  private _markupMode: string;
94
94
  private _markupColor = new MarkupColor(255, 0, 0);
@@ -111,8 +111,8 @@ export class KonvaMarkup implements IMarkup {
111
111
  public fontSize = 34;
112
112
 
113
113
  initialize(
114
- canvas: HTMLCanvasElement,
115
- canvasEvents: string[],
114
+ container: HTMLElement,
115
+ pointerEvents?: string[],
116
116
  viewer?: IEventEmitter,
117
117
  worldTransformer?: IWorldTransform
118
118
  ): void {
@@ -123,8 +123,8 @@ export class KonvaMarkup implements IMarkup {
123
123
 
124
124
  this._viewer = viewer;
125
125
  this._worldTransformer = worldTransformer;
126
- this._canvasOriginal = canvas;
127
- this._canvasEvents = canvasEvents ?? [];
126
+ this._container = container;
127
+ this._pointerEvents = pointerEvents ?? [];
128
128
 
129
129
  this._markupContainer = document.createElement("div");
130
130
  this._markupContainer.id = this._markupContainerName;
@@ -134,7 +134,7 @@ export class KonvaMarkup implements IMarkup {
134
134
  // to eliminate grey box during delete elements
135
135
  this._markupContainer.style.outline = "0px";
136
136
 
137
- const parentDiv = this._canvasOriginal.parentElement;
137
+ const parentDiv = this._container.parentElement;
138
138
  parentDiv.appendChild(this._markupContainer);
139
139
 
140
140
  this._markupColor.setColor(255, 0, 0);
@@ -142,9 +142,9 @@ export class KonvaMarkup implements IMarkup {
142
142
  this.initializeKonva();
143
143
  this.resize();
144
144
 
145
- this._canvasEvents.forEach((x) => this._markupContainer.addEventListener(x, this.redirectToViewer));
146
-
147
145
  if (this._viewer) {
146
+ this._pointerEvents.forEach((x) => this._markupContainer.addEventListener(x, this.redirectToViewer));
147
+
148
148
  this._viewer.addEventListener("resize", this.resize);
149
149
  this._viewer.addEventListener("changeactivedragger", this.changeActiveDragger);
150
150
  this._viewer.addEventListener("pan", this.pan);
@@ -162,14 +162,14 @@ export class KonvaMarkup implements IMarkup {
162
162
  this._viewer.removeEventListener("resize", this.resize);
163
163
  }
164
164
 
165
- this._canvasEvents.forEach((x) => this._markupContainer.removeEventListener(x, this.redirectToViewer));
165
+ this._pointerEvents.forEach((x) => this._markupContainer.removeEventListener(x, this.redirectToViewer));
166
166
 
167
167
  this.destroyKonva();
168
168
 
169
169
  this._markupContainer.remove();
170
170
  this._markupContainer = undefined;
171
171
 
172
- this._canvasOriginal = undefined;
172
+ this._container = undefined;
173
173
  this._viewer = undefined;
174
174
  this._worldTransformer = undefined;
175
175
 
@@ -180,7 +180,7 @@ export class KonvaMarkup implements IMarkup {
180
180
  changeActiveDragger = (event: ChangeActiveDraggerEvent) => {
181
181
  const draggerName = event.data;
182
182
 
183
- this._markupContainer.className = this._canvasOriginal.className
183
+ this._markupContainer.className = this._container.className
184
184
  .split(" ")
185
185
  .filter((x) => !x.startsWith("oda-cursor-"))
186
186
  .filter((x) => x)
@@ -201,8 +201,8 @@ export class KonvaMarkup implements IMarkup {
201
201
  };
202
202
 
203
203
  resize = () => {
204
- this._konvaStage?.width(this._canvasOriginal.clientWidth);
205
- this._konvaStage?.height(this._canvasOriginal.clientHeight);
204
+ this._konvaStage?.width(this._container.clientWidth);
205
+ this._konvaStage?.height(this._container.clientHeight);
206
206
  };
207
207
 
208
208
  pan = (event: PanEvent) => {
@@ -482,8 +482,8 @@ export class KonvaMarkup implements IMarkup {
482
482
  // first we need Konva core things: stage and layer
483
483
  this._konvaStage = new Konva.Stage({
484
484
  container: this._markupContainerName,
485
- width: this._canvasOriginal.clientWidth,
486
- height: this._canvasOriginal.clientHeight,
485
+ width: this._container.clientWidth,
486
+ height: this._container.clientHeight,
487
487
  });
488
488
  const stage = this._konvaStage;
489
489
  const layer = new Konva.Layer({ pixelRation: window.devicePixelRatio });
@@ -920,17 +920,16 @@ export class KonvaMarkup implements IMarkup {
920
920
  }
921
921
 
922
922
  private combineMarkupWithDrawing() {
923
- const trNodes = this._konvaTransformer.nodes();
924
- if (trNodes.length > 0) {
925
- this._konvaTransformer.nodes([]);
926
- }
923
+ this.clearSelected();
927
924
 
928
925
  const tempCanvas = document.createElement("canvas");
929
- tempCanvas.height = this._canvasOriginal.height;
930
- tempCanvas.width = this._canvasOriginal.width;
926
+ tempCanvas.width = this._konvaStage.width();
927
+ tempCanvas.height = this._konvaStage.height();
928
+
931
929
  const ctx = tempCanvas.getContext("2d");
932
- ctx.drawImage(this._canvasOriginal, 0, 0);
930
+ if (this._container instanceof HTMLCanvasElement) ctx.drawImage(this._container, 0, 0);
933
931
  ctx.drawImage(this._konvaStage.toCanvas({ pixelRatio: window.devicePixelRatio }), 0, 0);
932
+
934
933
  return tempCanvas.toDataURL("image/jpeg", 0.25);
935
934
  }
936
935