@tft/interact 12.4.1 → 12.5.1

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.
Files changed (45) hide show
  1. package/bundles/tft-interact.umd.js +158 -124
  2. package/bundles/tft-interact.umd.js.map +1 -1
  3. package/esm2015/lib/directives/account-for-scale.directive.js +3 -11
  4. package/esm2015/lib/directives/account-for-scale.directive.js.map +1 -1
  5. package/esm2015/lib/directives/account-for-scale.directive.metadata.json +1 -1
  6. package/esm2015/lib/directives/apply-scale.directive.js +4 -13
  7. package/esm2015/lib/directives/apply-scale.directive.js.map +1 -1
  8. package/esm2015/lib/directives/apply-scale.directive.metadata.json +1 -1
  9. package/esm2015/lib/directives/drag-root.directive.js +8 -11
  10. package/esm2015/lib/directives/drag-root.directive.js.map +1 -1
  11. package/esm2015/lib/directives/drag-root.directive.metadata.json +1 -1
  12. package/esm2015/lib/directives/draggable.directive.js +21 -12
  13. package/esm2015/lib/directives/draggable.directive.js.map +1 -1
  14. package/esm2015/lib/directives/draggable.directive.metadata.json +1 -1
  15. package/esm2015/lib/directives/dropzone.directive.js +12 -4
  16. package/esm2015/lib/directives/dropzone.directive.js.map +1 -1
  17. package/esm2015/lib/directives/dropzone.directive.metadata.json +1 -1
  18. package/esm2015/lib/directives/index.js.map +1 -1
  19. package/esm2015/lib/directives/resizable.directive.js +27 -8
  20. package/esm2015/lib/directives/resizable.directive.js.map +1 -1
  21. package/esm2015/lib/directives/resizable.directive.metadata.json +1 -1
  22. package/esm2015/lib/interact.module.js +13 -0
  23. package/esm2015/lib/interact.module.js.map +1 -1
  24. package/esm2015/lib/interact.module.metadata.json +1 -1
  25. package/esm2015/lib/models/interact.js +2 -0
  26. package/esm2015/lib/models/interact.js.map +1 -1
  27. package/esm2015/lib/models/interact.metadata.json +1 -1
  28. package/esm2015/lib/services/interact.service.js +31 -32
  29. package/esm2015/lib/services/interact.service.js.map +1 -1
  30. package/esm2015/lib/services/interact.service.metadata.json +1 -1
  31. package/fesm2015/tft-interact.js +136 -111
  32. package/fesm2015/tft-interact.js.map +1 -1
  33. package/lib/directives/account-for-scale.directive.d.ts +1 -3
  34. package/lib/directives/apply-scale.directive.d.ts +4 -7
  35. package/lib/directives/drag-root.directive.d.ts +2 -1
  36. package/lib/directives/draggable.directive.d.ts +3 -1
  37. package/lib/directives/dropzone.directive.d.ts +8 -5
  38. package/lib/directives/resizable.directive.d.ts +3 -1
  39. package/lib/interact.module.d.ts +3 -0
  40. package/lib/models/interact.d.ts +6 -0
  41. package/lib/services/interact.service.d.ts +6 -4
  42. package/package.json +1 -1
  43. package/tft-interact-12.5.1.tgz +0 -0
  44. package/tft-interact.metadata.json +1 -1
  45. package/tft-interact-12.4.1.tgz +0 -0
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Pipe, Injectable, RendererFactory2, NgZone, EventEmitter, Directive, ElementRef, Renderer2, Input, Output, InjectionToken, TemplateRef, Optional, Self, ViewContainerRef, Inject, SkipSelf, ContentChild, HostBinding, NgModule } from '@angular/core';
2
+ import { Pipe, InjectionToken, Injectable, RendererFactory2, NgZone, Optional, Inject, Directive, ElementRef, Input, EventEmitter, Renderer2, Output, TemplateRef, Self, ViewContainerRef, SkipSelf, ContentChild, HostBinding, NgModule } from '@angular/core';
3
3
  import { DOCUMENT, CommonModule } from '@angular/common';
4
4
  import interact from 'interactjs';
5
5
  import { BehaviorSubject, combineLatest } from 'rxjs';
@@ -22,6 +22,7 @@ ArrayOfNPipe.decorators = [
22
22
  },] }
