@seniorsistemas/angular-components 17.16.3 → 17.16.5

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.
@@ -17832,13 +17832,16 @@
17832
17832
  __decorate([
17833
17833
  core.Input()
17834
17834
  ], PanelComponent.prototype, "borderButtonOptions", void 0);
17835
+ __decorate([
17836
+ core.Input()
17837
+ ], PanelComponent.prototype, "class", void 0);
17835
17838
  __decorate([
17836
17839
  core.Output()
17837
17840
  ], PanelComponent.prototype, "collapsedChange", void 0);
17838
17841
  PanelComponent = __decorate([
17839
17842
  core.Component({
17840
17843
  selector: "s-panel",
17841
- template: "<div\n class=\"panel\"\n [ngClass]=\"{\n 'panel--success': severity === EnumSeverity.Success,\n 'panel--info': severity === EnumSeverity.Info,\n 'panel--warn': severity === EnumSeverity.Warn,\n 'panel--error': severity === EnumSeverity.Error,\n 'panel--collapsed': collapsed\n }\">\n <s-border-button\n *ngIf=\"\n borderButtonOptions?.visible\n ? borderButtonOptions?.visible(severity)\n : false\n \"\n [severity]=\"severity\"\n [options]=\"borderButtonOptions\"\n class=\"border-button\"\n [@BorderButtonAnimation]\n ></s-border-button>\n\n <div class=\"header\">\n <ng-container *ngIf=\"headerTemplate; then customHeaderTemplate; else simpleHeaderTemplate\"></ng-container>\n <ng-template #customHeaderTemplate>\n <ng-container *ngTemplateOutlet=\"headerTemplate\"></ng-container>\n </ng-template>\n <ng-template #simpleHeaderTemplate>\n <span>{{ header }}</span>\n </ng-template>\n\n <button\n *ngIf=\"collapsable\"\n class=\"collapse-button fas\"\n [ngClass]=\"{\n 'fa-plus': collapsed,\n 'fa-minus': !collapsed\n }\"\n (click)=\"toggleCollapsed()\">\n </button>\n </div>\n <div *ngIf=\"!collapsable || !collapsed\" class=\"panel-content\">\n <div class=\"body\">\n <ng-content></ng-content>\n <ng-container *ngTemplateOutlet=\"bodyTemplate\"></ng-container>\n </div>\n <div *ngIf=\"footerTemplate\" class=\"footer\">\n <ng-container *ngTemplateOutlet=\"footerTemplate\"></ng-container>\n </div>\n </div>\n</div>",
17844
+ template: "<div\n class=\"panel\"\n [ngClass]=\"[\n class,\n {\n 'panel--success': severity === EnumSeverity.Success,\n 'panel--info': severity === EnumSeverity.Info,\n 'panel--warn': severity === EnumSeverity.Warn,\n 'panel--error': severity === EnumSeverity.Error,\n 'panel--collapsed': collapsed\n }\n ]\">\n <s-border-button\n *ngIf=\"borderButtonOptions?.visible ? borderButtonOptions?.visible(severity) : false\"\n [severity]=\"severity\"\n [options]=\"borderButtonOptions\"\n class=\"border-button\"\n [@BorderButtonAnimation]>\n </s-border-button>\n\n <div class=\"header\">\n <ng-container *ngIf=\"headerTemplate; then customHeaderTemplate; else simpleHeaderTemplate\"></ng-container>\n <ng-template #customHeaderTemplate>\n <ng-container *ngTemplateOutlet=\"headerTemplate\"></ng-container>\n </ng-template>\n <ng-template #simpleHeaderTemplate>\n <span>{{ header }}</span>\n </ng-template>\n\n <button\n *ngIf=\"collapsable\"\n class=\"collapse-button fas\"\n [ngClass]=\"{\n 'fa-plus': collapsed,\n 'fa-minus': !collapsed\n }\"\n (click)=\"toggleCollapsed()\">\n </button>\n </div>\n <div *ngIf=\"!collapsable || !collapsed\" class=\"panel-content\">\n <div class=\"body\">\n <ng-content></ng-content>\n <ng-container *ngTemplateOutlet=\"bodyTemplate\"></ng-container>\n </div>\n <div *ngIf=\"footerTemplate\" class=\"footer\">\n <ng-container *ngTemplateOutlet=\"footerTemplate\"></ng-container>\n </div>\n </div>\n</div>",
17842
17845
  animations: [
17843
17846
  animations.trigger("BorderButtonAnimation", [
17844
17847
  animations.transition(":enter", [
@@ -18589,14 +18592,16 @@
18589
18592
  var SliderComponent = /** @class */ (function () {
18590
18593
  function SliderComponent() {
18591
18594
  var _this = this;
18595
+ this.MAX_RANGE_VALUE = 100;
18596
+ this.MIN_RANGE_VALUE = 0;
18592
18597
  this.multiple = false;
18593
18598
  this.value = 0;
18594
18599
  this.valueChange = new core.EventEmitter();
18595
18600
  this.step = 1;
18596
18601
  this.hiddenThumb = false;
18597
18602
  this.disabled = false;
18598
- this.min = 0;
18599
- this.max = 100;
18603
+ this.min = this.MIN_RANGE_VALUE;
18604
+ this.max = this.MAX_RANGE_VALUE;
18600
18605
  this.tabindex = 0;
18601
18606
  this.startValue = 0;
18602
18607
  this.endValue = 0;
@@ -18615,13 +18620,11 @@
18615
18620
  * @example
18616
18621
  * with min = -10 and max = 10 will have this map.
18617
18622
  * {
18618
- * -10: { left: 0, right: 10 },
18619
- * -9: { left: 11, right: 19 },
18623
+ * -10: { 0 },
18624
+ * -9: { 10 },
18620
18625
  * ...
18621
- * 10: { left: 90, right: 100 }
18626
+ * 10: { 10 }
18622
18627
  * }
18623
- * the left value represent value for startValue, the right value represent value for endValue
18624
- * left and right values ​​are used when applying percentages in the slider
18625
18628
  */
18626
18629
  this.mapRangeValuesForSlider = new Map();
18627
18630
  this.activeMouseDown = false;
@@ -18634,16 +18637,16 @@
18634
18637
  (_this.multiple && _this.draggingThumb === "end" && newPosition < _this.startValue)) {
18635
18638
  return;
18636
18639
  }
18637
- var positionInUserRange = _this.getUserValueFromSliderValueByMap(newPosition);
18640
+ var positionInUserRange = _this.getValueFromMapByValue(newPosition);
18638
18641
  if (_this.multiple) {
18639
18642
  if (_this.draggingThumb === "start") {
18640
18643
  _this.startValue = _this.needParseValues
18641
- ? _this.mapRangeValuesForSlider.get(positionInUserRange).left
18644
+ ? _this.mapRangeValuesForSlider.get(positionInUserRange)
18642
18645
  : newPosition;
18643
18646
  }
18644
18647
  else if (_this.draggingThumb === "end") {
18645
18648
  _this.endValue = _this.needParseValues
18646
- ? _this.mapRangeValuesForSlider.get(positionInUserRange).right
18649
+ ? _this.mapRangeValuesForSlider.get(positionInUserRange)
18647
18650
  : newPosition;
18648
18651
  }
18649
18652
  _this.setValue([_this.startValue, _this.endValue]);
@@ -18656,18 +18659,15 @@
18656
18659
  }
18657
18660
  }
18658
18661
  else {
18659
- var pickLeftValue = newPosition <= 50;
18660
- var pickRightValue = newPosition > 50;
18661
- if (pickLeftValue) {
18662
- _this.endValue = _this.needParseValues
18663
- ? _this.mapRangeValuesForSlider.get(positionInUserRange).left
18664
- : newPosition;
18665
- }
18666
- else if (pickRightValue) {
18667
- _this.endValue = _this.needParseValues
18668
- ? _this.mapRangeValuesForSlider.get(positionInUserRange).right
18669
- : newPosition;
18662
+ var currentValue = _this.value;
18663
+ var _value = _this.needParseValues ? positionInUserRange : newPosition;
18664
+ var isAtSameValue = _this.needParseValues ? positionInUserRange === _this.value : false;
18665
+ var hasStep = _this.step !== 0;
18666
+ var newValueIsValidByStep = hasStep ? currentValue + _this.step === _value || currentValue - _this.step === _value : false;
18667
+ if (isAtSameValue && !newValueIsValidByStep) {
18668
+ return;
18670
18669
  }
18670
+ _this.endValue = _this.needParseValues ? _this.mapRangeValuesForSlider.get(positionInUserRange) : newPosition;
18671
18671
  _this.startValue = _this.endValue;
18672
18672
  _this.setValue(_this.endValue);
18673
18673
  }
@@ -18688,20 +18688,20 @@
18688
18688
  var startValueBeforeEvent = _this.startValueBeforeProgressBarEvent;
18689
18689
  var range = _this.rangeBetweenElementsBeforeProgressBarEvent;
18690
18690
  var _a = calculateNewRange(startValueBeforeEvent, startValueBeforeEvent + range, startPositionBeforeEvent, newCenter), newStart = _a.newStart, newEnd = _a.newEnd;
18691
- if (newStart < 0 || newEnd > 100) {
18691
+ if (newStart < _this.MIN_RANGE_VALUE || newEnd > _this.MAX_RANGE_VALUE) {
18692
18692
  return;
18693
18693
  }
18694
18694
  if (_this.needParseValues) {
18695
- var startValueBeforeEventUserRange = _this.getUserValueFromSliderValueByMap(startValueBeforeEvent);
18696
- var startPositionBeforeEventUserRange = _this.getUserValueFromSliderValueByMap(startPositionBeforeEvent);
18697
- var centerUserRange = _this.getUserValueFromSliderValueByMap(newCenter);
18695
+ var startValueBeforeEventUserRange = _this.getValueFromMapByValue(startValueBeforeEvent);
18696
+ var startPositionBeforeEventUserRange = _this.getValueFromMapByValue(startPositionBeforeEvent);
18697
+ var centerUserRange = _this.getValueFromMapByValue(newCenter);
18698
18698
  var valueRange = _this.totalRangeBeforeProgressBarEvent;
18699
18699
  var _b = calculateNewRange(startValueBeforeEventUserRange, startValueBeforeEventUserRange + valueRange, startPositionBeforeEventUserRange, centerUserRange), newStart_1 = _b.newStart, newEnd_1 = _b.newEnd;
18700
18700
  if (newStart_1 < _this.min || newEnd_1 > _this.max) {
18701
18701
  return;
18702
18702
  }
18703
- _this.startValue = _this.mapRangeValuesForSlider.get(newStart_1).left;
18704
- _this.endValue = _this.mapRangeValuesForSlider.get(newEnd_1).right;
18703
+ _this.startValue = _this.mapRangeValuesForSlider.get(newStart_1);
18704
+ _this.endValue = _this.mapRangeValuesForSlider.get(newEnd_1);
18705
18705
  }
18706
18706
  else {
18707
18707
  _this.startValue = newStart;
@@ -18724,8 +18724,15 @@
18724
18724
  }
18725
18725
  SliderComponent_1 = SliderComponent;
18726
18726
  SliderComponent.prototype.ngOnInit = function () {
18727
- if (this.needParseValues) {
18727
+ this.setUserRangeMapValues();
18728
+ };
18729
+ SliderComponent.prototype.ngOnChanges = function (changes) {
18730
+ var hasChangesOnMin = changes.min && !changes.min.firstChange;
18731
+ var hasChangesOnMax = changes.max && !changes.max.firstChange;
18732
+ var hasChanges = hasChangesOnMin || hasChangesOnMax;
18733
+ if (hasChanges) {
18728
18734
  this.setUserRangeMapValues();
18735
+ this.setRangeValues();
18729
18736
  }
18730
18737
  };
18731
18738
  SliderComponent.prototype.ngAfterViewInit = function () {
@@ -18748,14 +18755,16 @@
18748
18755
  };
18749
18756
  Object.defineProperty(SliderComponent.prototype, "tooltipStartText", {
18750
18757
  get: function () {
18751
- return (this.needParseValues ? this.getUserValueFromSliderValueByMap(this.startValue) : this.startValue).toString();
18758
+ var _a, _b;
18759
+ return Array.isArray(this.value) ? (_a = this.value[0]) === null || _a === void 0 ? void 0 : _a.toString() : (_b = this.value) === null || _b === void 0 ? void 0 : _b.toString();
18752
18760
  },
18753
18761
  enumerable: true,
18754
18762
  configurable: true
18755
18763
  });
18756
18764
  Object.defineProperty(SliderComponent.prototype, "tooltipEndText", {
18757
18765
  get: function () {
18758
- return (this.needParseValues ? this.getUserValueFromSliderValueByMap(this.endValue) : this.endValue).toString();
18766
+ var _a, _b;
18767
+ return Array.isArray(this.value) ? (_a = this.value[1]) === null || _a === void 0 ? void 0 : _a.toString() : (_b = this.value) === null || _b === void 0 ? void 0 : _b.toString();
18759
18768
  },
18760
18769
  enumerable: true,
18761
18770
  configurable: true
@@ -18784,11 +18793,11 @@
18784
18793
  return;
18785
18794
  }
18786
18795
  var trackClickPercentage = this.getPercentageByEvent(evt);
18787
- var trackClickToUserRange = this.getUserValueFromSliderValueByMap(trackClickPercentage);
18796
+ var trackClickToUserRange = this.getValueFromMapByValue(trackClickPercentage);
18788
18797
  var _trackClickValid = this.needParseValues ? trackClickToUserRange : trackClickPercentage;
18789
18798
  var _setEndValue = function () {
18790
- var _endValueUserValue = _this.getUserValueFromSliderValueByMap(_this.endValue);
18791
- var _endValue = _this.needParseValues ? _this.mapRangeValuesForSlider.get(trackClickToUserRange).right : trackClickPercentage;
18799
+ var _endValueUserValue = _this.getValueFromMapByValue(_this.endValue);
18800
+ var _endValue = _this.needParseValues ? _this.mapRangeValuesForSlider.get(trackClickToUserRange) : trackClickPercentage;
18792
18801
  if (_this.needParseValues && _endValueUserValue !== trackClickToUserRange) {
18793
18802
  _this.endValue = _endValue;
18794
18803
  }
@@ -18797,10 +18806,10 @@
18797
18806
  }
18798
18807
  };
18799
18808
  var _setStartValue = function () {
18800
- var _startValueUserValue = _this.getUserValueFromSliderValueByMap(_this.startValue);
18809
+ var _startValueUserValue = _this.getValueFromMapByValue(_this.startValue);
18801
18810
  if (_this.needParseValues && _startValueUserValue !== trackClickToUserRange) {
18802
18811
  var _startValue = _this.needParseValues
18803
- ? _this.mapRangeValuesForSlider.get(trackClickToUserRange).left
18812
+ ? _this.mapRangeValuesForSlider.get(trackClickToUserRange)
18804
18813
  : trackClickPercentage;
18805
18814
  _this.startValue = _startValue;
18806
18815
  }
@@ -18810,8 +18819,8 @@
18810
18819
  };
18811
18820
  if (this.multiple) {
18812
18821
  var _a = __read(this.value, 2), start = _a[0], end = _a[1];
18813
- var validStart_1 = this.needParseValues ? this.mapRangeValuesForSlider.get(start).left : start;
18814
- var validEnd_1 = this.needParseValues ? this.mapRangeValuesForSlider.get(end).right : end;
18822
+ var validStart_1 = this.needParseValues ? this.mapRangeValuesForSlider.get(start) : start;
18823
+ var validEnd_1 = this.needParseValues ? this.mapRangeValuesForSlider.get(end) : end;
18815
18824
  var _updateStart = function () {
18816
18825
  _setStartValue();
18817
18826
  _this.setValue([trackClickPercentage, validEnd_1]);
@@ -18874,11 +18883,15 @@
18874
18883
  document.addEventListener("mouseup", this.onMouseUp);
18875
18884
  };
18876
18885
  SliderComponent.prototype.setRangeValues = function () {
18886
+ var _this = this;
18887
+ var _setStartAndEndValue = function (startValue, endValue) {
18888
+ _this.startValue = _this.getClosestValueFromMapSlider(startValue);
18889
+ _this.endValue = _this.getClosestValueFromMapSlider(endValue);
18890
+ };
18877
18891
  if (Array.isArray(this.value) && !this.multiple) {
18878
18892
  throw new Error('You must use "multiple" with value as array');
18879
18893
  }
18880
- var hasRangeValues = !!(this.startValue && this.endValue);
18881
- if (this.multiple && Array.isArray(this.value) && !hasRangeValues) {
18894
+ if (this.multiple && Array.isArray(this.value)) {
18882
18895
  this.startValue = this.value[0];
18883
18896
  this.endValue = this.value[1];
18884
18897
  }
@@ -18890,13 +18903,40 @@
18890
18903
  this.endValue = this.value;
18891
18904
  }
18892
18905
  if (this.needParseValues) {
18893
- var isEqualAndMultiple = this.multiple && this.startValue === this.endValue;
18894
- this.startValue = this.mapRangeValuesForSlider.get(this.startValue).left;
18895
- if (isEqualAndMultiple) {
18896
- this.endValue = this.startValue;
18906
+ _setStartAndEndValue(this.startValue, this.endValue);
18907
+ if (this.multiple) {
18908
+ var _a = __read(this.value, 2), _startValue = _a[0], _endValue = _a[1];
18909
+ var difference = getDifference(_endValue, _startValue);
18910
+ var endValueIsGreatherThanMax = _endValue > this.max;
18911
+ var startValueIsLessThanMin = _startValue < this.min;
18912
+ var needUpdateValues = endValueIsGreatherThanMax || startValueIsLessThanMin;
18913
+ if (endValueIsGreatherThanMax) {
18914
+ _endValue = this.max;
18915
+ _startValue = _endValue - difference;
18916
+ }
18917
+ else if (startValueIsLessThanMin) {
18918
+ _startValue = this.min;
18919
+ _endValue = _startValue + difference;
18920
+ }
18921
+ if (needUpdateValues) {
18922
+ _setStartAndEndValue(_startValue, _endValue);
18923
+ this.setValue([this.startValue, this.endValue]);
18924
+ }
18897
18925
  }
18898
18926
  else {
18899
- this.endValue = this.mapRangeValuesForSlider.get(this.endValue).right;
18927
+ var _value = this.value;
18928
+ var valueGreatherThanMax = _value > this.max;
18929
+ var valueLessThanMin = _value < this.min;
18930
+ var needUpdateValue = valueGreatherThanMax || valueLessThanMin;
18931
+ if (valueGreatherThanMax) {
18932
+ _value = this.max;
18933
+ }
18934
+ else if (valueLessThanMin) {
18935
+ _value = this.min;
18936
+ }
18937
+ if (needUpdateValue) {
18938
+ this.setValue(_value);
18939
+ }
18900
18940
  }
18901
18941
  }
18902
18942
  this.setProgress();
@@ -18918,22 +18958,22 @@
18918
18958
  */
18919
18959
  SliderComponent.prototype.getPercentageByEvent = function (mouseEvent) {
18920
18960
  var trackRect = this.track.nativeElement.getBoundingClientRect();
18921
- var newLeft = ((mouseEvent.clientX - trackRect.left) / trackRect.width) * 100;
18922
- newLeft = Math.round(newLeft / this.step) * this.step;
18923
- newLeft = Math.max(0, Math.min(newLeft, 100));
18961
+ var newLeft = Math.round(((mouseEvent.clientX - trackRect.left) / trackRect.width) * this.MAX_RANGE_VALUE);
18962
+ newLeft = Math.max(0, Math.min(newLeft, this.MAX_RANGE_VALUE));
18924
18963
  return newLeft;
18925
18964
  };
18926
- SliderComponent.prototype.setValue = function (value) {
18965
+ SliderComponent.prototype.setValue = function (value, parse) {
18927
18966
  var _this = this;
18967
+ if (parse === void 0) { parse = true; }
18928
18968
  if (this.disabled) {
18929
18969
  return;
18930
18970
  }
18931
- if (this.needParseValues) {
18971
+ if (this.needParseValues && parse) {
18932
18972
  if (Array.isArray(value)) {
18933
- value = value.map(function (x) { return _this.getUserValueFromSliderValueByMap(x); });
18973
+ value = value.map(function (x) { return _this.getValueFromMapByValue(x); });
18934
18974
  }
18935
18975
  else {
18936
- value = this.getUserValueFromSliderValueByMap(value);
18976
+ value = this.getValueFromMapByValue(value);
18937
18977
  }
18938
18978
  }
18939
18979
  this.value = value;
@@ -18946,54 +18986,84 @@
18946
18986
  var _this = this;
18947
18987
  var start = this.min;
18948
18988
  var end = this.max;
18949
- var forStart = 0;
18950
- var forEnd = 100;
18951
- this.mapRangeValuesForSlider.clear();
18952
- var mappedValues = [];
18953
- for (var i = start; i <= end; i++) {
18954
- var valuesWithMap = [];
18955
- for (var j = forStart; j <= forEnd; j++) {
18956
- var sliderToUserRangeValue = this.mapSliderToUserRange(j);
18957
- if (sliderToUserRangeValue !== i) {
18958
- forStart = j;
18959
- break;
18960
- }
18961
- else {
18962
- valuesWithMap.push(j);
18963
- }
18964
- }
18965
- var left = valuesWithMap[0];
18966
- var right = valuesWithMap[valuesWithMap.length - 1];
18967
- mappedValues.push({ value: i, left: left, right: right });
18989
+ if (start > end) {
18990
+ throw new Error('Max value must be greater than min value');
18968
18991
  }
18969
- adjustLastItem(mappedValues);
18970
- mappedValues.forEach(function (mappedValue) {
18971
- _this.mapRangeValuesForSlider.set(mappedValue.value, __assign({}, mappedValue));
18992
+ this.mapRangeValuesForSlider.clear();
18993
+ var range = end - start;
18994
+ var decimalPlaces = 2;
18995
+ var stepCount = Math.floor(range / this.step);
18996
+ var values = [];
18997
+ for (var value = start; value <= end; value += this.step) {
18998
+ values.push(value);
18999
+ }
19000
+ if (values[values.length - 1] !== end) {
19001
+ values.push(end);
19002
+ }
19003
+ var mappedValues = values.map(function (value) {
19004
+ var mapped = ((value - start) / range) * _this.MAX_RANGE_VALUE;
19005
+ return parseFloat(mapped.toFixed(decimalPlaces));
19006
+ });
19007
+ mappedValues[0] = 0;
19008
+ mappedValues[mappedValues.length - 1] = this.MAX_RANGE_VALUE;
19009
+ var error = this.MAX_RANGE_VALUE - mappedValues[mappedValues.length - 1];
19010
+ var errorPerStep = error / stepCount;
19011
+ for (var i = 1; i < mappedValues.length - 1; i++) {
19012
+ mappedValues[i] += errorPerStep;
19013
+ mappedValues[i] = parseFloat(mappedValues[i].toFixed(decimalPlaces));
19014
+ }
19015
+ values.forEach(function (value, index) {
19016
+ _this.mapRangeValuesForSlider.set(value, mappedValues[index]);
18972
19017
  });
18973
19018
  };
18974
19019
  /**
18975
- * Maps a slider value to a user value in the range [min, max].
19020
+ * Returns the user value from the given slider value by using the map of range values.
18976
19021
  * @example
18977
- * If min = 0 and max = 10, mapSliderToUserRange(25) returns 2.5
19022
+ * If the map is 0: { 0 }, 1: { 10 }, 2: { 30 }, 3: { 40 }, 4: { 50 }
19023
+ * and the sliderValue is 37, the function returns 3
19024
+ * or the slider value is 40, the function returns 4
19025
+ * @param sliderValue the value of the slider (values only between range MIN and MAX)
19026
+ * @returns the user value from the given slider value
18978
19027
  */
18979
- SliderComponent.prototype.mapSliderToUserRange = function (sliderValue) {
18980
- return Math.floor(this.min + (sliderValue / 100) * (this.max - this.min));
19028
+ SliderComponent.prototype.getValueFromMapByValue = function (sliderValue) {
19029
+ var mapToArray = Array.from(this.mapRangeValuesForSlider).map(function (_a) {
19030
+ var _b = __read(_a, 2), value = _b[0], mapped = _b[1];
19031
+ return ({ value: value, mapped: mapped });
19032
+ });
19033
+ var exactValue = mapToArray.find(function (x) { return x.mapped == sliderValue; });
19034
+ var closest = mapToArray.reduce(function (prev, curr) { return Math.abs(curr.mapped - sliderValue) < Math.abs(prev.mapped - sliderValue) ? curr : prev; });
19035
+ return exactValue ? exactValue.value : closest.value;
18981
19036
  };
18982
19037
  /**
18983
- * Returns the user value from the given slider value by using the map of range values.
18984
- * @example
18985
- * If the map is [{value: 0, left: 0, right: 25}, {value: 1, left: 25, right: 50}, {value: 2, left: 50, right: 75}, {value: 3, left: 75, right: 100}]
18986
- * and the sliderValue is 37, the function returns 1
18987
- * @param sliderValue the value of the slider
18988
- * @returns the user value from the given slider value
19038
+ * Retrieves the key from the map that is closest to the given slider value.
19039
+ * @param userValue - The value to find the closest key for. (values only between 0 - 100)
19040
+ * @returns The key that corresponds to the closest mapped value.
18989
19041
  */
18990
- SliderComponent.prototype.getUserValueFromSliderValueByMap = function (sliderValue) {
18991
- var _a;
18992
- var mapToArray = Array.from(this.mapRangeValuesForSlider).map(function (x) {
18993
- return __assign({ value: x[0] }, x[1]);
19042
+ SliderComponent.prototype.getClosestValueFromMapSlider = function (userValue) {
19043
+ var mapToArray = Array.from(this.mapRangeValuesForSlider).map(function (_a) {
19044
+ var _b = __read(_a, 2), value = _b[0], mapped = _b[1];
19045
+ return ({ value: value, mapped: mapped });
18994
19046
  });
18995
- var mappedValue = mapToArray.find(function (x) { return isInRange(sliderValue, x.left, x.right); });
18996
- return (_a = mappedValue === null || mappedValue === void 0 ? void 0 : mappedValue.value) !== null && _a !== void 0 ? _a : sliderValue;
19047
+ if (userValue >= this.max) {
19048
+ return mapToArray[mapToArray.length - 1].mapped;
19049
+ }
19050
+ else if (userValue <= this.min) {
19051
+ return mapToArray[0].mapped;
19052
+ }
19053
+ var exactValue = mapToArray.find(function (x) { return x.value == userValue; });
19054
+ var closestValue = mapToArray.reduce(function (prev, curr) { return Math.abs(curr.value - userValue) < Math.abs(prev.value - userValue) ? curr : prev; });
19055
+ var item = exactValue || closestValue;
19056
+ var isFirstItem = mapToArray[0] === item;
19057
+ var isLastItem = mapToArray[mapToArray.length - 1] === item;
19058
+ if (isFirstItem && userValue > this.min) {
19059
+ return getMidpoint(item.mapped, mapToArray[1].mapped);
19060
+ }
19061
+ else if (isLastItem && userValue < this.max) {
19062
+ return getMidpoint(item.mapped, mapToArray[mapToArray.length - 2].mapped);
19063
+ }
19064
+ else {
19065
+ return item.mapped;
19066
+ }
18997
19067
  };
18998
19068
  SliderComponent.prototype.handleArrowKeyLeft = function () {
18999
19069
  if (this.multiple) {
@@ -19015,6 +19085,7 @@
19015
19085
  };
19016
19086
  SliderComponent.prototype._incrementOrDecrementStartAndEndValue = function (increment) {
19017
19087
  var _a = __read(this.value, 2), start = _a[0], end = _a[1];
19088
+ var difference = getDifference(end, start);
19018
19089
  if (increment) {
19019
19090
  start += this.step;
19020
19091
  end += this.step;
@@ -19023,31 +19094,28 @@
19023
19094
  start -= this.step;
19024
19095
  end -= this.step;
19025
19096
  }
19026
- if (this.needParseValues) {
19027
- if (!this.mapRangeValuesForSlider.has(start) || !this.mapRangeValuesForSlider.has(end)) {
19028
- return;
19097
+ var startLessThanMin = start < this.min;
19098
+ var endGreaterThanMax = end > this.max;
19099
+ if (startLessThanMin || endGreaterThanMax) {
19100
+ if (startLessThanMin) {
19101
+ start = this.min;
19102
+ end = start + difference;
19029
19103
  }
19030
- var isEqual = start === end;
19031
- if (isEqual && end === this.max) {
19032
- start = this.mapRangeValuesForSlider.get(this.max).right;
19033
- end = start;
19034
- }
19035
- else {
19036
- start = this.mapRangeValuesForSlider.get(start).left;
19037
- if (isEqual) {
19038
- end = start;
19039
- }
19040
- else {
19041
- end = this.mapRangeValuesForSlider.get(end).right;
19042
- }
19104
+ else if (endGreaterThanMax) {
19105
+ end = this.max;
19106
+ start = end - difference;
19043
19107
  }
19044
19108
  }
19045
- if (start < 0 || end > 100) {
19109
+ if (start < this.min || end > this.max) {
19046
19110
  return;
19047
19111
  }
19112
+ this.setValue([start, end], false);
19113
+ if (this.needParseValues) {
19114
+ start = this.getClosestValueFromMapSlider(start);
19115
+ end = this.getClosestValueFromMapSlider(end);
19116
+ }
19048
19117
  this.startValue = start;
19049
19118
  this.endValue = end;
19050
- this.setValue([start, end]);
19051
19119
  };
19052
19120
  SliderComponent.prototype._incrementOrDecrementEndValue = function (increment) {
19053
19121
  var value = this.value;
@@ -19059,28 +19127,18 @@
19059
19127
  }
19060
19128
  var _newEndValue = value;
19061
19129
  if (this.needParseValues) {
19062
- var valueParsedInSlider = this.mapRangeValuesForSlider.get(value);
19063
- if (!valueParsedInSlider) {
19064
- return;
19065
- }
19066
- var pickLeft = valueParsedInSlider.right <= 50;
19067
- if (pickLeft) {
19068
- _newEndValue = this.mapRangeValuesForSlider.get(value).left;
19069
- }
19070
- else {
19071
- _newEndValue = this.mapRangeValuesForSlider.get(value).right;
19072
- }
19130
+ _newEndValue = this.getClosestValueFromMapSlider(_newEndValue);
19073
19131
  }
19074
- if (_newEndValue < 0 || _newEndValue > 100) {
19132
+ if (_newEndValue < this.MIN_RANGE_VALUE || _newEndValue > this.MAX_RANGE_VALUE) {
19075
19133
  return;
19076
19134
  }
19077
19135
  this.endValue = _newEndValue;
19078
19136
  this.startValue = this.endValue;
19079
- this.setValue(this.endValue);
19137
+ this.setValue(_newEndValue);
19080
19138
  };
19081
19139
  Object.defineProperty(SliderComponent.prototype, "needParseValues", {
19082
19140
  get: function () {
19083
- return this.max !== 100 || this.min !== 0;
19141
+ return this.max !== this.MAX_RANGE_VALUE || this.min !== this.MIN_RANGE_VALUE;
19084
19142
  },
19085
19143
  enumerable: true,
19086
19144
  configurable: true
@@ -19162,72 +19220,15 @@
19162
19220
  return value >= min && value <= max;
19163
19221
  };
19164
19222
  var ɵ1$1 = isInRange;
19165
- /**
19166
- * Adjust the last item of a mapped range to fill the gap between it and the penultimate item.
19167
- * The gap is calculated by subtracting the difference between the last item's right and left
19168
- * from the average difference between all the previous items.
19169
- *
19170
- * @param mappedValues - The mapped range to be adjusted.
19171
- *
19172
- * The function works by finding the gap between the last item and the penultimate item and
19173
- * then distributing this gap among the previous items. The distribution is done by finding
19174
- * the items that need to be fixed and then fixing them by shifting their left and right
19175
- * positions.
19176
- *
19177
- * The function returns nothing, but it modifies the mappedValues array in place.
19178
- */
19179
- var adjustLastItem = function (mappedValues) {
19180
- var lastItem = mappedValues[mappedValues.length - 1];
19181
- var lastDifference = lastItem.right - lastItem.left;
19182
- var withoutLastItem = mappedValues.slice(0, mappedValues.length - 1);
19183
- var differences = withoutLastItem.map(function (_a) {
19184
- var left = _a.left, right = _a.right;
19185
- return right - left;
19186
- });
19187
- var averageDifference = Math.floor(differences.reduce(function (sum, diff) { return sum + diff; }, 0) / differences.length);
19188
- var _getRandomIndexFromArray = function (array, storedChanges) {
19189
- if (storedChanges.length === array.length) {
19190
- storedChanges = [];
19191
- }
19192
- var randomIndex = Math.floor(Math.random() * array.length);
19193
- var randomIndexAlreadyStored = storedChanges.includes(randomIndex);
19194
- while (randomIndexAlreadyStored) {
19195
- randomIndex = Math.floor(Math.random() * withoutLastItem.length);
19196
- randomIndexAlreadyStored = storedChanges.includes(randomIndex);
19197
- }
19198
- storedChanges.push(randomIndex);
19199
- return { randomIndex: randomIndex, storedChanges: storedChanges };
19200
- };
19201
- var needFixLastItem = lastDifference < averageDifference;
19202
- var arr = [];
19203
- if (needFixLastItem) {
19204
- var captureItensCount = averageDifference - lastDifference;
19205
- var randomIndexStored = [];
19206
- for (var i = 0; i <= captureItensCount; i++) {
19207
- var _a = _getRandomIndexFromArray(withoutLastItem, randomIndexStored), randomIndex = _a.randomIndex, storedChanges = _a.storedChanges;
19208
- randomIndexStored = storedChanges;
19209
- arr.push(randomIndex);
19210
- var randomItem = withoutLastItem[randomIndex];
19211
- --lastItem.left;
19212
- --randomItem.right;
19213
- }
19214
- mappedValues.forEach(function (mappedValue, index) {
19215
- var _next = mappedValues[index + 1];
19216
- if (!_next) {
19217
- return;
19218
- }
19219
- var nextLeft = _next.left;
19220
- var currentRight = mappedValue.right;
19221
- if (currentRight !== currentRight + 1) {
19222
- var _nextDiff = _next.right - nextLeft;
19223
- var _nextLeft = currentRight + 1;
19224
- _next.left = _nextLeft;
19225
- _next.right = _nextLeft + _nextDiff;
19226
- }
19227
- });
19228
- }
19223
+ var getMidpoint = function (start, end) {
19224
+ var midpoint = (start + end) / 2;
19225
+ return parseFloat(midpoint.toFixed(2));
19226
+ };
19227
+ var ɵ2 = getMidpoint;
19228
+ var getDifference = function (end, start) {
19229
+ return Math.abs(end - start);
19229
19230
  };
19230
- var ɵ2 = adjustLastItem;
19231
+ var ɵ3 = getDifference;
19231
19232
 
19232
19233
  var SliderModule = /** @class */ (function () {
19233
19234
  function SliderModule() {
@@ -20601,7 +20602,7 @@
20601
20602
  var _list = list instanceof Set ? Array.from(list) : list;
20602
20603
  return _list.filter(function (x) { return !x.disabled; });
20603
20604
  };
20604
- var ɵ3 = filterEnabled;
20605
+ var ɵ3$1 = filterEnabled;
20605
20606
  var mapData = function (list) {
20606
20607
  return list.map(function (x) { return x.data; });
20607
20608
  };
@@ -21150,7 +21151,7 @@
21150
21151
  exports.ɵ0 = ɵ0$3;
21151
21152
  exports.ɵ1 = ɵ1$2;
21152
21153
  exports.ɵ2 = ɵ2$1;
21153
- exports.ɵ3 = ɵ3;
21154
+ exports.ɵ3 = ɵ3$1;
21154
21155
  exports.ɵ4 = ɵ4;
21155
21156
  exports.ɵa = TooltipComponent;
21156
21157
  exports.ɵb = TooltipDirective;