@tspro/ts-utils-lib 1.0.1 → 1.2.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.
@@ -1,1101 +0,0 @@
1
- /******/ // The require scope
2
- /******/ var __webpack_require__ = {};
3
- /******/
4
- /************************************************************************/
5
- /******/ /* webpack/runtime/define property getters */
6
- /******/ (() => {
7
- /******/ // define getter functions for harmony exports
8
- /******/ __webpack_require__.d = (exports, definition) => {
9
- /******/ for(var key in definition) {
10
- /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
11
- /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
12
- /******/ }
13
- /******/ }
14
- /******/ };
15
- /******/ })();
16
- /******/
17
- /******/ /* webpack/runtime/hasOwnProperty shorthand */
18
- /******/ (() => {
19
- /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
20
- /******/ })();
21
- /******/
22
- /******/ /* webpack/runtime/make namespace object */
23
- /******/ (() => {
24
- /******/ // define __esModule on exports
25
- /******/ __webpack_require__.r = (exports) => {
26
- /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
27
- /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
28
- /******/ }
29
- /******/ Object.defineProperty(exports, '__esModule', { value: true });
30
- /******/ };
31
- /******/ })();
32
- /******/
33
- /************************************************************************/
34
-
35
- // NAMESPACE OBJECT: ./src/math/index.ts
36
- var math_namespaceObject = {};
37
- __webpack_require__.r(math_namespaceObject);
38
- __webpack_require__.d(math_namespaceObject, {
39
- calcNormal: () => (calcNormal),
40
- clamp: () => (clamp),
41
- interpolateCoord: () => (interpolateCoord),
42
- interpolateY: () => (interpolateY),
43
- isInteger: () => (isInteger),
44
- linearToDecibels: () => (linearToDecibels),
45
- mod: () => (mod),
46
- romanize: () => (romanize),
47
- sum: () => (sum),
48
- toOrdinalNumber: () => (toOrdinalNumber)
49
- });
50
-
51
- // NAMESPACE OBJECT: ./src/array/index.ts
52
- var array_namespaceObject = {};
53
- __webpack_require__.r(array_namespaceObject);
54
- __webpack_require__.d(array_namespaceObject, {
55
- arrayContains: () => (arrayContains),
56
- chunckArray: () => (chunckArray),
57
- duplicate: () => (duplicate),
58
- fillArray: () => (fillArray),
59
- getRangeArray: () => (getRangeArray),
60
- getSequenceArray: () => (getSequenceArray),
61
- isArray: () => (isArray),
62
- mapRangeArray: () => (mapRangeArray),
63
- mapSequenceArray: () => (mapSequenceArray),
64
- removeDuplicates: () => (removeDuplicates),
65
- removeDuplicatesCmp: () => (removeDuplicatesCmp),
66
- toArray: () => (toArray)
67
- });
68
-
69
- // NAMESPACE OBJECT: ./src/dom/index.ts
70
- var dom_namespaceObject = {};
71
- __webpack_require__.r(dom_namespaceObject);
72
- __webpack_require__.d(dom_namespaceObject, {
73
- addClass: () => (addClass),
74
- appendTo: () => (appendTo),
75
- getButton: () => (getButton),
76
- getCanvas: () => (getCanvas),
77
- getCanvasTextWidth: () => (getCanvasTextWidth),
78
- getDimension: () => (getDimension),
79
- getHeight: () => (getHeight),
80
- getOffset: () => (getOffset),
81
- getPadding: () => (getPadding),
82
- getWidth: () => (getWidth),
83
- hasClass: () => (hasClass),
84
- removeClass: () => (removeClass),
85
- removeFromParent: () => (removeFromParent),
86
- setHeight: () => (setHeight),
87
- setOffset: () => (setOffset),
88
- setRect: () => (setRect),
89
- setVisibility: () => (setVisibility),
90
- setWidth: () => (setWidth),
91
- styleLayoutChanged: () => (styleLayoutChanged)
92
- });
93
-
94
- // NAMESPACE OBJECT: ./src/enum/index.ts
95
- var enum_namespaceObject = {};
96
- __webpack_require__.r(enum_namespaceObject);
97
- __webpack_require__.d(enum_namespaceObject, {
98
- getEnumValues: () => (getEnumValues)
99
- });
100
-
101
- // NAMESPACE OBJECT: ./src/map/index.ts
102
- var map_namespaceObject = {};
103
- __webpack_require__.r(map_namespaceObject);
104
- __webpack_require__.d(map_namespaceObject, {
105
- getMapKeys: () => (getMapKeys)
106
- });
107
-
108
- // NAMESPACE OBJECT: ./src/string/index.ts
109
- var string_namespaceObject = {};
110
- __webpack_require__.r(string_namespaceObject);
111
- __webpack_require__.d(string_namespaceObject, {
112
- chunkString: () => (chunkString),
113
- insertAt: () => (insertAt),
114
- makeSentenceFromPascal: () => (makeSentenceFromPascal),
115
- removeAt: () => (removeAt),
116
- repeatString: () => (repeatString),
117
- replaceAt: () => (replaceAt),
118
- toCharArray: () => (toCharArray)
119
- });
120
-
121
- ;// ./src/math/index.ts
122
- function isInteger(n) {
123
- return typeof n === "number" && isFinite(n) && n === Math.trunc(n);
124
- }
125
- function linearToDecibels(linearVolume) {
126
- if (!isFinite(linearVolume)) {
127
- throw new Error("linearToDecibel: Invalid linearVolume = " + linearVolume);
128
- }
129
- else if (linearVolume <= 0) {
130
- return -Infinity;
131
- }
132
- else {
133
- return 20 * Math.log10(linearVolume);
134
- }
135
- }
136
- function mod(m, n) {
137
- return ((m % n) + n) % n;
138
- }
139
- function romanize(n) {
140
- if (!isInteger(n) || n < 0) {
141
- throw new Error("romanize: Invalid n = " + n);
142
- }
143
- var digits = String(+n).split("");
144
- var key = ["", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM",
145
- "", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC",
146
- "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"];
147
- var roman = "", i = 3;
148
- while (i--)
149
- roman = (key[+digits.pop() + (i * 10)] || "") + roman;
150
- return Array(+digits.join("") + 1).join("M") + roman;
151
- }
152
- function toOrdinalNumber(n) {
153
- if (!isInteger(n)) {
154
- throw new Error("toOrdinalNumber: Invalid n = " + n);
155
- }
156
- const nStr = n.toString();
157
- const lastDigit = Number(nStr.charAt(nStr.length - 1));
158
- if (n === 1 || n >= 20 && lastDigit === 1) {
159
- return nStr + "st";
160
- }
161
- else if (n === 2 || n >= 20 && lastDigit === 2) {
162
- return nStr + "nd";
163
- }
164
- else if (n === 3 || n >= 20 && lastDigit === 3) {
165
- return nStr + "rd";
166
- }
167
- else {
168
- return nStr + "th";
169
- }
170
- }
171
- function interpolateCoord(startX, startY, endX, endY, t) {
172
- return {
173
- x: startX + (endX - startX) * t,
174
- y: startY + (endY - startY) * t
175
- };
176
- }
177
- function interpolateY(startX, startY, endX, endY, x) {
178
- let t = (x - startX) / (endX - startX);
179
- return startY + (endY - startY) * t;
180
- }
181
- function clamp(num, min, max) {
182
- return Math.min(Math.max(num, min), max);
183
- }
184
- function calcNormal(x1, y1, x2, y2) {
185
- let dx = x2 - x1;
186
- let dy = y2 - y1;
187
- let nx = -dy;
188
- let ny = dx;
189
- let len = Math.sqrt(nx * nx + ny * ny);
190
- if (len > 0) {
191
- nx /= len;
192
- ny /= len;
193
- }
194
- else {
195
- nx = 0;
196
- ny = 1;
197
- }
198
- return { nx, ny };
199
- }
200
- function sum(arr) {
201
- return arr.reduce((prev, cur) => cur + prev, 0);
202
- }
203
-
204
- ;// ./src/array/index.ts
205
-
206
- function isArray(a) {
207
- return !!a && Object.prototype.toString.call(a) === "[object Array]";
208
- }
209
- function toArray(a) {
210
- return isArray(a) ? a : [a];
211
- }
212
- function duplicate(a) {
213
- return a === undefined ? a : a.slice();
214
- }
215
- function removeDuplicates(a) {
216
- return a.filter((item, pos, arr) => arr.indexOf(item) === pos);
217
- }
218
- function removeDuplicatesCmp(arr, cmp) {
219
- return arr.filter((t1, index, self) => index === self.findIndex(t2 => cmp(t1, t2)));
220
- }
221
- function fillArray(fillValue, fillCount) {
222
- if (!isInteger(fillCount) || fillCount < 0) {
223
- throw new Error("fillArray: Invalid fillCount = " + fillCount);
224
- }
225
- return new Array(fillCount).fill(fillValue);
226
- }
227
- function mapSequenceArray(len, fn) {
228
- if (!isInteger(len) || len < 0) {
229
- throw new Error("mapSequenceArray: Invalid len = " + len);
230
- }
231
- let arr = new Array(len);
232
- for (let i = 0; i < len; i++) {
233
- arr[i] = fn(i);
234
- }
235
- return arr;
236
- }
237
- function getSequenceArray(len) {
238
- return mapSequenceArray(len, i => i);
239
- }
240
- function mapRangeArray(start, end, fn) {
241
- if (!isInteger(start)) {
242
- throw new Error("mapRangeArray: Invalid start = " + end);
243
- }
244
- if (!isInteger(end)) {
245
- throw new Error("mapRangeArray: Invalid end = " + end);
246
- }
247
- let len = Math.abs(end - start) + 1;
248
- let arr = new Array(len);
249
- for (let i = 0, s = start, inc = Math.sign(end - start); i < len; s += inc, i++) {
250
- arr[i] = fn(s);
251
- }
252
- return arr;
253
- }
254
- function getRangeArray(start, end) {
255
- return mapRangeArray(start, end, i => i);
256
- }
257
- function arrayContains(arg, item) {
258
- return arg.indexOf(item) >= 0;
259
- }
260
- function chunckArray(arr, chunckSize) {
261
- if (!isInteger(chunckSize) || chunckSize < 1) {
262
- throw new Error("chunckArray: Invalid chunckSize = " + chunckSize);
263
- }
264
- let result = [];
265
- for (let i = 0; i < arr.length; i += chunckSize) {
266
- result.push(arr.slice(i, i + chunckSize));
267
- }
268
- return result;
269
- }
270
-
271
- ;// ./src/modules/assert.ts
272
- var Assert;
273
- (function (Assert) {
274
- let errorConstructor = Error;
275
- function setErrorClass(ec) {
276
- errorConstructor = ec !== null && ec !== void 0 ? ec : Error;
277
- }
278
- Assert.setErrorClass = setErrorClass;
279
- function throwError(errorMsg, userMsg) {
280
- throw new errorConstructor("Assertion Error: " + errorMsg + (userMsg ? " " + userMsg : ""));
281
- }
282
- function is_int(a) {
283
- return typeof a === "number" && isFinite(a) && a === Math.trunc(a);
284
- }
285
- function is_number(a) {
286
- return typeof a === "number";
287
- }
288
- function assert(a, userMsg) {
289
- if (!a) {
290
- throwError(userMsg !== null && userMsg !== void 0 ? userMsg : "Assertion failed!");
291
- }
292
- }
293
- Assert.assert = assert;
294
- function interrupt(userMsg) {
295
- throwError(userMsg !== null && userMsg !== void 0 ? userMsg : "Interrupted!");
296
- }
297
- Assert.interrupt = interrupt;
298
- function int(a, userMsg) {
299
- if (!is_int(a)) {
300
- throwError(`Expected ${a} to be integer.`, userMsg);
301
- }
302
- return a;
303
- }
304
- Assert.int = int;
305
- function eq(a, b, userMsg) {
306
- if (a !== b) {
307
- throwError(`Expected ${a} to equal ${b}.`, userMsg);
308
- }
309
- return a;
310
- }
311
- Assert.eq = eq;
312
- function int_eq(a, b, userMsg) {
313
- if (!(is_int(a) && is_number(b) && a === b)) {
314
- throwError(`Expected ${a} to be integer equal to ${b}.`, userMsg);
315
- }
316
- return a;
317
- }
318
- Assert.int_eq = int_eq;
319
- function int_lt(a, b, userMsg) {
320
- if (!(is_int(a) && is_number(b) && a < b)) {
321
- throwError(`Expected ${a} to be integer less than ${b}.`, userMsg);
322
- }
323
- return a;
324
- }
325
- Assert.int_lt = int_lt;
326
- function int_lte(a, b, userMsg) {
327
- if (!(is_int(a) && is_number(b) && a <= b)) {
328
- throwError(`Expected ${a} to be integer less than or equal to ${b}.`, userMsg);
329
- }
330
- return a;
331
- }
332
- Assert.int_lte = int_lte;
333
- function int_gt(a, b, userMsg) {
334
- if (!(is_int(a) && is_number(b) && a > b)) {
335
- throwError(`Expected ${a} to be integer greater than ${b}.`, userMsg);
336
- }
337
- return a;
338
- }
339
- Assert.int_gt = int_gt;
340
- function int_gte(a, b, userMsg) {
341
- if (!(is_int(a) && is_number(b) && a >= b)) {
342
- throwError(`Expected ${a} to be integer greater than or equal to ${b}.`, userMsg);
343
- }
344
- return a;
345
- }
346
- Assert.int_gte = int_gte;
347
- function int_between(a, min, max, userMsg) {
348
- if (!(is_int(a) && is_number(min) && is_number(max) && a >= min && a <= max)) {
349
- throwError(`Expected ${a} to be integer between ${min} and ${max}.`, userMsg);
350
- }
351
- return a;
352
- }
353
- Assert.int_between = int_between;
354
- function odd(a, userMsg) {
355
- if (!(is_int(a) && a % 2 === 1)) {
356
- throwError(`Expected ${a} to be odd number.`, userMsg);
357
- }
358
- return a;
359
- }
360
- Assert.odd = odd;
361
- function even(a, userMsg) {
362
- if (!(is_int(a) && a % 2 === 0)) {
363
- throwError(`Expected ${a} to be even number.`, userMsg);
364
- }
365
- return a;
366
- }
367
- Assert.even = even;
368
- function in_group(a, group, userMsg) {
369
- if (!(group.some(e => e === a))) {
370
- let strGroup = group.map(v => String(v)).join(", ");
371
- throwError(`Expected ${a} to be in group [${strGroup}].`, userMsg);
372
- }
373
- return a;
374
- }
375
- Assert.in_group = in_group;
376
- function finite(a, userMsg) {
377
- if (!(is_number(a) && isFinite(a))) {
378
- throwError(`Expected ${a} to be finite number.`, userMsg);
379
- }
380
- return a;
381
- }
382
- Assert.finite = finite;
383
- function array_id(arr, id, userMsg) {
384
- if (!(is_int(id) && id >= 0 && id < arr.length)) {
385
- throwError(`Expected ${id} to be array index in bounds [0..${arr.length - 1}].`, userMsg);
386
- }
387
- return id;
388
- }
389
- Assert.array_id = array_id;
390
- function array_elem(arr, id, userMsg) {
391
- return arr[array_id(arr, id, userMsg)];
392
- }
393
- Assert.array_elem = array_elem;
394
- function require(arg, userMsg) {
395
- if (arg === undefined) {
396
- throwError("Required value is undefined.", userMsg);
397
- }
398
- else {
399
- return arg;
400
- }
401
- }
402
- Assert.require = require;
403
- })(Assert || (Assert = {}));
404
-
405
- ;// ./src/modules/device.ts
406
-
407
- var Device;
408
- (function (Device) {
409
- function getDPI() {
410
- let el = document.createElement("div");
411
- el.style.width = "1in";
412
- document.body.appendChild(el);
413
- let dpi = el.offsetWidth;
414
- el.remove();
415
- return dpi || 96;
416
- }
417
- function getScrollBarWidth() {
418
- try {
419
- let outer = document.createElement("div");
420
- outer.style.visibility = "hidden";
421
- outer.style.width = "100px";
422
- document.body.appendChild(outer);
423
- let widthNoScroll = outer.offsetWidth;
424
- outer.style.overflow = "scroll";
425
- let inner = document.createElement("div");
426
- inner.style.width = "100%";
427
- outer.appendChild(inner);
428
- let widthWithScroll = inner.offsetWidth;
429
- if (outer.parentNode) {
430
- outer.parentNode.removeChild(outer);
431
- }
432
- return widthNoScroll - widthWithScroll;
433
- }
434
- catch (e) {
435
- return 0;
436
- }
437
- }
438
- function getSystemFontSize() {
439
- let tmpDiv = document.createElement("div");
440
- tmpDiv.style.cssText = "display:inline-block; padding:0; line-height:1; position:absolute; visibility:hidden; font-size:1em";
441
- tmpDiv.appendChild(document.createTextNode("M"));
442
- document.body.appendChild(tmpDiv);
443
- let fontsize = tmpDiv.offsetHeight;
444
- document.body.removeChild(tmpDiv);
445
- return fontsize;
446
- }
447
- function getIsTouchDevice() {
448
- if ("ontouchstart" in window || "DocumentTouch" in window || "createTouch" in document && "createTouchList" in document) {
449
- return true;
450
- }
451
- var prefixes = " -webkit- -moz- -o- -ms- ".split(" ");
452
- var mq = function (query) {
453
- return window.matchMedia(query).matches;
454
- };
455
- var query = ["(", prefixes.join("touch-enabled),("), "heartz", ")"].join("");
456
- return mq(query);
457
- }
458
- function getIsMobileDevice() {
459
- let a = navigator.userAgent || navigator.vendor || window.opera;
460
- return (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4)));
461
- }
462
- function getHostAddress() {
463
- return location.protocol + "//" + location.host;
464
- }
465
- const UnitRegExp = /^(mm|cm|in|inch|px|em)$/;
466
- const ValueUnitRegExp = /^([0-9\\.]+)(.*)$/;
467
- Device.DPI = getDPI();
468
- Device.PxPerMm = Device.DPI / 25.4;
469
- Device.ScrollbarWidth = getScrollBarWidth();
470
- Device.FontSize = getSystemFontSize();
471
- Device.IsTouchDevice = getIsTouchDevice();
472
- Device.IsMobileDevice = getIsMobileDevice();
473
- Device.HostAddress = getHostAddress();
474
- function pxToMm(px) {
475
- return px / Device.PxPerMm;
476
- }
477
- Device.pxToMm = pxToMm;
478
- function mmToPx(mm) {
479
- return mm * Device.PxPerMm;
480
- }
481
- Device.mmToPx = mmToPx;
482
- function toPx(input) {
483
- if (typeof input === "number") {
484
- return input;
485
- }
486
- let value = NaN;
487
- let unit = undefined;
488
- let match = input.toString().match(ValueUnitRegExp);
489
- if (match && match[1]) {
490
- value = parseFloat(match[1]);
491
- let unitStr = match[2] ? match[2].toLowerCase() : "undefined";
492
- let unitStrOk = UnitRegExp.test(unitStr);
493
- unit = unitStrOk ? unitStr : undefined;
494
- if (!unit) {
495
- console.log("Unknown unit '" + unitStr + "' => using 'px'.");
496
- }
497
- }
498
- else {
499
- value = parseFloat(input);
500
- }
501
- Assert.finite(value, "value in function toPx");
502
- switch (unit) {
503
- case "mm":
504
- return mmToPx(value);
505
- case "cm":
506
- return mmToPx(value) * 10;
507
- case "in":
508
- case "inch":
509
- return mmToPx(value) * 25.4;
510
- case "em":
511
- return Device.FontSize * value;
512
- default:
513
- case "px":
514
- return value;
515
- }
516
- }
517
- Device.toPx = toPx;
518
- })(Device || (Device = {}));
519
-
520
- ;// ./src/dom/index.ts
521
-
522
- function toPx(value) {
523
- return value === undefined ? undefined : Device.toPx(value);
524
- }
525
- function hasClass(el, className) {
526
- if (className.length === 0) {
527
- return false;
528
- }
529
- else if (el.classList) {
530
- return el.classList.contains(className);
531
- }
532
- else {
533
- return !!el.className.match(new RegExp("(\\s|^)" + className + "(\\s|$)"));
534
- }
535
- }
536
- function addClass(el, className) {
537
- if (className.length === 0) {
538
- return;
539
- }
540
- else if (el.classList) {
541
- el.classList.add(className);
542
- }
543
- else if (!hasClass(el, className)) {
544
- el.className += " " + className;
545
- }
546
- }
547
- function removeClass(el, className) {
548
- if (className.length === 0) {
549
- return;
550
- }
551
- else if (el.classList) {
552
- el.classList.remove(className);
553
- }
554
- else if (hasClass(el, className)) {
555
- var reg = new RegExp("(\\s|^)" + className + "(\\s|$)");
556
- el.className = el.className.replace(reg, " ");
557
- }
558
- }
559
- function setOffset(el, left, top, unit = "px") {
560
- el.style.left = left + unit;
561
- el.style.top = top + unit;
562
- }
563
- function getOffset(el) {
564
- let box = el.getBoundingClientRect();
565
- let docElem = document.documentElement;
566
- return {
567
- top: box.top + window.pageYOffset - docElem.clientTop,
568
- left: box.left + window.pageXOffset - docElem.clientLeft
569
- };
570
- }
571
- function getWidth(el) {
572
- if (el instanceof Window) {
573
- return el.innerWidth;
574
- }
575
- else {
576
- let w = parseFloat(getComputedStyle(el, null).width.replace("px", ""));
577
- return isNaN(w) ? 0 : w;
578
- }
579
- }
580
- function setWidth(el, val) {
581
- el.style.width = val + 'px';
582
- }
583
- function getHeight(el) {
584
- if (el instanceof Window) {
585
- return el.innerHeight;
586
- }
587
- else {
588
- let h = parseFloat(getComputedStyle(el, null).height.replace("px", ""));
589
- return isNaN(h) ? 0 : h;
590
- }
591
- }
592
- function setHeight(el, val) {
593
- el.style.height = val + "px";
594
- }
595
- function appendTo(el, to) {
596
- to.appendChild(el);
597
- }
598
- function removeFromParent(el) {
599
- el.remove();
600
- }
601
- function setVisibility(el, visible) {
602
- el.style.display = visible ? "block" : "none";
603
- }
604
- function setRect(el, left, top, width, height, unit = "px") {
605
- el.style.left = left + unit;
606
- el.style.top = top + unit;
607
- el.style.width = width + unit;
608
- el.style.height = height + unit;
609
- }
610
- function getButton(btn) {
611
- let el = typeof btn === "string" ? document.getElementById(btn) : btn;
612
- return el instanceof HTMLButtonElement ? el : undefined;
613
- }
614
- function getCanvas(canvas) {
615
- let el = typeof canvas === "string" ? document.getElementById(canvas) : canvas;
616
- return el instanceof HTMLCanvasElement ? el : undefined;
617
- }
618
- function getPadding(style) {
619
- var _a;
620
- if (!style) {
621
- return { top: 0, right: 0, bottom: 0, left: 0 };
622
- }
623
- let top = toPx(style.paddingTop);
624
- let right = toPx(style.paddingRight);
625
- let bottom = toPx(style.paddingBottom);
626
- let left = toPx(style.paddingLeft);
627
- let padding = ((_a = style.padding) !== null && _a !== void 0 ? _a : "").toString().split(" ").filter(s => s.length > 0);
628
- switch (padding.length) {
629
- case 0:
630
- break;
631
- case 1:
632
- top !== null && top !== void 0 ? top : (top = toPx(padding[0]));
633
- right !== null && right !== void 0 ? right : (right = toPx(padding[0]));
634
- bottom !== null && bottom !== void 0 ? bottom : (bottom = toPx(padding[0]));
635
- left !== null && left !== void 0 ? left : (left = toPx(padding[0]));
636
- break;
637
- case 2:
638
- top !== null && top !== void 0 ? top : (top = toPx(padding[0]));
639
- right !== null && right !== void 0 ? right : (right = toPx(padding[1]));
640
- bottom !== null && bottom !== void 0 ? bottom : (bottom = toPx(padding[0]));
641
- left !== null && left !== void 0 ? left : (left = toPx(padding[1]));
642
- break;
643
- case 3:
644
- top !== null && top !== void 0 ? top : (top = toPx(padding[0]));
645
- right !== null && right !== void 0 ? right : (right = toPx(padding[1]));
646
- bottom !== null && bottom !== void 0 ? bottom : (bottom = toPx(padding[2]));
647
- left !== null && left !== void 0 ? left : (left = toPx(padding[1]));
648
- break;
649
- case 4:
650
- default:
651
- top !== null && top !== void 0 ? top : (top = toPx(padding[0]));
652
- right !== null && right !== void 0 ? right : (right = toPx(padding[1]));
653
- bottom !== null && bottom !== void 0 ? bottom : (bottom = toPx(padding[2]));
654
- left !== null && left !== void 0 ? left : (left = toPx(padding[3]));
655
- break;
656
- }
657
- top !== null && top !== void 0 ? top : (top = 0);
658
- right !== null && right !== void 0 ? right : (right = 0);
659
- bottom !== null && bottom !== void 0 ? bottom : (bottom = 0);
660
- left !== null && left !== void 0 ? left : (left = 0);
661
- return { top, right, bottom, left };
662
- }
663
- function getDimension(style) {
664
- let left = toPx(style === null || style === void 0 ? void 0 : style.left);
665
- let right = toPx(style === null || style === void 0 ? void 0 : style.right);
666
- let top = toPx(style === null || style === void 0 ? void 0 : style.top);
667
- let bottom = toPx(style === null || style === void 0 ? void 0 : style.bottom);
668
- let width = toPx(style === null || style === void 0 ? void 0 : style.width);
669
- let height = toPx(style === null || style === void 0 ? void 0 : style.height);
670
- if (width === undefined && left !== undefined && right !== undefined) {
671
- width = right - left;
672
- }
673
- if (height === undefined && top !== undefined && bottom !== undefined) {
674
- height = bottom - top;
675
- }
676
- return { left, top, width, height };
677
- }
678
- function styleLayoutChanged(style1, style2) {
679
- if (!style1 && !style2) {
680
- return false;
681
- }
682
- else if (!style1 || !style2) {
683
- return true;
684
- }
685
- else {
686
- return style1.left !== style2.left || style1.top !== style2.top ||
687
- style1.right !== style2.right || style1.bottom !== style2.bottom ||
688
- style1.width !== style2.width || style1.height !== style2.height;
689
- }
690
- }
691
- let canvas;
692
- function getCanvasTextWidth(text, font) {
693
- canvas !== null && canvas !== void 0 ? canvas : (canvas = document.createElement("canvas"));
694
- let ctx = canvas.getContext("2d");
695
- if (!ctx) {
696
- return 0;
697
- }
698
- ctx.font = font;
699
- return ctx.measureText(text).width;
700
- }
701
-
702
- ;// ./src/enum/index.ts
703
- function getEnumValues(e) {
704
- return Object.keys(e).filter(key => Number.isNaN(Number(key))).map(key => e[key]);
705
- }
706
-
707
- ;// ./src/map/index.ts
708
- function getMapKeys(map) {
709
- let keys = [];
710
- map.forEach((value, key) => keys.push(key));
711
- return keys;
712
- }
713
-
714
- ;// ./src/string/index.ts
715
-
716
- function toCharArray(str) {
717
- return str.split("");
718
- }
719
- function repeatString(repeatString, repeatCount) {
720
- if (!isInteger(repeatCount) || repeatCount < 0) {
721
- throw new Error("repeatStr: Invalid repeatCount = " + repeatCount);
722
- }
723
- return new Array(repeatCount + 1).join(repeatString);
724
- }
725
- function chunkString(str, chunkSize) {
726
- if (!isInteger(chunkSize) || chunkSize < 1) {
727
- throw new Error("chunckString: Invalid chuckSize = " + chunkSize);
728
- }
729
- let result = [];
730
- for (let i = 0; i < str.length; i += chunkSize) {
731
- result.push(str.slice(i, i + chunkSize));
732
- }
733
- return result;
734
- }
735
- function replaceAt(str, pos, removeCount, insert) {
736
- if (!isInteger(removeCount) || removeCount < 0) {
737
- throw new Error("replaceAt: Invalid removeCount = " + removeCount);
738
- }
739
- else if (!isInteger(pos) || pos < 0 || pos + removeCount > str.length) {
740
- throw new Error("replaceAt: Invalid pos = " + pos + ", removeCount = " + removeCount + ", str.length = " + str.length);
741
- }
742
- else {
743
- return str.substring(0, pos) + insert + str.substring(pos + removeCount);
744
- }
745
- }
746
- function insertAt(str, pos, insertStr) {
747
- return replaceAt(str, pos, 0, insertStr);
748
- }
749
- function removeAt(str, pos, removeCount) {
750
- return replaceAt(str, pos, removeCount, "");
751
- }
752
- function makeSentenceFromPascal(PascalString) {
753
- if (PascalString === "") {
754
- return "";
755
- }
756
- let word = PascalString.charAt(0);
757
- let sentence = "";
758
- const addWord = () => {
759
- if (word !== "") {
760
- if (sentence === "") {
761
- sentence += word.charAt(0).toUpperCase() + word.substring(1);
762
- }
763
- else {
764
- sentence += " " + word;
765
- }
766
- word = "";
767
- }
768
- };
769
- const isLetterAndCapital = (c) => {
770
- return c.toUpperCase() !== c.toLowerCase() && c === c.toUpperCase();
771
- };
772
- for (let i = 1; i < PascalString.length; i++) {
773
- let c = PascalString.charAt(i);
774
- if (isLetterAndCapital(c)) {
775
- addWord();
776
- }
777
- word += c.toLowerCase();
778
- }
779
- addWord();
780
- return sentence;
781
- }
782
-
783
- ;// ./src/modules/cookies.ts
784
- var Cookies;
785
- (function (Cookies) {
786
- const ConsentCookieName = "ConsentCookie";
787
- let ConsentState;
788
- (function (ConsentState) {
789
- ConsentState["Accept"] = "accept";
790
- ConsentState["Decline"] = "decline";
791
- })(ConsentState || (ConsentState = {}));
792
- let _consent;
793
- let _expires;
794
- let str = _read(ConsentCookieName);
795
- _consent = (str === ConsentState.Accept || str === ConsentState.Decline) ? str : undefined;
796
- function setExpireDays(days) {
797
- _expires = new Date();
798
- _expires.setDate(_expires.getDate() + days);
799
- }
800
- Cookies.setExpireDays = setExpireDays;
801
- function isConsentPending() {
802
- return _consent === undefined;
803
- }
804
- Cookies.isConsentPending = isConsentPending;
805
- function accept() {
806
- _consent = ConsentState.Accept;
807
- _save(ConsentCookieName, _consent);
808
- }
809
- Cookies.accept = accept;
810
- function decline() {
811
- _consent = ConsentState.Decline;
812
- _save(ConsentCookieName, _consent);
813
- }
814
- Cookies.decline = decline;
815
- function _getList() {
816
- let s = document.cookie;
817
- return s.split(";").map(c => c.trim());
818
- }
819
- function _save(name, value) {
820
- let cookie = name + "=" + value.toString() + ";sameSite=Lax;";
821
- if (_expires) {
822
- cookie += "expires=" + _expires.toUTCString() + ";";
823
- }
824
- document.cookie = cookie;
825
- return value;
826
- }
827
- function _read(name, defaultValue) {
828
- let str = _getList().find(c => c.startsWith(name + "="));
829
- return str === undefined ? defaultValue : str.substring(name.length + 1);
830
- }
831
- function _erase(name) {
832
- document.cookie = name + "=;" + "expires=Thu, 01 Jan 1970 00:00:00 UTC;";
833
- }
834
- function save(name, value) {
835
- if (_consent === ConsentState.Accept) {
836
- _save(name, value);
837
- }
838
- return value;
839
- }
840
- Cookies.save = save;
841
- function read(name, defaultValue) {
842
- if (_consent === ConsentState.Accept) {
843
- return _read(name, defaultValue) || defaultValue;
844
- }
845
- else {
846
- return defaultValue;
847
- }
848
- }
849
- Cookies.read = read;
850
- function readInt(name, defaultValue) {
851
- if (_consent === ConsentState.Accept) {
852
- let str = _read(name);
853
- return str === undefined ? defaultValue : parseInt(str);
854
- }
855
- else {
856
- return defaultValue;
857
- }
858
- }
859
- Cookies.readInt = readInt;
860
- function readBool(name, defaultValue) {
861
- if (_consent === ConsentState.Accept) {
862
- let str = _read(name);
863
- return str === undefined ? defaultValue : (/true|1/i).test(str);
864
- }
865
- else {
866
- return defaultValue;
867
- }
868
- }
869
- Cookies.readBool = readBool;
870
- function erase(name) {
871
- if (_consent === ConsentState.Accept || name === ConsentCookieName) {
872
- _erase(name);
873
- }
874
- }
875
- Cookies.erase = erase;
876
- function eraseAll() {
877
- document.cookie.split(';').forEach(c => erase(c.trim().split('=')[0]));
878
- }
879
- Cookies.eraseAll = eraseAll;
880
- })(Cookies || (Cookies = {}));
881
-
882
- ;// ./src/modules/index.ts
883
-
884
-
885
-
886
-
887
- ;// ./src/core/stack.ts
888
-
889
- class Stack {
890
- constructor() {
891
- this.list = [];
892
- }
893
- push(e) {
894
- this.list.push(e);
895
- return e;
896
- }
897
- pop() {
898
- Assert.int_gt(this.list.length, 0);
899
- return this.list.pop();
900
- }
901
- top() {
902
- return Assert.array_elem(this.list, this.list.length - 1, "Stack is empty!");
903
- }
904
- toArray() {
905
- return this.list;
906
- }
907
- get length() {
908
- return this.list.length;
909
- }
910
- clear() {
911
- this.list.length = 0;
912
- }
913
- }
914
-
915
- ;// ./src/core/vec2.ts
916
- class Vec2 {
917
- constructor(x, y) {
918
- this.x = x !== null && x !== void 0 ? x : 0;
919
- this.y = y !== null && y !== void 0 ? y : 0;
920
- }
921
- length() {
922
- return Math.sqrt(this.x * this.x + this.y * this.y);
923
- }
924
- add(a) {
925
- return new Vec2(this.x + a.x, this.y + a.y);
926
- }
927
- sub(a) {
928
- return new Vec2(this.x - a.x, this.y - a.y);
929
- }
930
- mul(a) {
931
- return new Vec2(this.x * a, this.y * a);
932
- }
933
- div(a) {
934
- return new Vec2(this.x / a, this.y / a);
935
- }
936
- }
937
-
938
- ;// ./src/core/LRU-cache.ts
939
- class LRUCache {
940
- constructor(maxSize, maxKeyLength = Infinity) {
941
- this.cache = Object.create(null);
942
- this.next = Object.create(null);
943
- this.prev = Object.create(null);
944
- this.head = null;
945
- this.tail = null;
946
- this.capacity = maxSize;
947
- this.size = 0;
948
- this.maxKeyLength = maxKeyLength;
949
- }
950
- get(key) {
951
- if (key.length > this.maxKeyLength)
952
- return undefined;
953
- if (this.cache[key] !== undefined) {
954
- this.touch(key);
955
- return this.cache[key];
956
- }
957
- return undefined;
958
- }
959
- set(key, value) {
960
- if (key.length > this.maxKeyLength) {
961
- return;
962
- }
963
- if (this.cache[key] !== undefined) {
964
- this.cache[key] = value;
965
- this.touch(key);
966
- return;
967
- }
968
- if (this.size >= this.capacity) {
969
- this.evict();
970
- }
971
- this.cache[key] = value;
972
- this.addToTail(key);
973
- this.size++;
974
- }
975
- touch(key) {
976
- if (this.tail === key)
977
- return;
978
- this.removeKey(key);
979
- this.addToTail(key);
980
- }
981
- evict() {
982
- if (this.head !== null) {
983
- const oldestKey = this.head;
984
- this.removeKey(oldestKey);
985
- delete this.cache[oldestKey];
986
- this.size--;
987
- }
988
- }
989
- removeKey(key) {
990
- const prevKey = this.prev[key];
991
- const nextKey = this.next[key];
992
- if (prevKey !== undefined) {
993
- this.next[prevKey] = nextKey;
994
- }
995
- else {
996
- this.head = nextKey !== null && nextKey !== void 0 ? nextKey : null;
997
- }
998
- if (nextKey !== undefined) {
999
- this.prev[nextKey] = prevKey;
1000
- }
1001
- else {
1002
- this.tail = prevKey !== null && prevKey !== void 0 ? prevKey : null;
1003
- }
1004
- delete this.prev[key];
1005
- delete this.next[key];
1006
- }
1007
- addToTail(key) {
1008
- if (this.tail !== null) {
1009
- this.next[this.tail] = key;
1010
- this.prev[key] = this.tail;
1011
- }
1012
- else {
1013
- this.head = key;
1014
- }
1015
- this.tail = key;
1016
- }
1017
- }
1018
-
1019
- ;// ./src/core/small-int-cache.ts
1020
-
1021
- class SmallIntCache {
1022
- constructor() {
1023
- this.pos = [];
1024
- this.neg = [];
1025
- }
1026
- set(key, value) {
1027
- if (!isInteger(key)) {
1028
- throw new Error("Key must be an integer");
1029
- }
1030
- else if (key >= 0) {
1031
- this.pos[key] = value;
1032
- }
1033
- else {
1034
- this.neg[-key - 1] = value;
1035
- }
1036
- }
1037
- get(key) {
1038
- if (!isInteger(key)) {
1039
- throw new Error("Key must be an integer");
1040
- }
1041
- else if (key >= 0) {
1042
- return this.pos[key];
1043
- }
1044
- else {
1045
- return this.neg[-key - 1];
1046
- }
1047
- }
1048
- has(key) {
1049
- if (!isInteger(key)) {
1050
- return false;
1051
- }
1052
- else if (key >= 0) {
1053
- return key in this.pos;
1054
- }
1055
- else {
1056
- return (-key - 1) in this.neg;
1057
- }
1058
- }
1059
- delete(key) {
1060
- if (!isInteger(key)) {
1061
- return;
1062
- }
1063
- else if (key >= 0) {
1064
- delete this.pos[key];
1065
- }
1066
- else {
1067
- delete this.neg[-key - 1];
1068
- }
1069
- }
1070
- clear() {
1071
- this.pos = [];
1072
- this.neg = [];
1073
- }
1074
- }
1075
-
1076
- ;// ./src/core/index.ts
1077
-
1078
-
1079
-
1080
-
1081
-
1082
- ;// ./src/index.ts
1083
-
1084
-
1085
-
1086
-
1087
-
1088
-
1089
- var Utils;
1090
- (function (Utils) {
1091
- Utils.Arr = array_namespaceObject;
1092
- Utils.Dom = dom_namespaceObject;
1093
- Utils.Enum = enum_namespaceObject;
1094
- Utils.Map = map_namespaceObject;
1095
- Utils.Math = math_namespaceObject;
1096
- Utils.Str = string_namespaceObject;
1097
- })(Utils || (Utils = {}));
1098
-
1099
-
1100
-
1101
- export { Assert, Cookies, Device, LRUCache, SmallIntCache, Stack, Utils, Vec2 };