23
23
  ];
24
24
 
25
+ const INTERACT_ROOT_CONFIG = new InjectionToken('INTERACT_ROOT_CONFIG_PARAMS');
25
26
  const DEFAULT_REGISTRY_ID = 'DEFAULT';
26
27
  /**
27
28
  * Default initial value for Delta BehaviorSubject
@@ -49,14 +50,17 @@ const defaultPosition = {
49
50
  };
50
51
 
51
52
  class InteractService {
52
- constructor(rendererFactory, ngZone) {
53
+ constructor(rendererFactory, ngZone, rootConfig) {
53
54
  this.rendererFactory = rendererFactory;
54
55
  this.ngZone = ngZone;
56
+ this.rootConfig = rootConfig;
55
57
  this._interactableIndex = 0;
56
58
  this._dropzoneIndex = 0;
57
59
  // TODO: consider using Map here
58
60
  this.dragRegistrySystem = {};
61
+ this.cssUnit = 'px';
59
62
  this.renderer = this.rendererFactory.createRenderer(null, null);
63
+ this.cssUnit = (rootConfig === null || rootConfig === void 0 ? void 0 : rootConfig.cssDimensionUnit) || 'px';
60
64
  }
61
65
  addDeltaToPosition(delta, position) {
62
66
  return {
@@ -73,7 +77,7 @@ class InteractService {
73
77
  addDraggableToRegistry(customRegistryId = null, interactableId = null) {
74
78
  const registryId = customRegistryId || DEFAULT_REGISTRY_ID;
75
79
  // if we pass an id to createInteractableId then it is used when creating the interactable
76
- // and returned, otherwise a an id is created for the draggable.
80
+ // and returned, otherwise a new id is created for the draggable.
77
81
  const key = this.createInteractableId(interactableId);
78
82
  if (!Object.prototype.hasOwnProperty.call(this.dragRegistrySystem, registryId)) {
79
83
  this.dragRegistrySystem[registryId] = {};
@@ -83,6 +87,11 @@ class InteractService {
83
87
  }
84
88
  destroyInteractable(interactableId, registryId = DEFAULT_REGISTRY_ID) {
85
89
  if (this.dragRegistrySystem[registryId][interactableId]) {
90
+ // unsubscribe from all the subscriptions if they're subscriptions
91
+ for (const propName in this.dragRegistrySystem[registryId][interactableId]) {
92
+ const prop = this.dragRegistrySystem[registryId][interactableId][propName];
93
+ prop === null || prop === void 0 ? void 0 : prop.unsubscribe();
94
+ }
86
95
  delete this.dragRegistrySystem[registryId][interactableId];
87
96
  }
88
97
  }
@@ -164,8 +173,8 @@ class InteractService {
164
173
  this.dragRegistrySystem[registryId][interactId].size$.next({ deltaX, deltaY, width, height, targetElement });
165
174
  }
166
175
  interactableExistOnRegistry(interactId, registryId = DEFAULT_REGISTRY_ID) {
167
- return this.dragRegistrySystem.hasOwnProperty(registryId)
168
- && this.dragRegistrySystem[registryId].hasOwnProperty(interactId);
176
+ // eslint-disable-next-line no-prototype-builtins
177
+ return this.dragRegistrySystem.hasOwnProperty(registryId) && this.dragRegistrySystem[registryId].hasOwnProperty(interactId);
169
178
  }
170
179
  /**
171
180
  * Uses renderer to set width and height of angular component
@@ -174,19 +183,10 @@ class InteractService {
174
183
  * @param target the element to transform
175
184
  */
176
185
  setElementSize(width, height, target) {
177
- var _a;
178
186
  if (!target)
179
187
  return;
180
- const accountForScaleDirective = (_a = target.resizeRef) === null || _a === void 0 ? void 0 : _a.account_for_scale_dir;
181
- if (accountForScaleDirective) {
182
- const { scaleX, scaleY } = accountForScaleDirective;
183
- const scaledWidth = width / scaleX;
184
- const scaledHeight = height / scaleY;
185
- this.renderer.setStyle(target, 'width', `${scaledWidth}px`);
186
- this.renderer.setStyle(target, 'height', `${scaledHeight}px`);
187
- }
188
- this.renderer.setStyle(target, 'width', `${width}px`);
189
- this.renderer.setStyle(target, 'height', `${height}px`);
188
+ this.renderer.setStyle(target, 'width', `${width}${this.cssUnit}`);
189
+ this.renderer.setStyle(target, 'height', `${height}${this.cssUnit}`);
190
190
  }
