@stemy/ngx-utils 19.4.10 → 19.4.11

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.
@@ -6904,7 +6904,7 @@ class InteractiveItemComponent {
6904
6904
  this.pos = new Point(this.pos.x, value);
6905
6905
  }
6906
6906
  set position(value) {
6907
- if (typeof value !== "object" || isNaN(value.x) || isNaN(value.y))
6907
+ if (typeof value !== "object" || isNaN(value.x) || isNaN(value.y) || value === this.pos)
6908
6908
  return;
6909
6909
  this.pos = new Point(value.x, value.y);
6910
6910
  }
@@ -6933,34 +6933,27 @@ class InteractiveItemComponent {
6933
6933
  this.onPanEnd = new EventEmitter();
6934
6934
  this.active = false;
6935
6935
  this.index = -1;
6936
- this.basePan = 0;
6936
+ this.cycles = [0];
6937
6937
  this.pos = Point.Zero;
6938
6938
  this.rotation = 0;
6939
6939
  this.direction = "none";
6940
6940
  this.mShapes = [];
6941
- this.subscription = ObservableUtils.multiSubscription(this.onPanStart.subscribe(() => {
6942
- this.deltaX = 0;
6943
- this.deltaY = 0;
6944
- }), this.onPan.subscribe(ev => {
6945
- const dx = ev.deltaX - this.deltaX;
6946
- const dy = ev.deltaY - this.deltaY;
6941
+ this.subscription = ObservableUtils.multiSubscription(this.onPan.subscribe(ev => {
6947
6942
  switch (this.direction) {
6948
6943
  case "free":
6949
- this.x += dx;
6950
- this.y += dy;
6944
+ this.x += ev.deltaX;
6945
+ this.y += ev.deltaY;
6951
6946
  break;
6952
6947
  case "horizontal":
6953
- this.x += dx;
6948
+ this.x += ev.deltaX;
6954
6949
  break;
6955
6950
  case "vertical":
6956
- this.y += dy;
6951
+ this.y += ev.deltaY;
6957
6952
  break;
6958
6953
  }
6959
6954
  if (this.direction !== "none") {
6960
6955
  this.calcShapes();
6961
6956
  }
6962
- this.deltaX = ev.deltaX;
6963
- this.deltaY = ev.deltaY;
6964
6957
  }));
6965
6958
  }
6966
6959
  ngOnDestroy() {
@@ -6969,13 +6962,13 @@ class InteractiveItemComponent {
6969
6962
  ngOnChanges() {
6970
6963
  this.calcShapes();
6971
6964
  }
6972
- calcShapes(basePan) {
6965
+ calcShapes(cycles) {
6973
6966
  const canvas = this.canvas;
6974
6967
  const ratio = canvas.ratio;
6975
6968
  const x = this.pos.x * ratio;
6976
- this.basePan = basePan ?? this.basePan;
6977
- this.mShapes = [0, 1, 2].map(cycle => {
6978
- const y = this.pos.y * ratio + this.basePan + cycle * canvas.fullHeight;
6969
+ this.cycles = cycles ?? this.cycles;
6970
+ this.mShapes = this.cycles.map(pan => {
6971
+ const y = this.pos.y * ratio + pan;
6979
6972
  return this.calcShape(x, y);
6980
6973
  });
6981
6974
  }
@@ -7031,6 +7024,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.5", ngImpor
7031
7024
  }] } });
7032
7025
 
7033
7026
  class InteractiveCanvasComponent {
7027
+ get selectedItem() {
7028
+ return this.items[this.selectedIndex];
7029
+ }
7030
+ get hoveredItem() {
7031
+ return this.items[this.hoveredIndex];
7032
+ }
7033
+ get lockedItem() {
7034
+ return this.items[this.lockedIndex];
7035
+ }
7034
7036
  constructor(renderer) {
7035
7037
  this.renderer = renderer;
7036
7038
  this.horizontal = false;
@@ -7044,11 +7046,11 @@ class InteractiveCanvasComponent {
7044
7046
  this.rotation = 0;
7045
7047
  this.canvasWidth = 0;
7046
7048
  this.canvasHeight = 0;
7047
- this.hoveredItem = null;
7048
- this.selectedItem = null;
7049
+ this.hoveredIndex = null;
7049
7050
  this.items = [];
7050
7051
  this.touched = false;
7051
- this.panFrom = 0;
7052
+ this.deltaX = 0;
7053
+ this.deltaY = 0;
7052
7054
  }
7053
7055
  ngOnInit() {
7054
7056
  this.redraw();
@@ -7087,7 +7089,7 @@ class InteractiveCanvasComponent {
7087
7089
  this.fixPan();
7088
7090
  }
7089
7091
  onTouchStart($event) {
7090
- this.hoveredItem = this.getItemUnderPointer($event.touches.item(0));
7092
+ this.hoveredIndex = this.getIndexUnderPointer($event.touches.item(0));
7091
7093
  this.touched = true;
7092
7094
  }
7093
7095
  onTouchEnd($event) {
@@ -7102,45 +7104,51 @@ class InteractiveCanvasComponent {
7102
7104
  onMouseMove($event) {
7103
7105
  if (this.touched)
7104
7106
  return;
7105
- this.hoveredItem = this.getItemUnderPointer($event);
7107
+ this.hoveredIndex = this.getIndexUnderPointer($event);
7106
7108
  this.updateCursor();
7107
7109
  }
7108
7110
  onMouseLeave() {
7109
- this.hoveredItem = null;
7111
+ this.hoveredIndex = null;
7110
7112
  this.updateCursor();
7111
7113
  }
7112
7114
  onPanStart($event) {
7113
- this.lockedItem = this.getItemUnderPointer($event?.pointers[0]);
7115
+ this.lockedIndex = this.getIndexUnderPointer($event?.pointers[0]);
7114
7116
  this.lockedItem?.onPanStart.emit({
7115
7117
  pointers: [],
7116
7118
  deltaX: 0,
7117
7119
  deltaY: 0,
7118
7120
  item: this.lockedItem
7119
7121
  });
7120
- this.panFrom = this.pan;
7122
+ this.deltaX = 0;
7123
+ this.deltaY = 0;
7121
7124
  }
7122
7125
  onPan($event) {
7123
- if (this.lockedItem) {
7126
+ const item = this.lockedItem;
7127
+ const deltaX = ($event.deltaX - this.deltaX) / this.ratio;
7128
+ const deltaY = ($event.deltaY - this.deltaY) / this.ratio;
7129
+ if (item) {
7124
7130
  const data = this.horizontal
7125
- ? { pointers: $event.pointers, deltaX: -$event.deltaY / this.ratio, deltaY: $event.deltaX / this.ratio }
7126
- : { pointers: $event.pointers, deltaX: $event.deltaX / this.ratio, deltaY: $event.deltaY / this.ratio };
7127
- data.item = this.lockedItem;
7128
- this.lockedItem.onPan.emit(data);
7129
- return;
7131
+ ? { pointers: $event.pointers, deltaX: -deltaY, deltaY: +deltaX }
7132
+ : { pointers: $event.pointers, deltaX, deltaY };
7133
+ data.item = item;
7134
+ item.onPan.emit(data);
7130
7135
  }
7131
- // if (this.useCanvasRatio) return;
7132
- // this.pan = this.panFrom + (this.horizontal ? $event.deltaX : $event.deltaY);
7133
- // this.fixPan();
7136
+ else if (this.resizeMode == "fill") {
7137
+ this.pan += this.horizontal ? deltaX : deltaY;
7138
+ this.fixPan();
7139
+ }
7140
+ this.deltaX = $event.deltaX;
7141
+ this.deltaY = $event.deltaY;
7134
7142
  }
7135
7143
  onPanEnd() {
7136
- this.lockedItem?.onPanEnd.emit({
7144
+ const item = this.lockedItem;
7145
+ item?.onPanEnd.emit({
7137
7146
  pointers: [],
7138
7147
  deltaX: 0,
7139
7148
  deltaY: 0,
7140
- item: this.lockedItem
7149
+ item
7141
7150
  });
7142
- this.lockedItem = null;
7143
- this.panFrom = this.pan;
7151
+ this.lockedIndex = -1;
7144
7152
  }
7145
7153
  fixPan() {
7146
7154
  if (this.fullHeight <= 0)
@@ -7153,8 +7161,9 @@ class InteractiveCanvasComponent {
7153
7161
  }
7154
7162
  this.rotation = Math.round(this.pan / this.fullHeight * 360);
7155
7163
  const basePan = (this.rotation / 360 - 1) * this.fullHeight;
7164
+ const cycles = this.resizeMode == "fit" ? [0] : [basePan - this.fullHeight, basePan, basePan + this.fullHeight];
7156
7165
  this.items.forEach(item => {
7157
- item.calcShapes(basePan);
7166
+ item.calcShapes(cycles);
7158
7167
  });
7159
7168
  }
7160
7169
  fixItems() {
@@ -7165,29 +7174,32 @@ class InteractiveCanvasComponent {
7165
7174
  this.fixPan();
7166
7175
  }
7167
7176
  selectItem(pointer) {
7168
- const selected = this.getItemUnderPointer(pointer);
7177
+ const selected = this.getIndexUnderPointer(pointer);
7169
7178
  this.touched = false;
7170
- this.selectedItem = selected;
7171
- if (selected) {
7172
- selected.active = !selected.active;
7173
- const items = Array.from(this.items);
7174
- this.selectedIndex = items.indexOf(selected);
7179
+ if (selected !== this.selectedIndex) {
7180
+ this.selectedIndex = selected;
7175
7181
  this.selectedIndexChange.emit(this.selectedIndex);
7182
+ const item = this.selectedItem;
7183
+ if (!item)
7184
+ return;
7185
+ item.active = !item.active;
7176
7186
  }
7177
7187
  }
7178
- getItemUnderPointer(pointer) {
7188
+ getIndexUnderPointer(pointer) {
7179
7189
  if (!pointer || !this.canvasElem || !this.items)
7180
7190
  return null;
7181
7191
  const canvasRect = this.canvasElem.nativeElement.getBoundingClientRect();
7182
7192
  const point = this.horizontal
7183
7193
  ? new Point(canvasRect.bottom - pointer.clientY, pointer.clientX - canvasRect.left)
7184
7194
  : new Point(pointer.clientX - canvasRect.left, pointer.clientY - canvasRect.top);
7185
- for (const item of this.items) {
7195
+ const length = this.items.length;
7196
+ for (let ix = 0; ix < length; ix++) {
7197
+ const item = this.items[ix];
7186
7198
  if (item?.hit(point)) {
7187
- return item.disabled ? null : item;
7199
+ return item.disabled ? null : ix;
7188
7200
  }
7189
7201
  }
7190
- return null;
7202
+ return -1;
7191
7203
  }
7192
7204
  updateCursor() {
7193
7205
  const cursor = this.getCursor();
@@ -7195,9 +7207,10 @@ class InteractiveCanvasComponent {
7195
7207
  this.renderer.setStyle(this.containerElem.nativeElement, "cursor", cursor);
7196
7208
  }
7197
7209
  getCursor() {
7198
- if (!this.hoveredItem)
7210
+ const hovered = this.hoveredItem;
7211
+ if (!hovered)
7199
7212
  return "default";
7200
- switch (this.hoveredItem.direction) {
7213
+ switch (hovered.direction) {
7201
7214
  case "free":
7202
7215
  return "all-scroll";
7203
7216
  case "horizontal":