@node-projects/web-component-designer 0.0.122 → 0.0.123

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.
@@ -916,25 +916,25 @@ export function moveSVGPath(path, xFactor, yFactor) {
916
916
  case ('l'):
917
917
  case ('T'):
918
918
  case ('t'):
919
- newPathData += p.type + (p.values[0] - xFactor) + " " + (p.values[1] - yFactor);
919
+ newPathData += p.type + " " + (p.values[0] - xFactor) + " " + (p.values[1] - yFactor) + " ";
920
920
  break;
921
921
  case ('Z'):
922
922
  case ('z'):
923
- newPathData += p.type;
923
+ newPathData += p.type + " ";
924
924
  break;
925
925
  case ('C'):
926
926
  case ('c'):
927
- newPathData += p.type + (p.values[0] - xFactor) + " " + (p.values[1] - yFactor) + " " + (p.values[2] - xFactor) + " " + (p.values[3] - yFactor) + " " + (p.values[4] - xFactor) + " " + (p.values[5] - yFactor);
927
+ newPathData += p.type + " " + (p.values[0] - xFactor) + " " + (p.values[1] - yFactor) + " " + (p.values[2] - xFactor) + " " + (p.values[3] - yFactor) + " " + (p.values[4] - xFactor) + " " + (p.values[5] - yFactor) + " ";
928
928
  break;
929
929
  case ('S'):
930
930
  case ('s'):
931
931
  case ('Q'):
932
932
  case ('q'):
933
- newPathData += p.type + (p.values[0] - xFactor) + " " + (p.values[1] - yFactor) + " " + (p.values[2] - xFactor) + " " + (p.values[3] - yFactor);
933
+ newPathData += p.type + " " + (p.values[0] - xFactor) + " " + (p.values[1] - yFactor) + " " + (p.values[2] - xFactor) + " " + (p.values[3] - yFactor) + " ";
934
934
  break;
935
935
  case ('A'):
936
936
  case ('a'):
937
- newPathData += p.type + (p.values[0] - xFactor) + " " + (p.values[1] - yFactor) + " " + p.values[2] + " " + p.values[3] + " " + p.values[4] + " " + (p.values[5] - xFactor) + " " + (p.values[6] - yFactor);
937
+ newPathData += p.type + " " + (p.values[0] - xFactor) + " " + (p.values[1] - yFactor) + " " + p.values[2] + " " + p.values[3] + " " + p.values[4] + " " + (p.values[5] - xFactor) + " " + (p.values[6] - yFactor) + " ";
938
938
  break;
939
939
  }
940
940
  }
@@ -66,6 +66,7 @@ export declare class DesignerCanvas extends BaseCustomWebComponentLazyAppend imp
66
66
  get designerOffsetHeight(): number;
67
67
  set additionalStyles(value: CSSStyleSheet[]);
68
68
  executeCommand(command: IUiCommand): Promise<void>;
69
+ zoomToFit(): void;
69
70
  canExecuteCommand(command: IUiCommand): boolean;
70
71
  handleSelectAll(): void;
71
72
  handleCopyCommand(): Promise<void>;
@@ -16,7 +16,7 @@ import { ExtensionType } from "./extensions/ExtensionType";
16
16
  import { ExtensionManager } from "./extensions/ExtensionManager";
17
17
  import { NamedTools } from "./tools/NamedTools";
18
18
  import { Screenshot } from '../../helper/Screenshot';
19
- import { dataURItoBlob, exportData } from "../../helper/Helper";
19
+ import { dataURItoBlob, exportData, sleep } from "../../helper/Helper";
20
20
  import { DomHelper } from '@node-projects/base-custom-webcomponent/dist/DomHelper';
21
21
  import { OverlayLayer } from "./extensions/OverlayLayer";
22
22
  import { OverlayLayerView } from './overlayLayerView';
