@lowentry/utils 1.13.5 → 1.15.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.
package/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
2
2
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
3
3
  import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
4
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
4
5
  import _typeof from '@babel/runtime/helpers/typeof';
5
6
  import '@babel/runtime/helpers/awaitAsyncGenerator';
6
7
  import _wrapAsyncGenerator from '@babel/runtime/helpers/wrapAsyncGenerator';
@@ -207,9 +208,12 @@ var FLOAT_LAX_ANY = function FLOAT_LAX_ANY() {
207
208
 
208
209
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
209
210
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
211
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
212
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
213
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
210
214
 
211
215
  /**
212
- * @param {LeUtils~TransactionalValue} transactionalValue
216
+ * @param {LeUtils_TransactionalValue} transactionalValue
213
217
  */
214
218
  var checkTransactionalValue = function checkTransactionalValue(transactionalValue) {
215
219
  if (!LeUtils.isTransactionalValueValid(transactionalValue)) {
@@ -220,7 +224,7 @@ var checkTransactionalValue = function checkTransactionalValue(transactionalValu
220
224
  };
221
225
 
222
226
  /**
223
- * @param {LeUtils~TransactionalValue} transactionalValue
227
+ * @param {LeUtils_TransactionalValue} transactionalValue
224
228
  * @param {string} changeId
225
229
  * @returns {{index:number, value:*}|null}
226
230
  */
@@ -268,7 +272,9 @@ var LeUtils = {
268
272
  };
269
273
  }
270
274
  if (document.readyState === 'interactive' || document.readyState === 'complete') {
271
- return LeUtils.setTimeout(callback, 0);
275
+ return LeUtils.setTimeout(function () {
276
+ return callback();
277
+ }, 0);
272
278
  } else {
273
279
  var listening = true;
274
280
  var _callbackWrapper = function callbackWrapper() {
@@ -542,21 +548,16 @@ var LeUtils = {
542
548
  });
543
549
  return result;
544
550
  },
545
- /**
546
- * @callback LeUtils~__findIndexValueCallback
547
- * @param {*} value
548
- * @param {*} index
549
- * @returns {boolean|undefined}
550
- */
551
551
  /**
552
552
  * Finds the first element in the given array or object that returns true from the callback, and returns an object with the index and value.
553
553
  *
554
554
  * @param {*[]|object|Function} elements
555
- * @param {LeUtils~__findIndexValueCallback} callback
555
+ * @param {(value:*, index:*) => boolean|void} callback
556
556
  * @param {boolean} [optionalSkipHasOwnPropertyCheck]
557
557
  * @returns {{index:*, value:*}|null}
558
558
  */
559
559
  findIndexValue: function findIndexValue(elements, callback) {
560
+ var optionalSkipHasOwnPropertyCheck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
560
561
  var result = null;
561
562
  LeUtils.each(elements, function (value, index) {
562
563
  if (callback.call(elements[index], elements[index], index)) {
@@ -566,14 +567,14 @@ var LeUtils = {
566
567
  };
567
568
  return false;
568
569
  }
569
- });
570
+ }, optionalSkipHasOwnPropertyCheck);
570
571
  return result;
571
572
  },
572
573
  /**
573
574
  * Finds the first element in the given array or object that returns true from the callback, and returns the index.
574
575
  *
575
576
  * @param {*[]|object|Function} elements
576
- * @param {LeUtils~__findIndexValueCallback} callback
577
+ * @param {(value:*, index:*) => boolean|void} callback
577
578
  * @param {boolean} [optionalSkipHasOwnPropertyCheck]
578
579
  * @returns {*|null}
579
580
  */
@@ -586,7 +587,7 @@ var LeUtils = {
586
587
  * Finds the first element in the given array or object that returns true from the callback, and returns the value.
587
588
  *
588
589
  * @param {*[]|object|Function} elements
589
- * @param {LeUtils~__findIndexValueCallback} callback
590
+ * @param {(value:*, index:*) => boolean|void} callback
590
591
  * @param {boolean} [optionalSkipHasOwnPropertyCheck]
591
592
  * @returns {*|null}
592
593
  */
@@ -596,246 +597,525 @@ var LeUtils = {
596
597
  return (_LeUtils$findIndexVal3 = (_LeUtils$findIndexVal4 = LeUtils.findIndexValue(elements, callback, optionalSkipHasOwnPropertyCheck)) === null || _LeUtils$findIndexVal4 === void 0 ? void 0 : _LeUtils$findIndexVal4.value) !== null && _LeUtils$findIndexVal3 !== void 0 ? _LeUtils$findIndexVal3 : null;
597
598
  },
598
599
  /**
599
- * @callback LeUtils~__eachCallback
600
- * @param {*} value
600
+ * Returns the value at the given index in the given elements.
601
+ *
602
+ * @param {*} elements
601
603
  * @param {*} index
602
- * @returns {boolean|undefined}
604
+ * @param {boolean} [optionalSkipHasOwnPropertyCheck]
605
+ * @returns {*}
606
+ */
607
+ getValueAtIndex: function getValueAtIndex(elements, index) {
608
+ var optionalSkipHasOwnPropertyCheck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
609
+ if (elements === null || typeof elements === 'undefined') {
610
+ return undefined;
611
+ }
612
+ if (Array.isArray(elements)) {
613
+ return elements[index];
614
+ }
615
+ if (_typeof(elements) === 'object' && (elements === null || elements === void 0 ? void 0 : elements.constructor) === Object) {
616
+ if (optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(elements, index)) {
617
+ return elements[index];
618
+ }
619
+ return undefined;
620
+ }
621
+ if (elements instanceof Map) {
622
+ return elements.get(index);
623
+ }
624
+ if (elements instanceof Set) {
625
+ return index;
626
+ }
627
+ if (ArrayBuffer.isView(elements) && !(elements instanceof DataView)) {
628
+ return elements[index];
629
+ }
630
+ if (typeof elements === 'string') {
631
+ return elements.charAt(index);
632
+ }
633
+ if (typeof (elements === null || elements === void 0 ? void 0 : elements[Symbol.iterator]) === 'function') {
634
+ var i = 0;
635
+ var _iterator = _createForOfIteratorHelper(elements),
636
+ _step;
637
+ try {
638
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
639
+ var value = _step.value;
640
+ if (i === index) {
641
+ return value;
642
+ }
643
+ i++;
644
+ }
645
+ } catch (err) {
646
+ _iterator.e(err);
647
+ } finally {
648
+ _iterator.f();
649
+ }
650
+ return undefined;
651
+ }
652
+ if (typeof (elements === null || elements === void 0 ? void 0 : elements.forEach) === 'function') {
653
+ var result = undefined;
654
+ var shouldContinue = true;
655
+ elements.forEach(function (value, i) {
656
+ if (shouldContinue) {
657
+ if (i === index) {
658
+ result = value;
659
+ shouldContinue = false;
660
+ }
661
+ }
662
+ });
663
+ return result;
664
+ }
665
+ if (_typeof(elements) === 'object' || typeof elements === 'function') {
666
+ if (optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(elements, index)) {
667
+ return elements[index];
668
+ }
669
+ return undefined;
670
+ }
671
+ return undefined;
672
+ },
673
+ /**
674
+ * Checks if the given elements can be iterated over using LeUtils.each().
675
+ *
676
+ * @param {*} elements
677
+ * @returns {boolean}
603
678
  */
679
+ supportsEach: function supportsEach(elements) {
680
+ if (elements === null || typeof elements === 'undefined') {
681
+ return false;
682
+ }
683
+ return !!(Array.isArray(elements) || _typeof(elements) === 'object' && (elements === null || elements === void 0 ? void 0 : elements.constructor) === Object || typeof elements === 'string' || typeof (elements === null || elements === void 0 ? void 0 : elements[Symbol.iterator]) === 'function' || typeof (elements === null || elements === void 0 ? void 0 : elements.forEach) === 'function' || _typeof(elements) === 'object' || typeof elements === 'function');
684
+ },
604
685
  /**
605
- * Loops through each element in the given array or object, and calls the callback for each element.
686
+ * Returns an iterator that iterates over each element in the given array or object, yielding an array with the value and the index/key.
606
687
  *
607
- * @param {*[]|object|Function} elements
608
- * @param {LeUtils~__eachCallback} callback
688
+ * @param {*} elements
609
689
  * @param {boolean} [optionalSkipHasOwnPropertyCheck]
610
- * @returns {*[]|object|Function}
690
+ * @returns {Generator<*, void, *>}
611
691
  */
