@node-projects/web-component-designer 0.0.92 → 0.0.93

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.
@@ -103,10 +103,8 @@ export class ContextMenuHelper {
103
103
  window.removeEventListener('resize', this._closeBound);
104
104
  window.removeEventListener('mousedown', this._closeOnDownBound);
105
105
  window.removeEventListener('mouseup', this._closeOnUpBound);
106
- if (this._shadowRoot === document)
107
- document.body.removeChild(this._element);
108
- else
109
- this._shadowRoot.removeChild(this._element);
106
+ if (this._element.parentElement)
107
+ this._element.parentElement.removeChild(this._element);
110
108
  });
111
109
  }
112
110
  show() {
@@ -20,6 +20,8 @@ export declare class DesignerView extends BaseCustomWebComponentConstructorAppen
20
20
  static readonly style: CSSStyleSheet;
21
21
  static readonly template: HTMLTemplateElement;
22
22
  constructor();
23
+ zoomReset(): void;
24
+ zoomToFit(): void;
23
25
  private _onScrollbar;
24
26
  private _onWheel;
25
27
  get designerWidth(): string;
@@ -179,38 +179,11 @@ export class DesignerView extends BaseCustomWebComponentConstructorAppend {
179
179
  };
180
180
  let zoomReset = this._getDomElement('zoomReset');
181
181
  zoomReset.onclick = () => {
182
- this._designerCanvas.canvasOffset = { x: 0, y: 0 };
183
- this._designerCanvas.zoomFactor = 1;
184
- this._sVert.value = 0.5;
185
- this._sHor.value = 0.5;
186
- this._zoomInput.value = Math.round(this._designerCanvas.zoomFactor * 100) + '%';
182
+ this.zoomReset();
187
183
  };
188
184
  let zoomFit = this._getDomElement('zoomFit');
189
185
  zoomFit.onclick = () => {
190
- let maxX = 0, maxY = 0, minX = 0, minY = 0;
191
- this._designerCanvas.canvasOffset = { x: 0, y: 0 };
192
- this._designerCanvas.zoomFactor = 1;
193
- for (let n of DomHelper.getAllChildNodes(this.designerCanvas.rootDesignItem.element)) {
194
- if (n instanceof Element) {
195
- const rect = n.getBoundingClientRect();
196
- minX = minX < rect.x ? minX : rect.x;
197
- minY = minY < rect.y ? minY : rect.y;
198
- maxX = maxX > rect.x + rect.width + autoZomOffset ? maxX : rect.x + rect.width + autoZomOffset;
199
- maxY = maxY > rect.y + rect.height + autoZomOffset ? maxY : rect.y + rect.height + autoZomOffset;
200
- }
201
- }
202
- const cvRect = this.designerCanvas.getBoundingClientRect();
203
- maxX -= cvRect.x;
204
- maxY -= cvRect.y;
205
- let scaleX = cvRect.width / (maxX / this._designerCanvas.zoomFactor);
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;
212
- this._designerCanvas.zoomFactor = scaleX < scaleY ? scaleX : scaleY;
213
- this._zoomInput.value = Math.round(this._designerCanvas.zoomFactor * 100) + '%';
186
+ this.zoomToFit();
214
187
  };
215
188
  this.addEventListener(EventNames.Wheel, event => this._onWheel(event));
216
189
  let alignSnap = this._getDomElement('alignSnap');
@@ -225,6 +198,39 @@ export class DesignerView extends BaseCustomWebComponentConstructorAppend {
225
198
  this._sVert.addEventListener('scrollbar-input', (e) => this._onScrollbar(e));
226
199
  this._sHor.addEventListener('scrollbar-input', (e) => this._onScrollbar(e));
227
200
  }
201
+ zoomReset() {
202
+ this._designerCanvas.canvasOffset = { x: 0, y: 0 };
203
+ this._designerCanvas.zoomFactor = 1;
204
+ this._sVert.value = 0.5;
205
+ this._sHor.value = 0.5;
206
+ this._zoomInput.value = Math.round(this._designerCanvas.zoomFactor * 100) + '%';
207
+ }
208
+ zoomToFit() {
209
+ let maxX = 0, maxY = 0, minX = 0, minY = 0;
210
+ this._designerCanvas.canvasOffset = { x: 0, y: 0 };
211
+ this._designerCanvas.zoomFactor = 1;
212
+ for (let n of DomHelper.getAllChildNodes(this.designerCanvas.rootDesignItem.element)) {
213
+ if (n instanceof Element) {
214
+ const rect = n.getBoundingClientRect();
215
+ minX = minX < rect.x ? minX : rect.x;
216
+ minY = minY < rect.y ? minY : rect.y;
217
+ maxX = maxX > rect.x + rect.width + autoZomOffset ? maxX : rect.x + rect.width + autoZomOffset;
218
+ maxY = maxY > rect.y + rect.height + autoZomOffset ? maxY : rect.y + rect.height + autoZomOffset;
219
+ }
220
+ }
221
+ const cvRect = this.designerCanvas.getBoundingClientRect();
222
+ maxX -= cvRect.x;
223
+ maxY -= cvRect.y;
224
+ let scaleX = cvRect.width / (maxX / this._designerCanvas.zoomFactor);
225
+ let scaleY = cvRect.height / (maxY / this._designerCanvas.zoomFactor);
226
+ const dimensions = this.designerCanvas.getDesignSurfaceDimensions();
227
+ if (dimensions.width)
228
+ scaleX = cvRect.width / dimensions.width;
229
+ if (dimensions.height)
230
+ scaleY = cvRect.height / dimensions.height;
231
+ this._designerCanvas.zoomFactor = scaleX < scaleY ? scaleX : scaleY;
232
+ this._zoomInput.value = Math.round(this._designerCanvas.zoomFactor * 100) + '%';
233
+ }
228
234
  _onScrollbar(e) {
229
235
  if (e?.detail == 'incrementLarge')
230
236
  e.target.value += 0.25;
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.92",
4
+ "version": "0.0.93",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "author": "",