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client-app/./node_modules/openbim-components/src/annotation/SVGArrow/index.js","webpack://client-app/./node_modules/openbim-components/src/annotation/DrawManager/index.js","webpack://client-app/./node_modules/openbim-components/src/annotation/ArrowAnnotation/index.js","webpack://client-app/./node_modules/openbim-components/src/annotation/SVGCircle/index.js","webpack://client-app/./node_modules/openbim-components/src/annotation/CircleAnnotation/index.js","webpack://client-app/./node_modules/openbim-components/src/annotation/SVGText/index.js","webpack://client-app/./node_modules/openbim-components/src/annotation/TextAnnotation/index.js","webpack://client-app/./node_modules/openbim-components/src/annotation/SVGRectangle/index.js","webpack://client-app/./node_modules/openbim-components/src/annotation/RectangleAnnotation/index.js"],"sourcesContent":["import { Vector2 } from \"three\";\r\nimport { generateUUID } from \"three/src/math/MathUtils\";\r\nimport { Component, Event, } from \"../../base-types\";\r\nexport class SVGArrow extends Component {\r\n constructor(components, startPoint, endPoint) {\r\n super(components);\r\n this.name = \"SVGRectangle\";\r\n this.enabled = true;\r\n this.id = generateUUID();\r\n /** {@link Disposable.onDisposed} */\r\n this.onDisposed = new Event();\r\n this._line = document.createElementNS(\"http://www.w3.org/2000/svg\", \"line\");\r\n this._polygon = document.createElementNS(\"http://www.w3.org/2000/svg\", \"polygon\");\r\n this._marker = document.createElementNS(\"http://www.w3.org/2000/svg\", \"marker\");\r\n this._arrow = document.createElementNS(\"http://www.w3.org/2000/svg\", \"g\");\r\n this._startPoint = new Vector2();\r\n this._endPoint = new Vector2();\r\n // Create marker for the arrow head\r\n this._marker.setAttribute(\"id\", `${this.id}-arrowhead`);\r\n this._marker.setAttribute(\"markerWidth\", \"5\");\r\n this._marker.setAttribute(\"markerHeight\", \"6\");\r\n this._marker.setAttribute(\"refX\", \"4\");\r\n this._marker.setAttribute(\"refY\", \"3\");\r\n this._marker.setAttribute(\"orient\", \"auto\");\r\n // Create polygon for the arrowhead shape\r\n this._polygon.setAttribute(\"points\", \"0 0, 5 3, 0 6\");\r\n this._marker.appendChild(this._polygon);\r\n this._line.setAttribute(\"marker-end\", `url(#${this.id}-arrowhead)`);\r\n this._arrow.append(this._marker, this._line);\r\n this.startPoint = startPoint ?? this.startPoint;\r\n this.endPoint = endPoint ?? this.endPoint;\r\n this._arrow.id = this.id;\r\n this.setStyle();\r\n }\r\n async dispose() {\r\n this._arrow.remove();\r\n this._marker.remove();\r\n this._polygon.remove();\r\n this._line.remove();\r\n this.components = null;\r\n await this.onDisposed.trigger();\r\n this.onDisposed.reset();\r\n }\r\n setStyle(style) {\r\n this._line.setAttribute(\"stroke\", style?.strokeColor ?? \"red\");\r\n this._line.setAttribute(\"stroke-width\", style?.strokeWidth?.toString() ?? \"4\");\r\n this._polygon.setAttribute(\"fill\", style?.strokeColor ?? \"red\");\r\n }\r\n reset() {\r\n this.x1 = 0;\r\n this.y1 = 0;\r\n this.x2 = 0;\r\n this.y2 = 0;\r\n }\r\n clone() {\r\n return new SVGArrow(this.components, this.startPoint, this.endPoint);\r\n }\r\n set x1(value) {\r\n this._startPoint.x = value;\r\n this._line.setAttribute(\"x1\", value.toString());\r\n }\r\n set y1(value) {\r\n this._startPoint.y = value;\r\n this._line.setAttribute(\"y1\", value.toString());\r\n }\r\n set startPoint(point) {\r\n this.x1 = point.x;\r\n this.y1 = point.y;\r\n }\r\n get startPoint() {\r\n return this._startPoint;\r\n }\r\n set x2(value) {\r\n this._endPoint.x = value;\r\n this._line.setAttribute(\"x2\", value.toString());\r\n }\r\n set y2(value) {\r\n this._endPoint.y = value;\r\n this._line.setAttribute(\"y2\", value.toString());\r\n }\r\n set endPoint(point) {\r\n this.x2 = point.x;\r\n this.y2 = point.y;\r\n }\r\n get endPoint() {\r\n return this._endPoint;\r\n }\r\n get() {\r\n return this._arrow;\r\n }\r\n}\r\n//# sourceMappingURL=index.js.map","import { UIElement, Event, } from \"../../base-types\";\r\nimport { Component } from \"../../base-types/component\";\r\nimport { SimpleSVGViewport } from \"../../core/SimpleSVGViewport\";\r\nimport { Button } from \"../../ui/ButtonComponent\";\r\nimport { Toolbar } from \"../../ui/ToolbarComponent\";\r\nexport class DrawManager extends Component {\r\n get isDrawing() {\r\n return this._isDrawing;\r\n }\r\n set isDrawing(value) {\r\n this._isDrawing = value;\r\n }\r\n get enabled() {\r\n return this._enabled;\r\n }\r\n set enabled(value) {\r\n this._enabled = value;\r\n if (this.components.uiEnabled) {\r\n this.uiElement.get(\"main\").active = value;\r\n this.uiElement.get(\"drawingTools\").visible = value;\r\n }\r\n this.viewport.enabled = value;\r\n }\r\n constructor(components) {\r\n super(components);\r\n this.name = \"DrawManager\";\r\n /** {@link Disposable.onDisposed} */\r\n this.onDisposed = new Event();\r\n this.uiElement = new UIElement();\r\n this.drawingTools = {};\r\n this.drawings = {};\r\n this._enabled = false;\r\n this._isDrawing = false;\r\n components.tools.add(DrawManager.uuid, this);\r\n this.viewport = new SimpleSVGViewport(components);\r\n if (components.uiEnabled) {\r\n this.setUI();\r\n }\r\n this.enabled = false;\r\n }\r\n async dispose() {\r\n this.uiElement.dispose();\r\n await this.viewport.dispose();\r\n for (const name in this.drawings) {\r\n this.drawings[name].remove();\r\n }\r\n this.drawings = {};\r\n this.components = null;\r\n await this.onDisposed.trigger(DrawManager.uuid);\r\n this.onDisposed.reset();\r\n }\r\n saveDrawing(name) {\r\n const currentDrawing = this.drawings[name];\r\n currentDrawing?.childNodes.forEach((child) => currentDrawing.removeChild(child));\r\n const drawing = this.viewport.getDrawing();\r\n const group = currentDrawing ??\r\n document.createElementNS(\"http://www.w3.org/2000/svg\", \"g\");\r\n group.id = name;\r\n group.append(...drawing);\r\n this.viewport.get().append(group);\r\n this.drawings[name] = group;\r\n return group;\r\n }\r\n addDrawingTool(name, tool) {\r\n const existingTool = this.drawingTools[name];\r\n if (!existingTool) {\r\n if (this.components.uiEnabled) {\r\n const main = tool.uiElement.get(\"main\");\r\n this.uiElement.get(\"drawingTools\").addChild(main);\r\n }\r\n tool.svgViewport = this.viewport.get();\r\n this.drawingTools[name] = tool;\r\n }\r\n }\r\n activateTool(tool) {\r\n const tools = Object.values(this.drawingTools);\r\n const existingTool = tools.find((t) => t === tool);\r\n if (!existingTool) {\r\n console.warn(\"DrawManager: Tried to activate a drawing tool that is not registered yet.\");\r\n return;\r\n }\r\n for (const t of tools) {\r\n t.enabled = false;\r\n }\r\n tool.enabled = true;\r\n }\r\n get activeTool() {\r\n const drawingTools = Object.values(this.drawingTools);\r\n return drawingTools.find((tool) => tool.enabled === true);\r\n }\r\n setUI() {\r\n const viewportToolbar = this.viewport.uiElement.get(\"toolbar\");\r\n const drawingTools = new Toolbar(this.components, { position: \"top\" });\r\n setTimeout(() => {\r\n drawingTools.visible = false;\r\n viewportToolbar.visible = false;\r\n }, 0.001);\r\n this.components.ui.addToolbar(drawingTools);\r\n this.components.ui.addToolbar(viewportToolbar);\r\n const main = new Button(this.components);\r\n main.materialIcon = \"gesture\";\r\n main.onClick.add(() => (this.enabled = !this.enabled));\r\n this.uiElement.set({ drawingTools, main });\r\n }\r\n get() {\r\n return null;\r\n }\r\n}\r\nDrawManager.uuid = \"4ab8b0f4-665d-4ea2-8f6e-66c98ed04392\";\r\n//# sourceMappingURL=index.js.map","import { BaseSVGAnnotation, UIElement } from \"../../base-types\";\r\nimport { Button } from \"../../ui\";\r\nimport { SVGArrow } from \"../SVGArrow\";\r\nimport { DrawManager } from \"../DrawManager\";\r\nexport class ArrowAnnotation extends BaseSVGAnnotation {\r\n constructor(components) {\r\n super(components);\r\n this.name = \"ArrowAnnotation\";\r\n this.canvas = null;\r\n this.uiElement = new UIElement();\r\n this.cancel = () => {\r\n if (!this._isDrawing) {\r\n return;\r\n }\r\n this._isDrawing = false;\r\n this._previewElement.reset();\r\n this._previewElement.get().remove();\r\n };\r\n this.start = (event) => {\r\n if (!this.canDraw) {\r\n return null;\r\n }\r\n const drawManager = this.components.tools.get(DrawManager);\r\n if (!this._isDrawing) {\r\n this._isDrawing = true;\r\n this._previewElement.setStyle(drawManager.viewport.config);\r\n this._previewElement.x1 = event.clientX;\r\n this._previewElement.y1 = event.clientY;\r\n this._previewElement.x2 = event.clientX;\r\n this._previewElement.y2 = event.clientY;\r\n this.svgViewport?.append(this._previewElement.get());\r\n }\r\n else {\r\n const arrow = this._previewElement.clone();\r\n arrow.setStyle(drawManager.viewport.config);\r\n this.svgViewport?.append(arrow.get());\r\n this.cancel();\r\n return arrow;\r\n }\r\n return null;\r\n };\r\n this.draw = (e) => {\r\n if (!this.canDraw || !this._isDrawing) {\r\n return;\r\n }\r\n this._previewElement.x1 = e.clientX;\r\n this._previewElement.y1 = e.clientY;\r\n };\r\n this._previewElement = new SVGArrow(components);\r\n const drawManager = this.components.tools.get(DrawManager);\r\n if (components.uiEnabled) {\r\n this.setUI();\r\n }\r\n drawManager.addDrawingTool(this.name, this);\r\n }\r\n setUI() {\r\n const drawManager = this.components.tools.get(DrawManager);\r\n const main = new Button(this.components);\r\n main.label = \"Arrow\";\r\n main.materialIcon = \"north_east\";\r\n main.onClick.add(() => {\r\n drawManager.activateTool(this);\r\n });\r\n this.uiElement.set({ main });\r\n }\r\n async dispose() {\r\n await super.dispose();\r\n this._previewElement.dispose();\r\n }\r\n}\r\n//# sourceMappingURL=index.js.map","import { Vector2 } from \"three\";\r\nimport { generateUUID } from \"three/src/math/MathUtils\";\r\nimport { Component, Event, } from \"../../base-types\";\r\nexport class SVGCircle extends Component {\r\n constructor(components, centerPoint, radius) {\r\n super(components);\r\n this.id = generateUUID();\r\n this.name = \"SVGRectangle\";\r\n this.enabled = true;\r\n /** {@link Disposable.onDisposed} */\r\n this.onDisposed = new Event();\r\n this._circle = document.createElementNS(\"http://www.w3.org/2000/svg\", \"circle\");\r\n this._centerPoint = new Vector2();\r\n this._radius = 20;\r\n this.centerPoint = centerPoint ?? this.centerPoint;\r\n this.radius = radius ?? this.radius;\r\n this._circle.id = this.id;\r\n this.setStyle();\r\n }\r\n async dispose() {\r\n this._circle.remove();\r\n this.components = null;\r\n await this.onDisposed.trigger();\r\n this.onDisposed.reset();\r\n }\r\n setStyle(style) {\r\n this._circle.setAttribute(\"stroke\", style?.strokeColor ?? \"red\");\r\n this._circle.setAttribute(\"stroke-width\", style?.strokeWidth?.toString() ?? \"4\");\r\n this._circle.setAttribute(\"fill\", style?.fillColor ?? \"transparent\");\r\n }\r\n reset() {\r\n this.cx = 0;\r\n this.cy = 0;\r\n this.radius = 0;\r\n }\r\n clone() {\r\n return new SVGCircle(this.components, this.centerPoint, this.radius);\r\n }\r\n set radius(value) {\r\n this._radius = value;\r\n this._circle.setAttribute(\"r\", value.toString());\r\n }\r\n get radius() {\r\n return this._radius;\r\n }\r\n set cx(value) {\r\n this._centerPoint.x = value;\r\n this._circle.setAttribute(\"cx\", value.toString());\r\n }\r\n set cy(value) {\r\n this._centerPoint.y = value;\r\n this._circle.setAttribute(\"cy\", value.toString());\r\n }\r\n set centerPoint(point) {\r\n this.cx = point.x;\r\n this.cy = point.y;\r\n }\r\n get centerPoint() {\r\n return this._centerPoint;\r\n }\r\n get() {\r\n return this._circle;\r\n }\r\n}\r\n//# sourceMappingURL=index.js.map","import { Vector2 } from \"three\";\r\nimport { BaseSVGAnnotation, UIElement } from \"../../base-types\";\r\nimport { Button } from \"../../ui\";\r\nimport { DrawManager } from \"../DrawManager\";\r\nimport { SVGCircle } from \"../SVGCircle\";\r\nexport class CircleAnnotation extends BaseSVGAnnotation {\r\n constructor(components) {\r\n super(components);\r\n this.name = \"CircleAnnotation\";\r\n this.canvas = null;\r\n this.uiElement = new UIElement();\r\n this._cursorPosition = new Vector2();\r\n this.start = (e) => {\r\n if (!this.canDraw) {\r\n return null;\r\n }\r\n const drawManager = this.components.tools.get(DrawManager);\r\n if (!this._isDrawing) {\r\n this._isDrawing = true;\r\n this._previewElement.setStyle(drawManager.viewport.config);\r\n this._previewElement.cx = e.clientX;\r\n this._previewElement.cy = e.clientY;\r\n this.svgViewport?.append(this._previewElement.get());\r\n }\r\n else {\r\n const circle = this._previewElement.clone();\r\n circle.setStyle(drawManager.viewport.config);\r\n this.svgViewport?.append(circle.get());\r\n this.cancel();\r\n return circle;\r\n }\r\n return null;\r\n };\r\n this.cancel = () => {\r\n if (!this._isDrawing) {\r\n return;\r\n }\r\n this._isDrawing = false;\r\n this._previewElement.reset();\r\n this._previewElement.get().remove();\r\n };\r\n this.draw = (e) => {\r\n if (!this.canDraw || !this._isDrawing) {\r\n return;\r\n }\r\n this._cursorPosition.x = e.clientX;\r\n this._cursorPosition.y = e.clientY;\r\n this._previewElement.radius = this._cursorPosition.distanceTo(this._previewElement.centerPoint);\r\n };\r\n this._previewElement = new SVGCircle(components);\r\n const drawManager = this.components.tools.get(DrawManager);\r\n if (components.uiEnabled) {\r\n this.setUI();\r\n }\r\n drawManager.addDrawingTool(\"circle_annotation\", this);\r\n }\r\n setUI() {\r\n const drawManager = this.components.tools.get(DrawManager);\r\n const main = new Button(this.components);\r\n main.label = \"Circle\";\r\n main.materialIcon = \"radio_button_unchecked\";\r\n main.onClick.add(() => {\r\n drawManager.activateTool(this);\r\n });\r\n this.uiElement.set({ main });\r\n }\r\n async dispose() {\r\n await super.dispose();\r\n this._previewElement.dispose();\r\n }\r\n}\r\n//# sourceMappingURL=index.js.map","import { Vector2 } from \"three\";\r\nimport { generateUUID } from \"three/src/math/MathUtils\";\r\nimport { Component, Event, } from \"../../base-types\";\r\nexport class SVGText extends Component {\r\n constructor(components, text, startPoint) {\r\n super(components);\r\n this.id = generateUUID();\r\n this.name = \"SVGRectangle\";\r\n this.enabled = true;\r\n /** {@link Disposable.onDisposed} */\r\n this.onDisposed = new Event();\r\n this._startPoint = new Vector2();\r\n this._text = document.createElementNS(\"http://www.w3.org/2000/svg\", \"text\");\r\n this._text.setAttribute(\"fill\", \"red\");\r\n this._text.classList.add(\"text-2xl\", \"font-medium\");\r\n this.text = text ?? \"\";\r\n this.startPoint = startPoint ?? this.startPoint;\r\n this._text.id = this.id;\r\n }\r\n async dispose() {\r\n this._text.remove();\r\n await this.onDisposed.trigger();\r\n this.onDisposed.reset();\r\n }\r\n setStyle(style) {\r\n this._text.setAttribute(\"fill\", style?.strokeColor ?? \"red\");\r\n }\r\n set text(value) {\r\n this._text.textContent = value;\r\n }\r\n get text() {\r\n return this._text.textContent ?? \"\";\r\n }\r\n reset() {\r\n this.x = 0;\r\n this.y = 0;\r\n }\r\n clone() {\r\n return new SVGText(this.components, this.text, this.startPoint);\r\n }\r\n set x(value) {\r\n this._startPoint.x = value;\r\n this._text.setAttribute(\"x\", value.toString());\r\n }\r\n set y(value) {\r\n this._startPoint.y = value;\r\n this._text.setAttribute(\"y\", value.toString());\r\n }\r\n set startPoint(point) {\r\n this.x = point.x;\r\n this.y = point.y;\r\n }\r\n get startPoint() {\r\n return this._startPoint;\r\n }\r\n get() {\r\n return this._text;\r\n }\r\n}\r\n//# sourceMappingURL=index.js.map","import { BaseSVGAnnotation, UIElement } from \"../../base-types\";\r\nimport { Button } from \"../../ui\";\r\nimport { DrawManager } from \"../DrawManager\";\r\nimport { SVGText } from \"../SVGText\";\r\nexport class TextAnnotation extends BaseSVGAnnotation {\r\n constructor(components) {\r\n super(components);\r\n this.name = \"TextAnnotation\";\r\n this.uiElement = new UIElement();\r\n this.canvas = null;\r\n this.cancel = () => {\r\n if (!this._isDrawing) {\r\n return;\r\n }\r\n this._isDrawing = false;\r\n this._previewElement.reset();\r\n this._previewElement.get().remove();\r\n };\r\n this.start = (e) => {\r\n if (!this.canDraw) {\r\n return null;\r\n }\r\n const drawManager = this.components.tools.get(DrawManager);\r\n if (!this._isDrawing) {\r\n this._isDrawing = true;\r\n const text = prompt(\"Enter your text\", this._previewElement.text);\r\n if (!text) {\r\n this.cancel();\r\n return null;\r\n }\r\n this._previewElement.setStyle(drawManager.viewport.config);\r\n this._previewElement.text = text;\r\n this._previewElement.x = e.clientX;\r\n this._previewElement.y = e.clientY;\r\n this.svgViewport?.append(this._previewElement.get());\r\n }\r\n else {\r\n const text = this._previewElement.clone();\r\n text.setStyle(drawManager.viewport.config);\r\n this.svgViewport?.append(text.get());\r\n this.cancel();\r\n return text;\r\n }\r\n return null;\r\n };\r\n this.draw = (e) => {\r\n if (!this.canDraw || !this._isDrawing) {\r\n return;\r\n }\r\n this._previewElement.x = e.clientX;\r\n this._previewElement.y = e.clientY;\r\n };\r\n this._previewElement = new SVGText(components);\r\n const drawManager = this.components.tools.get(DrawManager);\r\n if (components.uiEnabled) {\r\n this.setUI();\r\n }\r\n drawManager.addDrawingTool(this.name, this);\r\n }\r\n setUI() {\r\n const drawManager = this.components.tools.get(DrawManager);\r\n const main = new Button(this.components);\r\n main.label = \"Text\";\r\n main.materialIcon = \"title\";\r\n main.onClick.add(() => {\r\n drawManager.activateTool(this);\r\n });\r\n this.uiElement.set({ main });\r\n }\r\n async dispose() {\r\n await super.dispose();\r\n await this._previewElement.dispose();\r\n }\r\n}\r\n//# sourceMappingURL=index.js.map","import { Vector2 } from \"three\";\r\nimport { generateUUID } from \"three/src/math/MathUtils\";\r\nimport { Component, Event, } from \"../../base-types\";\r\nexport class SVGRectangle extends Component {\r\n constructor(components, startPoint, endPoint) {\r\n super(components);\r\n this.id = generateUUID();\r\n this.name = \"SVGRectangle\";\r\n this.enabled = true;\r\n /** {@link Disposable.onDisposed} */\r\n this.onDisposed = new Event();\r\n this._startPoint = new Vector2();\r\n this._endPoint = new Vector2();\r\n this._dimensions = new Vector2();\r\n this._rect = document.createElementNS(\"http://www.w3.org/2000/svg\", \"rect\");\r\n this.startPoint = startPoint ?? this.startPoint;\r\n this.endPoint = endPoint ?? this.endPoint;\r\n this._rect.setAttribute(\"rx\", \"5\");\r\n this._rect.id = this.id;\r\n this.setStyle();\r\n }\r\n async dispose() {\r\n this._rect.remove();\r\n this.components = null;\r\n await this.onDisposed.trigger();\r\n this.onDisposed.reset();\r\n }\r\n setStyle(style) {\r\n this._rect.setAttribute(\"stroke\", style?.strokeColor ?? \"red\");\r\n this._rect.setAttribute(\"stroke-width\", style?.strokeWidth?.toString() ?? \"4\");\r\n this._rect.setAttribute(\"fill\", style?.fillColor ?? \"transparent\");\r\n }\r\n reset() {\r\n this.x1 = 0;\r\n this.y1 = 0;\r\n this.x2 = 0;\r\n this.y2 = 0;\r\n }\r\n clone() {\r\n return new SVGRectangle(this.components, this.startPoint, this.endPoint);\r\n }\r\n set x1(value) {\r\n this._startPoint.x = value;\r\n this._rect.setAttribute(\"x\", value.toString());\r\n }\r\n set y1(value) {\r\n this._startPoint.y = value;\r\n this._rect.setAttribute(\"y\", value.toString());\r\n }\r\n set startPoint(point) {\r\n this.x1 = point.x;\r\n this.y1 = point.y;\r\n }\r\n get startPoint() {\r\n return this._startPoint;\r\n }\r\n set x2(value) {\r\n const lessThanStart = value < this.startPoint.x;\r\n this._endPoint.x = lessThanStart ? this.startPoint.x : value;\r\n this.x1 = lessThanStart ? value : this.startPoint.x;\r\n this._dimensions.x = this.endPoint.x - this.startPoint.x;\r\n this._rect.setAttribute(\"width\", this._dimensions.x.toString());\r\n }\r\n set y2(value) {\r\n const lessThanStart = value < this.startPoint.y;\r\n this._endPoint.y = lessThanStart ? this.startPoint.y : value;\r\n this.y1 = lessThanStart ? value : this.startPoint.y;\r\n this._dimensions.y = this.endPoint.y - this.startPoint.y;\r\n this._rect.setAttribute(\"height\", this._dimensions.y.toString());\r\n }\r\n set endPoint(point) {\r\n this.x2 = point.x;\r\n this.y2 = point.y;\r\n }\r\n get endPoint() {\r\n return this._endPoint;\r\n }\r\n set width(value) {\r\n this.x2 = this.startPoint.x + value;\r\n }\r\n get width() {\r\n return this._dimensions.x;\r\n }\r\n set height(value) {\r\n this.y2 = this.startPoint.y + value;\r\n }\r\n get height() {\r\n return this._dimensions.y;\r\n }\r\n set dimensions(value) {\r\n this.width = value.x;\r\n this.height = value.y;\r\n }\r\n get dimensions() {\r\n return this._dimensions;\r\n }\r\n get() {\r\n return this._rect;\r\n }\r\n}\r\n//# sourceMappingURL=index.js.map","import { Vector2 } from \"three\";\r\nimport { BaseSVGAnnotation, UIElement } from \"../../base-types\";\r\nimport { Button } from \"../../ui\";\r\nimport { DrawManager } from \"../DrawManager\";\r\nimport { SVGRectangle } from \"../SVGRectangle\";\r\nexport class RectangleAnnotation extends BaseSVGAnnotation {\r\n constructor(components) {\r\n super(components);\r\n this.name = \"RectangleAnnotation\";\r\n this.canvas = null;\r\n this.uiElement = new UIElement();\r\n this._startPoint = new Vector2();\r\n this.start = (e) => {\r\n if (!this.canDraw) {\r\n return null;\r\n }\r\n const drawManager = this.components.tools.get(DrawManager);\r\n if (!this._isDrawing) {\r\n this._isDrawing = true;\r\n this._previewElement.setStyle(drawManager.viewport.config);\r\n this._startPoint.set(e.clientX, e.clientY);\r\n this.svgViewport?.append(this._previewElement.get());\r\n }\r\n else {\r\n const rectangle = this._previewElement.clone();\r\n rectangle.setStyle(drawManager.viewport.config);\r\n this.svgViewport?.append(rectangle.get());\r\n this.cancel();\r\n return rectangle;\r\n }\r\n return null;\r\n };\r\n this.cancel = () => {\r\n if (!this._isDrawing) {\r\n return;\r\n }\r\n this._isDrawing = false;\r\n this._startPoint.x = 0;\r\n this._startPoint.y = 0;\r\n this._previewElement.reset();\r\n this._previewElement.get().remove();\r\n };\r\n this.draw = (e) => {\r\n if (!this.canDraw || !this._isDrawing) {\r\n return;\r\n }\r\n this._previewElement.x1 = this._startPoint.x;\r\n this._previewElement.y1 = this._startPoint.y;\r\n this._previewElement.x2 = e.clientX;\r\n this._previewElement.y2 = e.clientY;\r\n };\r\n this._previewElement = new SVGRectangle(components);\r\n const drawManager = this.components.tools.get(DrawManager);\r\n if (components.uiEnabled) {\r\n this.setUI();\r\n }\r\n drawManager.addDrawingTool(this.name, this);\r\n }\r\n setUI() {\r\n const drawManager = this.components.tools.get(DrawManager);\r\n const main = new Button(this.components);\r\n main.label = \"Rectangle\";\r\n main.materialIcon = \"crop_square\";\r\n main.onClick.add(() => {\r\n drawManager.activateTool(this);\r\n });\r\n this.uiElement.set({ main });\r\n }\r\n async dispose() {\r\n await super.dispose();\r\n this._previewElement.dispose();\r\n }\r\n}\r\n//# sourceMappingURL=index.js.map"],"names":["DrawManager","isDrawing","this","_isDrawing","value","enabled","_enabled","components","uiEnabled","uiElement","get","active","visible","viewport","constructor","super","name","onDisposed","drawingTools","drawings","tools","add","uuid","SimpleSVGViewport","setUI","dispose","remove","trigger","reset","saveDrawing","currentDrawing","childNodes","forEach","child","removeChild","drawing","getDrawing","group","document","createElementNS","id","append","addDrawingTool","tool","main","addChild","svgViewport","activateTool","Object","values","find","t","console","warn","activeTool","viewportToolbar","position","setTimeout","ui","addToolbar","materialIcon","onClick","set"],"sourceRoot":""}