@tspro/ts-utils-lib 1.16.0 → 1.17.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 +11 -0
- package/dist/index.d.mts +386 -115
- package/dist/index.d.ts +386 -115
- package/dist/index.js +637 -195
- package/dist/index.mjs +635 -195
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* TsUtilsLib v1.
|
|
1
|
+
/* TsUtilsLib v1.17.0 | (c) 2023 PahkaSoft | Licensed under the MIT License */
|
|
2
2
|
"use strict";
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -26,6 +26,7 @@ __export(index_exports, {
|
|
|
26
26
|
Assert: () => Assert,
|
|
27
27
|
Cookies: () => Cookies,
|
|
28
28
|
Device: () => Device,
|
|
29
|
+
DivRect: () => DivRect,
|
|
29
30
|
IndexArray: () => IndexArray,
|
|
30
31
|
LRUCache: () => LRUCache,
|
|
31
32
|
Map1: () => Map1,
|
|
@@ -36,6 +37,7 @@ __export(index_exports, {
|
|
|
36
37
|
SmallIntCache: () => SmallIntCache,
|
|
37
38
|
Stack: () => Stack,
|
|
38
39
|
Utils: () => utils_exports,
|
|
40
|
+
Vec: () => Vec,
|
|
39
41
|
Vec2: () => Vec2,
|
|
40
42
|
asMulti: () => asMulti
|
|
41
43
|
});
|
|
@@ -1117,28 +1119,396 @@ var Stack = class {
|
|
|
1117
1119
|
}
|
|
1118
1120
|
};
|
|
1119
1121
|
|
|
1120
|
-
// src/core/
|
|
1121
|
-
var
|
|
1122
|
-
constructor(
|
|
1123
|
-
__publicField(this, "
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1122
|
+
// src/core/vec.ts
|
|
1123
|
+
var Vec = class _Vec {
|
|
1124
|
+
constructor(...coords) {
|
|
1125
|
+
__publicField(this, "coords");
|
|
1126
|
+
if (coords.length < 2) {
|
|
1127
|
+
throw new TypeError("Vec needs minumum two coords!");
|
|
1128
|
+
}
|
|
1129
|
+
this.coords = coords;
|
|
1127
1130
|
}
|
|
1128
|
-
|
|
1129
|
-
return
|
|
1131
|
+
static vec2(x, y) {
|
|
1132
|
+
return new _Vec(x, y);
|
|
1130
1133
|
}
|
|
1131
|
-
|
|
1132
|
-
return new
|
|
1134
|
+
static vec3(x, y, z) {
|
|
1135
|
+
return new _Vec(x, y, z);
|
|
1133
1136
|
}
|
|
1134
|
-
|
|
1135
|
-
|
|
1137
|
+
static zero(dim) {
|
|
1138
|
+
if (dim < 2) {
|
|
1139
|
+
throw new TypeError("Vec.zero requires dimension >= 2");
|
|
1140
|
+
}
|
|
1141
|
+
return new _Vec(...Array(dim).fill(0));
|
|
1136
1142
|
}
|
|
1137
|
-
|
|
1138
|
-
return
|
|
1143
|
+
get length() {
|
|
1144
|
+
return Math.hypot(...this.coords);
|
|
1139
1145
|
}
|
|
1140
|
-
|
|
1141
|
-
return
|
|
1146
|
+
get x() {
|
|
1147
|
+
return this.coords[0];
|
|
1148
|
+
}
|
|
1149
|
+
get y() {
|
|
1150
|
+
return this.coords[1];
|
|
1151
|
+
}
|
|
1152
|
+
get z() {
|
|
1153
|
+
if (this.coords[2] === void 0) {
|
|
1154
|
+
throw new TypeError("Vec z-coord not available!");
|
|
1155
|
+
}
|
|
1156
|
+
return this.coords[2];
|
|
1157
|
+
}
|
|
1158
|
+
add(...args) {
|
|
1159
|
+
const otherCoords = args[0] instanceof _Vec ? args[0].coords : args;
|
|
1160
|
+
if (this.coords.length !== otherCoords.length) {
|
|
1161
|
+
throw new TypeError("Coordinate length mismatch!");
|
|
1162
|
+
}
|
|
1163
|
+
return new _Vec(...this.coords.map((coord, i) => coord + otherCoords[i]));
|
|
1164
|
+
}
|
|
1165
|
+
sub(...args) {
|
|
1166
|
+
const otherCoords = args[0] instanceof _Vec ? args[0].coords : args;
|
|
1167
|
+
if (this.coords.length !== otherCoords.length) {
|
|
1168
|
+
throw new TypeError("Coordinate length mismatch!");
|
|
1169
|
+
}
|
|
1170
|
+
return new _Vec(...this.coords.map((coord, i) => coord - otherCoords[i]));
|
|
1171
|
+
}
|
|
1172
|
+
mul(scalar) {
|
|
1173
|
+
return new _Vec(...this.coords.map((coord) => coord * scalar));
|
|
1174
|
+
}
|
|
1175
|
+
div(scalar) {
|
|
1176
|
+
return new _Vec(...this.coords.map((coord) => coord / scalar));
|
|
1177
|
+
}
|
|
1178
|
+
dot(other) {
|
|
1179
|
+
if (this.coords.length !== other.coords.length) {
|
|
1180
|
+
throw new TypeError("Coordinate length mismatch!");
|
|
1181
|
+
}
|
|
1182
|
+
return this.coords.reduce((sum2, c, i) => sum2 + c * other.coords[i], 0);
|
|
1183
|
+
}
|
|
1184
|
+
distance(other) {
|
|
1185
|
+
if (this.coords.length !== other.coords.length) {
|
|
1186
|
+
throw new TypeError("Coordinate length mismatch!");
|
|
1187
|
+
}
|
|
1188
|
+
return Math.hypot(...this.coords.map((c, i) => c - other.coords[i]));
|
|
1189
|
+
}
|
|
1190
|
+
normalize() {
|
|
1191
|
+
const len = this.length;
|
|
1192
|
+
if (len === 0) {
|
|
1193
|
+
throw new TypeError("Cannot normalize zero-length vector!");
|
|
1194
|
+
}
|
|
1195
|
+
return this.div(len);
|
|
1196
|
+
}
|
|
1197
|
+
equals(other) {
|
|
1198
|
+
return this.coords.length === other.coords.length && this.coords.every((v, i) => v === other.coords[i]);
|
|
1199
|
+
}
|
|
1200
|
+
clone() {
|
|
1201
|
+
return new _Vec(...this.coords);
|
|
1202
|
+
}
|
|
1203
|
+
toObject() {
|
|
1204
|
+
return { x: this.x, y: this.y, z: this.z };
|
|
1205
|
+
}
|
|
1206
|
+
[Symbol.iterator]() {
|
|
1207
|
+
return this.coords[Symbol.iterator]();
|
|
1208
|
+
}
|
|
1209
|
+
toString() {
|
|
1210
|
+
return `Vec(${this.coords.join(", ")})`;
|
|
1211
|
+
}
|
|
1212
|
+
};
|
|
1213
|
+
|
|
1214
|
+
// src/core/div-rect.ts
|
|
1215
|
+
var DivRect = class _DivRect {
|
|
1216
|
+
constructor(...args) {
|
|
1217
|
+
__publicField(this, "left");
|
|
1218
|
+
__publicField(this, "centerX");
|
|
1219
|
+
__publicField(this, "right");
|
|
1220
|
+
__publicField(this, "top");
|
|
1221
|
+
__publicField(this, "centerY");
|
|
1222
|
+
__publicField(this, "bottom");
|
|
1223
|
+
if (args.length === 6) {
|
|
1224
|
+
this.left = args[0];
|
|
1225
|
+
this.centerX = args[1];
|
|
1226
|
+
this.right = args[2];
|
|
1227
|
+
this.top = args[3];
|
|
1228
|
+
this.centerY = args[4];
|
|
1229
|
+
this.bottom = args[5];
|
|
1230
|
+
} else if (args.length === 4) {
|
|
1231
|
+
this.left = args[0];
|
|
1232
|
+
this.right = args[1];
|
|
1233
|
+
this.centerX = (this.left + this.right) / 2;
|
|
1234
|
+
this.top = args[2];
|
|
1235
|
+
this.bottom = args[3];
|
|
1236
|
+
this.centerY = (this.top + this.bottom) / 2;
|
|
1237
|
+
} else if (args.length === 0) {
|
|
1238
|
+
this.left = this.centerX = this.right = 0;
|
|
1239
|
+
this.top = this.centerY = this.bottom = 0;
|
|
1240
|
+
} else {
|
|
1241
|
+
throw new TypeError(`Invalid DivRect args: ${args}`);
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
/**
|
|
1245
|
+
* Create rect from basic left, top, width and height arguments.
|
|
1246
|
+
*
|
|
1247
|
+
* @param left - Left coordinate.
|
|
1248
|
+
* @param top - Top coordinate.
|
|
1249
|
+
* @param width - Width.
|
|
1250
|
+
* @param height - Height.
|
|
1251
|
+
* @returns - DivRect.
|
|
1252
|
+
*/
|
|
1253
|
+
static create(left, top, width, height) {
|
|
1254
|
+
return new _DivRect(left, left + width, top, top + height);
|
|
1255
|
+
}
|
|
1256
|
+
/**
|
|
1257
|
+
* Create rect from centerX, centerY, width, height arguments.
|
|
1258
|
+
*
|
|
1259
|
+
* @param centerX - Center x-coordinate.
|
|
1260
|
+
* @param centerY - Center y-coordinate.
|
|
1261
|
+
* @param width - Width.
|
|
1262
|
+
* @param height - Height.
|
|
1263
|
+
* @returns - DivRect.
|
|
1264
|
+
*/
|
|
1265
|
+
static createCentered(centerX, centerY, width, height) {
|
|
1266
|
+
return new _DivRect(
|
|
1267
|
+
centerX - width / 2,
|
|
1268
|
+
centerX,
|
|
1269
|
+
centerX + width / 2,
|
|
1270
|
+
centerY - height / 2,
|
|
1271
|
+
centerY,
|
|
1272
|
+
centerY + height / 2
|
|
1273
|
+
);
|
|
1274
|
+
}
|
|
1275
|
+
/**
|
|
1276
|
+
* Create rect from sections.
|
|
1277
|
+
*
|
|
1278
|
+
* @param leftw - Left section width.
|
|
1279
|
+
* @param rightw - Right section width.
|
|
1280
|
+
* @param toph - Top section height.
|
|
1281
|
+
* @param bottomh - Bottomsection height.
|
|
1282
|
+
* @returns - DivRect.
|
|
1283
|
+
*/
|
|
1284
|
+
static createSections(leftw, rightw, toph, bottomh) {
|
|
1285
|
+
return new _DivRect(-leftw, 0, rightw, -toph, 0, bottomh);
|
|
1286
|
+
}
|
|
1287
|
+
/**
|
|
1288
|
+
* Width getter.
|
|
1289
|
+
*/
|
|
1290
|
+
get width() {
|
|
1291
|
+
return this.right - this.left;
|
|
1292
|
+
}
|
|
1293
|
+
/**
|
|
1294
|
+
* Height getter.
|
|
1295
|
+
*/
|
|
1296
|
+
get height() {
|
|
1297
|
+
return this.bottom - this.top;
|
|
1298
|
+
}
|
|
1299
|
+
/**
|
|
1300
|
+
* Left section width getter.
|
|
1301
|
+
*/
|
|
1302
|
+
get leftw() {
|
|
1303
|
+
return this.centerX - this.left;
|
|
1304
|
+
}
|
|
1305
|
+
/**
|
|
1306
|
+
* Right section width getter.
|
|
1307
|
+
*/
|
|
1308
|
+
get rightw() {
|
|
1309
|
+
return this.right - this.centerX;
|
|
1310
|
+
}
|
|
1311
|
+
/**
|
|
1312
|
+
* Top section height getter.
|
|
1313
|
+
*/
|
|
1314
|
+
get toph() {
|
|
1315
|
+
return this.centerY - this.top;
|
|
1316
|
+
}
|
|
1317
|
+
/**
|
|
1318
|
+
* Bottom section height getter.
|
|
1319
|
+
*/
|
|
1320
|
+
get bottomh() {
|
|
1321
|
+
return this.bottom - this.centerY;
|
|
1322
|
+
}
|
|
1323
|
+
/**
|
|
1324
|
+
* Does this Rect contain given (x, y)-point?
|
|
1325
|
+
*
|
|
1326
|
+
* @param x - X-coordinate.
|
|
1327
|
+
* @param y - Y-coordinate.
|
|
1328
|
+
* @returns - True/false.
|
|
1329
|
+
*/
|
|
1330
|
+
contains(x, y) {
|
|
1331
|
+
return x >= this.left && x <= this.right && y >= this.top && y <= this.bottom;
|
|
1332
|
+
}
|
|
1333
|
+
/**
|
|
1334
|
+
* Do a and b rects overlap?
|
|
1335
|
+
*
|
|
1336
|
+
* @param a - DivRect a.
|
|
1337
|
+
* @param b - DivRect b.
|
|
1338
|
+
* @returns - True/false.
|
|
1339
|
+
*/
|
|
1340
|
+
static overlap(a, b) {
|
|
1341
|
+
return a.right > b.left && a.left < b.right && a.bottom > b.top && a.top < b.bottom;
|
|
1342
|
+
}
|
|
1343
|
+
/**
|
|
1344
|
+
* Do horizontal measures of a and b rects overlap?
|
|
1345
|
+
*
|
|
1346
|
+
* @param a - DivRect a.
|
|
1347
|
+
* @param b - DivRect b.
|
|
1348
|
+
* @returns - True/false.
|
|
1349
|
+
*/
|
|
1350
|
+
static overlapX(a, b) {
|
|
1351
|
+
return a.right > b.left && a.left < b.right;
|
|
1352
|
+
}
|
|
1353
|
+
/**
|
|
1354
|
+
* Check if given rects are equal.
|
|
1355
|
+
* @param a - DivRect a.
|
|
1356
|
+
* @param b - DivRect b.
|
|
1357
|
+
* @returns - True/false.
|
|
1358
|
+
*/
|
|
1359
|
+
static equals(a, b) {
|
|
1360
|
+
if (a == null && b == null) {
|
|
1361
|
+
return true;
|
|
1362
|
+
} else if (a == null || b == null) {
|
|
1363
|
+
return false;
|
|
1364
|
+
} else {
|
|
1365
|
+
return a === b || a.left === b.left && a.centerX === b.centerX && a.right === b.right && a.top === b.top && a.centerY === b.centerY && a.bottom === b.bottom;
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
/**
|
|
1369
|
+
* Check if this rect equals with another rect.
|
|
1370
|
+
* @param other - The other rect.
|
|
1371
|
+
* @returns - True/false.
|
|
1372
|
+
*/
|
|
1373
|
+
equals(other) {
|
|
1374
|
+
return _DivRect.equals(this, other);
|
|
1375
|
+
}
|
|
1376
|
+
/**
|
|
1377
|
+
* Check if edges of given rects are equal, ignoring centerX and centerY.
|
|
1378
|
+
*
|
|
1379
|
+
* @param a - DivRect a.
|
|
1380
|
+
* @param b - DivRect b.
|
|
1381
|
+
* @returns - True/false.
|
|
1382
|
+
*/
|
|
1383
|
+
static equalsEdges(a, b) {
|
|
1384
|
+
if (a == null && b == null) {
|
|
1385
|
+
return true;
|
|
1386
|
+
} else if (a == null || b == null) {
|
|
1387
|
+
return false;
|
|
1388
|
+
} else {
|
|
1389
|
+
return a === b || a.left === b.left && a.right === b.right && a.top === b.top && a.bottom === b.bottom;
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
/**
|
|
1393
|
+
* Check if edges of this Rect equals with given Rect, ignoring centerX and centerY.
|
|
1394
|
+
*
|
|
1395
|
+
* @param other - The other DivRect.
|
|
1396
|
+
* @returns - True/false.
|
|
1397
|
+
*/
|
|
1398
|
+
equalsEdges(other) {
|
|
1399
|
+
return _DivRect.equalsEdges(this, other);
|
|
1400
|
+
}
|
|
1401
|
+
/**
|
|
1402
|
+
* Created duplicate of this Rect.
|
|
1403
|
+
*
|
|
1404
|
+
* @returns - Duplicate.
|
|
1405
|
+
*/
|
|
1406
|
+
copy() {
|
|
1407
|
+
return new _DivRect(this.left, this.centerX, this.right, this.top, this.centerY, this.bottom);
|
|
1408
|
+
}
|
|
1409
|
+
/**
|
|
1410
|
+
* Move this rect by (dx, dy). Modifies this Rect.
|
|
1411
|
+
*
|
|
1412
|
+
* @param dx - Offset amount in x-direction.
|
|
1413
|
+
* @param dy - Offset amount in y-direction.
|
|
1414
|
+
* @returns - This DivRect instance.
|
|
1415
|
+
*/
|
|
1416
|
+
offsetInPlace(dx, dy) {
|
|
1417
|
+
this.left += dx;
|
|
1418
|
+
this.centerX += dx;
|
|
1419
|
+
this.right += dx;
|
|
1420
|
+
this.top += dy;
|
|
1421
|
+
this.centerY += dy;
|
|
1422
|
+
this.bottom += dy;
|
|
1423
|
+
return this;
|
|
1424
|
+
}
|
|
1425
|
+
/**
|
|
1426
|
+
* Move this rect by (dx, dy). Immutable, returns modified copy.
|
|
1427
|
+
*
|
|
1428
|
+
* @param dx - Offset amount in x-direction.
|
|
1429
|
+
* @param dy - Offset amount in y-direction.
|
|
1430
|
+
* @returns - DivRect copy with applied offset.
|
|
1431
|
+
*/
|
|
1432
|
+
offsetCopy(dx, dy) {
|
|
1433
|
+
return this.copy().offsetInPlace(dx, dy);
|
|
1434
|
+
}
|
|
1435
|
+
/**
|
|
1436
|
+
* Expand this Rect by given Rect. Modifies this Rect.
|
|
1437
|
+
*
|
|
1438
|
+
* @param rect - DivRect to expand this instance with.
|
|
1439
|
+
* @returns - This DivRect instance.
|
|
1440
|
+
*/
|
|
1441
|
+
expandInPlace(rect) {
|
|
1442
|
+
this.left = Math.min(this.left, rect.left);
|
|
1443
|
+
this.right = Math.max(this.right, rect.right);
|
|
1444
|
+
this.top = Math.min(this.top, rect.top);
|
|
1445
|
+
this.bottom = Math.max(this.bottom, rect.bottom);
|
|
1446
|
+
return this;
|
|
1447
|
+
}
|
|
1448
|
+
/**
|
|
1449
|
+
* Expand this Rect by given Rect. Immutable, returns modified copy.
|
|
1450
|
+
*
|
|
1451
|
+
* @param rect - DivRect to expand this instance with.
|
|
1452
|
+
* @returns - Expanded copy of this DivRect.
|
|
1453
|
+
*/
|
|
1454
|
+
expandCopy(rect) {
|
|
1455
|
+
return this.copy().expandInPlace(rect);
|
|
1456
|
+
}
|
|
1457
|
+
/**
|
|
1458
|
+
* Clip this Rect by given Rect. Mmodifies this Rect.
|
|
1459
|
+
*
|
|
1460
|
+
* @param clipRect - DivRect to clip this instance with.
|
|
1461
|
+
* @returns - This DivRect instance.
|
|
1462
|
+
*/
|
|
1463
|
+
clipInPlace(clipRect) {
|
|
1464
|
+
this.left = Math.max(this.left, clipRect.left);
|
|
1465
|
+
this.right = Math.min(this.right, clipRect.right);
|
|
1466
|
+
this.centerX = clamp(this.centerX, this.left, this.right);
|
|
1467
|
+
this.top = Math.max(this.top, clipRect.top);
|
|
1468
|
+
this.bottom = Math.min(this.bottom, clipRect.bottom);
|
|
1469
|
+
this.centerY = clamp(this.centerY, this.top, this.bottom);
|
|
1470
|
+
return this;
|
|
1471
|
+
}
|
|
1472
|
+
/**
|
|
1473
|
+
* Clip this Rect by given Rect. Immutable, return modified copy.
|
|
1474
|
+
*
|
|
1475
|
+
* @param clipRect - DivRecto to clip this instance with.
|
|
1476
|
+
* @returns - Clipped DivRect copy.
|
|
1477
|
+
*/
|
|
1478
|
+
clipCopy(clipRect) {
|
|
1479
|
+
return this.copy().clipInPlace(clipRect);
|
|
1480
|
+
}
|
|
1481
|
+
/**
|
|
1482
|
+
* Scale Rect. Anchor pos is (centerX, centerY). Modifies this Rect.
|
|
1483
|
+
*
|
|
1484
|
+
* @param scaleX - Scale x-amount.
|
|
1485
|
+
* @param scaleY - Scale y-amount. If undefined then scale x-amount is used.
|
|
1486
|
+
* @returns This DivRect instance.
|
|
1487
|
+
*/
|
|
1488
|
+
scaleInPlace(scaleX, scaleY) {
|
|
1489
|
+
scaleY = scaleY ?? scaleX;
|
|
1490
|
+
this.left = this.centerX - this.leftw * scaleX;
|
|
1491
|
+
this.right = this.centerX + this.rightw * scaleX;
|
|
1492
|
+
this.top = this.centerY - this.toph * scaleY;
|
|
1493
|
+
this.bottom = this.centerY + this.bottomh * scaleY;
|
|
1494
|
+
return this;
|
|
1495
|
+
}
|
|
1496
|
+
/**
|
|
1497
|
+
* Scale Rect. Anchor pos is (centerX, centerY). Immutable, returns modified copy.
|
|
1498
|
+
*
|
|
1499
|
+
* @param scaleX - Scale x-amount.
|
|
1500
|
+
* @param scaleY - Scale y-amount. If undefined then scale x-amount is used.
|
|
1501
|
+
* @returns Scaled copy of this DivRect.
|
|
1502
|
+
*/
|
|
1503
|
+
scaleCopy(scaleX, scaleY) {
|
|
1504
|
+
return this.copy().scaleInPlace(scaleX, scaleY);
|
|
1505
|
+
}
|
|
1506
|
+
/**
|
|
1507
|
+
* Get this DivRect instance.
|
|
1508
|
+
* @returns - This DivRect instance.
|
|
1509
|
+
*/
|
|
1510
|
+
getRect() {
|
|
1511
|
+
return this;
|
|
1142
1512
|
}
|
|
1143
1513
|
};
|
|
1144
1514
|
|
|
@@ -1239,84 +1609,28 @@ var LRUCache = class {
|
|
|
1239
1609
|
}
|
|
1240
1610
|
};
|
|
1241
1611
|
|
|
1242
|
-
// src/core/small-int-cache.ts
|
|
1243
|
-
var SmallIntCache = class {
|
|
1244
|
-
// for keys < 0
|
|
1245
|
-
constructor() {
|
|
1246
|
-
__publicField(this, "pos");
|
|
1247
|
-
// for keys >= 0
|
|
1248
|
-
__publicField(this, "neg");
|
|
1249
|
-
this.pos = [];
|
|
1250
|
-
this.neg = [];
|
|
1251
|
-
}
|
|
1252
|
-
set(key, value) {
|
|
1253
|
-
if (!isInteger(key)) {
|
|
1254
|
-
throw new Error("Key must be an integer");
|
|
1255
|
-
} else if (key >= 0) {
|
|
1256
|
-
this.pos[key] = value;
|
|
1257
|
-
} else {
|
|
1258
|
-
this.neg[-key - 1] = value;
|
|
1259
|
-
}
|
|
1260
|
-
}
|
|
1261
|
-
get(key) {
|
|
1262
|
-
if (!isInteger(key)) {
|
|
1263
|
-
throw new Error("Key must be an integer");
|
|
1264
|
-
} else if (key >= 0) {
|
|
1265
|
-
return this.pos[key];
|
|
1266
|
-
} else {
|
|
1267
|
-
return this.neg[-key - 1];
|
|
1268
|
-
}
|
|
1269
|
-
}
|
|
1270
|
-
has(key) {
|
|
1271
|
-
if (!isInteger(key)) {
|
|
1272
|
-
return false;
|
|
1273
|
-
} else if (key >= 0) {
|
|
1274
|
-
return key in this.pos;
|
|
1275
|
-
} else {
|
|
1276
|
-
return -key - 1 in this.neg;
|
|
1277
|
-
}
|
|
1278
|
-
}
|
|
1279
|
-
delete(key) {
|
|
1280
|
-
if (!isInteger(key)) {
|
|
1281
|
-
return;
|
|
1282
|
-
} else if (key >= 0) {
|
|
1283
|
-
delete this.pos[key];
|
|
1284
|
-
} else {
|
|
1285
|
-
delete this.neg[-key - 1];
|
|
1286
|
-
}
|
|
1287
|
-
}
|
|
1288
|
-
clear() {
|
|
1289
|
-
this.pos = [];
|
|
1290
|
-
this.neg = [];
|
|
1291
|
-
}
|
|
1292
|
-
};
|
|
1293
|
-
|
|
1294
1612
|
// src/core/index-array.ts
|
|
1295
1613
|
var IndexArray = class _IndexArray {
|
|
1296
1614
|
constructor(entries) {
|
|
1297
|
-
|
|
1298
|
-
__publicField(this, "posEl");
|
|
1615
|
+
__publicField(this, "posVal");
|
|
1299
1616
|
__publicField(this, "hasPos");
|
|
1300
|
-
//
|
|
1301
|
-
__publicField(this, "
|
|
1617
|
+
// Number of values
|
|
1618
|
+
__publicField(this, "valCount");
|
|
1302
1619
|
if (entries instanceof _IndexArray) {
|
|
1303
|
-
this.
|
|
1620
|
+
this.posVal = entries.posVal.slice();
|
|
1304
1621
|
this.hasPos = entries.hasPos.slice();
|
|
1305
|
-
this.
|
|
1622
|
+
this.valCount = entries.valCount;
|
|
1306
1623
|
} else {
|
|
1307
|
-
this.
|
|
1624
|
+
this.posVal = [];
|
|
1308
1625
|
this.hasPos = [];
|
|
1309
|
-
this.
|
|
1626
|
+
this.valCount = 0;
|
|
1310
1627
|
if (entries) {
|
|
1311
|
-
for (const [id,
|
|
1312
|
-
this.set(id,
|
|
1628
|
+
for (const [id, value] of entries) {
|
|
1629
|
+
this.set(id, value);
|
|
1313
1630
|
}
|
|
1314
1631
|
}
|
|
1315
1632
|
}
|
|
1316
1633
|
}
|
|
1317
|
-
static toNegIndex(id) {
|
|
1318
|
-
return -id - 1;
|
|
1319
|
-
}
|
|
1320
1634
|
static validateIndex(id) {
|
|
1321
1635
|
if (!isIntegerGte(id, 0)) throw new Error(`Invalid index ${id} - must be an integer >= 0!`);
|
|
1322
1636
|
return id;
|
|
@@ -1325,7 +1639,7 @@ var IndexArray = class _IndexArray {
|
|
|
1325
1639
|
return this.hasPos.length;
|
|
1326
1640
|
}
|
|
1327
1641
|
get size() {
|
|
1328
|
-
return this.
|
|
1642
|
+
return this.valCount;
|
|
1329
1643
|
}
|
|
1330
1644
|
isEmpty() {
|
|
1331
1645
|
return this.size === 0;
|
|
@@ -1334,15 +1648,15 @@ var IndexArray = class _IndexArray {
|
|
|
1334
1648
|
_IndexArray.validateIndex(id);
|
|
1335
1649
|
return this.hasPos[id] === true;
|
|
1336
1650
|
}
|
|
1337
|
-
set(id,
|
|
1651
|
+
set(id, value) {
|
|
1338
1652
|
_IndexArray.validateIndex(id);
|
|
1339
|
-
if (this.hasPos[id] !== true) this.
|
|
1340
|
-
this.
|
|
1653
|
+
if (this.hasPos[id] !== true) this.valCount++;
|
|
1654
|
+
this.posVal[id] = value;
|
|
1341
1655
|
this.hasPos[id] = true;
|
|
1342
1656
|
}
|
|
1343
1657
|
get(id) {
|
|
1344
1658
|
_IndexArray.validateIndex(id);
|
|
1345
|
-
return this.hasPos[id] ? this.
|
|
1659
|
+
return this.hasPos[id] ? this.posVal[id] : void 0;
|
|
1346
1660
|
}
|
|
1347
1661
|
getOrDefault(id, defaultValue) {
|
|
1348
1662
|
return this.get(id) ?? defaultValue;
|
|
@@ -1358,19 +1672,19 @@ var IndexArray = class _IndexArray {
|
|
|
1358
1672
|
delete(id) {
|
|
1359
1673
|
_IndexArray.validateIndex(id);
|
|
1360
1674
|
if (!this.hasPos[id]) return false;
|
|
1361
|
-
this.
|
|
1675
|
+
this.posVal[id] = void 0;
|
|
1362
1676
|
this.hasPos[id] = false;
|
|
1363
|
-
this.
|
|
1677
|
+
this.valCount--;
|
|
1364
1678
|
return true;
|
|
1365
1679
|
}
|
|
1366
1680
|
clear() {
|
|
1367
|
-
this.
|
|
1681
|
+
this.posVal = [];
|
|
1368
1682
|
this.hasPos = [];
|
|
1369
|
-
this.
|
|
1683
|
+
this.valCount = 0;
|
|
1370
1684
|
}
|
|
1371
1685
|
forEach(callbackfn, thisArg) {
|
|
1372
|
-
for (const [id,
|
|
1373
|
-
callbackfn.call(thisArg,
|
|
1686
|
+
for (const [id, value] of this.entries()) {
|
|
1687
|
+
callbackfn.call(thisArg, value, id, this);
|
|
1374
1688
|
}
|
|
1375
1689
|
}
|
|
1376
1690
|
*indices() {
|
|
@@ -1380,12 +1694,12 @@ var IndexArray = class _IndexArray {
|
|
|
1380
1694
|
}
|
|
1381
1695
|
*values() {
|
|
1382
1696
|
for (let id = 0; id < this.posLen; id++) {
|
|
1383
|
-
if (this.hasPos[id]) yield this.
|
|
1697
|
+
if (this.hasPos[id]) yield this.posVal[id];
|
|
1384
1698
|
}
|
|
1385
1699
|
}
|
|
1386
1700
|
*entries() {
|
|
1387
1701
|
for (let id = 0; id < this.posLen; id++) {
|
|
1388
|
-
if (this.hasPos[id]) yield [id, this.
|
|
1702
|
+
if (this.hasPos[id]) yield [id, this.posVal[id]];
|
|
1389
1703
|
}
|
|
1390
1704
|
}
|
|
1391
1705
|
indicesArray() {
|
|
@@ -1403,13 +1717,13 @@ var IndexArray = class _IndexArray {
|
|
|
1403
1717
|
}
|
|
1404
1718
|
}
|
|
1405
1719
|
*kvValues() {
|
|
1406
|
-
for (const
|
|
1407
|
-
yield
|
|
1720
|
+
for (const value of this.values()) {
|
|
1721
|
+
yield value;
|
|
1408
1722
|
}
|
|
1409
1723
|
}
|
|
1410
1724
|
*kvEntries() {
|
|
1411
|
-
for (const [id,
|
|
1412
|
-
yield [[id],
|
|
1725
|
+
for (const [id, value] of this.entries()) {
|
|
1726
|
+
yield [[id], value];
|
|
1413
1727
|
}
|
|
1414
1728
|
}
|
|
1415
1729
|
*[Symbol.iterator]() {
|
|
@@ -1429,21 +1743,21 @@ var IndexArray = class _IndexArray {
|
|
|
1429
1743
|
return this;
|
|
1430
1744
|
}
|
|
1431
1745
|
some(fn) {
|
|
1432
|
-
for (const [id,
|
|
1433
|
-
if (fn(
|
|
1746
|
+
for (const [id, value] of this.entries()) {
|
|
1747
|
+
if (fn(value, id)) return true;
|
|
1434
1748
|
}
|
|
1435
1749
|
return false;
|
|
1436
1750
|
}
|
|
1437
1751
|
every(fn) {
|
|
1438
|
-
for (const [id,
|
|
1439
|
-
if (!fn(
|
|
1752
|
+
for (const [id, value] of this.entries()) {
|
|
1753
|
+
if (!fn(value, id)) return false;
|
|
1440
1754
|
}
|
|
1441
1755
|
return true;
|
|
1442
1756
|
}
|
|
1443
|
-
filter(
|
|
1444
|
-
|
|
1445
|
-
for (const [id,
|
|
1446
|
-
if (
|
|
1757
|
+
filter(predicate) {
|
|
1758
|
+
const result = new this.constructor();
|
|
1759
|
+
for (const [id, value] of this.entries()) {
|
|
1760
|
+
if (predicate(value, id, this)) result.set(id, value);
|
|
1447
1761
|
}
|
|
1448
1762
|
return result;
|
|
1449
1763
|
}
|
|
@@ -1466,22 +1780,22 @@ var IndexArray = class _IndexArray {
|
|
|
1466
1780
|
start = first;
|
|
1467
1781
|
}
|
|
1468
1782
|
for (let current = start; !current.done; current = iterator.next()) {
|
|
1469
|
-
const [id,
|
|
1470
|
-
acc = fn(acc,
|
|
1783
|
+
const [id, value] = current.value;
|
|
1784
|
+
acc = fn(acc, value, id);
|
|
1471
1785
|
}
|
|
1472
1786
|
return acc;
|
|
1473
1787
|
}
|
|
1474
1788
|
mapToArray(fn) {
|
|
1475
1789
|
let result = [];
|
|
1476
|
-
for (const [id,
|
|
1477
|
-
result.push(fn(
|
|
1790
|
+
for (const [id, value] of this.entries()) {
|
|
1791
|
+
result.push(fn(value, id));
|
|
1478
1792
|
}
|
|
1479
1793
|
return result;
|
|
1480
1794
|
}
|
|
1481
1795
|
map(fn) {
|
|
1482
1796
|
let result = new _IndexArray();
|
|
1483
|
-
for (const [id,
|
|
1484
|
-
result.set(id, fn(
|
|
1797
|
+
for (const [id, value] of this.entries()) {
|
|
1798
|
+
result.set(id, fn(value, id));
|
|
1485
1799
|
}
|
|
1486
1800
|
return result;
|
|
1487
1801
|
}
|
|
@@ -1493,13 +1807,13 @@ var IndexArray = class _IndexArray {
|
|
|
1493
1807
|
const hasA = this.hasPos[i];
|
|
1494
1808
|
const hasB = other.hasPos[i];
|
|
1495
1809
|
if (hasA !== hasB) return false;
|
|
1496
|
-
if (hasA && !eq(this.
|
|
1810
|
+
if (hasA && !eq(this.posVal[i], other.posVal[i])) return false;
|
|
1497
1811
|
}
|
|
1498
1812
|
return true;
|
|
1499
1813
|
}
|
|
1500
1814
|
toString() {
|
|
1501
1815
|
if (this.size === 0) return `IndexArray[ ]`;
|
|
1502
|
-
const entries = this.entriesArray().map(([id,
|
|
1816
|
+
const entries = this.entriesArray().map(([id, value]) => `${id}: ${value}`).join(", ");
|
|
1503
1817
|
return `IndexArray[ ${entries} ]`;
|
|
1504
1818
|
}
|
|
1505
1819
|
};
|
|
@@ -1507,29 +1821,29 @@ var IndexArray = class _IndexArray {
|
|
|
1507
1821
|
// src/core/signed-index-array.ts
|
|
1508
1822
|
var SignedIndexArray = class _SignedIndexArray {
|
|
1509
1823
|
constructor(entries) {
|
|
1510
|
-
//
|
|
1511
|
-
__publicField(this, "
|
|
1824
|
+
// For indexes >= 0
|
|
1825
|
+
__publicField(this, "posVal");
|
|
1512
1826
|
__publicField(this, "hasPos");
|
|
1513
|
-
//
|
|
1514
|
-
__publicField(this, "
|
|
1827
|
+
// For indexes < 0
|
|
1828
|
+
__publicField(this, "negVal");
|
|
1515
1829
|
__publicField(this, "hasNeg");
|
|
1516
|
-
//
|
|
1517
|
-
__publicField(this, "
|
|
1830
|
+
// Number of values
|
|
1831
|
+
__publicField(this, "valCount");
|
|
1518
1832
|
if (entries instanceof _SignedIndexArray) {
|
|
1519
|
-
this.
|
|
1833
|
+
this.negVal = entries.negVal.slice();
|
|
1520
1834
|
this.hasNeg = entries.hasNeg.slice();
|
|
1521
|
-
this.
|
|
1835
|
+
this.posVal = entries.posVal.slice();
|
|
1522
1836
|
this.hasPos = entries.hasPos.slice();
|
|
1523
|
-
this.
|
|
1837
|
+
this.valCount = entries.valCount;
|
|
1524
1838
|
} else {
|
|
1525
|
-
this.
|
|
1839
|
+
this.negVal = [];
|
|
1526
1840
|
this.hasNeg = [];
|
|
1527
|
-
this.
|
|
1841
|
+
this.posVal = [];
|
|
1528
1842
|
this.hasPos = [];
|
|
1529
|
-
this.
|
|
1843
|
+
this.valCount = 0;
|
|
1530
1844
|
if (entries) {
|
|
1531
|
-
for (const [id,
|
|
1532
|
-
this.set(id,
|
|
1845
|
+
for (const [id, value] of entries) {
|
|
1846
|
+
this.set(id, value);
|
|
1533
1847
|
}
|
|
1534
1848
|
}
|
|
1535
1849
|
}
|
|
@@ -1542,7 +1856,7 @@ var SignedIndexArray = class _SignedIndexArray {
|
|
|
1542
1856
|
return id;
|
|
1543
1857
|
}
|
|
1544
1858
|
get size() {
|
|
1545
|
-
return this.
|
|
1859
|
+
return this.valCount;
|
|
1546
1860
|
}
|
|
1547
1861
|
isEmpty() {
|
|
1548
1862
|
return this.size === 0;
|
|
@@ -1561,26 +1875,26 @@ var SignedIndexArray = class _SignedIndexArray {
|
|
|
1561
1875
|
return this.hasNeg[_SignedIndexArray.toNegIndex(id)] === true;
|
|
1562
1876
|
}
|
|
1563
1877
|
}
|
|
1564
|
-
set(id,
|
|
1878
|
+
set(id, value) {
|
|
1565
1879
|
_SignedIndexArray.validateIndex(id);
|
|
1566
1880
|
if (id >= 0) {
|
|
1567
|
-
if (this.hasPos[id] !== true) this.
|
|
1568
|
-
this.
|
|
1881
|
+
if (this.hasPos[id] !== true) this.valCount++;
|
|
1882
|
+
this.posVal[id] = value;
|
|
1569
1883
|
this.hasPos[id] = true;
|
|
1570
1884
|
} else {
|
|
1571
1885
|
let negId = _SignedIndexArray.toNegIndex(id);
|
|
1572
|
-
if (this.hasNeg[negId] !== true) this.
|
|
1573
|
-
this.
|
|
1886
|
+
if (this.hasNeg[negId] !== true) this.valCount++;
|
|
1887
|
+
this.negVal[negId] = value;
|
|
1574
1888
|
this.hasNeg[negId] = true;
|
|
1575
1889
|
}
|
|
1576
1890
|
}
|
|
1577
1891
|
get(id) {
|
|
1578
1892
|
_SignedIndexArray.validateIndex(id);
|
|
1579
1893
|
if (id >= 0) {
|
|
1580
|
-
return this.hasPos[id] ? this.
|
|
1894
|
+
return this.hasPos[id] ? this.posVal[id] : void 0;
|
|
1581
1895
|
} else {
|
|
1582
1896
|
let negId = _SignedIndexArray.toNegIndex(id);
|
|
1583
|
-
return this.hasNeg[negId] ? this.
|
|
1897
|
+
return this.hasNeg[negId] ? this.negVal[negId] : void 0;
|
|
1584
1898
|
}
|
|
1585
1899
|
}
|
|
1586
1900
|
getOrDefault(id, defaultValue) {
|
|
@@ -1597,25 +1911,25 @@ var SignedIndexArray = class _SignedIndexArray {
|
|
|
1597
1911
|
delete(id) {
|
|
1598
1912
|
_SignedIndexArray.validateIndex(id);
|
|
1599
1913
|
const isPos = id >= 0;
|
|
1600
|
-
const arr = isPos ? this.
|
|
1914
|
+
const arr = isPos ? this.posVal : this.negVal;
|
|
1601
1915
|
const has = isPos ? this.hasPos : this.hasNeg;
|
|
1602
1916
|
const idx = isPos ? id : _SignedIndexArray.toNegIndex(id);
|
|
1603
1917
|
if (!has[idx]) return false;
|
|
1604
1918
|
arr[idx] = void 0;
|
|
1605
1919
|
has[idx] = false;
|
|
1606
|
-
this.
|
|
1920
|
+
this.valCount--;
|
|
1607
1921
|
return true;
|
|
1608
1922
|
}
|
|
1609
1923
|
clear() {
|
|
1610
|
-
this.
|
|
1924
|
+
this.negVal = [];
|
|
1611
1925
|
this.hasNeg = [];
|
|
1612
|
-
this.
|
|
1926
|
+
this.posVal = [];
|
|
1613
1927
|
this.hasPos = [];
|
|
1614
|
-
this.
|
|
1928
|
+
this.valCount = 0;
|
|
1615
1929
|
}
|
|
1616
1930
|
forEach(callbackfn, thisArg) {
|
|
1617
|
-
for (const [id,
|
|
1618
|
-
callbackfn.call(thisArg,
|
|
1931
|
+
for (const [id, value] of this.entries()) {
|
|
1932
|
+
callbackfn.call(thisArg, value, id, this);
|
|
1619
1933
|
}
|
|
1620
1934
|
}
|
|
1621
1935
|
*indices() {
|
|
@@ -1628,18 +1942,18 @@ var SignedIndexArray = class _SignedIndexArray {
|
|
|
1628
1942
|
}
|
|
1629
1943
|
*values() {
|
|
1630
1944
|
for (let id = this.negLen - 1; id >= 0; id--) {
|
|
1631
|
-
if (this.hasNeg[id]) yield this.
|
|
1945
|
+
if (this.hasNeg[id]) yield this.negVal[id];
|
|
1632
1946
|
}
|
|
1633
1947
|
for (let id = 0; id < this.posLen; id++) {
|
|
1634
|
-
if (this.hasPos[id]) yield this.
|
|
1948
|
+
if (this.hasPos[id]) yield this.posVal[id];
|
|
1635
1949
|
}
|
|
1636
1950
|
}
|
|
1637
1951
|
*entries() {
|
|
1638
1952
|
for (let id = this.negLen - 1; id >= 0; id--) {
|
|
1639
|
-
if (this.hasNeg[id]) yield [_SignedIndexArray.toNegIndex(id), this.
|
|
1953
|
+
if (this.hasNeg[id]) yield [_SignedIndexArray.toNegIndex(id), this.negVal[id]];
|
|
1640
1954
|
}
|
|
1641
1955
|
for (let id = 0; id < this.posLen; id++) {
|
|
1642
|
-
if (this.hasPos[id]) yield [id, this.
|
|
1956
|
+
if (this.hasPos[id]) yield [id, this.posVal[id]];
|
|
1643
1957
|
}
|
|
1644
1958
|
}
|
|
1645
1959
|
indicesArray() {
|
|
@@ -1657,13 +1971,13 @@ var SignedIndexArray = class _SignedIndexArray {
|
|
|
1657
1971
|
}
|
|
1658
1972
|
}
|
|
1659
1973
|
*kvValues() {
|
|
1660
|
-
for (const
|
|
1661
|
-
yield
|
|
1974
|
+
for (const value of this.values()) {
|
|
1975
|
+
yield value;
|
|
1662
1976
|
}
|
|
1663
1977
|
}
|
|
1664
1978
|
*kvEntries() {
|
|
1665
|
-
for (const [id,
|
|
1666
|
-
yield [[id],
|
|
1979
|
+
for (const [id, value] of this.entries()) {
|
|
1980
|
+
yield [[id], value];
|
|
1667
1981
|
}
|
|
1668
1982
|
}
|
|
1669
1983
|
*[Symbol.iterator]() {
|
|
@@ -1683,21 +1997,21 @@ var SignedIndexArray = class _SignedIndexArray {
|
|
|
1683
1997
|
return this;
|
|
1684
1998
|
}
|
|
1685
1999
|
some(fn) {
|
|
1686
|
-
for (const [id,
|
|
1687
|
-
if (fn(
|
|
2000
|
+
for (const [id, value] of this.entries()) {
|
|
2001
|
+
if (fn(value, id)) return true;
|
|
1688
2002
|
}
|
|
1689
2003
|
return false;
|
|
1690
2004
|
}
|
|
1691
2005
|
every(fn) {
|
|
1692
|
-
for (const [id,
|
|
1693
|
-
if (!fn(
|
|
2006
|
+
for (const [id, value] of this.entries()) {
|
|
2007
|
+
if (!fn(value, id)) return false;
|
|
1694
2008
|
}
|
|
1695
2009
|
return true;
|
|
1696
2010
|
}
|
|
1697
|
-
filter(
|
|
1698
|
-
|
|
1699
|
-
for (const [id,
|
|
1700
|
-
if (
|
|
2011
|
+
filter(predicate) {
|
|
2012
|
+
const result = new this.constructor();
|
|
2013
|
+
for (const [id, value] of this.entries()) {
|
|
2014
|
+
if (predicate(value, id, this)) result.set(id, value);
|
|
1701
2015
|
}
|
|
1702
2016
|
return result;
|
|
1703
2017
|
}
|
|
@@ -1720,22 +2034,22 @@ var SignedIndexArray = class _SignedIndexArray {
|
|
|
1720
2034
|
start = first;
|
|
1721
2035
|
}
|
|
1722
2036
|
for (let current = start; !current.done; current = iterator.next()) {
|
|
1723
|
-
const [id,
|
|
1724
|
-
acc = fn(acc,
|
|
2037
|
+
const [id, value] = current.value;
|
|
2038
|
+
acc = fn(acc, value, id);
|
|
1725
2039
|
}
|
|
1726
2040
|
return acc;
|
|
1727
2041
|
}
|
|
1728
2042
|
mapToArray(fn) {
|
|
1729
2043
|
let result = [];
|
|
1730
|
-
for (const [id,
|
|
1731
|
-
result.push(fn(
|
|
2044
|
+
for (const [id, value] of this.entries()) {
|
|
2045
|
+
result.push(fn(value, id));
|
|
1732
2046
|
}
|
|
1733
2047
|
return result;
|
|
1734
2048
|
}
|
|
1735
2049
|
map(fn) {
|
|
1736
2050
|
let result = new _SignedIndexArray();
|
|
1737
|
-
for (const [id,
|
|
1738
|
-
result.set(id, fn(
|
|
2051
|
+
for (const [id, value] of this.entries()) {
|
|
2052
|
+
result.set(id, fn(value, id));
|
|
1739
2053
|
}
|
|
1740
2054
|
return result;
|
|
1741
2055
|
}
|
|
@@ -1747,25 +2061,25 @@ var SignedIndexArray = class _SignedIndexArray {
|
|
|
1747
2061
|
const hasA = this.hasPos[i];
|
|
1748
2062
|
const hasB = other.hasPos[i];
|
|
1749
2063
|
if (hasA !== hasB) return false;
|
|
1750
|
-
if (hasA && !eq(this.
|
|
2064
|
+
if (hasA && !eq(this.posVal[i], other.posVal[i])) return false;
|
|
1751
2065
|
}
|
|
1752
2066
|
const negLen = Math.max(this.negLen, other.negLen);
|
|
1753
2067
|
for (let i = 0; i < negLen; ++i) {
|
|
1754
2068
|
const hasA = this.hasNeg[i];
|
|
1755
2069
|
const hasB = other.hasNeg[i];
|
|
1756
2070
|
if (hasA !== hasB) return false;
|
|
1757
|
-
if (hasA && !eq(this.
|
|
2071
|
+
if (hasA && !eq(this.negVal[i], other.negVal[i])) return false;
|
|
1758
2072
|
}
|
|
1759
2073
|
return true;
|
|
1760
2074
|
}
|
|
1761
2075
|
toString() {
|
|
1762
2076
|
if (this.size === 0) return `SignedIndexArray[ ]`;
|
|
1763
|
-
const entries = this.entriesArray().map(([id,
|
|
2077
|
+
const entries = this.entriesArray().map(([id, value]) => `${id}: ${value}`).join(", ");
|
|
1764
2078
|
return `SignedIndexArray[ ${entries} ]`;
|
|
1765
2079
|
}
|
|
1766
2080
|
};
|
|
1767
2081
|
|
|
1768
|
-
// src/core/
|
|
2082
|
+
// src/core/map1.ts
|
|
1769
2083
|
var Map1 = class _Map1 {
|
|
1770
2084
|
constructor(entries) {
|
|
1771
2085
|
__publicField(this, "map1");
|
|
@@ -1869,16 +2183,33 @@ var Map1 = class _Map1 {
|
|
|
1869
2183
|
}
|
|
1870
2184
|
return true;
|
|
1871
2185
|
}
|
|
1872
|
-
filter(
|
|
1873
|
-
|
|
2186
|
+
filter(predicate) {
|
|
2187
|
+
const result = new this.constructor();
|
|
1874
2188
|
for (const [key1, value] of this.map1) {
|
|
1875
|
-
if (
|
|
2189
|
+
if (predicate(value, key1, this)) result.set(key1, value);
|
|
1876
2190
|
}
|
|
1877
2191
|
return result;
|
|
1878
2192
|
}
|
|
1879
2193
|
reduce(fn, init) {
|
|
1880
|
-
let
|
|
1881
|
-
|
|
2194
|
+
let iterator = this.entries();
|
|
2195
|
+
let first = iterator.next();
|
|
2196
|
+
if (first.done) {
|
|
2197
|
+
if (arguments.length < 2) {
|
|
2198
|
+
throw new TypeError("Reduce of empty Map1 with no initial value!");
|
|
2199
|
+
}
|
|
2200
|
+
return init;
|
|
2201
|
+
}
|
|
2202
|
+
let acc;
|
|
2203
|
+
let start;
|
|
2204
|
+
if (arguments.length < 2) {
|
|
2205
|
+
acc = first.value[1];
|
|
2206
|
+
start = iterator.next();
|
|
2207
|
+
} else {
|
|
2208
|
+
acc = init;
|
|
2209
|
+
start = first;
|
|
2210
|
+
}
|
|
2211
|
+
for (let current = start; !current.done; current = iterator.next()) {
|
|
2212
|
+
const [key1, value] = current.value;
|
|
1882
2213
|
acc = fn(acc, value, key1);
|
|
1883
2214
|
}
|
|
1884
2215
|
return acc;
|
|
@@ -1902,9 +2233,11 @@ var Map1 = class _Map1 {
|
|
|
1902
2233
|
}
|
|
1903
2234
|
toString() {
|
|
1904
2235
|
const entries = [...this.map1].map(([k, v]) => `${k} => ${v}`).join(", ");
|
|
1905
|
-
return `Map1(${this.
|
|
2236
|
+
return entries.length === 0 ? `Map1(0){ }` : `Map1(${this.size}){ ${entries} }`;
|
|
1906
2237
|
}
|
|
1907
2238
|
};
|
|
2239
|
+
|
|
2240
|
+
// src/core/map2.ts
|
|
1908
2241
|
var Map2 = class _Map2 {
|
|
1909
2242
|
constructor(entries) {
|
|
1910
2243
|
__publicField(this, "map1", /* @__PURE__ */ new Map());
|
|
@@ -2030,21 +2363,36 @@ var Map2 = class _Map2 {
|
|
|
2030
2363
|
}
|
|
2031
2364
|
return true;
|
|
2032
2365
|
}
|
|
2033
|
-
filter(
|
|
2034
|
-
|
|
2366
|
+
filter(predicate) {
|
|
2367
|
+
const result = new this.constructor();
|
|
2035
2368
|
for (const [key1, map2] of this.map1) {
|
|
2036
2369
|
for (const [key2, value] of map2) {
|
|
2037
|
-
if (
|
|
2370
|
+
if (predicate(value, key1, key2, this)) result.set(key1, key2, value);
|
|
2038
2371
|
}
|
|
2039
2372
|
}
|
|
2040
2373
|
return result;
|
|
2041
2374
|
}
|
|
2042
2375
|
reduce(fn, init) {
|
|
2043
|
-
let
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2376
|
+
let iterator = this.entries();
|
|
2377
|
+
let first = iterator.next();
|
|
2378
|
+
if (first.done) {
|
|
2379
|
+
if (arguments.length < 2) {
|
|
2380
|
+
throw new TypeError("Reduce of empty Map2 with no initial value!");
|
|
2047
2381
|
}
|
|
2382
|
+
return init;
|
|
2383
|
+
}
|
|
2384
|
+
let acc;
|
|
2385
|
+
let start;
|
|
2386
|
+
if (arguments.length < 2) {
|
|
2387
|
+
acc = first.value[2];
|
|
2388
|
+
start = iterator.next();
|
|
2389
|
+
} else {
|
|
2390
|
+
acc = init;
|
|
2391
|
+
start = first;
|
|
2392
|
+
}
|
|
2393
|
+
for (let current = start; !current.done; current = iterator.next()) {
|
|
2394
|
+
const [key1, key2, value] = current.value;
|
|
2395
|
+
acc = fn(acc, value, key1, key2);
|
|
2048
2396
|
}
|
|
2049
2397
|
return acc;
|
|
2050
2398
|
}
|
|
@@ -2081,9 +2429,11 @@ var Map2 = class _Map2 {
|
|
|
2081
2429
|
const inner = [...map2].map(([key2, v]) => `${key2} => ${v}`).join(", ");
|
|
2082
2430
|
entries.push(`${key1} => { ${inner} }`);
|
|
2083
2431
|
}
|
|
2084
|
-
return `Map2(${this.size})
|
|
2432
|
+
return entries.length === 0 ? `Map2(0){ }` : `Map2(${this.size}){ ${entries} }`;
|
|
2085
2433
|
}
|
|
2086
2434
|
};
|
|
2435
|
+
|
|
2436
|
+
// src/core/map3.ts
|
|
2087
2437
|
var Map3 = class _Map3 {
|
|
2088
2438
|
constructor(entries) {
|
|
2089
2439
|
__publicField(this, "map1", /* @__PURE__ */ new Map());
|
|
@@ -2232,25 +2582,38 @@ var Map3 = class _Map3 {
|
|
|
2232
2582
|
}
|
|
2233
2583
|
return true;
|
|
2234
2584
|
}
|
|
2235
|
-
filter(
|
|
2236
|
-
|
|
2585
|
+
filter(predicate) {
|
|
2586
|
+
const result = new this.constructor();
|
|
2237
2587
|
for (const [key1, map2] of this.map1) {
|
|
2238
2588
|
for (const [key2, map3] of map2) {
|
|
2239
2589
|
for (const [key3, value] of map3) {
|
|
2240
|
-
if (
|
|
2590
|
+
if (predicate(value, key1, key2, key3, this)) result.set(key1, key2, key3, value);
|
|
2241
2591
|
}
|
|
2242
2592
|
}
|
|
2243
2593
|
}
|
|
2244
2594
|
return result;
|
|
2245
2595
|
}
|
|
2246
2596
|
reduce(fn, init) {
|
|
2247
|
-
let
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
}
|
|
2597
|
+
let iterator = this.entries();
|
|
2598
|
+
let first = iterator.next();
|
|
2599
|
+
if (first.done) {
|
|
2600
|
+
if (arguments.length < 2) {
|
|
2601
|
+
throw new TypeError("Reduce of empty Map3 with no initial value!");
|
|
2253
2602
|
}
|
|
2603
|
+
return init;
|
|
2604
|
+
}
|
|
2605
|
+
let acc;
|
|
2606
|
+
let start;
|
|
2607
|
+
if (arguments.length < 2) {
|
|
2608
|
+
acc = first.value[3];
|
|
2609
|
+
start = iterator.next();
|
|
2610
|
+
} else {
|
|
2611
|
+
acc = init;
|
|
2612
|
+
start = first;
|
|
2613
|
+
}
|
|
2614
|
+
for (let current = start; !current.done; current = iterator.next()) {
|
|
2615
|
+
const [key1, key2, key3, value] = current.value;
|
|
2616
|
+
acc = fn(acc, value, key1, key2, key3);
|
|
2254
2617
|
}
|
|
2255
2618
|
return acc;
|
|
2256
2619
|
}
|
|
@@ -2295,7 +2658,7 @@ var Map3 = class _Map3 {
|
|
|
2295
2658
|
entries.push(`${key1} => ${key2} => { ${inner} }`);
|
|
2296
2659
|
}
|
|
2297
2660
|
}
|
|
2298
|
-
return `Map3(${this.size})
|
|
2661
|
+
return entries.length === 0 ? `Map3(0){ }` : `Map3(${this.size}){ ${entries.join(", ")} }`;
|
|
2299
2662
|
}
|
|
2300
2663
|
};
|
|
2301
2664
|
|
|
@@ -2367,11 +2730,89 @@ var MultiContainer = class {
|
|
|
2367
2730
|
function asMulti(base) {
|
|
2368
2731
|
return new MultiContainer(base);
|
|
2369
2732
|
}
|
|
2733
|
+
|
|
2734
|
+
// src/core/deprecated/vec2.ts
|
|
2735
|
+
var Vec2 = class _Vec2 {
|
|
2736
|
+
constructor(x, y) {
|
|
2737
|
+
__publicField(this, "x");
|
|
2738
|
+
__publicField(this, "y");
|
|
2739
|
+
this.x = x ?? 0;
|
|
2740
|
+
this.y = y ?? 0;
|
|
2741
|
+
}
|
|
2742
|
+
length() {
|
|
2743
|
+
return Math.sqrt(this.x * this.x + this.y * this.y);
|
|
2744
|
+
}
|
|
2745
|
+
add(a) {
|
|
2746
|
+
return new _Vec2(this.x + a.x, this.y + a.y);
|
|
2747
|
+
}
|
|
2748
|
+
sub(a) {
|
|
2749
|
+
return new _Vec2(this.x - a.x, this.y - a.y);
|
|
2750
|
+
}
|
|
2751
|
+
mul(a) {
|
|
2752
|
+
return new _Vec2(this.x * a, this.y * a);
|
|
2753
|
+
}
|
|
2754
|
+
div(a) {
|
|
2755
|
+
return new _Vec2(this.x / a, this.y / a);
|
|
2756
|
+
}
|
|
2757
|
+
};
|
|
2758
|
+
|
|
2759
|
+
// src/core/deprecated/small-int-cache.ts
|
|
2760
|
+
var SmallIntCache = class {
|
|
2761
|
+
// for keys < 0
|
|
2762
|
+
constructor() {
|
|
2763
|
+
__publicField(this, "pos");
|
|
2764
|
+
// for keys >= 0
|
|
2765
|
+
__publicField(this, "neg");
|
|
2766
|
+
this.pos = [];
|
|
2767
|
+
this.neg = [];
|
|
2768
|
+
}
|
|
2769
|
+
set(key, value) {
|
|
2770
|
+
if (!isInteger(key)) {
|
|
2771
|
+
throw new Error("Key must be an integer");
|
|
2772
|
+
} else if (key >= 0) {
|
|
2773
|
+
this.pos[key] = value;
|
|
2774
|
+
} else {
|
|
2775
|
+
this.neg[-key - 1] = value;
|
|
2776
|
+
}
|
|
2777
|
+
}
|
|
2778
|
+
get(key) {
|
|
2779
|
+
if (!isInteger(key)) {
|
|
2780
|
+
throw new Error("Key must be an integer");
|
|
2781
|
+
} else if (key >= 0) {
|
|
2782
|
+
return this.pos[key];
|
|
2783
|
+
} else {
|
|
2784
|
+
return this.neg[-key - 1];
|
|
2785
|
+
}
|
|
2786
|
+
}
|
|
2787
|
+
has(key) {
|
|
2788
|
+
if (!isInteger(key)) {
|
|
2789
|
+
return false;
|
|
2790
|
+
} else if (key >= 0) {
|
|
2791
|
+
return key in this.pos;
|
|
2792
|
+
} else {
|
|
2793
|
+
return -key - 1 in this.neg;
|
|
2794
|
+
}
|
|
2795
|
+
}
|
|
2796
|
+
delete(key) {
|
|
2797
|
+
if (!isInteger(key)) {
|
|
2798
|
+
return;
|
|
2799
|
+
} else if (key >= 0) {
|
|
2800
|
+
delete this.pos[key];
|
|
2801
|
+
} else {
|
|
2802
|
+
delete this.neg[-key - 1];
|
|
2803
|
+
}
|
|
2804
|
+
}
|
|
2805
|
+
clear() {
|
|
2806
|
+
this.pos = [];
|
|
2807
|
+
this.neg = [];
|
|
2808
|
+
}
|
|
2809
|
+
};
|
|
2370
2810
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2371
2811
|
0 && (module.exports = {
|
|
2372
2812
|
Assert,
|
|
2373
2813
|
Cookies,
|
|
2374
2814
|
Device,
|
|
2815
|
+
DivRect,
|
|
2375
2816
|
IndexArray,
|
|
2376
2817
|
LRUCache,
|
|
2377
2818
|
Map1,
|
|
@@ -2382,6 +2823,7 @@ function asMulti(base) {
|
|
|
2382
2823
|
SmallIntCache,
|
|
2383
2824
|
Stack,
|
|
2384
2825
|
Utils,
|
|
2826
|
+
Vec,
|
|
2385
2827
|
Vec2,
|
|
2386
2828
|
asMulti
|
|
2387
2829
|
});
|