@inweb/markup 25.7.8 → 25.7.10

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.
@@ -93,6 +93,13 @@ export interface IMarkup {
93
93
  * Create a viewpoint.
94
94
  */
95
95
  getViewpoint(): IViewpoint;
96
+ /**
97
+ * Enables mouse interactions to select or draw markups.
98
+ *
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`.
101
+ */
102
+ enableEditMode(mode: MarkupMode | false): this;
96
103
  /**
97
104
  * Create a Markup object.
98
105
  *
@@ -1,6 +1,6 @@
1
1
  import { IEventEmitter } from "@inweb/eventemitter2";
2
2
  import { ChangeActiveDraggerEvent, IViewpoint, PanEvent } from "@inweb/viewer-core";
3
- import { IMarkup } from "../IMarkup";
3
+ import { IMarkup, MarkupMode } from "../IMarkup";
4
4
  import { IWorldTransform } from "../IWorldTransform";
5
5
  import { IMarkupObject } from "../IMarkupObject";
6
6
  import { MarkupLineType } from "../IMarkupLine";
@@ -49,6 +49,7 @@ export declare class KonvaMarkup implements IMarkup {
49
49
  colorizeSelectedMarkups(r: number, g: number, b: number): void;
50
50
  setViewpoint(viewpoint: IViewpoint): void;
51
51
  getViewpoint(): IViewpoint;
52
+ enableEditMode(mode: MarkupMode | false): this;
52
53
  createObject(type: string, params: any): IMarkupObject;
53
54
  getObjects(): IMarkupObject[];
54
55
  getSelectedObjects(): IMarkupObject[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inweb/markup",
3
- "version": "25.7.8",
3
+ "version": "25.7.10",
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.8",
30
- "@inweb/viewer-core": "~25.7.8"
29
+ "@inweb/eventemitter2": "~25.7.10",
30
+ "@inweb/viewer-core": "~25.7.10"
31
31
  },
32
32
  "devDependencies": {
33
33
  "canvas": "^2.11.2",
@@ -132,6 +132,14 @@ export interface IMarkup {
132
132
  */
133
133
  getViewpoint(): IViewpoint;
134
134
 
135
+ /**
136
+ * Enables mouse interactions to select or draw markups.
137
+ *
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`.
140
+ */
141
+ enableEditMode(mode: MarkupMode | false): this;
142
+
135
143
  /**
136
144
  * Create a Markup object.
137
145
  *
@@ -25,11 +25,12 @@ import Konva from "konva";
25
25
  import { IEventEmitter } from "@inweb/eventemitter2";
26
26
  import { ChangeActiveDraggerEvent, IViewpoint, PanEvent } from "@inweb/viewer-core";
27
27
 
28
- import { IMarkup } from "../IMarkup";
28
+ import { IMarkup, MarkupMode } from "../IMarkup";
29
29
  import { IWorldTransform } from "../IWorldTransform";
30
- import { MarkupColor } from "./MarkupColor";
31
30
  import { IMarkupObject } from "../IMarkupObject";
32
31
  import { IMarkupColorable } from "../IMarkupColorable";
32
+ import { MarkupLineType } from "../IMarkupLine";
33
+ import { MarkupColor } from "./MarkupColor";
33
34
  import { KonvaLine } from "./KonvaLine";
34
35
  import { KonvaText } from "./KonvaText";
35
36
  import { KonvaRectangle } from "./KonvaRectangle";
@@ -37,13 +38,6 @@ import { KonvaEllipse } from "./KonvaEllipse";
37
38
  import { KonvaArrow } from "./KonvaArrow";
38
39
  import { KonvaImage } from "./KonvaImage";
39
40
  import { KonvaCloud } from "./KonvaCloud";
40
- import { IMarkupLine, MarkupLineType } from "../IMarkupLine";
41
- import { IMarkupArrow } from "../IMarkupArrow";
42
- import { IMarkupEllipse } from "../IMarkupEllipse";
43
- import { IMarkupRectangle } from "../IMarkupRectangle";
44
- import { IMarkupCloud } from "../IMarkupCloud";
45
- import { IMarkupImage } from "../IMarkupImage";
46
- import { IMarkupText } from "../IMarkupText";
47
41
 
48
42
  const MarkupMode2Konva = {
49
43
  SelectMarkup: {
@@ -90,7 +84,7 @@ export class KonvaMarkup implements IMarkup {
90
84
  private _container: HTMLElement;
91
85
  private _pointerEvents: string[];
92
86
  private _markupIsActive = false;
93
- private _markupMode: string;
87
+ private _markupMode: MarkupMode;
94
88
  private _markupColor = new MarkupColor(255, 0, 0);
95
89
  private _konvaStage: Konva.Stage;
96
90
  private _konvaLayer: Konva.Layer;
@@ -193,14 +187,7 @@ export class KonvaMarkup implements IMarkup {
193
187
  this.removeTextInput();
194
188
  this.removeImageInput();
195
189
 
196
- const konvaShape = MarkupMode2Konva[draggerName];
197
- if (konvaShape) {
198
- this._markupMode = draggerName;
199
- this._markupIsActive = true;
200
- } else {
201
- this._markupIsActive = false;
202
- this._konvaTransformer.nodes([]);
203
- }
190
+ this.enableEditMode(draggerName as MarkupMode);
204
191
  };
205
192
 
206
193
  resizeContainer = (entries: ResizeObserverEntry[]) => {
@@ -296,6 +283,17 @@ export class KonvaMarkup implements IMarkup {
296
283
  return viewpoint;
297
284
  }
298
285
 
286
+ enableEditMode(mode: MarkupMode | false): this {
287
+ if (!mode || !MarkupMode2Konva[mode]) {
288
+ this.clearSelected();
289
+ this._markupIsActive = false;
290
+ } else {
291
+ this._markupMode = mode;
292
+ this._markupIsActive = true;
293
+ }
294
+ return this;
295
+ }
296
+
299
297
  createObject(type: string, params: any): IMarkupObject {
300
298
  let object = null;
301
299
  let zIndex = this._zIndex;
@@ -946,8 +944,9 @@ export class KonvaMarkup implements IMarkup {
946
944
  type?: MarkupLineType,
947
945
  width?: number,
948
946
  id?: string
949
- ): IMarkupLine | void {
947
+ ): KonvaLine | void {
950
948
  if (!linePoints || linePoints.length === 0) return;
949
+
951
950
  const points: { x: number; y: number }[] = [];
952
951
  for (let i = 0; i < linePoints.length; i += 2) {
953
952
  points.push({ x: linePoints[i], y: linePoints[i + 1] });
@@ -1058,7 +1057,7 @@ export class KonvaMarkup implements IMarkup {
1058
1057
  textSize?: number,
1059
1058
  fontSize?: number,
1060
1059
  id?: string
1061
- ): IMarkupText | void {
1060
+ ): KonvaText | void {
1062
1061
  const trNodes = this._konvaTransformer.nodes();
1063
1062
  if (trNodes.length > 0) {
1064
1063
  // in case of edit - remove old Konva.Text object
@@ -1099,7 +1098,7 @@ export class KonvaMarkup implements IMarkup {
1099
1098
  lineWidth?: number,
1100
1099
  color?: string,
1101
1100
  id?: string
1102
- ): IMarkupRectangle | void {
1101
+ ): KonvaRectangle | void {
1103
1102
  if (!position) return;
1104
1103
 
1105
1104
  const konvaRectangle = new KonvaRectangle({
@@ -1122,7 +1121,7 @@ export class KonvaMarkup implements IMarkup {
1122
1121
  lineWidth?: number,
1123
1122
  color?: string,
1124
1123
  id?: string
1125
- ): IMarkupEllipse | void {
1124
+ ): KonvaEllipse | void {
1126
1125
  if (!position) return;
1127
1126
 
1128
1127
  const konvaEllipse = new KonvaEllipse({
@@ -1143,7 +1142,7 @@ export class KonvaMarkup implements IMarkup {
1143
1142
  end: { x: number; y: number },
1144
1143
  color?: string,
1145
1144
  id?: string
1146
- ): IMarkupArrow | void {
1145
+ ): KonvaArrow | void {
1147
1146
  if (!start || !end) return;
1148
1147
 
1149
1148
  const konvaArrow = new KonvaArrow({
@@ -1165,7 +1164,7 @@ export class KonvaMarkup implements IMarkup {
1165
1164
  lineWidth?: number,
1166
1165
  color?: string,
1167
1166
  id?: string
1168
- ): IMarkupCloud | void {
1167
+ ): KonvaCloud | void {
1169
1168
  if (!position || !width || !height) return;
1170
1169
 
1171
1170
  const konvaCloud = new KonvaCloud({
@@ -1188,10 +1187,10 @@ export class KonvaMarkup implements IMarkup {
1188
1187
  width?: number,
1189
1188
  height?: number,
1190
1189
  id?: string
1191
- ): IMarkupImage | void {
1190
+ ): KonvaImage | void {
1192
1191
  if (!position) return;
1193
1192
 
1194
- let konvaImage: IMarkupImage;
1193
+ let konvaImage: KonvaImage;
1195
1194
 
1196
1195
  if (src) {
1197
1196
  konvaImage = new KonvaImage({