@inweb/viewer-visualize 25.3.13

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.
Files changed (164) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +63 -0
  3. package/dist/viewer-visualize.js +16982 -0
  4. package/dist/viewer-visualize.js.map +1 -0
  5. package/dist/viewer-visualize.min.js +1 -0
  6. package/dist/viewer-visualize.module.js +5267 -0
  7. package/dist/viewer-visualize.module.js.map +1 -0
  8. package/lib/Viewer/Commands/ApplyModelTransform.d.ts +1 -0
  9. package/lib/Viewer/Commands/ClearMarkup.d.ts +1 -0
  10. package/lib/Viewer/Commands/ClearSlices.d.ts +1 -0
  11. package/lib/Viewer/Commands/CreatePreview.d.ts +1 -0
  12. package/lib/Viewer/Commands/Explode.d.ts +1 -0
  13. package/lib/Viewer/Commands/GetDefaultViewPositions.d.ts +1 -0
  14. package/lib/Viewer/Commands/GetModels.d.ts +1 -0
  15. package/lib/Viewer/Commands/GetSelected.d.ts +1 -0
  16. package/lib/Viewer/Commands/HideSelected.d.ts +1 -0
  17. package/lib/Viewer/Commands/IsolateSelected.d.ts +1 -0
  18. package/lib/Viewer/Commands/RegenerateAll.d.ts +1 -0
  19. package/lib/Viewer/Commands/ResetView.d.ts +1 -0
  20. package/lib/Viewer/Commands/SelectModel.d.ts +1 -0
  21. package/lib/Viewer/Commands/SetActiveDragger.d.ts +1 -0
  22. package/lib/Viewer/Commands/SetDefaultViewPosition.d.ts +1 -0
  23. package/lib/Viewer/Commands/SetMarkupColor.d.ts +1 -0
  24. package/lib/Viewer/Commands/SetSelected.d.ts +1 -0
  25. package/lib/Viewer/Commands/ShowAll.d.ts +1 -0
  26. package/lib/Viewer/Commands/Unselect.d.ts +1 -0
  27. package/lib/Viewer/Commands/ZoomToExtents.d.ts +1 -0
  28. package/lib/Viewer/Commands/ZoomToObjects.d.ts +1 -0
  29. package/lib/Viewer/Commands/ZoomToSelected.d.ts +1 -0
  30. package/lib/Viewer/Commands/index.d.ts +22 -0
  31. package/lib/Viewer/Draggers/Actions/OrbitAction.d.ts +21 -0
  32. package/lib/Viewer/Draggers/Actions/PanAction.d.ts +17 -0
  33. package/lib/Viewer/Draggers/Actions/ZoomAction.d.ts +7 -0
  34. package/lib/Viewer/Draggers/Common/Geometry.d.ts +114 -0
  35. package/lib/Viewer/Draggers/Common/GestureManager.d.ts +40 -0
  36. package/lib/Viewer/Draggers/Common/OdBaseDragger.d.ts +53 -0
  37. package/lib/Viewer/Draggers/Common/OdaGeAction.d.ts +29 -0
  38. package/lib/Viewer/Draggers/MeasureLineDragger/MeasureLineItem.d.ts +30 -0
  39. package/lib/Viewer/Draggers/MeasureLineDragger/MeasureUtils.d.ts +19 -0
  40. package/lib/Viewer/Draggers/MeasureLineDragger/index.d.ts +23 -0
  41. package/lib/Viewer/Draggers/OdBaseCuttingPlaneDragger.d.ts +26 -0
  42. package/lib/Viewer/Draggers/OdCuttingPlaneXAxisDragger.d.ts +7 -0
  43. package/lib/Viewer/Draggers/OdCuttingPlaneYAxisDragger.d.ts +7 -0
  44. package/lib/Viewer/Draggers/OdCuttingPlaneZAxisDragger.d.ts +7 -0
  45. package/lib/Viewer/Draggers/OdOrbitDragger.d.ts +14 -0
  46. package/lib/Viewer/Draggers/OdPanDragger.d.ts +11 -0
  47. package/lib/Viewer/Draggers/OdZoomDragger.d.ts +11 -0
  48. package/lib/Viewer/Draggers/OdZoomWheelDragger.d.ts +10 -0
  49. package/lib/Viewer/Draggers/OdZoomWindowDragger/OdSelectionFrame.d.ts +18 -0
  50. package/lib/Viewer/Draggers/OdZoomWindowDragger/index.d.ts +13 -0
  51. package/lib/Viewer/Draggers/OdaLineDragger.d.ts +14 -0
  52. package/lib/Viewer/Draggers/OdaTextDragger.d.ts +15 -0
  53. package/lib/Viewer/Draggers/OdaWalkDragger.d.ts +29 -0
  54. package/lib/Viewer/Draggers/OrbitAroundBuildingDragger.d.ts +18 -0
  55. package/lib/Viewer/Loaders/BaseLoader.d.ts +10 -0
  56. package/lib/Viewer/Loaders/LoaderFactory.d.ts +10 -0
  57. package/lib/Viewer/Loaders/TCSLoader.d.ts +4 -0
  58. package/lib/Viewer/Loaders/UpdaterController.d.ts +14 -0
  59. package/lib/Viewer/Loaders/VsfXLoader.d.ts +4 -0
  60. package/lib/Viewer/Loaders/VsfXPartialLoader.d.ts +4 -0
  61. package/lib/Viewer/Loaders/VsfXStreamingLoader.d.ts +4 -0
  62. package/lib/Viewer/Markup/Api/IMarkupArrow.d.ts +21 -0
  63. package/lib/Viewer/Markup/Api/IMarkupCloud.d.ts +14 -0
  64. package/lib/Viewer/Markup/Api/IMarkupColorable.d.ts +4 -0
  65. package/lib/Viewer/Markup/Api/IMarkupEllipse.d.ts +14 -0
  66. package/lib/Viewer/Markup/Api/IMarkupImage.d.ts +14 -0
  67. package/lib/Viewer/Markup/Api/IMarkupLine.d.ts +12 -0
  68. package/lib/Viewer/Markup/Api/IMarkupObject.d.ts +11 -0
  69. package/lib/Viewer/Markup/Api/IMarkupRectangle.d.ts +14 -0
  70. package/lib/Viewer/Markup/Api/IMarkupText.d.ts +12 -0
  71. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaArrow.d.ts +46 -0
  72. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaCloud.d.ts +35 -0
  73. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaEllipse.d.ts +40 -0
  74. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaImage.d.ts +36 -0
  75. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaLine.d.ts +36 -0
  76. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaRectangle.d.ts +38 -0
  77. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaText.d.ts +37 -0
  78. package/lib/Viewer/Markup/IMarkup.d.ts +39 -0
  79. package/lib/Viewer/Markup/Impl/Konva/KonvaMarkup.d.ts +70 -0
  80. package/lib/Viewer/Markup/Impl/Konva/MarkupColor.d.ts +18 -0
  81. package/lib/Viewer/Markup/Impl/Visualize/VisualizeMarkup.d.ts +33 -0
  82. package/lib/Viewer/Markup/MarkupFactory.d.ts +6 -0
  83. package/lib/Viewer/Viewer.d.ts +346 -0
  84. package/lib/Viewer/utils.d.ts +3 -0
  85. package/lib/index.d.ts +3 -0
  86. package/package.json +44 -0
  87. package/src/Viewer/Commands/ApplyModelTransform.ts +69 -0
  88. package/src/Viewer/Commands/ClearMarkup.ts +28 -0
  89. package/src/Viewer/Commands/ClearSlices.ts +27 -0
  90. package/src/Viewer/Commands/CreatePreview.ts +33 -0
  91. package/src/Viewer/Commands/Explode.ts +38 -0
  92. package/src/Viewer/Commands/GetDefaultViewPositions.ts +36 -0
  93. package/src/Viewer/Commands/GetModels.ts +43 -0
  94. package/src/Viewer/Commands/GetSelected.ts +58 -0
  95. package/src/Viewer/Commands/HideSelected.ts +37 -0
  96. package/src/Viewer/Commands/IsolateSelected.ts +37 -0
  97. package/src/Viewer/Commands/RegenerateAll.ts +37 -0
  98. package/src/Viewer/Commands/ResetView.ts +43 -0
  99. package/src/Viewer/Commands/SelectModel.ts +52 -0
  100. package/src/Viewer/Commands/SetActiveDragger.ts +29 -0
  101. package/src/Viewer/Commands/SetDefaultViewPosition.ts +50 -0
  102. package/src/Viewer/Commands/SetMarkupColor.ts +29 -0
  103. package/src/Viewer/Commands/SetSelected.ts +47 -0
  104. package/src/Viewer/Commands/ShowAll.ts +37 -0
  105. package/src/Viewer/Commands/Unselect.ts +37 -0
  106. package/src/Viewer/Commands/ZoomToExtents.ts +43 -0
  107. package/src/Viewer/Commands/ZoomToObjects.ts +47 -0
  108. package/src/Viewer/Commands/ZoomToSelected.ts +39 -0
  109. package/src/Viewer/Commands/index.ts +45 -0
  110. package/src/Viewer/Draggers/Actions/OrbitAction.ts +250 -0
  111. package/src/Viewer/Draggers/Actions/PanAction.ts +102 -0
  112. package/src/Viewer/Draggers/Actions/ZoomAction.ts +45 -0
  113. package/src/Viewer/Draggers/Common/Geometry.ts +152 -0
  114. package/src/Viewer/Draggers/Common/GestureManager.ts +263 -0
  115. package/src/Viewer/Draggers/Common/OdBaseDragger.ts +270 -0
  116. package/src/Viewer/Draggers/Common/OdaGeAction.ts +146 -0
  117. package/src/Viewer/Draggers/MeasureLineDragger/MeasureLineItem.ts +248 -0
  118. package/src/Viewer/Draggers/MeasureLineDragger/MeasureUtils.ts +182 -0
  119. package/src/Viewer/Draggers/MeasureLineDragger/index.ts +166 -0
  120. package/src/Viewer/Draggers/OdBaseCuttingPlaneDragger.ts +182 -0
  121. package/src/Viewer/Draggers/OdCuttingPlaneXAxisDragger.ts +53 -0
  122. package/src/Viewer/Draggers/OdCuttingPlaneYAxisDragger.ts +53 -0
  123. package/src/Viewer/Draggers/OdCuttingPlaneZAxisDragger.ts +53 -0
  124. package/src/Viewer/Draggers/OdOrbitDragger.ts +70 -0
  125. package/src/Viewer/Draggers/OdPanDragger.ts +62 -0
  126. package/src/Viewer/Draggers/OdZoomDragger.ts +59 -0
  127. package/src/Viewer/Draggers/OdZoomWheelDragger.ts +103 -0
  128. package/src/Viewer/Draggers/OdZoomWindowDragger/OdSelectionFrame.ts +123 -0
  129. package/src/Viewer/Draggers/OdZoomWindowDragger/index.ts +75 -0
  130. package/src/Viewer/Draggers/OdaLineDragger.ts +80 -0
  131. package/src/Viewer/Draggers/OdaTextDragger.ts +118 -0
  132. package/src/Viewer/Draggers/OdaWalkDragger.ts +278 -0
  133. package/src/Viewer/Draggers/OrbitAroundBuildingDragger.ts +184 -0
  134. package/src/Viewer/Loaders/BaseLoader.ts +40 -0
  135. package/src/Viewer/Loaders/LoaderFactory.ts +48 -0
  136. package/src/Viewer/Loaders/TCSLoader.ts +82 -0
  137. package/src/Viewer/Loaders/UpdaterController.ts +36 -0
  138. package/src/Viewer/Loaders/VsfXLoader.ts +65 -0
  139. package/src/Viewer/Loaders/VsfXPartialLoader.ts +208 -0
  140. package/src/Viewer/Loaders/VsfXStreamingLoader.ts +87 -0
  141. package/src/Viewer/Markup/Api/IMarkupArrow.ts +12 -0
  142. package/src/Viewer/Markup/Api/IMarkupCloud.ts +15 -0
  143. package/src/Viewer/Markup/Api/IMarkupColorable.ts +4 -0
  144. package/src/Viewer/Markup/Api/IMarkupEllipse.ts +15 -0
  145. package/src/Viewer/Markup/Api/IMarkupImage.ts +15 -0
  146. package/src/Viewer/Markup/Api/IMarkupLine.ts +13 -0
  147. package/src/Viewer/Markup/Api/IMarkupObject.ts +15 -0
  148. package/src/Viewer/Markup/Api/IMarkupRectangle.ts +15 -0
  149. package/src/Viewer/Markup/Api/IMarkupText.ts +12 -0
  150. package/src/Viewer/Markup/Api/Impl/Konva/KonvaArrow.ts +117 -0
  151. package/src/Viewer/Markup/Api/Impl/Konva/KonvaCloud.ts +208 -0
  152. package/src/Viewer/Markup/Api/Impl/Konva/KonvaEllipse.ts +118 -0
  153. package/src/Viewer/Markup/Api/Impl/Konva/KonvaImage.ts +123 -0
  154. package/src/Viewer/Markup/Api/Impl/Konva/KonvaLine.ts +131 -0
  155. package/src/Viewer/Markup/Api/Impl/Konva/KonvaRectangle.ts +119 -0
  156. package/src/Viewer/Markup/Api/Impl/Konva/KonvaText.ts +110 -0
  157. package/src/Viewer/Markup/IMarkup.ts +42 -0
  158. package/src/Viewer/Markup/Impl/Konva/KonvaMarkup.ts +1144 -0
  159. package/src/Viewer/Markup/Impl/Konva/MarkupColor.ts +39 -0
  160. package/src/Viewer/Markup/Impl/Visualize/VisualizeMarkup.ts +229 -0
  161. package/src/Viewer/Markup/MarkupFactory.ts +32 -0
  162. package/src/Viewer/Viewer.ts +1183 -0
  163. package/src/Viewer/utils.ts +74 -0
  164. package/src/index.ts +26 -0
