@tspro/ts-utils-lib 1.13.0 → 1.15.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 +18 -0
- package/README.md +10 -4
- package/dist/index.d.mts +258 -128
- package/dist/index.d.ts +258 -128
- package/dist/index.js +783 -299
- package/dist/index.mjs +778 -298
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* TsUtilsLib v1.
|
|
1
|
+
/* TsUtilsLib v1.15.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,14 +26,18 @@ __export(index_exports, {
|
|
|
26
26
|
Assert: () => Assert,
|
|
27
27
|
Cookies: () => Cookies,
|
|
28
28
|
Device: () => Device,
|
|
29
|
+
IndexArray: () => IndexArray,
|
|
29
30
|
LRUCache: () => LRUCache,
|
|
30
31
|
Map1: () => Map1,
|
|
31
32
|
Map2: () => Map2,
|
|
32
33
|
Map3: () => Map3,
|
|
34
|
+
MultiContainer: () => MultiContainer,
|
|
35
|
+
SignedIndexArray: () => SignedIndexArray,
|
|
33
36
|
SmallIntCache: () => SmallIntCache,
|
|
34
37
|
Stack: () => Stack,
|
|
35
38
|
Utils: () => utils_exports,
|
|
36
|
-
Vec2: () => Vec2
|
|
39
|
+
Vec2: () => Vec2,
|
|
40
|
+
asMulti: () => asMulti
|
|
37
41
|
});
|
|
38
42
|
module.exports = __toCommonJS(index_exports);
|
|
39
43
|
|
|
@@ -67,136 +71,175 @@ __export(arr_exports, {
|
|
|
67
71
|
toArray: () => toArray
|
|
68
72
|
});
|
|
69
73
|
|
|
70
|
-
// src/utils/
|
|
71
|
-
var
|
|
72
|
-
__export(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
// src/utils/is/index.ts
|
|
75
|
+
var is_exports = {};
|
|
76
|
+
__export(is_exports, {
|
|
77
|
+
isArray: () => isArray,
|
|
78
|
+
isArrayOrUndefined: () => isArrayOrUndefined,
|
|
79
|
+
isBoolean: () => isBoolean,
|
|
80
|
+
isBooleanOrUndefined: () => isBooleanOrUndefined,
|
|
81
|
+
isEmptyArray: () => isEmptyArray,
|
|
82
|
+
isEmptyArrayOrUndefined: () => isEmptyArrayOrUndefined,
|
|
83
|
+
isEmptyString: () => isEmptyString,
|
|
84
|
+
isEmptyStringOrUndefined: () => isEmptyStringOrUndefined,
|
|
85
|
+
isEnumValue: () => isEnumValue,
|
|
86
|
+
isEnumValueOrUndefined: () => isEnumValueOrUndefined,
|
|
87
|
+
isFinite: () => isFinite2,
|
|
88
|
+
isFunction: () => isFunction,
|
|
89
|
+
isFunctionOrUndefined: () => isFunctionOrUndefined,
|
|
90
|
+
isInfinity: () => isInfinity,
|
|
79
91
|
isInteger: () => isInteger,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
92
|
+
isIntegerBetween: () => isIntegerBetween,
|
|
93
|
+
isIntegerEq: () => isIntegerEq,
|
|
94
|
+
isIntegerGt: () => isIntegerGt,
|
|
95
|
+
isIntegerGte: () => isIntegerGte,
|
|
96
|
+
isIntegerLt: () => isIntegerLt,
|
|
97
|
+
isIntegerLte: () => isIntegerLte,
|
|
98
|
+
isIntegerOrUndefined: () => isIntegerOrUndefined,
|
|
99
|
+
isNaNValue: () => isNaNValue,
|
|
100
|
+
isNegInfinity: () => isNegInfinity,
|
|
101
|
+
isNonEmptyArray: () => isNonEmptyArray,
|
|
102
|
+
isNonEmptyArrayOrUndefined: () => isNonEmptyArrayOrUndefined,
|
|
103
|
+
isNonEmptyString: () => isNonEmptyString,
|
|
104
|
+
isNonEmptyStringOrUndefined: () => isNonEmptyStringOrUndefined,
|
|
105
|
+
isNull: () => isNull,
|
|
106
|
+
isNullish: () => isNullish,
|
|
107
|
+
isNumber: () => isNumber,
|
|
108
|
+
isNumberOrUndefined: () => isNumberOrUndefined,
|
|
109
|
+
isObject: () => isObject,
|
|
110
|
+
isObjectOrUndefined: () => isObjectOrUndefined,
|
|
111
|
+
isPosInfinity: () => isPosInfinity,
|
|
112
|
+
isString: () => isString,
|
|
113
|
+
isStringOrUndefined: () => isStringOrUndefined,
|
|
114
|
+
isUndefined: () => isUndefined
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// src/utils/enum/index.ts
|
|
118
|
+
var enum_exports = {};
|
|
119
|
+
__export(enum_exports, {
|
|
120
|
+
getEnumValues: () => getEnumValues
|
|
85
121
|
});
|
|
122
|
+
function getEnumValues(e) {
|
|
123
|
+
return Object.keys(e).filter((key) => Number.isNaN(Number(key))).map((key) => e[key]);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// src/utils/is/index.ts
|
|
127
|
+
function isUndefined(value) {
|
|
128
|
+
return value === void 0;
|
|
129
|
+
}
|
|
130
|
+
function isNull(value) {
|
|
131
|
+
return value === null;
|
|
132
|
+
}
|
|
133
|
+
function isNullish(value) {
|
|
134
|
+
return value === void 0 || value === null;
|
|
135
|
+
}
|
|
136
|
+
function isObject(value) {
|
|
137
|
+
return typeof value === "object" && value !== null && !isArray(value);
|
|
138
|
+
}
|
|
139
|
+
function isObjectOrUndefined(value) {
|
|
140
|
+
return value === void 0 || isObject(value);
|
|
141
|
+
}
|
|
142
|
+
function isArray(a) {
|
|
143
|
+
return !!a && Object.prototype.toString.call(a) === "[object Array]";
|
|
144
|
+
}
|
|
145
|
+
function isArrayOrUndefined(value) {
|
|
146
|
+
return value === void 0 || isArray(value);
|
|
147
|
+
}
|
|
148
|
+
function isEmptyArray(a) {
|
|
149
|
+
return isArray(a) && a.length === 0;
|
|
150
|
+
}
|
|
151
|
+
function isNonEmptyArray(a) {
|
|
152
|
+
return isArray(a) && a.length > 0;
|
|
153
|
+
}
|
|
154
|
+
function isEmptyArrayOrUndefined(a) {
|
|
155
|
+
return isArray(a) && a.length === 0 || a === void 0;
|
|
156
|
+
}
|
|
157
|
+
function isNonEmptyArrayOrUndefined(a) {
|
|
158
|
+
return isArray(a) && a.length > 0 || a === void 0;
|
|
159
|
+
}
|
|
160
|
+
function isString(value) {
|
|
161
|
+
return typeof value === "string";
|
|
162
|
+
}
|
|
163
|
+
function isEmptyString(value) {
|
|
164
|
+
return typeof value === "string" && value.length === 0;
|
|
165
|
+
}
|
|
166
|
+
function isNonEmptyString(value) {
|
|
167
|
+
return typeof value === "string" && value.length > 0;
|
|
168
|
+
}
|
|
169
|
+
function isStringOrUndefined(value) {
|
|
170
|
+
return value === void 0 || typeof value === "string";
|
|
171
|
+
}
|
|
172
|
+
function isEmptyStringOrUndefined(value) {
|
|
173
|
+
return typeof value === "string" && value.length === 0 || value === void 0;
|
|
174
|
+
}
|
|
175
|
+
function isNonEmptyStringOrUndefined(value) {
|
|
176
|
+
return typeof value === "string" && value.length > 0 || value === void 0;
|
|
177
|
+
}
|
|
178
|
+
function isBoolean(value) {
|
|
179
|
+
return typeof value === "boolean";
|
|
180
|
+
}
|
|
181
|
+
function isBooleanOrUndefined(value) {
|
|
182
|
+
return value === void 0 || typeof value === "boolean";
|
|
183
|
+
}
|
|
184
|
+
function isFunction(value) {
|
|
185
|
+
return typeof value === "function";
|
|
186
|
+
}
|
|
187
|
+
function isFunctionOrUndefined(value) {
|
|
188
|
+
return value === void 0 || typeof value === "function";
|
|
189
|
+
}
|
|
190
|
+
function isEnumValue(value, enumObj, name = "value") {
|
|
191
|
+
return getEnumValues(enumObj).some((v) => v === value);
|
|
192
|
+
}
|
|
193
|
+
function isEnumValueOrUndefined(value, enumObj, name = "value") {
|
|
194
|
+
return value === void 0 || getEnumValues(enumObj).some((v) => v === value);
|
|
195
|
+
}
|
|
196
|
+
function isNumber(value) {
|
|
197
|
+
return typeof value === "number";
|
|
198
|
+
}
|
|
199
|
+
function isNumberOrUndefined(value) {
|
|
200
|
+
return typeof value === "number" || value === void 0;
|
|
201
|
+
}
|
|
202
|
+
function isFinite2(value) {
|
|
203
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
204
|
+
}
|
|
86
205
|
function isInteger(n) {
|
|
87
|
-
return typeof n === "number" &&
|
|
206
|
+
return typeof n === "number" && isFinite2(n) && n === Math.trunc(n);
|
|
88
207
|
}
|
|
89
|
-
function
|
|
90
|
-
|
|
91
|
-
throw new Error("linearToDecibel: Invalid linearVolume = " + linearVolume);
|
|
92
|
-
} else if (linearVolume <= 0) {
|
|
93
|
-
return -Infinity;
|
|
94
|
-
} else {
|
|
95
|
-
return 20 * Math.log10(linearVolume);
|
|
96
|
-
}
|
|
208
|
+
function isIntegerOrUndefined(n) {
|
|
209
|
+
return typeof n === "number" && isFinite2(n) && n === Math.trunc(n) || n === void 0;
|
|
97
210
|
}
|
|
98
|
-
function
|
|
99
|
-
return (
|
|
211
|
+
function isIntegerEq(value, compareTo) {
|
|
212
|
+
return isInteger(value) && value === compareTo;
|
|
100
213
|
}
|
|
101
|
-
function
|
|
102
|
-
|
|
103
|
-
throw new Error("romanize: Invalid n = " + n);
|
|
104
|
-
}
|
|
105
|
-
var digits = String(+n).split("");
|
|
106
|
-
var key = [
|
|
107
|
-
"",
|
|
108
|
-
"C",
|
|
109
|
-
"CC",
|
|
110
|
-
"CCC",
|
|
111
|
-
"CD",
|
|
112
|
-
"D",
|
|
113
|
-
"DC",
|
|
114
|
-
"DCC",
|
|
115
|
-
"DCCC",
|
|
116
|
-
"CM",
|
|
117
|
-
"",
|
|
118
|
-
"X",
|
|
119
|
-
"XX",
|
|
120
|
-
"XXX",
|
|
121
|
-
"XL",
|
|
122
|
-
"L",
|
|
123
|
-
"LX",
|
|
124
|
-
"LXX",
|
|
125
|
-
"LXXX",
|
|
126
|
-
"XC",
|
|
127
|
-
"",
|
|
128
|
-
"I",
|
|
129
|
-
"II",
|
|
130
|
-
"III",
|
|
131
|
-
"IV",
|
|
132
|
-
"V",
|
|
133
|
-
"VI",
|
|
134
|
-
"VII",
|
|
135
|
-
"VIII",
|
|
136
|
-
"IX"
|
|
137
|
-
];
|
|
138
|
-
var roman = "", i = 3;
|
|
139
|
-
while (i--) roman = (key[+digits.pop() + i * 10] || "") + roman;
|
|
140
|
-
return Array(+digits.join("") + 1).join("M") + roman;
|
|
214
|
+
function isIntegerGt(value, compareTo) {
|
|
215
|
+
return isInteger(value) && value > compareTo;
|
|
141
216
|
}
|
|
142
|
-
function
|
|
143
|
-
|
|
144
|
-
throw new Error("toOrdinalNumber: Invalid n = " + n);
|
|
145
|
-
}
|
|
146
|
-
const nStr = n.toString();
|
|
147
|
-
const lastDigit = Number(nStr.charAt(nStr.length - 1));
|
|
148
|
-
if (n === 1 || n >= 20 && lastDigit === 1) {
|
|
149
|
-
return nStr + "st";
|
|
150
|
-
} else if (n === 2 || n >= 20 && lastDigit === 2) {
|
|
151
|
-
return nStr + "nd";
|
|
152
|
-
} else if (n === 3 || n >= 20 && lastDigit === 3) {
|
|
153
|
-
return nStr + "rd";
|
|
154
|
-
} else {
|
|
155
|
-
return nStr + "th";
|
|
156
|
-
}
|
|
217
|
+
function isIntegerGte(value, compareTo) {
|
|
218
|
+
return isInteger(value) && value >= compareTo;
|
|
157
219
|
}
|
|
158
|
-
function
|
|
159
|
-
return
|
|
160
|
-
x: startX + (endX - startX) * t,
|
|
161
|
-
y: startY + (endY - startY) * t
|
|
162
|
-
};
|
|
220
|
+
function isIntegerLt(value, compareTo) {
|
|
221
|
+
return isInteger(value) && value < compareTo;
|
|
163
222
|
}
|
|
164
|
-
function
|
|
165
|
-
|
|
166
|
-
return startY + (endY - startY) * t;
|
|
223
|
+
function isIntegerLte(value, compareTo) {
|
|
224
|
+
return isInteger(value) && value <= compareTo;
|
|
167
225
|
}
|
|
168
|
-
function
|
|
169
|
-
return
|
|
226
|
+
function isIntegerBetween(value, min, max) {
|
|
227
|
+
return isInteger(value) && value >= min && value <= max;
|
|
170
228
|
}
|
|
171
|
-
function
|
|
172
|
-
|
|
173
|
-
let dy = y2 - y1;
|
|
174
|
-
let nx = -dy;
|
|
175
|
-
let ny = dx;
|
|
176
|
-
let len = Math.sqrt(nx * nx + ny * ny);
|
|
177
|
-
if (len > 0) {
|
|
178
|
-
nx /= len;
|
|
179
|
-
ny /= len;
|
|
180
|
-
} else {
|
|
181
|
-
nx = 0;
|
|
182
|
-
ny = 1;
|
|
183
|
-
}
|
|
184
|
-
return { nx, ny };
|
|
229
|
+
function isNaNValue(value) {
|
|
230
|
+
return typeof value === "number" && Number.isNaN(value);
|
|
185
231
|
}
|
|
186
|
-
function
|
|
187
|
-
return
|
|
232
|
+
function isInfinity(value) {
|
|
233
|
+
return typeof value === "number" && Math.abs(value) === Infinity;
|
|
188
234
|
}
|
|
189
|
-
function
|
|
190
|
-
return
|
|
235
|
+
function isPosInfinity(value) {
|
|
236
|
+
return typeof value === "number" && value === Infinity;
|
|
191
237
|
}
|
|
192
|
-
function
|
|
193
|
-
return
|
|
238
|
+
function isNegInfinity(value) {
|
|
239
|
+
return typeof value === "number" && value === -Infinity;
|
|
194
240
|
}
|
|
195
241
|
|
|
196
242
|
// src/utils/arr/index.ts
|
|
197
|
-
function isArray(a) {
|
|
198
|
-
return !!a && Object.prototype.toString.call(a) === "[object Array]";
|
|
199
|
-
}
|
|
200
243
|
function toArray(a) {
|
|
201
244
|
return isArray(a) ? a : [a];
|
|
202
245
|
}
|
|
@@ -283,15 +326,6 @@ __export(dom_exports, {
|
|
|
283
326
|
styleLayoutChanged: () => styleLayoutChanged
|
|
284
327
|
});
|
|
285
328
|
|
|
286
|
-
// src/utils/enum/index.ts
|
|
287
|
-
var enum_exports = {};
|
|
288
|
-
__export(enum_exports, {
|
|
289
|
-
getEnumValues: () => getEnumValues
|
|
290
|
-
});
|
|
291
|
-
function getEnumValues(e) {
|
|
292
|
-
return Object.keys(e).filter((key) => Number.isNaN(Number(key))).map((key) => e[key]);
|
|
293
|
-
}
|
|
294
|
-
|
|
295
329
|
// src/modules/assert.ts
|
|
296
330
|
var Assert;
|
|
297
331
|
((Assert2) => {
|
|
@@ -711,172 +745,139 @@ function getCanvasTextWidth(text, font) {
|
|
|
711
745
|
return ctx.measureText(text).width;
|
|
712
746
|
}
|
|
713
747
|
|
|
714
|
-
// src/utils/
|
|
715
|
-
var
|
|
716
|
-
__export(
|
|
717
|
-
|
|
718
|
-
isArrayOrUndefined: () => isArrayOrUndefined,
|
|
719
|
-
isBoolean: () => isBoolean,
|
|
720
|
-
isBooleanOrUndefined: () => isBooleanOrUndefined,
|
|
721
|
-
isEmptyArray: () => isEmptyArray,
|
|
722
|
-
isEmptyArrayOrUndefined: () => isEmptyArrayOrUndefined,
|
|
723
|
-
isEmptyString: () => isEmptyString,
|
|
724
|
-
isEmptyStringOrUndefined: () => isEmptyStringOrUndefined,
|
|
725
|
-
isEnumValue: () => isEnumValue,
|
|
726
|
-
isEnumValueOrUndefined: () => isEnumValueOrUndefined,
|
|
727
|
-
isFinite: () => isFinite2,
|
|
728
|
-
isFunction: () => isFunction,
|
|
729
|
-
isFunctionOrUndefined: () => isFunctionOrUndefined,
|
|
730
|
-
isInfinity: () => isInfinity,
|
|
731
|
-
isInteger: () => isInteger2,
|
|
732
|
-
isIntegerBetween: () => isIntegerBetween,
|
|
733
|
-
isIntegerEq: () => isIntegerEq,
|
|
734
|
-
isIntegerGt: () => isIntegerGt,
|
|
735
|
-
isIntegerGte: () => isIntegerGte,
|
|
736
|
-
isIntegerLt: () => isIntegerLt,
|
|
737
|
-
isIntegerLte: () => isIntegerLte,
|
|
738
|
-
isIntegerOrUndefined: () => isIntegerOrUndefined,
|
|
739
|
-
isNaNValue: () => isNaNValue,
|
|
740
|
-
isNegInfinity: () => isNegInfinity,
|
|
741
|
-
isNonEmptyArray: () => isNonEmptyArray,
|
|
742
|
-
isNonEmptyArrayOrUndefined: () => isNonEmptyArrayOrUndefined,
|
|
743
|
-
isNonEmptyString: () => isNonEmptyString,
|
|
744
|
-
isNonEmptyStringOrUndefined: () => isNonEmptyStringOrUndefined,
|
|
745
|
-
isNull: () => isNull,
|
|
746
|
-
isNullish: () => isNullish,
|
|
747
|
-
isNumber: () => isNumber,
|
|
748
|
-
isNumberOrUndefined: () => isNumberOrUndefined,
|
|
749
|
-
isObject: () => isObject,
|
|
750
|
-
isObjectOrUndefined: () => isObjectOrUndefined,
|
|
751
|
-
isPosInfinity: () => isPosInfinity,
|
|
752
|
-
isString: () => isString,
|
|
753
|
-
isStringOrUndefined: () => isStringOrUndefined,
|
|
754
|
-
isUndefined: () => isUndefined
|
|
748
|
+
// src/utils/map/index.ts
|
|
749
|
+
var map_exports = {};
|
|
750
|
+
__export(map_exports, {
|
|
751
|
+
getMapKeys: () => getMapKeys
|
|
755
752
|
});
|
|
756
|
-
function
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
return value === null;
|
|
761
|
-
}
|
|
762
|
-
function isNullish(value) {
|
|
763
|
-
return value === void 0 || value === null;
|
|
764
|
-
}
|
|
765
|
-
function isObject(value) {
|
|
766
|
-
return typeof value === "object" && value !== null && !isArray2(value);
|
|
767
|
-
}
|
|
768
|
-
function isObjectOrUndefined(value) {
|
|
769
|
-
return value === void 0 || isObject(value);
|
|
770
|
-
}
|
|
771
|
-
function isArray2(a) {
|
|
772
|
-
return !!a && Object.prototype.toString.call(a) === "[object Array]";
|
|
773
|
-
}
|
|
774
|
-
function isArrayOrUndefined(value) {
|
|
775
|
-
return value === void 0 || isArray2(value);
|
|
776
|
-
}
|
|
777
|
-
function isEmptyArray(a) {
|
|
778
|
-
return isArray2(a) && a.length === 0;
|
|
779
|
-
}
|
|
780
|
-
function isNonEmptyArray(a) {
|
|
781
|
-
return isArray2(a) && a.length > 0;
|
|
782
|
-
}
|
|
783
|
-
function isEmptyArrayOrUndefined(a) {
|
|
784
|
-
return isArray2(a) && a.length === 0 || a === void 0;
|
|
785
|
-
}
|
|
786
|
-
function isNonEmptyArrayOrUndefined(a) {
|
|
787
|
-
return isArray2(a) && a.length > 0 || a === void 0;
|
|
788
|
-
}
|
|
789
|
-
function isString(value) {
|
|
790
|
-
return typeof value === "string";
|
|
791
|
-
}
|
|
792
|
-
function isEmptyString(value) {
|
|
793
|
-
return typeof value === "string" && value.length === 0;
|
|
794
|
-
}
|
|
795
|
-
function isNonEmptyString(value) {
|
|
796
|
-
return typeof value === "string" && value.length > 0;
|
|
797
|
-
}
|
|
798
|
-
function isStringOrUndefined(value) {
|
|
799
|
-
return value === void 0 || typeof value === "string";
|
|
800
|
-
}
|
|
801
|
-
function isEmptyStringOrUndefined(value) {
|
|
802
|
-
return typeof value === "string" && value.length === 0 || value === void 0;
|
|
803
|
-
}
|
|
804
|
-
function isNonEmptyStringOrUndefined(value) {
|
|
805
|
-
return typeof value === "string" && value.length > 0 || value === void 0;
|
|
806
|
-
}
|
|
807
|
-
function isBoolean(value) {
|
|
808
|
-
return typeof value === "boolean";
|
|
809
|
-
}
|
|
810
|
-
function isBooleanOrUndefined(value) {
|
|
811
|
-
return value === void 0 || typeof value === "boolean";
|
|
812
|
-
}
|
|
813
|
-
function isFunction(value) {
|
|
814
|
-
return typeof value === "function";
|
|
815
|
-
}
|
|
816
|
-
function isFunctionOrUndefined(value) {
|
|
817
|
-
return value === void 0 || typeof value === "function";
|
|
818
|
-
}
|
|
819
|
-
function isEnumValue(value, enumObj, name = "value") {
|
|
820
|
-
return getEnumValues(enumObj).some((v) => v === value);
|
|
821
|
-
}
|
|
822
|
-
function isEnumValueOrUndefined(value, enumObj, name = "value") {
|
|
823
|
-
return value === void 0 || getEnumValues(enumObj).some((v) => v === value);
|
|
824
|
-
}
|
|
825
|
-
function isNumber(value) {
|
|
826
|
-
return typeof value === "number";
|
|
827
|
-
}
|
|
828
|
-
function isNumberOrUndefined(value) {
|
|
829
|
-
return typeof value === "number" || value === void 0;
|
|
830
|
-
}
|
|
831
|
-
function isFinite2(value) {
|
|
832
|
-
return typeof value === "number" && Number.isFinite(value);
|
|
833
|
-
}
|
|
834
|
-
function isInteger2(n) {
|
|
835
|
-
return typeof n === "number" && isFinite2(n) && n === Math.trunc(n);
|
|
836
|
-
}
|
|
837
|
-
function isIntegerOrUndefined(n) {
|
|
838
|
-
return typeof n === "number" && isFinite2(n) && n === Math.trunc(n) || n === void 0;
|
|
753
|
+
function getMapKeys(map) {
|
|
754
|
+
let keys = [];
|
|
755
|
+
map.forEach((value, key) => keys.push(key));
|
|
756
|
+
return keys;
|
|
839
757
|
}
|
|
840
|
-
|
|
841
|
-
|
|
758
|
+
|
|
759
|
+
// src/utils/math/index.ts
|
|
760
|
+
var math_exports = {};
|
|
761
|
+
__export(math_exports, {
|
|
762
|
+
avg: () => avg,
|
|
763
|
+
calcNormal: () => calcNormal,
|
|
764
|
+
clamp: () => clamp,
|
|
765
|
+
cmp: () => cmp,
|
|
766
|
+
interpolateCoord: () => interpolateCoord,
|
|
767
|
+
interpolateY: () => interpolateY,
|
|
768
|
+
isInteger: () => isInteger,
|
|
769
|
+
isNumber: () => isNumber,
|
|
770
|
+
linearToDecibels: () => linearToDecibels,
|
|
771
|
+
mod: () => mod,
|
|
772
|
+
romanize: () => romanize,
|
|
773
|
+
sum: () => sum,
|
|
774
|
+
toOrdinalNumber: () => toOrdinalNumber
|
|
775
|
+
});
|
|
776
|
+
function linearToDecibels(linearVolume) {
|
|
777
|
+
if (!isFinite(linearVolume)) {
|
|
778
|
+
throw new Error("linearToDecibel: Invalid linearVolume = " + linearVolume);
|
|
779
|
+
} else if (linearVolume <= 0) {
|
|
780
|
+
return -Infinity;
|
|
781
|
+
} else {
|
|
782
|
+
return 20 * Math.log10(linearVolume);
|
|
783
|
+
}
|
|
842
784
|
}
|
|
843
|
-
function
|
|
844
|
-
return
|
|
785
|
+
function mod(m, n) {
|
|
786
|
+
return (m % n + n) % n;
|
|
845
787
|
}
|
|
846
|
-
function
|
|
847
|
-
|
|
788
|
+
function romanize(n) {
|
|
789
|
+
if (!isInteger(n) || n < 0) {
|
|
790
|
+
throw new Error("romanize: Invalid n = " + n);
|
|
791
|
+
}
|
|
792
|
+
var digits = String(+n).split("");
|
|
793
|
+
var key = [
|
|
794
|
+
"",
|
|
795
|
+
"C",
|
|
796
|
+
"CC",
|
|
797
|
+
"CCC",
|
|
798
|
+
"CD",
|
|
799
|
+
"D",
|
|
800
|
+
"DC",
|
|
801
|
+
"DCC",
|
|
802
|
+
"DCCC",
|
|
803
|
+
"CM",
|
|
804
|
+
"",
|
|
805
|
+
"X",
|
|
806
|
+
"XX",
|
|
807
|
+
"XXX",
|
|
808
|
+
"XL",
|
|
809
|
+
"L",
|
|
810
|
+
"LX",
|
|
811
|
+
"LXX",
|
|
812
|
+
"LXXX",
|
|
813
|
+
"XC",
|
|
814
|
+
"",
|
|
815
|
+
"I",
|
|
816
|
+
"II",
|
|
817
|
+
"III",
|
|
818
|
+
"IV",
|
|
819
|
+
"V",
|
|
820
|
+
"VI",
|
|
821
|
+
"VII",
|
|
822
|
+
"VIII",
|
|
823
|
+
"IX"
|
|
824
|
+
];
|
|
825
|
+
var roman = "", i = 3;
|
|
826
|
+
while (i--) roman = (key[+digits.pop() + i * 10] || "") + roman;
|
|
827
|
+
return Array(+digits.join("") + 1).join("M") + roman;
|
|
848
828
|
}
|
|
849
|
-
function
|
|
850
|
-
|
|
829
|
+
function toOrdinalNumber(n) {
|
|
830
|
+
if (!isInteger(n)) {
|
|
831
|
+
throw new Error("toOrdinalNumber: Invalid n = " + n);
|
|
832
|
+
}
|
|
833
|
+
const nStr = n.toString();
|
|
834
|
+
const lastDigit = Number(nStr.charAt(nStr.length - 1));
|
|
835
|
+
if (n === 1 || n >= 20 && lastDigit === 1) {
|
|
836
|
+
return nStr + "st";
|
|
837
|
+
} else if (n === 2 || n >= 20 && lastDigit === 2) {
|
|
838
|
+
return nStr + "nd";
|
|
839
|
+
} else if (n === 3 || n >= 20 && lastDigit === 3) {
|
|
840
|
+
return nStr + "rd";
|
|
841
|
+
} else {
|
|
842
|
+
return nStr + "th";
|
|
843
|
+
}
|
|
851
844
|
}
|
|
852
|
-
function
|
|
853
|
-
return
|
|
845
|
+
function interpolateCoord(startX, startY, endX, endY, t) {
|
|
846
|
+
return {
|
|
847
|
+
x: startX + (endX - startX) * t,
|
|
848
|
+
y: startY + (endY - startY) * t
|
|
849
|
+
};
|
|
854
850
|
}
|
|
855
|
-
function
|
|
856
|
-
|
|
851
|
+
function interpolateY(startX, startY, endX, endY, x) {
|
|
852
|
+
let t = (x - startX) / (endX - startX);
|
|
853
|
+
return startY + (endY - startY) * t;
|
|
857
854
|
}
|
|
858
|
-
function
|
|
859
|
-
return
|
|
855
|
+
function clamp(num, min, max) {
|
|
856
|
+
return Math.min(Math.max(num, min), max);
|
|
860
857
|
}
|
|
861
|
-
function
|
|
862
|
-
|
|
858
|
+
function calcNormal(x1, y1, x2, y2) {
|
|
859
|
+
let dx = x2 - x1;
|
|
860
|
+
let dy = y2 - y1;
|
|
861
|
+
let nx = -dy;
|
|
862
|
+
let ny = dx;
|
|
863
|
+
let len = Math.sqrt(nx * nx + ny * ny);
|
|
864
|
+
if (len > 0) {
|
|
865
|
+
nx /= len;
|
|
866
|
+
ny /= len;
|
|
867
|
+
} else {
|
|
868
|
+
nx = 0;
|
|
869
|
+
ny = 1;
|
|
870
|
+
}
|
|
871
|
+
return { nx, ny };
|
|
863
872
|
}
|
|
864
|
-
function
|
|
865
|
-
return
|
|
873
|
+
function sum(arr) {
|
|
874
|
+
return arr.reduce((prev, cur) => cur + prev, 0);
|
|
866
875
|
}
|
|
867
|
-
function
|
|
868
|
-
return
|
|
876
|
+
function avg(...values) {
|
|
877
|
+
return sum(values) / values.length;
|
|
869
878
|
}
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
var map_exports = {};
|
|
873
|
-
__export(map_exports, {
|
|
874
|
-
getMapKeys: () => getMapKeys
|
|
875
|
-
});
|
|
876
|
-
function getMapKeys(map) {
|
|
877
|
-
let keys = [];
|
|
878
|
-
map.forEach((value, key) => keys.push(key));
|
|
879
|
-
return keys;
|
|
879
|
+
function cmp(a, b) {
|
|
880
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
880
881
|
}
|
|
881
882
|
|
|
882
883
|
// src/utils/obj/index.ts
|
|
@@ -884,13 +885,10 @@ var obj_exports = {};
|
|
|
884
885
|
__export(obj_exports, {
|
|
885
886
|
deepEqual: () => deepEqual,
|
|
886
887
|
hasProperties: () => hasProperties,
|
|
887
|
-
isObject: () =>
|
|
888
|
+
isObject: () => isObject
|
|
888
889
|
});
|
|
889
|
-
function isObject2(obj) {
|
|
890
|
-
return typeof obj === "object" && obj !== null && !isArray(obj);
|
|
891
|
-
}
|
|
892
890
|
function hasProperties(obj, props) {
|
|
893
|
-
return
|
|
891
|
+
return isObject(obj) && props.every((p) => p in obj);
|
|
894
892
|
}
|
|
895
893
|
function deepEqual(a, b) {
|
|
896
894
|
if (a === b) return true;
|
|
@@ -917,6 +915,7 @@ __export(str_exports, {
|
|
|
917
915
|
charCount: () => charCount,
|
|
918
916
|
chunkString: () => chunkString,
|
|
919
917
|
insertAt: () => insertAt,
|
|
918
|
+
isString: () => isString,
|
|
920
919
|
makeSentenceFromPascal: () => makeSentenceFromPascal,
|
|
921
920
|
removeAt: () => removeAt,
|
|
922
921
|
repeatString: () => repeatString,
|
|
@@ -1292,6 +1291,444 @@ var SmallIntCache = class {
|
|
|
1292
1291
|
}
|
|
1293
1292
|
};
|
|
1294
1293
|
|
|
1294
|
+
// src/core/index-array.ts
|
|
1295
|
+
var IndexArray = class _IndexArray {
|
|
1296
|
+
constructor(entries) {
|
|
1297
|
+
// for indexes >= 0
|
|
1298
|
+
__publicField(this, "posEl");
|
|
1299
|
+
__publicField(this, "hasPos");
|
|
1300
|
+
// number of elems
|
|
1301
|
+
__publicField(this, "elCount");
|
|
1302
|
+
if (entries instanceof _IndexArray) {
|
|
1303
|
+
this.posEl = entries.posEl.slice();
|
|
1304
|
+
this.hasPos = entries.hasPos.slice();
|
|
1305
|
+
this.elCount = entries.elCount;
|
|
1306
|
+
} else {
|
|
1307
|
+
this.posEl = [];
|
|
1308
|
+
this.hasPos = [];
|
|
1309
|
+
this.elCount = 0;
|
|
1310
|
+
if (entries) {
|
|
1311
|
+
for (const [id, el] of entries) {
|
|
1312
|
+
this.set(id, el);
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
static toNegIndex(id) {
|
|
1318
|
+
return -id - 1;
|
|
1319
|
+
}
|
|
1320
|
+
static validateIndex(id) {
|
|
1321
|
+
if (!isIntegerGte(id, 0)) throw new Error(`Invalid index ${id} - must be an integer >= 0!`);
|
|
1322
|
+
return id;
|
|
1323
|
+
}
|
|
1324
|
+
get size() {
|
|
1325
|
+
return this.elCount;
|
|
1326
|
+
}
|
|
1327
|
+
get posLen() {
|
|
1328
|
+
return this.hasPos.length;
|
|
1329
|
+
}
|
|
1330
|
+
has(id) {
|
|
1331
|
+
_IndexArray.validateIndex(id);
|
|
1332
|
+
return this.hasPos[id] === true;
|
|
1333
|
+
}
|
|
1334
|
+
set(id, el) {
|
|
1335
|
+
_IndexArray.validateIndex(id);
|
|
1336
|
+
if (this.hasPos[id] !== true) this.elCount++;
|
|
1337
|
+
this.posEl[id] = el;
|
|
1338
|
+
this.hasPos[id] = true;
|
|
1339
|
+
}
|
|
1340
|
+
get(id) {
|
|
1341
|
+
_IndexArray.validateIndex(id);
|
|
1342
|
+
return this.hasPos[id] ? this.posEl[id] : void 0;
|
|
1343
|
+
}
|
|
1344
|
+
getOrDefault(id, defaultValue) {
|
|
1345
|
+
return this.get(id) ?? defaultValue;
|
|
1346
|
+
}
|
|
1347
|
+
getOrCreate(id, creatorOrValue) {
|
|
1348
|
+
if (!this.has(id)) {
|
|
1349
|
+
const value = isFunction(creatorOrValue) ? creatorOrValue() : creatorOrValue;
|
|
1350
|
+
this.set(id, value);
|
|
1351
|
+
return value;
|
|
1352
|
+
}
|
|
1353
|
+
return this.get(id);
|
|
1354
|
+
}
|
|
1355
|
+
delete(id) {
|
|
1356
|
+
_IndexArray.validateIndex(id);
|
|
1357
|
+
if (!this.hasPos[id]) return false;
|
|
1358
|
+
this.posEl[id] = void 0;
|
|
1359
|
+
this.hasPos[id] = false;
|
|
1360
|
+
this.elCount--;
|
|
1361
|
+
return true;
|
|
1362
|
+
}
|
|
1363
|
+
clear() {
|
|
1364
|
+
this.posEl = [];
|
|
1365
|
+
this.hasPos = [];
|
|
1366
|
+
this.elCount = 0;
|
|
1367
|
+
}
|
|
1368
|
+
forEach(callbackfn, thisArg) {
|
|
1369
|
+
for (const [id, el] of this.entries()) {
|
|
1370
|
+
callbackfn.call(thisArg, el, id, this);
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
*indices() {
|
|
1374
|
+
for (let id = 0; id < this.posLen; id++) {
|
|
1375
|
+
if (this.hasPos[id]) yield id;
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
indicesArray() {
|
|
1379
|
+
return [...this.indices()];
|
|
1380
|
+
}
|
|
1381
|
+
*values() {
|
|
1382
|
+
for (let id = 0; id < this.posLen; id++) {
|
|
1383
|
+
if (this.hasPos[id]) yield this.posEl[id];
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
valuesArray() {
|
|
1387
|
+
return [...this.values()];
|
|
1388
|
+
}
|
|
1389
|
+
*entries() {
|
|
1390
|
+
for (let id = 0; id < this.posLen; id++) {
|
|
1391
|
+
if (this.hasPos[id]) yield [id, this.posEl[id]];
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
entriesArray() {
|
|
1395
|
+
return [...this.entries()];
|
|
1396
|
+
}
|
|
1397
|
+
*[Symbol.iterator]() {
|
|
1398
|
+
yield* this.entries();
|
|
1399
|
+
}
|
|
1400
|
+
clone() {
|
|
1401
|
+
return new _IndexArray(this);
|
|
1402
|
+
}
|
|
1403
|
+
merge(other, conflictResolver) {
|
|
1404
|
+
for (const [id, value] of other.entries()) {
|
|
1405
|
+
if (this.has(id) && conflictResolver) {
|
|
1406
|
+
this.set(id, conflictResolver(this.get(id), value, id));
|
|
1407
|
+
} else {
|
|
1408
|
+
this.set(id, value);
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
return this;
|
|
1412
|
+
}
|
|
1413
|
+
some(fn) {
|
|
1414
|
+
for (const [id, el] of this.entries()) {
|
|
1415
|
+
if (fn(el, id)) return true;
|
|
1416
|
+
}
|
|
1417
|
+
return false;
|
|
1418
|
+
}
|
|
1419
|
+
every(fn) {
|
|
1420
|
+
for (const [id, el] of this.entries()) {
|
|
1421
|
+
if (!fn(el, id)) return false;
|
|
1422
|
+
}
|
|
1423
|
+
return true;
|
|
1424
|
+
}
|
|
1425
|
+
filter(fn) {
|
|
1426
|
+
let result = new _IndexArray();
|
|
1427
|
+
for (const [id, el] of this.entries()) {
|
|
1428
|
+
if (fn(el, id)) result.set(id, el);
|
|
1429
|
+
}
|
|
1430
|
+
return result;
|
|
1431
|
+
}
|
|
1432
|
+
reduce(fn, init) {
|
|
1433
|
+
let iterator = this.entries();
|
|
1434
|
+
let first = iterator.next();
|
|
1435
|
+
if (first.done) {
|
|
1436
|
+
if (arguments.length < 2) {
|
|
1437
|
+
throw new TypeError("Reduce of empty IndexArray with no initial value!");
|
|
1438
|
+
}
|
|
1439
|
+
return init;
|
|
1440
|
+
}
|
|
1441
|
+
let acc;
|
|
1442
|
+
let start;
|
|
1443
|
+
if (arguments.length < 2) {
|
|
1444
|
+
acc = first.value[1];
|
|
1445
|
+
start = iterator.next();
|
|
1446
|
+
} else {
|
|
1447
|
+
acc = init;
|
|
1448
|
+
start = first;
|
|
1449
|
+
}
|
|
1450
|
+
for (let current = start; !current.done; current = iterator.next()) {
|
|
1451
|
+
const [id, el] = current.value;
|
|
1452
|
+
acc = fn(acc, el, id);
|
|
1453
|
+
}
|
|
1454
|
+
return acc;
|
|
1455
|
+
}
|
|
1456
|
+
mapToArray(fn) {
|
|
1457
|
+
let result = [];
|
|
1458
|
+
for (const [id, el] of this.entries()) {
|
|
1459
|
+
result.push(fn(el, id));
|
|
1460
|
+
}
|
|
1461
|
+
return result;
|
|
1462
|
+
}
|
|
1463
|
+
map(fn) {
|
|
1464
|
+
let result = new _IndexArray();
|
|
1465
|
+
for (const [id, el] of this.entries()) {
|
|
1466
|
+
result.set(id, fn(el, id));
|
|
1467
|
+
}
|
|
1468
|
+
return result;
|
|
1469
|
+
}
|
|
1470
|
+
equals(other, eq) {
|
|
1471
|
+
if (this.size !== other.size) return false;
|
|
1472
|
+
eq ?? (eq = (a, b) => a === b);
|
|
1473
|
+
const posLen = Math.max(this.posLen, other.posLen);
|
|
1474
|
+
for (let i = 0; i < posLen; ++i) {
|
|
1475
|
+
const hasA = this.hasPos[i];
|
|
1476
|
+
const hasB = other.hasPos[i];
|
|
1477
|
+
if (hasA !== hasB) return false;
|
|
1478
|
+
if (hasA && !eq(this.posEl[i], other.posEl[i])) return false;
|
|
1479
|
+
}
|
|
1480
|
+
return true;
|
|
1481
|
+
}
|
|
1482
|
+
toString() {
|
|
1483
|
+
if (this.size === 0) return `IndexArray[ ]`;
|
|
1484
|
+
const entries = this.entriesArray().map(([id, el]) => `${id}: ${el}`).join(", ");
|
|
1485
|
+
return `IndexArray[ ${entries} ]`;
|
|
1486
|
+
}
|
|
1487
|
+
};
|
|
1488
|
+
|
|
1489
|
+
// src/core/signed-index-array.ts
|
|
1490
|
+
var SignedIndexArray = class _SignedIndexArray {
|
|
1491
|
+
constructor(entries) {
|
|
1492
|
+
// for indexes >= 0
|
|
1493
|
+
__publicField(this, "posEl");
|
|
1494
|
+
__publicField(this, "hasPos");
|
|
1495
|
+
// for indexes < 0
|
|
1496
|
+
__publicField(this, "negEl");
|
|
1497
|
+
__publicField(this, "hasNeg");
|
|
1498
|
+
// number of elems
|
|
1499
|
+
__publicField(this, "elCount");
|
|
1500
|
+
if (entries instanceof _SignedIndexArray) {
|
|
1501
|
+
this.negEl = entries.negEl.slice();
|
|
1502
|
+
this.hasNeg = entries.hasNeg.slice();
|
|
1503
|
+
this.posEl = entries.posEl.slice();
|
|
1504
|
+
this.hasPos = entries.hasPos.slice();
|
|
1505
|
+
this.elCount = entries.elCount;
|
|
1506
|
+
} else {
|
|
1507
|
+
this.negEl = [];
|
|
1508
|
+
this.hasNeg = [];
|
|
1509
|
+
this.posEl = [];
|
|
1510
|
+
this.hasPos = [];
|
|
1511
|
+
this.elCount = 0;
|
|
1512
|
+
if (entries) {
|
|
1513
|
+
for (const [id, el] of entries) {
|
|
1514
|
+
this.set(id, el);
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
static toNegIndex(id) {
|
|
1520
|
+
return -id - 1;
|
|
1521
|
+
}
|
|
1522
|
+
static validateIndex(id) {
|
|
1523
|
+
if (!isInteger(id)) throw new Error(`Invalid index ${id} - must be an integer!`);
|
|
1524
|
+
return id;
|
|
1525
|
+
}
|
|
1526
|
+
get size() {
|
|
1527
|
+
return this.elCount;
|
|
1528
|
+
}
|
|
1529
|
+
get posLen() {
|
|
1530
|
+
return this.hasPos.length;
|
|
1531
|
+
}
|
|
1532
|
+
get negLen() {
|
|
1533
|
+
return this.hasNeg.length;
|
|
1534
|
+
}
|
|
1535
|
+
has(id) {
|
|
1536
|
+
_SignedIndexArray.validateIndex(id);
|
|
1537
|
+
if (id >= 0) {
|
|
1538
|
+
return this.hasPos[id] === true;
|
|
1539
|
+
} else {
|
|
1540
|
+
return this.hasNeg[_SignedIndexArray.toNegIndex(id)] === true;
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
set(id, el) {
|
|
1544
|
+
_SignedIndexArray.validateIndex(id);
|
|
1545
|
+
if (id >= 0) {
|
|
1546
|
+
if (this.hasPos[id] !== true) this.elCount++;
|
|
1547
|
+
this.posEl[id] = el;
|
|
1548
|
+
this.hasPos[id] = true;
|
|
1549
|
+
} else {
|
|
1550
|
+
let negId = _SignedIndexArray.toNegIndex(id);
|
|
1551
|
+
if (this.hasNeg[negId] !== true) this.elCount++;
|
|
1552
|
+
this.negEl[negId] = el;
|
|
1553
|
+
this.hasNeg[negId] = true;
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
get(id) {
|
|
1557
|
+
_SignedIndexArray.validateIndex(id);
|
|
1558
|
+
if (id >= 0) {
|
|
1559
|
+
return this.hasPos[id] ? this.posEl[id] : void 0;
|
|
1560
|
+
} else {
|
|
1561
|
+
let negId = _SignedIndexArray.toNegIndex(id);
|
|
1562
|
+
return this.hasNeg[negId] ? this.negEl[negId] : void 0;
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
getOrDefault(id, defaultValue) {
|
|
1566
|
+
return this.get(id) ?? defaultValue;
|
|
1567
|
+
}
|
|
1568
|
+
getOrCreate(id, creatorOrValue) {
|
|
1569
|
+
if (!this.has(id)) {
|
|
1570
|
+
const value = isFunction(creatorOrValue) ? creatorOrValue() : creatorOrValue;
|
|
1571
|
+
this.set(id, value);
|
|
1572
|
+
return value;
|
|
1573
|
+
}
|
|
1574
|
+
return this.get(id);
|
|
1575
|
+
}
|
|
1576
|
+
delete(id) {
|
|
1577
|
+
_SignedIndexArray.validateIndex(id);
|
|
1578
|
+
const isPos = id >= 0;
|
|
1579
|
+
const arr = isPos ? this.posEl : this.negEl;
|
|
1580
|
+
const has = isPos ? this.hasPos : this.hasNeg;
|
|
1581
|
+
const idx = isPos ? id : _SignedIndexArray.toNegIndex(id);
|
|
1582
|
+
if (!has[idx]) return false;
|
|
1583
|
+
arr[idx] = void 0;
|
|
1584
|
+
has[idx] = false;
|
|
1585
|
+
this.elCount--;
|
|
1586
|
+
return true;
|
|
1587
|
+
}
|
|
1588
|
+
clear() {
|
|
1589
|
+
this.negEl = [];
|
|
1590
|
+
this.hasNeg = [];
|
|
1591
|
+
this.posEl = [];
|
|
1592
|
+
this.hasPos = [];
|
|
1593
|
+
this.elCount = 0;
|
|
1594
|
+
}
|
|
1595
|
+
forEach(callbackfn, thisArg) {
|
|
1596
|
+
for (const [id, el] of this.entries()) {
|
|
1597
|
+
callbackfn.call(thisArg, el, id, this);
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
*indices() {
|
|
1601
|
+
for (let id = this.negLen - 1; id >= 0; id--) {
|
|
1602
|
+
if (this.hasNeg[id]) yield _SignedIndexArray.toNegIndex(id);
|
|
1603
|
+
}
|
|
1604
|
+
for (let id = 0; id < this.posLen; id++) {
|
|
1605
|
+
if (this.hasPos[id]) yield id;
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
indicesArray() {
|
|
1609
|
+
return [...this.indices()];
|
|
1610
|
+
}
|
|
1611
|
+
*values() {
|
|
1612
|
+
for (let id = this.negLen - 1; id >= 0; id--) {
|
|
1613
|
+
if (this.hasNeg[id]) yield this.negEl[id];
|
|
1614
|
+
}
|
|
1615
|
+
for (let id = 0; id < this.posLen; id++) {
|
|
1616
|
+
if (this.hasPos[id]) yield this.posEl[id];
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
valuesArray() {
|
|
1620
|
+
return [...this.values()];
|
|
1621
|
+
}
|
|
1622
|
+
*entries() {
|
|
1623
|
+
for (let id = this.negLen - 1; id >= 0; id--) {
|
|
1624
|
+
if (this.hasNeg[id]) yield [_SignedIndexArray.toNegIndex(id), this.negEl[id]];
|
|
1625
|
+
}
|
|
1626
|
+
for (let id = 0; id < this.posLen; id++) {
|
|
1627
|
+
if (this.hasPos[id]) yield [id, this.posEl[id]];
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
entriesArray() {
|
|
1631
|
+
return [...this.entries()];
|
|
1632
|
+
}
|
|
1633
|
+
*[Symbol.iterator]() {
|
|
1634
|
+
yield* this.entries();
|
|
1635
|
+
}
|
|
1636
|
+
clone() {
|
|
1637
|
+
return new _SignedIndexArray(this);
|
|
1638
|
+
}
|
|
1639
|
+
merge(other, conflictResolver) {
|
|
1640
|
+
for (const [id, value] of other.entries()) {
|
|
1641
|
+
if (this.has(id) && conflictResolver) {
|
|
1642
|
+
this.set(id, conflictResolver(this.get(id), value, id));
|
|
1643
|
+
} else {
|
|
1644
|
+
this.set(id, value);
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
return this;
|
|
1648
|
+
}
|
|
1649
|
+
some(fn) {
|
|
1650
|
+
for (const [id, el] of this.entries()) {
|
|
1651
|
+
if (fn(el, id)) return true;
|
|
1652
|
+
}
|
|
1653
|
+
return false;
|
|
1654
|
+
}
|
|
1655
|
+
every(fn) {
|
|
1656
|
+
for (const [id, el] of this.entries()) {
|
|
1657
|
+
if (!fn(el, id)) return false;
|
|
1658
|
+
}
|
|
1659
|
+
return true;
|
|
1660
|
+
}
|
|
1661
|
+
filter(fn) {
|
|
1662
|
+
let result = new _SignedIndexArray();
|
|
1663
|
+
for (const [id, el] of this.entries()) {
|
|
1664
|
+
if (fn(el, id)) result.set(id, el);
|
|
1665
|
+
}
|
|
1666
|
+
return result;
|
|
1667
|
+
}
|
|
1668
|
+
reduce(fn, init) {
|
|
1669
|
+
let iterator = this.entries();
|
|
1670
|
+
let first = iterator.next();
|
|
1671
|
+
if (first.done) {
|
|
1672
|
+
if (arguments.length < 2) {
|
|
1673
|
+
throw new TypeError("Reduce of empty SignedIndexArray with no initial value!");
|
|
1674
|
+
}
|
|
1675
|
+
return init;
|
|
1676
|
+
}
|
|
1677
|
+
let acc;
|
|
1678
|
+
let start;
|
|
1679
|
+
if (arguments.length < 2) {
|
|
1680
|
+
acc = first.value[1];
|
|
1681
|
+
start = iterator.next();
|
|
1682
|
+
} else {
|
|
1683
|
+
acc = init;
|
|
1684
|
+
start = first;
|
|
1685
|
+
}
|
|
1686
|
+
for (let current = start; !current.done; current = iterator.next()) {
|
|
1687
|
+
const [id, el] = current.value;
|
|
1688
|
+
acc = fn(acc, el, id);
|
|
1689
|
+
}
|
|
1690
|
+
return acc;
|
|
1691
|
+
}
|
|
1692
|
+
mapToArray(fn) {
|
|
1693
|
+
let result = [];
|
|
1694
|
+
for (const [id, el] of this.entries()) {
|
|
1695
|
+
result.push(fn(el, id));
|
|
1696
|
+
}
|
|
1697
|
+
return result;
|
|
1698
|
+
}
|
|
1699
|
+
map(fn) {
|
|
1700
|
+
let result = new _SignedIndexArray();
|
|
1701
|
+
for (const [id, el] of this.entries()) {
|
|
1702
|
+
result.set(id, fn(el, id));
|
|
1703
|
+
}
|
|
1704
|
+
return result;
|
|
1705
|
+
}
|
|
1706
|
+
equals(other, eq) {
|
|
1707
|
+
if (this.size !== other.size) return false;
|
|
1708
|
+
eq ?? (eq = (a, b) => a === b);
|
|
1709
|
+
const posLen = Math.max(this.posLen, other.posLen);
|
|
1710
|
+
for (let i = 0; i < posLen; ++i) {
|
|
1711
|
+
const hasA = this.hasPos[i];
|
|
1712
|
+
const hasB = other.hasPos[i];
|
|
1713
|
+
if (hasA !== hasB) return false;
|
|
1714
|
+
if (hasA && !eq(this.posEl[i], other.posEl[i])) return false;
|
|
1715
|
+
}
|
|
1716
|
+
const negLen = Math.max(this.negLen, other.negLen);
|
|
1717
|
+
for (let i = 0; i < negLen; ++i) {
|
|
1718
|
+
const hasA = this.hasNeg[i];
|
|
1719
|
+
const hasB = other.hasNeg[i];
|
|
1720
|
+
if (hasA !== hasB) return false;
|
|
1721
|
+
if (hasA && !eq(this.negEl[i], other.negEl[i])) return false;
|
|
1722
|
+
}
|
|
1723
|
+
return true;
|
|
1724
|
+
}
|
|
1725
|
+
toString() {
|
|
1726
|
+
if (this.size === 0) return `SignedIndexArray[ ]`;
|
|
1727
|
+
const entries = this.entriesArray().map(([id, el]) => `${id}: ${el}`).join(", ");
|
|
1728
|
+
return `SignedIndexArray[ ${entries} ]`;
|
|
1729
|
+
}
|
|
1730
|
+
};
|
|
1731
|
+
|
|
1295
1732
|
// src/core/map.ts
|
|
1296
1733
|
var Map1 = class _Map1 {
|
|
1297
1734
|
constructor(entries) {
|
|
@@ -1311,12 +1748,13 @@ var Map1 = class _Map1 {
|
|
|
1311
1748
|
getOrDefault(key1, defaultValue) {
|
|
1312
1749
|
return this.get(key1) ?? defaultValue;
|
|
1313
1750
|
}
|
|
1314
|
-
getOrCreate(key1,
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
this.set(key1, value
|
|
1751
|
+
getOrCreate(key1, creatorOrValue) {
|
|
1752
|
+
if (!this.has(key1)) {
|
|
1753
|
+
const value = isFunction(creatorOrValue) ? creatorOrValue() : creatorOrValue;
|
|
1754
|
+
this.set(key1, value);
|
|
1755
|
+
return value;
|
|
1318
1756
|
}
|
|
1319
|
-
return
|
|
1757
|
+
return this.get(key1);
|
|
1320
1758
|
}
|
|
1321
1759
|
delete(key1) {
|
|
1322
1760
|
return this.map1.delete(key1);
|
|
@@ -1440,12 +1878,13 @@ var Map2 = class _Map2 {
|
|
|
1440
1878
|
getOrDefault(key1, key2, defaultValue) {
|
|
1441
1879
|
return this.get(key1, key2) ?? defaultValue;
|
|
1442
1880
|
}
|
|
1443
|
-
getOrCreate(key1, key2,
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
this.set(key1, key2, value
|
|
1881
|
+
getOrCreate(key1, key2, creatorOrValue) {
|
|
1882
|
+
if (!this.has(key1, key2)) {
|
|
1883
|
+
const value = isFunction(creatorOrValue) ? creatorOrValue() : creatorOrValue;
|
|
1884
|
+
this.set(key1, key2, value);
|
|
1885
|
+
return value;
|
|
1447
1886
|
}
|
|
1448
|
-
return
|
|
1887
|
+
return this.get(key1, key2);
|
|
1449
1888
|
}
|
|
1450
1889
|
delete(key1, key2) {
|
|
1451
1890
|
if (key2 === void 0) return this.map1.delete(key1);
|
|
@@ -1616,12 +2055,13 @@ var Map3 = class _Map3 {
|
|
|
1616
2055
|
getOrDefault(key1, key2, key3, defaultValue) {
|
|
1617
2056
|
return this.get(key1, key2, key3) ?? defaultValue;
|
|
1618
2057
|
}
|
|
1619
|
-
getOrCreate(key1, key2, key3,
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
this.set(key1, key2, key3, value
|
|
2058
|
+
getOrCreate(key1, key2, key3, creatorOrValue) {
|
|
2059
|
+
if (!this.has(key1, key2, key3)) {
|
|
2060
|
+
const value = isFunction(creatorOrValue) ? creatorOrValue() : creatorOrValue;
|
|
2061
|
+
this.set(key1, key2, key3, value);
|
|
2062
|
+
return value;
|
|
1623
2063
|
}
|
|
1624
|
-
return
|
|
2064
|
+
return this.get(key1, key2, key3);
|
|
1625
2065
|
}
|
|
1626
2066
|
delete(key1, key2, key3) {
|
|
1627
2067
|
if (key3 === void 0) {
|
|
@@ -1786,18 +2226,62 @@ var Map3 = class _Map3 {
|
|
|
1786
2226
|
return `Map3(${this.size}) { ${entries.join(", ")} }`;
|
|
1787
2227
|
}
|
|
1788
2228
|
};
|
|
2229
|
+
|
|
2230
|
+
// src/core/multi-container.ts
|
|
2231
|
+
var MultiContainer = class {
|
|
2232
|
+
constructor(base) {
|
|
2233
|
+
this.base = base;
|
|
2234
|
+
}
|
|
2235
|
+
add(...keysAndValue) {
|
|
2236
|
+
const keys = keysAndValue.slice(0, -1);
|
|
2237
|
+
const value = keysAndValue[keysAndValue.length - 1];
|
|
2238
|
+
const arr = this.base.get(...keys);
|
|
2239
|
+
this.base.set(...[...keys, arr ? [...arr, value] : [value]]);
|
|
2240
|
+
return value;
|
|
2241
|
+
}
|
|
2242
|
+
remove(...keysAndValue) {
|
|
2243
|
+
const keys = keysAndValue.slice(0, -1);
|
|
2244
|
+
const value = keysAndValue[keysAndValue.length - 1];
|
|
2245
|
+
const arr = this.base.get(...keys);
|
|
2246
|
+
if (!arr) return false;
|
|
2247
|
+
const i = arr.indexOf(value);
|
|
2248
|
+
if (i === -1) return false;
|
|
2249
|
+
arr.splice(i, 1);
|
|
2250
|
+
if (arr.length === 0) this.base.delete(...keys);
|
|
2251
|
+
return true;
|
|
2252
|
+
}
|
|
2253
|
+
getAll(...keys) {
|
|
2254
|
+
return this.base.get(...keys) ?? [];
|
|
2255
|
+
}
|
|
2256
|
+
*iterAll(...keys) {
|
|
2257
|
+
const arr = this.getAll(...keys);
|
|
2258
|
+
for (const v of arr) {
|
|
2259
|
+
yield v;
|
|
2260
|
+
}
|
|
2261
|
+
}
|
|
2262
|
+
clear() {
|
|
2263
|
+
this.base.clear?.();
|
|
2264
|
+
}
|
|
2265
|
+
};
|
|
2266
|
+
function asMulti(base) {
|
|
2267
|
+
return new MultiContainer(base);
|
|
2268
|
+
}
|
|
1789
2269
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1790
2270
|
0 && (module.exports = {
|
|
1791
2271
|
Assert,
|
|
1792
2272
|
Cookies,
|
|
1793
2273
|
Device,
|
|
2274
|
+
IndexArray,
|
|
1794
2275
|
LRUCache,
|
|
1795
2276
|
Map1,
|
|
1796
2277
|
Map2,
|
|
1797
2278
|
Map3,
|
|
2279
|
+
MultiContainer,
|
|
2280
|
+
SignedIndexArray,
|
|
1798
2281
|
SmallIntCache,
|
|
1799
2282
|
Stack,
|
|
1800
2283
|
Utils,
|
|
1801
|
-
Vec2
|
|
2284
|
+
Vec2,
|
|
2285
|
+
asMulti
|
|
1802
2286
|
});
|
|
1803
2287
|
//# sourceMappingURL=index.js.map
|