@inweb/markup 27.1.2 → 27.1.4

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.
@@ -33,7 +33,7 @@ export interface IMarkup {
33
33
  *
34
34
  * @param container - Container element used to operate on. This is usually a `<canvas>` or `<div>` on
35
35
  * top of which the markup is drawn. If the `container` is a `<canvas>` element, its content will be
36
- * combined with the markup in the viewpoint snapshot.
36
+ * combined with the markup in the snapshot.
37
37
  * @param containerEvents - Deprecated since `26.7`, can be null. List of container events, such as
38
38
  * mouse events or
39
39
  * {@link https://developer.mozilla.org/docs/Web/API/Pointer_events#event_types_and_global_event_handlers | pointer events}
@@ -99,6 +99,20 @@ export interface IMarkup {
99
99
  * Saves the markup state at the viewpoint.
100
100
  */
101
101
  getViewpoint(viewpoint: IViewpoint): IViewpoint;
102
+ /**
103
+ * Creates a snapshot image combining the container canvas with markup overlay.
104
+ *
105
+ * @param type - The MIME type of the image format. Can be one of:
106
+ *
107
+ * - `image/png` - PNG format with lossless compression (recommended for quality)
108
+ * - `image/jpeg` - JPEG format with lossy compression (smaller file size)
109
+ * - `image/webp` - WebP format (modern browsers only)
110
+ *
111
+ * @param quality - A number between 0 and 1 indicating the image quality for lossy formats.
112
+ * @returns A {@link https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/Data_URIs | Data URL}
113
+ * string containing the snapshot image.
114
+ */
115
+ getSnapshot(type?: string, quality?: number): string;
102
116
  /**
103
117
  * Enables mouse interactions to select or draw markups.
104
118
  *
@@ -50,6 +50,7 @@ export declare class KonvaMarkup implements IMarkup {
50
50
  colorizeSelectedMarkups(r: number, g: number, b: number): void;
51
51
  setViewpoint(viewpoint: IViewpoint): void;
52
52
  getViewpoint(viewpoint: IViewpoint): IViewpoint;
53
+ getSnapshot(type?: string, quality?: number): string;
53
54
  enableEditMode(mode: MarkupMode | false): this;
54
55
  createObject(type: string, params: any): IMarkupObject;
55
56
  getObjects(): IMarkupObject[];
@@ -70,7 +71,6 @@ export declare class KonvaMarkup implements IMarkup {
70
71
  private getMarkupArrows;
71
72
  private getMarkupImages;
72
73
  private getMarkupClouds;
73
- private combineMarkupWithDrawing;
74
74
  private addLine;
75
75
  private createTextInput;
76
76
  private removeTextInput;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inweb/markup",
3
- "version": "27.1.2",
3
+ "version": "27.1.4",
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": "~27.1.2",
30
- "@inweb/viewer-core": "~27.1.2"
29
+ "@inweb/eventemitter2": "~27.1.4",
30
+ "@inweb/viewer-core": "~27.1.4"
31
31
  },
32
32
  "devDependencies": {
33
33
  "konva": "^10.0.2"
@@ -61,7 +61,7 @@ export interface IMarkup {
61
61
  *
62
62
  * @param container - Container element used to operate on. This is usually a `<canvas>` or `<div>` on
63
63
  * top of which the markup is drawn. If the `container` is a `<canvas>` element, its content will be
64
- * combined with the markup in the viewpoint snapshot.
64
+ * combined with the markup in the snapshot.
65
65
  * @param containerEvents - Deprecated since `26.7`, can be null. List of container events, such as
66
66
  * mouse events or
67
67
  * {@link https://developer.mozilla.org/docs/Web/API/Pointer_events#event_types_and_global_event_handlers | pointer events}
@@ -138,6 +138,21 @@ export interface IMarkup {
138
138
  */
139
139
  getViewpoint(viewpoint: IViewpoint): IViewpoint;
140
140
 
141
+ /**
142
+ * Creates a snapshot image combining the container canvas with markup overlay.
143
+ *
144
+ * @param type - The MIME type of the image format. Can be one of:
145
+ *
146
+ * - `image/png` - PNG format with lossless compression (recommended for quality)
147
+ * - `image/jpeg` - JPEG format with lossy compression (smaller file size)
148
+ * - `image/webp` - WebP format (modern browsers only)
149
+ *
150
+ * @param quality - A number between 0 and 1 indicating the image quality for lossy formats.
151
+ * @returns A {@link https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/Data_URIs | Data URL}
152
+ * string containing the snapshot image.
153
+ */
154
+ getSnapshot(type?: string, quality?: number): string;
155
+
141
156
  /**
142
157
  * Enables mouse interactions to select or draw markups.
143
158
  *
@@ -323,12 +323,27 @@ export class KonvaMarkup implements IMarkup {
323
323
  viewpoint.images = this.getMarkupImages();
324
324
  viewpoint.rectangles = this.getMarkupRectangles();
325
325
 
326
- viewpoint.snapshot = { data: this.combineMarkupWithDrawing() };
327
326
  viewpoint.custom_fields.markup_color = this.getMarkupColor();
328
327
 
329
328
  return viewpoint;
330
329
  }
331
330
 
331
+ getSnapshot(type = "image/jpeg", quality = 0.25): string {
332
+ this.clearSelected();
333
+
334
+ const tempCanvas = document.createElement("canvas");
335
+ if (this._konvaStage) {
336
+ tempCanvas.width = this._konvaStage.width();
337
+ tempCanvas.height = this._konvaStage.height();
338
+
339
+ const ctx = tempCanvas.getContext("2d");
340
+ if (this._container instanceof HTMLCanvasElement) ctx.drawImage(this._container, 0, 0);
341
+ ctx.drawImage(this._konvaStage.toCanvas({ pixelRatio: window.devicePixelRatio }), 0, 0);
342
+ }
343
+
344
+ return tempCanvas.toDataURL(type, quality);
345
+ }
346
+
332
347
  enableEditMode(mode: MarkupMode | false): this {
333
348
  if (!mode || !MarkupMode2Konva[mode]) {
334
349
  this.clearSelected();
@@ -863,22 +878,6 @@ export class KonvaMarkup implements IMarkup {
863
878
  return clouds;
864
879
  }
865
880
 
866
- private combineMarkupWithDrawing() {
867
- this.clearSelected();
868
-
869
- const tempCanvas = document.createElement("canvas");
870
- if (this._konvaStage) {
871
- tempCanvas.width = this._konvaStage.width();
872
- tempCanvas.height = this._konvaStage.height();
873
-
874
- const ctx = tempCanvas.getContext("2d");
875
- if (this._container instanceof HTMLCanvasElement) ctx.drawImage(this._container, 0, 0);
876
- ctx.drawImage(this._konvaStage.toCanvas({ pixelRatio: window.devicePixelRatio }), 0, 0);
877
- }
878
-
879
- return tempCanvas.toDataURL("image/jpeg", 0.25);
880
- }
881
-
882
881
  private addLine(
883
882
  linePoints: number[],
884
883
  color?: string,