612
- each: function each(elements, callback) {
613
- var optionalSkipHasOwnPropertyCheck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
614
- if (elements !== null && typeof elements !== 'undefined') {
615
- if (Array.isArray(elements)) {
616
- for (var index = 0; index < elements.length; index++) {
617
- if (callback.call(elements[index], elements[index], index) === false) {
692
+ eachIterator: function eachIterator(elements) {
693
+ var optionalSkipHasOwnPropertyCheck = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
694
+ return /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
695
+ var i, _i, _iterator2, _step2, _step2$value, _i2, value, _iterator3, _step3, _value, _i3, _i4, _iterator4, _step4, _value2, buffer, _i5, _buffer, entry, _i6, _t, _t2, _t3, _t4, _t5, _t6, _t7;
696
+ return _regeneratorRuntime.wrap(function (_context) {
697
+ while (1) switch (_context.prev = _context.next) {
698
+ case 0:
699
+ if (!(elements === null || typeof elements === 'undefined')) {
700
+ _context.next = 1;
701
+ break;
702
+ }
703
+ return _context.abrupt("return");
704
+ case 1:
705
+ if (!Array.isArray(elements)) {
706
+ _context.next = 5;
707
+ break;
708
+ }
709
+ i = 0;
710
+ case 2:
711
+ if (!(i < elements.length)) {
712
+ _context.next = 4;
713
+ break;
714
+ }
715
+ _context.next = 3;
716
+ return [elements[i], i];
717
+ case 3:
718
+ i++;
719
+ _context.next = 2;
618
720
  break;
619
- }
620
- }
621
- } else if (_typeof(elements) === 'object' || typeof elements === 'function') {
622
- for (var _index in elements) {
623
- if (optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(elements, _index)) {
624
- if (callback.call(elements[_index], elements[_index], _index) === false) {
721
+ case 4:
722
+ return _context.abrupt("return");
723
+ case 5:
724
+ if (!(_typeof(elements) === 'object' && (elements === null || elements === void 0 ? void 0 : elements.constructor) === Object)) {
725
+ _context.next = 9;
625
726
  break;
626
727
  }
627
- }
728
+ _t = _regeneratorRuntime.keys(elements);
729
+ case 6:
730
+ if ((_t2 = _t()).done) {
731
+ _context.next = 8;
732
+ break;
733
+ }
734
+ _i = _t2.value;
735
+ if (!(optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(elements, _i))) {
736
+ _context.next = 7;
737
+ break;
738
+ }
739
+ _context.next = 7;
740
+ return [elements[_i], _i];
741
+ case 7:
742
+ _context.next = 6;
743
+ break;
744
+ case 8:
745
+ return _context.abrupt("return");
746
+ case 9:
747
+ if (!(elements instanceof Map)) {
748
+ _context.next = 17;
749
+ break;
750
+ }
751
+ _iterator2 = _createForOfIteratorHelper(elements);
752
+ _context.prev = 10;
753
+ _iterator2.s();
754
+ case 11:
755
+ if ((_step2 = _iterator2.n()).done) {
756
+ _context.next = 13;
757
+ break;
758
+ }
759
+ _step2$value = _slicedToArray(_step2.value, 2), _i2 = _step2$value[0], value = _step2$value[1];
760
+ _context.next = 12;
761
+ return [value, _i2];
762
+ case 12:
763
+ _context.next = 11;
764
+ break;
765
+ case 13:
766
+ _context.next = 15;
767
+ break;
768
+ case 14:
769
+ _context.prev = 14;
770
+ _t3 = _context["catch"](10);
771
+ _iterator2.e(_t3);
772
+ case 15:
773
+ _context.prev = 15;
774
+ _iterator2.f();
775
+ return _context.finish(15);
776
+ case 16:
777
+ return _context.abrupt("return");
778
+ case 17:
779
+ if (!(elements instanceof Set)) {
780
+ _context.next = 25;
781
+ break;
782
+ }
783
+ _iterator3 = _createForOfIteratorHelper(elements);
784
+ _context.prev = 18;
785
+ _iterator3.s();
786
+ case 19:
787
+ if ((_step3 = _iterator3.n()).done) {
788
+ _context.next = 21;
789
+ break;
790
+ }
791
+ _value = _step3.value;
792
+ _context.next = 20;
793
+ return [_value, _value];
794
+ case 20:
795
+ _context.next = 19;
796
+ break;
797
+ case 21:
798
+ _context.next = 23;
799
+ break;
800
+ case 22:
801
+ _context.prev = 22;
802
+ _t4 = _context["catch"](18);
803
+ _iterator3.e(_t4);
804
+ case 23:
805
+ _context.prev = 23;
806
+ _iterator3.f();
807
+ return _context.finish(23);
808
+ case 24:
809
+ return _context.abrupt("return");
810
+ case 25:
811
+ if (!(typeof elements === 'string')) {
812
+ _context.next = 29;
813
+ break;
814
+ }
815
+ _i3 = 0;
816
+ case 26:
817
+ if (!(_i3 < elements.length)) {
818
+ _context.next = 28;
819
+ break;
820
+ }
821
+ _context.next = 27;
822
+ return [elements.charAt(_i3), _i3];
823
+ case 27:
824
+ _i3++;
825
+ _context.next = 26;
826
+ break;
827
+ case 28:
828
+ return _context.abrupt("return");
829
+ case 29:
830
+ if (!(typeof (elements === null || elements === void 0 ? void 0 : elements[Symbol.iterator]) === 'function')) {
831
+ _context.next = 38;
832
+ break;
833
+ }
834
+ _i4 = 0;
835
+ _iterator4 = _createForOfIteratorHelper(elements);
836
+ _context.prev = 30;
837
+ _iterator4.s();
838
+ case 31:
839
+ if ((_step4 = _iterator4.n()).done) {
840
+ _context.next = 34;
841
+ break;
842
+ }
843
+ _value2 = _step4.value;
844
+ _context.next = 32;
845
+ return [_value2, _i4];
846
+ case 32:
847
+ _i4++;
848
+ case 33:
849
+ _context.next = 31;
850
+ break;
851
+ case 34:
852
+ _context.next = 36;
853
+ break;
854
+ case 35:
855
+ _context.prev = 35;
856
+ _t5 = _context["catch"](30);
857
+ _iterator4.e(_t5);
858
+ case 36:
859
+ _context.prev = 36;
860
+ _iterator4.f();
861
+ return _context.finish(36);
862
+ case 37:
863
+ return _context.abrupt("return");
864
+ case 38:
865
+ if (!(typeof (elements === null || elements === void 0 ? void 0 : elements.forEach) === 'function')) {
866
+ _context.next = 42;
867
+ break;
868
+ }
869
+ buffer = [];
870
+ elements.forEach(function (value, i) {
871
+ buffer.push([value, i]);
872
+ });
873
+ _i5 = 0, _buffer = buffer;
874
+ case 39:
875
+ if (!(_i5 < _buffer.length)) {
876
+ _context.next = 41;
877
+ break;
878
+ }
879
+ entry = _buffer[_i5];
880
+ _context.next = 40;
881
+ return entry;
882
+ case 40:
883
+ _i5++;
884
+ _context.next = 39;
885
+ break;
886
+ case 41:
887
+ return _context.abrupt("return");
888
+ case 42:
889
+ if (!(_typeof(elements) === 'object' || typeof elements === 'function')) {
890
+ _context.next = 46;
891
+ break;
892
+ }
893
+ _t6 = _regeneratorRuntime.keys(elements);
894
+ case 43:
895
+ if ((_t7 = _t6()).done) {
896
+ _context.next = 45;
897
+ break;
898
+ }
899
+ _i6 = _t7.value;
900
+ if (!(optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(elements, _i6))) {
901
+ _context.next = 44;
902
+ break;
903
+ }
904
+ _context.next = 44;
905
+ return [elements[_i6], _i6];
906
+ case 44:
907
+ _context.next = 43;
908
+ break;
909
+ case 45:
910
+ return _context.abrupt("return");
911
+ case 46:
912
+ console.warn('Executed LeUtils.eachIterator() on an invalid type: [' + _typeof(elements) + ']', elements);
913
+ case 47:
914
+ case "end":
915
+ return _context.stop();
916
+ }
917
+ }, _callee, null, [[10, 14, 15, 16], [18, 22, 23, 24], [30, 35, 36, 37]]);
918
+ })();
919
+ },
920
+ /**
921
+ * Loops through each element in the given array or object, and calls the callback for each element.
922
+ *
923
+ * @param {*} elements
924
+ * @param {(value:*, index?:*) => boolean|void} callback
925
+ * @param {boolean} [optionalSkipHasOwnPropertyCheck]
926
+ * @returns {*}
927
+ */
928
+ each: function each(elements, callback) {
929
+ var optionalSkipHasOwnPropertyCheck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
930
+ var _iterator5 = _createForOfIteratorHelper(LeUtils.eachIterator(elements, optionalSkipHasOwnPropertyCheck)),
931
+ _step5;
932
+ try {
933
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
934
+ var _step5$value = _slicedToArray(_step5.value, 2),
935
+ value = _step5$value[0],
936
+ key = _step5$value[1];
937
+ if (callback.call(value, value, key) === false) {
938
+ break;
628
939
  }
629
- } else {
630
- console.warn('Executed LeUtils.each() on an invalid type: [' + _typeof(elements) + ']', elements);
631
940
  }
941
+ } catch (err) {
942
+ _iterator5.e(err);
943
+ } finally {
944
+ _iterator5.f();
632
945
  }
633
946
  return elements;
634
947
  },
635
948
  /**
636
949
  * Like LeUtils.each(), except that it expects an async callback.
637
950
  *
638
- * @param {*[]|object|function} elements
639
- * @param {LeUtils~__eachCallback} asyncCallback
951
+ * @param {*} elements
952
+ * @param {(value:*, index?:*) => Promise<boolean|undefined>} asyncCallback
640
953
  * @param {number} [optionalParallelCount]
641
954
  * @param {boolean} [optionalSkipHasOwnPropertyCheck]
642
- * @returns {*[]|object|function}
955
+ * @returns {Promise<*>}
643
956
  */
644
957
  eachAsync: function () {
958
+ /**
959
+ * Instead of waiting for every promise individually, this function will queue up multiple promises at once, then wait for any of them to finish, before adding more, until it has looped through all elements.
960
+ * Then, at the end, it will wait for the remaining promises to finish.
961
+ */
645
962
  var eachAsyncParallel = /*#__PURE__*/function () {
646
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(elements, asyncCallback, optionalParallelCount, optionalSkipHasOwnPropertyCheck) {
647
- var promises, doBreak;
648
- return _regeneratorRuntime.wrap(function _callee3$(_context4) {
963
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(elements, asyncCallback, optionalParallelCount, optionalSkipHasOwnPropertyCheck) {
964
+ var runningPromises, doBreak;
965
+ return _regeneratorRuntime.wrap(function (_context4) {
649
966
  while (1) switch (_context4.prev = _context4.next) {
650
967
  case 0:
651
- promises = [];
968
+ runningPromises = new Set();
652
969
  doBreak = false;
653
- _context4.next = 4;
970
+ _context4.next = 1;
654
971
  return LeUtils.eachAsync(elements, /*#__PURE__*/function () {
655
- var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(element, index) {
656
- var _loop, promise;
657
- return _regeneratorRuntime.wrap(function _callee2$(_context3) {
972
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(value, index) {
973
+ var promise;
974
+ return _regeneratorRuntime.wrap(function (_context3) {
658
975
  while (1) switch (_context3.prev = _context3.next) {
659
976
  case 0:
660
- _loop = /*#__PURE__*/_regeneratorRuntime.mark(function _loop() {
661
- var newPromises;
662
- return _regeneratorRuntime.wrap(function _loop$(_context2) {
663
- while (1) switch (_context2.prev = _context2.next) {
664
- case 0:
665
- newPromises = [];
666
- LeUtils.each(promises, function (promise) {
667
- if (!promise.__lowentry_utils__promise_is_done__) {
668
- newPromises.push(promise);
669
- }
670
- });
671
- promises = newPromises;
672
- if (!(promises.length > optionalParallelCount)) {
673
- _context2.next = 6;
674
- break;
675
- }
676
- _context2.next = 6;
677
- return Promise.any(promises);
678
- case 6:
679
- case "end":
680
- return _context2.stop();
681
- }
682
- }, _loop);
683
- });
977
+ if (!doBreak) {
978
+ _context3.next = 1;
979
+ break;
980
+ }
981
+ return _context3.abrupt("return", false);
684
982
  case 1:
685
- if (!(promises.length > optionalParallelCount)) {
686
- _context3.next = 5;
983
+ if (!(runningPromises.size >= optionalParallelCount)) {
984
+ _context3.next = 4;
687
985
  break;
688
986
  }
689
- return _context3.delegateYield(_loop(), "t0", 3);
690
- case 3:
691
- _context3.next = 1;
692
- break;
693
- case 5:
987
+ _context3.next = 2;
988
+ return Promise.race(runningPromises);
989
+ case 2:
694
990
  if (!doBreak) {
695
- _context3.next = 7;
991
+ _context3.next = 3;
696
992
  break;
697
993
  }
698
994
  return _context3.abrupt("return", false);
699
- case 7:
700
- promise = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
701
- return _regeneratorRuntime.wrap(function _callee$(_context) {
702
- while (1) switch (_context.prev = _context.next) {
995
+ case 3:
996
+ _context3.next = 1;
997
+ break;
998
+ case 4:
999
+ // process this element, by creating a promise, and adding it to the queue
1000
+ promise = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
1001
+ var _t8;
1002
+ return _regeneratorRuntime.wrap(function (_context2) {
1003
+ while (1) switch (_context2.prev = _context2.next) {
703
1004
  case 0:
704
- _context.next = 2;
705
- return asyncCallback.call(element, element, index);
706
- case 2:
707
- _context.t0 = _context.sent;
708
- if (!(_context.t0 === false)) {
709
- _context.next = 5;
1005
+ _context2.next = 1;
1006
+ return asyncCallback.call(value, value, index);
1007
+ case 1:
1008
+ _t8 = _context2.sent;
1009
+ if (!(_t8 === false)) {
1010
+ _context2.next = 2;
710
1011
  break;
711
1012
  }
712
1013
  doBreak = true;
713
- case 5:
714
- promise.__lowentry_utils__promise_is_done__ = true;
715
- case 6:
1014
+ case 2:
716
1015
  case "end":
717
- return _context.stop();
1016
+ return _context2.stop();
718
1017
  }
719
- }, _callee);
1018
+ }, _callee2);
720
1019
  }))();
721
- promises.push(promise);
722
- case 9:
1020
+ runningPromises.add(promise);
1021
+ promise["finally"](function () {
1022
+ runningPromises["delete"](promise);
1023
+ });
1024
+ case 5:
723
1025
  case "end":
724
1026
  return _context3.stop();
725
1027
  }
726
- }, _callee2);
1028
+ }, _callee3);
727
1029
  }));
728
1030
  return function (_x5, _x6) {
729
1031
  return _ref3.apply(this, arguments);
730
1032
  };
731
- }(), optionalSkipHasOwnPropertyCheck);
732
- case 4:
733
- _context4.next = 6;
734
- return Promise.all(promises);
735
- case 6:
1033
+ }(), 1, optionalSkipHasOwnPropertyCheck);
1034
+ case 1:
1035
+ _context4.next = 2;
1036
+ return Promise.all(runningPromises);
1037
+ case 2:
736
1038
  return _context4.abrupt("return", elements);
737
- case 7:
1039
+ case 3:
738
1040
  case "end":
739
1041
  return _context4.stop();
740
1042
  }
741
- }, _callee3);
1043
+ }, _callee4);
742
1044
  }));
