@stemy/ngx-utils 19.4.10 → 19.4.12

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.
@@ -1907,57 +1907,58 @@ class JSONfn {
1907
1907
  }
1908
1908
 
1909
1909
  class LoaderUtils {
1910
- static { this.scriptPromises = {}; }
1911
- static { this.stylePromises = {}; }
1910
+ static { this.promises = {}; }
1912
1911
  static loadScript(src, async = false, type = "text/javascript", parent) {
1913
- this.scriptPromises[src] = this.scriptPromises[src] || new Promise((resolve, reject) => {
1914
- // Load script
1912
+ return LoaderUtils.loadElement(src, parent, () => {
1913
+ const time = new Date().getTime();
1915
1914
  const script = document.createElement("script");
1916
1915
  script.type = type;
1917
- script.src = src;
1916
+ script.src = `${src}?time=${time}`;
1918
1917
  script.async = async;
1919
- if (script.readyState) {
1920
- // Internet explorer
1921
- script.onreadystatechange = () => {
1922
- if (script.readyState === "loaded" || script.readyState === "complete") {
1923
- script.onreadystatechange = null;
1924
- resolve(script);
1925
- }
1926
- };
1927
- }
1928
- else {
1929
- // Other browsers
1930
- script.onload = () => resolve(script);
1931
- }
1932
- script.onerror = (error) => reject(error);
1933
- (parent || document.body).appendChild(script);
1918
+ return script;
1934
1919
  });
1935
- return this.scriptPromises[src];
1936
1920
  }
1937
1921
  static loadStyle(src, parent) {
1938
- this.stylePromises[src] = this.stylePromises[src] || new Promise((resolve, reject) => {
1939
- // Load script
1922
+ return LoaderUtils.loadElement(src, parent, () => {
1923
+ const time = new Date().getTime();
1940
1924
  const link = document.createElement("link");
1941
1925
  link.rel = "stylesheet";
1942
1926
  link.type = "text/css";
1943
- link.href = src;
1944
- if (link.readyState) {
1927
+ link.href = `${src}?time=${time}`;
1928
+ return link;
1929
+ });
1930
+ }
1931
+ static loadElement(src, parent, setup) {
1932
+ const promises = LoaderUtils.promises;
1933
+ parent = parent || document.body;
1934
+ let { elem, promise } = promises[src] || {};
1935
+ if (elem) {
1936
+ if (parent === elem.parentElement)
1937
+ return promise;
1938
+ if (elem.parentElement) {
1939
+ elem.remove();
1940
+ }
1941
+ }
1942
+ elem = setup();
1943
+ promise = new Promise((resolve, reject) => {
1944
+ if (elem.readyState) {
1945
1945
  // Internet explorer
1946
- link.onreadystatechange = () => {
1947
- if (link.readyState === "loaded" || link.readyState === "complete") {
1948
- link.onreadystatechange = null;
1949
- resolve(link);
1946
+ elem.onreadystatechange = () => {
1947
+ if (elem.readyState === "loaded" || elem.readyState === "complete") {
1948
+ elem.onreadystatechange = null;
1949
+ resolve(elem);
1950
1950
  }
1951
1951
  };
1952
1952
  }
1953
1953
  else {
1954
1954
  // Other browsers
1955
- link.onload = () => resolve(link);
1955
+ elem.onload = () => resolve(elem);
1956
1956
  }
1957
- link.onerror = (error) => reject(error);
1958
- (parent || document.body).appendChild(link);
1957
+ elem.onerror = (error) => reject(error);
1959
1958
  });
1960
- return this.stylePromises[src];
1959
+ parent.appendChild(elem);
1960
+ promises[src] = { elem, promise };
1961
+ return promise;
1961
1962
  }
1962
1963
  }
1963
1964
 
@@ -6904,7 +6905,7 @@ class InteractiveItemComponent {
6904
6905
  this.pos = new Point(this.pos.x, value);
6905
6906
  }
6906
6907
  set position(value) {
6907
- if (typeof value !== "object" || isNaN(value.x) || isNaN(value.y))
6908
+ if (typeof value !== "object" || isNaN(value.x) || isNaN(value.y) || value === this.pos)
6908
6909
  return;
6909
6910
  this.pos = new Point(value.x, value.y);
6910
6911
  }
@@ -6933,34 +6934,27 @@ class InteractiveItemComponent {
6933
6934
  this.onPanEnd = new EventEmitter();
6934
6935
  this.active = false;
6935
6936
  this.index = -1;
6936
- this.basePan = 0;
6937
+ this.cycles = [0];
6937
6938
  this.pos = Point.Zero;
6938
6939
  this.rotation = 0;
6939
6940
  this.direction = "none";
6940
6941
  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;
6942
+ this.subscription = ObservableUtils.multiSubscription(this.onPan.subscribe(ev => {
6947
6943
  switch (this.direction) {
6948
6944
  case "free":
6949
- this.x += dx;
6950
- this.y += dy;
6945
+ this.x += ev.deltaX;
6946
+ this.y += ev.deltaY;
6951
6947
  break;
6952
6948
  case "horizontal":
6953
- this.x += dx;
6949
+ this.x += ev.deltaX;
6954
6950
  break;
6955
6951
  case "vertical":
6956
- this.y += dy;
6952
+ this.y += ev.deltaY;
6957
6953
  break;
6958
6954
  }
6959
6955
  if (this.direction !== "none") {
6960
6956
  this.calcShapes();
6961
6957
  }
6962
- this.deltaX = ev.deltaX;
6963
- this.deltaY = ev.deltaY;
6964
6958
  }));
6965
6959
  }
6966
6960
  ngOnDestroy() {
@@ -6969,13 +6963,13 @@ class InteractiveItemComponent {
6969
6963
  ngOnChanges() {
6970
6964
  this.calcShapes();
6971
6965
  }
6972
- calcShapes(basePan) {
6966
+ calcShapes(cycles) {
6973
6967
  const canvas = this.canvas;
6974
6968
  const ratio = canvas.ratio;
6975
6969
  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;
6970
+ this.cycles = cycles ?? this.cycles;
6971
+ this.mShapes = this.cycles.map(pan => {
6972
+ const y = this.pos.y * ratio + pan;
6979
6973
  return this.calcShape(x, y);
6980
6974
  });
6981
6975
  }
@@ -7031,6 +7025,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.5", ngImpor
7031
7025
  }] } });
7032
7026
 
7033
7027
  class InteractiveCanvasComponent {
7028
+ get selectedItem() {
7029
+ return this.items[this.selectedIndex];
7030
+ }
7031
+ get hoveredItem() {
7032
+ return this.items[this.hoveredIndex];
7033
+ }
7034
+ get lockedItem() {
7035
+ return this.items[this.lockedIndex];
7036
+ }
7034
7037
  constructor(renderer) {
7035
7038
  this.renderer = renderer;
7036
7039
  this.horizontal = false;
@@ -7044,11 +7047,11 @@ class InteractiveCanvasComponent {
7044
7047
  this.rotation = 0;
7045
7048
  this.canvasWidth = 0;
7046
7049
  this.canvasHeight = 0;
7047
- this.hoveredItem = null;
7048
- this.selectedItem = null;
7050
+ this.hoveredIndex = null;
7049
7051
  this.items = [];
7050
7052
  this.touched = false;
7051
- this.panFrom = 0;
7053
+ this.deltaX = 0;
7054
+ this.deltaY = 0;
7052
7055
  }
7053
7056
  ngOnInit() {
7054
7057
  this.redraw();
@@ -7087,7 +7090,7 @@ class InteractiveCanvasComponent {
7087
7090
  this.fixPan();
7088
7091
  }
7089
7092
  onTouchStart($event) {
7090
- this.hoveredItem = this.getItemUnderPointer($event.touches.item(0));
7093
+ this.hoveredIndex = this.getIndexUnderPointer($event.touches.item(0));
7091
7094
  this.touched = true;
7092
7095
  }
7093
7096
  onTouchEnd($event) {
@@ -7102,45 +7105,51 @@ class InteractiveCanvasComponent {
7102
7105
  onMouseMove($event) {
7103
7106
  if (this.touched)
7104
7107
  return;
7105
- this.hoveredItem = this.getItemUnderPointer($event);
7108
+ this.hoveredIndex = this.getIndexUnderPointer($event);
7106
7109
  this.updateCursor();
7107
7110
  }
7108
7111
  onMouseLeave() {
7109
- this.hoveredItem = null;
7112
+ this.hoveredIndex = null;
7110
7113
  this.updateCursor();
7111
7114
  }
7112
7115
  onPanStart($event) {
7113
- this.lockedItem = this.getItemUnderPointer($event?.pointers[0]);
7116
+ this.lockedIndex = this.getIndexUnderPointer($event?.pointers[0]);
7114
7117
  this.lockedItem?.onPanStart.emit({
7115
7118
  pointers: [],
7116
7119
  deltaX: 0,
7117
7120
  deltaY: 0,
7118
7121
  item: this.lockedItem
7119
7122
  });
7120
- this.panFrom = this.pan;
7123
+ this.deltaX = 0;
7124
+ this.deltaY = 0;
7121
7125
  }
7122
7126
  onPan($event) {
7123
- if (this.lockedItem) {
7127
+ const item = this.lockedItem;
7128
+ const deltaX = ($event.deltaX - this.deltaX) / this.ratio;
7129
+ const deltaY = ($event.deltaY - this.deltaY) / this.ratio;
7130
+ if (item) {
7124
7131
  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;
7132
+ ? { pointers: $event.pointers, deltaX: -deltaY, deltaY: +deltaX }
7133
+ : { pointers: $event.pointers, deltaX, deltaY };
7134
+ data.item = item;
7135
+ item.onPan.emit(data);
7136
+ }
7137
+ else if (this.resizeMode == "fill") {
7138
+ this.pan += this.horizontal ? deltaX : deltaY;
7139
+ this.fixPan();
7130
7140
  }
7131
- // if (this.useCanvasRatio) return;
7132
- // this.pan = this.panFrom + (this.horizontal ? $event.deltaX : $event.deltaY);
7133
- // this.fixPan();
7141
+ this.deltaX = $event.deltaX;
7142
+ this.deltaY = $event.deltaY;
7134
7143
  }
7135
7144
  onPanEnd() {
7136
- this.lockedItem?.onPanEnd.emit({
7145
+ const item = this.lockedItem;
7146
+ item?.onPanEnd.emit({
7137
7147
  pointers: [],
7138
7148
  deltaX: 0,
7139
7149
  deltaY: 0,
7140
- item: this.lockedItem
7150
+ item
7141
7151
  });
7142
- this.lockedItem = null;
7143
- this.panFrom = this.pan;
7152
+ this.lockedIndex = -1;
7144
7153
  }
7145
7154
  fixPan() {
7146
7155
  if (this.fullHeight <= 0)
@@ -7153,8 +7162,9 @@ class InteractiveCanvasComponent {
7153
7162
  }
7154
7163
  this.rotation = Math.round(this.pan / this.fullHeight * 360);
7155
7164
  const basePan = (this.rotation / 360 - 1) * this.fullHeight;
7165
+ const cycles = this.resizeMode == "fit" ? [0] : [basePan - this.fullHeight, basePan, basePan + this.fullHeight];
7156
7166
  this.items.forEach(item => {
7157
- item.calcShapes(basePan);
7167
+ item.calcShapes(cycles);
7158
7168
  });
7159
7169
  }
7160
7170
  fixItems() {
@@ -7165,29 +7175,32 @@ class InteractiveCanvasComponent {
7165
7175
  this.fixPan();
7166
7176
  }
7167
7177
  selectItem(pointer) {
7168
- const selected = this.getItemUnderPointer(pointer);
7178
+ const selected = this.getIndexUnderPointer(pointer);
7169
7179
  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);
7180
+ if (selected !== this.selectedIndex) {
7181
+ this.selectedIndex = selected;
7175
7182
  this.selectedIndexChange.emit(this.selectedIndex);
7183
+ const item = this.selectedItem;
7184
+ if (!item)
7185
+ return;
7186
+ item.active = !item.active;
7176
7187
  }
7177
7188
  }
7178
- getItemUnderPointer(pointer) {
7189
+ getIndexUnderPointer(pointer) {
7179
7190
  if (!pointer || !this.canvasElem || !this.items)
7180
7191
  return null;
7181
7192
  const canvasRect = this.canvasElem.nativeElement.getBoundingClientRect();
7182
7193
  const point = this.horizontal
7183
7194
  ? new Point(canvasRect.bottom - pointer.clientY, pointer.clientX - canvasRect.left)
7184
7195
  : new Point(pointer.clientX - canvasRect.left, pointer.clientY - canvasRect.top);
7185
- for (const item of this.items) {
7196
+ const length = this.items.length;
7197
+ for (let ix = 0; ix < length; ix++) {
7198
+ const item = this.items[ix];
7186
7199
  if (item?.hit(point)) {
7187
- return item.disabled ? null : item;
7200
+ return item.disabled ? null : ix;
7188
7201
  }
7189
7202
  }
7190
- return null;
7203
+ return -1;
7191
7204
  }
7192
7205
  updateCursor() {
7193
7206
  const cursor = this.getCursor();
@@ -7195,9 +7208,10 @@ class InteractiveCanvasComponent {
7195
7208
  this.renderer.setStyle(this.containerElem.nativeElement, "cursor", cursor);
7196
7209
  }
7197
7210
  getCursor() {
7198
- if (!this.hoveredItem)
7211
+ const hovered = this.hoveredItem;
7212
+ if (!hovered)
7199
7213
  return "default";
7200
- switch (this.hoveredItem.direction) {
7214
+ switch (hovered.direction) {
7201
7215
  case "free":
7202
7216
  return "all-scroll";
7203
7217
  case "horizontal":