@@ -232,8 +232,19 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
232
232
  switch (command.type) {
233
233
  case CommandType.screenshot:
234
234
  {
235
- if (!this.instanceServiceContainer.selectionService.primarySelection)
236
- alert("you need to select an element!");
235
+ if (!this.instanceServiceContainer.selectionService.primarySelection) {
236
+ this.zoomToFit();
237
+ const backgroundImage = this._canvas.style.backgroundImage;
238
+ this._canvas.style.backgroundImage = 'none';
239
+ await sleep(100);
240
+ const el = this.rootDesignItem.element;
241
+ const sel = this.instanceServiceContainer.selectionService.selectedElements;
242
+ this.instanceServiceContainer.selectionService.setSelectedElements(null);
243
+ const screenshot = await Screenshot.takeScreenshot(el, el.clientWidth, el.clientHeight);
244
+ await exportData(dataURItoBlob(screenshot), "screenshot.png");
245
+ this.instanceServiceContainer.selectionService.setSelectedElements(sel);
246
+ this._canvas.style.backgroundImage = backgroundImage;
247
+ }
237
248
  else {
238
249
  if (!Screenshot.screenshotsEnabled) {
239
250
  alert("you need to select current tab in next browser dialog, or screenshots will not work correctly");
@@ -291,6 +302,35 @@ export class DesignerCanvas extends BaseCustomWebComponentLazyAppend {
291
302
  break;
292
303
  }
293
304
  }
305
+ zoomToFit() {
306
+ const autoZomOffset = 10;
307
+ let maxX = 0, maxY = 0, minX = 0, minY = 0;
308
+ this.canvasOffset = { x: 0, y: 0 };
309
+ this.zoomFactor = 1;
310
+ for (let n of DomHelper.getAllChildNodes(this.rootDesignItem.element)) {
311
+ if (n instanceof Element) {
312
+ const rect = n.getBoundingClientRect();
313
+ minX = minX < rect.x ? minX : rect.x;
314
+ minY = minY < rect.y ? minY : rect.y;
315
+ maxX = maxX > rect.x + rect.width + autoZomOffset ? maxX : rect.x + rect.width + autoZomOffset;
316
+ maxY = maxY > rect.y + rect.height + autoZomOffset ? maxY : rect.y + rect.height + autoZomOffset;
317
+ }
318
+ }
319
+ const cvRect = this.getBoundingClientRect();
320
+ maxX -= cvRect.x;
321
+ maxY -= cvRect.y;
322
+ let scaleX = cvRect.width / (maxX / this.zoomFactor);
323
+ let scaleY = cvRect.height / (maxY / this.zoomFactor);
324
+ const dimensions = this.getDesignSurfaceDimensions();
325
+ if (dimensions.width)
326
+ scaleX = cvRect.width / dimensions.width;
327
+ if (dimensions.height)
328
+ scaleY = cvRect.height / dimensions.height;
329
+ let fak = scaleX < scaleY ? scaleX : scaleY;
330
+ if (!isNaN(fak))
331
+ this.zoomFactor = fak;
332
+ //this._zoomInput.value = Math.round(this.zoomFactor * 100) + '%';
333
+ }
294
334
  canExecuteCommand(command) {
295
335
  const modelCommandService = this.serviceContainer.modelCommandService;
296
336
  if (modelCommandService) {
@@ -4,7 +4,6 @@ import { DomConverter } from './DomConverter.js';
4
4
  import { DefaultHtmlParserService } from '../../services/htmlParserService/DefaultHtmlParserService.js';
5
5
  import { EventNames } from '../../../enums/EventNames.js';
6
6
  import { DesignerToolbar } from './tools/toolBar/DesignerToolbar.js';
7
- const autoZomOffset = 10;
8
7
  export class DesignerView extends BaseCustomWebComponentConstructorAppend {
9
8
  _sVert;
10
9
  _sHor;
@@ -221,32 +220,7 @@ export class DesignerView extends BaseCustomWebComponentConstructorAppend {
221
220
  this._zoomInput.value = Math.round(this._designerCanvas.zoomFactor * 100) + '%';
222
221
  }
223
222
  zoomToFit() {
224
- let maxX = 0, maxY = 0, minX = 0, minY = 0;
225
- this._designerCanvas.canvasOffset = { x: 0, y: 0 };
226
- this._designerCanvas.zoomFactor = 1;
227
- for (let n of DomHelper.getAllChildNodes(this.designerCanvas.rootDesignItem.element)) {
228
- if (n instanceof Element) {
229
- const rect = n.getBoundingClientRect();
230
- minX = minX < rect.x ? minX : rect.x;
231
- minY = minY < rect.y ? minY : rect.y;
232
- maxX = maxX > rect.x + rect.width + autoZomOffset ? maxX : rect.x + rect.width + autoZomOffset;
233
- maxY = maxY > rect.y + rect.height + autoZomOffset ? maxY : rect.y + rect.height + autoZomOffset;
234
- }
235
- }
236
- const cvRect = this.designerCanvas.getBoundingClientRect();
237
- maxX -= cvRect.x;
238
- maxY -= cvRect.y;
239
- let scaleX = cvRect.width / (maxX / this._designerCanvas.zoomFactor);
240
- let scaleY = cvRect.height / (maxY / this._designerCanvas.zoomFactor);
241
- const dimensions = this.designerCanvas.getDesignSurfaceDimensions();
242
- if (dimensions.width)
243
- scaleX = cvRect.width / dimensions.width;
244
- if (dimensions.height)
245
- scaleY = cvRect.height / dimensions.height;
246
- let fak = scaleX < scaleY ? scaleX : scaleY;
247
- if (!isNaN(fak))
248
- this._designerCanvas.zoomFactor = fak;
249
- this._zoomInput.value = Math.round(this._designerCanvas.zoomFactor * 100) + '%';
223
+ this._designerCanvas.zoomToFit();
250
224
  }
251
225
  _onScrollbar(e) {
252
226
  if (e?.detail == 'incrementLarge')
@@ -13,7 +13,7 @@ export declare class ExtensionManager implements IExtensionManager {
13
13
  removeExtension(designItem: IDesignItem, extensionType?: ExtensionType): void;
14
14
  removeExtensions(designItems: IDesignItem[], extensionType?: ExtensionType): void;
15
15
  refreshExtension(designItem: IDesignItem, extensionType?: ExtensionType): void;
16
- refreshExtensions(designItems: IDesignItem[], extensionType?: ExtensionType): void;
17
- refreshAllExtensions(designItems: IDesignItem[]): void;
16
+ refreshExtensions(designItems: IDesignItem[], extensionType?: ExtensionType, ignoredExtension?: any): void;
17
+ refreshAllExtensions(designItems: IDesignItem[], ignoredExtension?: any): void;
18
18
  refreshAllAppliedExtentions(): void;
19
19
  }
@@ -204,7 +204,7 @@ export class ExtensionManager {
204
204
  }
205
205
  }
206
206
  }
207
- refreshExtensions(designItems, extensionType) {
207
+ refreshExtensions(designItems, extensionType, ignoredExtension) {
208
208
  if (designItems) {
209
209
  if (extensionType) {
210
210
  for (let i of designItems) {
@@ -212,7 +212,8 @@ export class ExtensionManager {
212
212
  if (exts) {
213
213
  for (let e of exts) {
214
214
  try {
215
- e.refresh();
215
+ if (e != ignoredExtension)
216
+ e.refresh();
216
217
  }
217
218
  catch (err) {
218
219
  console.error(err);
@@ -226,7 +227,8 @@ export class ExtensionManager {
226
227
  for (let appE of i.appliedDesignerExtensions) {
227
228
  for (let e of appE[1]) {
228
229
  try {
229
- e.refresh();
230
+ if (e != ignoredExtension)
231
+ e.refresh();
230
232
  }
231
233
  catch (err) {
232
234
  console.error(err);
@@ -237,18 +239,18 @@ export class ExtensionManager {
237
239
  }
238
240
  }
239
241
  }
240
- refreshAllExtensions(designItems) {
242
+ refreshAllExtensions(designItems, ignoredExtension) {
241
243
  if (designItems) {
242
- this.refreshExtensions(designItems, ExtensionType.Permanent);
243
- this.refreshExtensions(designItems, ExtensionType.Selection);
244
- this.refreshExtensions(designItems, ExtensionType.PrimarySelection);
245
- this.refreshExtensions(designItems, ExtensionType.PrimarySelectionContainer);
246
- this.refreshExtensions(designItems, ExtensionType.MouseOver);
247
- this.refreshExtensions(designItems, ExtensionType.OnlyOneItemSelected);
248
- this.refreshExtensions(designItems, ExtensionType.MultipleItemsSelected);
249
- this.refreshExtensions(designItems, ExtensionType.ContainerDragOver);
250
- this.refreshExtensions(designItems, ExtensionType.ContainerDrag);
251
- this.refreshExtensions(designItems, ExtensionType.Doubleclick);
244
+ this.refreshExtensions(designItems, ExtensionType.Permanent, ignoredExtension);
245
+ this.refreshExtensions(designItems, ExtensionType.Selection, ignoredExtension);
246
+ this.refreshExtensions(designItems, ExtensionType.PrimarySelection, ignoredExtension);
247
+ this.refreshExtensions(designItems, ExtensionType.PrimarySelectionContainer, ignoredExtension);
248
+ this.refreshExtensions(designItems, ExtensionType.MouseOver, ignoredExtension);
249
+ this.refreshExtensions(designItems, ExtensionType.OnlyOneItemSelected, ignoredExtension);
250
+ this.refreshExtensions(designItems, ExtensionType.MultipleItemsSelected, ignoredExtension);
251
+ this.refreshExtensions(designItems, ExtensionType.ContainerDragOver, ignoredExtension);
252
+ this.refreshExtensions(designItems, ExtensionType.ContainerDrag, ignoredExtension);
253
+ this.refreshExtensions(designItems, ExtensionType.Doubleclick, ignoredExtension);
252
254
  }
253
255
  }
254
256
  refreshAllAppliedExtentions() {
@@ -7,6 +7,6 @@ export interface IExtensionManager {
7
7
  removeExtensions(designItems: IDesignItem[], extensionType?: ExtensionType): any;
8
8
  refreshExtension(designItem: IDesignItem, extensionType?: ExtensionType): any;
9
9
  refreshExtensions(designItems: IDesignItem[], extensionType?: ExtensionType): any;
10
- refreshAllExtensions(designItems: IDesignItem[]): any;
10
+ refreshAllExtensions(designItems: IDesignItem[], ignoredExtension?: any): any;
11
11
  refreshAllAppliedExtentions(): any;
12
12
  }
@@ -73,6 +73,7 @@ export class EllipsisExtension extends AbstractExtension {
73
73
  }
74
74
  e.setAttribute("rx", this._newRx.toString());
75
75
  e.setAttribute("ry", this._newRy.toString());
76
+ this.designerCanvas.extensionManager.refreshAllExtensions([this.extendedItem], this);
76
77
  this._redrawPathCircle(this._cx, this._cy - this._newRy, this._circle1);
77
78
  this._redrawPathCircle(this._cx + this._newRx, this._cy, this._circle2);
78
79
  this._redrawPathCircle(this._cx, this._cy + this._newRy, this._circle3);
@@ -53,6 +53,7 @@ export class LineExtension extends AbstractExtension {
53
53
  this._newCirclePoint = { x: this._circlePos.x + dx, y: this._circlePos.y + dy };
54
54
  this._newLinePoint = { x: this._originalPoint.x + dx, y: this._originalPoint.y + dy };
55
55
  }
56
+ this.designerCanvas.extensionManager.refreshAllExtensions([this.extendedItem], this);
56
57
  circle.setAttribute("cx", this._newCirclePoint.x.toString());
57
58
  circle.setAttribute("cy", this._newCirclePoint.y.toString());
58
59
  l.setAttribute("x" + index, this._newLinePoint.x.toString());
@@ -148,6 +148,7 @@ export class PathExtension extends AbstractExtension {
148
148
  circle.setAttribute("cy", (this._circlePos.y + dy).toString());
149
149
  }
150
150
  }
151
+ this.designerCanvas.extensionManager.refreshAllExtensions([this.extendedItem], this);
151
152
  this.extendedItem.element.setAttribute("d", createPathD(this._pathdata));
152
153
  }
153
154
  break;
@@ -76,6 +76,7 @@ export class RectExtension extends AbstractExtension {
76
76
  r.setAttribute("height", this._rect.h.toString());
77
77
  circle.setAttribute("cx", (this._circlePos.x + dx).toString());
78
78
  circle.setAttribute("cy", (this._circlePos.y + dy).toString());
79
+ this.designerCanvas.extensionManager.refreshAllExtensions([this.extendedItem], this);
79
80
  this._redrawPathCircle(this._rect.x, this._rect.y, this._circle1);
80
81
  this._redrawPathCircle(this._rect.x + this._rect.w, this._rect.y, this._circle2);
81
82
  this._redrawPathCircle(this._rect.x + this._rect.w, this._rect.y + this._rect.h, this._circle3);
@@ -18,7 +18,7 @@ export class DrawEllipsisTool {
18
18
  }
19
19
  pointerEventHandler(designerCanvas, event, currentElement) {
20
20
  const currentPoint = designerCanvas.getNormalizedEventCoordinates(event);
21
- const offset = 50;
21
+ const offset = 10;
22
22
  switch (event.type) {
23
23
  case EventNames.PointerDown:
24
24
  this._startPoint = currentPoint;
@@ -69,19 +69,19 @@ export class DrawEllipsisTool {
69
69
  case EventNames.PointerUp:
70
70
  event.target.releasePointerCapture(event.pointerId);
71
71
  designerCanvas.releaseActiveTool();
72
- const rect = this._path.getBoundingClientRect();
72
+ let coords = designerCanvas.getNormalizedElementCoordinates(this._path);
73
73
  designerCanvas.overlayLayer.removeOverlay(this._path);
74
74
  const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
75
- const mvX = rect.x - designerCanvas.containerBoundingRect.x - offset;
76
- const mvY = rect.y - designerCanvas.containerBoundingRect.y - offset;
75
+ const mvX = coords.x - offset;
76
+ const mvY = coords.y - offset;
77
77
  svg.appendChild(this._path);
78
78
  this._path.setAttribute("cx", (this._cx - mvX).toString());
79
79
  this._path.setAttribute("cy", (this._cy - mvY).toString());
80
80
  svg.style.left = (mvX) + 'px';
81
81
  svg.style.top = (mvY) + 'px';
82
82
  svg.style.position = 'absolute';
83
- svg.style.width = (rect.width + 2 * offset) + 'px';
84
- svg.style.height = (rect.height + 2 * offset) + 'px';
83
+ svg.style.width = (coords.width + 2 * offset) + 'px';
84
+ svg.style.height = (coords.height + 2 * offset) + 'px';
85
85
  svg.style.overflow = 'visible';
86
86
  this._path = null;
87
87
  const di = DesignItem.createDesignItemFromInstance(svg, designerCanvas.serviceContainer, designerCanvas.instanceServiceContainer);
@@ -16,7 +16,7 @@ export class DrawLineTool {
16
16
  }
17
17
  pointerEventHandler(designerCanvas, event, currentElement) {
18
18
  const currentPoint = designerCanvas.getNormalizedEventCoordinates(event);
19
- const offset = 50;
19
+ const offset = 10;
20
20
  switch (event.type) {
21
21
  case EventNames.PointerDown:
22
22
  this._startPoint = currentPoint;
@@ -52,11 +52,11 @@ export class DrawLineTool {
52
52
  case EventNames.PointerUp:
53
53
  event.target.releasePointerCapture(event.pointerId);
54
54
  designerCanvas.releaseActiveTool();
55
- const rect = this._path.getBoundingClientRect();
55
+ let coords = designerCanvas.getNormalizedElementCoordinates(this._path);
56
56
  designerCanvas.overlayLayer.removeOverlay(this._path);
57
57
  const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
58
- const mvX = rect.x - designerCanvas.containerBoundingRect.x - offset;
59
- const mvY = rect.y - designerCanvas.containerBoundingRect.y - offset;
58
+ const mvX = coords.x - offset;
59
+ const mvY = coords.y - offset;
60
60
  this._path.setAttribute("x1", (this._startPoint.x - mvX).toString());
61
61
  this._path.setAttribute("y1", (this._startPoint.y - mvY).toString());
62
62
  this._path.setAttribute("x2", (this._endPoint.x - mvX).toString());
@@ -65,8 +65,8 @@ export class DrawLineTool {
65
65
  svg.style.left = (mvX) + 'px';
66
66
  svg.style.top = (mvY) + 'px';
67
67
  svg.style.position = 'absolute';
68
- svg.style.width = (rect.width + 2 * offset) + 'px';
69
- svg.style.height = (rect.height + 2 * offset) + 'px';
68
+ svg.style.width = (coords.width + 2 * offset) + 'px';
69
+ svg.style.height = (coords.height + 2 * offset) + 'px';
70
70
  svg.style.overflow = 'visible';
71
71
  this._path = null;
72
72
  const di = DesignItem.createDesignItemFromInstance(svg, designerCanvas.serviceContainer, designerCanvas.instanceServiceContainer);
@@ -21,7 +21,7 @@ export class DrawRectTool {
21
21
  }
22
22
  pointerEventHandler(designerCanvas, event, currentElement) {
23
23
  const currentPoint = designerCanvas.getNormalizedEventCoordinates(event);
24
- const offset = 50;
24
+ const offset = 10;
25
25
  switch (event.type) {
26
26
  case EventNames.PointerDown:
27
27
  this._startPoint = currentPoint;
@@ -84,19 +84,19 @@ export class DrawRectTool {
84
84
  case EventNames.PointerUp:
85
85
  event.target.releasePointerCapture(event.pointerId);
86
86
  designerCanvas.releaseActiveTool();
87
- const rect = this._path.getBoundingClientRect();
87
+ let coords = designerCanvas.getNormalizedElementCoordinates(this._path);
88
88
  designerCanvas.overlayLayer.removeOverlay(this._path);
89
89
  const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
90
- const mvX = rect.x - designerCanvas.containerBoundingRect.x - offset;
91
- const mvY = rect.y - designerCanvas.containerBoundingRect.y - offset;
90
+ const mvX = coords.x - offset;
91
+ const mvY = coords.y - offset;
92
92
  this._path.setAttribute("x", (this._px - mvX).toString());
93
93
  this._path.setAttribute("y", (this._py - mvY).toString());
94
94
  svg.appendChild(this._path);
95
95
  svg.style.left = (mvX) + 'px';
96
96
  svg.style.top = (mvY) + 'px';
97
97
  svg.style.position = 'absolute';
98
- svg.style.width = (rect.width + 2 * offset) + 'px';
99
- svg.style.height = (rect.height + 2 * offset) + 'px';
98
+ svg.style.width = (coords.width + 2 * offset) + 'px';
99
+ svg.style.height = (coords.height + 2 * offset) + 'px';
100
100
  svg.style.overflow = 'visible';
101
101
  this._path = null;
102
102
  const di = DesignItem.createDesignItemFromInstance(svg, designerCanvas.serviceContainer, designerCanvas.instanceServiceContainer);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "description": "A UI designer for Polymer apps",
3
3
  "name": "@node-projects/web-component-designer",
4
- "version": "0.0.122",
4
+ "version": "0.0.123",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "author": "",