743
1045
  return function eachAsyncParallel(_x, _x2, _x3, _x4) {
744
1046
  return _ref2.apply(this, arguments);
745
1047
  };
746
1048
  }();
747
1049
  return /*#__PURE__*/function () {
748
- var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(elements, asyncCallback) {
1050
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(elements, asyncCallback) {
749
1051
  var parallelCount,
750
1052
  optionalSkipHasOwnPropertyCheck,
751
- index,
752
- _index2,
753
- _args5 = arguments;
754
- return _regeneratorRuntime.wrap(function _callee4$(_context5) {
1053
+ _iterator6,
1054
+ _step6,
1055
+ _step6$value,
1056
+ value,
1057
+ key,
1058
+ _args5 = arguments,
1059
+ _t9,
1060
+ _t0;
1061
+ return _regeneratorRuntime.wrap(function (_context5) {
755
1062
  while (1) switch (_context5.prev = _context5.next) {
756
1063
  case 0:
757
1064
  parallelCount = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : 1;
758
1065
  optionalSkipHasOwnPropertyCheck = _args5.length > 3 && _args5[3] !== undefined ? _args5[3] : false;
759
1066
  if (!(elements !== null && typeof elements !== 'undefined')) {
760
- _context5.next = 36;
1067
+ _context5.next = 10;
761
1068
  break;
762
1069
  }
763
1070
  parallelCount = INT_LAX(parallelCount);
764
1071
  if (!(parallelCount > 1)) {
765
- _context5.next = 8;
1072
+ _context5.next = 2;
766
1073
  break;
767
1074
  }
768
- _context5.next = 7;
1075
+ _context5.next = 1;
769
1076
  return eachAsyncParallel(elements, asyncCallback, parallelCount, optionalSkipHasOwnPropertyCheck);
770
- case 7:
1077
+ case 1:
771
1078
  return _context5.abrupt("return", _context5.sent);
772
- case 8:
773
- if (!Array.isArray(elements)) {
774
- _context5.next = 21;
775
- break;
776
- }
777
- index = 0;
778
- case 10:
779
- if (!(index < elements.length)) {
780
- _context5.next = 19;
781
- break;
782
- }
783
- _context5.next = 13;
784
- return asyncCallback.call(elements[index], elements[index], index);
785
- case 13:
786
- _context5.t0 = _context5.sent;
787
- if (!(_context5.t0 === false)) {
788
- _context5.next = 16;
789
- break;
790
- }
791
- return _context5.abrupt("break", 19);
792
- case 16:
793
- index++;
794
- _context5.next = 10;
795
- break;
796
- case 19:
797
- _context5.next = 36;
798
- break;
799
- case 21:
800
- if (!(_typeof(elements) === 'object' || typeof elements === 'function')) {
801
- _context5.next = 35;
802
- break;
803
- }
804
- _context5.t1 = _regeneratorRuntime.keys(elements);
805
- case 23:
806
- if ((_context5.t2 = _context5.t1()).done) {
807
- _context5.next = 33;
808
- break;
809
- }
810
- _index2 = _context5.t2.value;
811
- if (!(optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(elements, _index2))) {
812
- _context5.next = 31;
1079
+ case 2:
1080
+ _iterator6 = _createForOfIteratorHelper(LeUtils.eachIterator(elements, optionalSkipHasOwnPropertyCheck));
1081
+ _context5.prev = 3;
1082
+ _iterator6.s();
1083
+ case 4:
1084
+ if ((_step6 = _iterator6.n()).done) {
1085
+ _context5.next = 7;
813
1086
  break;
814
1087
  }
815
- _context5.next = 28;
816
- return asyncCallback.call(elements[_index2], elements[_index2], _index2);
817
- case 28:
818
- _context5.t3 = _context5.sent;
819
- if (!(_context5.t3 === false)) {
820
- _context5.next = 31;
1088
+ _step6$value = _slicedToArray(_step6.value, 2), value = _step6$value[0], key = _step6$value[1];
1089
+ _context5.next = 5;
1090
+ return asyncCallback.call(value, value, key);
1091
+ case 5:
1092
+ _t9 = _context5.sent;
1093
+ if (!(_t9 === false)) {
1094
+ _context5.next = 6;
821
1095
  break;
822
1096
  }
823
- return _context5.abrupt("break", 33);
824
- case 31:
825
- _context5.next = 23;
1097
+ return _context5.abrupt("continue", 7);
1098
+ case 6:
1099
+ _context5.next = 4;
826
1100
  break;
827
- case 33:
828
- _context5.next = 36;
1101
+ case 7:
1102
+ _context5.next = 9;
829
1103
  break;
830
- case 35:
831
- console.warn('Executed LeUtils.eachAsync() on an invalid type: [' + _typeof(elements) + ']', elements);
832
- case 36:
1104
+ case 8:
1105
+ _context5.prev = 8;
1106
+ _t0 = _context5["catch"](3);
1107
+ _iterator6.e(_t0);
1108
+ case 9:
1109
+ _context5.prev = 9;
1110
+ _iterator6.f();
1111
+ return _context5.finish(9);
1112
+ case 10:
833
1113
  return _context5.abrupt("return", elements);
834
- case 37:
1114
+ case 11:
835
1115
  case "end":
836
1116
  return _context5.stop();
837
1117
  }
838
- }, _callee4);
1118
+ }, _callee5, null, [[3, 8, 9, 10]]);
839
1119
  }));
840
1120
  return function (_x7, _x8) {
841
1121
  return _ref5.apply(this, arguments);
@@ -843,146 +1123,137 @@ var LeUtils = {
843
1123
  }();
844
1124
  }(),
845
1125
  /**
846
- * @callback LeUtils~__filterCallback
847
- * @param {*} value
848
- * @param {*} index
849
- * @returns {boolean|undefined}
1126
+ * Returns an empty simplified collection (array, object, or Map), based on the given elements.
1127
+ *
1128
+ * Usage:
1129
+ *
1130
+ * ```js
1131
+ * const [success, collection, add] = LeUtils.getEmptySimplifiedCollection(elements);
1132
+ * ```
1133
+ *
1134
+ * @param {*} elements
1135
+ * @returns {[boolean, *[]|object|Map, (value:*,index:*)=>void]}
850
1136
  */
1137
+ getEmptySimplifiedCollection: function getEmptySimplifiedCollection(elements) {
1138
+ if (elements === null || typeof elements === 'undefined') {
1139
+ return [false, [], function (value, index) {}];
1140
+ }
1141
+ var collection = null;
1142
+ var add = null;
1143
+ if (Array.isArray(elements)) {
1144
+ collection = [];
1145
+ add = function add(value, index) {
1146
+ collection.push(value);
1147
+ };
1148
+ } else if (_typeof(elements) === 'object' && (elements === null || elements === void 0 ? void 0 : elements.constructor) === Object) {
1149
+ collection = {};
1150
+ add = function add(value, index) {
1151
+ collection[index] = value;
1152
+ };
1153
+ } else if (elements instanceof Map) {
1154
+ collection = new Map();
1155
+ add = function add(value, index) {
1156
+ collection.set(index, value);
1157
+ };
1158
+ } else if (typeof elements === 'string' || typeof (elements === null || elements === void 0 ? void 0 : elements[Symbol.iterator]) === 'function' || typeof (elements === null || elements === void 0 ? void 0 : elements.forEach) === 'function') {
1159
+ collection = [];
1160
+ add = function add(value, index) {
1161
+ collection.push(value);
1162
+ };
1163
+ } else if (_typeof(elements) === 'object' || typeof elements === 'function') {
1164
+ collection = {};
1165
+ add = function add(value, index) {
1166
+ collection[index] = value;
1167
+ };
1168
+ } else {
1169
+ console.warn('Executed LeUtils.getEmptySimplifiedCollection() on an invalid type: [' + _typeof(elements) + ']', elements);
1170
+ return [false, [], function (value, index) {}];
1171
+ }
1172
+ return [true, collection, add];
1173
+ },
851
1174
  /**
852
- * Loops through the given elements, and returns a new array or object, with only the elements that returned true (or a value equals to true) from the callback.
1175
+ * Loops through the given elements, and returns a new collection, with only the elements that returned true (or a value equals to true) from the callback.
853
1176
  * If no callback is given, it will return all elements that are of a true value (for example, values that are: not null, not undefined, not false, not 0, not an empty string, not an empty array, not an empty object).
854
1177
  *
855
- * @param {*[]|object|Function} elements
856
- * @param {LeUtils~__filterCallback} [callback]
1178
+ * @param {*} elements
1179
+ * @param {(value:*, index:*) => boolean|undefined} [callback]
857
1180
  * @param {boolean} [optionalSkipHasOwnPropertyCheck]
858
- * @returns {*[]|object|Function}
1181
+ * @returns {*}
859
1182
  */
860
1183
  filter: function filter(elements, callback) {
861
1184
  var optionalSkipHasOwnPropertyCheck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
862
- if (elements !== null && typeof elements !== 'undefined') {
863
- if (Array.isArray(elements)) {
864
- var result = [];
865
- for (var index = 0; index < elements.length; index++) {
866
- if (!callback && elements[index] || callback && callback.call(elements[index], elements[index], index)) {
867
- result.push(elements[index]);
868
- }
869
- }
870
- return result;
871
- } else if (_typeof(elements) === 'object' || typeof elements === 'function') {
872
- var _result = {};
873
- for (var _index3 in elements) {
874
- if (optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(elements, _index3)) {
875
- if (!callback && elements[_index3] || callback && callback.call(elements[_index3], elements[_index3], _index3)) {
876
- _result[_index3] = elements[_index3];
877
- }
878
- }
1185
+ var _LeUtils$getEmptySimp = LeUtils.getEmptySimplifiedCollection(elements),
1186
+ _LeUtils$getEmptySimp2 = _slicedToArray(_LeUtils$getEmptySimp, 3),
1187
+ success = _LeUtils$getEmptySimp2[0],
1188
+ collection = _LeUtils$getEmptySimp2[1],
1189
+ add = _LeUtils$getEmptySimp2[2];
1190
+ if (!success) {
1191
+ return elements;
1192
+ }
1193
+ LeUtils.each(elements, function (value, index) {
1194
+ if (!callback) {
1195
+ if (value) {
1196
+ add(value, index);
879
1197
  }
880
- return _result;
881
- } else {
882
- console.warn('Executed LeUtils.filter() on an invalid type: [' + _typeof(elements) + ']', elements);
1198
+ } else if (callback.call(value, value, index)) {
1199
+ add(value, index);
883
1200
  }
884
- }
885
- return elements;
1201
+ }, optionalSkipHasOwnPropertyCheck);
1202
+ return collection;
886
1203
  },
887
1204
  /**
888
- * @callback LeUtils~__mapCallback
889
- * @param {*} value
890
- * @param {*} index
891
- * @returns {*}
892
- */
893
- /**
894
- * Loops through the given elements, and returns a new array or object, with the elements that were returned from the callback.
1205
+ * Loops through the given elements, and returns a new collection, with the elements that were returned from the callback.
895
1206
  *
896
- * @param {*[]|object|Function} elements
897
- * @param {LeUtils~__mapCallback} [callback]
1207
+ * @param {*} elements
1208
+ * @param {(value:*, index:*) => *} [callback]
898
1209
  * @param {boolean} [optionalSkipHasOwnPropertyCheck]
899
- * @returns {*[]|object|Function}
1210
+ * @returns {*}
900
1211
  */
901
1212
  map: function map(elements, callback) {
902
1213
  var optionalSkipHasOwnPropertyCheck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
903
- if (elements !== null && typeof elements !== 'undefined') {
904
- if (Array.isArray(elements)) {
905
- var result = [];
906
- for (var index = 0; index < elements.length; index++) {
907
- if (!callback) {
908
- result[index] = elements[index];
909
- } else {
910
- result[index] = callback.call(elements[index], elements[index], index);
911
- }
912
- }
913
- return result;
914
- } else if (_typeof(elements) === 'object' || typeof elements === 'function') {
915
- var _result2 = {};
916
- for (var _index4 in elements) {
917
- if (optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(elements, _index4)) {
918
- if (!callback) {
919
- _result2[_index4] = elements[_index4];
920
- } else {
921
- _result2[_index4] = callback.call(elements[_index4], elements[_index4], _index4);
922
- }
923
- }
924
- }
925
- return _result2;
1214
+ var _LeUtils$getEmptySimp3 = LeUtils.getEmptySimplifiedCollection(elements),
1215
+ _LeUtils$getEmptySimp4 = _slicedToArray(_LeUtils$getEmptySimp3, 3),
1216
+ success = _LeUtils$getEmptySimp4[0],
1217
+ collection = _LeUtils$getEmptySimp4[1],
1218
+ add = _LeUtils$getEmptySimp4[2];
1219
+ if (!success) {
1220
+ return elements;
1221
+ }
1222
+ LeUtils.each(elements, function (value, index) {
1223
+ if (!callback) {
1224
+ add(value, index);
926
1225
  } else {
927
- console.warn('Executed LeUtils.map() on an invalid type: [' + _typeof(elements) + ']', elements);
1226
+ add(callback.call(value, value, index), index);
928
1227
  }
929
- }
930
- return elements;
1228
+ }, optionalSkipHasOwnPropertyCheck);
1229
+ return collection;
931
1230
  },
932
- /**
933
- * @callback LeUtils~__mapToArrayCallback
934
- * @param {*} value
935
- * @param {*} index
936
- * @returns {*}
937
- */
938
1231
  /**
939
1232
  * Loops through the given elements, and returns a new array, with the elements that were returned from the callback. Always returns an array.
940
1233
  *
941
- * @param {*[]|object|Function} elements
942
- * @param {LeUtils~__mapToArrayCallback} [callback]
1234
+ * @param {*} elements
1235
+ * @param {(value:*, index:*) => *} [callback]
943
1236
  * @param {boolean} [optionalSkipHasOwnPropertyCheck]
944
1237
  * @returns {*[]}
945
1238
  */
946
1239
  mapToArray: function mapToArray(elements, callback) {
947
1240
  var optionalSkipHasOwnPropertyCheck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
948
1241
  var result = [];
949
- if (elements !== null && typeof elements !== 'undefined') {
950
- if (Array.isArray(elements)) {
951
- for (var index = 0; index < elements.length; index++) {
952
- if (!callback) {
953
- result.push(elements[index]);
954
- } else {
955
- result.push(callback.call(elements[index], elements[index], index));
956
- }
957
- }
958
- } else if (_typeof(elements) === 'object' || typeof elements === 'function') {
959
- for (var _index5 in elements) {
960
- if (optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(elements, _index5)) {
961
- if (!callback) {
962
- result.push(elements[_index5]);
963
- } else {
964
- result.push(callback.call(elements[_index5], elements[_index5], _index5));
965
- }
966
- }
967
- }
1242
+ LeUtils.each(elements, function (value, index) {
1243
+ if (!callback) {
1244
+ result.push(value);
968
1245
  } else {
969
- console.warn('Executed LeUtils.mapToArray() on an invalid type: [' + _typeof(elements) + ']', elements);
1246
+ result.push(callback.call(value, value, index));
970
1247
  }
971
- }
1248
+ }, optionalSkipHasOwnPropertyCheck);
972
1249
  return result;
973
1250
  },
974
- /**
975
- * @callback LeUtils~__mapToArraySortedCallback
976
- * @param {*} value
977
- * @param {*} index
978
- * @returns {*}
979
- */
980
1251
  /**
981
1252
  * Loops through the given elements, and returns a new array, with the elements that were returned from the callback. The elements will be sorted by the result from the given comparator. Always returns an array.
982
1253
  *
983
- * @param {*[]|object|Function} elements
984
- * @param {LeUtils~__sortKeysComparatorCallback} comparator
985
- * @param {LeUtils~__mapToArraySortedCallback} [callback]
1254
+ * @param {*} elements
1255
+ * @param {(valueA:*, valueB:*) => number} comparator
1256
+ * @param {(value:*, index:*) => *} [callback]
986
1257
  * @param {boolean} [optionalSkipHasOwnPropertyCheck]
987
1258
  * @returns {*[]}
988
1259
  */
@@ -990,49 +1261,41 @@ var LeUtils = {
990
1261
  var optionalSkipHasOwnPropertyCheck = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
991
1262
  var keys = LeUtils.sortKeys(elements, comparator, optionalSkipHasOwnPropertyCheck);
992
1263
  var result = [];
993
- for (var i = 0; i < keys.length; i++) {
994
- if (!callback) {
995
- result.push(elements[keys[i]]);
996
- } else {
997
- result.push(callback.call(elements[keys[i]], elements[keys[i]], keys[i]));
1264
+ var _iterator7 = _createForOfIteratorHelper(keys),
1265
+ _step7;
1266
+ try {
1267
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1268
+ var key = _step7.value;
1269
+ var value = LeUtils.getValueAtIndex(elements, key, optionalSkipHasOwnPropertyCheck);
1270
+ if (!callback) {
1271
+ result.push(value);
1272
+ } else {
1273
+ result.push(callback.call(value, value, key));
1274
+ }
998
1275
  }
1276
+ } catch (err) {
1277
+ _iterator7.e(err);
1278
+ } finally {
1279
+ _iterator7.f();
999
1280
  }
1000
1281
  return result;
1001
1282
  },
1002
- /**
1003
- * @callback LeUtils~__sortKeysComparatorCallback
1004
- * @param {*} elementA
1005
- * @param {*} elementB
1006
- * @returns {number}
1007
- */
1008
1283
  /**
1009
1284
  * Loops through the given elements, and returns a new array, with the keys from the given elements, sorted by the result from the given comparator. Always returns an array.
1010
1285
  *
1011
- * @param {*[]|object|Function} elements
1012
- * @param {LeUtils~__sortKeysComparatorCallback} comparator
1286
+ * @param {*} elements
1287
+ * @param {(valueA:*, valueB:*) => number} comparator
1013
1288
  * @param {boolean} [optionalSkipHasOwnPropertyCheck]
1014
1289
  * @returns {*[]}
1015
1290
  */
1016
1291
  sortKeys: function sortKeys(elements, comparator) {
1017
1292
  var optionalSkipHasOwnPropertyCheck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1018
1293
  var keys = [];
1019
- if (elements !== null && typeof elements !== 'undefined') {
1020
- if (Array.isArray(elements)) {
1021
- for (var index = 0; index < elements.length; index++) {
1022
- keys.push(index);
1023
- }
1024
- } else if (_typeof(elements) === 'object' || typeof elements === 'function') {
1025
- for (var _index6 in elements) {
1026
- if (optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(elements, _index6)) {
1027
- keys.push(_index6);
1028
- }
1029
- }
1030
- } else {
1031
- console.warn('Executed LeUtils.sortKeys() on an invalid type: [' + _typeof(elements) + ']', elements);
1032
- }
1033
- }
1294
+ LeUtils.each(elements, function (value, index) {
1295
+ keys.push(index);
1296
+ }, optionalSkipHasOwnPropertyCheck);
1034
1297
  keys.sort(function (a, b) {
1035
- return comparator(elements[a], elements[b]);
1298
+ return comparator(LeUtils.getValueAtIndex(elements, a, optionalSkipHasOwnPropertyCheck), LeUtils.getValueAtIndex(elements, b, optionalSkipHasOwnPropertyCheck));
1036
1299
  });
1037
1300
  return keys;
1038
1301
  },
@@ -1065,6 +1328,37 @@ var LeUtils = {
1065
1328
  return result;
1066
1329
  };
1067
1330
  }(),
1331
+ /**
1332
+ * Turns the given value(s) into a 1 dimensional array.
1333
+ *
1334
+ * Compared to LeUtils.flattenArray(), this function also supports objects, Maps, Sets, and other iterable objects.
1335
+ *
1336
+ * @param {*} elements
1337
+ * @param {boolean} [optionalSkipHasOwnPropertyCheck]
1338
+ * @returns {*[]}
1339
+ */
1340
+ flattenToArray: function () {
1341
+ var _flattenToArrayRecursive = function flattenToArrayRecursive(result, elements, optionalSkipHasOwnPropertyCheck) {
1342
+ if (!LeUtils.supportsEach(elements)) {
1343
+ result.push(elements);
1344
+ return;
1345
+ }
1346
+ LeUtils.each(elements, function (entry) {
1347
+ _flattenToArrayRecursive(result, entry, optionalSkipHasOwnPropertyCheck);
1348
+ }, optionalSkipHasOwnPropertyCheck);
1349
+ };
1350
+ return function (elements) {
1351
+ var optionalSkipHasOwnPropertyCheck = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1352
+ if (!LeUtils.supportsEach(elements)) {
1353
+ return [elements];
1354
+ }
1355
+ var result = [];
1356
+ LeUtils.each(elements, function (entry) {
1357
+ _flattenToArrayRecursive(result, entry, optionalSkipHasOwnPropertyCheck);
1358
+ }, optionalSkipHasOwnPropertyCheck);
1359
+ return result;
1360
+ };
1361
+ }(),
1068
1362
  /**
1069
1363
  * Compares two values. Primarily used for sorting.
1070
1364
  *
@@ -1093,12 +1387,22 @@ var LeUtils = {
1093
1387
  * @returns {number}
1094
1388
  */
1095
1389
  compareNumericStrings: function compareNumericStrings(a, b) {
1096
- a = STRING(a).trim();
1097
- b = STRING(b).trim();
1098
- if (a.length === b.length) {
1099
- return a < b ? -1 : a > b ? 1 : 0;
1390
+ var aParts = STRING(a).split('.');
1391
+ var bParts = STRING(b).split('.');
1392
+ for (var i = 0; i < Math.min(aParts.length, bParts.length); i++) {
1393
+ a = aParts[i].trim();
1394
+ b = bParts[i].trim();
1395
+ if (a.length !== b.length) {
1396
+ return a.length < b.length ? -1 : 1;
1397
+ }
1398
+ if (a !== b) {
1399
+ return a < b ? -1 : 1;
1400
+ }
1100
1401
  }
1101
- return a.length < b.length ? -1 : 1;
1402
+ if (aParts.length !== bParts.length) {
1403
+ return aParts.length < bParts.length ? -1 : 1;
1404
+ }
1405
+ return 0;
1102
1406
  },
1103
1407
  /**
1104
1408
  * Compares two strings generated by LeUtils.timestamp(). Primarily used for sorting.
@@ -1152,27 +1456,27 @@ var LeUtils = {
1152
1456
  * @returns {boolean}
1153
1457
  */
1154
1458
  isGeneratorFunction: function () {
1155
- var GeneratorFunction = _regeneratorRuntime.mark(function _callee5() {
1156
- return _regeneratorRuntime.wrap(function _callee5$(_context6) {
1459
+ var GeneratorFunction = _regeneratorRuntime.mark(function _callee6() {
1460
+ return _regeneratorRuntime.wrap(function (_context6) {
1157
1461
  while (1) switch (_context6.prev = _context6.next) {
1158
1462
  case 0:
1159
1463
  case "end":
1160
1464
  return _context6.stop();
1161
1465
  }
1162
- }, _callee5);
1466
+ }, _callee6);
1163
1467
  }).constructor;
1164
- var AsyncGeneratorFunction = _wrapAsyncGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
1165
- return _regeneratorRuntime.wrap(function _callee6$(_context7) {
1468
+ var AsyncGeneratorFunction = _wrapAsyncGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
1469
+ return _regeneratorRuntime.wrap(function (_context7) {
1166
1470
  while (1) switch (_context7.prev = _context7.next) {
1167
1471
  case 0:
1168
1472
  case "end":
1169
1473
  return _context7.stop();
1170
1474
  }
1171
- }, _callee6);
1475
+ }, _callee7);
1172
1476
  })).constructor;
1173
1477
  var RegularFunction = function () {}.constructor;
1174
- var PossibleGeneratorFunctionNames = Array.from(new Set(['GeneratorFunction', 'AsyncFunction', 'AsyncGeneratorFunction', GeneratorFunction.name, GeneratorFunction.displayName, AsyncGeneratorFunction.name, AsyncGeneratorFunction.displayName])).filter(function (element) {
1175
- return element && element !== RegularFunction.name && element !== RegularFunction.displayName;
1478
+ var PossibleGeneratorFunctionNames = Array.from(new Set(['GeneratorFunction', 'AsyncFunction', 'AsyncGeneratorFunction', GeneratorFunction.name, AsyncGeneratorFunction.name])).filter(function (element) {
1479
+ return element && element !== RegularFunction.name;
1176
1480
  });
1177
1481
  return function (func) {
1178
1482
  if (!func) {
@@ -1182,19 +1486,16 @@ var LeUtils = {
1182
1486
  if (!constructor) {
1183
1487
  return false;
1184
1488
  }
1489
+ // noinspection JSUnresolvedVariable
1185
1490
  return constructor.name && PossibleGeneratorFunctionNames.includes(constructor.name) || constructor.displayName && PossibleGeneratorFunctionNames.includes(constructor.displayName);
1186
1491
  };
1187
1492
  }(),
1188
- /**
1189
- * @callback LeUtils~__setTimeoutCallback
1190
- * @param {number} deltaTime
1191
- */
1192
1493
  /**
1193
1494
  * Executes the callback after the given number of milliseconds. Passes the elapsed time in seconds to the callback.
1194
1495
  *
1195
1496
  * To cancel the timeout, call remove() on the result of this function (example: "const timeoutHandler = LeUtils.setTimeout((deltaTime)=>{}, 1000); timeoutHandler.remove();")
1196
1497
  *
1197
- * @param {LeUtils~__setTimeoutCallback} callback ([number] deltaTime)
1498
+ * @param {(deltaTime:number) => *} callback
1198
1499
  * @param {number} ms
1199
1500
  * @returns {{remove:Function}}
1200
1501
  */
@@ -1206,6 +1507,7 @@ var LeUtils = {
1206
1507
  }
1207
1508
  ms = FLOAT_LAX(ms);
1208
1509
  var lastTime = performance.now();
1510
+ /** @type {number|null} */
1209
1511
  var handler = window.setTimeout(function () {
1210
1512
  var currentTime = performance.now();
1211
1513
  try {
@@ -1224,16 +1526,12 @@ var LeUtils = {
1224
1526
  }
1225
1527
  };
1226
1528
  },
1227
- /**
1228
- * @callback LeUtils~__setIntervalCallback
1229
- * @param {number} deltaTime
1230
- */
1231
1529
  /**
1232
1530
  * Executes the callback every given number of milliseconds. Passes the time difference in seconds between the last frame and now to it.
1233
1531
  *
1234
1532
  * To remove the interval, call remove() on the result of this function (example: "const intervalHandler = LeUtils.setInterval((deltaTime)=>{}, 1000); intervalHandler.remove();")
1235
1533
  *
1236
- * @param {LeUtils~__setIntervalCallback} callback ([number] deltaTime)
1534
+ * @param {(deltaTime:number) => *} callback
1237
1535
  * @param {number} [intervalMs]
1238
1536
  * @param {boolean} [fireImmediately]
1239
1537
  * @returns {{remove:Function}}
@@ -1255,6 +1553,7 @@ var LeUtils = {
1255
1553
  };
1256
1554
  }
1257
1555
  var lastTime = performance.now();
1556
+ /** @type {number|null} */
1258
1557
  var handler = window.setInterval(function () {
1259
1558
  var currentTime = performance.now();
1260
1559
  try {
@@ -1273,16 +1572,12 @@ var LeUtils = {
1273
1572
  }
1274
1573
  };
1275
1574
  },
1276
- /**
1277
- * @callback LeUtils~__setAnimationFrameTimeoutCallback
1278
- * @param {number} deltaTime
1279
- */
1280
1575
  /**
1281
1576
  * Executes the callback after the given number of frames. Passes the elapsed time in seconds to the callback.
1282
1577
  *
1283
1578
  * To cancel the timeout, call remove() on the result of this function (example: "const timeoutHandler = LeUtils.setAnimationFrameTimeout((deltaTime){}, 5); timeoutHandler.remove();")
1284
1579
  *
1285
- * @param {LeUtils~__setAnimationFrameTimeoutCallback} callback ([number] deltaTime)
1580
+ * @param {(deltaTime:number) => *} callback
1286
1581
  * @param {number} [frames]
1287
1582
  * @returns {{remove:Function}}
1288
1583
  */
@@ -1326,16 +1621,12 @@ var LeUtils = {
1326
1621
  }
1327
1622
  };
1328
1623
  },
1329
- /**
1330
- * @callback LeUtils~__setAnimationFrameIntervalCallback
1331
- * @param {number} deltaTime
1332
- */
1333
1624
  /**
1334
1625
  * Executes the callback every given number of frames. Passes the time difference in seconds between the last frame and now to it.
1335
1626
  *
1336
1627
  * To remove the interval, call remove() on the result of this function (example: "const intervalHandler = LeUtils.setAnimationFrameInterval((deltaTime)=>{}, 5); intervalHandler.remove();")
1337
1628
  *
1338
- * @param {LeUtils~__setAnimationFrameIntervalCallback} callback ([number] deltaTime)
1629
+ * @param {(deltaTime:number) => *} callback
1339
1630
  * @param {number} [intervalFrames]
1340
1631
  * @param {boolean} [fireImmediately]
1341
1632
  * @returns {{remove:Function}}
@@ -1393,13 +1684,13 @@ var LeUtils = {
1393
1684
  * Returns a promise, which will be resolved after the given number of milliseconds.
1394
1685
  *
1395
1686
  * @param {number} ms
1396
- * @returns {Promise}
1687
+ * @returns {Promise<number>}
1397
1688
  */
1398
1689
  promiseTimeout: function promiseTimeout(ms) {
1399
1690
  ms = FLOAT_LAX(ms);
1400
1691
  if (ms <= 0) {
1401
1692
  return new Promise(function (resolve) {
1402
- return resolve(undefined);
1693
+ return resolve(0);
1403
1694
  });
1404
1695
  }
1405
1696
  return new Promise(function (resolve) {
@@ -1410,13 +1701,13 @@ var LeUtils = {
1410
1701
  * Returns a promise, which will be resolved after the given number of frames.
1411
1702
  *
1412
1703
  * @param {number} frames
1413
- * @returns {Promise}
1704
+ * @returns {Promise<number>}
1414
1705
  */
1415
1706
  promiseAnimationFrameTimeout: function promiseAnimationFrameTimeout(frames) {
1416
1707
  frames = INT_LAX(frames);
1417
1708
  if (frames <= 0) {
1418
1709
  return new Promise(function (resolve) {
1419
- return resolve(undefined);
1710
+ return resolve(0);
1420
1711
  });
1421
1712
  }
1422
1713
  return new Promise(function (resolve) {
@@ -1427,11 +1718,11 @@ var LeUtils = {
1427
1718
  * Allows you to do a fetch, with built-in retry and abort functionality.
1428
1719
  *
1429
1720
  * @param {string} url
1430
- * @param {Object} [options]
1721
+ * @param {{retries?:number|null, delay?:number|((attempt:number)=>number)|null}|object|null} [options]
1431
1722
  * @returns {{then:Function, catch:Function, finally:Function, remove:Function, isRemoved:Function}}
1432
1723
  */
1433
1724
  fetch: function (_fetch) {
1434
- function fetch(_x9, _x10) {
1725
+ function fetch(_x9, _x0) {
1435
1726
  return _fetch.apply(this, arguments);
1436
1727
  }
1437
1728
  fetch.toString = function () {
@@ -1446,83 +1737,83 @@ var LeUtils = {
1446
1737
  if (typeof window !== 'undefined' && typeof window.AbortController !== 'undefined') {
1447
1738
  controller = new AbortController();
1448
1739
  }
1449
- var promise = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
1740
+ var promise = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
1450
1741
  var _attemptFetch;
1451
- return _regeneratorRuntime.wrap(function _callee8$(_context9) {
1742
+ return _regeneratorRuntime.wrap(function (_context9) {
1452
1743
  while (1) switch (_context9.prev = _context9.next) {
1453
1744
  case 0:
1454
1745
  _attemptFetch = /*#__PURE__*/function () {
1455
- var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
1746
+ var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
1456
1747
  var _controller;
1457
- var _controller2, response, _controller3;
1458
- return _regeneratorRuntime.wrap(function _callee7$(_context8) {
1748
+ var _controller2, response, _controller3, _t1;
1749
+ return _regeneratorRuntime.wrap(function (_context8) {
1459
1750
  while (1) switch (_context8.prev = _context8.next) {
1460
1751
  case 0:
1461
1752
  if (!(controllerAborted || (_controller = controller) !== null && _controller !== void 0 && (_controller = _controller.signal) !== null && _controller !== void 0 && _controller.aborted)) {
1462
- _context8.next = 2;
1753
+ _context8.next = 1;
1463
1754
  break;
1464
1755
  }
1465
1756
  throw new Error('Aborted');
1466
- case 2:
1467
- _context8.prev = 2;
1468
- _context8.next = 5;
1757
+ case 1:
1758
+ _context8.prev = 1;
1759
+ _context8.next = 2;
1469
1760
  return fetch(url, _objectSpread(_objectSpread({
1470
1761
  signal: (_controller2 = controller) === null || _controller2 === void 0 ? void 0 : _controller2.signal
1471
1762
  }, options !== null && options !== void 0 ? options : {}), {}, {
1472
1763
  retries: undefined,
1473
1764
  delay: undefined
1474
1765
  }));
1475
- case 5:
1766
+ case 2:
1476
1767
  response = _context8.sent;
1477
1768
  if (response.ok) {
1478
- _context8.next = 8;
1769
+ _context8.next = 3;
1479
1770
  break;
1480
1771
  }
1481
1772
  throw new Error('Network request failed: ' + response.status + ' ' + response.statusText);
1482
- case 8:
1773
+ case 3:
1483
1774
  return _context8.abrupt("return", response);
1484
- case 11:
1485
- _context8.prev = 11;
1486
- _context8.t0 = _context8["catch"](2);
1775
+ case 4:
1776
+ _context8.prev = 4;
1777
+ _t1 = _context8["catch"](1);
1487
1778
  if (!(controllerAborted || (_controller3 = controller) !== null && _controller3 !== void 0 && (_controller3 = _controller3.signal) !== null && _controller3 !== void 0 && _controller3.aborted)) {
1488
- _context8.next = 15;
1779
+ _context8.next = 5;
1489
1780
  break;
1490
1781
  }
1491
1782
  throw new Error('Aborted');
1492
- case 15:
1783
+ case 5:
1493
1784
  if (!(currentRetries >= retries)) {
1494
- _context8.next = 17;
1785
+ _context8.next = 6;
1495
1786
  break;
1496
1787
  }
1497
- throw _context8.t0;
1498
- case 17:
1788
+ throw _t1;
1789
+ case 6:
1499
1790
  currentRetries++;
1500
- _context8.next = 20;
1791
+ _context8.next = 7;
1501
1792
  return LeUtils.promiseTimeout(typeof (options === null || options === void 0 ? void 0 : options.delay) === 'function' ? INT_LAX_ANY(options === null || options === void 0 ? void 0 : options.delay(currentRetries), 500) : INT_LAX_ANY(options === null || options === void 0 ? void 0 : options.delay, 500));
1502
- case 20:
1503
- _context8.next = 22;
1793
+ case 7:
1794
+ _context8.next = 8;
1504
1795
  return _attemptFetch();
1505
- case 22:
1796
+ case 8:
1506
1797
  return _context8.abrupt("return", _context8.sent);
1507
- case 23:
1798
+ case 9:
1508
1799
  case "end":
1509
1800
  return _context8.stop();
1510
1801
  }
1511
- }, _callee7, null, [[2, 11]]);
1802
+ }, _callee8, null, [[1, 4]]);
1512
1803
  }));
1513
1804
  return function attemptFetch() {
1514
1805
  return _ref7.apply(this, arguments);
1515
1806
  };
1516
1807
  }();
1517
- _context9.next = 3;
1808
+ _context9.next = 1;
1518
1809
  return _attemptFetch();
1519
- case 3:
1810
+ case 1:
1520
1811
  return _context9.abrupt("return", _context9.sent);
1521
- case 4:
1812
+ case 2:
1522
1813
  case "end":
1523
1814
  return _context9.stop();
1524
1815
  }
1525
- }, _callee8);
1816
+ }, _callee9);
1526
1817
  }))();
1527
1818
  var result = {};
1528
1819
  result.then = function () {
@@ -1554,6 +1845,120 @@ var LeUtils = {
1554
1845
  };
1555
1846
  return result;
1556
1847
  }),
1848
+ /**
1849
+ * Allows you to do a fetch, with built-in retry functionality. Caches on the requested URL, so that the same URL will not be fetched multiple times.
1850
+ *
1851
+ * @param {string} url
1852
+ * @param {{retries?:number|null, delay?:number|((attempt:number)=>number)|null, [verify]:((data:*,response:*)=>void)|null}|null} [options]
1853
+ * @param {((response:*)=>*)|null} [responseFunction] A function that will be called with the response object, and should return the data to be cached.
1854
+ * @returns {Promise<*>}
1855
+ */
1856
+ cachedFetch: function () {
1857
+ var cache = new Map();
1858
+ return /*#__PURE__*/function () {
1859
+ var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee1(url, options, responseFunction) {
1860
+ var result, promise;
1861
+ return _regeneratorRuntime.wrap(function (_context1) {
1862
+ while (1) switch (_context1.prev = _context1.next) {
1863
+ case 0:
1864
+ if (!cache.has(url)) {
1865
+ _context1.next = 5;
1866
+ break;
1867
+ }
1868
+ result = cache.get(url);
1869
+ if (!result.data) {
1870
+ _context1.next = 1;
1871
+ break;
1872
+ }
1873
+ return _context1.abrupt("return", result.data);
1874
+ case 1:
1875
+ if (!result.promise) {
1876
+ _context1.next = 3;
1877
+ break;
1878
+ }
1879
+ _context1.next = 2;
1880
+ return result.promise;
1881
+ case 2:
1882
+ return _context1.abrupt("return", _context1.sent);
1883
+ case 3:
1884
+ if (!result.error) {
1885
+ _context1.next = 4;
1886
+ break;
1887
+ }
1888
+ throw result.error;
1889
+ case 4:
1890
+ console.warn('Failed to use the cachedFetch cache, for URL: ', url, ', it is in an unexpected state: ', result);
1891
+ return _context1.abrupt("return", null);
1892
+ case 5:
1893
+ promise = LeUtils.fetch(url, options).then(/*#__PURE__*/function () {
1894
+ var _ref9 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee0(response) {
1895
+ var data, _t10;
1896
+ return _regeneratorRuntime.wrap(function (_context0) {
1897
+ while (1) switch (_context0.prev = _context0.next) {
1898
+ case 0:
1899
+ if (!responseFunction) {
1900
+ _context0.next = 2;
1901
+ break;
1902
+ }
1903
+ _context0.next = 1;
1904
+ return responseFunction(response);
1905
+ case 1:
1906
+ _t10 = _context0.sent;
1907
+ _context0.next = 3;
1908
+ break;
1909
+ case 2:
1910
+ _t10 = response;
1911
+ case 3:
1912
+ data = _t10;
1913
+ if (!(typeof (options === null || options === void 0 ? void 0 : options.verify) === 'function')) {
1914
+ _context0.next = 4;
1915
+ break;
1916
+ }
1917
+ _context0.next = 4;
1918
+ return options.verify(data, response);
1919
+ case 4:
1920
+ return _context0.abrupt("return", data);
1921
+ case 5:
1922
+ case "end":
1923
+ return _context0.stop();
1924
+ }
1925
+ }, _callee0);
1926
+ }));
1927
+ return function (_x12) {
1928
+ return _ref9.apply(this, arguments);
1929
+ };
1930
+ }()).then(function (data) {
1931
+ cache.set(url, {
1932
+ data: data
1933
+ });
1934
+ return data;
1935
+ })["catch"](function (error) {
1936
+ cache.set(url, {
1937
+ error: error
1938
+ });
1939
+ console.error('Failed to fetch: ', error);
1940
+ throw error;
1941
+ });
1942
+ if (!cache.has(url)) {
1943
+ cache.set(url, {
1944
+ promise: promise
1945
+ });
1946
+ }
1947
+ _context1.next = 6;
1948
+ return promise;
1949
+ case 6:
1950
+ return _context1.abrupt("return", _context1.sent);
1951
+ case 7:
1952
+ case "end":
1953
+ return _context1.stop();
1954
+ }
1955
+ }, _callee1);
1956
+ }));
1957
+ return function (_x1, _x10, _x11) {
1958
+ return _ref8.apply(this, arguments);
1959
+ };
1960
+ }();
1961
+ }(),
1557
1962
  /**
1558
1963
  * Returns true if the user is on a smartphone device (mobile).
1559
1964
  * Will return false if the user is on a tablet or on a desktop.
@@ -1759,7 +2164,7 @@ var LeUtils = {
1759
2164
  * - foo-bar
1760
2165
  * - foo_bar
1761
2166
  *
1762
- * @param {string} names
2167
+ * @param {string[]} names
1763
2168
  * @returns {string[]}
1764
2169
  */
1765
2170
  generateNamePermutations: function generateNamePermutations() {
@@ -1802,17 +2207,17 @@ var LeUtils = {
1802
2207
  if (string === '') {
1803
2208
  return '1';
1804
2209
  }
1805
- for (var _i = string.length - 1; _i >= 0; _i--) {
1806
- var _c = string.charAt(_i);
2210
+ for (var _i7 = string.length - 1; _i7 >= 0; _i7--) {
2211
+ var _c = string.charAt(_i7);
1807
2212
  if (_c < '0' || _c > '9') {
1808
2213
  return '1';
1809
2214
  }
1810
2215
  if (_c < '9') {
1811
- _c++;
1812
- string = string.substring(0, _i) + _c + string.substring(_i + 1); // string[i] = (char + 1);
2216
+ _c = String.fromCharCode(_c.charCodeAt(0) + 1);
2217
+ string = string.substring(0, _i7) + _c + string.substring(_i7 + 1); // string[i] = (char + 1);
1813
2218
  break;
1814
2219
  }
1815
- string = string.substring(0, _i) + '0' + string.substring(_i + 1); // string[i] = '0';
2220
+ string = string.substring(0, _i7) + '0' + string.substring(_i7 + 1); // string[i] = '0';
1816
2221
  }
1817
2222
  if (string.charAt(0) === '0') {
1818
2223
  string = '1' + string;
@@ -1826,7 +2231,7 @@ var LeUtils = {
1826
2231
  */
1827
2232
  uniqueId: function () {
1828
2233
  var previousUniqueIdsTime = null;
1829
- var previousUniqueIds = {};
2234
+ var previousUniqueIds = new Map();
1830
2235
  var numberToBytes = function numberToBytes(number) {
1831
2236
  var size = number === 0 ? 0 : Math.ceil((Math.floor(Math.log2(number)) + 1) / 8);
1832
2237
  var bytes = new Uint8ClampedArray(size);
@@ -1886,10 +2291,11 @@ var LeUtils = {
1886
2291
  var result = generateUniqueId();
1887
2292
  if (previousUniqueIdsTime !== result.time) {
1888
2293
  previousUniqueIdsTime = result.time;
1889
- previousUniqueIds = _defineProperty({}, result.id, true);
2294
+ previousUniqueIds.clear();
2295
+ previousUniqueIds.set(result.id, true);
1890
2296
  return result.id;
1891
- } else if (previousUniqueIds[result.id] !== true) {
1892
- previousUniqueIds[result.id] = true;
2297
+ } else if (previousUniqueIds.get(result.id) !== true) {
2298
+ previousUniqueIds.set(result.id, true);
1893
2299
  return result.id;
1894
2300
  }
1895
2301
  }
@@ -1955,7 +2361,7 @@ var LeUtils = {
1955
2361
  getPercentage: function getPercentage(part, total) {
1956
2362
  part = FLOAT_LAX(part);
1957
2363
  total = FLOAT_LAX(total);
1958
- if (total <= 0) {
2364
+ if (total === 0) {
1959
2365
  return 100;
1960
2366
  }
1961
2367
  return Math.max(0, Math.min(100, part / total * 100));
@@ -1976,17 +2382,16 @@ var LeUtils = {
1976
2382
  var ctx = canvas.getContext('2d');
1977
2383
  var width = Math.floor(image.width);
1978
2384
  var height = Math.floor(image.height);
1979
- if (width <= 0 || height <= 0) {
1980
- canvas.width = 1;
1981
- canvas.height = 1;
1982
- } else {
1983
- canvas.width = width;
1984
- canvas.height = height;
1985
- ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
2385
+ if (!ctx || width <= 0 || height <= 0) {
2386
+ return new Uint8ClampedArray();
1986
2387
  }
2388
+ canvas.width = width;
2389
+ canvas.height = height;
2390
+ ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
1987
2391
  return ctx.getImageData(0, 0, canvas.width, canvas.height).data;
1988
2392
  } finally {
1989
- canvas.parentNode.removeChild(canvas);
2393
+ var _canvas$parentNode;
2394
+ canvas === null || canvas === void 0 || (_canvas$parentNode = canvas.parentNode) === null || _canvas$parentNode === void 0 || _canvas$parentNode.removeChild(canvas);
1990
2395
  }
1991
2396
  },
1992
2397
  /**
@@ -2006,20 +2411,19 @@ var LeUtils = {
2006
2411
  var ctx = canvas.getContext('2d');
2007
2412
  var width = Math.floor(image.width);
2008
2413
  var height = Math.floor(image.height);
2009
- if (width <= 0 || height <= 0) {
2010
- canvas.width = 1;
2011
- canvas.height = 1;
2012
- } else {
2013
- canvas.width = width;
2014
- canvas.height = height;
2015
- ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
2414
+ if (!ctx || width <= 0 || height <= 0) {
2415
+ return LeUtils.getEmptyImageSrc();
2016
2416
  }
2417
+ canvas.width = width;
2418
+ canvas.height = height;
2419
+ ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
2017
2420
  ctx.globalCompositeOperation = 'source-in';
2018
2421
  ctx.fillStyle = color;
2019
2422
  ctx.fillRect(0, 0, canvas.width, canvas.height);
2020
2423
  return canvas.toDataURL('image/png');
2021
2424
  } finally {
2022
- canvas.parentNode.removeChild(canvas);
2425
+ var _canvas$parentNode2;
2426
+ canvas === null || canvas === void 0 || (_canvas$parentNode2 = canvas.parentNode) === null || _canvas$parentNode2 === void 0 || _canvas$parentNode2.removeChild(canvas);
2023
2427
  }
2024
2428
  },
2025
2429
  /**
@@ -2041,14 +2445,19 @@ var LeUtils = {
2041
2445
  * @returns {number[]}
2042
2446
  */
2043
2447
  hexToRgb: function hexToRgb(hexstring) {
2448
+ var _hexstring$match;
2449
+ var initialHexstring = hexstring;
2044
2450
  hexstring = hexstring.replace(/[^0-9A-F]/gi, '');
2045
2451
  var hasAlpha = hexstring.length === 4 || hexstring.length === 8;
2046
2452
  while (hexstring.length < 6) {
2047
2453
  hexstring = hexstring.replace(/(.)/g, '$1$1');
2048
2454
  }
2049
- var result = hexstring.match(/\w{2}/g).map(function (a) {
2455
+ var result = (_hexstring$match = hexstring.match(/\w{2}/g)) === null || _hexstring$match === void 0 ? void 0 : _hexstring$match.map(function (a) {
2050
2456
  return parseInt(a, 16);
2051
2457
  });
2458
+ if (!result || result.length < 3) {
2459
+ throw new Error('Invalid hex color: "' + hexstring + '" (was given "' + initialHexstring + '")');
2460
+ }
2052
2461
  return [result[0], result[1], result[2]].concat(_toConsumableArray(hasAlpha ? [result[3]] : []));
2053
2462
  },
2054
2463
  /**
@@ -2063,12 +2472,10 @@ var LeUtils = {
2063
2472
  var b = rgb[2] / 255;
2064
2473
  var max = Math.max(r, g, b);
2065
2474
  var min = Math.min(r, g, b);
2066
- var h,
2067
- s,
2068
- l = (max + min) / 2;
2069
- if (max === min) {
2070
- h = s = 0;
2071
- } else {
2475
+ var h = 0;
2476
+ var s = 0;
2477
+ var l = (max + min) / 2;
2478
+ if (max !== min) {
2072
2479
  var d = max - min;
2073
2480
  s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
2074
2481
  switch (max) {
@@ -2115,10 +2522,10 @@ var LeUtils = {
2115
2522
  var h = hsl[0];
2116
2523
  var s = hsl[1];
2117
2524
  var l = hsl[2];
2118
- var r, g, b;
2119
- if (s === 0) {
2120
- r = g = b = l;
2121
- } else {
2525
+ var r = 1;
2526
+ var g = 1;
2527
+ var b = 1;
2528
+ if (s !== 0) {
2122
2529
  var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
2123
2530
  var p = 2 * l - q;
2124
2531
  r = hue2rgb(p, q, h + 1 / 3);
@@ -2156,13 +2563,13 @@ var LeUtils = {
2156
2563
  *
2157
2564
  * Returns a number:
2158
2565
  *
2159
- * <pre>
2160
- * < 1.0 is not perceptible by human eyes
2566
+ * ```js
2567
+ * < 1 is not perceptible by human eyes
2161
2568
  * 1-2 is perceptible through close observation
2162
2569
  * 2-10 is perceptible at a glance
2163
2570
  * 11-49 is more similar than opposite
2164
2571
  * 100 is exactly the opposite color
2165
- * </pre>
2572
+ * ```
2166
2573
  *
2167
2574
  * @param {number[]} rgbA
2168
2575
  * @param {number[]} rgbB
@@ -2178,13 +2585,13 @@ var LeUtils = {
2178
2585
  *
2179
2586
  * Returns a number:
2180
2587
  *
2181
- * <pre>
2182
- * < 1.0 is not perceptible by human eyes
2588
+ * ```js
2589
+ * < 1 is not perceptible by human eyes
2183
2590
  * 1-2 is perceptible through close observation
2184
2591
  * 2-10 is perceptible at a glance
2185
2592
  * 11-49 is more similar than opposite
2186
2593
  * 100 is exactly the opposite color
2187
- * </pre>
2594
+ * ```
2188
2595
  *
2189
2596
  * @param {number[]} labA
2190
2597
  * @param {number[]} labB
@@ -2213,16 +2620,16 @@ var LeUtils = {
2213
2620
  *
2214
2621
  * Usage:
2215
2622
  *
2216
- * <pre>
2623
+ * ```js
2217
2624
  * LeUtils.getRgbOfGradient({
2218
2625
  * 0: [255, 0, 0],
2219
2626
  * 33: [255, 255, 0],
2220
2627
  * 66: [0, 255, 0],
2221
2628
  * 100:[0, 255, 255],
2222
2629
  * }, 45.1234);
2223
- * </pre>
2630
+ * ```
2224
2631
  *
2225
- * @param {{[percentage]: number[]}} gradient
2632
+ * @param {{percentage?:number[]}} gradient
2226
2633
  * @param {number} percentage
2227
2634
  * @returns {number[]}
2228
2635
  */
@@ -2241,11 +2648,13 @@ var LeUtils = {
2241
2648
  }
2242
2649
  });
2243
2650
  if (closest === null) {
2244
- return null;
2651
+ return [0, 0, 0];
2245
2652
  }
2246
2653
  closest = closest[0];
2247
- var higher = 99999;
2248
- var lower = -99999;
2654
+ var HIGHER = 99999;
2655
+ var LOWER = -99999;
2656
+ var higher = HIGHER;
2657
+ var lower = LOWER;
2249
2658
  LeUtils.each(gradient, function (color, percent) {
2250
2659
  percent = INT_LAX(percent);
2251
2660
  if (percent < closest) {
@@ -2259,15 +2668,9 @@ var LeUtils = {
2259
2668
  }
2260
2669
  }
2261
2670
  });
2262
- if (higher === 99999) {
2263
- higher = null;
2264
- }
2265
- if (lower === -99999) {
2266
- lower = null;
2267
- }
2268
- if (higher === null && lower === null || higher === lower) {
2671
+ if (higher === HIGHER && lower === LOWER || higher === lower) {
2269
2672
  return gradient[closest];
2270
- } else if (higher !== null && lower !== null) {
2673
+ } else if (higher !== HIGHER && lower !== LOWER) {
2271
2674
  var higherDifference = Math.abs(higher - percentage);
2272
2675
  var lowerDifference = Math.abs(percentage - lower);
2273
2676
  if (higherDifference > lowerDifference) {
@@ -2275,7 +2678,7 @@ var LeUtils = {
2275
2678
  } else {
2276
2679
  lower = closest;
2277
2680
  }
2278
- } else if (lower === null) {
2681
+ } else if (lower === LOWER) {
2279
2682
  lower = closest;
2280
2683
  } else {
2281
2684
  higher = closest;
@@ -2315,7 +2718,7 @@ var LeUtils = {
2315
2718
  * @returns {string}
2316
2719
  */
2317
2720
  btoa: function (_btoa) {
2318
- function btoa(_x11) {
2721
+ function btoa(_x13) {
2319
2722
  return _btoa.apply(this, arguments);
2320
2723
  }
2321
2724
  btoa.toString = function () {
@@ -2335,7 +2738,7 @@ var LeUtils = {
2335
2738
  * @returns {string}
2336
2739
  */
2337
2740
  atob: function (_atob) {
2338
- function atob(_x12) {
2741
+ function atob(_x14) {
2339
2742
  return _atob.apply(this, arguments);
2340
2743
  }
2341
2744
  atob.toString = function () {
@@ -2388,9 +2791,14 @@ var LeUtils = {
2388
2791
  * @returns {string}
2389
2792
  */
2390
2793
  hexToBase64: function hexToBase64(hexstring) {
2391
- return LeUtils.btoa(hexstring.replace(/[^0-9A-F]/gi, '').match(/\w{2}/g).map(function (a) {
2794
+ var _hexstring$replace$ma;
2795
+ var hexResult = (_hexstring$replace$ma = hexstring.replace(/[^0-9A-F]/gi, '').match(/\w{2}/g)) === null || _hexstring$replace$ma === void 0 || (_hexstring$replace$ma = _hexstring$replace$ma.map(function (a) {
2392
2796
  return String.fromCharCode(parseInt(a, 16));
2393
- }).join(''));
2797
+ })) === null || _hexstring$replace$ma === void 0 ? void 0 : _hexstring$replace$ma.join('');
2798
+ if (!hexResult) {
2799
+ throw new Error('Invalid hex string: "' + hexstring + '"');
2800
+ }
2801
+ return LeUtils.btoa(hexResult);
2394
2802
  },
2395
2803
  /**
2396
2804
  * Converts a base64 string into bytes (Uint8Array).
@@ -2410,7 +2818,7 @@ var LeUtils = {
2410
2818
  /**
2411
2819
  * Converts bytes into a base64 string.
2412
2820
  *
2413
- * @param {ArrayLike<number>|ArrayBufferLike} arraybuffer
2821
+ * @param {ArrayLike<number>|ArrayBuffer} arraybuffer
2414
2822
  * @returns {string}
2415
2823
  */
2416
2824
  bytesToBase64: function bytesToBase64(arraybuffer) {
@@ -2454,10 +2862,8 @@ var LeUtils = {
2454
2862
  return;
2455
2863
  }
2456
2864
  try {
2457
- result = JSON.parse(result);
2458
- if (typeof result['-'] !== 'undefined') {
2459
- return result['-'];
2460
- }
2865
+ var _JSON$parse;
2866
+ return (_JSON$parse = JSON.parse(result)) === null || _JSON$parse === void 0 ? void 0 : _JSON$parse['-'];
2461
2867
  } catch (e) {}
2462
2868
  },
2463
2869
  /**
@@ -2545,8 +2951,8 @@ var LeUtils = {
2545
2951
  * This way, you can have values that aren't the same be treated as if they are. This can be used to deal with issues such as floating point errors for example.
2546
2952
  *
2547
2953
  * @param {*[]} elements
2548
- * @param {Function} comparator
2549
- * @returns {{getElements: (function(): *[]), getComparator: (function(): Function), size: (function(): number), isEmpty: (function(): boolean), contains: (function(*): boolean), first: (function(): *|undefined), last: (function(): *|undefined), pollFirst: (function(): *|undefined), pollLast: (function(): *|undefined), add: function(*), addAll: function(*[]|object), getEqualValue: (function(*): (*)), getEqualValueOrAdd: (function(*): (*))}}
2954
+ * @param {(valueA:*, valueB:*) => number} comparator
2955
+ * @returns {{getElements:(()=>*[]), getComparator:(()=>((valueA:*,valueB:*)=>number)), size:(()=>number), isEmpty:(()=>boolean), contains:((value:*)=>boolean), first:(()=>*|undefined), last:(()=>*|undefined), pollFirst:(()=>*|undefined), pollLast:(()=>*|undefined), add:((value:*)=>void), addAll:((values:*)=>void), getEqualValue:((value:*)=>*), getEqualValueOrAdd:((value:*)=>*)}}
2550
2956
  */
2551
2957
  createTreeSet: function createTreeSet(elements, comparator) {
2552
2958
  comparator = comparator || LeUtils.compare;
@@ -2596,7 +3002,7 @@ var LeUtils = {
2596
3002
  /**
2597
3003
  * Returns the comparator of the set.
2598
3004
  *
2599
- * @returns {Function}
3005
+ * @returns {(valueA:*, valueB:*) => number}
2600
3006
  */
2601
3007
  getComparator: function getComparator() {
2602
3008
  return comparator;
@@ -2673,7 +3079,7 @@ var LeUtils = {
2673
3079
  /**
2674
3080
  * Adds all the given values to the set. Will only do so if no equal value already exists.
2675
3081
  *
2676
- * @param {*[]|object} values
3082
+ * @param {*} values
2677
3083
  */
2678
3084
  addAll: function addAll(values) {
2679
3085
  LeUtils.each(values, treeSet.add);
@@ -2709,7 +3115,7 @@ var LeUtils = {
2709
3115
  return treeSet;
2710
3116
  },
2711
3117
  /**
2712
- * @typedef {Object} LeUtils~TransactionalValue
3118
+ * @typedef {Object} LeUtils_TransactionalValue
2713
3119
  * @property {*} value
2714
3120
  * @property {{id:string, value:*}[]} changes
2715
3121
  */
@@ -2722,7 +3128,7 @@ var LeUtils = {
2722
3128
  * This allows you to make multiple unconfirmed changes, and confirm or cancel each of them individually at any time.
2723
3129
  *
2724
3130
  * @param {*} [value]
2725
- * @returns {LeUtils~TransactionalValue}
3131
+ * @returns {LeUtils_TransactionalValue}
2726
3132
  */
2727
3133
  createTransactionalValue: function createTransactionalValue(value) {
2728
3134
  if (typeof value === 'undefined') {
@@ -2736,7 +3142,7 @@ var LeUtils = {
2736
3142
  /**
2737
3143
  * Returns true if the given value is a valid TransactionalValue, returns false if it isn't.
2738
3144
  *
2739
- * @param {LeUtils~TransactionalValue} transactionalValue
3145
+ * @param {LeUtils_TransactionalValue} transactionalValue
2740
3146
  * @returns {boolean}
2741
3147
  */
2742
3148
  isTransactionalValueValid: function isTransactionalValueValid(transactionalValue) {
@@ -2745,7 +3151,7 @@ var LeUtils = {
2745
3151
  /**
2746
3152
  * Returns true if the given value is a TransactionalValue, false otherwise.
2747
3153
  *
2748
- * @param {LeUtils~TransactionalValue} transactionalValue
3154
+ * @param {LeUtils_TransactionalValue} transactionalValue
2749
3155
  * @returns {string}
2750
3156
  */
2751
3157
  transactionalValueToString: function transactionalValueToString(transactionalValue) {
@@ -2764,7 +3170,7 @@ var LeUtils = {
2764
3170
  /**
2765
3171
  * Sets the committed value of the given TransactionalValue to the given value. Clears out the previously uncommitted changes.
2766
3172
  *
2767
- * @param {LeUtils~TransactionalValue} transactionalValue
3173
+ * @param {LeUtils_TransactionalValue} transactionalValue
2768
3174
  * @param {*} value
2769
3175
  */
2770
3176
  transactionSetAndCommit: function transactionSetAndCommit(transactionalValue, value) {
@@ -2779,7 +3185,7 @@ var LeUtils = {
2779
3185
  * Sets the value of the given TransactionalValue to the given value, without yet committing it, meaning it can be committed or cancelled later.
2780
3186
  * It returns the ID of the change, which can be used to commit or cancel the change later.
2781
3187
  *
2782
- * @param {LeUtils~TransactionalValue} transactionalValue
3188
+ * @param {LeUtils_TransactionalValue} transactionalValue
2783
3189
  * @param {*} value
2784
3190
  * @returns {string}
2785
3191
  */
@@ -2799,7 +3205,7 @@ var LeUtils = {
2799
3205
  * Commits the change with the given ID, making it the new committed value.
2800
3206
  * Returns true if the change was found and committed, returns false if it was already overwritten by a newer committed change.
2801
3207
  *
2802
- * @param {LeUtils~TransactionalValue} transactionalValue
3208
+ * @param {LeUtils_TransactionalValue} transactionalValue
2803
3209
  * @param {string} changeId
2804
3210
  * @returns {boolean}
2805
3211
  */
@@ -2817,7 +3223,7 @@ var LeUtils = {
2817
3223
  * Cancels the change with the given ID, removing it from the uncommitted changes.
2818
3224
  * Returns true if the change was found and removed, returns false if it was already overwritten by a newer committed change.
2819
3225
  *
2820
- * @param {LeUtils~TransactionalValue} transactionalValue
3226
+ * @param {LeUtils_TransactionalValue} transactionalValue
2821
3227
  * @param {string} changeId
2822
3228
  * @returns {boolean}
2823
3229
  */
@@ -2834,7 +3240,7 @@ var LeUtils = {
2834
3240
  * Returns true if the change was found, meaning it can still make a difference to the final committed value of this TransactionalValue.
2835
3241
  * Returns false if it was already overwritten by a newer committed change, meaning that this change can no longer make a difference to the final committed value of this TransactionalValue.
2836
3242
  *
2837
- * @param {LeUtils~TransactionalValue} transactionalValue
3243
+ * @param {LeUtils_TransactionalValue} transactionalValue
2838
3244
  * @param {string} changeId
2839
3245
  * @returns {boolean}
2840
3246
  */
@@ -2845,7 +3251,7 @@ var LeUtils = {
2845
3251
  /**
2846
3252
  * Returns the committed value of the given TransactionalValue.
2847
3253
  *
2848
- * @param {LeUtils~TransactionalValue} transactionalValue
3254
+ * @param {LeUtils_TransactionalValue} transactionalValue
2849
3255
  * @returns {*}
2850
3256
  */
2851
3257
  transactionGetCommittedValue: function transactionGetCommittedValue(transactionalValue) {
@@ -2855,7 +3261,7 @@ var LeUtils = {
2855
3261
  /**
2856
3262
  * Returns the value (including any uncommitted changes made to it) of the given TransactionalValue.
2857
3263
  *
2858
- * @param {LeUtils~TransactionalValue} transactionalValue
3264
+ * @param {LeUtils_TransactionalValue} transactionalValue
2859
3265
  * @returns {*}
2860
3266
  */
2861
3267
  transactionGetValue: function transactionGetValue(transactionalValue) {
@@ -2917,24 +3323,26 @@ var LeUtils = {
2917
3323
  * ```
2918
3324
  *
2919
3325
  * @param {string} name
2920
- * @returns {{worker: Worker, sendMessage: function(Object, {timeout: number|undefined}|undefined): Promise<Object>}}
3326
+ * @returns {{worker:Worker|null, sendMessage:(data:Object,options:{timeout:number|undefined}|undefined)=>Promise<Object>}}
2921
3327
  */
2922
3328
  createWorkerThread: function createWorkerThread(name) {
2923
3329
  if (typeof window === 'undefined' || typeof Worker === 'undefined') {
2924
3330
  return {
2925
3331
  worker: null,
2926
- sendMessage: new Promise(function (resolve, reject) {
2927
- reject('Workers are not supported in this environment');
2928
- })
3332
+ sendMessage: function sendMessage(data, options) {
3333
+ return new Promise(function (resolve, reject) {
3334
+ reject('Workers are not supported in this environment');
3335
+ });
3336
+ }
2929
3337
  };
2930
3338
  }
2931
3339
  var worker = new Worker('/workers/' + name + '.worker.js');
2932
- var listeners = {};
3340
+ var listeners = new Map();
2933
3341
  var addListener = function addListener(id, callback) {
2934
- listeners[id] = callback;
3342
+ listeners.set(id, callback);
2935
3343
  };
2936
3344
  var removeListener = function removeListener(id) {
2937
- delete listeners[id];
3345
+ listeners["delete"](id);
2938
3346
  };
2939
3347
  var sendMessage = function sendMessage(data, options) {
2940
3348
  return new Promise(function (resolve, reject) {
@@ -2956,7 +3364,7 @@ var LeUtils = {
2956
3364
  worker.onmessage = function (message) {
2957
3365
  var data = message.data;
2958
3366
  if (data !== null && data !== void 0 && data.id) {
2959
- var callback = listeners[data.id];
3367
+ var callback = listeners.get(data.id);
2960
3368
  if (callback) {
2961
3369
  removeListener(data.id);
2962
3370
  callback(data);
@@ -2975,16 +3383,16 @@ var LeUtils = {
2975
3383
  *
2976
3384
  * @param {string} workerName
2977
3385
  * @param {Object} data
2978
- * @param {{timeout: number|undefined}} [options]
3386
+ * @param {{timeout:number|undefined}} [options]
2979
3387
  * @returns {Promise<Object>}
2980
3388
  */
2981
3389
  sendWorkerMessage: function () {
2982
- var workers = {};
3390
+ var workers = new Map();
2983
3391
  return function (workerName, data, options) {
2984
- if (!workers[workerName]) {
2985
- workers[workerName] = LeUtils.createWorkerThread(workerName);
3392
+ if (!workers.has(workerName)) {
3393
+ workers.set(workerName, LeUtils.createWorkerThread(workerName));
2986
3394
  }
2987
- return workers[workerName].sendMessage(data, options);
3395
+ return workers.get(workerName).sendMessage(data, options);
2988
3396
  };
2989
3397
  }(),
2990
3398
  /**
@@ -3013,8 +3421,8 @@ var LeUtils = {
3013
3421
  }
3014
3422
  var inputTypes = ['text', 'search', 'email', 'number', 'password', 'tel', 'time', 'url', 'week', 'month', 'date', 'datetime-local'];
3015
3423
  return function () {
3016
- var _document, _document2;
3017
- return !(((_document = document) === null || _document === void 0 || (_document = _document.activeElement) === null || _document === void 0 || (_document = _document.tagName) === null || _document === void 0 ? void 0 : _document.toLowerCase()) === 'input' && inputTypes.includes((_document2 = document) === null || _document2 === void 0 || (_document2 = _document2.activeElement) === null || _document2 === void 0 || (_document2 = _document2.type) === null || _document2 === void 0 ? void 0 : _document2.toLowerCase()));
3424
+ var _document, _document$activeEleme, _document2;
3425
+ return !(((_document = document) === null || _document === void 0 || (_document = _document.activeElement) === null || _document === void 0 || (_document = _document.tagName) === null || _document === void 0 ? void 0 : _document.toLowerCase()) === 'input' && inputTypes.includes((_document$activeEleme = (_document2 = document) === null || _document2 === void 0 || (_document2 = _document2.activeElement) === null || _document2 === void 0 || (_document2 = _document2.getAttribute('type')) === null || _document2 === void 0 ? void 0 : _document2.toLowerCase()) !== null && _document$activeEleme !== void 0 ? _document$activeEleme : ''));
3018
3426
  };
3019
3427
  }(),
3020
3428
  /**