@tspro/ts-utils-lib 2.2.0 → 2.3.0
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/CHANGELOG.md +14 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.es5.iife.js +1 -1
- package/dist/index.es5.polyfilled.iife.js +1 -1
- package/dist/index.js +70 -35
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +70 -35
- package/dist/index.mjs.map +1 -0
- package/package.json +7 -9
- package/dist/index.d.mts +0 -1541
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
/*!
|
|
4
|
-
* TsUtilsLib v2.
|
|
4
|
+
* TsUtilsLib v2.3.0 (cjs)
|
|
5
5
|
* (c) 2023-2025 PahkaSoft
|
|
6
6
|
* Licensed under the MIT License
|
|
7
7
|
*/
|
|
@@ -1145,7 +1145,9 @@ var _consent;
|
|
|
1145
1145
|
var _expires;
|
|
1146
1146
|
var str = _read(ConsentCookieName);
|
|
1147
1147
|
_consent = str === "accept" /* Accept */ || str === "decline" /* Decline */ ? str : void 0;
|
|
1148
|
-
function
|
|
1148
|
+
function _getCookieList() {
|
|
1149
|
+
if (typeof document === "undefined")
|
|
1150
|
+
return [];
|
|
1149
1151
|
let s = document.cookie;
|
|
1150
1152
|
return s.split(";").map((c) => c.trim());
|
|
1151
1153
|
}
|
|
@@ -1154,15 +1156,17 @@ function _save(name, value) {
|
|
|
1154
1156
|
if (_expires) {
|
|
1155
1157
|
cookie += "expires=" + _expires.toUTCString() + ";";
|
|
1156
1158
|
}
|
|
1157
|
-
document
|
|
1159
|
+
if (typeof document !== "undefined")
|
|
1160
|
+
document.cookie = cookie;
|
|
1158
1161
|
return value;
|
|
1159
1162
|
}
|
|
1160
1163
|
function _read(name, defaultValue) {
|
|
1161
|
-
let str2 =
|
|
1164
|
+
let str2 = _getCookieList().find((c) => c.startsWith(name + "="));
|
|
1162
1165
|
return str2 === void 0 ? defaultValue : str2.substring(name.length + 1);
|
|
1163
1166
|
}
|
|
1164
1167
|
function _erase(name) {
|
|
1165
|
-
|
|
1168
|
+
if (typeof document !== "undefined")
|
|
1169
|
+
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC;";
|
|
1166
1170
|
}
|
|
1167
1171
|
function setExpireDays(days) {
|
|
1168
1172
|
_expires = /* @__PURE__ */ new Date();
|
|
@@ -1211,7 +1215,8 @@ function erase(name) {
|
|
|
1211
1215
|
_erase(name);
|
|
1212
1216
|
}
|
|
1213
1217
|
function eraseAll() {
|
|
1214
|
-
|
|
1218
|
+
if (typeof document !== "undefined")
|
|
1219
|
+
document.cookie.split(";").forEach((c) => erase(c.trim().split("=")[0]));
|
|
1215
1220
|
}
|
|
1216
1221
|
|
|
1217
1222
|
// src/web/device.ts
|
|
@@ -1229,12 +1234,16 @@ __export(device_exports, {
|
|
|
1229
1234
|
toPx: () => toPx
|
|
1230
1235
|
});
|
|
1231
1236
|
function getDPI() {
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1237
|
+
try {
|
|
1238
|
+
let el = document.createElement("div");
|
|
1239
|
+
el.style.width = "1in";
|
|
1240
|
+
document.body.appendChild(el);
|
|
1241
|
+
let dpi = el.offsetWidth;
|
|
1242
|
+
el.remove();
|
|
1243
|
+
return dpi || 96;
|
|
1244
|
+
} catch (e) {
|
|
1245
|
+
return 96;
|
|
1246
|
+
}
|
|
1238
1247
|
}
|
|
1239
1248
|
function getScrollBarWidth() {
|
|
1240
1249
|
try {
|
|
@@ -1257,18 +1266,23 @@ function getScrollBarWidth() {
|
|
|
1257
1266
|
}
|
|
1258
1267
|
}
|
|
1259
1268
|
function getSystemFontSize() {
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1269
|
+
try {
|
|
1270
|
+
let tmpDiv = document.createElement("div");
|
|
1271
|
+
tmpDiv.style.cssText = "display:inline-block; padding:0; line-height:1; position:absolute; visibility:hidden; font-size:1em";
|
|
1272
|
+
tmpDiv.appendChild(document.createTextNode("M"));
|
|
1273
|
+
document.body.appendChild(tmpDiv);
|
|
1274
|
+
let fontsize = tmpDiv.offsetHeight;
|
|
1275
|
+
document.body.removeChild(tmpDiv);
|
|
1276
|
+
return fontsize;
|
|
1277
|
+
} catch (e) {
|
|
1278
|
+
return 16;
|
|
1279
|
+
}
|
|
1267
1280
|
}
|
|
1268
1281
|
function getIsTouchDevice() {
|
|
1269
|
-
if (
|
|
1282
|
+
if (typeof window === "undefined")
|
|
1283
|
+
return false;
|
|
1284
|
+
if ("ontouchstart" in window || "DocumentTouch" in window || "createTouch" in document && "createTouchList" in document)
|
|
1270
1285
|
return true;
|
|
1271
|
-
}
|
|
1272
1286
|
var prefixes = " -webkit- -moz- -o- -ms- ".split(" ");
|
|
1273
1287
|
var mq = function(query2) {
|
|
1274
1288
|
return window.matchMedia(query2).matches;
|
|
@@ -1281,7 +1295,10 @@ function getIsMobileDevice() {
|
|
|
1281
1295
|
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(4|6)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(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)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\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|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(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|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(\-|0|1)|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(i|m)|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(a.substr(0, 4));
|
|
1282
1296
|
}
|
|
1283
1297
|
function getHostAddress() {
|
|
1284
|
-
|
|
1298
|
+
if (typeof location === "undefined" || !location.host) {
|
|
1299
|
+
return "localhost";
|
|
1300
|
+
}
|
|
1301
|
+
return `${location.protocol}//${location.host}`;
|
|
1285
1302
|
}
|
|
1286
1303
|
var UnitRegExp = /^(mm|cm|in|inch|px|em)$/;
|
|
1287
1304
|
var ValueUnitRegExp = /^([0-9\\.]+)(.*)$/;
|
|
@@ -1432,6 +1449,7 @@ __export(dom_exports, {
|
|
|
1432
1449
|
getPadding: () => getPadding,
|
|
1433
1450
|
getWidth: () => getWidth,
|
|
1434
1451
|
hasClass: () => hasClass,
|
|
1452
|
+
injectCss: () => injectCss,
|
|
1435
1453
|
removeClass: () => removeClass,
|
|
1436
1454
|
removeFromParent: () => removeFromParent,
|
|
1437
1455
|
setHeight: () => setHeight,
|
|
@@ -1441,6 +1459,9 @@ __export(dom_exports, {
|
|
|
1441
1459
|
setWidth: () => setWidth,
|
|
1442
1460
|
styleLayoutChanged: () => styleLayoutChanged
|
|
1443
1461
|
});
|
|
1462
|
+
function _getElemById(id) {
|
|
1463
|
+
return typeof document === "undefined" ? void 0 : document.getElementById(id) ?? void 0;
|
|
1464
|
+
}
|
|
1444
1465
|
function toPx2(value) {
|
|
1445
1466
|
return value === void 0 ? void 0 : device_exports.toPx(value);
|
|
1446
1467
|
}
|
|
@@ -1477,12 +1498,17 @@ function setOffset(el, left, top, unit = "px") {
|
|
|
1477
1498
|
el.style.top = top + unit;
|
|
1478
1499
|
}
|
|
1479
1500
|
function getOffset(el) {
|
|
1480
|
-
let
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
top
|
|
1484
|
-
|
|
1485
|
-
|
|
1501
|
+
let { left, top } = el.getBoundingClientRect();
|
|
1502
|
+
if (typeof window !== "undefined") {
|
|
1503
|
+
left += window.pageXOffset;
|
|
1504
|
+
top += window.pageYOffset;
|
|
1505
|
+
}
|
|
1506
|
+
if (typeof document !== "undefined") {
|
|
1507
|
+
let de = document.documentElement;
|
|
1508
|
+
left -= de.clientLeft;
|
|
1509
|
+
top -= de.clientTop;
|
|
1510
|
+
}
|
|
1511
|
+
return { left, top };
|
|
1486
1512
|
}
|
|
1487
1513
|
function getWidth(el) {
|
|
1488
1514
|
if (el instanceof Window) {
|
|
@@ -1522,11 +1548,11 @@ function setRect(el, left, top, width, height, unit = "px") {
|
|
|
1522
1548
|
el.style.height = height + unit;
|
|
1523
1549
|
}
|
|
1524
1550
|
function getButton(btn) {
|
|
1525
|
-
let el = typeof btn === "string" ?
|
|
1551
|
+
let el = typeof btn === "string" ? _getElemById(btn) : btn;
|
|
1526
1552
|
return el instanceof HTMLButtonElement ? el : void 0;
|
|
1527
1553
|
}
|
|
1528
1554
|
function getCanvas(canvas2) {
|
|
1529
|
-
let el = typeof canvas2 === "string" ?
|
|
1555
|
+
let el = typeof canvas2 === "string" ? _getElemById(canvas2) : canvas2;
|
|
1530
1556
|
return el instanceof HTMLCanvasElement ? el : void 0;
|
|
1531
1557
|
}
|
|
1532
1558
|
function getPadding(style) {
|
|
@@ -1599,14 +1625,23 @@ function styleLayoutChanged(style1, style2) {
|
|
|
1599
1625
|
}
|
|
1600
1626
|
var canvas;
|
|
1601
1627
|
function getCanvasTextWidth(text, font) {
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1628
|
+
if (!canvas && typeof document !== "undefined")
|
|
1629
|
+
canvas = document.createElement("canvas");
|
|
1630
|
+
let ctx = canvas?.getContext("2d");
|
|
1631
|
+
if (!ctx)
|
|
1605
1632
|
return 0;
|
|
1606
|
-
}
|
|
1607
1633
|
ctx.font = font;
|
|
1608
1634
|
return ctx.measureText(text).width;
|
|
1609
1635
|
}
|
|
1636
|
+
function injectCss(styleId, styleCss) {
|
|
1637
|
+
if (styleId === "" || styleCss === "") return;
|
|
1638
|
+
if (typeof document === "undefined") return;
|
|
1639
|
+
if (document.getElementById(styleId)) return;
|
|
1640
|
+
const style = document.createElement("style");
|
|
1641
|
+
style.id = styleId;
|
|
1642
|
+
style.textContent = styleCss;
|
|
1643
|
+
document.head.appendChild(style);
|
|
1644
|
+
}
|
|
1610
1645
|
|
|
1611
1646
|
// src/utils/math/index.ts
|
|
1612
1647
|
var math_exports = {};
|
|
@@ -4344,7 +4379,7 @@ var LinkedList = class _LinkedList extends BaseContainer {
|
|
|
4344
4379
|
|
|
4345
4380
|
// src/index.ts
|
|
4346
4381
|
function getLibInfo() {
|
|
4347
|
-
return "TsUtilsLib v2.
|
|
4382
|
+
return "TsUtilsLib v2.3.0 (cjs)";
|
|
4348
4383
|
}
|
|
4349
4384
|
|
|
4350
4385
|
exports.AnchoredRect = AnchoredRect;
|