@node-projects/web-component-designer 0.0.61 → 0.0.65
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/.vscode/settings.json +1 -1
- package/ACKNOWLEDGMENTS +7 -0
- package/dist/elements/controls/DesignerTabControl.js +4 -2
- package/dist/elements/controls/PlainScrollbar.d.ts +15 -0
- package/dist/elements/controls/PlainScrollbar.js +482 -0
- package/dist/elements/controls/SimpleSplitView.d.ts +11 -0
- package/dist/elements/controls/SimpleSplitView.js +67 -0
- package/dist/elements/controls/SimpleSplitView2.d.ts +11 -0
- package/dist/elements/controls/SimpleSplitView2.js +63 -0
- package/dist/elements/controls/aa.d.ts +24 -0
- package/dist/elements/controls/aa.js +98 -0
- package/dist/elements/documentContainer.d.ts +6 -1
- package/dist/elements/documentContainer.js +51 -14
- package/dist/elements/helper/PathDataPolyfill.d.ts +5 -1
- package/dist/elements/helper/PathDataPolyfill.js +49 -1
- package/dist/elements/helper/contextMenu/ContextMenuHelper.js +1 -0
- package/dist/elements/services/DefaultServiceBootstrap.js +8 -0
- package/dist/elements/services/htmlParserService/NodeHtmlParserService.js +2 -0
- package/dist/elements/services/undoService/UndoService.js +3 -0
- package/dist/elements/widgets/codeView/code-view-monaco.js +2 -2
- package/dist/elements/widgets/designerView/IDesignerCanvas.d.ts +4 -0
- package/dist/elements/widgets/designerView/designerCanvas.d.ts +8 -1
- package/dist/elements/widgets/designerView/designerCanvas.js +48 -22
- package/dist/elements/widgets/designerView/designerView.d.ts +2 -1
- package/dist/elements/widgets/designerView/designerView.js +68 -18
- package/dist/elements/widgets/designerView/extensions/MouseOverExtension.js +1 -1
- package/dist/elements/widgets/designerView/extensions/PositionExtension.js +4 -4
- package/dist/elements/widgets/designerView/extensions/PrimarySelectionDefaultExtension.js +2 -2
- package/dist/elements/widgets/designerView/extensions/ResizeExtension.d.ts +2 -1
- package/dist/elements/widgets/designerView/extensions/ResizeExtension.js +19 -15
- package/dist/elements/widgets/designerView/extensions/RotateExtension.js +1 -1
- package/dist/elements/widgets/designerView/extensions/SelectionDefaultExtension.js +1 -1
- package/dist/elements/widgets/designerView/extensions/TransformOriginExtension.js +2 -2
- package/dist/elements/widgets/designerView/overlayLayerView.d.ts +1 -0
- package/dist/elements/widgets/designerView/overlayLayerView.js +6 -0
- package/dist/elements/widgets/designerView/tools/DrawEllipsisTool.d.ts +13 -0
- package/dist/elements/widgets/designerView/tools/DrawEllipsisTool.js +72 -0
- package/dist/elements/widgets/designerView/tools/DrawLineTool.d.ts +13 -0
- package/dist/elements/widgets/designerView/tools/DrawLineTool.js +75 -0
- package/dist/elements/widgets/designerView/tools/DrawPathTool.d.ts +0 -2
- package/dist/elements/widgets/designerView/tools/DrawPathTool.js +5 -18
- package/dist/elements/widgets/designerView/tools/DrawRectTool.d.ts +18 -0
- package/dist/elements/widgets/designerView/tools/DrawRectTool.js +86 -0
- package/dist/elements/widgets/designerView/tools/NamedTools.d.ts +3 -0
- package/dist/elements/widgets/designerView/tools/NamedTools.js +3 -0
- package/dist/elements/widgets/designerView/tools/PanTool.js +14 -0
- package/dist/elements/widgets/designerView/tools/PointerTool.js +7 -0
- package/dist/elements/widgets/designerView/tools/RectangleSelectorTool.js +2 -2
- package/dist/elements/widgets/propertyGrid/PropertyGrid.js +1 -0
- package/dist/elements/widgets/propertyGrid/PropertyGridWithHeader.js +1 -0
- package/dist/elements/widgets/treeView/treeView.js +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/package.json +1 -1
|
@@ -3,6 +3,7 @@ import { DesignerCanvas } from "./designerCanvas.js";
|
|
|
3
3
|
import { DomConverter } from './DomConverter.js';
|
|
4
4
|
import { DefaultHtmlParserService } from '../../services/htmlParserService/DefaultHtmlParserService.js';
|
|
5
5
|
import { EventNames } from '../../../enums/EventNames.js';
|
|
6
|
+
const autoZomOffset = 10;
|
|
6
7
|
export class DesignerView extends BaseCustomWebComponentConstructorAppend {
|
|
7
8
|
get serviceContainer() {
|
|
8
9
|
return this._designerCanvas.serviceContainer;
|
|
@@ -16,6 +17,10 @@ export class DesignerView extends BaseCustomWebComponentConstructorAppend {
|
|
|
16
17
|
set instanceServiceContainer(value) {
|
|
17
18
|
this._designerCanvas.instanceServiceContainer = value;
|
|
18
19
|
}
|
|
20
|
+
_designerCanvas;
|
|
21
|
+
get designerCanvas() {
|
|
22
|
+
return this._designerCanvas;
|
|
23
|
+
}
|
|
19
24
|
_zoomInput;
|
|
20
25
|
_lowertoolbar;
|
|
21
26
|
static style = css `
|
|
@@ -82,24 +87,50 @@ export class DesignerView extends BaseCustomWebComponentConstructorAppend {
|
|
|
82
87
|
}
|
|
83
88
|
.snap-guide {
|
|
84
89
|
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAYVJREFUeNqkU7tKA1EQnbs3CnlVqbQNARMjFilS+AnZQhIbW0ER/AA/wlYbhXR2wUKx0iKNYGMKDViEdEIgieBujGvCPpyz7sK6iWLIwJk798zsuXsfIxzHoXksAqcoij+vMbYq7MoszGxaEB3wtODlH3i5E5uojck210RCgq7SJie4MC0TsdO1cim/lMmkwHdarZWni+t16/1jz/FElJBAGc5imLzyakXNG0IuVo+OnwHE4JCzgisG7BJu/I3CQjyRuq1dvWi6vg8gBofcOHgGAZO+AFv88/VNDofDEcd3IBCD43ycfhEowY28Sazfnzh1cKMggWsUQvi4waiqKuVyud16/d7JZrOHxWJxKudMuQV3C81mk3RdX0wmk9Tr9UxN06jb7dJgMPjBwQRUAu/AtWg0SpZl7TDSUso2/1UVNWHOMIwJARzWBhcQwMXu1oJb9Ufbtsk0zYktPLrvgD8E/mWeYoNxxlj2xoZ3qI2/YrePQs10PksjTRPozCog5m3nLwEGABrLzseuHT6IAAAAAElFTkSuQmCC);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.bottom-scroll {
|
|
93
|
+
width: calc(100% - 16px);
|
|
94
|
+
position: absolute;
|
|
95
|
+
bottom: 16px;
|
|
96
|
+
height: 16px;
|
|
97
|
+
box-sizing: border-box;
|
|
98
|
+
}
|
|
99
|
+
.right-scroll {
|
|
100
|
+
height: calc(100% - 32px);
|
|
101
|
+
position: absolute;
|
|
102
|
+
right: 0;
|
|
103
|
+
top: 0;
|
|
104
|
+
width: 16px;
|
|
105
|
+
box-sizing: border-box;
|
|
106
|
+
}
|
|
107
|
+
.bottom-right {
|
|
108
|
+
width: 16px;
|
|
109
|
+
height: 16px;
|
|
110
|
+
bottom: 16px;
|
|
111
|
+
right: 0;
|
|
112
|
+
position: absolute;
|
|
113
|
+
background: #f0f0f0;
|
|
85
114
|
}`;
|
|
86
115
|
static template = html `
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
116
|
+
<div id="outer">
|
|
117
|
+
<node-projects-plain-scrollbar value="0.5" class="bottom-scroll"></node-projects-plain-scrollbar>
|
|
118
|
+
<node-projects-plain-scrollbar value="0.5" orientation="vertical" class="right-scroll"></node-projects-plain-scrollbar>
|
|
119
|
+
<div class="bottom-right"></div>
|
|
120
|
+
<div id="lowertoolbar">
|
|
121
|
+
<input id="zoomInput" type="text" value="100%">
|
|
122
|
+
<div title="decrease zoom" id="zoomIncrease" class="toolbar-control zoom-in"></div>
|
|
123
|
+
<div title="increase zoom" id="zoomDecrease" class="toolbar-control zoom-out"></div>
|
|
124
|
+
<div title="reset zoom" id="zoomReset" class="toolbar-control"
|
|
125
|
+
style="width: 16px; height: 16px; font-size: 14px; display: flex; align-items: center; justify-content: center;">1
|
|
126
|
+
</div>
|
|
127
|
+
<div title="zoom to fit" id="zoomFit" class="toolbar-control"
|
|
128
|
+
style="width: 16px; height: 16px; font-size: 8px; display: flex; align-items: center; justify-content: center;">
|
|
129
|
+
100%</div>
|
|
130
|
+
<div title="snap to grid" id="alignGrid" class="toolbar-control snap-grid"></div>
|
|
131
|
+
<div title="snap to elements" id="alignSnap" class="toolbar-control snap-guide"></div>
|
|
132
|
+
</div>
|
|
133
|
+
</div>`;
|
|
103
134
|
constructor() {
|
|
104
135
|
super();
|
|
105
136
|
const outer = this._getDomElement('outer');
|
|
@@ -130,12 +161,30 @@ export class DesignerView extends BaseCustomWebComponentConstructorAppend {
|
|
|
130
161
|
};
|
|
131
162
|
let zoomReset = this._getDomElement('zoomReset');
|
|
132
163
|
zoomReset.onclick = () => {
|
|
164
|
+
this._designerCanvas.canvasOffset = { x: 0, y: 0 };
|
|
133
165
|
this._designerCanvas.zoomFactor = 1;
|
|
134
166
|
this._zoomInput.value = Math.round(this._designerCanvas.zoomFactor * 100) + '%';
|
|
135
167
|
};
|
|
136
168
|
let zoomFit = this._getDomElement('zoomFit');
|
|
137
169
|
zoomFit.onclick = () => {
|
|
138
|
-
|
|
170
|
+
let maxX = 0, maxY = 0, minX = 0, minY = 0;
|
|
171
|
+
this._designerCanvas.canvasOffset = { x: 0, y: 0 };
|
|
172
|
+
this._designerCanvas.zoomFactor = 1;
|
|
173
|
+
for (let n of DomHelper.getAllChildNodes(this.designerCanvas.rootDesignItem.element)) {
|
|
174
|
+
if (n instanceof Element) {
|
|
175
|
+
const rect = n.getBoundingClientRect();
|
|
176
|
+
minX = minX < rect.x ? minX : rect.x;
|
|
177
|
+
minY = minY < rect.y ? minY : rect.y;
|
|
178
|
+
maxX = maxX > rect.x + rect.width + autoZomOffset ? maxX : rect.x + rect.width + autoZomOffset;
|
|
179
|
+
maxY = maxY > rect.y + rect.height + autoZomOffset ? maxY : rect.y + rect.height + autoZomOffset;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const cvRect = this.designerCanvas.getBoundingClientRect();
|
|
183
|
+
maxX -= cvRect.x;
|
|
184
|
+
maxY -= cvRect.y;
|
|
185
|
+
let scaleX = cvRect.width / (maxX / this._designerCanvas.zoomFactor);
|
|
186
|
+
let scaleY = cvRect.height / (maxY / this._designerCanvas.zoomFactor);
|
|
187
|
+
this._designerCanvas.zoomFactor = scaleX < scaleY ? scaleX : scaleY;
|
|
139
188
|
this._zoomInput.value = Math.round(this._designerCanvas.zoomFactor * 100) + '%';
|
|
140
189
|
};
|
|
141
190
|
this.addEventListener(EventNames.Wheel, event => this._onWheel(event));
|
|
@@ -196,13 +245,14 @@ export class DesignerView extends BaseCustomWebComponentConstructorAppend {
|
|
|
196
245
|
}
|
|
197
246
|
}
|
|
198
247
|
getHTML(designItemsAssignmentList) {
|
|
199
|
-
this.instanceServiceContainer.selectionService.setSelectedElements(null);
|
|
248
|
+
//this.instanceServiceContainer.selectionService.setSelectedElements(null);
|
|
200
249
|
return DomConverter.ConvertToString([...this._designerCanvas.rootDesignItem.children()], designItemsAssignmentList);
|
|
201
250
|
}
|
|
202
251
|
async parseHTML(html) {
|
|
203
252
|
const parserService = this.serviceContainer.htmlParserService;
|
|
204
253
|
if (!html) {
|
|
205
254
|
this.instanceServiceContainer.undoService.clear();
|
|
255
|
+
this._designerCanvas.overlayLayer.removeAllOverlays();
|
|
206
256
|
DomHelper.removeAllChildnodes(this._designerCanvas.overlayLayer);
|
|
207
257
|
this._designerCanvas.rootDesignItem.clearChildren();
|
|
208
258
|
}
|
|
@@ -12,7 +12,7 @@ export class MouseOverExtension extends AbstractExtension {
|
|
|
12
12
|
let itemRect = this.extendedItem.element.getBoundingClientRect();
|
|
13
13
|
const xOffset = itemRect.x - this.designerCanvas.containerBoundingRect.x;
|
|
14
14
|
const yOffset = itemRect.y - this.designerCanvas.containerBoundingRect.y;
|
|
15
|
-
this._rect = this._drawRect(xOffset - offset, yOffset - offset, itemRect.width + offset + offset, itemRect.height + offset + offset, 'svg-hover', this._rect);
|
|
15
|
+
this._rect = this._drawRect((xOffset - offset) / this.designerCanvas.scaleFactor, (yOffset - offset) / this.designerCanvas.scaleFactor, (itemRect.width + offset + offset) / this.designerCanvas.scaleFactor, (itemRect.height + offset + offset) / this.designerCanvas.scaleFactor, 'svg-hover', this._rect);
|
|
16
16
|
}
|
|
17
17
|
dispose() {
|
|
18
18
|
this._removeAllOverlays();
|
|
@@ -34,10 +34,10 @@ export class PositionExtension extends AbstractExtension {
|
|
|
34
34
|
tx = Number.parseFloat(transforms[4]);
|
|
35
35
|
ty = Number.parseFloat(transforms[5].replace(')', ''));
|
|
36
36
|
}
|
|
37
|
-
this._line1 = this._drawLine(xOffset - left - tx, yOffset + itemRect.height / 2, xOffset, yOffset + itemRect.height / 2, 'svg-position', this._line1);
|
|
38
|
-
this._line2 = this._drawLine(xOffset + itemRect.width / 2, yOffset - top - ty, xOffset + itemRect.width / 2, yOffset, 'svg-position', this._line2);
|
|
39
|
-
this._line3 = this._drawLine(xOffset + itemRect.width, yOffset + itemRect.height / 2, xOffset + itemRect.width + right + -1 * tx, yOffset + itemRect.height / 2, 'svg-position', this._line3);
|
|
40
|
-
this._line4 = this._drawLine(xOffset + itemRect.width / 2, yOffset + itemRect.height, xOffset + itemRect.width / 2, yOffset + itemRect.height + bottom + -1 * ty, 'svg-position', this._line4);
|
|
37
|
+
this._line1 = this._drawLine((xOffset / this.designerCanvas.scaleFactor - left - tx), (yOffset + itemRect.height / 2) / this.designerCanvas.scaleFactor, xOffset / this.designerCanvas.scaleFactor, (yOffset + itemRect.height / 2) / this.designerCanvas.scaleFactor, 'svg-position', this._line1);
|
|
38
|
+
this._line2 = this._drawLine((xOffset + itemRect.width / 2) / this.designerCanvas.scaleFactor, (yOffset / this.designerCanvas.scaleFactor) - top - ty, (xOffset + itemRect.width / 2) / this.designerCanvas.scaleFactor, yOffset / this.designerCanvas.scaleFactor, 'svg-position', this._line2);
|
|
39
|
+
this._line3 = this._drawLine((xOffset + itemRect.width) / this.designerCanvas.scaleFactor, (yOffset + itemRect.height / 2) / this.designerCanvas.scaleFactor, (xOffset + itemRect.width + right + -1 * tx) / this.designerCanvas.scaleFactor, (yOffset + itemRect.height / 2) / this.designerCanvas.scaleFactor, 'svg-position', this._line3);
|
|
40
|
+
this._line4 = this._drawLine((xOffset + itemRect.width / 2) / this.designerCanvas.scaleFactor, (yOffset + itemRect.height) / this.designerCanvas.scaleFactor, (xOffset + itemRect.width / 2) / this.designerCanvas.scaleFactor, (yOffset + itemRect.height + bottom + -1 * ty) / this.designerCanvas.scaleFactor, 'svg-position', this._line4);
|
|
41
41
|
}
|
|
42
42
|
dispose() {
|
|
43
43
|
this._removeAllOverlays();
|
|
@@ -12,8 +12,8 @@ export class PrimarySelectionDefaultExtension extends AbstractExtension {
|
|
|
12
12
|
}
|
|
13
13
|
refresh() {
|
|
14
14
|
const boundRect = this.extendedItem.element.getBoundingClientRect();
|
|
15
|
-
this._rect = this._drawRect(boundRect.x - this.designerCanvas.containerBoundingRect.x, boundRect.y - this.designerCanvas.containerBoundingRect.y - 16, 60, 15, 'svg-primary-selection-move', this._rect);
|
|
16
|
-
this._text = this._drawText(this.extendedItem.name.substring(0, 10) + '…', boundRect.x - this.designerCanvas.containerBoundingRect.x, boundRect.y - this.designerCanvas.containerBoundingRect.y - 5, 'svg-text-primary', this._text);
|
|
15
|
+
this._rect = this._drawRect((boundRect.x - this.designerCanvas.containerBoundingRect.x) / this.designerCanvas.scaleFactor, (boundRect.y - this.designerCanvas.containerBoundingRect.y) / this.designerCanvas.scaleFactor - 16, 60, 15, 'svg-primary-selection-move', this._rect);
|
|
16
|
+
this._text = this._drawText(this.extendedItem.name.substring(0, 10) + '…', (boundRect.x - this.designerCanvas.containerBoundingRect.x) / this.designerCanvas.scaleFactor, (boundRect.y - this.designerCanvas.containerBoundingRect.y) / this.designerCanvas.scaleFactor - 5, 'svg-text-primary', this._text);
|
|
17
17
|
}
|
|
18
18
|
dispose() {
|
|
19
19
|
this._removeAllOverlays();
|
|
@@ -7,6 +7,7 @@ export declare class ResizeExtension extends AbstractExtension {
|
|
|
7
7
|
private _initialSizes;
|
|
8
8
|
private _actionModeStarted;
|
|
9
9
|
private _initialPoint;
|
|
10
|
+
private _offsetPoint;
|
|
10
11
|
private _circle1;
|
|
11
12
|
private _circle2;
|
|
12
13
|
private _circle3;
|
|
@@ -19,6 +20,6 @@ export declare class ResizeExtension extends AbstractExtension {
|
|
|
19
20
|
extend(): void;
|
|
20
21
|
refresh(): void;
|
|
21
22
|
_drawResizerOverlay(x: number, y: number, cursor: string, oldCircle?: SVGCircleElement): SVGCircleElement;
|
|
22
|
-
_pointerActionTypeResize(event: PointerEvent, actionMode?: string): void;
|
|
23
|
+
_pointerActionTypeResize(circle: SVGCircleElement, event: PointerEvent, actionMode?: string): void;
|
|
23
24
|
dispose(): void;
|
|
24
25
|
}
|
|
@@ -5,6 +5,7 @@ export class ResizeExtension extends AbstractExtension {
|
|
|
5
5
|
_initialSizes;
|
|
6
6
|
_actionModeStarted;
|
|
7
7
|
_initialPoint;
|
|
8
|
+
_offsetPoint;
|
|
8
9
|
_circle1;
|
|
9
10
|
_circle2;
|
|
10
11
|
_circle3;
|
|
@@ -21,14 +22,14 @@ export class ResizeExtension extends AbstractExtension {
|
|
|
21
22
|
}
|
|
22
23
|
refresh() {
|
|
23
24
|
const rect = this.extendedItem.element.getBoundingClientRect();
|
|
24
|
-
this._circle1 = this._drawResizerOverlay(rect.x - this.designerCanvas.containerBoundingRect.x, rect.y - this.designerCanvas.containerBoundingRect.y, 'nw-resize', this._circle1);
|
|
25
|
-
this._circle2 = this._drawResizerOverlay(rect.x + (rect.width / 2) - this.designerCanvas.containerBoundingRect.x, rect.y - this.designerCanvas.containerBoundingRect.y, 'n-resize', this._circle2);
|
|
26
|
-
this._circle3 = this._drawResizerOverlay(rect.x + rect.width - this.designerCanvas.containerBoundingRect.x, rect.y - this.designerCanvas.containerBoundingRect.y, 'ne-resize', this._circle3);
|
|
27
|
-
this._circle4 = this._drawResizerOverlay(rect.x - this.designerCanvas.containerBoundingRect.x, rect.y + rect.height - this.designerCanvas.containerBoundingRect.y, 'sw-resize', this._circle4);
|
|
28
|
-
this._circle5 = this._drawResizerOverlay(rect.x + (rect.width / 2) - this.designerCanvas.containerBoundingRect.x, rect.y + rect.height - this.designerCanvas.containerBoundingRect.y, 's-resize', this._circle5);
|
|
29
|
-
this._circle6 = this._drawResizerOverlay(rect.x + rect.width - this.designerCanvas.containerBoundingRect.x, rect.y + rect.height - this.designerCanvas.containerBoundingRect.y, 'se-resize', this._circle6);
|
|
30
|
-
this._circle7 = this._drawResizerOverlay(rect.x - this.designerCanvas.containerBoundingRect.x, rect.y + (rect.height / 2) - this.designerCanvas.containerBoundingRect.y, 'w-resize', this._circle7);
|
|
31
|
-
this._circle8 = this._drawResizerOverlay(rect.x + rect.width - this.designerCanvas.containerBoundingRect.x, rect.y + (rect.height / 2) - this.designerCanvas.containerBoundingRect.y, 'e-resize', this._circle8);
|
|
25
|
+
this._circle1 = this._drawResizerOverlay((rect.x - this.designerCanvas.containerBoundingRect.x) / this.designerCanvas.scaleFactor, (rect.y - this.designerCanvas.containerBoundingRect.y) / this.designerCanvas.scaleFactor, 'nw-resize', this._circle1);
|
|
26
|
+
this._circle2 = this._drawResizerOverlay((rect.x + (rect.width / 2) - this.designerCanvas.containerBoundingRect.x) / this.designerCanvas.scaleFactor, (rect.y - this.designerCanvas.containerBoundingRect.y) / this.designerCanvas.scaleFactor, 'n-resize', this._circle2);
|
|
27
|
+
this._circle3 = this._drawResizerOverlay((rect.x + rect.width - this.designerCanvas.containerBoundingRect.x) / this.designerCanvas.scaleFactor, (rect.y - this.designerCanvas.containerBoundingRect.y) / this.designerCanvas.scaleFactor, 'ne-resize', this._circle3);
|
|
28
|
+
this._circle4 = this._drawResizerOverlay((rect.x - this.designerCanvas.containerBoundingRect.x) / this.designerCanvas.scaleFactor, (rect.y + rect.height - this.designerCanvas.containerBoundingRect.y) / this.designerCanvas.scaleFactor, 'sw-resize', this._circle4);
|
|
29
|
+
this._circle5 = this._drawResizerOverlay((rect.x + (rect.width / 2) - this.designerCanvas.containerBoundingRect.x) / this.designerCanvas.scaleFactor, (rect.y + rect.height - this.designerCanvas.containerBoundingRect.y) / this.designerCanvas.scaleFactor, 's-resize', this._circle5);
|
|
30
|
+
this._circle6 = this._drawResizerOverlay((rect.x + rect.width - this.designerCanvas.containerBoundingRect.x) / this.designerCanvas.scaleFactor, (rect.y + rect.height - this.designerCanvas.containerBoundingRect.y) / this.designerCanvas.scaleFactor, 'se-resize', this._circle6);
|
|
31
|
+
this._circle7 = this._drawResizerOverlay((rect.x - this.designerCanvas.containerBoundingRect.x) / this.designerCanvas.scaleFactor, (rect.y + (rect.height / 2) - this.designerCanvas.containerBoundingRect.y) / this.designerCanvas.scaleFactor, 'w-resize', this._circle7);
|
|
32
|
+
this._circle8 = this._drawResizerOverlay((rect.x + rect.width - this.designerCanvas.containerBoundingRect.x) / this.designerCanvas.scaleFactor, (rect.y + (rect.height / 2) - this.designerCanvas.containerBoundingRect.y) / this.designerCanvas.scaleFactor, 'e-resize', this._circle8);
|
|
32
33
|
if (rect.width < 12) {
|
|
33
34
|
this._circle2.style.display = 'none';
|
|
34
35
|
this._circle5.style.display = 'none';
|
|
@@ -49,25 +50,28 @@ export class ResizeExtension extends AbstractExtension {
|
|
|
49
50
|
_drawResizerOverlay(x, y, cursor, oldCircle) {
|
|
50
51
|
let circle = this._drawCircle(x, y, 3, 'svg-primary-resizer', oldCircle);
|
|
51
52
|
if (!oldCircle) {
|
|
52
|
-
circle.addEventListener(EventNames.PointerDown, event => this._pointerActionTypeResize(event, cursor));
|
|
53
|
-
circle.addEventListener(EventNames.PointerMove, event => this._pointerActionTypeResize(event, cursor));
|
|
54
|
-
circle.addEventListener(EventNames.PointerUp, event => this._pointerActionTypeResize(event, cursor));
|
|
53
|
+
circle.addEventListener(EventNames.PointerDown, event => this._pointerActionTypeResize(circle, event, cursor));
|
|
54
|
+
circle.addEventListener(EventNames.PointerMove, event => this._pointerActionTypeResize(circle, event, cursor));
|
|
55
|
+
circle.addEventListener(EventNames.PointerUp, event => this._pointerActionTypeResize(circle, event, cursor));
|
|
55
56
|
}
|
|
56
57
|
circle.setAttribute('style', 'cursor: ' + cursor);
|
|
57
58
|
return circle;
|
|
58
59
|
}
|
|
59
|
-
_pointerActionTypeResize(event, actionMode = 'se-resize') {
|
|
60
|
+
_pointerActionTypeResize(circle, event, actionMode = 'se-resize') {
|
|
60
61
|
event.stopPropagation();
|
|
61
62
|
const currentPoint = this.designerCanvas.getNormalizedEventCoordinates(event); //, this.extendedItem.element, event.type === 'pointerdown' ? null : this._initialPoint);
|
|
62
63
|
switch (event.type) {
|
|
63
64
|
case EventNames.PointerDown:
|
|
65
|
+
const cx = parseFloat(circle.getAttribute('cx'));
|
|
66
|
+
const cy = parseFloat(circle.getAttribute('cy'));
|
|
67
|
+
this._offsetPoint = { x: cx - currentPoint.x, y: cy - currentPoint.y };
|
|
64
68
|
event.target.setPointerCapture(event.pointerId);
|
|
65
69
|
this._initialPoint = currentPoint;
|
|
66
70
|
this._initialSizes = [];
|
|
67
71
|
this._actionModeStarted = actionMode;
|
|
68
72
|
for (const designItem of this.designerCanvas.instanceServiceContainer.selectionService.selectedElements) {
|
|
69
73
|
let rect = designItem.element.getBoundingClientRect();
|
|
70
|
-
this._initialSizes.push({ width: rect.width, height: rect.height });
|
|
74
|
+
this._initialSizes.push({ width: rect.width / this.designerCanvas.scaleFactor, height: rect.height / this.designerCanvas.scaleFactor });
|
|
71
75
|
}
|
|
72
76
|
if (this.designerCanvas.alignOnSnap)
|
|
73
77
|
this.designerCanvas.snapLines.calculateSnaplines(this.designerCanvas.instanceServiceContainer.selectionService.selectedElements);
|
|
@@ -77,8 +81,8 @@ export class ResizeExtension extends AbstractExtension {
|
|
|
77
81
|
const containerStyle = getComputedStyle(this.extendedItem.parent.element);
|
|
78
82
|
const containerService = this.designerCanvas.serviceContainer.getLastServiceWhere('containerService', x => x.serviceForContainer(this.extendedItem.parent, containerStyle));
|
|
79
83
|
const diff = containerService.placePoint(event, this.designerCanvas, this.extendedItem.parent, this._initialPoint, { x: 0, y: 0 }, currentPoint, this.designerCanvas.instanceServiceContainer.selectionService.selectedElements);
|
|
80
|
-
let trackX = diff.x - this._initialPoint.x;
|
|
81
|
-
let trackY = diff.y - this._initialPoint.y;
|
|
84
|
+
let trackX = diff.x - this._initialPoint.x - this._offsetPoint.x;
|
|
85
|
+
let trackY = diff.y - this._initialPoint.y - this._offsetPoint.y;
|
|
82
86
|
let i = 0;
|
|
83
87
|
switch (this._actionModeStarted) {
|
|
84
88
|
case 'se-resize':
|
|
@@ -26,7 +26,7 @@ export class RotateExtension extends AbstractExtension {
|
|
|
26
26
|
g.addEventListener(EventNames.PointerMove, event => this._pointerActionTypeRotate(event));
|
|
27
27
|
g.addEventListener(EventNames.PointerUp, event => this._pointerActionTypeRotate(event));
|
|
28
28
|
g.setAttribute('class', 'svg-primary-rotate');
|
|
29
|
-
g.setAttribute('transform', 'translate(' + (itemRect.x - this.designerCanvas.containerBoundingRect.x - 13) + ',' + (itemRect.y - this.designerCanvas.containerBoundingRect.y - 8.5) + ')');
|
|
29
|
+
g.setAttribute('transform', 'translate(' + ((itemRect.x - this.designerCanvas.containerBoundingRect.x) / this.designerCanvas.scaleFactor - 13) + ',' + ((itemRect.y - this.designerCanvas.containerBoundingRect.y) / this.designerCanvas.scaleFactor - 8.5) + ')');
|
|
30
30
|
this.overlayLayerView.addOverlay(g);
|
|
31
31
|
this.overlays.push(g);
|
|
32
32
|
}
|
|
@@ -14,7 +14,7 @@ export class SelectionDefaultExtension extends AbstractExtension {
|
|
|
14
14
|
const top = Number.parseFloat(computedStyle.marginTop.replace('px', ''));
|
|
15
15
|
const right = Number.parseFloat(computedStyle.marginRight.replace('px', ''));
|
|
16
16
|
const bottom = Number.parseFloat(computedStyle.marginBottom.replace('px', ''));
|
|
17
|
-
this._rect = this._drawRect(itemRect.x - this.designerCanvas.containerBoundingRect.x - left, itemRect.y - this.designerCanvas.containerBoundingRect.y - top, left + itemRect.width + right, top + itemRect.height + bottom, 'svg-selection', this._rect);
|
|
17
|
+
this._rect = this._drawRect((itemRect.x - this.designerCanvas.containerBoundingRect.x - left) / this.designerCanvas.scaleFactor, (itemRect.y - this.designerCanvas.containerBoundingRect.y - top) / this.designerCanvas.scaleFactor, (left + itemRect.width + right) / this.designerCanvas.scaleFactor, (top + itemRect.height + bottom) / this.designerCanvas.scaleFactor, 'svg-selection', this._rect);
|
|
18
18
|
}
|
|
19
19
|
dispose() {
|
|
20
20
|
this._removeAllOverlays();
|
|
@@ -11,9 +11,9 @@ export class TransformOriginExtension extends AbstractExtension {
|
|
|
11
11
|
const rect = this.extendedItem.element.getBoundingClientRect();
|
|
12
12
|
const computed = getComputedStyle(this.extendedItem.element);
|
|
13
13
|
const to = computed.transformOrigin.split(' ');
|
|
14
|
-
this._circle = this._drawCircle(rect.x - this.designerCanvas.containerBoundingRect.x + Number.parseFloat(to[0].replace('px', '')), rect.y - this.designerCanvas.containerBoundingRect.y + Number.parseFloat(to[1].replace('px', '')), 5, 'svg-transform-origin');
|
|
14
|
+
this._circle = this._drawCircle((rect.x - this.designerCanvas.containerBoundingRect.x) / this.designerCanvas.scaleFactor + Number.parseFloat(to[0].replace('px', '')), (rect.y - this.designerCanvas.containerBoundingRect.y) / this.designerCanvas.scaleFactor + Number.parseFloat(to[1].replace('px', '')), 5, 'svg-transform-origin');
|
|
15
15
|
this._circle.setAttribute('style', 'cursor: pointer');
|
|
16
|
-
this._circle2 = this._drawCircle(rect.x - this.designerCanvas.containerBoundingRect.x + Number.parseFloat(to[0].replace('px', '')), rect.y - this.designerCanvas.containerBoundingRect.y + Number.parseFloat(to[1].replace('px', '')), 1, 'svg-transform-origin');
|
|
16
|
+
this._circle2 = this._drawCircle((rect.x - this.designerCanvas.containerBoundingRect.x) / this.designerCanvas.scaleFactor + Number.parseFloat(to[0].replace('px', '')), (rect.y - this.designerCanvas.containerBoundingRect.y) / this.designerCanvas.scaleFactor + Number.parseFloat(to[1].replace('px', '')), 1, 'svg-transform-origin');
|
|
17
17
|
this._circle2.setAttribute('style', 'pointer-events: none');
|
|
18
18
|
this._circle.addEventListener(EventNames.PointerDown, event => this.pointerEvent(event));
|
|
19
19
|
this._circle.addEventListener(EventNames.PointerMove, event => this.pointerEvent(event));
|
|
@@ -15,6 +15,7 @@ export declare class OverlayLayerView extends BaseCustomWebComponentConstructorA
|
|
|
15
15
|
addOverlay(element: SVGGraphicsElement, overlayLayer?: OverlayLayer): void;
|
|
16
16
|
removeOverlay(element: SVGGraphicsElement): void;
|
|
17
17
|
removeAllNodesWithClass(className: string): void;
|
|
18
|
+
removeAllOverlays(): void;
|
|
18
19
|
createPoint(): DOMPointInit;
|
|
19
20
|
elementFromPoint(x: number, y: number): Element;
|
|
20
21
|
drawLine(x1: number, y1: number, x2: number, y2: number, className?: string, line?: SVGLineElement, overlayLayer?: OverlayLayer): SVGLineElement;
|
|
@@ -80,6 +80,12 @@ export class OverlayLayerView extends BaseCustomWebComponentConstructorAppend {
|
|
|
80
80
|
e.parentNode.removeChild(e);
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
+
removeAllOverlays() {
|
|
84
|
+
const nodes = this._svg.querySelectorAll('svg > g > *');
|
|
85
|
+
for (const e of nodes) {
|
|
86
|
+
e.parentNode.removeChild(e);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
83
89
|
createPoint() {
|
|
84
90
|
//@ts-ignore
|
|
85
91
|
return this._svg.createSVGPoint();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IDesignerCanvas } from '../IDesignerCanvas';
|
|
2
|
+
import { ITool } from './ITool';
|
|
3
|
+
import { ServiceContainer } from '../../../services/ServiceContainer.js';
|
|
4
|
+
export declare class DrawEllipsisTool implements ITool {
|
|
5
|
+
readonly cursor = "crosshair";
|
|
6
|
+
private _path;
|
|
7
|
+
private _startPoint;
|
|
8
|
+
private _radius;
|
|
9
|
+
constructor();
|
|
10
|
+
activated(serviceContainer: ServiceContainer): void;
|
|
11
|
+
dispose(): void;
|
|
12
|
+
pointerEventHandler(designerCanvas: IDesignerCanvas, event: PointerEvent, currentElement: Element): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { EventNames } from '../../../../enums/EventNames';
|
|
2
|
+
import { OverlayLayer } from '../extensions/OverlayLayer.js';
|
|
3
|
+
import { calculateNormLegth } from '../../../helper/PathDataPolyfill';
|
|
4
|
+
import { DesignItem } from '../../../item/DesignItem';
|
|
5
|
+
import { InsertAction } from '../../../services/undoService/transactionItems/InsertAction';
|
|
6
|
+
export class DrawEllipsisTool {
|
|
7
|
+
cursor = 'crosshair';
|
|
8
|
+
_path;
|
|
9
|
+
_startPoint;
|
|
10
|
+
_radius;
|
|
11
|
+
constructor() {
|
|
12
|
+
}
|
|
13
|
+
activated(serviceContainer) {
|
|
14
|
+
}
|
|
15
|
+
dispose() {
|
|
16
|
+
}
|
|
17
|
+
pointerEventHandler(designerCanvas, event, currentElement) {
|
|
18
|
+
const currentPoint = designerCanvas.getNormalizedEventCoordinates(event);
|
|
19
|
+
const offset = 50;
|
|
20
|
+
switch (event.type) {
|
|
21
|
+
case EventNames.PointerDown:
|
|
22
|
+
this._startPoint = currentPoint;
|
|
23
|
+
event.target.setPointerCapture(event.pointerId);
|
|
24
|
+
this._path = document.createElementNS("http://www.w3.org/2000/svg", "ellipse");
|
|
25
|
+
this._path.setAttribute("stroke", designerCanvas.serviceContainer.globalContext.strokeColor);
|
|
26
|
+
this._path.setAttribute("fill", designerCanvas.serviceContainer.globalContext.fillBrush);
|
|
27
|
+
this._path.setAttribute("stroke-width", designerCanvas.serviceContainer.globalContext.strokeThickness);
|
|
28
|
+
this._path.setAttribute("cx", currentPoint.x.toString());
|
|
29
|
+
this._path.setAttribute("cy", currentPoint.y.toString());
|
|
30
|
+
this._path.setAttribute("rx", "0");
|
|
31
|
+
this._path.setAttribute("ry", "0");
|
|
32
|
+
designerCanvas.overlayLayer.addOverlay(this._path, OverlayLayer.Foregorund);
|
|
33
|
+
break;
|
|
34
|
+
case EventNames.PointerMove:
|
|
35
|
+
if (this._path) {
|
|
36
|
+
this._radius = { x: Math.abs(currentPoint.x - this._startPoint.x), y: Math.abs(currentPoint.y - this._startPoint.y) };
|
|
37
|
+
this._path.setAttribute("cx", this._startPoint.x.toString());
|
|
38
|
+
this._path.setAttribute("cy", this._startPoint.y.toString());
|
|
39
|
+
if (event.shiftKey) {
|
|
40
|
+
const radius = calculateNormLegth(this._startPoint, currentPoint);
|
|
41
|
+
this._path.setAttribute("rx", radius.toString());
|
|
42
|
+
this._path.setAttribute("ry", radius.toString());
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
this._path.setAttribute("rx", this._radius.x.toString());
|
|
46
|
+
this._path.setAttribute("ry", this._radius.y.toString());
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
break;
|
|
50
|
+
case EventNames.PointerUp:
|
|
51
|
+
event.target.releasePointerCapture(event.pointerId);
|
|
52
|
+
const rect = this._path.getBoundingClientRect();
|
|
53
|
+
designerCanvas.overlayLayer.removeOverlay(this._path);
|
|
54
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
55
|
+
const mvX = rect.x - designerCanvas.containerBoundingRect.x - offset;
|
|
56
|
+
const mvY = rect.y - designerCanvas.containerBoundingRect.y - offset;
|
|
57
|
+
svg.appendChild(this._path);
|
|
58
|
+
this._path.setAttribute("cx", (this._startPoint.x - mvX).toString());
|
|
59
|
+
this._path.setAttribute("cy", (this._startPoint.y - mvY).toString());
|
|
60
|
+
svg.style.left = (mvX) + 'px';
|
|
61
|
+
svg.style.top = (mvY) + 'px';
|
|
62
|
+
svg.style.position = 'absolute';
|
|
63
|
+
svg.style.width = (rect.width + 2 * offset) + 'px';
|
|
64
|
+
svg.style.height = (rect.height + 2 * offset) + 'px';
|
|
65
|
+
this._path = null;
|
|
66
|
+
const di = DesignItem.createDesignItemFromInstance(svg, designerCanvas.serviceContainer, designerCanvas.instanceServiceContainer);
|
|
67
|
+
designerCanvas.instanceServiceContainer.undoService.execute(new InsertAction(designerCanvas.rootDesignItem, designerCanvas.rootDesignItem.childCount, di));
|
|
68
|
+
designerCanvas.serviceContainer.globalContext.finishedWithTool(this);
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IDesignerCanvas } from '../IDesignerCanvas';
|
|
2
|
+
import { ITool } from './ITool';
|
|
3
|
+
import { ServiceContainer } from '../../../services/ServiceContainer.js';
|
|
4
|
+
export declare class DrawLineTool implements ITool {
|
|
5
|
+
readonly cursor = "crosshair";
|
|
6
|
+
private _path;
|
|
7
|
+
private _startPoint;
|
|
8
|
+
private _endPoint;
|
|
9
|
+
constructor();
|
|
10
|
+
activated(serviceContainer: ServiceContainer): void;
|
|
11
|
+
dispose(): void;
|
|
12
|
+
pointerEventHandler(designerCanvas: IDesignerCanvas, event: PointerEvent, currentElement: Element): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { EventNames } from '../../../../enums/EventNames';
|
|
2
|
+
import { OverlayLayer } from '../extensions/OverlayLayer.js';
|
|
3
|
+
import { straightenLine } from '../../../helper/PathDataPolyfill';
|
|
4
|
+
import { DesignItem } from '../../../item/DesignItem';
|
|
5
|
+
import { InsertAction } from '../../../services/undoService/transactionItems/InsertAction';
|
|
6
|
+
export class DrawLineTool {
|
|
7
|
+
cursor = 'crosshair';
|
|
8
|
+
_path;
|
|
9
|
+
_startPoint;
|
|
10
|
+
_endPoint;
|
|
11
|
+
constructor() {
|
|
12
|
+
}
|
|
13
|
+
activated(serviceContainer) {
|
|
14
|
+
}
|
|
15
|
+
dispose() {
|
|
16
|
+
}
|
|
17
|
+
pointerEventHandler(designerCanvas, event, currentElement) {
|
|
18
|
+
const currentPoint = designerCanvas.getNormalizedEventCoordinates(event);
|
|
19
|
+
const offset = 50;
|
|
20
|
+
switch (event.type) {
|
|
21
|
+
case EventNames.PointerDown:
|
|
22
|
+
this._startPoint = currentPoint;
|
|
23
|
+
event.target.setPointerCapture(event.pointerId);
|
|
24
|
+
this._path = document.createElementNS("http://www.w3.org/2000/svg", "line");
|
|
25
|
+
// this._pathD = "M" + currentPoint.x + " " + currentPoint.y;
|
|
26
|
+
// this._path.setAttribute("d", this._pathD);
|
|
27
|
+
this._path.setAttribute("stroke", designerCanvas.serviceContainer.globalContext.strokeColor);
|
|
28
|
+
this._path.setAttribute("stroke-width", designerCanvas.serviceContainer.globalContext.strokeThickness);
|
|
29
|
+
this._path.setAttribute("x1", currentPoint.x.toString());
|
|
30
|
+
this._path.setAttribute("y1", currentPoint.y.toString());
|
|
31
|
+
this._path.setAttribute("x2", currentPoint.x.toString());
|
|
32
|
+
this._path.setAttribute("y2", currentPoint.y.toString());
|
|
33
|
+
designerCanvas.overlayLayer.addOverlay(this._path, OverlayLayer.Foregorund);
|
|
34
|
+
break;
|
|
35
|
+
case EventNames.PointerMove:
|
|
36
|
+
if (this._path) {
|
|
37
|
+
if (event.shiftKey) {
|
|
38
|
+
let straightLine = straightenLine(this._startPoint, currentPoint);
|
|
39
|
+
this._path.setAttribute("x2", straightLine.x.toString());
|
|
40
|
+
this._path.setAttribute("y2", straightLine.y.toString());
|
|
41
|
+
this._endPoint = straightLine;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
//this._path.setAttribute("d", this._pathD + "L" + currentPoint.x + " " + currentPoint.y);
|
|
45
|
+
this._path.setAttribute("x2", currentPoint.x.toString());
|
|
46
|
+
this._path.setAttribute("y2", currentPoint.y.toString());
|
|
47
|
+
this._endPoint = currentPoint;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
break;
|
|
51
|
+
case EventNames.PointerUp:
|
|
52
|
+
event.target.releasePointerCapture(event.pointerId);
|
|
53
|
+
const rect = this._path.getBoundingClientRect();
|
|
54
|
+
designerCanvas.overlayLayer.removeOverlay(this._path);
|
|
55
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
56
|
+
const mvX = rect.x - designerCanvas.containerBoundingRect.x - offset;
|
|
57
|
+
const mvY = rect.y - designerCanvas.containerBoundingRect.y - offset;
|
|
58
|
+
this._path.setAttribute("x1", (this._startPoint.x - mvX).toString());
|
|
59
|
+
this._path.setAttribute("y1", (this._startPoint.y - mvY).toString());
|
|
60
|
+
this._path.setAttribute("x2", (this._endPoint.x - mvX).toString());
|
|
61
|
+
this._path.setAttribute("y2", (this._endPoint.y - mvY).toString());
|
|
62
|
+
svg.appendChild(this._path);
|
|
63
|
+
svg.style.left = (mvX) + 'px';
|
|
64
|
+
svg.style.top = (mvY) + 'px';
|
|
65
|
+
svg.style.position = 'absolute';
|
|
66
|
+
svg.style.width = (rect.width + 2 * offset) + 'px';
|
|
67
|
+
svg.style.height = (rect.height + 2 * offset) + 'px';
|
|
68
|
+
this._path = null;
|
|
69
|
+
const di = DesignItem.createDesignItemFromInstance(svg, designerCanvas.serviceContainer, designerCanvas.instanceServiceContainer);
|
|
70
|
+
designerCanvas.instanceServiceContainer.undoService.execute(new InsertAction(designerCanvas.rootDesignItem, designerCanvas.rootDesignItem.childCount, di));
|
|
71
|
+
designerCanvas.serviceContainer.globalContext.finishedWithTool(this);
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { IDesignerCanvas } from '../IDesignerCanvas';
|
|
2
2
|
import { ITool } from './ITool';
|
|
3
3
|
import { ServiceContainer } from '../../../services/ServiceContainer.js';
|
|
4
|
-
import { IPoint } from '../../../..';
|
|
5
4
|
export declare class DrawPathTool implements ITool {
|
|
6
5
|
readonly cursor = "crosshair";
|
|
7
6
|
private _pathD;
|
|
@@ -17,5 +16,4 @@ export declare class DrawPathTool implements ITool {
|
|
|
17
16
|
activated(serviceContainer: ServiceContainer): void;
|
|
18
17
|
dispose(): void;
|
|
19
18
|
pointerEventHandler(designerCanvas: IDesignerCanvas, event: PointerEvent, currentElement: Element): void;
|
|
20
|
-
straightenLine(p1: IPoint, p2: IPoint): IPoint;
|
|
21
19
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EventNames } from '../../../../enums/EventNames';
|
|
2
|
-
import {
|
|
2
|
+
import { moveSVGPath, straightenLine } from '../../../helper/PathDataPolyfill';
|
|
3
3
|
import { InsertAction } from '../../../services/undoService/transactionItems/InsertAction';
|
|
4
4
|
import { DesignItem } from '../../../item/DesignItem';
|
|
5
5
|
import { OverlayLayer } from '../extensions/OverlayLayer.js';
|
|
@@ -30,7 +30,7 @@ export class DrawPathTool {
|
|
|
30
30
|
event.target.setPointerCapture(event.pointerId);
|
|
31
31
|
this._path = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
32
32
|
this._pathD = "M" + currentPoint.x + " " + currentPoint.y;
|
|
33
|
-
this._path.setAttribute("
|
|
33
|
+
this._path.setAttribute("d", this._pathD);
|
|
34
34
|
this._path.setAttribute("stroke", designerCanvas.serviceContainer.globalContext.strokeColor);
|
|
35
35
|
this._path.setAttribute("fill", designerCanvas.serviceContainer.globalContext.fillBrush);
|
|
36
36
|
this._path.setAttribute("stroke-width", designerCanvas.serviceContainer.globalContext.strokeThickness);
|
|
@@ -56,7 +56,7 @@ export class DrawPathTool {
|
|
|
56
56
|
if (this._path) {
|
|
57
57
|
let straightLine = currentPoint;
|
|
58
58
|
if (event.shiftKey)
|
|
59
|
-
straightLine =
|
|
59
|
+
straightLine = straightenLine(this._savedPoint, currentPoint);
|
|
60
60
|
this._path.setAttribute("d", this._pathD + "L" + straightLine.x + " " + straightLine.y);
|
|
61
61
|
}
|
|
62
62
|
}
|
|
@@ -69,7 +69,7 @@ export class DrawPathTool {
|
|
|
69
69
|
if (this._p2pMode && !this._samePoint) {
|
|
70
70
|
if (this._path) {
|
|
71
71
|
if (event.shiftKey) {
|
|
72
|
-
let straightLine =
|
|
72
|
+
let straightLine = straightenLine(this._savedPoint, currentPoint);
|
|
73
73
|
this._pathD += "L" + straightLine.x + " " + straightLine.y;
|
|
74
74
|
this._path.setAttribute("d", this._pathD);
|
|
75
75
|
}
|
|
@@ -91,7 +91,7 @@ export class DrawPathTool {
|
|
|
91
91
|
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
92
92
|
const mvX = rect.x - designerCanvas.containerBoundingRect.x - offset;
|
|
93
93
|
const mvY = rect.y - designerCanvas.containerBoundingRect.y - offset;
|
|
94
|
-
const d =
|
|
94
|
+
const d = moveSVGPath(this._path, mvX, mvY);
|
|
95
95
|
this._path.setAttribute("d", d);
|
|
96
96
|
svg.appendChild(this._path);
|
|
97
97
|
svg.style.left = (mvX) + 'px';
|
|
@@ -110,17 +110,4 @@ export class DrawPathTool {
|
|
|
110
110
|
break;
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
|
-
straightenLine(p1, p2) {
|
|
114
|
-
let newP = { x: 0, y: 0 };
|
|
115
|
-
let alpha = -1 * Math.atan2(p2.y - p1.y, p2.x - p1.x) * 180 / Math.PI;
|
|
116
|
-
if (alpha < 0)
|
|
117
|
-
alpha += 360;
|
|
118
|
-
if (alpha > 0 && alpha < 45 || alpha > 315 && alpha < 360 || alpha > 135 && alpha < 225) // right or left
|
|
119
|
-
newP = { x: p2.x, y: p1.y };
|
|
120
|
-
else if (alpha > 45 && alpha < 135 || alpha > 225 && alpha < 315) // up or down
|
|
121
|
-
newP = { x: p1.x, y: p2.y };
|
|
122
|
-
else // something else
|
|
123
|
-
newP = { x: p2.x, y: p2.y };
|
|
124
|
-
return newP;
|
|
125
|
-
}
|
|
126
113
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { IDesignerCanvas } from '../IDesignerCanvas';
|
|
2
|
+
import { ITool } from './ITool';
|
|
3
|
+
import { ServiceContainer } from '../../../services/ServiceContainer.js';
|
|
4
|
+
export declare class DrawRectTool implements ITool {
|
|
5
|
+
readonly cursor = "crosshair";
|
|
6
|
+
private _path;
|
|
7
|
+
private _startPoint;
|
|
8
|
+
private _minX;
|
|
9
|
+
private _minY;
|
|
10
|
+
private _maxX;
|
|
11
|
+
private _maxY;
|
|
12
|
+
private _px;
|
|
13
|
+
private _py;
|
|
14
|
+
constructor();
|
|
15
|
+
activated(serviceContainer: ServiceContainer): void;
|
|
16
|
+
dispose(): void;
|
|
17
|
+
pointerEventHandler(designerCanvas: IDesignerCanvas, event: PointerEvent, currentElement: Element): void;
|
|
18
|
+
}
|