@node-projects/web-component-designer 0.0.87 → 0.0.88
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/dist/elements/controls/PlainScrollbar.js +122 -116
- package/dist/elements/widgets/designerView/IDesignerCanvas.d.ts +5 -0
- package/dist/elements/widgets/designerView/designerCanvas.d.ts +10 -1
- package/dist/elements/widgets/designerView/designerCanvas.js +63 -14
- package/dist/elements/widgets/designerView/designerCanvas.ts.BASE.d.ts +92 -0
- package/dist/elements/widgets/designerView/designerCanvas.ts.BASE.js +734 -0
- package/dist/elements/widgets/designerView/designerCanvas.ts.LOCAL.d.ts +95 -0
- package/dist/elements/widgets/designerView/designerCanvas.ts.LOCAL.js +768 -0
- package/dist/elements/widgets/designerView/designerCanvas.ts.REMOTE.d.ts +94 -0
- package/dist/elements/widgets/designerView/designerCanvas.ts.REMOTE.js +745 -0
- package/dist/elements/widgets/designerView/designerView.js +19 -15
- package/dist/elements/widgets/designerView/tools/MagicWandSelectorTool.js +9 -9
- package/dist/elements/widgets/designerView/tools/RectangleSelectorTool.js +9 -9
- package/dist/elements/widgets/designerView/tools/ZoomTool.d.ts +7 -1
- package/dist/elements/widgets/designerView/tools/ZoomTool.js +34 -0
- package/package.json +1 -1
|
@@ -41,6 +41,8 @@ export class DesignerView extends BaseCustomWebComponentConstructorAppend {
|
|
|
41
41
|
height: 16px;
|
|
42
42
|
background: #787f82;
|
|
43
43
|
display: flex;
|
|
44
|
+
bottom: 0;
|
|
45
|
+
position: absolute;
|
|
44
46
|
}
|
|
45
47
|
input {
|
|
46
48
|
width: 40px;
|
|
@@ -75,8 +77,8 @@ export class DesignerView extends BaseCustomWebComponentConstructorAppend {
|
|
|
75
77
|
height: 100%;
|
|
76
78
|
}
|
|
77
79
|
#canvas {
|
|
78
|
-
width: 100
|
|
79
|
-
height: 100
|
|
80
|
+
width: calc(100% - 16px);
|
|
81
|
+
height: calc(100% - 32px);
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
.zoom-in {
|
|
@@ -141,15 +143,21 @@ export class DesignerView extends BaseCustomWebComponentConstructorAppend {
|
|
|
141
143
|
this._designerCanvas.id = "canvas";
|
|
142
144
|
this._designerCanvas.appendChild(document.createElement("slot"));
|
|
143
145
|
outer.insertAdjacentElement('afterbegin', this._designerCanvas);
|
|
146
|
+
this._designerCanvas.onZoomFactorChanged.on(() => {
|
|
147
|
+
this._zoomInput.value = Math.round(this._designerCanvas.zoomFactor * 100) + '%';
|
|
148
|
+
const pos = this.designerCanvas.canvasOffset;
|
|
149
|
+
const w = this.designerCanvas.designerOffsetWidth > this.designerCanvas.offsetWidth ? this.designerCanvas.designerOffsetWidth : this.designerCanvas.offsetWidth;
|
|
150
|
+
const h = this.designerCanvas.designerOffsetHeight > this.designerCanvas.offsetHeight ? this.designerCanvas.designerOffsetHeight : this.designerCanvas.offsetHeight;
|
|
151
|
+
this._sHor.value = (pos.x / (-2 * w)) + 0.5;
|
|
152
|
+
this._sVert.value = (pos.y / (-2 * h)) + 0.5;
|
|
153
|
+
});
|
|
144
154
|
this._zoomInput = this._getDomElement('zoomInput');
|
|
145
155
|
this._zoomInput.onkeydown = (e) => {
|
|
146
156
|
if (e.key == 'Enter')
|
|
147
157
|
this._designerCanvas.zoomFactor = parseFloat(this._zoomInput.value) / 100;
|
|
148
|
-
this._zoomInput.value = Math.round(this._designerCanvas.zoomFactor * 100) + '%';
|
|
149
158
|
};
|
|
150
159
|
this._zoomInput.onblur = () => {
|
|
151
160
|
this._designerCanvas.zoomFactor = parseFloat(this._zoomInput.value) / 100;
|
|
152
|
-
this._zoomInput.value = Math.round(this._designerCanvas.zoomFactor * 100) + '%';
|
|
153
161
|
};
|
|
154
162
|
this._zoomInput.onclick = this._zoomInput.select;
|
|
155
163
|
let zoomIncrease = this._getDomElement('zoomIncrease');
|
|
@@ -158,7 +166,6 @@ export class DesignerView extends BaseCustomWebComponentConstructorAppend {
|
|
|
158
166
|
this._designerCanvas.zoomFactor += 0.1;
|
|
159
167
|
else
|
|
160
168
|
this._designerCanvas.zoomFactor += 0.01;
|
|
161
|
-
this._zoomInput.value = Math.round(this._designerCanvas.zoomFactor * 100) + '%';
|
|
162
169
|
};
|
|
163
170
|
let zoomDecrease = this._getDomElement('zoomDecrease');
|
|
164
171
|
zoomDecrease.onclick = () => {
|
|
@@ -197,6 +204,11 @@ export class DesignerView extends BaseCustomWebComponentConstructorAppend {
|
|
|
197
204
|
maxY -= cvRect.y;
|
|
198
205
|
let scaleX = cvRect.width / (maxX / this._designerCanvas.zoomFactor);
|
|
199
206
|
let scaleY = cvRect.height / (maxY / this._designerCanvas.zoomFactor);
|
|
207
|
+
const dimensions = this.designerCanvas.getDesignSurfaceDimensions();
|
|
208
|
+
if (dimensions.width)
|
|
209
|
+
scaleX = cvRect.width / dimensions.width;
|
|
210
|
+
if (dimensions.height)
|
|
211
|
+
scaleY = cvRect.height / dimensions.height;
|
|
200
212
|
this._designerCanvas.zoomFactor = scaleX < scaleY ? scaleX : scaleY;
|
|
201
213
|
this._zoomInput.value = Math.round(this._designerCanvas.zoomFactor * 100) + '%';
|
|
202
214
|
};
|
|
@@ -235,16 +247,8 @@ export class DesignerView extends BaseCustomWebComponentConstructorAppend {
|
|
|
235
247
|
zf += event.deltaY * -0.001; //deltamode = 0
|
|
236
248
|
if (zf < 0.02)
|
|
237
249
|
zf = 0.02;
|
|
238
|
-
this.
|
|
239
|
-
this.
|
|
240
|
-
const rect = this.getBoundingClientRect();
|
|
241
|
-
//const xc = this.designerCanvas.canvasOffset.x;
|
|
242
|
-
//const yc = this.designerCanvas.canvasOffset.y;
|
|
243
|
-
const xp = event.x - rect.x;
|
|
244
|
-
const yp = event.y - rect.y;
|
|
245
|
-
const x = xp / zf * (1 - zf);
|
|
246
|
-
const y = yp / zf * (1 - zf);
|
|
247
|
-
this.designerCanvas.canvasOffset = { x, y };
|
|
250
|
+
const vp = this.designerCanvas.getViewportCoordinates(event);
|
|
251
|
+
this.designerCanvas.zoomTowardsPointer(vp, zf);
|
|
248
252
|
}
|
|
249
253
|
else {
|
|
250
254
|
this._sHor.value += event.deltaX / 1000;
|
|
@@ -28,18 +28,18 @@ export class MagicWandSelectorTool {
|
|
|
28
28
|
const inSelectionElements = [];
|
|
29
29
|
let point = designerCanvas.overlayLayer.createPoint();
|
|
30
30
|
for (let e of elements) {
|
|
31
|
-
let elementRect =
|
|
32
|
-
point.x = elementRect.
|
|
33
|
-
point.y = elementRect.
|
|
31
|
+
let elementRect = designerCanvas.getNormalizedElementCoordinates(e);
|
|
32
|
+
point.x = elementRect.x;
|
|
33
|
+
point.y = elementRect.y;
|
|
34
34
|
const p1 = this._path.isPointInFill(point) || this._path.isPointInStroke(point);
|
|
35
|
-
point.x = elementRect.
|
|
36
|
-
point.y = elementRect.
|
|
35
|
+
point.x = elementRect.x + elementRect.width;
|
|
36
|
+
point.y = elementRect.y;
|
|
37
37
|
const p2 = this._path.isPointInFill(point) || this._path.isPointInStroke(point);
|
|
38
|
-
point.x = elementRect.
|
|
39
|
-
point.y = elementRect.
|
|
38
|
+
point.x = elementRect.x;
|
|
39
|
+
point.y = elementRect.y + elementRect.height;
|
|
40
40
|
const p3 = this._path.isPointInFill(point) || this._path.isPointInStroke(point);
|
|
41
|
-
point.x = elementRect.
|
|
42
|
-
point.y = elementRect.
|
|
41
|
+
point.x = elementRect.x + elementRect.width;
|
|
42
|
+
point.y = elementRect.y + elementRect.height;
|
|
43
43
|
const p4 = this._path.isPointInFill(point) || this._path.isPointInStroke(point);
|
|
44
44
|
if (p1 && p2 && p3 && p4) {
|
|
45
45
|
const desItem = DesignItem.GetOrCreateDesignItem(e, designerCanvas.serviceContainer, designerCanvas.instanceServiceContainer);
|
|
@@ -50,18 +50,18 @@ export class RectangleSelectorTool {
|
|
|
50
50
|
const inSelectionElements = [];
|
|
51
51
|
let point = designerCanvas.overlayLayer.createPoint();
|
|
52
52
|
for (let e of elements) {
|
|
53
|
-
let elementRect =
|
|
54
|
-
point.x = elementRect.
|
|
55
|
-
point.y = elementRect.
|
|
53
|
+
let elementRect = designerCanvas.getNormalizedElementCoordinates(e);
|
|
54
|
+
point.x = elementRect.x;
|
|
55
|
+
point.y = elementRect.y;
|
|
56
56
|
const p1 = this._rect.isPointInFill(point);
|
|
57
|
-
point.x = elementRect.
|
|
58
|
-
point.y = elementRect.
|
|
57
|
+
point.x = elementRect.x + elementRect.width;
|
|
58
|
+
point.y = elementRect.y;
|
|
59
59
|
const p2 = p1 && this._rect.isPointInFill(point);
|
|
60
|
-
point.x = elementRect.
|
|
61
|
-
point.y = elementRect.
|
|
60
|
+
point.x = elementRect.x;
|
|
61
|
+
point.y = elementRect.y + elementRect.height;
|
|
62
62
|
const p3 = p2 && this._rect.isPointInFill(point);
|
|
63
|
-
point.x = elementRect.
|
|
64
|
-
point.y = elementRect.
|
|
63
|
+
point.x = elementRect.x + elementRect.width;
|
|
64
|
+
point.y = elementRect.y + elementRect.height;
|
|
65
65
|
const p4 = p3 && this._rect.isPointInFill(point);
|
|
66
66
|
if (p4) {
|
|
67
67
|
const desItem = DesignItem.GetOrCreateDesignItem(e, designerCanvas.serviceContainer, designerCanvas.instanceServiceContainer);
|
|
@@ -2,9 +2,15 @@ import { ServiceContainer } from '../../../services/ServiceContainer.js';
|
|
|
2
2
|
import { IDesignerCanvas } from '../IDesignerCanvas';
|
|
3
3
|
import { ITool } from './ITool';
|
|
4
4
|
export declare class ZoomTool implements ITool {
|
|
5
|
-
|
|
5
|
+
cursor: string;
|
|
6
|
+
private _startPoint;
|
|
7
|
+
private _endPoint;
|
|
8
|
+
private _pointerMovementTolerance;
|
|
9
|
+
private _zoomStepSize;
|
|
6
10
|
activated(serviceContainer: ServiceContainer): void;
|
|
7
11
|
pointerEventHandler(designerCanvas: IDesignerCanvas, event: PointerEvent, currentElement: Element): void;
|
|
12
|
+
private _zoomOnto;
|
|
13
|
+
private _isPositionEqual;
|
|
8
14
|
keyboardEventHandler(designerCanvas: IDesignerCanvas, event: KeyboardEvent, currentElement: Element): void;
|
|
9
15
|
dispose(): void;
|
|
10
16
|
}
|
|
@@ -1,8 +1,42 @@
|
|
|
1
|
+
import { EventNames } from '../../../../index.js';
|
|
1
2
|
export class ZoomTool {
|
|
2
3
|
cursor = 'zoom-in';
|
|
4
|
+
_startPoint;
|
|
5
|
+
_endPoint;
|
|
6
|
+
_pointerMovementTolerance = 5;
|
|
7
|
+
_zoomStepSize = 0.2; //number x 100 = Scale in percent
|
|
3
8
|
activated(serviceContainer) {
|
|
4
9
|
}
|
|
5
10
|
pointerEventHandler(designerCanvas, event, currentElement) {
|
|
11
|
+
const eventPoint = designerCanvas.getViewportCoordinates(event);
|
|
12
|
+
switch (event.type) {
|
|
13
|
+
case EventNames.PointerDown:
|
|
14
|
+
this._startPoint = eventPoint;
|
|
15
|
+
break;
|
|
16
|
+
case EventNames.PointerUp:
|
|
17
|
+
this._endPoint = eventPoint;
|
|
18
|
+
let isLeftClick = event.button == 0;
|
|
19
|
+
switch (event.button) {
|
|
20
|
+
case 0: //Left-Click
|
|
21
|
+
case 2: //Right-Click
|
|
22
|
+
this._zoomOnto(isLeftClick, this._startPoint, this._endPoint, designerCanvas);
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
_zoomOnto(isZoomInto, startPoint, endPoint, designerCanvas) {
|
|
29
|
+
if (this._isPositionEqual(startPoint, endPoint)) {
|
|
30
|
+
const oldZoom = designerCanvas.zoomFactor;
|
|
31
|
+
const newZoom = isZoomInto ? oldZoom + this._zoomStepSize : oldZoom - this._zoomStepSize;
|
|
32
|
+
designerCanvas.zoomTowardsPointer(endPoint, newZoom);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
_isPositionEqual(startPoint, endPoint) {
|
|
38
|
+
let tolerance = this._pointerMovementTolerance;
|
|
39
|
+
return Math.abs(startPoint.x - endPoint.x) <= tolerance && Math.abs(startPoint.y - endPoint.y) <= tolerance;
|
|
6
40
|
}
|
|
7
41
|
keyboardEventHandler(designerCanvas, event, currentElement) { }
|
|
8
42
|
dispose() {
|