@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.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* TsUtilsLib v1.
|
|
1
|
+
/* TsUtilsLib v1.17.0 | (c) 2023 PahkaSoft | Licensed under the MIT License */
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
4
|
var __export = (target, all) => {
|
|
@@ -1083,28 +1083,396 @@ var Stack = class {
|
|
|
1083
1083
|
}
|
|
1084
1084
|
};
|
|
1085
1085
|
|
|
1086
|
-
// src/core/
|
|
1087
|
-
var
|
|
1088
|
-
constructor(
|
|
1089
|
-
__publicField(this, "
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1086
|
+
// src/core/vec.ts
|
|
1087
|
+
var Vec = class _Vec {
|
|
1088
|
+
constructor(...coords) {
|
|
1089
|
+
__publicField(this, "coords");
|
|
1090
|
+
if (coords.length < 2) {
|
|
1091
|
+
throw new TypeError("Vec needs minumum two coords!");
|
|
1092
|
+
}
|
|
1093
|
+
this.coords = coords;
|
|
1093
1094
|
}
|
|
1094
|
-
|
|
1095
|
-
return
|
|
1095
|
+
static vec2(x, y) {
|
|
1096
|
+
return new _Vec(x, y);
|
|
1096
1097
|
}
|
|
1097
|
-
|
|
1098
|
-
return new
|
|
1098
|
+
static vec3(x, y, z) {
|
|
1099
|
+
return new _Vec(x, y, z);
|
|
1099
1100
|
}
|
|
1100
|
-
|
|
1101
|
-
|
|
1101
|
+
static zero(dim) {
|
|
1102
|
+
if (dim < 2) {
|
|
1103
|
+
throw new TypeError("Vec.zero requires dimension >= 2");
|
|
1104
|
+
}
|
|
1105
|
+
return new _Vec(...Array(dim).fill(0));
|
|
1102
1106
|
}
|
|
1103
|
-
|
|
1104
|
-
return
|
|
1107
|
+
get length() {
|
|
1108
|
+
return Math.hypot(...this.coords);
|
|
1105
1109
|
}
|
|
1106
|
-
|
|
1107
|
-
return
|
|
1110
|
+
get x() {
|
|
1111
|
+
return this.coords[0];
|
|
1112
|
+
}
|
|
1113
|
+
get y() {
|
|
1114
|
+
return this.coords[1];
|
|
1115
|
+
}
|
|
1116
|
+
get z() {
|
|
1117
|
+
if (this.coords[2] === void 0) {
|
|
1118
|
+
throw new TypeError("Vec z-coord not available!");
|
|
1119
|
+
}
|
|
1120
|
+
return this.coords[2];
|
|
1121
|
+
}
|
|
1122
|
+
add(...args) {
|
|
1123
|
+
const otherCoords = args[0] instanceof _Vec ? args[0].coords : args;
|
|
1124
|
+
if (this.coords.length !== otherCoords.length) {
|
|
1125
|
+
throw new TypeError("Coordinate length mismatch!");
|
|
1126
|
+
}
|
|
1127
|
+
return new _Vec(...this.coords.map((coord, i) => coord + otherCoords[i]));
|
|
1128
|
+
}
|
|
1129
|
+
sub(...args) {
|
|
1130
|
+
const otherCoords = args[0] instanceof _Vec ? args[0].coords : args;
|
|
1131
|
+
if (this.coords.length !== otherCoords.length) {
|
|
1132
|
+
throw new TypeError("Coordinate length mismatch!");
|
|
1133
|
+
}
|
|
1134
|
+
return new _Vec(...this.coords.map((coord, i) => coord - otherCoords[i]));
|
|
1135
|
+
}
|
|
1136
|
+
mul(scalar) {
|
|
1137
|
+
return new _Vec(...this.coords.map((coord) => coord * scalar));
|
|
1138
|
+
}
|
|
1139
|
+
div(scalar) {
|
|
1140
|
+
return new _Vec(...this.coords.map((coord) => coord / scalar));
|
|
1141
|
+
}
|
|
1142
|
+
dot(other) {
|
|
1143
|
+
if (this.coords.length !== other.coords.length) {
|
|
1144
|
+
throw new TypeError("Coordinate length mismatch!");
|
|
1145
|
+
}
|
|
1146
|
+
return this.coords.reduce((sum2, c, i) => sum2 + c * other.coords[i], 0);
|
|
1147
|
+
}
|
|
1148
|
+
distance(other) {
|
|
1149
|
+
if (this.coords.length !== other.coords.length) {
|
|
1150
|
+
throw new TypeError("Coordinate length mismatch!");
|
|
1151
|
+
}
|
|
1152
|
+
return Math.hypot(...this.coords.map((c, i) => c - other.coords[i]));
|
|
1153
|
+
}
|
|
1154
|
+
normalize() {
|
|
1155
|
+
const len = this.length;
|
|
1156
|
+
if (len === 0) {
|
|
1157
|
+
throw new TypeError("Cannot normalize zero-length vector!");
|
|
1158
|
+
}
|
|
1159
|
+
return this.div(len);
|
|
1160
|
+
}
|
|
1161
|
+
equals(other) {
|
|
1162
|
+
return this.coords.length === other.coords.length && this.coords.every((v, i) => v === other.coords[i]);
|
|
1163
|
+
}
|
|
1164
|
+
clone() {
|
|
1165
|
+
return new _Vec(...this.coords);
|
|
1166
|
+
}
|
|
1167
|
+
toObject() {
|
|
1168
|
+
return { x: this.x, y: this.y, z: this.z };
|
|
1169
|
+
}
|
|
1170
|
+
[Symbol.iterator]() {
|
|
1171
|
+
return this.coords[Symbol.iterator]();
|
|
1172
|
+
}
|
|
1173
|
+
toString() {
|
|
1174
|
+
return `Vec(${this.coords.join(", ")})`;
|
|
1175
|
+
}
|
|
1176
|
+
};
|
|
1177
|
+
|
|
1178
|
+
// src/core/div-rect.ts
|
|
1179
|
+
var DivRect = class _DivRect {
|
|
1180
|
+
constructor(...args) {
|
|
1181
|
+
__publicField(this, "left");
|
|
1182
|
+
__publicField(this, "centerX");
|
|
1183
|
+
__publicField(this, "right");
|
|
1184
|
+
__publicField(this, "top");
|
|
1185
|
+
__publicField(this, "centerY");
|
|
1186
|
+
__publicField(this, "bottom");
|
|
1187
|
+
if (args.length === 6) {
|
|
1188
|
+
this.left = args[0];
|
|
1189
|
+
this.centerX = args[1];
|
|
1190
|
+
this.right = args[2];
|
|
1191
|
+
this.top = args[3];
|
|
1192
|
+
this.centerY = args[4];
|
|
1193
|
+
this.bottom = args[5];
|
|
1194
|
+
} else if (args.length === 4) {
|
|
1195
|
+
this.left = args[0];
|
|
1196
|
+
this.right = args[1];
|
|
1197
|
+
this.centerX = (this.left + this.right) / 2;
|
|
1198
|
+
this.top = args[2];
|
|
1199
|
+
this.bottom = args[3];
|
|
1200
|
+
this.centerY = (this.top + this.bottom) / 2;
|
|
1201
|
+
} else if (args.length === 0) {
|
|
1202
|
+
this.left = this.centerX = this.right = 0;
|
|
1203
|
+
this.top = this.centerY = this.bottom = 0;
|
|
1204
|
+
} else {
|
|
1205
|
+
throw new TypeError(`Invalid DivRect args: ${args}`);
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
/**
|
|
1209
|
+
* Create rect from basic left, top, width and height arguments.
|
|
1210
|
+
*
|
|
1211
|
+
* @param left - Left coordinate.
|
|
1212
|
+
* @param top - Top coordinate.
|
|
1213
|
+
* @param width - Width.
|
|
1214
|
+
* @param height - Height.
|
|
1215
|
+
* @returns - DivRect.
|
|
1216
|
+
*/
|
|
1217
|
+
static create(left, top, width, height) {
|
|
1218
|
+
return new _DivRect(left, left + width, top, top + height);
|
|
1219
|
+
}
|
|
1220
|
+
/**
|
|
1221
|
+
* Create rect from centerX, centerY, width, height arguments.
|
|
1222
|
+
*
|
|
1223
|
+
* @param centerX - Center x-coordinate.
|
|
1224
|
+
* @param centerY - Center y-coordinate.
|
|
1225
|
+
* @param width - Width.
|
|
1226
|
+
* @param height - Height.
|
|
1227
|
+
* @returns - DivRect.
|
|
1228
|
+
*/
|
|
1229
|
+
static createCentered(centerX, centerY, width, height) {
|
|
1230
|
+
return new _DivRect(
|
|
1231
|
+
centerX - width / 2,
|
|
1232
|
+
centerX,
|
|
1233
|
+
centerX + width / 2,
|
|
1234
|
+
centerY - height / 2,
|
|
1235
|
+
centerY,
|
|
1236
|
+
centerY + height / 2
|
|
1237
|
+
);
|
|
1238
|
+
}
|
|
1239
|
+
/**
|
|
1240
|
+
* Create rect from sections.
|
|
1241
|
+
*
|
|
1242
|
+
* @param leftw - Left section width.
|
|
1243
|
+
* @param rightw - Right section width.
|
|
1244
|
+
* @param toph - Top section height.
|
|
1245
|
+
* @param bottomh - Bottomsection height.
|
|
1246
|
+
* @returns - DivRect.
|
|
1247
|
+
*/
|
|
1248
|
+
static createSections(leftw, rightw, toph, bottomh) {
|
|
1249
|
+
return new _DivRect(-leftw, 0, rightw, -toph, 0, bottomh);
|
|
1250
|
+
}
|
|
1251
|
+
/**
|
|
1252
|
+
* Width getter.
|
|
1253
|
+
*/
|
|
1254
|
+
get width() {
|
|
1255
|
+
return this.right - this.left;
|
|
1256
|
+
}
|
|
1257
|
+
/**
|
|
1258
|
+
* Height getter.
|
|
1259
|
+
*/
|
|
1260
|
+
get height() {
|
|
1261
|
+
return this.bottom - this.top;
|
|
1262
|
+
}
|
|
1263
|
+
/**
|
|
1264
|
+
* Left section width getter.
|
|
1265
|
+
*/
|
|
1266
|
+
get leftw() {
|
|
1267
|
+
return this.centerX - this.left;
|
|
1268
|
+
}
|
|
1269
|
+
/**
|
|
1270
|
+
* Right section width getter.
|
|
1271
|
+
*/
|
|
1272
|
+
get rightw() {
|
|
1273
|
+
return this.right - this.centerX;
|
|
1274
|
+
}
|
|
1275
|
+
/**
|
|
1276
|
+
* Top section height getter.
|
|
1277
|
+
*/
|
|
1278
|
+
get toph() {
|
|
1279
|
+
return this.centerY - this.top;
|
|
1280
|
+
}
|
|
1281
|
+
/**
|
|
1282
|
+
* Bottom section height getter.
|
|
1283
|
+
*/
|
|
1284
|
+
get bottomh() {
|
|
1285
|
+
return this.bottom - this.centerY;
|
|
1286
|
+
}
|
|
1287
|
+
/**
|
|
1288
|
+
* Does this Rect contain given (x, y)-point?
|
|
1289
|
+
*
|
|
1290
|
+
* @param x - X-coordinate.
|
|
1291
|
+
* @param y - Y-coordinate.
|
|
1292
|
+
* @returns - True/false.
|
|
1293
|
+
*/
|
|
1294
|
+
contains(x, y) {
|
|
1295
|
+
return x >= this.left && x <= this.right && y >= this.top && y <= this.bottom;
|
|
1296
|
+
}
|
|
1297
|
+
/**
|
|
1298
|
+
* Do a and b rects overlap?
|
|
1299
|
+
*
|
|
1300
|
+
* @param a - DivRect a.
|
|
1301
|
+
* @param b - DivRect b.
|
|
1302
|
+
* @returns - True/false.
|
|
1303
|
+
*/
|
|
1304
|
+
static overlap(a, b) {
|
|
1305
|
+
return a.right > b.left && a.left < b.right && a.bottom > b.top && a.top < b.bottom;
|
|
1306
|
+
}
|
|
1307
|
+
/**
|
|
1308
|
+
* Do horizontal measures of a and b rects overlap?
|
|
1309
|
+
*
|
|
1310
|
+
* @param a - DivRect a.
|
|
1311
|
+
* @param b - DivRect b.
|
|
1312
|
+
* @returns - True/false.
|
|
1313
|
+
*/
|
|
1314
|
+
static overlapX(a, b) {
|
|
1315
|
+
return a.right > b.left && a.left < b.right;
|
|
1316
|
+
}
|
|
1317
|
+
/**
|
|
1318
|
+
* Check if given rects are equal.
|
|
1319
|
+
* @param a - DivRect a.
|
|
1320
|
+
* @param b - DivRect b.
|
|
1321
|
+
* @returns - True/false.
|
|
1322
|
+
*/
|
|
1323
|
+
static equals(a, b) {
|
|
1324
|
+
if (a == null && b == null) {
|
|
1325
|
+
return true;
|
|
1326
|
+
} else if (a == null || b == null) {
|
|
1327
|
+
return false;
|
|
1328
|
+
} else {
|
|
1329
|
+
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;
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
/**
|
|
1333
|
+
* Check if this rect equals with another rect.
|
|
1334
|
+
* @param other - The other rect.
|
|
1335
|
+
* @returns - True/false.
|
|
1336
|
+
*/
|
|
1337
|
+
equals(other) {
|
|
1338
|
+
return _DivRect.equals(this, other);
|
|
1339
|
+
}
|
|
1340
|
+
/**
|
|
1341
|
+
* Check if edges of given rects are equal, ignoring centerX and centerY.
|
|
1342
|
+
*
|
|
1343
|
+
* @param a - DivRect a.
|
|
1344
|
+
* @param b - DivRect b.
|
|
1345
|
+
* @returns - True/false.
|
|
1346
|
+
*/
|
|
1347
|
+
static equalsEdges(a, b) {
|
|
1348
|
+
if (a == null && b == null) {
|
|
1349
|
+
return true;
|
|
1350
|
+
} else if (a == null || b == null) {
|
|
1351
|
+
return false;
|
|
1352
|
+
} else {
|
|
1353
|
+
return a === b || a.left === b.left && a.right === b.right && a.top === b.top && a.bottom === b.bottom;
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
/**
|
|
1357
|
+
* Check if edges of this Rect equals with given Rect, ignoring centerX and centerY.
|
|
1358
|
+
*
|
|
1359
|
+
* @param other - The other DivRect.
|
|
1360
|
+
* @returns - True/false.
|
|
1361
|
+
*/
|
|
1362
|
+
equalsEdges(other) {
|
|
1363
|
+
return _DivRect.equalsEdges(this, other);
|
|
1364
|
+
}
|
|
1365
|
+
/**
|
|
1366
|
+
* Created duplicate of this Rect.
|
|
1367
|
+
*
|
|
1368
|
+
* @returns - Duplicate.
|
|
1369
|
+
*/
|
|
1370
|
+
copy() {
|
|
1371
|
+
return new _DivRect(this.left, this.centerX, this.right, this.top, this.centerY, this.bottom);
|
|
1372
|
+
}
|
|
1373
|
+
/**
|
|
1374
|
+
* Move this rect by (dx, dy). Modifies this Rect.
|
|
1375
|
+
*
|
|
1376
|
+
* @param dx - Offset amount in x-direction.
|
|
1377
|
+
* @param dy - Offset amount in y-direction.
|
|
1378
|
+
* @returns - This DivRect instance.
|
|
1379
|
+
*/
|
|
1380
|
+
offsetInPlace(dx, dy) {
|
|
1381
|
+
this.left += dx;
|
|
1382
|
+
this.centerX += dx;
|
|
1383
|
+
this.right += dx;
|
|
1384
|
+
this.top += dy;
|
|
1385
|
+
this.centerY += dy;
|
|
1386
|
+
this.bottom += dy;
|
|
1387
|
+
return this;
|
|
1388
|
+
}
|
|
1389
|
+
/**
|
|
1390
|
+
* Move this rect by (dx, dy). Immutable, returns modified copy.
|
|
1391
|
+
*
|
|
1392
|
+
* @param dx - Offset amount in x-direction.
|
|
1393
|
+
* @param dy - Offset amount in y-direction.
|
|
1394
|
+
* @returns - DivRect copy with applied offset.
|
|
1395
|
+
*/
|
|
1396
|
+
offsetCopy(dx, dy) {
|
|
1397
|
+
return this.copy().offsetInPlace(dx, dy);
|
|
1398
|
+
}
|
|
1399
|
+
/**
|
|
1400
|
+
* Expand this Rect by given Rect. Modifies this Rect.
|
|
1401
|
+
*
|
|
1402
|
+
* @param rect - DivRect to expand this instance with.
|
|
1403
|
+
* @returns - This DivRect instance.
|
|
1404
|
+
*/
|
|
1405
|
+
expandInPlace(rect) {
|
|
1406
|
+
this.left = Math.min(this.left, rect.left);
|
|
1407
|
+
this.right = Math.max(this.right, rect.right);
|
|
1408
|
+
this.top = Math.min(this.top, rect.top);
|
|
1409
|
+
this.bottom = Math.max(this.bottom, rect.bottom);
|
|
1410
|
+
return this;
|
|
1411
|
+
}
|
|
1412
|
+
/**
|
|
1413
|
+
* Expand this Rect by given Rect. Immutable, returns modified copy.
|
|
1414
|
+
*
|
|
1415
|
+
* @param rect - DivRect to expand this instance with.
|
|
1416
|
+
* @returns - Expanded copy of this DivRect.
|
|
1417
|
+
*/
|
|
1418
|
+
expandCopy(rect) {
|
|
1419
|
+
return this.copy().expandInPlace(rect);
|
|
1420
|
+
}
|
|
1421
|
+
/**
|
|
1422
|
+
* Clip this Rect by given Rect. Mmodifies this Rect.
|
|
1423
|
+
*
|
|
1424
|
+
* @param clipRect - DivRect to clip this instance with.
|
|
1425
|
+
* @returns - This DivRect instance.
|
|
1426
|
+
*/
|
|
1427
|
+
clipInPlace(clipRect) {
|
|
1428
|
+
this.left = Math.max(this.left, clipRect.left);
|
|
1429
|
+
this.right = Math.min(this.right, clipRect.right);
|
|
1430
|
+
this.centerX = clamp(this.centerX, this.left, this.right);
|
|
1431
|
+
this.top = Math.max(this.top, clipRect.top);
|
|
1432
|
+
this.bottom = Math.min(this.bottom, clipRect.bottom);
|
|
1433
|
+
this.centerY = clamp(this.centerY, this.top, this.bottom);
|
|
1434
|
+
return this;
|
|
1435
|
+
}
|
|
1436
|
+
/**
|
|
1437
|
+
* Clip this Rect by given Rect. Immutable, return modified copy.
|
|
1438
|
+
*
|
|
1439
|
+
* @param clipRect - DivRecto to clip this instance with.
|
|
1440
|
+
* @returns - Clipped DivRect copy.
|
|
1441
|
+
*/
|
|
1442
|
+
clipCopy(clipRect) {
|
|
1443
|
+
return this.copy().clipInPlace(clipRect);
|
|
1444
|
+
}
|
|
1445
|
+
/**
|
|
1446
|
+
* Scale Rect. Anchor pos is (centerX, centerY). Modifies this Rect.
|
|
1447
|
+
*
|
|
1448
|
+
* @param scaleX - Scale x-amount.
|
|
1449
|
+
* @param scaleY - Scale y-amount. If undefined then scale x-amount is used.
|
|
1450
|
+
* @returns This DivRect instance.
|
|
1451
|
+
*/
|
|
1452
|
+
scaleInPlace(scaleX, scaleY) {
|
|
1453
|
+
scaleY = scaleY ?? scaleX;
|
|
1454
|
+
this.left = this.centerX - this.leftw * scaleX;
|
|
1455
|
+
this.right = this.centerX + this.rightw * scaleX;
|
|
1456
|
+
this.top = this.centerY - this.toph * scaleY;
|
|
1457
|
+
this.bottom = this.centerY + this.bottomh * scaleY;
|
|
1458
|
+
return this;
|
|
1459
|
+
}
|
|
1460
|
+
/**
|
|
1461
|
+
* Scale Rect. Anchor pos is (centerX, centerY). Immutable, returns modified copy.
|
|
1462
|
+
*
|
|
1463
|
+
* @param scaleX - Scale x-amount.
|
|
1464
|
+
* @param scaleY - Scale y-amount. If undefined then scale x-amount is used.
|
|
1465
|
+
* @returns Scaled copy of this DivRect.
|
|
1466
|
+
*/
|
|
1467
|
+
scaleCopy(scaleX, scaleY) {
|
|
1468
|
+
return this.copy().scaleInPlace(scaleX, scaleY);
|
|
1469
|
+
}
|
|
1470
|
+
/**
|
|
1471
|
+
* Get this DivRect instance.
|
|
1472
|
+
* @returns - This DivRect instance.
|
|
1473
|
+
*/
|
|
1474
|
+
getRect() {
|
|
1475
|
+
return this;
|
|
1108
1476
|
}
|
|
1109
1477
|
};
|
|
1110
1478
|
|
|
@@ -1205,84 +1573,28 @@ var LRUCache = class {
|
|
|
1205
1573
|
}
|
|
1206
1574
|
};
|
|
1207
1575
|
|
|
1208
|
-
// src/core/small-int-cache.ts
|
|
1209
|
-
var SmallIntCache = class {
|
|
1210
|
-
// for keys < 0
|
|
1211
|
-
constructor() {
|
|
1212
|
-
__publicField(this, "pos");
|
|
1213
|
-
// for keys >= 0
|
|
1214
|
-
__publicField(this, "neg");
|
|
1215
|
-
this.pos = [];
|
|
1216
|
-
this.neg = [];
|
|
1217
|
-
}
|
|
1218
|
-
set(key, value) {
|
|
1219
|
-
if (!isInteger(key)) {
|
|
1220
|
-
throw new Error("Key must be an integer");
|
|
1221
|
-
} else if (key >= 0) {
|
|
1222
|
-
this.pos[key] = value;
|
|
1223
|
-
} else {
|
|
1224
|
-
this.neg[-key - 1] = value;
|
|
1225
|
-
}
|
|
1226
|
-
}
|
|
1227
|
-
get(key) {
|
|
1228
|
-
if (!isInteger(key)) {
|
|
1229
|
-
throw new Error("Key must be an integer");
|
|
1230
|
-
} else if (key >= 0) {
|
|
1231
|
-
return this.pos[key];
|
|
1232
|
-
} else {
|
|
1233
|
-
return this.neg[-key - 1];
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
1236
|
-
has(key) {
|
|
1237
|
-
if (!isInteger(key)) {
|
|
1238
|
-
return false;
|
|
1239
|
-
} else if (key >= 0) {
|
|
1240
|
-
return key in this.pos;
|
|
1241
|
-
} else {
|
|
1242
|
-
return -key - 1 in this.neg;
|
|
1243
|
-
}
|
|
1244
|
-
}
|
|
1245
|
-
delete(key) {
|
|
1246
|
-
if (!isInteger(key)) {
|
|
1247
|
-
return;
|
|
1248
|
-
} else if (key >= 0) {
|
|
1249
|
-
delete this.pos[key];
|
|
1250
|
-
} else {
|
|
1251
|
-
delete this.neg[-key - 1];
|
|
1252
|
-
}
|
|
1253
|
-
}
|
|
1254
|
-
clear() {
|
|
1255
|
-
this.pos = [];
|
|
1256
|
-
this.neg = [];
|
|
1257
|
-
}
|
|
1258
|
-
};
|
|
1259
|
-
|
|
1260
1576
|
// src/core/index-array.ts
|
|
1261
1577
|
var IndexArray = class _IndexArray {
|
|
1262
1578
|
constructor(entries) {
|
|
1263
|
-
|
|
1264
|
-
__publicField(this, "posEl");
|
|
1579
|
+
__publicField(this, "posVal");
|
|
1265
1580
|
__publicField(this, "hasPos");
|
|
1266
|
-
//
|
|
1267
|
-
__publicField(this, "
|
|
1581
|
+
// Number of values
|
|
1582
|
+
__publicField(this, "valCount");
|
|
1268
1583
|
if (entries instanceof _IndexArray) {
|
|
1269
|
-
this.
|
|
1584
|
+
this.posVal = entries.posVal.slice();
|
|
1270
1585
|
this.hasPos = entries.hasPos.slice();
|
|
1271
|
-
this.
|
|
1586
|
+
this.valCount = entries.valCount;
|
|
1272
1587
|
} else {
|
|
1273
|
-
this.
|
|
1588
|
+
this.posVal = [];
|
|
1274
1589
|
this.hasPos = [];
|
|
1275
|
-
this.
|
|
1590
|
+
this.valCount = 0;
|
|
1276
1591
|
if (entries) {
|
|
1277
|
-
for (const [id,
|
|
1278
|
-
this.set(id,
|
|
1592
|
+
for (const [id, value] of entries) {
|
|
1593
|
+
this.set(id, value);
|
|
1279
1594
|
}
|
|
1280
1595
|
}
|
|
1281
1596
|
}
|
|
1282
1597
|
}
|
|
1283
|
-
static toNegIndex(id) {
|
|
1284
|
-
return -id - 1;
|
|
1285
|
-
}
|
|
1286
1598
|
static validateIndex(id) {
|
|
1287
1599
|
if (!isIntegerGte(id, 0)) throw new Error(`Invalid index ${id} - must be an integer >= 0!`);
|
|
1288
1600
|
return id;
|
|
@@ -1291,7 +1603,7 @@ var IndexArray = class _IndexArray {
|
|
|
1291
1603
|
return this.hasPos.length;
|
|
1292
1604
|
}
|
|
1293
1605
|
get size() {
|
|
1294
|
-
return this.
|
|
1606
|
+
return this.valCount;
|
|
1295
1607
|
}
|
|
1296
1608
|
isEmpty() {
|
|
1297
1609
|
return this.size === 0;
|
|
@@ -1300,15 +1612,15 @@ var IndexArray = class _IndexArray {
|
|
|
1300
1612
|
_IndexArray.validateIndex(id);
|
|
1301
1613
|
return this.hasPos[id] === true;
|
|
1302
1614
|
}
|
|
1303
|
-
set(id,
|
|
1615
|
+
set(id, value) {
|
|
1304
1616
|
_IndexArray.validateIndex(id);
|
|
1305
|
-
if (this.hasPos[id] !== true) this.
|
|
1306
|
-
this.
|
|
1617
|
+
if (this.hasPos[id] !== true) this.valCount++;
|
|
1618
|
+
this.posVal[id] = value;
|
|
1307
1619
|
this.hasPos[id] = true;
|
|
1308
1620
|
}
|
|
1309
1621
|
get(id) {
|
|
1310
1622
|
_IndexArray.validateIndex(id);
|
|
1311
|
-
return this.hasPos[id] ? this.
|
|
1623
|
+
return this.hasPos[id] ? this.posVal[id] : void 0;
|
|
1312
1624
|
}
|
|
1313
1625
|
getOrDefault(id, defaultValue) {
|
|
1314
1626
|
return this.get(id) ?? defaultValue;
|
|
@@ -1324,19 +1636,19 @@ var IndexArray = class _IndexArray {
|
|
|
1324
1636
|
delete(id) {
|
|
1325
1637
|
_IndexArray.validateIndex(id);
|
|
1326
1638
|
if (!this.hasPos[id]) return false;
|
|
1327
|
-
this.
|
|
1639
|
+
this.posVal[id] = void 0;
|
|
1328
1640
|
this.hasPos[id] = false;
|
|
1329
|
-
this.
|
|
1641
|
+
this.valCount--;
|
|
1330
1642
|
return true;
|
|
1331
1643
|
}
|
|
1332
1644
|
clear() {
|
|
1333
|
-
this.
|
|
1645
|
+
this.posVal = [];
|
|
1334
1646
|
this.hasPos = [];
|
|
1335
|
-
this.
|
|
1647
|
+
this.valCount = 0;
|
|
1336
1648
|
}
|
|
1337
1649
|
forEach(callbackfn, thisArg) {
|
|
1338
|
-
for (const [id,
|
|
1339
|
-
callbackfn.call(thisArg,
|
|
1650
|
+
for (const [id, value] of this.entries()) {
|
|
1651
|
+
callbackfn.call(thisArg, value, id, this);
|
|
1340
1652
|
}
|
|
1341
1653
|
}
|
|
1342
1654
|
*indices() {
|
|
@@ -1346,12 +1658,12 @@ var IndexArray = class _IndexArray {
|
|
|
1346
1658
|
}
|
|
1347
1659
|
*values() {
|
|
1348
1660
|
for (let id = 0; id < this.posLen; id++) {
|
|
1349
|
-
if (this.hasPos[id]) yield this.
|
|
1661
|
+
if (this.hasPos[id]) yield this.posVal[id];
|
|
1350
1662
|
}
|
|
1351
1663
|
}
|
|
1352
1664
|
*entries() {
|
|
1353
1665
|
for (let id = 0; id < this.posLen; id++) {
|
|
1354
|
-
if (this.hasPos[id]) yield [id, this.
|
|
1666
|
+
if (this.hasPos[id]) yield [id, this.posVal[id]];
|
|
1355
1667
|
}
|
|
1356
1668
|
}
|
|
1357
1669
|
indicesArray() {
|
|
@@ -1369,13 +1681,13 @@ var IndexArray = class _IndexArray {
|
|
|
1369
1681
|
}
|
|
1370
1682
|
}
|
|
1371
1683
|
*kvValues() {
|
|
1372
|
-
for (const
|
|
1373
|
-
yield
|
|
1684
|
+
for (const value of this.values()) {
|
|
1685
|
+
yield value;
|
|
1374
1686
|
}
|
|
1375
1687
|
}
|
|
1376
1688
|
*kvEntries() {
|
|
1377
|
-
for (const [id,
|
|
1378
|
-
yield [[id],
|
|
1689
|
+
for (const [id, value] of this.entries()) {
|
|
1690
|
+
yield [[id], value];
|
|
1379
1691
|
}
|
|
1380
1692
|
}
|
|
1381
1693
|
*[Symbol.iterator]() {
|
|
@@ -1395,21 +1707,21 @@ var IndexArray = class _IndexArray {
|
|
|
1395
1707
|
return this;
|
|
1396
1708
|
}
|
|
1397
1709
|
some(fn) {
|
|
1398
|
-
for (const [id,
|
|
1399
|
-
if (fn(
|
|
1710
|
+
for (const [id, value] of this.entries()) {
|
|
1711
|
+
if (fn(value, id)) return true;
|
|
1400
1712
|
}
|
|
1401
1713
|
return false;
|
|
1402
1714
|
}
|
|
1403
1715
|
every(fn) {
|
|
1404
|
-
for (const [id,
|
|
1405
|
-
if (!fn(
|
|
1716
|
+
for (const [id, value] of this.entries()) {
|
|
1717
|
+
if (!fn(value, id)) return false;
|
|
1406
1718
|
}
|
|
1407
1719
|
return true;
|
|
1408
1720
|
}
|
|
1409
|
-
filter(
|
|
1410
|
-
|
|
1411
|
-
for (const [id,
|
|
1412
|
-
if (
|
|
1721
|
+
filter(predicate) {
|
|
1722
|
+
const result = new this.constructor();
|
|
1723
|
+
for (const [id, value] of this.entries()) {
|
|
1724
|
+
if (predicate(value, id, this)) result.set(id, value);
|
|
1413
1725
|
}
|
|
1414
1726
|
return result;
|
|
1415
1727
|
}
|
|
@@ -1432,22 +1744,22 @@ var IndexArray = class _IndexArray {
|
|
|
1432
1744
|
start = first;
|
|
1433
1745
|
}
|
|
1434
1746
|
for (let current = start; !current.done; current = iterator.next()) {
|
|
1435
|
-
const [id,
|
|
1436
|
-
acc = fn(acc,
|
|
1747
|
+
const [id, value] = current.value;
|
|
1748
|
+
acc = fn(acc, value, id);
|
|
1437
1749
|
}
|
|
1438
1750
|
return acc;
|
|
1439
1751
|
}
|
|
1440
1752
|
mapToArray(fn) {
|
|
1441
1753
|
let result = [];
|
|
1442
|
-
for (const [id,
|
|
1443
|
-
result.push(fn(
|
|
1754
|
+
for (const [id, value] of this.entries()) {
|
|
1755
|
+
result.push(fn(value, id));
|
|
1444
1756
|
}
|
|
1445
1757
|
return result;
|
|
1446
1758
|
}
|
|
1447
1759
|
map(fn) {
|
|
1448
1760
|
let result = new _IndexArray();
|
|
1449
|
-
for (const [id,
|
|
1450
|
-
result.set(id, fn(
|
|
1761
|
+
for (const [id, value] of this.entries()) {
|
|
1762
|
+
result.set(id, fn(value, id));
|
|
1451
1763
|
}
|
|
1452
1764
|
return result;
|
|
1453
1765
|
}
|
|
@@ -1459,13 +1771,13 @@ var IndexArray = class _IndexArray {
|
|
|
1459
1771
|
const hasA = this.hasPos[i];
|
|
1460
1772
|
const hasB = other.hasPos[i];
|
|
1461
1773
|
if (hasA !== hasB) return false;
|
|
1462
|
-
if (hasA && !eq(this.
|
|
1774
|
+
if (hasA && !eq(this.posVal[i], other.posVal[i])) return false;
|
|
1463
1775
|
}
|
|
1464
1776
|
return true;
|
|
1465
1777
|
}
|
|
1466
1778
|
toString() {
|
|
1467
1779
|
if (this.size === 0) return `IndexArray[ ]`;
|
|
1468
|
-
const entries = this.entriesArray().map(([id,
|
|
1780
|
+
const entries = this.entriesArray().map(([id, value]) => `${id}: ${value}`).join(", ");
|
|
1469
1781
|
return `IndexArray[ ${entries} ]`;
|
|
1470
1782
|
}
|
|
1471
1783
|
};
|
|
@@ -1473,29 +1785,29 @@ var IndexArray = class _IndexArray {
|
|
|
1473
1785
|
// src/core/signed-index-array.ts
|
|
1474
1786
|
var SignedIndexArray = class _SignedIndexArray {
|
|
1475
1787
|
constructor(entries) {
|
|
1476
|
-
//
|
|
1477
|
-
__publicField(this, "
|
|
1788
|
+
// For indexes >= 0
|
|
1789
|
+
__publicField(this, "posVal");
|
|
1478
1790
|
__publicField(this, "hasPos");
|
|
1479
|
-
//
|
|
1480
|
-
__publicField(this, "
|
|
1791
|
+
// For indexes < 0
|
|
1792
|
+
__publicField(this, "negVal");
|
|
1481
1793
|
__publicField(this, "hasNeg");
|
|
1482
|
-
//
|
|
1483
|
-
__publicField(this, "
|
|
1794
|
+
// Number of values
|
|
1795
|
+
__publicField(this, "valCount");
|
|
1484
1796
|
if (entries instanceof _SignedIndexArray) {
|
|
1485
|
-
this.
|
|
1797
|
+
this.negVal = entries.negVal.slice();
|
|
1486
1798
|
this.hasNeg = entries.hasNeg.slice();
|
|
1487
|
-
this.
|
|
1799
|
+
this.posVal = entries.posVal.slice();
|
|
1488
1800
|
this.hasPos = entries.hasPos.slice();
|
|
1489
|
-
this.
|
|
1801
|
+
this.valCount = entries.valCount;
|
|
1490
1802
|
} else {
|
|
1491
|
-
this.
|
|
1803
|
+
this.negVal = [];
|
|
1492
1804
|
this.hasNeg = [];
|
|
1493
|
-
this.
|
|
1805
|
+
this.posVal = [];
|
|
1494
1806
|
this.hasPos = [];
|
|
1495
|
-
this.
|
|
1807
|
+
this.valCount = 0;
|
|
1496
1808
|
if (entries) {
|
|
1497
|
-
for (const [id,
|
|
1498
|
-
this.set(id,
|
|
1809
|
+
for (const [id, value] of entries) {
|
|
1810
|
+
this.set(id, value);
|
|
1499
1811
|
}
|
|
1500
1812
|
}
|
|
1501
1813
|
}
|
|
@@ -1508,7 +1820,7 @@ var SignedIndexArray = class _SignedIndexArray {
|
|
|
1508
1820
|
return id;
|
|
1509
1821
|
}
|
|
1510
1822
|
get size() {
|
|
1511
|
-
return this.
|
|
1823
|
+
return this.valCount;
|
|
1512
1824
|
}
|
|
1513
1825
|
isEmpty() {
|
|
1514
1826
|
return this.size === 0;
|
|
@@ -1527,26 +1839,26 @@ var SignedIndexArray = class _SignedIndexArray {
|
|
|
1527
1839
|
return this.hasNeg[_SignedIndexArray.toNegIndex(id)] === true;
|
|
1528
1840
|
}
|
|
1529
1841
|
}
|
|
1530
|
-
set(id,
|
|
1842
|
+
set(id, value) {
|
|
1531
1843
|
_SignedIndexArray.validateIndex(id);
|
|
1532
1844
|
if (id >= 0) {
|
|
1533
|
-
if (this.hasPos[id] !== true) this.
|
|
1534
|
-
this.
|
|
1845
|
+
if (this.hasPos[id] !== true) this.valCount++;
|
|
1846
|
+
this.posVal[id] = value;
|
|
1535
1847
|
this.hasPos[id] = true;
|
|
1536
1848
|
} else {
|
|
1537
1849
|
let negId = _SignedIndexArray.toNegIndex(id);
|
|
1538
|
-
if (this.hasNeg[negId] !== true) this.
|
|
1539
|
-
this.
|
|
1850
|
+
if (this.hasNeg[negId] !== true) this.valCount++;
|
|
1851
|
+
this.negVal[negId] = value;
|
|
1540
1852
|
this.hasNeg[negId] = true;
|
|
1541
1853
|
}
|
|
1542
1854
|
}
|
|
1543
1855
|
get(id) {
|
|
1544
1856
|
_SignedIndexArray.validateIndex(id);
|
|
1545
1857
|
if (id >= 0) {
|
|
1546
|
-
return this.hasPos[id] ? this.
|
|
1858
|
+
return this.hasPos[id] ? this.posVal[id] : void 0;
|
|
1547
1859
|
} else {
|
|
1548
1860
|
let negId = _SignedIndexArray.toNegIndex(id);
|
|
1549
|
-
return this.hasNeg[negId] ? this.
|
|
1861
|
+
return this.hasNeg[negId] ? this.negVal[negId] : void 0;
|
|
1550
1862
|
}
|
|
1551
1863
|
}
|
|
1552
1864
|
getOrDefault(id, defaultValue) {
|
|
@@ -1563,25 +1875,25 @@ var SignedIndexArray = class _SignedIndexArray {
|
|
|
1563
1875
|
delete(id) {
|
|
1564
1876
|
_SignedIndexArray.validateIndex(id);
|
|
1565
1877
|
const isPos = id >= 0;
|
|
1566
|
-
const arr = isPos ? this.
|
|
1878
|
+
const arr = isPos ? this.posVal : this.negVal;
|
|
1567
1879
|
const has = isPos ? this.hasPos : this.hasNeg;
|
|
1568
1880
|
const idx = isPos ? id : _SignedIndexArray.toNegIndex(id);
|
|
1569
1881
|
if (!has[idx]) return false;
|
|
1570
1882
|
arr[idx] = void 0;
|
|
1571
1883
|
has[idx] = false;
|
|
1572
|
-
this.
|
|
1884
|
+
this.valCount--;
|
|
1573
1885
|
return true;
|
|
1574
1886
|
}
|
|
1575
1887
|
clear() {
|
|
1576
|
-
this.
|
|
1888
|
+
this.negVal = [];
|
|
1577
1889
|
this.hasNeg = [];
|
|
1578
|
-
this.
|
|
1890
|
+
this.posVal = [];
|
|
1579
1891
|
this.hasPos = [];
|
|
1580
|
-
this.
|
|
1892
|
+
this.valCount = 0;
|
|
1581
1893
|
}
|
|
1582
1894
|
forEach(callbackfn, thisArg) {
|
|
1583
|
-
for (const [id,
|
|
1584
|
-
callbackfn.call(thisArg,
|
|
1895
|
+
for (const [id, value] of this.entries()) {
|
|
1896
|
+
callbackfn.call(thisArg, value, id, this);
|
|
1585
1897
|
}
|
|
1586
1898
|
}
|
|
1587
1899
|
*indices() {
|
|
@@ -1594,18 +1906,18 @@ var SignedIndexArray = class _SignedIndexArray {
|
|
|
1594
1906
|
}
|
|
1595
1907
|
*values() {
|
|
1596
1908
|
for (let id = this.negLen - 1; id >= 0; id--) {
|
|
1597
|
-
if (this.hasNeg[id]) yield this.
|
|
1909
|
+
if (this.hasNeg[id]) yield this.negVal[id];
|
|
1598
1910
|
}
|
|
1599
1911
|
for (let id = 0; id < this.posLen; id++) {
|
|
1600
|
-
if (this.hasPos[id]) yield this.
|
|
1912
|
+
if (this.hasPos[id]) yield this.posVal[id];
|
|
1601
1913
|
}
|
|
1602
1914
|
}
|
|
1603
1915
|
*entries() {
|
|
1604
1916
|
for (let id = this.negLen - 1; id >= 0; id--) {
|
|
1605
|
-
if (this.hasNeg[id]) yield [_SignedIndexArray.toNegIndex(id), this.
|
|
1917
|
+
if (this.hasNeg[id]) yield [_SignedIndexArray.toNegIndex(id), this.negVal[id]];
|
|
1606
1918
|
}
|
|
1607
1919
|
for (let id = 0; id < this.posLen; id++) {
|
|
1608
|
-
if (this.hasPos[id]) yield [id, this.
|
|
1920
|
+
if (this.hasPos[id]) yield [id, this.posVal[id]];
|
|
1609
1921
|
}
|
|
1610
1922
|
}
|
|
1611
1923
|
indicesArray() {
|
|
@@ -1623,13 +1935,13 @@ var SignedIndexArray = class _SignedIndexArray {
|
|
|
1623
1935
|
}
|
|
1624
1936
|
}
|
|
1625
1937
|
*kvValues() {
|
|
1626
|
-
for (const
|
|
1627
|
-
yield
|
|
1938
|
+
for (const value of this.values()) {
|
|
1939
|
+
yield value;
|
|
1628
1940
|
}
|
|
1629
1941
|
}
|
|
1630
1942
|
*kvEntries() {
|
|
1631
|
-
for (const [id,
|
|
1632
|
-
yield [[id],
|
|
1943
|
+
for (const [id, value] of this.entries()) {
|
|
1944
|
+
yield [[id], value];
|
|
1633
1945
|
}
|
|
1634
1946
|
}
|
|
1635
1947
|
*[Symbol.iterator]() {
|
|
@@ -1649,21 +1961,21 @@ var SignedIndexArray = class _SignedIndexArray {
|
|
|
1649
1961
|
return this;
|
|
1650
1962
|
}
|
|
1651
1963
|
some(fn) {
|
|
1652
|
-
for (const [id,
|
|
1653
|
-
if (fn(
|
|
1964
|
+
for (const [id, value] of this.entries()) {
|
|
1965
|
+
if (fn(value, id)) return true;
|
|
1654
1966
|
}
|
|
1655
1967
|
return false;
|
|
1656
1968
|
}
|
|
1657
1969
|
every(fn) {
|
|
1658
|
-
for (const [id,
|
|
1659
|
-
if (!fn(
|
|
1970
|
+
for (const [id, value] of this.entries()) {
|
|
1971
|
+
if (!fn(value, id)) return false;
|
|
1660
1972
|
}
|
|
1661
1973
|
return true;
|
|
1662
1974
|
}
|
|
1663
|
-
filter(
|
|
1664
|
-
|
|
1665
|
-
for (const [id,
|
|
1666
|
-
if (
|
|
1975
|
+
filter(predicate) {
|
|
1976
|
+
const result = new this.constructor();
|
|
1977
|
+
for (const [id, value] of this.entries()) {
|
|
1978
|
+
if (predicate(value, id, this)) result.set(id, value);
|
|
1667
1979
|
}
|
|
1668
1980
|
return result;
|
|
1669
1981
|
}
|
|
@@ -1686,22 +1998,22 @@ var SignedIndexArray = class _SignedIndexArray {
|
|
|
1686
1998
|
start = first;
|
|
1687
1999
|
}
|
|
1688
2000
|
for (let current = start; !current.done; current = iterator.next()) {
|
|
1689
|
-
const [id,
|
|
1690
|
-
acc = fn(acc,
|
|
2001
|
+
const [id, value] = current.value;
|
|
2002
|
+
acc = fn(acc, value, id);
|
|
1691
2003
|
}
|
|
1692
2004
|
return acc;
|
|
1693
2005
|
}
|
|
1694
2006
|
mapToArray(fn) {
|
|
1695
2007
|
let result = [];
|
|
1696
|
-
for (const [id,
|
|
1697
|
-
result.push(fn(
|
|
2008
|
+
for (const [id, value] of this.entries()) {
|
|
2009
|
+
result.push(fn(value, id));
|
|
1698
2010
|
}
|
|
1699
2011
|
return result;
|
|
1700
2012
|
}
|
|
1701
2013
|
map(fn) {
|
|
1702
2014
|
let result = new _SignedIndexArray();
|
|
1703
|
-
for (const [id,
|
|
1704
|
-
result.set(id, fn(
|
|
2015
|
+
for (const [id, value] of this.entries()) {
|
|
2016
|
+
result.set(id, fn(value, id));
|
|
1705
2017
|
}
|
|
1706
2018
|
return result;
|
|
1707
2019
|
}
|
|
@@ -1713,25 +2025,25 @@ var SignedIndexArray = class _SignedIndexArray {
|
|
|
1713
2025
|
const hasA = this.hasPos[i];
|
|
1714
2026
|
const hasB = other.hasPos[i];
|
|
1715
2027
|
if (hasA !== hasB) return false;
|
|
1716
|
-
if (hasA && !eq(this.
|
|
2028
|
+
if (hasA && !eq(this.posVal[i], other.posVal[i])) return false;
|
|
1717
2029
|
}
|
|
1718
2030
|
const negLen = Math.max(this.negLen, other.negLen);
|
|
1719
2031
|
for (let i = 0; i < negLen; ++i) {
|
|
1720
2032
|
const hasA = this.hasNeg[i];
|
|
1721
2033
|
const hasB = other.hasNeg[i];
|
|
1722
2034
|
if (hasA !== hasB) return false;
|
|
1723
|
-
if (hasA && !eq(this.
|
|
2035
|
+
if (hasA && !eq(this.negVal[i], other.negVal[i])) return false;
|
|
1724
2036
|
}
|
|
1725
2037
|
return true;
|
|
1726
2038
|
}
|
|
1727
2039
|
toString() {
|
|
1728
2040
|
if (this.size === 0) return `SignedIndexArray[ ]`;
|
|
1729
|
-
const entries = this.entriesArray().map(([id,
|
|
2041
|
+
const entries = this.entriesArray().map(([id, value]) => `${id}: ${value}`).join(", ");
|
|
1730
2042
|
return `SignedIndexArray[ ${entries} ]`;
|
|
1731
2043
|
}
|
|
1732
2044
|
};
|
|
1733
2045
|
|
|
1734
|
-
// src/core/
|
|
2046
|
+
// src/core/map1.ts
|
|
1735
2047
|
var Map1 = class _Map1 {
|
|
1736
2048
|
constructor(entries) {
|
|
1737
2049
|
__publicField(this, "map1");
|
|
@@ -1835,16 +2147,33 @@ var Map1 = class _Map1 {
|
|
|
1835
2147
|
}
|
|
1836
2148
|
return true;
|
|
1837
2149
|
}
|
|
1838
|
-
filter(
|
|
1839
|
-
|
|
2150
|
+
filter(predicate) {
|
|
2151
|
+
const result = new this.constructor();
|
|
1840
2152
|
for (const [key1, value] of this.map1) {
|
|
1841
|
-
if (
|
|
2153
|
+
if (predicate(value, key1, this)) result.set(key1, value);
|
|
1842
2154
|
}
|
|
1843
2155
|
return result;
|
|
1844
2156
|
}
|
|
1845
2157
|
reduce(fn, init) {
|
|
1846
|
-
let
|
|
1847
|
-
|
|
2158
|
+
let iterator = this.entries();
|
|
2159
|
+
let first = iterator.next();
|
|
2160
|
+
if (first.done) {
|
|
2161
|
+
if (arguments.length < 2) {
|
|
2162
|
+
throw new TypeError("Reduce of empty Map1 with no initial value!");
|
|
2163
|
+
}
|
|
2164
|
+
return init;
|
|
2165
|
+
}
|
|
2166
|
+
let acc;
|
|
2167
|
+
let start;
|
|
2168
|
+
if (arguments.length < 2) {
|
|
2169
|
+
acc = first.value[1];
|
|
2170
|
+
start = iterator.next();
|
|
2171
|
+
} else {
|
|
2172
|
+
acc = init;
|
|
2173
|
+
start = first;
|
|
2174
|
+
}
|
|
2175
|
+
for (let current = start; !current.done; current = iterator.next()) {
|
|
2176
|
+
const [key1, value] = current.value;
|
|
1848
2177
|
acc = fn(acc, value, key1);
|
|
1849
2178
|
}
|
|
1850
2179
|
return acc;
|
|
@@ -1868,9 +2197,11 @@ var Map1 = class _Map1 {
|
|
|
1868
2197
|
}
|
|
1869
2198
|
toString() {
|
|
1870
2199
|
const entries = [...this.map1].map(([k, v]) => `${k} => ${v}`).join(", ");
|
|
1871
|
-
return `Map1(${this.
|
|
2200
|
+
return entries.length === 0 ? `Map1(0){ }` : `Map1(${this.size}){ ${entries} }`;
|
|
1872
2201
|
}
|
|
1873
2202
|
};
|
|
2203
|
+
|
|
2204
|
+
// src/core/map2.ts
|
|
1874
2205
|
var Map2 = class _Map2 {
|
|
1875
2206
|
constructor(entries) {
|
|
1876
2207
|
__publicField(this, "map1", /* @__PURE__ */ new Map());
|
|
@@ -1996,21 +2327,36 @@ var Map2 = class _Map2 {
|
|
|
1996
2327
|
}
|
|
1997
2328
|
return true;
|
|
1998
2329
|
}
|
|
1999
|
-
filter(
|
|
2000
|
-
|
|
2330
|
+
filter(predicate) {
|
|
2331
|
+
const result = new this.constructor();
|
|
2001
2332
|
for (const [key1, map2] of this.map1) {
|
|
2002
2333
|
for (const [key2, value] of map2) {
|
|
2003
|
-
if (
|
|
2334
|
+
if (predicate(value, key1, key2, this)) result.set(key1, key2, value);
|
|
2004
2335
|
}
|
|
2005
2336
|
}
|
|
2006
2337
|
return result;
|
|
2007
2338
|
}
|
|
2008
2339
|
reduce(fn, init) {
|
|
2009
|
-
let
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2340
|
+
let iterator = this.entries();
|
|
2341
|
+
let first = iterator.next();
|
|
2342
|
+
if (first.done) {
|
|
2343
|
+
if (arguments.length < 2) {
|
|
2344
|
+
throw new TypeError("Reduce of empty Map2 with no initial value!");
|
|
2013
2345
|
}
|
|
2346
|
+
return init;
|
|
2347
|
+
}
|
|
2348
|
+
let acc;
|
|
2349
|
+
let start;
|
|
2350
|
+
if (arguments.length < 2) {
|
|
2351
|
+
acc = first.value[2];
|
|
2352
|
+
start = iterator.next();
|
|
2353
|
+
} else {
|
|
2354
|
+
acc = init;
|
|
2355
|
+
start = first;
|
|
2356
|
+
}
|
|
2357
|
+
for (let current = start; !current.done; current = iterator.next()) {
|
|
2358
|
+
const [key1, key2, value] = current.value;
|
|
2359
|
+
acc = fn(acc, value, key1, key2);
|
|
2014
2360
|
}
|
|
2015
2361
|
return acc;
|
|
2016
2362
|
}
|
|
@@ -2047,9 +2393,11 @@ var Map2 = class _Map2 {
|
|
|
2047
2393
|
const inner = [...map2].map(([key2, v]) => `${key2} => ${v}`).join(", ");
|
|
2048
2394
|
entries.push(`${key1} => { ${inner} }`);
|
|
2049
2395
|
}
|
|
2050
|
-
return `Map2(${this.size})
|
|
2396
|
+
return entries.length === 0 ? `Map2(0){ }` : `Map2(${this.size}){ ${entries} }`;
|
|
2051
2397
|
}
|
|
2052
2398
|
};
|
|
2399
|
+
|
|
2400
|
+
// src/core/map3.ts
|
|
2053
2401
|
var Map3 = class _Map3 {
|
|
2054
2402
|
constructor(entries) {
|
|
2055
2403
|
__publicField(this, "map1", /* @__PURE__ */ new Map());
|
|
@@ -2198,25 +2546,38 @@ var Map3 = class _Map3 {
|
|
|
2198
2546
|
}
|
|
2199
2547
|
return true;
|
|
2200
2548
|
}
|
|
2201
|
-
filter(
|
|
2202
|
-
|
|
2549
|
+
filter(predicate) {
|
|
2550
|
+
const result = new this.constructor();
|
|
2203
2551
|
for (const [key1, map2] of this.map1) {
|
|
2204
2552
|
for (const [key2, map3] of map2) {
|
|
2205
2553
|
for (const [key3, value] of map3) {
|
|
2206
|
-
if (
|
|
2554
|
+
if (predicate(value, key1, key2, key3, this)) result.set(key1, key2, key3, value);
|
|
2207
2555
|
}
|
|
2208
2556
|
}
|
|
2209
2557
|
}
|
|
2210
2558
|
return result;
|
|
2211
2559
|
}
|
|
2212
2560
|
reduce(fn, init) {
|
|
2213
|
-
let
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
}
|
|
2561
|
+
let iterator = this.entries();
|
|
2562
|
+
let first = iterator.next();
|
|
2563
|
+
if (first.done) {
|
|
2564
|
+
if (arguments.length < 2) {
|
|
2565
|
+
throw new TypeError("Reduce of empty Map3 with no initial value!");
|
|
2219
2566
|
}
|
|
2567
|
+
return init;
|
|
2568
|
+
}
|
|
2569
|
+
let acc;
|
|
2570
|
+
let start;
|
|
2571
|
+
if (arguments.length < 2) {
|
|
2572
|
+
acc = first.value[3];
|
|
2573
|
+
start = iterator.next();
|
|
2574
|
+
} else {
|
|
2575
|
+
acc = init;
|
|
2576
|
+
start = first;
|
|
2577
|
+
}
|
|
2578
|
+
for (let current = start; !current.done; current = iterator.next()) {
|
|
2579
|
+
const [key1, key2, key3, value] = current.value;
|
|
2580
|
+
acc = fn(acc, value, key1, key2, key3);
|
|
2220
2581
|
}
|
|
2221
2582
|
return acc;
|
|
2222
2583
|
}
|
|
@@ -2261,7 +2622,7 @@ var Map3 = class _Map3 {
|
|
|
2261
2622
|
entries.push(`${key1} => ${key2} => { ${inner} }`);
|
|
2262
2623
|
}
|
|
2263
2624
|
}
|
|
2264
|
-
return `Map3(${this.size})
|
|
2625
|
+
return entries.length === 0 ? `Map3(0){ }` : `Map3(${this.size}){ ${entries.join(", ")} }`;
|
|
2265
2626
|
}
|
|
2266
2627
|
};
|
|
2267
2628
|
|
|
@@ -2333,10 +2694,88 @@ var MultiContainer = class {
|
|
|
2333
2694
|
function asMulti(base) {
|
|
2334
2695
|
return new MultiContainer(base);
|
|
2335
2696
|
}
|
|
2697
|
+
|
|
2698
|
+
// src/core/deprecated/vec2.ts
|
|
2699
|
+
var Vec2 = class _Vec2 {
|
|
2700
|
+
constructor(x, y) {
|
|
2701
|
+
__publicField(this, "x");
|
|
2702
|
+
__publicField(this, "y");
|
|
2703
|
+
this.x = x ?? 0;
|
|
2704
|
+
this.y = y ?? 0;
|
|
2705
|
+
}
|
|
2706
|
+
length() {
|
|
2707
|
+
return Math.sqrt(this.x * this.x + this.y * this.y);
|
|
2708
|
+
}
|
|
2709
|
+
add(a) {
|
|
2710
|
+
return new _Vec2(this.x + a.x, this.y + a.y);
|
|
2711
|
+
}
|
|
2712
|
+
sub(a) {
|
|
2713
|
+
return new _Vec2(this.x - a.x, this.y - a.y);
|
|
2714
|
+
}
|
|
2715
|
+
mul(a) {
|
|
2716
|
+
return new _Vec2(this.x * a, this.y * a);
|
|
2717
|
+
}
|
|
2718
|
+
div(a) {
|
|
2719
|
+
return new _Vec2(this.x / a, this.y / a);
|
|
2720
|
+
}
|
|
2721
|
+
};
|
|
2722
|
+
|
|
2723
|
+
// src/core/deprecated/small-int-cache.ts
|
|
2724
|
+
var SmallIntCache = class {
|
|
2725
|
+
// for keys < 0
|
|
2726
|
+
constructor() {
|
|
2727
|
+
__publicField(this, "pos");
|
|
2728
|
+
// for keys >= 0
|
|
2729
|
+
__publicField(this, "neg");
|
|
2730
|
+
this.pos = [];
|
|
2731
|
+
this.neg = [];
|
|
2732
|
+
}
|
|
2733
|
+
set(key, value) {
|
|
2734
|
+
if (!isInteger(key)) {
|
|
2735
|
+
throw new Error("Key must be an integer");
|
|
2736
|
+
} else if (key >= 0) {
|
|
2737
|
+
this.pos[key] = value;
|
|
2738
|
+
} else {
|
|
2739
|
+
this.neg[-key - 1] = value;
|
|
2740
|
+
}
|
|
2741
|
+
}
|
|
2742
|
+
get(key) {
|
|
2743
|
+
if (!isInteger(key)) {
|
|
2744
|
+
throw new Error("Key must be an integer");
|
|
2745
|
+
} else if (key >= 0) {
|
|
2746
|
+
return this.pos[key];
|
|
2747
|
+
} else {
|
|
2748
|
+
return this.neg[-key - 1];
|
|
2749
|
+
}
|
|
2750
|
+
}
|
|
2751
|
+
has(key) {
|
|
2752
|
+
if (!isInteger(key)) {
|
|
2753
|
+
return false;
|
|
2754
|
+
} else if (key >= 0) {
|
|
2755
|
+
return key in this.pos;
|
|
2756
|
+
} else {
|
|
2757
|
+
return -key - 1 in this.neg;
|
|
2758
|
+
}
|
|
2759
|
+
}
|
|
2760
|
+
delete(key) {
|
|
2761
|
+
if (!isInteger(key)) {
|
|
2762
|
+
return;
|
|
2763
|
+
} else if (key >= 0) {
|
|
2764
|
+
delete this.pos[key];
|
|
2765
|
+
} else {
|
|
2766
|
+
delete this.neg[-key - 1];
|
|
2767
|
+
}
|
|
2768
|
+
}
|
|
2769
|
+
clear() {
|
|
2770
|
+
this.pos = [];
|
|
2771
|
+
this.neg = [];
|
|
2772
|
+
}
|
|
2773
|
+
};
|
|
2336
2774
|
export {
|
|
2337
2775
|
Assert,
|
|
2338
2776
|
Cookies,
|
|
2339
2777
|
Device,
|
|
2778
|
+
DivRect,
|
|
2340
2779
|
IndexArray,
|
|
2341
2780
|
LRUCache,
|
|
2342
2781
|
Map1,
|
|
@@ -2347,6 +2786,7 @@ export {
|
|
|
2347
2786
|
SmallIntCache,
|
|
2348
2787
|
Stack,
|
|
2349
2788
|
utils_exports as Utils,
|
|
2789
|
+
Vec,
|
|
2350
2790
|
Vec2,
|
|
2351
2791
|
asMulti
|
|
2352
2792
|
};
|