191
191
  /**
192
192
  * Uses renderer to set position of angular component
@@ -195,18 +195,10 @@ class InteractService {
195
195
  * @param target the element to transform
196
196
  */
197
197
  setElementTransform(x, y, position) {
198
- var _a, _b, _c, _d;
199
198
  if (!(position === null || position === void 0 ? void 0 : position.targetElement))
200
199
  return;
201
- if ((_b = (_a = position.targetElement) === null || _a === void 0 ? void 0 : _a.dragRef) === null || _b === void 0 ? void 0 : _b.account_for_scale_dir) {
202
- const { scaleX, scaleY } = (_d = (_c = position.targetElement) === null || _c === void 0 ? void 0 : _c.dragRef) === null || _d === void 0 ? void 0 : _d.account_for_scale_dir;
203
- this.renderer.setStyle(position.targetElement, 'left', `${x / scaleX}px`);
204
- this.renderer.setStyle(position.targetElement, 'top', `${y / scaleY}px`);
205
- }
206
- else {
207
- this.renderer.setStyle(position.targetElement, 'left', `${x}px`);
208
- this.renderer.setStyle(position.targetElement, 'top', `${y}px`);
209
- }
200
+ this.renderer.setStyle(position.targetElement, 'left', `${x}${this.cssUnit}`);
201
+ this.renderer.setStyle(position.targetElement, 'top', `${y}${this.cssUnit}`);
210
202
  }
211
203
  /**
212
204
  * Generates a translate string for the x and y arguments passed to
@@ -215,32 +207,65 @@ class InteractService {
215
207
  * @param y the position along the y axis
216
208
  */
217
209
  createTransformString(x, y) {
218
- return `translate3d(${x}px, ${y}px, 0)`;
210
+ return `translate3d(${x}${this.cssUnit}, ${y}${this.cssUnit}, 0)`;
219
211
  }
220
- calculatePositionInElement(zoneElement, dragElement) {
212
+ calculatePositionInElement(zoneElement, dragElement, scale) {
221
213
  // TODO: this calculation may not cover a lot of scenarios, keep an eye out for possible improvements
222
214
  const zoneRect = zoneElement.getBoundingClientRect();
223
215
  const dragRect = dragElement.getBoundingClientRect();
224
- return {
216
+ const position = scale
217
+ ? {
218
+ x: (dragRect.left - zoneRect.left) / scale || 1,
219
+ y: (dragRect.top - zoneRect.top) / scale || 1
220
+ } : {
225
221
  x: dragRect.left - zoneRect.left,
226
222
  y: dragRect.top - zoneRect.top
227
223
  };
224
+ // console.log({ y:position.y, drt:dragRect.top, zrt: zoneRect.top})
225
+ return position;
228
226
  }
229
227
  }
230
- InteractService.ɵprov = i0.ɵɵdefineInjectable({ factory: function InteractService_Factory() { return new InteractService(i0.ɵɵinject(i0.RendererFactory2), i0.ɵɵinject(i0.NgZone)); }, token: InteractService, providedIn: "root" });
228
+ InteractService.ɵprov = i0.ɵɵdefineInjectable({ factory: function InteractService_Factory() { return new InteractService(i0.ɵɵinject(i0.RendererFactory2), i0.ɵɵinject(i0.NgZone), i0.ɵɵinject(INTERACT_ROOT_CONFIG, 8)); }, token: InteractService, providedIn: "root" });
231
229
  InteractService.decorators = [
232
230
  { type: Injectable, args: [{ providedIn: 'root' },] }
233
231
  ];
234
232
  InteractService.ctorParameters = () => [
235
233
  { type: RendererFactory2 },
236
- { type: NgZone }
234
+ { type: NgZone },
235
+ { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [INTERACT_ROOT_CONFIG,] }] }
237
236
  ];
238
237
 
