@node-projects/web-component-designer 0.0.64 → 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 +3 -1
- 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.js +1 -0
- 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/widgets/designerView/IDesignerCanvas.d.ts +2 -0
- package/dist/elements/widgets/designerView/designerCanvas.d.ts +6 -0
- package/dist/elements/widgets/designerView/designerCanvas.js +45 -21
- package/dist/elements/widgets/designerView/designerView.js +62 -16
- 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/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
|
@@ -34,7 +34,9 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
|
|
|
34
34
|
overlayLayer;
|
|
35
35
|
rootDesignItem;
|
|
36
36
|
eatEvents;
|
|
37
|
-
_zoomFactor = 1;
|
|
37
|
+
_zoomFactor = 1; //if scale or zoom css property is used this needs to be the value
|
|
38
|
+
_scaleFactor = 1; //if scale css property is used this need to be the scale value
|
|
39
|
+
_canvasOffset = { x: 0, y: 0 };
|
|
38
40
|
get zoomFactor() {
|
|
39
41
|
return this._zoomFactor;
|
|
40
42
|
}
|
|
@@ -42,6 +44,16 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
|
|
|
42
44
|
this._zoomFactor = value;
|
|
43
45
|
this.zoomFactorChanged();
|
|
44
46
|
}
|
|
47
|
+
get scaleFactor() {
|
|
48
|
+
return this._scaleFactor;
|
|
49
|
+
}
|
|
50
|
+
get canvasOffset() {
|
|
51
|
+
return this._canvasOffset;
|
|
52
|
+
}
|
|
53
|
+
set canvasOffset(value) {
|
|
54
|
+
this._canvasOffset = value;
|
|
55
|
+
this.zoomFactorChanged();
|
|
56
|
+
}
|
|
45
57
|
onContentChanged = new TypedEvent();
|
|
46
58
|
// Private Variables
|
|
47
59
|
_canvas;
|
|
@@ -91,23 +103,27 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
|
|
|
91
103
|
pointer-events: none;
|
|
92
104
|
overflow: visible;
|
|
93
105
|
user-select: none;
|
|
106
|
+
-webkit-user-select: none;
|
|
94
107
|
z-index: 999999999999;
|
|
95
108
|
}
|
|
96
109
|
|
|
97
110
|
#node-projects-designer-canvas-canvas * {
|
|
98
111
|
cursor: pointer;
|
|
99
112
|
user-select: none;
|
|
113
|
+
-webkit-user-select: none;
|
|
100
114
|
}`;
|
|
101
115
|
static template = html `
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
116
|
+
<div style="display: flex;flex-direction: column;width: 100%;height: 100%;">
|
|
117
|
+
<div style="width: 100%;height: 100%;">
|
|
118
|
+
<div id="node-projects-designer-canvas-outercanvas2"
|
|
119
|
+
style="width:100%;height:100%;position:relative;">
|
|
120
|
+
<div id="node-projects-designer-canvas-canvasContainer"
|
|
121
|
+
style="width: 100%;height: 100%;margin: auto;position: absolute;top: 0;/* bottom: 0; does not work with fixed sized when size is bigger then view */left: 0;user-select: none;">
|
|
122
|
+
<div id="node-projects-designer-canvas-canvas" part="canvas" tabindex="0"></div>
|
|
109
123
|
</div>
|
|
110
|
-
</div
|
|
124
|
+
</div>
|
|
125
|
+
</div>
|
|
126
|
+
</div>`;
|
|
111
127
|
extensionManager;
|
|
112
128
|
_pointerextensions;
|
|
113
129
|
_onDblClickBound;
|
|
@@ -321,12 +337,18 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
|
|
|
321
337
|
}
|
|
322
338
|
}
|
|
323
339
|
zoomFactorChanged() {
|
|
324
|
-
|
|
325
|
-
this._canvasContainer.style.zoom = this._zoomFactor;
|
|
326
|
-
//this._canvasContainer.style.transform = 'scale(' + this._zoomFactor+')';
|
|
340
|
+
//a@ts-ignore
|
|
341
|
+
//this._canvasContainer.style.zoom = <any>this._zoomFactor;
|
|
342
|
+
//this._canvasContainer.style.transform = 'scale(' + this._zoomFactor+') translate(' + this._translate.x + ', '+this._translate.y+')';
|
|
327
343
|
//this._canvasContainer.style.transformOrigin = '0 0';
|
|
328
344
|
this._canvasContainer.style.bottom = this._outercanvas2.offsetHeight >= this._canvasContainer.offsetHeight ? '0' : '';
|
|
329
345
|
this._canvasContainer.style.right = this._outercanvas2.offsetWidth >= this._canvasContainer.offsetWidth ? '0' : '';
|
|
346
|
+
this._updateTransform();
|
|
347
|
+
}
|
|
348
|
+
_updateTransform() {
|
|
349
|
+
this._scaleFactor = this._zoomFactor;
|
|
350
|
+
this._canvasContainer.style.transform = 'scale(' + this._zoomFactor + ') translate(' + this._canvasOffset.x + 'px, ' + this._canvasOffset.y + 'px)';
|
|
351
|
+
this._canvasContainer.style.transformOrigin = '0 0';
|
|
330
352
|
this.snapLines.clearSnaplines();
|
|
331
353
|
}
|
|
332
354
|
setDesignItems(designItems) {
|
|
@@ -405,11 +427,13 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
|
|
|
405
427
|
}
|
|
406
428
|
_onContextMenu(event) {
|
|
407
429
|
event.preventDefault();
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
this.instanceServiceContainer.selectionService.
|
|
430
|
+
if (!event.shiftKey) {
|
|
431
|
+
const designItem = DesignItem.GetOrCreateDesignItem(event.target, this.serviceContainer, this.instanceServiceContainer);
|
|
432
|
+
if (!this.instanceServiceContainer.selectionService.isSelected(designItem)) {
|
|
433
|
+
this.instanceServiceContainer.selectionService.setSelectedElements([designItem]);
|
|
434
|
+
}
|
|
435
|
+
this.showDesignItemContextMenu(designItem, event);
|
|
411
436
|
}
|
|
412
|
-
this.showDesignItemContextMenu(designItem, event);
|
|
413
437
|
}
|
|
414
438
|
showDesignItemContextMenu(designItem, event) {
|
|
415
439
|
const mnuItems = [];
|
|
@@ -496,12 +520,12 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
|
|
|
496
520
|
}
|
|
497
521
|
getNormalizedEventCoordinates(event) {
|
|
498
522
|
const offsetOfOuterX = (event.clientX - this.outerRect.x) / this.zoomFactor;
|
|
499
|
-
const offsetOfCanvasX = this.containerBoundingRect.x - this.outerRect.x / this.zoomFactor;
|
|
523
|
+
const offsetOfCanvasX = this.containerBoundingRect.x - this.outerRect.x / this.zoomFactor * this._scaleFactor;
|
|
500
524
|
const offsetOfOuterY = (event.clientY - this.outerRect.y) / this.zoomFactor;
|
|
501
|
-
const offsetOfCanvasY = this.containerBoundingRect.y - this.outerRect.y / this.zoomFactor;
|
|
525
|
+
const offsetOfCanvasY = this.containerBoundingRect.y - this.outerRect.y / this.zoomFactor * this._scaleFactor;
|
|
502
526
|
return {
|
|
503
|
-
x: offsetOfOuterX - offsetOfCanvasX,
|
|
504
|
-
y: offsetOfOuterY - offsetOfCanvasY
|
|
527
|
+
x: offsetOfOuterX - offsetOfCanvasX + offsetOfCanvasX - offsetOfCanvasX / this.zoomFactor,
|
|
528
|
+
y: offsetOfOuterY - offsetOfCanvasY + offsetOfCanvasY - offsetOfCanvasY / this.zoomFactor
|
|
505
529
|
};
|
|
506
530
|
}
|
|
507
531
|
getNormalizedElementCoordinates(element) {
|
|
@@ -567,7 +591,7 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
|
|
|
567
591
|
}
|
|
568
592
|
if (event.composedPath().indexOf(this.eatEvents) >= 0)
|
|
569
593
|
return;
|
|
570
|
-
if (event.
|
|
594
|
+
if (event.buttons == 2)
|
|
571
595
|
return;
|
|
572
596
|
let currentElement = this.serviceContainer.elementAtPointService.getElementAtPoint(this, { x: event.x, y: event.y });
|
|
573
597
|
if (currentElement === this._outercanvas2 || currentElement === this.overlayLayer || !currentElement) {
|
|
@@ -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;
|
|
@@ -86,23 +87,50 @@ export class DesignerView extends BaseCustomWebComponentConstructorAppend {
|
|
|
86
87
|
}
|
|
87
88
|
.snap-guide {
|
|
88
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;
|
|
89
114
|
}`;
|
|
90
115
|
static template = html `
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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>`;
|
|
106
134
|
constructor() {
|
|
107
135
|
super();
|
|
108
136
|
const outer = this._getDomElement('outer');
|
|
@@ -133,12 +161,30 @@ export class DesignerView extends BaseCustomWebComponentConstructorAppend {
|
|
|
133
161
|
};
|
|
134
162
|
let zoomReset = this._getDomElement('zoomReset');
|
|
135
163
|
zoomReset.onclick = () => {
|
|
164
|
+
this._designerCanvas.canvasOffset = { x: 0, y: 0 };
|
|
136
165
|
this._designerCanvas.zoomFactor = 1;
|
|
137
166
|
this._zoomInput.value = Math.round(this._designerCanvas.zoomFactor * 100) + '%';
|
|
138
167
|
};
|
|
139
168
|
let zoomFit = this._getDomElement('zoomFit');
|
|
140
169
|
zoomFit.onclick = () => {
|
|
141
|
-
|
|
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;
|
|
142
188
|
this._zoomInput.value = Math.round(this._designerCanvas.zoomFactor * 100) + '%';
|
|
143
189
|
};
|
|
144
190
|
this.addEventListener(EventNames.Wheel, event => this._onWheel(event));
|
|
@@ -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));
|
|
@@ -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
|
}
|