@lowentry/utils 1.15.4 → 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/package.json
CHANGED
package/src/LeUtils.js
CHANGED
|
@@ -63,9 +63,10 @@ export const LeUtils = {
|
|
|
63
63
|
onDomReady:
|
|
64
64
|
(callback) =>
|
|
65
65
|
{
|
|
66
|
-
if(
|
|
66
|
+
if(!globalThis?.document || !globalThis?.document?.addEventListener || !globalThis?.document?.removeEventListener)
|
|
67
67
|
{
|
|
68
68
|
// no document, so we can't wait for it to be ready
|
|
69
|
+
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.');
|
|
69
70
|
return {
|
|
70
71
|
remove:() =>
|
|
71
72
|
{
|
|
@@ -73,7 +74,7 @@ export const LeUtils = {
|
|
|
73
74
|
};
|
|
74
75
|
}
|
|
75
76
|
|
|
76
|
-
if((document.readyState === 'interactive') || (document.readyState === 'complete'))
|
|
77
|
+
if((globalThis.document.readyState === 'interactive') || (globalThis.document.readyState === 'complete'))
|
|
77
78
|
{
|
|
78
79
|
return LeUtils.setTimeout(() => callback(), 0);
|
|
79
80
|
}
|
|
@@ -85,12 +86,12 @@ export const LeUtils = {
|
|
|
85
86
|
if(listening)
|
|
86
87
|
{
|
|
87
88
|
listening = false;
|
|
88
|
-
document.removeEventListener('DOMContentLoaded', callbackWrapper);
|
|
89
|
+
globalThis.document.removeEventListener('DOMContentLoaded', callbackWrapper);
|
|
89
90
|
callback();
|
|
90
91
|
}
|
|
91
92
|
};
|
|
92
93
|
|
|
93
|
-
document.addEventListener('DOMContentLoaded', callbackWrapper);
|
|
94
|
+
globalThis.document.addEventListener('DOMContentLoaded', callbackWrapper);
|
|
94
95
|
|
|
95
96
|
return {
|
|
96
97
|
remove:
|
|
@@ -99,7 +100,7 @@ export const LeUtils = {
|
|
|
99
100
|
if(listening)
|
|
100
101
|
{
|
|
101
102
|
listening = false;
|
|
102
|
-
document.removeEventListener('DOMContentLoaded', callbackWrapper);
|
|
103
|
+
globalThis.document.removeEventListener('DOMContentLoaded', callbackWrapper);
|
|
103
104
|
}
|
|
104
105
|
},
|
|
105
106
|
};
|
|
@@ -1236,8 +1237,9 @@ export const LeUtils = {
|
|
|
1236
1237
|
setTimeout:
|
|
1237
1238
|
(callback, ms) =>
|
|
1238
1239
|
{
|
|
1239
|
-
if(
|
|
1240
|
+
if(!globalThis?.setTimeout || !globalThis?.clearTimeout)
|
|
1240
1241
|
{
|
|
1242
|
+
console.warn('LeUtils.setTimeout() called in an environment without globalThis.setTimeout, returning a no-op handler.');
|
|
1241
1243
|
return {
|
|
1242
1244
|
remove:() =>
|
|
1243
1245
|
{
|
|
@@ -1247,11 +1249,11 @@ export const LeUtils = {
|
|
|
1247
1249
|
|
|
1248
1250
|
ms = FLOAT_LAX(ms);
|
|
1249
1251
|
|
|
1250
|
-
let lastTime = performance
|
|
1252
|
+
let lastTime = performance?.now?.() ?? 0;
|
|
1251
1253
|
/** @type {number|null} */
|
|
1252
|
-
let handler =
|
|
1254
|
+
let handler = globalThis.setTimeout(() =>
|
|
1253
1255
|
{
|
|
1254
|
-
const currentTime = performance
|
|
1256
|
+
const currentTime = performance?.now?.() ?? 0;
|
|
1255
1257
|
try
|
|
1256
1258
|
{
|
|
1257
1259
|
callback((currentTime - lastTime) / 1000);
|
|
@@ -1269,7 +1271,7 @@ export const LeUtils = {
|
|
|
1269
1271
|
{
|
|
1270
1272
|
if(handler !== null)
|
|
1271
1273
|
{
|
|
1272
|
-
|
|
1274
|
+
globalThis.clearTimeout(handler);
|
|
1273
1275
|
handler = null;
|
|
1274
1276
|
}
|
|
1275
1277
|
},
|
|
@@ -1303,8 +1305,9 @@ export const LeUtils = {
|
|
|
1303
1305
|
}
|
|
1304
1306
|
}
|
|
1305
1307
|
|
|
1306
|
-
if(
|
|
1308
|
+
if(!globalThis?.setInterval || !globalThis?.clearInterval)
|
|
1307
1309
|
{
|
|
1310
|
+
console.warn('LeUtils.setInterval() called in an environment without globalThis.setInterval, returning a no-op handler.');
|
|
1308
1311
|
return {
|
|
1309
1312
|
remove:() =>
|
|
1310
1313
|
{
|
|
@@ -1312,11 +1315,11 @@ export const LeUtils = {
|
|
|
1312
1315
|
};
|
|
1313
1316
|
}
|
|
1314
1317
|
|
|
1315
|
-
let lastTime = performance
|
|
1318
|
+
let lastTime = performance?.now?.() ?? 0;
|
|
1316
1319
|
/** @type {number|null} */
|
|
1317
|
-
let handler =
|
|
1320
|
+
let handler = globalThis.setInterval(() =>
|
|
1318
1321
|
{
|
|
1319
|
-
const currentTime = performance
|
|
1322
|
+
const currentTime = performance?.now?.() ?? 0;
|
|
1320
1323
|
try
|
|
1321
1324
|
{
|
|
1322
1325
|
callback((currentTime - lastTime) / 1000);
|
|
@@ -1334,7 +1337,7 @@ export const LeUtils = {
|
|
|
1334
1337
|
{
|
|
1335
1338
|
if(handler !== null)
|
|
1336
1339
|
{
|
|
1337
|
-
|
|
1340
|
+
globalThis.clearInterval(handler);
|
|
1338
1341
|
handler = null;
|
|
1339
1342
|
}
|
|
1340
1343
|
},
|
|
@@ -1353,8 +1356,9 @@ export const LeUtils = {
|
|
|
1353
1356
|
setAnimationFrameTimeout:
|
|
1354
1357
|
(callback, frames = 1) =>
|
|
1355
1358
|
{
|
|
1356
|
-
if(
|
|
1359
|
+
if(!globalThis?.requestAnimationFrame || !globalThis?.cancelAnimationFrame)
|
|
1357
1360
|
{
|
|
1361
|
+
console.warn('LeUtils.setAnimationFrameTimeout() called in an environment without globalThis.requestAnimationFrame, returning a no-op handler.');
|
|
1358
1362
|
return {
|
|
1359
1363
|
remove:() =>
|
|
1360
1364
|
{
|
|
@@ -1366,7 +1370,7 @@ export const LeUtils = {
|
|
|
1366
1370
|
|
|
1367
1371
|
let run = true;
|
|
1368
1372
|
let requestAnimationFrameId = null;
|
|
1369
|
-
let lastTime = performance
|
|
1373
|
+
let lastTime = performance?.now?.() ?? 0;
|
|
1370
1374
|
const tick = () =>
|
|
1371
1375
|
{
|
|
1372
1376
|
if(run)
|
|
@@ -1375,7 +1379,7 @@ export const LeUtils = {
|
|
|
1375
1379
|
{
|
|
1376
1380
|
run = false;
|
|
1377
1381
|
requestAnimationFrameId = null;
|
|
1378
|
-
const currentTime = performance
|
|
1382
|
+
const currentTime = performance?.now?.() ?? 0;
|
|
1379
1383
|
try
|
|
1380
1384
|
{
|
|
1381
1385
|
callback((currentTime - lastTime) / 1000);
|
|
@@ -1388,7 +1392,7 @@ export const LeUtils = {
|
|
|
1388
1392
|
return;
|
|
1389
1393
|
}
|
|
1390
1394
|
frames--;
|
|
1391
|
-
requestAnimationFrameId =
|
|
1395
|
+
requestAnimationFrameId = globalThis.requestAnimationFrame(tick);
|
|
1392
1396
|
}
|
|
1393
1397
|
};
|
|
1394
1398
|
tick();
|
|
@@ -1400,7 +1404,7 @@ export const LeUtils = {
|
|
|
1400
1404
|
run = false;
|
|
1401
1405
|
if(requestAnimationFrameId !== null)
|
|
1402
1406
|
{
|
|
1403
|
-
|
|
1407
|
+
globalThis.cancelAnimationFrame(requestAnimationFrameId);
|
|
1404
1408
|
requestAnimationFrameId = null;
|
|
1405
1409
|
}
|
|
1406
1410
|
},
|
|
@@ -1434,8 +1438,9 @@ export const LeUtils = {
|
|
|
1434
1438
|
}
|
|
1435
1439
|
}
|
|
1436
1440
|
|
|
1437
|
-
if(
|
|
1441
|
+
if(!globalThis?.requestAnimationFrame || !globalThis?.cancelAnimationFrame)
|
|
1438
1442
|
{
|
|
1443
|
+
console.warn('LeUtils.setAnimationFrameInterval() called in an environment without globalThis.requestAnimationFrame, returning a no-op handler.');
|
|
1439
1444
|
return {
|
|
1440
1445
|
remove:() =>
|
|
1441
1446
|
{
|
|
@@ -1445,7 +1450,7 @@ export const LeUtils = {
|
|
|
1445
1450
|
|
|
1446
1451
|
let run = true;
|
|
1447
1452
|
let requestAnimationFrameId = null;
|
|
1448
|
-
let lastTime = performance
|
|
1453
|
+
let lastTime = performance?.now?.() ?? 0;
|
|
1449
1454
|
let frames = intervalFrames;
|
|
1450
1455
|
const tick = () =>
|
|
1451
1456
|
{
|
|
@@ -1453,7 +1458,7 @@ export const LeUtils = {
|
|
|
1453
1458
|
{
|
|
1454
1459
|
if(frames <= 0)
|
|
1455
1460
|
{
|
|
1456
|
-
let currentTime = performance
|
|
1461
|
+
let currentTime = performance?.now?.() ?? 0;
|
|
1457
1462
|
try
|
|
1458
1463
|
{
|
|
1459
1464
|
callback((currentTime - lastTime) / 1000);
|
|
@@ -1469,11 +1474,11 @@ export const LeUtils = {
|
|
|
1469
1474
|
|
|
1470
1475
|
if(run)
|
|
1471
1476
|
{
|
|
1472
|
-
requestAnimationFrameId =
|
|
1477
|
+
requestAnimationFrameId = globalThis.requestAnimationFrame(tick);
|
|
1473
1478
|
}
|
|
1474
1479
|
}
|
|
1475
1480
|
};
|
|
1476
|
-
|
|
1481
|
+
globalThis.requestAnimationFrame(tick);
|
|
1477
1482
|
|
|
1478
1483
|
return {
|
|
1479
1484
|
remove:
|
|
@@ -1482,7 +1487,7 @@ export const LeUtils = {
|
|
|
1482
1487
|
run = false;
|
|
1483
1488
|
if(requestAnimationFrameId !== null)
|
|
1484
1489
|
{
|
|
1485
|
-
|
|
1490
|
+
globalThis.cancelAnimationFrame(requestAnimationFrameId);
|
|
1486
1491
|
requestAnimationFrameId = null;
|
|
1487
1492
|
}
|
|
1488
1493
|
},
|
|
@@ -1538,7 +1543,7 @@ export const LeUtils = {
|
|
|
1538
1543
|
|
|
1539
1544
|
let controllerAborted = false;
|
|
1540
1545
|
let controller = null;
|
|
1541
|
-
if(
|
|
1546
|
+
if(globalThis?.AbortController)
|
|
1542
1547
|
{
|
|
1543
1548
|
controller = new AbortController();
|
|
1544
1549
|
}
|
|
@@ -1689,13 +1694,9 @@ export const LeUtils = {
|
|
|
1689
1694
|
platformIsMobile:
|
|
1690
1695
|
() =>
|
|
1691
1696
|
{
|
|
1692
|
-
if(typeof window === 'undefined')
|
|
1693
|
-
{
|
|
1694
|
-
return false;
|
|
1695
|
-
}
|
|
1696
1697
|
// noinspection JSDeprecatedSymbols, JSUnresolvedReference
|
|
1697
1698
|
/** navigator.userAgentData.mobile doesn't return the correct value on some platforms, so this is a work-around, code from: http://detectmobilebrowsers.com **/
|
|
1698
|
-
const a = STRING(
|
|
1699
|
+
const a = STRING(globalThis?.navigator?.userAgent || globalThis?.navigator?.vendor || globalThis?.opera || '');
|
|
1699
1700
|
const b = a.substring(0, 4);
|
|
1700
1701
|
return !!(
|
|
1701
1702
|
/(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
|
|
@@ -1714,11 +1715,7 @@ export const LeUtils = {
|
|
|
1714
1715
|
platformHasCursor:
|
|
1715
1716
|
() =>
|
|
1716
1717
|
{
|
|
1717
|
-
|
|
1718
|
-
{
|
|
1719
|
-
return true;
|
|
1720
|
-
}
|
|
1721
|
-
return !LeUtils.platformIsMobile() && !window.matchMedia('(any-hover: none)')?.matches;
|
|
1718
|
+
return !LeUtils.platformIsMobile() && !globalThis?.matchMedia?.('(any-hover: none)')?.matches;
|
|
1722
1719
|
},
|
|
1723
1720
|
|
|
1724
1721
|
/**
|
|
@@ -2042,21 +2039,13 @@ export const LeUtils = {
|
|
|
2042
2039
|
let now;
|
|
2043
2040
|
try
|
|
2044
2041
|
{
|
|
2045
|
-
if(typeof window === 'undefined')
|
|
2046
|
-
{
|
|
2047
|
-
throw new Error();
|
|
2048
|
-
}
|
|
2049
2042
|
// noinspection JSDeprecatedSymbols
|
|
2050
|
-
now = (performance
|
|
2051
|
-
if(typeof now !== 'number')
|
|
2052
|
-
{
|
|
2053
|
-
throw new Error();
|
|
2054
|
-
}
|
|
2043
|
+
now = (performance?.timeOrigin || performance?.timing?.navigationStart || 0) + (performance?.now?.() ?? 0);
|
|
2055
2044
|
}
|
|
2056
2045
|
catch(e)
|
|
2057
2046
|
{
|
|
2058
|
-
now = (Date.now ? Date.now() : (new Date()).getTime());
|
|
2059
2047
|
}
|
|
2048
|
+
now = now || (Date.now ? Date.now() : (new Date()).getTime());
|
|
2060
2049
|
now = Math.round(now);
|
|
2061
2050
|
const nowBytes = numberToBytes(now);
|
|
2062
2051
|
|
|
@@ -2151,21 +2140,13 @@ export const LeUtils = {
|
|
|
2151
2140
|
{
|
|
2152
2141
|
try
|
|
2153
2142
|
{
|
|
2154
|
-
if(typeof window === 'undefined')
|
|
2155
|
-
{
|
|
2156
|
-
throw new Error();
|
|
2157
|
-
}
|
|
2158
2143
|
// noinspection JSDeprecatedSymbols
|
|
2159
|
-
now = (performance
|
|
2160
|
-
if(typeof now !== 'number')
|
|
2161
|
-
{
|
|
2162
|
-
throw new Error();
|
|
2163
|
-
}
|
|
2144
|
+
now = (performance?.timeOrigin || performance?.timing?.navigationStart || 0) + (performance?.now?.() ?? 0);
|
|
2164
2145
|
}
|
|
2165
2146
|
catch(e)
|
|
2166
2147
|
{
|
|
2167
|
-
now = (Date.now ? Date.now() : (new Date()).getTime());
|
|
2168
2148
|
}
|
|
2149
|
+
now = now || (Date.now ? Date.now() : (new Date()).getTime());
|
|
2169
2150
|
}
|
|
2170
2151
|
now = Math.round(now);
|
|
2171
2152
|
const nowBytes = numberToBytes(now);
|
|
@@ -2214,12 +2195,13 @@ export const LeUtils = {
|
|
|
2214
2195
|
getImagePixels:
|
|
2215
2196
|
(image) =>
|
|
2216
2197
|
{
|
|
2217
|
-
if(
|
|
2198
|
+
if(!globalThis?.document?.createElement || !globalThis?.document?.body?.appendChild)
|
|
2218
2199
|
{
|
|
2200
|
+
console.warn('LeUtils.getImagePixels: Document is not available, returning empty pixels.');
|
|
2219
2201
|
return new Uint8ClampedArray();
|
|
2220
2202
|
}
|
|
2221
|
-
const canvas = document.createElement('canvas');
|
|
2222
|
-
document.body.appendChild(canvas);
|
|
2203
|
+
const canvas = globalThis.document.createElement('canvas');
|
|
2204
|
+
globalThis.document.body.appendChild(canvas);
|
|
2223
2205
|
try
|
|
2224
2206
|
{
|
|
2225
2207
|
const ctx = canvas.getContext('2d');
|
|
@@ -2250,12 +2232,13 @@ export const LeUtils = {
|
|
|
2250
2232
|
getColoredImage:
|
|
2251
2233
|
(image, color) =>
|
|
2252
2234
|
{
|
|
2253
|
-
if(
|
|
2235
|
+
if(!globalThis?.document?.createElement || !globalThis?.document?.body?.appendChild)
|
|
2254
2236
|
{
|
|
2237
|
+
console.warn('LeUtils.getColoredImage: Document is not available, returning empty image src.');
|
|
2255
2238
|
return LeUtils.getEmptyImageSrc();
|
|
2256
2239
|
}
|
|
2257
|
-
const canvas = document.createElement('canvas');
|
|
2258
|
-
document.body.appendChild(canvas);
|
|
2240
|
+
const canvas = globalThis.document.createElement('canvas');
|
|
2241
|
+
globalThis.document.body.appendChild(canvas);
|
|
2259
2242
|
try
|
|
2260
2243
|
{
|
|
2261
2244
|
const ctx = canvas.getContext('2d');
|
|
@@ -2641,12 +2624,15 @@ export const LeUtils = {
|
|
|
2641
2624
|
btoa:
|
|
2642
2625
|
(string) =>
|
|
2643
2626
|
{
|
|
2644
|
-
if(typeof btoa === 'function')
|
|
2627
|
+
if(typeof globalThis?.btoa === 'function')
|
|
2628
|
+
{
|
|
2629
|
+
return globalThis.btoa(string);
|
|
2630
|
+
}
|
|
2631
|
+
if(typeof globalThis?.Buffer?.from === 'function')
|
|
2645
2632
|
{
|
|
2646
|
-
return
|
|
2633
|
+
return globalThis.Buffer.from(string).toString('base64');
|
|
2647
2634
|
}
|
|
2648
|
-
|
|
2649
|
-
return Buffer.from(string).toString('base64');
|
|
2635
|
+
throw new Error('LeUtils.btoa: No btoa implementation found in this environment.');
|
|
2650
2636
|
},
|
|
2651
2637
|
|
|
2652
2638
|
/**
|
|
@@ -2658,12 +2644,15 @@ export const LeUtils = {
|
|
|
2658
2644
|
atob:
|
|
2659
2645
|
(base64string) =>
|
|
2660
2646
|
{
|
|
2661
|
-
if(typeof atob === 'function')
|
|
2647
|
+
if(typeof globalThis?.atob === 'function')
|
|
2648
|
+
{
|
|
2649
|
+
return globalThis.atob(base64string);
|
|
2650
|
+
}
|
|
2651
|
+
if(typeof globalThis?.Buffer?.from === 'function')
|
|
2662
2652
|
{
|
|
2663
|
-
return
|
|
2653
|
+
return globalThis.Buffer.from(base64string, 'base64').toString();
|
|
2664
2654
|
}
|
|
2665
|
-
|
|
2666
|
-
return Buffer.from(base64string, 'base64').toString();
|
|
2655
|
+
throw new Error('LeUtils.atob: No atob implementation found in this environment.');
|
|
2667
2656
|
},
|
|
2668
2657
|
|
|
2669
2658
|
/**
|
|
@@ -2767,11 +2756,12 @@ export const LeUtils = {
|
|
|
2767
2756
|
downloadFile:
|
|
2768
2757
|
(base64string, fileName, mimeType) =>
|
|
2769
2758
|
{
|
|
2770
|
-
if(
|
|
2759
|
+
if(!globalThis?.document?.createElement)
|
|
2771
2760
|
{
|
|
2761
|
+
console.warn('LeUtils.downloadFile: Document is not available, cannot download file.');
|
|
2772
2762
|
return;
|
|
2773
2763
|
}
|
|
2774
|
-
const link = document.createElement('a');
|
|
2764
|
+
const link = globalThis.document.createElement('a');
|
|
2775
2765
|
link.setAttribute('download', (typeof fileName === 'string') ? fileName : 'file');
|
|
2776
2766
|
link.href = 'data:' + mimeType + ';base64,' + base64string;
|
|
2777
2767
|
link.setAttribute('target', '_blank');
|
|
@@ -2787,11 +2777,12 @@ export const LeUtils = {
|
|
|
2787
2777
|
localStorageGet:
|
|
2788
2778
|
(id) =>
|
|
2789
2779
|
{
|
|
2790
|
-
if(
|
|
2780
|
+
if(!globalThis?.localStorage?.getItem)
|
|
2791
2781
|
{
|
|
2782
|
+
console.warn('LeUtils.localStorageGet: LocalStorage is not available, returning undefined.');
|
|
2792
2783
|
return;
|
|
2793
2784
|
}
|
|
2794
|
-
let result =
|
|
2785
|
+
let result = globalThis.localStorage.getItem('LeUtils_' + id);
|
|
2795
2786
|
if(typeof result !== 'string')
|
|
2796
2787
|
{
|
|
2797
2788
|
return;
|
|
@@ -2814,16 +2805,17 @@ export const LeUtils = {
|
|
|
2814
2805
|
localStorageSet:
|
|
2815
2806
|
(id, data) =>
|
|
2816
2807
|
{
|
|
2817
|
-
if(
|
|
2808
|
+
if(!globalThis?.localStorage?.setItem)
|
|
2818
2809
|
{
|
|
2810
|
+
console.warn('LeUtils.localStorageSet: LocalStorage is not available, cannot save data.');
|
|
2819
2811
|
return;
|
|
2820
2812
|
}
|
|
2821
2813
|
if(typeof data === 'undefined')
|
|
2822
2814
|
{
|
|
2823
|
-
|
|
2815
|
+
globalThis.localStorage.removeItem('LeUtils_' + id);
|
|
2824
2816
|
return;
|
|
2825
2817
|
}
|
|
2826
|
-
|
|
2818
|
+
globalThis.localStorage.setItem('LeUtils_' + id, JSON.stringify({'-':data}));
|
|
2827
2819
|
},
|
|
2828
2820
|
|
|
2829
2821
|
/**
|
|
@@ -2834,15 +2826,16 @@ export const LeUtils = {
|
|
|
2834
2826
|
localStorageRemove:
|
|
2835
2827
|
(id) =>
|
|
2836
2828
|
{
|
|
2837
|
-
if(
|
|
2829
|
+
if(!globalThis?.localStorage?.removeItem)
|
|
2838
2830
|
{
|
|
2831
|
+
console.warn('LeUtils.localStorageRemove: LocalStorage is not available, cannot remove data.');
|
|
2839
2832
|
return;
|
|
2840
2833
|
}
|
|
2841
|
-
|
|
2834
|
+
globalThis.localStorage.removeItem('LeUtils_' + id);
|
|
2842
2835
|
},
|
|
2843
2836
|
|
|
2844
2837
|
/**
|
|
2845
|
-
* Returns whether the current hostname (
|
|
2838
|
+
* Returns whether the current hostname (globalThis.location.hostname) is private (such as localhost, 192.168.1.1, etc).
|
|
2846
2839
|
* This can be used to determine if the app is running in a development environment or not.
|
|
2847
2840
|
*
|
|
2848
2841
|
* Only "localhost" and IPv4 addresses are supported. IPv6 addresses will always return false.
|
|
@@ -2857,11 +2850,12 @@ export const LeUtils = {
|
|
|
2857
2850
|
|
|
2858
2851
|
return () =>
|
|
2859
2852
|
{
|
|
2860
|
-
if(
|
|
2853
|
+
if(!globalThis?.location?.hostname)
|
|
2861
2854
|
{
|
|
2862
|
-
|
|
2855
|
+
console.warn('LeUtils.isCurrentHostPrivate: No location.hostname found, returning false.');
|
|
2856
|
+
return false;
|
|
2863
2857
|
}
|
|
2864
|
-
const hostname =
|
|
2858
|
+
const hostname = globalThis.location.hostname;
|
|
2865
2859
|
if(lastHostname === hostname)
|
|
2866
2860
|
{
|
|
2867
2861
|
return lastResult;
|
|
@@ -3334,8 +3328,9 @@ export const LeUtils = {
|
|
|
3334
3328
|
createWorkerThread:
|
|
3335
3329
|
(name) =>
|
|
3336
3330
|
{
|
|
3337
|
-
if(
|
|
3331
|
+
if(!globalThis?.Worker)
|
|
3338
3332
|
{
|
|
3333
|
+
console.warn('LeUtils.createWorkerThread: Workers are not supported in this environment, returning a dummy worker.');
|
|
3339
3334
|
return {
|
|
3340
3335
|
worker: null,
|
|
3341
3336
|
sendMessage:(data, options) => new Promise((resolve, reject) =>
|
|
@@ -3345,7 +3340,7 @@ export const LeUtils = {
|
|
|
3345
3340
|
};
|
|
3346
3341
|
}
|
|
3347
3342
|
|
|
3348
|
-
const worker = new Worker('/workers/' + name + '.worker.js');
|
|
3343
|
+
const worker = new globalThis.Worker('/workers/' + name + '.worker.js');
|
|
3349
3344
|
let listeners = new Map();
|
|
3350
3345
|
|
|
3351
3346
|
const addListener = (id, callback) =>
|
|
@@ -3446,12 +3441,8 @@ export const LeUtils = {
|
|
|
3446
3441
|
*/
|
|
3447
3442
|
isFocusClear:(() =>
|
|
3448
3443
|
{
|
|
3449
|
-
if((typeof window === 'undefined') || !document)
|
|
3450
|
-
{
|
|
3451
|
-
return () => true;
|
|
3452
|
-
}
|
|
3453
3444
|
const inputTypes = ['text', 'search', 'email', 'number', 'password', 'tel', 'time', 'url', 'week', 'month', 'date', 'datetime-local'];
|
|
3454
|
-
return () => !((document?.activeElement?.tagName?.toLowerCase() === 'input') && inputTypes.includes(document?.activeElement?.getAttribute('type')?.toLowerCase() ?? ''));
|
|
3445
|
+
return () => !((globalThis?.document?.activeElement?.tagName?.toLowerCase() === 'input') && inputTypes.includes(globalThis?.document?.activeElement?.getAttribute('type')?.toLowerCase() ?? ''));
|
|
3455
3446
|
})(),
|
|
3456
3447
|
|
|
3457
3448
|
/**
|
|
@@ -3468,11 +3459,7 @@ export const LeUtils = {
|
|
|
3468
3459
|
{
|
|
3469
3460
|
userLocale = (() =>
|
|
3470
3461
|
{
|
|
3471
|
-
|
|
3472
|
-
{
|
|
3473
|
-
return 'en-US';
|
|
3474
|
-
}
|
|
3475
|
-
let locales = navigator?.languages ?? [];
|
|
3462
|
+
let locales = globalThis?.navigator?.languages ?? [];
|
|
3476
3463
|
if(!IS_ARRAY(locales) || (locales.length <= 0))
|
|
3477
3464
|
{
|
|
3478
3465
|
return 'en-US';
|
|
@@ -3509,9 +3496,9 @@ export const LeUtils = {
|
|
|
3509
3496
|
userLocaleDateFormat = (() =>
|
|
3510
3497
|
{
|
|
3511
3498
|
let char = '/';
|
|
3512
|
-
if(
|
|
3499
|
+
if(globalThis?.Intl?.DateTimeFormat)
|
|
3513
3500
|
{
|
|
3514
|
-
const formattedDate = new
|
|
3501
|
+
const formattedDate = new globalThis.Intl.DateTimeFormat(LeUtils.getUserLocale()).format();
|
|
3515
3502
|
if(formattedDate.includes('-'))
|
|
3516
3503
|
{
|
|
3517
3504
|
char = '-';
|