@lowentry/utils 1.15.3 → 1.16.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 +112 -119
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/src/LeUtils.js +85 -98
- package/tests/each.test.js +637 -20
- /package/{jest.config.js → jest.config.mjs} +0 -0
package/index.js
CHANGED
|
@@ -265,13 +265,15 @@ var LeUtils = {
|
|
|
265
265
|
* @returns {{remove:Function}}
|
|
266
266
|
*/
|
|
267
267
|
onDomReady: function onDomReady(callback) {
|
|
268
|
-
|
|
268
|
+
var _globalThis$document, _globalThis$document2;
|
|
269
|
+
if (!(globalThis !== null && globalThis !== void 0 && globalThis.document) || !(globalThis !== null && globalThis !== void 0 && (_globalThis$document = globalThis.document) !== null && _globalThis$document !== void 0 && _globalThis$document.addEventListener) || !(globalThis !== null && globalThis !== void 0 && (_globalThis$document2 = globalThis.document) !== null && _globalThis$document2 !== void 0 && _globalThis$document2.removeEventListener)) {
|
|
269
270
|
// no document, so we can't wait for it to be ready
|
|
271
|
+
console.warn('LeUtils.onDomReady() was called, but there is no document available. This might happen if the code is executed in a non-browser environment.');
|
|
270
272
|
return {
|
|
271
273
|
remove: function remove() {}
|
|
272
274
|
};
|
|
273
275
|
}
|
|
274
|
-
if (document.readyState === 'interactive' || document.readyState === 'complete') {
|
|
276
|
+
if (globalThis.document.readyState === 'interactive' || globalThis.document.readyState === 'complete') {
|
|
275
277
|
return LeUtils.setTimeout(function () {
|
|
276
278
|
return callback();
|
|
277
279
|
}, 0);
|
|
@@ -280,16 +282,16 @@ var LeUtils = {
|
|
|
280
282
|
var _callbackWrapper = function callbackWrapper() {
|
|
281
283
|
if (listening) {
|
|
282
284
|
listening = false;
|
|
283
|
-
document.removeEventListener('DOMContentLoaded', _callbackWrapper);
|
|
285
|
+
globalThis.document.removeEventListener('DOMContentLoaded', _callbackWrapper);
|
|
284
286
|
callback();
|
|
285
287
|
}
|
|
286
288
|
};
|
|
287
|
-
document.addEventListener('DOMContentLoaded', _callbackWrapper);
|
|
289
|
+
globalThis.document.addEventListener('DOMContentLoaded', _callbackWrapper);
|
|
288
290
|
return {
|
|
289
291
|
remove: function remove() {
|
|
290
292
|
if (listening) {
|
|
291
293
|
listening = false;
|
|
292
|
-
document.removeEventListener('DOMContentLoaded', _callbackWrapper);
|
|
294
|
+
globalThis.document.removeEventListener('DOMContentLoaded', _callbackWrapper);
|
|
293
295
|
}
|
|
294
296
|
}
|
|
295
297
|
};
|
|
@@ -1500,16 +1502,19 @@ var LeUtils = {
|
|
|
1500
1502
|
* @returns {{remove:Function}}
|
|
1501
1503
|
*/
|
|
1502
1504
|
setTimeout: function setTimeout(callback, ms) {
|
|
1503
|
-
|
|
1505
|
+
var _performance$now, _performance, _performance$now2;
|
|
1506
|
+
if (!(globalThis !== null && globalThis !== void 0 && globalThis.setTimeout) || !(globalThis !== null && globalThis !== void 0 && globalThis.clearTimeout)) {
|
|
1507
|
+
console.warn('LeUtils.setTimeout() called in an environment without globalThis.setTimeout, returning a no-op handler.');
|
|
1504
1508
|
return {
|
|
1505
1509
|
remove: function remove() {}
|
|
1506
1510
|
};
|
|
1507
1511
|
}
|
|
1508
1512
|
ms = FLOAT_LAX(ms);
|
|
1509
|
-
var lastTime = performance.now();
|
|
1513
|
+
var lastTime = (_performance$now = (_performance = performance) === null || _performance === void 0 || (_performance$now2 = _performance.now) === null || _performance$now2 === void 0 ? void 0 : _performance$now2.call(_performance)) !== null && _performance$now !== void 0 ? _performance$now : 0;
|
|
1510
1514
|
/** @type {number|null} */
|
|
1511
|
-
var handler =
|
|
1512
|
-
var
|
|
1515
|
+
var handler = globalThis.setTimeout(function () {
|
|
1516
|
+
var _performance$now3, _performance2, _performance2$now;
|
|
1517
|
+
var currentTime = (_performance$now3 = (_performance2 = performance) === null || _performance2 === void 0 || (_performance2$now = _performance2.now) === null || _performance2$now === void 0 ? void 0 : _performance2$now.call(_performance2)) !== null && _performance$now3 !== void 0 ? _performance$now3 : 0;
|
|
1513
1518
|
try {
|
|
1514
1519
|
callback((currentTime - lastTime) / 1000);
|
|
1515
1520
|
} catch (e) {
|
|
@@ -1520,7 +1525,7 @@ var LeUtils = {
|
|
|
1520
1525
|
return {
|
|
1521
1526
|
remove: function remove() {
|
|
1522
1527
|
if (handler !== null) {
|
|
1523
|
-
|
|
1528
|
+
globalThis.clearTimeout(handler);
|
|
1524
1529
|
handler = null;
|
|
1525
1530
|
}
|
|
1526
1531
|
}
|
|
@@ -1537,6 +1542,7 @@ var LeUtils = {
|
|
|
1537
1542
|
* @returns {{remove:Function}}
|
|
1538
1543
|
*/
|
|
1539
1544
|
setInterval: function setInterval(callback) {
|
|
1545
|
+
var _performance$now4, _performance3, _performance3$now;
|
|
1540
1546
|
var intervalMs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1000;
|
|
1541
1547
|
var fireImmediately = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1542
1548
|
intervalMs = FLOAT_LAX_ANY(intervalMs, 1000);
|
|
@@ -1547,15 +1553,17 @@ var LeUtils = {
|
|
|
1547
1553
|
console.error(e);
|
|
1548
1554
|
}
|
|
1549
1555
|
}
|
|
1550
|
-
if (
|
|
1556
|
+
if (!(globalThis !== null && globalThis !== void 0 && globalThis.setInterval) || !(globalThis !== null && globalThis !== void 0 && globalThis.clearInterval)) {
|
|
1557
|
+
console.warn('LeUtils.setInterval() called in an environment without globalThis.setInterval, returning a no-op handler.');
|
|
1551
1558
|
return {
|
|
1552
1559
|
remove: function remove() {}
|
|
1553
1560
|
};
|
|
1554
1561
|
}
|
|
1555
|
-
var lastTime = performance.now();
|
|
1562
|
+
var lastTime = (_performance$now4 = (_performance3 = performance) === null || _performance3 === void 0 || (_performance3$now = _performance3.now) === null || _performance3$now === void 0 ? void 0 : _performance3$now.call(_performance3)) !== null && _performance$now4 !== void 0 ? _performance$now4 : 0;
|
|
1556
1563
|
/** @type {number|null} */
|
|
1557
|
-
var handler =
|
|
1558
|
-
var
|
|
1564
|
+
var handler = globalThis.setInterval(function () {
|
|
1565
|
+
var _performance$now5, _performance4, _performance4$now;
|
|
1566
|
+
var currentTime = (_performance$now5 = (_performance4 = performance) === null || _performance4 === void 0 || (_performance4$now = _performance4.now) === null || _performance4$now === void 0 ? void 0 : _performance4$now.call(_performance4)) !== null && _performance$now5 !== void 0 ? _performance$now5 : 0;
|
|
1559
1567
|
try {
|
|
1560
1568
|
callback((currentTime - lastTime) / 1000);
|
|
1561
1569
|
} catch (e) {
|
|
@@ -1566,7 +1574,7 @@ var LeUtils = {
|
|
|
1566
1574
|
return {
|
|
1567
1575
|
remove: function remove() {
|
|
1568
1576
|
if (handler !== null) {
|
|
1569
|
-
|
|
1577
|
+
globalThis.clearInterval(handler);
|
|
1570
1578
|
handler = null;
|
|
1571
1579
|
}
|
|
1572
1580
|
}
|
|
@@ -1582,8 +1590,10 @@ var LeUtils = {
|
|
|
1582
1590
|
* @returns {{remove:Function}}
|
|
1583
1591
|
*/
|
|
1584
1592
|
setAnimationFrameTimeout: function setAnimationFrameTimeout(callback) {
|
|
1593
|
+
var _performance$now6, _performance5, _performance5$now;
|
|
1585
1594
|
var frames = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
1586
|
-
if (
|
|
1595
|
+
if (!(globalThis !== null && globalThis !== void 0 && globalThis.requestAnimationFrame) || !(globalThis !== null && globalThis !== void 0 && globalThis.cancelAnimationFrame)) {
|
|
1596
|
+
console.warn('LeUtils.setAnimationFrameTimeout() called in an environment without globalThis.requestAnimationFrame, returning a no-op handler.');
|
|
1587
1597
|
return {
|
|
1588
1598
|
remove: function remove() {}
|
|
1589
1599
|
};
|
|
@@ -1591,13 +1601,14 @@ var LeUtils = {
|
|
|
1591
1601
|
frames = INT_LAX_ANY(frames, 1);
|
|
1592
1602
|
var run = true;
|
|
1593
1603
|
var requestAnimationFrameId = null;
|
|
1594
|
-
var lastTime = performance.now();
|
|
1604
|
+
var lastTime = (_performance$now6 = (_performance5 = performance) === null || _performance5 === void 0 || (_performance5$now = _performance5.now) === null || _performance5$now === void 0 ? void 0 : _performance5$now.call(_performance5)) !== null && _performance$now6 !== void 0 ? _performance$now6 : 0;
|
|
1595
1605
|
var _tick = function tick() {
|
|
1596
1606
|
if (run) {
|
|
1597
1607
|
if (frames <= 0) {
|
|
1608
|
+
var _performance$now7, _performance6, _performance6$now;
|
|
1598
1609
|
run = false;
|
|
1599
1610
|
requestAnimationFrameId = null;
|
|
1600
|
-
var currentTime = performance.now();
|
|
1611
|
+
var currentTime = (_performance$now7 = (_performance6 = performance) === null || _performance6 === void 0 || (_performance6$now = _performance6.now) === null || _performance6$now === void 0 ? void 0 : _performance6$now.call(_performance6)) !== null && _performance$now7 !== void 0 ? _performance$now7 : 0;
|
|
1601
1612
|
try {
|
|
1602
1613
|
callback((currentTime - lastTime) / 1000);
|
|
1603
1614
|
} catch (e) {
|
|
@@ -1607,7 +1618,7 @@ var LeUtils = {
|
|
|
1607
1618
|
return;
|
|
1608
1619
|
}
|
|
1609
1620
|
frames--;
|
|
1610
|
-
requestAnimationFrameId =
|
|
1621
|
+
requestAnimationFrameId = globalThis.requestAnimationFrame(_tick);
|
|
1611
1622
|
}
|
|
1612
1623
|
};
|
|
1613
1624
|
_tick();
|
|
@@ -1615,7 +1626,7 @@ var LeUtils = {
|
|
|
1615
1626
|
remove: function remove() {
|
|
1616
1627
|
run = false;
|
|
1617
1628
|
if (requestAnimationFrameId !== null) {
|
|
1618
|
-
|
|
1629
|
+
globalThis.cancelAnimationFrame(requestAnimationFrameId);
|
|
1619
1630
|
requestAnimationFrameId = null;
|
|
1620
1631
|
}
|
|
1621
1632
|
}
|
|
@@ -1632,6 +1643,7 @@ var LeUtils = {
|
|
|
1632
1643
|
* @returns {{remove:Function}}
|
|
1633
1644
|
*/
|
|
1634
1645
|
setAnimationFrameInterval: function setAnimationFrameInterval(callback) {
|
|
1646
|
+
var _performance$now8, _performance7, _performance7$now;
|
|
1635
1647
|
var intervalFrames = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
1636
1648
|
var fireImmediately = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1637
1649
|
intervalFrames = INT_LAX_ANY(intervalFrames, 1);
|
|
@@ -1642,19 +1654,21 @@ var LeUtils = {
|
|
|
1642
1654
|
console.error(e);
|
|
1643
1655
|
}
|
|
1644
1656
|
}
|
|
1645
|
-
if (
|
|
1657
|
+
if (!(globalThis !== null && globalThis !== void 0 && globalThis.requestAnimationFrame) || !(globalThis !== null && globalThis !== void 0 && globalThis.cancelAnimationFrame)) {
|
|
1658
|
+
console.warn('LeUtils.setAnimationFrameInterval() called in an environment without globalThis.requestAnimationFrame, returning a no-op handler.');
|
|
1646
1659
|
return {
|
|
1647
1660
|
remove: function remove() {}
|
|
1648
1661
|
};
|
|
1649
1662
|
}
|
|
1650
1663
|
var run = true;
|
|
1651
1664
|
var requestAnimationFrameId = null;
|
|
1652
|
-
var lastTime = performance.now();
|
|
1665
|
+
var lastTime = (_performance$now8 = (_performance7 = performance) === null || _performance7 === void 0 || (_performance7$now = _performance7.now) === null || _performance7$now === void 0 ? void 0 : _performance7$now.call(_performance7)) !== null && _performance$now8 !== void 0 ? _performance$now8 : 0;
|
|
1653
1666
|
var frames = intervalFrames;
|
|
1654
1667
|
var _tick2 = function tick() {
|
|
1655
1668
|
if (run) {
|
|
1656
1669
|
if (frames <= 0) {
|
|
1657
|
-
var
|
|
1670
|
+
var _performance$now9, _performance8, _performance8$now;
|
|
1671
|
+
var currentTime = (_performance$now9 = (_performance8 = performance) === null || _performance8 === void 0 || (_performance8$now = _performance8.now) === null || _performance8$now === void 0 ? void 0 : _performance8$now.call(_performance8)) !== null && _performance$now9 !== void 0 ? _performance$now9 : 0;
|
|
1658
1672
|
try {
|
|
1659
1673
|
callback((currentTime - lastTime) / 1000);
|
|
1660
1674
|
} catch (e) {
|
|
@@ -1665,16 +1679,16 @@ var LeUtils = {
|
|
|
1665
1679
|
}
|
|
1666
1680
|
frames--;
|
|
1667
1681
|
if (run) {
|
|
1668
|
-
requestAnimationFrameId =
|
|
1682
|
+
requestAnimationFrameId = globalThis.requestAnimationFrame(_tick2);
|
|
1669
1683
|
}
|
|
1670
1684
|
}
|
|
1671
1685
|
};
|
|
1672
|
-
|
|
1686
|
+
globalThis.requestAnimationFrame(_tick2);
|
|
1673
1687
|
return {
|
|
1674
1688
|
remove: function remove() {
|
|
1675
1689
|
run = false;
|
|
1676
1690
|
if (requestAnimationFrameId !== null) {
|
|
1677
|
-
|
|
1691
|
+
globalThis.cancelAnimationFrame(requestAnimationFrameId);
|
|
1678
1692
|
requestAnimationFrameId = null;
|
|
1679
1693
|
}
|
|
1680
1694
|
}
|
|
@@ -1734,7 +1748,7 @@ var LeUtils = {
|
|
|
1734
1748
|
var retries = INT_LAX(options === null || options === void 0 ? void 0 : options.retries);
|
|
1735
1749
|
var controllerAborted = false;
|
|
1736
1750
|
var controller = null;
|
|
1737
|
-
if (
|
|
1751
|
+
if (globalThis !== null && globalThis !== void 0 && globalThis.AbortController) {
|
|
1738
1752
|
controller = new AbortController();
|
|
1739
1753
|
}
|
|
1740
1754
|
var promise = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
|
|
@@ -1971,13 +1985,10 @@ var LeUtils = {
|
|
|
1971
1985
|
* @returns {boolean}
|
|
1972
1986
|
*/
|
|
1973
1987
|
platformIsMobile: function platformIsMobile() {
|
|
1974
|
-
var
|
|
1975
|
-
if (typeof window === 'undefined') {
|
|
1976
|
-
return false;
|
|
1977
|
-
}
|
|
1988
|
+
var _globalThis$navigator, _globalThis$navigator2;
|
|
1978
1989
|
// noinspection JSDeprecatedSymbols, JSUnresolvedReference
|
|
1979
1990
|
/** navigator.userAgentData.mobile doesn't return the correct value on some platforms, so this is a work-around, code from: http://detectmobilebrowsers.com **/
|
|
1980
|
-
var a = STRING(((
|
|
1991
|
+
var a = STRING((globalThis === null || globalThis === void 0 || (_globalThis$navigator = globalThis.navigator) === null || _globalThis$navigator === void 0 ? void 0 : _globalThis$navigator.userAgent) || (globalThis === null || globalThis === void 0 || (_globalThis$navigator2 = globalThis.navigator) === null || _globalThis$navigator2 === void 0 ? void 0 : _globalThis$navigator2.vendor) || (globalThis === null || globalThis === void 0 ? void 0 : globalThis.opera) || '');
|
|
1981
1992
|
var b = a.substring(0, 4);
|
|
1982
1993
|
return !!(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series([46])0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br([ev])w|bumb|bw-([nu])|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do([cp])o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly([-_])|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-([mpt])|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c([- _agpst])|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac([ \-/])|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja([tv])a|jbro|jemu|jigs|kddi|keji|kgt([ /])|klon|kpt |kwc-|kyo([ck])|le(no|xi)|lg( g|\/([klu])|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t([- ov])|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30([02])|n50([025])|n7(0([01])|10)|ne(([cm])-|on|tf|wf|wg|wt)|nok([6i])|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan([adt])|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\/|se(c([-01])|47|mc|nd|ri)|sgh-|shar|sie([-m])|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel([im])|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c([- ])|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test(b));
|
|
1983
1994
|
},
|
|
@@ -1988,11 +1999,8 @@ var LeUtils = {
|
|
|
1988
1999
|
* @returns {boolean}
|
|
1989
2000
|
*/
|
|
1990
2001
|
platformHasCursor: function platformHasCursor() {
|
|
1991
|
-
var
|
|
1992
|
-
|
|
1993
|
-
return true;
|
|
1994
|
-
}
|
|
1995
|
-
return !LeUtils.platformIsMobile() && !((_window$matchMedia = window.matchMedia('(any-hover: none)')) !== null && _window$matchMedia !== void 0 && _window$matchMedia.matches);
|
|
2002
|
+
var _globalThis$matchMedi;
|
|
2003
|
+
return !LeUtils.platformIsMobile() && !(globalThis !== null && globalThis !== void 0 && (_globalThis$matchMedi = globalThis.matchMedia) !== null && _globalThis$matchMedi !== void 0 && (_globalThis$matchMedi = _globalThis$matchMedi.call(globalThis, '(any-hover: none)')) !== null && _globalThis$matchMedi !== void 0 && _globalThis$matchMedi.matches);
|
|
1996
2004
|
},
|
|
1997
2005
|
/**
|
|
1998
2006
|
* Returns the given string, with the first character capitalized.
|
|
@@ -2246,17 +2254,11 @@ var LeUtils = {
|
|
|
2246
2254
|
var generateUniqueId = function generateUniqueId() {
|
|
2247
2255
|
var now;
|
|
2248
2256
|
try {
|
|
2249
|
-
|
|
2250
|
-
throw new Error();
|
|
2251
|
-
}
|
|
2257
|
+
var _performance9, _performance0, _performance$now0, _performance1, _performance1$now;
|
|
2252
2258
|
// noinspection JSDeprecatedSymbols
|
|
2253
|
-
now = (performance.timeOrigin || performance.timing.navigationStart) + performance.now();
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
}
|
|
2257
|
-
} catch (e) {
|
|
2258
|
-
now = Date.now ? Date.now() : new Date().getTime();
|
|
2259
|
-
}
|
|
2259
|
+
now = (((_performance9 = performance) === null || _performance9 === void 0 ? void 0 : _performance9.timeOrigin) || ((_performance0 = performance) === null || _performance0 === void 0 || (_performance0 = _performance0.timing) === null || _performance0 === void 0 ? void 0 : _performance0.navigationStart) || 0) + ((_performance$now0 = (_performance1 = performance) === null || _performance1 === void 0 || (_performance1$now = _performance1.now) === null || _performance1$now === void 0 ? void 0 : _performance1$now.call(_performance1)) !== null && _performance$now0 !== void 0 ? _performance$now0 : 0);
|
|
2260
|
+
} catch (e) {}
|
|
2261
|
+
now = now || (Date.now ? Date.now() : new Date().getTime());
|
|
2260
2262
|
now = Math.round(now);
|
|
2261
2263
|
var nowBytes = numberToBytes(now);
|
|
2262
2264
|
var uuid = null;
|
|
@@ -2325,17 +2327,11 @@ var LeUtils = {
|
|
|
2325
2327
|
now = FLOAT_LAX(now);
|
|
2326
2328
|
} else {
|
|
2327
2329
|
try {
|
|
2328
|
-
|
|
2329
|
-
throw new Error();
|
|
2330
|
-
}
|
|
2330
|
+
var _performance10, _performance11, _performance$now1, _performance12, _performance12$now;
|
|
2331
2331
|
// noinspection JSDeprecatedSymbols
|
|
2332
|
-
now = (performance.timeOrigin || performance.timing.navigationStart) + performance.now();
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
}
|
|
2336
|
-
} catch (e) {
|
|
2337
|
-
now = Date.now ? Date.now() : new Date().getTime();
|
|
2338
|
-
}
|
|
2332
|
+
now = (((_performance10 = performance) === null || _performance10 === void 0 ? void 0 : _performance10.timeOrigin) || ((_performance11 = performance) === null || _performance11 === void 0 || (_performance11 = _performance11.timing) === null || _performance11 === void 0 ? void 0 : _performance11.navigationStart) || 0) + ((_performance$now1 = (_performance12 = performance) === null || _performance12 === void 0 || (_performance12$now = _performance12.now) === null || _performance12$now === void 0 ? void 0 : _performance12$now.call(_performance12)) !== null && _performance$now1 !== void 0 ? _performance$now1 : 0);
|
|
2333
|
+
} catch (e) {}
|
|
2334
|
+
now = now || (Date.now ? Date.now() : new Date().getTime());
|
|
2339
2335
|
}
|
|
2340
2336
|
now = Math.round(now);
|
|
2341
2337
|
var nowBytes = numberToBytes(now);
|
|
@@ -2373,11 +2369,13 @@ var LeUtils = {
|
|
|
2373
2369
|
* @returns {Uint8ClampedArray}
|
|
2374
2370
|
*/
|
|
2375
2371
|
getImagePixels: function getImagePixels(image) {
|
|
2376
|
-
|
|
2372
|
+
var _globalThis$document3, _globalThis$document4;
|
|
2373
|
+
if (!(globalThis !== null && globalThis !== void 0 && (_globalThis$document3 = globalThis.document) !== null && _globalThis$document3 !== void 0 && _globalThis$document3.createElement) || !(globalThis !== null && globalThis !== void 0 && (_globalThis$document4 = globalThis.document) !== null && _globalThis$document4 !== void 0 && (_globalThis$document4 = _globalThis$document4.body) !== null && _globalThis$document4 !== void 0 && _globalThis$document4.appendChild)) {
|
|
2374
|
+
console.warn('LeUtils.getImagePixels: Document is not available, returning empty pixels.');
|
|
2377
2375
|
return new Uint8ClampedArray();
|
|
2378
2376
|
}
|
|
2379
|
-
var canvas = document.createElement('canvas');
|
|
2380
|
-
document.body.appendChild(canvas);
|
|
2377
|
+
var canvas = globalThis.document.createElement('canvas');
|
|
2378
|
+
globalThis.document.body.appendChild(canvas);
|
|
2381
2379
|
try {
|
|
2382
2380
|
var ctx = canvas.getContext('2d');
|
|
2383
2381
|
var width = Math.floor(image.width);
|
|
@@ -2402,11 +2400,13 @@ var LeUtils = {
|
|
|
2402
2400
|
* @returns {string}
|
|
2403
2401
|
*/
|
|
2404
2402
|
getColoredImage: function getColoredImage(image, color) {
|
|
2405
|
-
|
|
2403
|
+
var _globalThis$document5, _globalThis$document6;
|
|
2404
|
+
if (!(globalThis !== null && globalThis !== void 0 && (_globalThis$document5 = globalThis.document) !== null && _globalThis$document5 !== void 0 && _globalThis$document5.createElement) || !(globalThis !== null && globalThis !== void 0 && (_globalThis$document6 = globalThis.document) !== null && _globalThis$document6 !== void 0 && (_globalThis$document6 = _globalThis$document6.body) !== null && _globalThis$document6 !== void 0 && _globalThis$document6.appendChild)) {
|
|
2405
|
+
console.warn('LeUtils.getColoredImage: Document is not available, returning empty image src.');
|
|
2406
2406
|
return LeUtils.getEmptyImageSrc();
|
|
2407
2407
|
}
|
|
2408
|
-
var canvas = document.createElement('canvas');
|
|
2409
|
-
document.body.appendChild(canvas);
|
|
2408
|
+
var canvas = globalThis.document.createElement('canvas');
|
|
2409
|
+
globalThis.document.body.appendChild(canvas);
|
|
2410
2410
|
try {
|
|
2411
2411
|
var ctx = canvas.getContext('2d');
|
|
2412
2412
|
var width = Math.floor(image.width);
|
|
@@ -2717,42 +2717,32 @@ var LeUtils = {
|
|
|
2717
2717
|
* @param {string} string
|
|
2718
2718
|
* @returns {string}
|
|
2719
2719
|
*/
|
|
2720
|
-
btoa: function (
|
|
2721
|
-
|
|
2722
|
-
|
|
2720
|
+
btoa: function btoa(string) {
|
|
2721
|
+
var _globalThis$Buffer;
|
|
2722
|
+
if (typeof (globalThis === null || globalThis === void 0 ? void 0 : globalThis.btoa) === 'function') {
|
|
2723
|
+
return globalThis.btoa(string);
|
|
2723
2724
|
}
|
|
2724
|
-
|
|
2725
|
-
return
|
|
2726
|
-
};
|
|
2727
|
-
return btoa;
|
|
2728
|
-
}(function (string) {
|
|
2729
|
-
if (typeof btoa === 'function') {
|
|
2730
|
-
return btoa(string);
|
|
2725
|
+
if (typeof (globalThis === null || globalThis === void 0 || (_globalThis$Buffer = globalThis.Buffer) === null || _globalThis$Buffer === void 0 ? void 0 : _globalThis$Buffer.from) === 'function') {
|
|
2726
|
+
return globalThis.Buffer.from(string).toString('base64');
|
|
2731
2727
|
}
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
}),
|
|
2728
|
+
throw new Error('LeUtils.btoa: No btoa implementation found in this environment.');
|
|
2729
|
+
},
|
|
2735
2730
|
/**
|
|
2736
2731
|
* An implementation of the atob function, which should work in all environments.
|
|
2737
2732
|
*
|
|
2738
2733
|
* @param {string} base64string
|
|
2739
2734
|
* @returns {string}
|
|
2740
2735
|
*/
|
|
2741
|
-
atob: function (
|
|
2742
|
-
|
|
2743
|
-
|
|
2736
|
+
atob: function atob(base64string) {
|
|
2737
|
+
var _globalThis$Buffer2;
|
|
2738
|
+
if (typeof (globalThis === null || globalThis === void 0 ? void 0 : globalThis.atob) === 'function') {
|
|
2739
|
+
return globalThis.atob(base64string);
|
|
2744
2740
|
}
|
|
2745
|
-
|
|
2746
|
-
return
|
|
2747
|
-
};
|
|
2748
|
-
return atob;
|
|
2749
|
-
}(function (base64string) {
|
|
2750
|
-
if (typeof atob === 'function') {
|
|
2751
|
-
return atob(base64string);
|
|
2741
|
+
if (typeof (globalThis === null || globalThis === void 0 || (_globalThis$Buffer2 = globalThis.Buffer) === null || _globalThis$Buffer2 === void 0 ? void 0 : _globalThis$Buffer2.from) === 'function') {
|
|
2742
|
+
return globalThis.Buffer.from(base64string, 'base64').toString();
|
|
2752
2743
|
}
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
}),
|
|
2744
|
+
throw new Error('LeUtils.atob: No atob implementation found in this environment.');
|
|
2745
|
+
},
|
|
2756
2746
|
/**
|
|
2757
2747
|
* Encodes a UTF-8 string into a base64 string.
|
|
2758
2748
|
*
|
|
@@ -2840,10 +2830,12 @@ var LeUtils = {
|
|
|
2840
2830
|
* @param {string} [mimeType]
|
|
2841
2831
|
*/
|
|
2842
2832
|
downloadFile: function downloadFile(base64string, fileName, mimeType) {
|
|
2843
|
-
|
|
2833
|
+
var _globalThis$document7;
|
|
2834
|
+
if (!(globalThis !== null && globalThis !== void 0 && (_globalThis$document7 = globalThis.document) !== null && _globalThis$document7 !== void 0 && _globalThis$document7.createElement)) {
|
|
2835
|
+
console.warn('LeUtils.downloadFile: Document is not available, cannot download file.');
|
|
2844
2836
|
return;
|
|
2845
2837
|
}
|
|
2846
|
-
var link = document.createElement('a');
|
|
2838
|
+
var link = globalThis.document.createElement('a');
|
|
2847
2839
|
link.setAttribute('download', typeof fileName === 'string' ? fileName : 'file');
|
|
2848
2840
|
link.href = 'data:' + mimeType + ';base64,' + base64string;
|
|
2849
2841
|
link.setAttribute('target', '_blank');
|
|
@@ -2856,10 +2848,12 @@ var LeUtils = {
|
|
|
2856
2848
|
* @returns {*}
|
|
2857
2849
|
*/
|
|
2858
2850
|
localStorageGet: function localStorageGet(id) {
|
|
2859
|
-
|
|
2851
|
+
var _globalThis$localStor;
|
|
2852
|
+
if (!(globalThis !== null && globalThis !== void 0 && (_globalThis$localStor = globalThis.localStorage) !== null && _globalThis$localStor !== void 0 && _globalThis$localStor.getItem)) {
|
|
2853
|
+
console.warn('LeUtils.localStorageGet: LocalStorage is not available, returning undefined.');
|
|
2860
2854
|
return;
|
|
2861
2855
|
}
|
|
2862
|
-
var result =
|
|
2856
|
+
var result = globalThis.localStorage.getItem('LeUtils_' + id);
|
|
2863
2857
|
if (typeof result !== 'string') {
|
|
2864
2858
|
return;
|
|
2865
2859
|
}
|
|
@@ -2875,14 +2869,16 @@ var LeUtils = {
|
|
|
2875
2869
|
* @param {*} data
|
|
2876
2870
|
*/
|
|
2877
2871
|
localStorageSet: function localStorageSet(id, data) {
|
|
2878
|
-
|
|
2872
|
+
var _globalThis$localStor2;
|
|
2873
|
+
if (!(globalThis !== null && globalThis !== void 0 && (_globalThis$localStor2 = globalThis.localStorage) !== null && _globalThis$localStor2 !== void 0 && _globalThis$localStor2.setItem)) {
|
|
2874
|
+
console.warn('LeUtils.localStorageSet: LocalStorage is not available, cannot save data.');
|
|
2879
2875
|
return;
|
|
2880
2876
|
}
|
|
2881
2877
|
if (typeof data === 'undefined') {
|
|
2882
|
-
|
|
2878
|
+
globalThis.localStorage.removeItem('LeUtils_' + id);
|
|
2883
2879
|
return;
|
|
2884
2880
|
}
|
|
2885
|
-
|
|
2881
|
+
globalThis.localStorage.setItem('LeUtils_' + id, JSON.stringify({
|
|
2886
2882
|
'-': data
|
|
2887
2883
|
}));
|
|
2888
2884
|
},
|
|
@@ -2892,13 +2888,15 @@ var LeUtils = {
|
|
|
2892
2888
|
* @param {string} id
|
|
2893
2889
|
*/
|
|
2894
2890
|
localStorageRemove: function localStorageRemove(id) {
|
|
2895
|
-
|
|
2891
|
+
var _globalThis$localStor3;
|
|
2892
|
+
if (!(globalThis !== null && globalThis !== void 0 && (_globalThis$localStor3 = globalThis.localStorage) !== null && _globalThis$localStor3 !== void 0 && _globalThis$localStor3.removeItem)) {
|
|
2893
|
+
console.warn('LeUtils.localStorageRemove: LocalStorage is not available, cannot remove data.');
|
|
2896
2894
|
return;
|
|
2897
2895
|
}
|
|
2898
|
-
|
|
2896
|
+
globalThis.localStorage.removeItem('LeUtils_' + id);
|
|
2899
2897
|
},
|
|
2900
2898
|
/**
|
|
2901
|
-
* Returns whether the current hostname (
|
|
2899
|
+
* Returns whether the current hostname (globalThis.location.hostname) is private (such as localhost, 192.168.1.1, etc).
|
|
2902
2900
|
* This can be used to determine if the app is running in a development environment or not.
|
|
2903
2901
|
*
|
|
2904
2902
|
* Only "localhost" and IPv4 addresses are supported. IPv6 addresses will always return false.
|
|
@@ -2909,10 +2907,12 @@ var LeUtils = {
|
|
|
2909
2907
|
var lastHostname = null;
|
|
2910
2908
|
var lastResult = false;
|
|
2911
2909
|
return function () {
|
|
2912
|
-
|
|
2913
|
-
|
|
2910
|
+
var _globalThis$location;
|
|
2911
|
+
if (!(globalThis !== null && globalThis !== void 0 && (_globalThis$location = globalThis.location) !== null && _globalThis$location !== void 0 && _globalThis$location.hostname)) {
|
|
2912
|
+
console.warn('LeUtils.isCurrentHostPrivate: No location.hostname found, returning false.');
|
|
2913
|
+
return false;
|
|
2914
2914
|
}
|
|
2915
|
-
var hostname =
|
|
2915
|
+
var hostname = globalThis.location.hostname;
|
|
2916
2916
|
if (lastHostname === hostname) {
|
|
2917
2917
|
return lastResult;
|
|
2918
2918
|
}
|
|
@@ -3328,7 +3328,8 @@ var LeUtils = {
|
|
|
3328
3328
|
* @returns {{worker:Worker|null, sendMessage:(data:Object,options:{timeout:number|undefined}|undefined)=>Promise<Object>}}
|
|
3329
3329
|
*/
|
|
3330
3330
|
createWorkerThread: function createWorkerThread(name) {
|
|
3331
|
-
if (
|
|
3331
|
+
if (!(globalThis !== null && globalThis !== void 0 && globalThis.Worker)) {
|
|
3332
|
+
console.warn('LeUtils.createWorkerThread: Workers are not supported in this environment, returning a dummy worker.');
|
|
3332
3333
|
return {
|
|
3333
3334
|
worker: null,
|
|
3334
3335
|
sendMessage: function sendMessage(data, options) {
|
|
@@ -3338,7 +3339,7 @@ var LeUtils = {
|
|
|
3338
3339
|
}
|
|
3339
3340
|
};
|
|
3340
3341
|
}
|
|
3341
|
-
var worker = new Worker('/workers/' + name + '.worker.js');
|
|
3342
|
+
var worker = new globalThis.Worker('/workers/' + name + '.worker.js');
|
|
3342
3343
|
var listeners = new Map();
|
|
3343
3344
|
var addListener = function addListener(id, callback) {
|
|
3344
3345
|
listeners.set(id, callback);
|
|
@@ -3416,15 +3417,10 @@ var LeUtils = {
|
|
|
3416
3417
|
* @returns {boolean}
|
|
3417
3418
|
*/
|
|
3418
3419
|
isFocusClear: function () {
|
|
3419
|
-
if (typeof window === 'undefined' || !document) {
|
|
3420
|
-
return function () {
|
|
3421
|
-
return true;
|
|
3422
|
-
};
|
|
3423
|
-
}
|
|
3424
3420
|
var inputTypes = ['text', 'search', 'email', 'number', 'password', 'tel', 'time', 'url', 'week', 'month', 'date', 'datetime-local'];
|
|
3425
3421
|
return function () {
|
|
3426
|
-
var
|
|
3427
|
-
return !(((
|
|
3422
|
+
var _globalThis$document8, _globalThis$document$, _globalThis$document9;
|
|
3423
|
+
return !((globalThis === null || globalThis === void 0 || (_globalThis$document8 = globalThis.document) === null || _globalThis$document8 === void 0 || (_globalThis$document8 = _globalThis$document8.activeElement) === null || _globalThis$document8 === void 0 || (_globalThis$document8 = _globalThis$document8.tagName) === null || _globalThis$document8 === void 0 ? void 0 : _globalThis$document8.toLowerCase()) === 'input' && inputTypes.includes((_globalThis$document$ = globalThis === null || globalThis === void 0 || (_globalThis$document9 = globalThis.document) === null || _globalThis$document9 === void 0 || (_globalThis$document9 = _globalThis$document9.activeElement) === null || _globalThis$document9 === void 0 || (_globalThis$document9 = _globalThis$document9.getAttribute('type')) === null || _globalThis$document9 === void 0 ? void 0 : _globalThis$document9.toLowerCase()) !== null && _globalThis$document$ !== void 0 ? _globalThis$document$ : ''));
|
|
3428
3424
|
};
|
|
3429
3425
|
}(),
|
|
3430
3426
|
/**
|
|
@@ -3436,11 +3432,8 @@ var LeUtils = {
|
|
|
3436
3432
|
var userLocale = null;
|
|
3437
3433
|
return function () {
|
|
3438
3434
|
if (userLocale === null) {
|
|
3439
|
-
userLocale = function (
|
|
3440
|
-
|
|
3441
|
-
return 'en-US';
|
|
3442
|
-
}
|
|
3443
|
-
var locales = (_navigator$languages = (_navigator = navigator) === null || _navigator === void 0 ? void 0 : _navigator.languages) !== null && _navigator$languages !== void 0 ? _navigator$languages : [];
|
|
3435
|
+
userLocale = function (_globalThis$navigator3, _globalThis$navigator4) {
|
|
3436
|
+
var locales = (_globalThis$navigator3 = globalThis === null || globalThis === void 0 || (_globalThis$navigator4 = globalThis.navigator) === null || _globalThis$navigator4 === void 0 ? void 0 : _globalThis$navigator4.languages) !== null && _globalThis$navigator3 !== void 0 ? _globalThis$navigator3 : [];
|
|
3444
3437
|
if (!IS_ARRAY(locales) || locales.length <= 0) {
|
|
3445
3438
|
return 'en-US';
|
|
3446
3439
|
}
|
|
@@ -3471,10 +3464,10 @@ var LeUtils = {
|
|
|
3471
3464
|
var userLocaleDateFormat = null;
|
|
3472
3465
|
return function () {
|
|
3473
3466
|
if (userLocaleDateFormat === null) {
|
|
3474
|
-
userLocaleDateFormat = function () {
|
|
3467
|
+
userLocaleDateFormat = function (_globalThis$Intl) {
|
|
3475
3468
|
var _char = '/';
|
|
3476
|
-
if (
|
|
3477
|
-
var formattedDate = new
|
|
3469
|
+
if (globalThis !== null && globalThis !== void 0 && (_globalThis$Intl = globalThis.Intl) !== null && _globalThis$Intl !== void 0 && _globalThis$Intl.DateTimeFormat) {
|
|
3470
|
+
var formattedDate = new globalThis.Intl.DateTimeFormat(LeUtils.getUserLocale()).format();
|
|
3478
3471
|
if (formattedDate.includes('-')) {
|
|
3479
3472
|
_char = '-';
|
|
3480
3473
|
} else if (formattedDate.includes('. ')) {
|