238
+ /**
239
+ * Use to apply scale to the element and tell the drag and resize directives to account for the scale when
240
+ * @example <div tftAccountForScale [scale]="2.5"> <div tftDraggable> </div> </div>
241
+ * @note if `dragRoot` is used this directive should be used on the same element to ensure that the drag
242
+ * element accounts for scale
243
+ */
244
+ class AccountForScaleDirective {
245
+ constructor(el) {
246
+ this.el = el;
247
+ // this setup allows consumers to set x, y scale independently or just set them both with scale
248
+ this.scale = 1;
249
+ }
250
+ }
251
+ AccountForScaleDirective.decorators = [
252
+ { type: Directive, args: [{
253
+ selector: '[tftAccountForScale]'
254
+ },] }
255
+ ];
256
+ AccountForScaleDirective.ctorParameters = () => [
257
+ { type: ElementRef }
258
+ ];
259
+ AccountForScaleDirective.propDecorators = {
260
+ scale: [{ type: Input }]
261
+ };
262
+
239
263
  class DropzoneDirective {
240
- constructor(el, renderer, interactService) {
264
+ constructor(el, renderer, interactService, account_for_scale_dir) {
241
265
  this.el = el;
242
266
  this.renderer = renderer;
243
267
  this.interactService = interactService;
268
+ this.account_for_scale_dir = account_for_scale_dir;
244
269
  this.dropzoneConfig = {};
245
270
  // proxies to pass interact events through to consumer of directive
246
271
  this.dropActivate = new EventEmitter();
@@ -248,6 +273,10 @@ class DropzoneDirective {
248
273
  this.dragLeave = new EventEmitter();
249
274
  this.dragDrop = new EventEmitter();
250
275
  }
276
+ get scale() {
277
+ var _a;
278
+ return (_a = this.account_for_scale_dir) === null || _a === void 0 ? void 0 : _a.scale;
279
+ }
251
280
  ngOnInit() {
252
281
  // connects
253
282
  this.dropzone = this.connectDropzoneEvents(this.el.nativeElement, this.dropzoneConfig);
@@ -293,8 +322,9 @@ class DropzoneDirective {
293
322
  var _a, _b;
294
323
  const zoneElement = event.target;
295
324
  const dragElement = (_b = (_a = event.relatedTarget) === null || _a === void 0 ? void 0 : _a.dragRef) === null || _b === void 0 ? void 0 : _b.previewRef;
325
+ const scale = this.scale;
296
326
  const positionInDropTarget = zoneElement && dragElement
297
- ? this.interactService.calculatePositionInElement(zoneElement, dragElement)
327
+ ? this.interactService.calculatePositionInElement(zoneElement, dragElement, scale)
298
328
  : null;
299
329
  return {
300
330
  interactEvent: event,
@@ -316,7 +346,8 @@ DropzoneDirective.decorators = [
316
346
  DropzoneDirective.ctorParameters = () => [
317
347
  { type: ElementRef },
318
348
  { type: Renderer2 },
319
- { type: InteractService }
349
+ { type: InteractService },
350
+ { type: AccountForScaleDirective, decorators: [{ type: Optional }] }
320
351
  ];
321
352
  DropzoneDirective.propDecorators = {
322
353
  dropzoneId: [{ type: Input }],
@@ -382,60 +413,24 @@ function getRootNode(viewRef, _document) {
382
413
  return wrapper;
383
414
  }
384
415
 
385
- /**
386
- * Use to apply scale to the element and tell the drag and resize directives to account for the scale when
387
- * @example <div tftAccountForScale [scale]="2.5"> <div tftDraggable> </div> </div>
388
- * @note if `dragRoot` is used this directive should be used on the same element to ensure that the drag
389
- * element accounts for scale
390
- */
391
- class AccountForScaleDirective {
392
- constructor(el) {
393
- this.el = el;
394
- this.scaleX = 1;
395
- this.scaleY = 1;
396
- }
397
- // this setup allows consumers to set x, y scale independently or just set them both with scale
398
- set scale(val) {
399
- this.scaleY = val;
400
- this.scaleX = val;
401
- }
402
- ;
403
- }
404
- AccountForScaleDirective.decorators = [
405
- { type: Directive, args: [{
406
- selector: '[tftAccountForScale]'
407
- },] }
408
- ];
409
- AccountForScaleDirective.ctorParameters = () => [
410
- { type: ElementRef }
411
- ];
412
- AccountForScaleDirective.propDecorators = {
413
- scale: [{ type: Input }],
414
- scaleX: [{ type: Input }],
415
- scaleY: [{ type: Input }]
416
- };
417
-
418
416
  /**
419
417
  * Use this directive to select which element to attach the element to while dragging
420
418
  * @example <div tftDragRoot><div tftDraggable> </div> </div>
421
419
  * @note this directive will overwrite any style transformations (e.g. transform: scale(2); )
422
420
  */
423
421
  class DragRootDirective {
424
- constructor(el, account_for_scale_dir) {
422
+ constructor(el,
423
+ // This is used when passing a dragRoot as in input to a draggable element that not a child of that dragRoot
424
+ // It allows the the interact service to check if the drag root has some scaling applied to it and account for it when the component is dragged
425
+ account_for_scale_dir) {
425
426
  this.el = el;
426
- // This accounts for a bug where drag element is misaligned when using a drag root
427
- // with a dropzone inside of it and a drag item inside the dropzone
428
- // e.g <div tftDragRoot> <div tftDropzone> <div tftDraggable</div> </div> </div>
429
- // TODO: This is a band-aid, root cause in misunderstood, it started after switching from
430
- // using `translate3d` to top/left for positioning
431
- if (!account_for_scale_dir) {
432
- el.nativeElement.style.transform = 'scale(1)';
433
- }
427
+ this.account_for_scale_dir = account_for_scale_dir;
434
428
  }
435
429
  }
436
430
  DragRootDirective.decorators = [
437
431
  { type: Directive, args: [{
438
- selector: '[tftDragRoot]'
432
+ selector: '[tftDragRoot]',
433
+ exportAs: 'tftDragRoot'
439
434
  },] }
440
435
  ];
441
436
  DragRootDirective.ctorParameters = () => [
@@ -446,7 +441,6 @@ DragRootDirective.ctorParameters = () => [
446
441
  /** @dynamic */
447
442
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
448
443
  class DraggableDirective {
449
- // cache holding element to use as placeholder while dragging
450
444
  constructor(el, interactService, renderer, _viewContainerRef, _document, account_for_scale_dir, dropzone_dir, drag_root_dir) {
451
445
  this.el = el;
452
446
  this.interactService = interactService;
@@ -471,13 +465,18 @@ class DraggableDirective {
471
465
  this.dragInertiaStart = new EventEmitter();
472
466
  this.dragEnd = new EventEmitter();
473
467
  }
468
+ // check all the different places for scale
469
+ get scale() {
470
+ var _a, _b, _c, _d;
471
+ return ((_a = this.account_for_scale_dir) === null || _a === void 0 ? void 0 : _a.scale) || ((_b = this.drag_root_dir) === null || _b === void 0 ? void 0 : _b.account_for_scale_dir.scale) || ((_d = (_c = this.dragRoot) === null || _c === void 0 ? void 0 : _c.account_for_scale_dir) === null || _d === void 0 ? void 0 : _d.scale);
472
+ }
474
473
  ngOnInit() {
475
- var _a, _b, _c;
474
+ var _a, _b, _c, _d, _e;
476
475
  this.interactable = this.initiateDragEvents(this.dragConfig, this.el.nativeElement);
477
- this.dragRoot = this.dragRoot || ((_b = (_a = this.drag_root_dir) === null || _a === void 0 ? void 0 : _a.el) === null || _b === void 0 ? void 0 : _b.nativeElement) || this._document.body;
476
+ this.dragRootEl = (((_b = (_a = this.dragRoot) === null || _a === void 0 ? void 0 : _a.el) === null || _b === void 0 ? void 0 : _b.nativeElement) || ((_d = (_c = this.drag_root_dir) === null || _c === void 0 ? void 0 : _c.el) === null || _d === void 0 ? void 0 : _d.nativeElement)) || this._document.body;
478
477
  // register with parent dropzone if it exists, otherwise use default
479
478
  // this gives us a place on the registry to store our drag items that don't have a dropzone
480
- this.registryId = ((_c = this.dropzone_dir) === null || _c === void 0 ? void 0 : _c.dropzoneId) || DEFAULT_REGISTRY_ID;
479
+ this.registryId = ((_e = this.dropzone_dir) === null || _e === void 0 ? void 0 : _e.dropzoneId) || DEFAULT_REGISTRY_ID;
481
480
  // add draggable to directory and store its id
482
481
  this.interactableId = this.interactService.addDraggableToRegistry(this.registryId, this.interactableId);
483
482
  this.alignPositionWithInputs(this.x, this.y);
@@ -528,12 +527,15 @@ class DraggableDirective {
528
527
  }
529
528
  dragMoveListener(event, element) {
530
529
  const { dx, dy } = event;
531
- this.interactService.updateDeltas(this.interactableId, this.registryId, { deltaX: dx, deltaY: dy }, element);
530
+ const scale = this.scale;
531
+ const deltaX = scale ? dx / scale : dx;
532
+ const deltaY = scale ? dy / scale : dy;
533
+ this.interactService.updateDeltas(this.interactableId, this.registryId, { deltaX, deltaY }, element);
532
534
  }
533
535
  setDragStyles(dragElement) {
534
536
  this.renderer.setStyle(dragElement, 'touchAction', 'none');
535
537
  this.renderer.setStyle(dragElement, 'zIndex', this.dragZIndex);
536
- this.renderer.setStyle(dragElement, 'position', 'fixed');
538
+ this.renderer.setStyle(dragElement, 'position', 'absolute');
537
539
  }
538
540
  addDragPropertiesToElement(nativeElement) {
539
541
  this.renderer.setProperty(nativeElement, 'dropTarget', this.dropzone_dir || null);
@@ -544,8 +546,9 @@ class DraggableDirective {
544
546
  var _a;
545
547
  const { target, dropzone } = event;
546
548
  const dropzoneElement = (dropzone === null || dropzone === void 0 ? void 0 : dropzone.target) || ((_a = target.dropTarget) === null || _a === void 0 ? void 0 : _a.el.nativeElement);
549
+ const scale = this.scale;
547
550
  const positionInDropTarget = target && dropzoneElement
548
- ? this.interactService.calculatePositionInElement(dropzoneElement, this.previewRef)
551
+ ? this.interactService.calculatePositionInElement(dropzoneElement, this.previewRef, scale)
549
552
  : null;
550
553
  return {
551
554
  interactEvent: event,
@@ -575,6 +578,7 @@ class DraggableDirective {
575
578
  initiateDragEvents(dragConfig, nativeElement) {
576
579
  return interact(nativeElement).draggable(Object.assign(Object.assign({}, dragConfig), { enabled: !(this.disabled || this.dragDisabled) }))
577
580
  .on('dragstart', (event) => {
581
+ var _a, _b, _c;
578
582
  const interaction = event.interaction;
579
583
  // check if we should append drag element to body
580
584
  if (this.enableDragDefault
@@ -592,8 +596,9 @@ class DraggableDirective {
592
596
  }
593
597
  this.addDragPropertiesToElement(this.previewRef);
594
598
  this.setDragStyles(this.previewRef);
595
- this.dragRoot.prepend(this.previewRef);
596
- const { x, y } = this.interactService.calculatePositionInElement(this.dragRoot, nativeElement);
599
+ this.dragRootEl.prepend(this.previewRef);
600
+ const scale = ((_a = this.account_for_scale_dir) === null || _a === void 0 ? void 0 : _a.scale) || ((_c = (_b = this.dragRoot) === null || _b === void 0 ? void 0 : _b.account_for_scale_dir) === null || _c === void 0 ? void 0 : _c.scale) || 1;
601
+ const { x, y } = this.interactService.calculatePositionInElement(this.dragRootEl, nativeElement, scale);
597
602
  this.interactService.updatePosition(this.interactableId, this.registryId, { x, y }, this.previewRef);
598
603
  if (!this.showPlaceholder) {
599
604
  this.renderer.setStyle(this.el.nativeElement, 'display', 'none');
@@ -621,10 +626,9 @@ class DraggableDirective {
621
626
  this.renderer.setStyle(this.el.nativeElement, 'display', '');
622
627
  this.dragEnd.emit(mappedEvent);
623
628
  if (this.el.nativeElement !== this.previewRef) {
624
- // we do this in a timeout, so that we don't
625
- // remove before the dropzone can get the boundingElementRect
629
+ // we do this in a timeout, so that we don't remove before the dropzone can get the boundingElementRect
626
630
  setTimeout(() => {
627
- this.dragRoot.removeChild(this.previewRef);
631
+ this.dragRootEl.removeChild(this.previewRef);
628
632
  });
629
633
  }
630
634
  });
@@ -697,6 +701,7 @@ class ResizableDirective {
697
701
  this._document = _document;
698
702
  this.interactService = interactService;
699
703
  this.renderer = renderer;
704
+ this.drag_root_dir = drag_root_dir;
700
705
  this.account_for_scale_dir = account_for_scale_dir;
701
706
  this.draggable_dir = draggable_dir;
702
707
  this.dropzone_dir = dropzone_dir;
@@ -711,7 +716,11 @@ class ResizableDirective {
711
716
  this.defaultConfig = {
712
717
  edges: { left: true, right: true, bottom: true, top: true }
713
718
  };
714
- this.dragRoot = ((_a = drag_root_dir === null || drag_root_dir === void 0 ? void 0 : drag_root_dir.el) === null || _a === void 0 ? void 0 : _a.nativeElement) || this._document.body;
719
+ this.dragRootEl = ((_a = drag_root_dir === null || drag_root_dir === void 0 ? void 0 : drag_root_dir.el) === null || _a === void 0 ? void 0 : _a.nativeElement) || this._document.body;
720
+ }
721
+ get scale() {
722
+ var _a, _b;
723
+ return ((_a = this.account_for_scale_dir) === null || _a === void 0 ? void 0 : _a.scale) || ((_b = this.drag_root_dir) === null || _b === void 0 ? void 0 : _b.account_for_scale_dir.scale);
715
724
  }
716
725
  ngOnInit() {
717
726
  var _a, _b;
@@ -740,9 +749,23 @@ class ResizableDirective {
740
749
  this.interactService.destroyInteractable(this.interactableId, this.registryId);
741
750
  }
742
751
  resizeListener(event) {
743
- const deltaX = event.deltaRect.left;
744
- const deltaY = event.deltaRect.top;
745
- const { width, height } = event.rect;
752
+ const scale = this.scale;
753
+ let deltaX;
754
+ let deltaY;
755
+ let height;
756
+ let width;
757
+ if (scale) {
758
+ deltaX = event.deltaRect.left / scale;
759
+ deltaY = event.deltaRect.top / scale;
760
+ height = event.rect.height / scale;
761
+ width = event.rect.width / scale;
762
+ }
763
+ else {
764
+ deltaX = event.deltaRect.left;
765
+ deltaY = event.deltaRect.top;
766
+ width = event.rect.width;
767
+ height = event.rect.height;
768
+ }
746
769
  this.interactService.updateSize(this.interactableId, this.registryId, { deltaX, deltaY, width, height }, this.el.nativeElement);
747
770
  }
748
771
  /**
@@ -769,16 +792,16 @@ class ResizableDirective {
769
792
  .on('resizeend', (event) => this.resizeEnd.emit(this.mapResizeEvent(event)));
770
793
  }
771
794
  mapResizeEvent(event) {
772
- var _a, _b;
773
- const { target } = event;
795
+ var _a, _b, _c, _d, _e;
796
+ const target = event.target;
774
797
  const relatedTarget = (_b = (_a = this.draggable_dir) === null || _a === void 0 ? void 0 : _a.dropzone_dir) === null || _b === void 0 ? void 0 : _b.el.nativeElement;
798
+ const scale = ((_c = this.account_for_scale_dir) === null || _c === void 0 ? void 0 : _c.scale) || ((_e = (_d = this.drag_root_dir) === null || _d === void 0 ? void 0 : _d.account_for_scale_dir) === null || _e === void 0 ? void 0 : _e.scale) || 1;
775
799
  const positionInDropTarget = target && relatedTarget
776
- ? this.interactService.calculatePositionInElement(relatedTarget, target)
800
+ ? this.interactService.calculatePositionInElement(relatedTarget, target, scale)
777
801
  : null;
778
802
  return {
779
803
  interactEvent: event,
780
804
  resizeRef: this,
781
- // should I remove this?
782
805
  dragRef: this.draggable_dir,
783
806
  dragOrigin: this.dropzone_dir,
784
807
  dropTarget: this.el.nativeElement.dropTarget,
@@ -909,20 +932,14 @@ GesturableDirective.propDecorators = {
909
932
  class ApplyScaleDirective {
910
933
  constructor(el) {
911
934
  this.el = el;
912
- this.scaleX = 1;
913
- this.scaleY = 1;
914
- this.transformOrigin = '0 0';
935
+ this._scale = 1;
915
936
  }
916
937
  // this setup allows consumers to set x, y scale independently or just set them both with scale
917
938
  set scale(val) {
918
- this.scaleY = val;
919
- this.scaleX = val;
939
+ this._scale;
940
+ this.fontSize = `${val}px`;
920
941
  }
921
942
  ;
922
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
923
- ngOnChanges(_changes) {
924
- this.transform = `scaleX(${this.scaleX}) scaleY(${this.scaleY})`;
925
- }
926
943
  }
927
944
  ApplyScaleDirective.decorators = [
928
945
  { type: Directive, args: [{
@@ -934,10 +951,7 @@ ApplyScaleDirective.ctorParameters = () => [
934
951
  ];
935
952
  ApplyScaleDirective.propDecorators = {
936
953
  scale: [{ type: Input }],
937
- scaleX: [{ type: Input }],
938
- scaleY: [{ type: Input }],
939
- transform: [{ type: HostBinding, args: ['style.transform',] }],
940
- transformOrigin: [{ type: Input }, { type: HostBinding, args: ['style.transformOrigin',] }]
954
+ fontSize: [{ type: HostBinding, args: ['style.fontSize',] }]
941
955
  };
942
956
 
943
957
  const EXPORTS = [
@@ -952,10 +966,21 @@ const EXPORTS = [
952
966
  ArrayOfNPipe,
953
967
  ];
954
968
  class InteractModule {
969
+ static forRoot(config) {
970
+ const defaultConfig = { cssDimensionUnit: 'px' };
971
+ return {
972
+ ngModule: InteractModule,
973
+ providers: [
974
+ { provide: INTERACT_ROOT_CONFIG, useValue: Object.assign(Object.assign({}, defaultConfig), config) },
975
+ InteractService
976
+ ]
977
+ };
978
+ }
955
979
  }
956
980
  InteractModule.decorators = [
957
981
  { type: NgModule, args: [{
958
982
  imports: [CommonModule],
983
+ // providers: [{ provide: INTERACT_ROOT_CONFIG, useValue: 'px' }],
959
984
  declarations: [
960
985
  ...EXPORTS,
961
986
  ],
@@ -969,5 +994,5 @@ InteractModule.decorators = [
969
994
  * Generated bundle index. Do not edit.
970
995
  */
971
996
 
972
- export { AccountForScaleDirective, ApplyScaleDirective, ArrayOfNPipe, DEFAULT_REGISTRY_ID, DragPreviewDirective, DragRootDirective, DraggableDirective, DropzoneDirective, GesturableDirective, InteractModule, ResizableDirective, TFT_DRAG_PREVIEW, cloneElement$1 as cloneElement, defaultDelta, defaultPosition, defaultSize, getClosestMatchingAncestor, getRootNode, DraggableDirective as ɵa, ResizableDirective as ɵb, DropzoneDirective as ɵc, GesturableDirective as ɵd, DragRootDirective as ɵe, AccountForScaleDirective as ɵf, ApplyScaleDirective as ɵg, DragPreviewDirective as ɵh, ArrayOfNPipe as ɵi };
997
+ export { AccountForScaleDirective, ApplyScaleDirective, ArrayOfNPipe, DEFAULT_REGISTRY_ID, DragPreviewDirective, DragRootDirective, DraggableDirective, DropzoneDirective, GesturableDirective, INTERACT_ROOT_CONFIG, InteractModule, ResizableDirective, TFT_DRAG_PREVIEW, cloneElement$1 as cloneElement, defaultDelta, defaultPosition, defaultSize, getClosestMatchingAncestor, getRootNode, DraggableDirective as ɵa, ResizableDirective as ɵb, DropzoneDirective as ɵc, GesturableDirective as ɵd, DragRootDirective as ɵe, AccountForScaleDirective as ɵf, ApplyScaleDirective as ɵg, DragPreviewDirective as ɵh, ArrayOfNPipe as ɵi };
973
998
  //# sourceMappingURL=tft-interact.js.map