@inweb/markup 25.7.6 → 25.7.8
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.
- package/dist/markup.js +25 -23
- package/dist/markup.js.map +1 -1
- package/dist/markup.min.js +1 -1
- package/dist/markup.module.js +23 -23
- package/dist/markup.module.js.map +1 -1
- package/lib/markup/IMarkup.d.ts +15 -14
- package/lib/markup/Konva/KonvaMarkup.d.ts +5 -4
- package/package.json +3 -3
- package/src/markup/IMarkup.ts +14 -13
- package/src/markup/Konva/KonvaMarkup.ts +33 -27
package/lib/markup/IMarkup.d.ts
CHANGED
|
@@ -23,21 +23,22 @@ export interface IMarkup {
|
|
|
23
23
|
*/
|
|
24
24
|
fontSize: number;
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
26
|
+
* Initializes the markup instance.
|
|
27
27
|
*
|
|
28
|
-
* @param canvas
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* @param
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
|
15
|
-
private
|
|
14
|
+
private _container;
|
|
15
|
+
private _pointerEvents;
|
|
16
16
|
private _markupIsActive;
|
|
17
17
|
private _markupMode;
|
|
18
18
|
private _markupColor;
|
|
@@ -25,15 +25,16 @@ export declare class KonvaMarkup implements IMarkup {
|
|
|
25
25
|
private _imageInputRef;
|
|
26
26
|
private _imageInputPos;
|
|
27
27
|
private _markupContainer;
|
|
28
|
+
private _resizeObserver;
|
|
28
29
|
private _zIndex;
|
|
29
30
|
private readonly _markupContainerName;
|
|
30
31
|
lineWidth: number;
|
|
31
32
|
lineType: MarkupLineType;
|
|
32
33
|
fontSize: number;
|
|
33
|
-
initialize(
|
|
34
|
+
initialize(container: HTMLElement, pointerEvents?: string[], viewer?: IEventEmitter, worldTransformer?: IWorldTransform): void;
|
|
34
35
|
dispose(): void;
|
|
35
36
|
changeActiveDragger: (event: ChangeActiveDraggerEvent) => void;
|
|
36
|
-
|
|
37
|
+
resizeContainer: (entries: ResizeObserverEntry[]) => void;
|
|
37
38
|
pan: (event: PanEvent) => void;
|
|
38
39
|
redirectToViewer: (event: any) => void;
|
|
39
40
|
syncOverlay(): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inweb/markup",
|
|
3
|
-
"version": "25.7.
|
|
3
|
+
"version": "25.7.8",
|
|
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.
|
|
30
|
-
"@inweb/viewer-core": "~25.7.
|
|
29
|
+
"@inweb/eventemitter2": "~25.7.8",
|
|
30
|
+
"@inweb/viewer-core": "~25.7.8"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"canvas": "^2.11.2",
|
package/src/markup/IMarkup.ts
CHANGED
|
@@ -51,27 +51,28 @@ export interface IMarkup {
|
|
|
51
51
|
fontSize: number;
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
|
-
*
|
|
54
|
+
* Initializes the markup instance.
|
|
55
55
|
*
|
|
56
|
-
* @param canvas
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* @param
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
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
|
-
|
|
67
|
-
|
|
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
|
|
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
|
|
91
|
-
private
|
|
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);
|
|
@@ -102,6 +102,7 @@ export class KonvaMarkup implements IMarkup {
|
|
|
102
102
|
private _imageInputRef: HTMLInputElement;
|
|
103
103
|
private _imageInputPos: Konva.Vector2d;
|
|
104
104
|
private _markupContainer: HTMLDivElement;
|
|
105
|
+
private _resizeObserver: ResizeObserver;
|
|
105
106
|
private _zIndex = 1;
|
|
106
107
|
|
|
107
108
|
private readonly _markupContainerName = "markupContainer";
|
|
@@ -111,8 +112,8 @@ export class KonvaMarkup implements IMarkup {
|
|
|
111
112
|
public fontSize = 34;
|
|
112
113
|
|
|
113
114
|
initialize(
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
container: HTMLElement,
|
|
116
|
+
pointerEvents?: string[],
|
|
116
117
|
viewer?: IEventEmitter,
|
|
117
118
|
worldTransformer?: IWorldTransform
|
|
118
119
|
): void {
|
|
@@ -123,8 +124,8 @@ export class KonvaMarkup implements IMarkup {
|
|
|
123
124
|
|
|
124
125
|
this._viewer = viewer;
|
|
125
126
|
this._worldTransformer = worldTransformer;
|
|
126
|
-
this.
|
|
127
|
-
this.
|
|
127
|
+
this._container = container;
|
|
128
|
+
this._pointerEvents = pointerEvents ?? [];
|
|
128
129
|
|
|
129
130
|
this._markupContainer = document.createElement("div");
|
|
130
131
|
this._markupContainer.id = this._markupContainerName;
|
|
@@ -134,18 +135,18 @@ export class KonvaMarkup implements IMarkup {
|
|
|
134
135
|
// to eliminate grey box during delete elements
|
|
135
136
|
this._markupContainer.style.outline = "0px";
|
|
136
137
|
|
|
137
|
-
const parentDiv = this.
|
|
138
|
+
const parentDiv = this._container.parentElement;
|
|
138
139
|
parentDiv.appendChild(this._markupContainer);
|
|
139
140
|
|
|
141
|
+
this._resizeObserver = new ResizeObserver(this.resizeContainer);
|
|
142
|
+
this._resizeObserver.observe(parentDiv);
|
|
143
|
+
|
|
140
144
|
this._markupColor.setColor(255, 0, 0);
|
|
141
145
|
|
|
142
146
|
this.initializeKonva();
|
|
143
|
-
this.resize();
|
|
144
|
-
|
|
145
|
-
this._canvasEvents.forEach((x) => this._markupContainer.addEventListener(x, this.redirectToViewer));
|
|
146
147
|
|
|
147
148
|
if (this._viewer) {
|
|
148
|
-
this.
|
|
149
|
+
this._pointerEvents.forEach((x) => this._markupContainer.addEventListener(x, this.redirectToViewer));
|
|
149
150
|
this._viewer.addEventListener("changeactivedragger", this.changeActiveDragger);
|
|
150
151
|
this._viewer.addEventListener("pan", this.pan);
|
|
151
152
|
}
|
|
@@ -159,17 +160,19 @@ export class KonvaMarkup implements IMarkup {
|
|
|
159
160
|
if (this._viewer) {
|
|
160
161
|
this._viewer.removeEventListener("pan", this.pan);
|
|
161
162
|
this._viewer.removeEventListener("changeactivedragger", this.changeActiveDragger);
|
|
162
|
-
this._viewer.removeEventListener("resize", this.resize);
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
-
this.
|
|
165
|
+
this._pointerEvents.forEach((x) => this._markupContainer.removeEventListener(x, this.redirectToViewer));
|
|
166
166
|
|
|
167
167
|
this.destroyKonva();
|
|
168
168
|
|
|
169
|
+
this._resizeObserver.disconnect();
|
|
170
|
+
this._resizeObserver = undefined;
|
|
171
|
+
|
|
169
172
|
this._markupContainer.remove();
|
|
170
173
|
this._markupContainer = undefined;
|
|
171
174
|
|
|
172
|
-
this.
|
|
175
|
+
this._container = undefined;
|
|
173
176
|
this._viewer = undefined;
|
|
174
177
|
this._worldTransformer = undefined;
|
|
175
178
|
|
|
@@ -180,7 +183,7 @@ export class KonvaMarkup implements IMarkup {
|
|
|
180
183
|
changeActiveDragger = (event: ChangeActiveDraggerEvent) => {
|
|
181
184
|
const draggerName = event.data;
|
|
182
185
|
|
|
183
|
-
this._markupContainer.className = this.
|
|
186
|
+
this._markupContainer.className = this._container.className
|
|
184
187
|
.split(" ")
|
|
185
188
|
.filter((x) => !x.startsWith("oda-cursor-"))
|
|
186
189
|
.filter((x) => x)
|
|
@@ -200,9 +203,13 @@ export class KonvaMarkup implements IMarkup {
|
|
|
200
203
|
}
|
|
201
204
|
};
|
|
202
205
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
+
resizeContainer = (entries: ResizeObserverEntry[]) => {
|
|
207
|
+
const { width, height } = entries[0].contentRect;
|
|
208
|
+
|
|
209
|
+
if (!width || !height) return; // <- invisible container, or container with parent removed
|
|
210
|
+
|
|
211
|
+
this._konvaStage?.width(width);
|
|
212
|
+
this._konvaStage?.height(height);
|
|
206
213
|
};
|
|
207
214
|
|
|
208
215
|
pan = (event: PanEvent) => {
|
|
@@ -482,8 +489,8 @@ export class KonvaMarkup implements IMarkup {
|
|
|
482
489
|
// first we need Konva core things: stage and layer
|
|
483
490
|
this._konvaStage = new Konva.Stage({
|
|
484
491
|
container: this._markupContainerName,
|
|
485
|
-
width: this.
|
|
486
|
-
height: this.
|
|
492
|
+
width: this._container.clientWidth,
|
|
493
|
+
height: this._container.clientHeight,
|
|
487
494
|
});
|
|
488
495
|
const stage = this._konvaStage;
|
|
489
496
|
const layer = new Konva.Layer({ pixelRation: window.devicePixelRatio });
|
|
@@ -920,17 +927,16 @@ export class KonvaMarkup implements IMarkup {
|
|
|
920
927
|
}
|
|
921
928
|
|
|
922
929
|
private combineMarkupWithDrawing() {
|
|
923
|
-
|
|
924
|
-
if (trNodes.length > 0) {
|
|
925
|
-
this._konvaTransformer.nodes([]);
|
|
926
|
-
}
|
|
930
|
+
this.clearSelected();
|
|
927
931
|
|
|
928
932
|
const tempCanvas = document.createElement("canvas");
|
|
929
|
-
tempCanvas.
|
|
930
|
-
tempCanvas.
|
|
933
|
+
tempCanvas.width = this._konvaStage.width();
|
|
934
|
+
tempCanvas.height = this._konvaStage.height();
|
|
935
|
+
|
|
931
936
|
const ctx = tempCanvas.getContext("2d");
|
|
932
|
-
ctx.drawImage(this.
|
|
937
|
+
if (this._container instanceof HTMLCanvasElement) ctx.drawImage(this._container, 0, 0);
|
|
933
938
|
ctx.drawImage(this._konvaStage.toCanvas({ pixelRatio: window.devicePixelRatio }), 0, 0);
|
|
939
|
+
|
|
934
940
|
return tempCanvas.toDataURL("image/jpeg", 0.25);
|
|
935
941
|
}
|
|
936
942
|
|