@@ -0,0 +1,87 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2002-2021, Open Design Alliance (the "Alliance").
3
+ // All rights reserved.
4
+ //
5
+ // This software and its documentation and related materials are owned by
6
+ // the Alliance. The software may only be incorporated into application
7
+ // programs owned by members of the Alliance, subject to a signed
8
+ // Membership Agreement and Supplemental Software License Agreement with the
9
+ // Alliance. The structure and organization of this software are the valuable
10
+ // trade secrets of the Alliance and its suppliers. The software is also
11
+ // protected by copyright law and international treaty provisions. Application
12
+ // programs incorporating this software must include the following statement
13
+ // with their copyright notices:
14
+ //
15
+ // This application incorporates Open Design Alliance software pursuant to a
16
+ // license agreement with Open Design Alliance.
17
+ // Open Design Alliance Copyright (C) 2002-2021 by Open Design Alliance.
18
+ // All rights reserved.
19
+ //
20
+ // By use of this software, its documentation or related materials, you
21
+ // acknowledge and accept the above terms.
22
+ ///////////////////////////////////////////////////////////////////////////////
23
+
24
+ import { BaseLoader } from "./BaseLoader";
25
+ import { UpdaterController, UpdateType } from "./UpdaterController";
26
+
27
+ export class VsfXStreamingLoader extends BaseLoader {
28
+ override async load(): Promise<void> {
29
+ if (!this.viewer.visualizeJs) return;
30
+
31
+ const visLib = this.viewer.visLib();
32
+ const visViewer = visLib.getViewer();
33
+ const abortController = new AbortController();
34
+
35
+ const updaterController = new UpdaterController();
36
+ updaterController.initialize(this.viewer);
37
+
38
+ this.viewer._abortController = abortController;
39
+
40
+ let isFireDatabaseChunk = false;
41
+
42
+ const chunkLoadHandler = (progress, data) => {
43
+ if (!this.viewer.visualizeJs) return;
44
+
45
+ const status = visViewer.parseVsfx(data);
46
+ updaterController.update(UpdateType.kDelay);
47
+
48
+ this.viewer.emitEvent({ type: "geometryprogress", data: progress, model: this.model });
49
+
50
+ let state = false;
51
+ if (
52
+ status === visLib.DatabaseStreamStatus.ReadyServiceData ||
53
+ (status === visLib.DatabaseStreamStatus.Complete && !isFireDatabaseChunk)
54
+ ) {
55
+ isFireDatabaseChunk = true;
56
+ state = true;
57
+ }
58
+
59
+ if (state) {
60
+ updaterController.update(UpdateType.kForce);
61
+
62
+ this.viewer.syncOpenCloudVisualStyle(false);
63
+ this.viewer.syncOptions();
64
+ this.viewer.resize();
65
+
66
+ this.viewer.emitEvent({ type: "databasechunk", data, model: this.model });
67
+ } else {
68
+ this.viewer.emitEvent({ type: "geometrychunk", data, model: this.model });
69
+ }
70
+ };
71
+
72
+ console.time("File load time");
73
+ try {
74
+ this.viewer.emitEvent({ type: "geometrystart", model: this.model });
75
+
76
+ await this.model.partialDownloadResource(this.model.database, chunkLoadHandler, abortController.signal);
77
+ console.timeEnd("File load time");
78
+
79
+ updaterController.update(UpdateType.kNormal);
80
+
81
+ this.viewer.emitEvent({ type: "geometryend", model: this.model });
82
+ } catch (error) {
83
+ this.viewer.emitEvent({ type: "geometryerror", data: error, model: this.model });
84
+ throw error;
85
+ }
86
+ }
87
+ }
@@ -0,0 +1,12 @@
1
+ import { IMarkupObject } from "./IMarkupObject";
2
+
3
+ export interface IMarkupArrow extends IMarkupObject {
4
+ getPoints(): { x: number; y: number }[];
5
+ setPoints(points: { x: number; y: number }[]);
6
+
7
+ getStartPoint(): { x: number; y: number };
8
+ setStartPoint(x: number, y: number);
9
+
10
+ getEndPoint(): { x: number; y: number };
11
+ setEndPoint(x: number, y: number);
12
+ }
@@ -0,0 +1,15 @@
1
+ import { IMarkupObject } from "./IMarkupObject";
2
+
3
+ export interface IMarkupCloud extends IMarkupObject {
4
+ getPosition(): { x: number; y: number };
5
+ setPosition(x: number, y: number);
6
+
7
+ getWidth(): number;
8
+ setWidth(w: number);
9
+
10
+ getHeigth(): number;
11
+ setHeight(h: number);
12
+
13
+ getLineWidth(): number;
14
+ setLineWidth(size: number);
15
+ }
@@ -0,0 +1,4 @@
1
+ export interface IMarkupColorable {
2
+ getColor(): string;
3
+ setColor(hex: string): void;
4
+ }
@@ -0,0 +1,15 @@
1
+ import { IMarkupObject } from "./IMarkupObject";
2
+
3
+ export interface IMarkupEllipse extends IMarkupObject {
4
+ getPosition(): { x: number; y: number };
5
+ setPosition(x: number, y: number);
6
+
7
+ getRadiusX(): number;
8
+ setRadiusX(r: number);
9
+
10
+ getRadiusY(): number;
11
+ setRadiusY(r: number);
12
+
13
+ getLineWidth(): number;
14
+ setLineWidth(size: number);
15
+ }
@@ -0,0 +1,15 @@
1
+ import { IMarkupObject } from "./IMarkupObject";
2
+
3
+ export interface IMarkupImage extends IMarkupObject {
4
+ getPosition(): { x: number; y: number };
5
+ setPosition(x: number, y: number);
6
+
7
+ getSrc(): string;
8
+ setSrc(src: string);
9
+
10
+ getWidth(): number;
11
+ setWidth(w: number);
12
+
13
+ getHeight(): number;
14
+ setHeight(h: number);
15
+ }
@@ -0,0 +1,13 @@
1
+ import { IMarkupObject } from "./IMarkupObject";
2
+
3
+ export interface IMarkupLine extends IMarkupObject {
4
+ getPoints(): number[];
5
+
6
+ getLineWidth(): number;
7
+ setLineWidth(size: number);
8
+
9
+ getLineType(): string;
10
+ setLineType(type: string);
11
+
12
+ addPoints(points: [{ x: number; y: number }]);
13
+ }
@@ -0,0 +1,15 @@
1
+ export interface IMarkupObject {
2
+ // link to library object (Konva, Vis...)
3
+ ref(): any;
4
+ id(): string;
5
+ enableMouseEditing(value: boolean);
6
+ type(): string;
7
+
8
+ getRotation(): number;
9
+ setRotation(degrees: number): void;
10
+
11
+ getZIndex(): number;
12
+ setZIndex(zIndex: number): void;
13
+
14
+ delete();
15
+ }
@@ -0,0 +1,15 @@
1
+ import { IMarkupObject } from "./IMarkupObject";
2
+
3
+ export interface IMarkupRectangle extends IMarkupObject {
4
+ getPosition(): { x: number; y: number };
5
+ setPosition(x: number, y: number);
6
+
7
+ getWidth(): number;
8
+ setWidth(w: number);
9
+
10
+ getHeigth(): number;
11
+ setHeight(h: number);
12
+
13
+ getLineWidth(): number;
14
+ setLineWidth(size: number);
15
+ }
@@ -0,0 +1,12 @@
1
+ import { IMarkupObject } from "./IMarkupObject";
2
+
3
+ export interface IMarkupText extends IMarkupObject {
4
+ getText(): string;
5
+ setText(text: string): void;
6
+
7
+ getPosition(): { x: number; y: number };
8
+ setPosition(x: number, y: number);
9
+
10
+ getFontSize();
11
+ setFontSize(size: number);
12
+ }
@@ -0,0 +1,117 @@
1
+ import Konva from "konva";
2
+ import { IMarkupArrow } from "../../IMarkupArrow";
3
+ import { IMarkupColorable } from "../../IMarkupColorable";
4
+
5
+ export class KonvaArrow implements IMarkupArrow, IMarkupColorable {
6
+ private _ref: Konva.Arrow;
7
+
8
+ constructor(
9
+ params: {
10
+ start: { x: number; y: number };
11
+ end: { x: number; y: number };
12
+ color?: string;
13
+ id?: string;
14
+ },
15
+ ref = null
16
+ ) {
17
+ if (ref) {
18
+ this._ref = ref;
19
+ return;
20
+ }
21
+
22
+ if (!params.start || !params.end) return;
23
+
24
+ this._ref = new Konva.Arrow({
25
+ stroke: params.color ?? "#ff0000",
26
+ fill: params.color ?? "#ff0000",
27
+ strokeWidth: 4,
28
+ globalCompositeOperation: "source-over",
29
+ lineCap: "round",
30
+ lineJoin: "round",
31
+ points: [params.start.x, params.start.y, params.end.x, params.end.y],
32
+ draggable: true,
33
+ strokeScaleEnabled: false,
34
+ });
35
+
36
+ this._ref.id(this._ref._id.toString());
37
+ }
38
+
39
+ ref() {
40
+ return this._ref;
41
+ }
42
+
43
+ id(): string {
44
+ return this._ref.id();
45
+ }
46
+
47
+ enableMouseEditing(value: boolean) {
48
+ this._ref.draggable(value);
49
+ }
50
+
51
+ type(): string {
52
+ return "arrow";
53
+ }
54
+
55
+ getColor(): string {
56
+ return this._ref.stroke();
57
+ }
58
+
59
+ setColor(hex: string) {
60
+ this._ref.stroke(hex);
61
+ }
62
+
63
+ getRotation(): number {
64
+ return this._ref.rotation();
65
+ }
66
+
67
+ setRotation(degrees: number): void {
68
+ this._ref.rotation(degrees);
69
+ }
70
+
71
+ getZIndex(): number {
72
+ return this._ref.zIndex();
73
+ }
74
+
75
+ setZIndex(zIndex: number): void {
76
+ this._ref.zIndex(zIndex);
77
+ }
78
+
79
+ delete() {
80
+ this._ref.destroy();
81
+ this._ref = null;
82
+ }
83
+
84
+ getPoints(): { x: number; y: number }[] {
85
+ const points = this._ref.points();
86
+ return [
87
+ { x: points[0], y: points[1] },
88
+ { x: points[2], y: points[3] },
89
+ ];
90
+ }
91
+
92
+ setPoints(points: { x: number; y: number }[]) {
93
+ if (points.length === 2) {
94
+ this._ref.points([points[0].x, points[0].y, points[1].x, points[1].y]);
95
+ }
96
+ }
97
+
98
+ getStartPoint(): { x: number; y: number } {
99
+ const points = this._ref.points();
100
+ return { x: points[0], y: points[1] };
101
+ }
102
+
103
+ setStartPoint(x: number, y: number) {
104
+ const points = this._ref.points();
105
+ this._ref.points([x, y, points[2], points[3]]);
106
+ }
107
+
108
+ getEndPoint(): { x: number; y: number } {
109
+ const points = this._ref.points();
110
+ return { x: points[2], y: points[3] };
111
+ }
112
+
113
+ setEndPoint(x: number, y: number) {
114
+ const points = this._ref.points();
115
+ this._ref.points([points[0], points[1], x, y]);
116
+ }
117
+ }
@@ -0,0 +1,208 @@
1
+ import Konva from "konva";
2
+ import { IMarkupColorable } from "../../IMarkupColorable";
3
+ import { IMarkupCloud } from "../../IMarkupCloud";
4
+
5
+ export class KonvaCloud implements IMarkupCloud, IMarkupColorable {
6
+ private _ref: Konva.Shape;
7
+
8
+ constructor(
9
+ params: {
10
+ position: { x: number; y: number };
11
+ width?: number;
12
+ height?: number;
13
+ lineWidth?: number;
14
+ color?: string;
15
+ id?: string;
16
+ },
17
+ ref = null
18
+ ) {
19
+ if (ref) {
20
+ this._ref = ref;
21
+ return;
22
+ }
23
+
24
+ if (!params.position || !params.width || !params.height) return;
25
+
26
+ const arcRadius = 16;
27
+
28
+ this._ref = new Konva.Shape({
29
+ x: params.position.x,
30
+ y: params.position.y,
31
+ width: params.width ?? 200,
32
+ height: params.height ?? 200,
33
+ stroke: params.color ?? "#ff0000",
34
+ strokeWidth: params.lineWidth ?? 5,
35
+ draggable: true,
36
+ strokeScaleEnabled: false,
37
+ globalCompositeOperation: "source-over",
38
+ sceneFunc: (context, shape) => {
39
+ function calculateMidpoint(position, width, height) {
40
+ const midX = position.x + width / 2;
41
+ const midY = position.y + height / 2;
42
+ return { x: midX, y: midY };
43
+ }
44
+
45
+ const points = [
46
+ { x: 0, y: 0 },
47
+ { x: 0 + this._ref.width(), y: 0 },
48
+ { x: 0 + this._ref.width(), y: 0 + this._ref.height() },
49
+ { x: 0, y: 0 + this._ref.height() },
50
+ { x: 0, y: 0 },
51
+ ];
52
+
53
+ const midPoint = calculateMidpoint({ x: 0, y: 0 }, this._ref.width(), this._ref.height());
54
+
55
+ const baseArcLength = 30;
56
+ context.beginPath();
57
+ for (let iPoint = 0; iPoint < points.length - 1; iPoint++) {
58
+ let approxArcLength = baseArcLength;
59
+ const dx = points[iPoint + 1].x - points[iPoint].x;
60
+ const dy = points[iPoint + 1].y - points[iPoint].y;
61
+ const length = Math.sqrt(dx * dx + dy * dy);
62
+
63
+ const arcCount = Math.floor(length / approxArcLength);
64
+ const lengthMod = length % approxArcLength;
65
+ approxArcLength = baseArcLength + arcCount / lengthMod;
66
+
67
+ let pX = points[iPoint].x + dx / arcCount / 2;
68
+ let pY = points[iPoint].y + dy / arcCount / 2;
69
+ const pEndX = points[iPoint + 1].x;
70
+ const pEndY = points[iPoint + 1].y;
71
+ const endAngle = Math.atan((pEndY - pY) / (pEndX - pX));
72
+ const startAngle = endAngle + Math.PI;
73
+ const counterClockwise = pX > midPoint.x && pY > midPoint.y;
74
+ for (let iArc = 0; iArc < arcCount; iArc++) {
75
+ if (counterClockwise) {
76
+ context.arc(pX, pY, arcRadius, endAngle, startAngle);
77
+ } else {
78
+ context.arc(pX, pY, arcRadius, startAngle, endAngle);
79
+ }
80
+
81
+ pX += dx / arcCount;
82
+ pY += dy / arcCount;
83
+ }
84
+ }
85
+
86
+ context.closePath();
87
+ // (!) Konva specific method, it is very important
88
+ // it will apply are required styles
89
+ context.fillStrokeShape(shape);
90
+ },
91
+ });
92
+
93
+ this._ref.className = "Cloud";
94
+
95
+ this._ref.on("transform", (e) => {
96
+ const attrs = e.target.attrs;
97
+
98
+ const minWidth = 100;
99
+ const minHeight = 100;
100
+
101
+ const newWidth = this._ref.width() * attrs.scaleX;
102
+ const newHeight = this._ref.height() * attrs.scaleY;
103
+
104
+ if (newWidth < minWidth || newHeight < minHeight) {
105
+ this._ref.scale({ x: 1, y: 1 });
106
+ return;
107
+ }
108
+
109
+ if (Math.abs(attrs.scaleX - 1) > 10e-6) {
110
+ this._ref.width(newWidth);
111
+ }
112
+
113
+ if (Math.abs(attrs.scaleY - 1) > 10e-6) {
114
+ this._ref.height(newHeight);
115
+ }
116
+
117
+ this._ref.scale({ x: 1, y: 1 });
118
+ });
119
+
120
+ this._ref.getSelfRect = () => {
121
+ return {
122
+ x: 0 - arcRadius,
123
+ y: 0 - arcRadius,
124
+ width: this._ref.width() + 2 * arcRadius,
125
+ height: this._ref.height() + 2 * arcRadius,
126
+ };
127
+ };
128
+
129
+ this._ref.id(this._ref._id.toString());
130
+ }
131
+
132
+ ref() {
133
+ return this._ref;
134
+ }
135
+
136
+ id(): string {
137
+ return this._ref.id();
138
+ }
139
+
140
+ enableMouseEditing(value: boolean) {
141
+ this._ref.draggable(value);
142
+ }
143
+
144
+ type(): string {
145
+ return "cloud";
146
+ }
147
+
148
+ getColor(): string {
149
+ return this._ref.stroke();
150
+ }
151
+
152
+ setColor(hex: string) {
153
+ this._ref.stroke(hex);
154
+ }
155
+
156
+ getRotation(): number {
157
+ return this._ref.rotation();
158
+ }
159
+
160
+ setRotation(degrees: number): void {
161
+ this._ref.rotation(degrees);
162
+ }
163
+
164
+ getZIndex(): number {
165
+ return this._ref.zIndex();
166
+ }
167
+
168
+ setZIndex(zIndex: number): void {
169
+ this._ref.zIndex(zIndex);
170
+ }
171
+
172
+ delete() {
173
+ this._ref.destroy();
174
+ this._ref = null;
175
+ }
176
+
177
+ getPosition() {
178
+ return this._ref.position();
179
+ }
180
+
181
+ setPosition(x: number, y: number) {
182
+ this._ref.position({ x, y });
183
+ }
184
+
185
+ getWidth(): number {
186
+ return this._ref.width();
187
+ }
188
+
189
+ setWidth(w: number) {
190
+ this._ref.width(w);
191
+ }
192
+
193
+ getHeigth(): number {
194
+ return this._ref.height();
195
+ }
196
+
197
+ setHeight(h: number) {
198
+ this._ref.height(h);
199
+ }
200
+
201
+ getLineWidth(): number {
202
+ return this._ref.strokeWidth();
203
+ }
204
+
205
+ setLineWidth(size: number) {
206
+ this._ref.strokeWidth(size);
207
+ }
208
+ }
@@ -0,0 +1,118 @@
1
+ import Konva from "konva";
2
+ import { IMarkupEllipse } from "../../IMarkupEllipse";
3
+ import { IMarkupColorable } from "../../IMarkupColorable";
4
+
5
+ export class KonvaEllipse implements IMarkupEllipse, IMarkupColorable {
6
+ private _ref: Konva.Ellipse;
7
+
8
+ constructor(
9
+ params: {
10
+ position: { x: number; y: number };
11
+ radius: { x: number; y: number };
12
+ lineWidth?: number;
13
+ color?: string;
14
+ id?: string;
15
+ },
16
+ ref = null
17
+ ) {
18
+ if (ref) {
19
+ this._ref = ref;
20
+ return;
21
+ }
22
+
23
+ if (!params.position) return;
24
+
25
+ this._ref = new Konva.Ellipse({
26
+ stroke: params.color ?? "#ff0000",
27
+ strokeWidth: params.lineWidth ?? 4,
28
+ globalCompositeOperation: "source-over",
29
+ lineCap: "round",
30
+ lineJoin: "round",
31
+ x: params.position.x,
32
+ y: params.position.y,
33
+ radiusX: params.radius.x,
34
+ radiusY: params.radius.y,
35
+ draggable: true,
36
+ strokeScaleEnabled: false,
37
+ });
38
+
39
+ this._ref.id(this._ref._id.toString());
40
+ }
41
+
42
+ getPosition(): { x: number; y: number } {
43
+ return this._ref.position();
44
+ }
45
+
46
+ setPosition(x: number, y: number) {
47
+ this._ref.setPosition({ x, y });
48
+ }
49
+
50
+ getRadiusX(): number {
51
+ return this._ref.radiusX();
52
+ }
53
+
54
+ setRadiusX(r: number) {
55
+ this._ref.radius({ x: r, y: this._ref.radiusY() });
56
+ }
57
+
58
+ getRadiusY(): number {
59
+ return this._ref.radiusY();
60
+ }
61
+
62
+ setRadiusY(r: number) {
63
+ this._ref.radius({ x: this._ref.radiusX(), y: r });
64
+ }
65
+
66
+ getLineWidth(): number {
67
+ return this._ref.strokeWidth();
68
+ }
69
+
70
+ setLineWidth(size: number) {
71
+ this._ref.strokeWidth(size);
72
+ }
73
+
74
+ ref() {
75
+ return this._ref;
76
+ }
77
+
78
+ id(): string {
79
+ return this._ref.id();
80
+ }
81
+
82
+ enableMouseEditing(value: boolean) {
83
+ this._ref.draggable(value);
84
+ }
85
+
86
+ type(): string {
87
+ return "ellipse";
88
+ }
89
+
90
+ getColor(): string {
91
+ return this._ref.stroke();
92
+ }
93
+
94
+ setColor(hex: string) {
95
+ this._ref.stroke(hex);
96
+ }
97
+
98
+ getRotation(): number {
99
+ return this._ref.rotation();
100
+ }
101
+
102
+ setRotation(degrees: number): void {
103
+ this._ref.rotation(degrees);
104
+ }
105
+
106
+ getZIndex(): number {
107
+ return this._ref.zIndex();
108
+ }
109
+
110
+ setZIndex(zIndex: number): void {
111
+ this._ref.zIndex(zIndex);
112
+ }
113
+
114
+ delete() {
115
+ this._ref.destroy();
116
+ this._ref = null;
117
+ }
118
+ }