@igo2/utils 1.12.0 → 1.13.0-alpha.1

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,1103 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('bowser'), require('rxjs'), require('rxjs/operators')) :
3
- typeof define === 'function' && define.amd ? define('@igo2/utils', ['exports', 'bowser', 'rxjs', 'rxjs/operators'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.igo2 = global.igo2 || {}, global.igo2.utils = {}), global.bowser, global.rxjs, global.rxjs.operators));
5
- })(this, (function (exports, Bowser, rxjs, operators) { 'use strict';
6
-
7
- function _interopNamespace(e) {
8
- if (e && e.__esModule) return e;
9
- var n = Object.create(null);
10
- if (e) {
11
- Object.keys(e).forEach(function (k) {
12
- if (k !== 'default') {
13
- var d = Object.getOwnPropertyDescriptor(e, k);
14
- Object.defineProperty(n, k, d.get ? d : {
15
- enumerable: true,
16
- get: function () { return e[k]; }
17
- });
18
- }
19
- });
20
- }
21
- n["default"] = e;
22
- return Object.freeze(n);
23
- }
24
-
25
- var Bowser__namespace = /*#__PURE__*/_interopNamespace(Bowser);
26
-
27
- /* eslint-disable */
28
- var ALPHA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
29
- var Base64 = /** @class */ (function () {
30
- function Base64() {
31
- }
32
- Base64.getByte = function (s, i) {
33
- var x = s.charCodeAt(i);
34
- return x;
35
- };
36
- Base64.getByte64 = function (s, i) {
37
- var idx = this.ALPHA.indexOf(s.charAt(i));
38
- return idx;
39
- };
40
- Base64.decode = function (s) {
41
- var pads = 0, i, b10, imax = s.length, x = [];
42
- s = String(s);
43
- if (imax === 0) {
44
- return s;
45
- }
46
- if (s.charAt(imax - 1) === this.PADCHAR) {
47
- pads = 1;
48
- if (s.charAt(imax - 2) === this.PADCHAR) {
49
- pads = 2;
50
- }
51
- imax -= 4;
52
- }
53
- for (i = 0; i < imax; i += 4) {
54
- b10 =
55
- (this.getByte64(s, i) << 18) |
56
- (this.getByte64(s, i + 1) << 12) |
57
- (this.getByte64(s, i + 2) << 6) |
58
- this.getByte64(s, i + 3);
59
- x.push(String.fromCharCode(b10 >> 16, (b10 >> 8) & 255, b10 & 255));
60
- }
61
- switch (pads) {
62
- case 1:
63
- b10 =
64
- (this.getByte64(s, i) << 18) |
65
- (this.getByte64(s, i + 1) << 12) |
66
- (this.getByte64(s, i + 2) << 6);
67
- x.push(String.fromCharCode(b10 >> 16, (b10 >> 8) & 255));
68
- break;
69
- case 2:
70
- b10 = (this.getByte64(s, i) << 18) | (this.getByte64(s, i + 1) << 12);
71
- x.push(String.fromCharCode(b10 >> 16));
72
- break;
73
- }
74
- return x.join('');
75
- };
76
- Base64.encode = function (s) {
77
- s = String(s);
78
- var i, b10, x = [], imax = s.length - s.length % 3;
79
- if (s.length === 0) {
80
- return s;
81
- }
82
- for (i = 0; i < imax; i += 3) {
83
- b10 =
84
- (this.getByte(s, i) << 16) |
85
- (this.getByte(s, i + 1) << 8) |
86
- this.getByte(s, i + 2);
87
- x.push(this.ALPHA.charAt(b10 >> 18));
88
- x.push(this.ALPHA.charAt((b10 >> 12) & 63));
89
- x.push(this.ALPHA.charAt((b10 >> 6) & 63));
90
- x.push(this.ALPHA.charAt(b10 & 63));
91
- }
92
- switch (s.length - imax) {
93
- case 1:
94
- b10 = this.getByte(s, i) << 16;
95
- x.push(this.ALPHA.charAt(b10 >> 18) +
96
- this.ALPHA.charAt((b10 >> 12) & 63) +
97
- this.PADCHAR +
98
- this.PADCHAR);
99
- break;
100
- case 2:
101
- b10 = (this.getByte(s, i) << 16) | (this.getByte(s, i + 1) << 8);
102
- x.push(this.ALPHA.charAt(b10 >> 18) +
103
- this.ALPHA.charAt((b10 >> 12) & 63) +
104
- this.ALPHA.charAt((b10 >> 6) & 63) +
105
- this.PADCHAR);
106
- break;
107
- }
108
- return x.join('');
109
- };
110
- return Base64;
111
- }());
112
- Base64.PADCHAR = '=';
113
- Base64.ALPHA = ALPHA;
114
-
115
- var userAgent = Bowser__namespace.getParser(window.navigator.userAgent);
116
-
117
- var Clipboard = /** @class */ (function () {
118
- function Clipboard() {
119
- }
120
- Clipboard.copy = function (element) {
121
- var successful = false;
122
- if (typeof element === 'string') {
123
- var textArea = Clipboard.createTextArea(element);
124
- Clipboard.selectText(textArea);
125
- successful = Clipboard.copyTextToClipboard();
126
- Clipboard.destroyTextArea(textArea);
127
- }
128
- else {
129
- Clipboard.selectText(element);
130
- successful = Clipboard.copyTextToClipboard();
131
- }
132
- return successful;
133
- };
134
- Clipboard.createTextArea = function (text) {
135
- var textArea = document.createElement('textArea');
136
- textArea.value = text;
137
- document.body.appendChild(textArea);
138
- return textArea;
139
- };
140
- Clipboard.destroyTextArea = function (textArea) {
141
- document.body.removeChild(textArea);
142
- };
143
- Clipboard.selectText = function (textArea) {
144
- if (userAgent.getOSName() === 'iOS') {
145
- var oldContentEditable = textArea.contentEditable;
146
- var oldReadOnly = textArea.readOnly;
147
- var range = document.createRange();
148
- var selection = window.getSelection();
149
- textArea.contenteditable = true;
150
- textArea.readonly = false;
151
- range.selectNodeContents(textArea);
152
- selection.removeAllRanges();
153
- selection.addRange(range);
154
- textArea.setSelectionRange(0, 999999);
155
- textArea.contentEditable = oldContentEditable;
156
- textArea.readOnly = oldReadOnly;
157
- }
158
- else {
159
- textArea.select();
160
- }
161
- };
162
- Clipboard.copyTextToClipboard = function () {
163
- if (!(userAgent.getOSName() === 'iOS' && userAgent.compareVersion('<10'))) {
164
- return document.execCommand('copy');
165
- }
166
- return false;
167
- };
168
- return Clipboard;
169
- }());
170
-
171
- /*! *****************************************************************************
172
- Copyright (c) Microsoft Corporation.
173
-
174
- Permission to use, copy, modify, and/or distribute this software for any
175
- purpose with or without fee is hereby granted.
176
-
177
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
178
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
179
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
180
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
181
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
182
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
183
- PERFORMANCE OF THIS SOFTWARE.
184
- ***************************************************************************** */
185
- /* global Reflect, Promise */
186
- var extendStatics = function (d, b) {
187
- extendStatics = Object.setPrototypeOf ||
188
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
189
- function (d, b) { for (var p in b)
190
- if (Object.prototype.hasOwnProperty.call(b, p))
191
- d[p] = b[p]; };
192
- return extendStatics(d, b);
193
- };
194
- function __extends(d, b) {
195
- if (typeof b !== "function" && b !== null)
196
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
197
- extendStatics(d, b);
198
- function __() { this.constructor = d; }
199
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
200
- }
201
- var __assign = function () {
202
- __assign = Object.assign || function __assign(t) {
203
- for (var s, i = 1, n = arguments.length; i < n; i++) {
204
- s = arguments[i];
205
- for (var p in s)
206
- if (Object.prototype.hasOwnProperty.call(s, p))
207
- t[p] = s[p];
208
- }
209
- return t;
210
- };
211
- return __assign.apply(this, arguments);
212
- };
213
- function __rest(s, e) {
214
- var t = {};
215
- for (var p in s)
216
- if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
217
- t[p] = s[p];
218
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
219
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
220
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
221
- t[p[i]] = s[p[i]];
222
- }
223
- return t;
224
- }
225
- function __decorate(decorators, target, key, desc) {
226
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
227
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
228
- r = Reflect.decorate(decorators, target, key, desc);
229
- else
230
- for (var i = decorators.length - 1; i >= 0; i--)
231
- if (d = decorators[i])
232
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
233
- return c > 3 && r && Object.defineProperty(target, key, r), r;
234
- }
235
- function __param(paramIndex, decorator) {
236
- return function (target, key) { decorator(target, key, paramIndex); };
237
- }
238
- function __metadata(metadataKey, metadataValue) {
239
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
240
- return Reflect.metadata(metadataKey, metadataValue);
241
- }
242
- function __awaiter(thisArg, _arguments, P, generator) {
243
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
244
- return new (P || (P = Promise))(function (resolve, reject) {
245
- function fulfilled(value) { try {
246
- step(generator.next(value));
247
- }
248
- catch (e) {
249
- reject(e);
250
- } }
251
- function rejected(value) { try {
252
- step(generator["throw"](value));
253
- }
254
- catch (e) {
255
- reject(e);
256
- } }
257
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
258
- step((generator = generator.apply(thisArg, _arguments || [])).next());
259
- });
260
- }
261
- function __generator(thisArg, body) {
262
- var _ = { label: 0, sent: function () { if (t[0] & 1)
263
- throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
264
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
265
- function verb(n) { return function (v) { return step([n, v]); }; }
266
- function step(op) {
267
- if (f)
268
- throw new TypeError("Generator is already executing.");
269
- while (_)
270
- try {
271
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
272
- return t;
273
- if (y = 0, t)
274
- op = [op[0] & 2, t.value];
275
- switch (op[0]) {
276
- case 0:
277
- case 1:
278
- t = op;
279
- break;
280
- case 4:
281
- _.label++;
282
- return { value: op[1], done: false };
283
- case 5:
284
- _.label++;
285
- y = op[1];
286
- op = [0];
287
- continue;
288
- case 7:
289
- op = _.ops.pop();
290
- _.trys.pop();
291
- continue;
292
- default:
293
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
294
- _ = 0;
295
- continue;
296
- }
297
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
298
- _.label = op[1];
299
- break;
300
- }
301
- if (op[0] === 6 && _.label < t[1]) {
302
- _.label = t[1];
303
- t = op;
304
- break;
305
- }
306
- if (t && _.label < t[2]) {
307
- _.label = t[2];
308
- _.ops.push(op);
309
- break;
310
- }
311
- if (t[2])
312
- _.ops.pop();
313
- _.trys.pop();
314
- continue;
315
- }
316
- op = body.call(thisArg, _);
317
- }
318
- catch (e) {
319
- op = [6, e];
320
- y = 0;
321
- }
322
- finally {
323
- f = t = 0;
324
- }
325
- if (op[0] & 5)
326
- throw op[1];
327
- return { value: op[0] ? op[1] : void 0, done: true };
328
- }
329
- }
330
- var __createBinding = Object.create ? (function (o, m, k, k2) {
331
- if (k2 === undefined)
332
- k2 = k;
333
- Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
334
- }) : (function (o, m, k, k2) {
335
- if (k2 === undefined)
336
- k2 = k;
337
- o[k2] = m[k];
338
- });
339
- function __exportStar(m, o) {
340
- for (var p in m)
341
- if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
342
- __createBinding(o, m, p);
343
- }
344
- function __values(o) {
345
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
346
- if (m)
347
- return m.call(o);
348
- if (o && typeof o.length === "number")
349
- return {
350
- next: function () {
351
- if (o && i >= o.length)
352
- o = void 0;
353
- return { value: o && o[i++], done: !o };
354
- }
355
- };
356
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
357
- }
358
- function __read(o, n) {
359
- var m = typeof Symbol === "function" && o[Symbol.iterator];
360
- if (!m)
361
- return o;
362
- var i = m.call(o), r, ar = [], e;
363
- try {
364
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
365
- ar.push(r.value);
366
- }
367
- catch (error) {
368
- e = { error: error };
369
- }
370
- finally {
371
- try {
372
- if (r && !r.done && (m = i["return"]))
373
- m.call(i);
374
- }
375
- finally {
376
- if (e)
377
- throw e.error;
378
- }
379
- }
380
- return ar;
381
- }
382
- /** @deprecated */
383
- function __spread() {
384
- for (var ar = [], i = 0; i < arguments.length; i++)
385
- ar = ar.concat(__read(arguments[i]));
386
- return ar;
387
- }
388
- /** @deprecated */
389
- function __spreadArrays() {
390
- for (var s = 0, i = 0, il = arguments.length; i < il; i++)
391
- s += arguments[i].length;
392
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
393
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
394
- r[k] = a[j];
395
- return r;
396
- }
397
- function __spreadArray(to, from, pack) {
398
- if (pack || arguments.length === 2)
399
- for (var i = 0, l = from.length, ar; i < l; i++) {
400
- if (ar || !(i in from)) {
401
- if (!ar)
402
- ar = Array.prototype.slice.call(from, 0, i);
403
- ar[i] = from[i];
404
- }
405
- }
406
- return to.concat(ar || Array.prototype.slice.call(from));
407
- }
408
- function __await(v) {
409
- return this instanceof __await ? (this.v = v, this) : new __await(v);
410
- }
411
- function __asyncGenerator(thisArg, _arguments, generator) {
412
- if (!Symbol.asyncIterator)
413
- throw new TypeError("Symbol.asyncIterator is not defined.");
414
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
415
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
416
- function verb(n) { if (g[n])
417
- i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
418
- function resume(n, v) { try {
419
- step(g[n](v));
420
- }
421
- catch (e) {
422
- settle(q[0][3], e);
423
- } }
424
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
425
- function fulfill(value) { resume("next", value); }
426
- function reject(value) { resume("throw", value); }
427
- function settle(f, v) { if (f(v), q.shift(), q.length)
428
- resume(q[0][0], q[0][1]); }
429
- }
430
- function __asyncDelegator(o) {
431
- var i, p;
432
- return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
433
- function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
434
- }
435
- function __asyncValues(o) {
436
- if (!Symbol.asyncIterator)
437
- throw new TypeError("Symbol.asyncIterator is not defined.");
438
- var m = o[Symbol.asyncIterator], i;
439
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
440
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
441
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
442
- }
443
- function __makeTemplateObject(cooked, raw) {
444
- if (Object.defineProperty) {
445
- Object.defineProperty(cooked, "raw", { value: raw });
446
- }
447
- else {
448
- cooked.raw = raw;
449
- }
450
- return cooked;
451
- }
452
- ;
453
- var __setModuleDefault = Object.create ? (function (o, v) {
454
- Object.defineProperty(o, "default", { enumerable: true, value: v });
455
- }) : function (o, v) {
456
- o["default"] = v;
457
- };
458
- function __importStar(mod) {
459
- if (mod && mod.__esModule)
460
- return mod;
461
- var result = {};
462
- if (mod != null)
463
- for (var k in mod)
464
- if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
465
- __createBinding(result, mod, k);
466
- __setModuleDefault(result, mod);
467
- return result;
468
- }
469
- function __importDefault(mod) {
470
- return (mod && mod.__esModule) ? mod : { default: mod };
471
- }
472
- function __classPrivateFieldGet(receiver, state, kind, f) {
473
- if (kind === "a" && !f)
474
- throw new TypeError("Private accessor was defined without a getter");
475
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
476
- throw new TypeError("Cannot read private member from an object whose class did not declare it");
477
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
478
- }
479
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
480
- if (kind === "m")
481
- throw new TypeError("Private method is not writable");
482
- if (kind === "a" && !f)
483
- throw new TypeError("Private accessor was defined without a setter");
484
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
485
- throw new TypeError("Cannot write private member to an object whose class did not declare it");
486
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
487
- }
488
-
489
- var StringUtils = /** @class */ (function () {
490
- function StringUtils() {
491
- }
492
- StringUtils.diff = function (s1, s2, p) {
493
- if (p === void 0) { p = 4; }
494
- if (!s1 && !s2) {
495
- return '';
496
- }
497
- if (!s1) {
498
- return '<span class="inserted">' + s2 + '</span>';
499
- }
500
- if (!s2) {
501
- return '<span class="deleted">' + s1 + '</span>';
502
- }
503
- s1 = s1.toString();
504
- s2 = s2.toString();
505
- var changeData = StringUtils.getChanges(s1, s2, '', p);
506
- var nextS = s2.slice(changeData.mtc.length + changeData.ins.length + changeData.sbs.length); // remaining part of "s"
507
- var nextThis = s1.slice(changeData.mtc.length + changeData.del.length + changeData.sbs.length); // remaining part of "this"
508
- var result = ''; // the glorious result
509
- if (changeData.del.length > 0) {
510
- changeData.del = '<span class="deleted">' + changeData.del + '</span>';
511
- }
512
- if (changeData.ins.length > 0) {
513
- changeData.ins = '<span class="inserted">' + changeData.ins + '</span>';
514
- }
515
- result = changeData.mtc + changeData.del + changeData.ins + changeData.sbs;
516
- result +=
517
- nextThis !== '' || nextS !== ''
518
- ? StringUtils.diff(nextThis, nextS, p)
519
- : '';
520
- return result;
521
- };
522
- StringUtils.getMatchingSubstring = function (s, l, m) {
523
- // returns the first matching substring in-between the two strings
524
- var i = 0;
525
- var match = false;
526
- var slen = s.length;
527
- var o = { fis: slen, mtc: m, sbs: '' }; // temporary object used to construct the cd (change data) object
528
- while (i < slen) {
529
- l[i] === s[i]
530
- ? match
531
- ? (o.sbs += s[i]) // o.sbs holds the matching substring itsef
532
- : ((match = true), (o.fis = i), (o.sbs = s[i]))
533
- : match
534
- ? (i = slen) // stop after the first found substring
535
- : (i = i);
536
- ++i;
537
- }
538
- return o;
539
- };
540
- StringUtils.getChanges = function (s1, s2, m, p) {
541
- var _a;
542
- var isThisLonger = s1.length >= s1.length ? true : false;
543
- var _b = __read(isThisLonger ? [s1, s2] : [s2, s1], 2), longer = _b[0], shorter = _b[1]; // assignment of longer and shorter by es6 destructuring
544
- var bi = 0; // base index designating the index of first mismacthing character in both strings
545
- while (shorter[bi] === longer[bi] && bi < shorter.length) {
546
- ++bi;
547
- } // make bi the index of first mismatching character
548
- longer = longer.split('').slice(bi); // as the longer string will be rotated it is converted into array
549
- shorter = shorter.slice(bi); // shorter and longer now starts from the first mismatching character
550
- var len = longer.length; // length of the longer string
551
- var cd = {
552
- fis: shorter.length,
553
- fil: len,
554
- sbs: '',
555
- mtc: m + s2.slice(0, bi)
556
- }; // if exists mtc holds the matching string at the front
557
- var sub = { sbs: '' }; // returned substring per 1 character rotation of the longer string
558
- if (shorter !== '') {
559
- for (var rc = 0; rc < len && sub.sbs.length < p; rc++) {
560
- // rc -> rotate count, p -> precision factor
561
- sub = StringUtils.getMatchingSubstring(shorter, StringUtils.rotateArray(longer, rc), cd.mtc); // rotate longer string 1 char and get substring
562
- sub.fil =
563
- rc < len - sub.fis
564
- ? sub.fis + rc // mismatch is longer than the mismatch in short
565
- : sub.fis - len + rc; // mismatch is shorter than the mismatch in short
566
- if (sub.sbs.length > cd.sbs.length) {
567
- cd = sub; // only keep the one with the longest substring.
568
- }
569
- }
570
- }
571
- // insert the mismatching delete subsrt and insert substr to the cd object and attach the previous substring
572
- _a = __read(isThisLonger
573
- ? [longer.slice(0, cd.fil).join(''), shorter.slice(0, cd.fis)]
574
- : [shorter.slice(0, cd.fis), longer.slice(0, cd.fil).join('')], 2), cd.del = _a[0], cd.ins = _a[1];
575
- return cd.del.indexOf(' ') === -1 ||
576
- cd.ins.indexOf(' ') === -1 ||
577
- cd.del === '' ||
578
- cd.ins === '' ||
579
- cd.sbs === ''
580
- ? cd
581
- : StringUtils.getChanges(cd.del, cd.ins, cd.mtc, p);
582
- };
583
- StringUtils.rotateArray = function (array, n) {
584
- var len = array.length;
585
- var res = new Array(array.length);
586
- if (n % len === 0) {
587
- return array.slice();
588
- }
589
- else {
590
- for (var i = 0; i < len; i++) {
591
- res[i] = array[(i + (len + (n % len))) % len];
592
- }
593
- }
594
- return res;
595
- };
596
- return StringUtils;
597
- }());
598
-
599
- exports.ChangeType = void 0;
600
- (function (ChangeType) {
601
- ChangeType["ADDED"] = "added";
602
- ChangeType["DELETED"] = "deleted";
603
- ChangeType["MODIFIED"] = "modified";
604
- })(exports.ChangeType || (exports.ChangeType = {}));
605
-
606
- var ChangeUtils = /** @class */ (function () {
607
- function ChangeUtils() {
608
- }
609
- ChangeUtils.findChanges = function (obj1, obj2, ignoreKeys) {
610
- var e_1, _a;
611
- if (ignoreKeys === void 0) { ignoreKeys = []; }
612
- var items = {
613
- added: [],
614
- deleted: [],
615
- modified: []
616
- };
617
- if (!obj1 || !obj2) {
618
- return items;
619
- }
620
- var obj1Clone = __spreadArray([], __read(obj1));
621
- var obj2Clone = __spreadArray([], __read(obj2));
622
- var _loop_1 = function (fromItem) {
623
- var index = obj2Clone.findIndex(function (s) { return s.id === fromItem.id; });
624
- if (index === -1) {
625
- items.deleted.push({
626
- change: { type: exports.ChangeType.DELETED },
627
- value: fromItem
628
- });
629
- return "continue";
630
- }
631
- var toItem = obj2Clone.splice(index, 1)[0];
632
- var fromItemClone = JSON.parse(JSON.stringify(fromItem));
633
- var toItemClone = JSON.parse(JSON.stringify(toItem));
634
- var keysChanged = ChangeUtils.compareObject(fromItemClone, toItemClone, undefined, ignoreKeys);
635
- if (keysChanged.length) {
636
- items.modified.push({
637
- change: {
638
- type: exports.ChangeType.MODIFIED,
639
- keysChanged: keysChanged
640
- },
641
- value: fromItemClone,
642
- oldValue: fromItem,
643
- newValue: toItem
644
- });
645
- }
646
- };
647
- try {
648
- for (var obj1Clone_1 = __values(obj1Clone), obj1Clone_1_1 = obj1Clone_1.next(); !obj1Clone_1_1.done; obj1Clone_1_1 = obj1Clone_1.next()) {
649
- var fromItem = obj1Clone_1_1.value;
650
- _loop_1(fromItem);
651
- }
652
- }
653
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
654
- finally {
655
- try {
656
- if (obj1Clone_1_1 && !obj1Clone_1_1.done && (_a = obj1Clone_1.return)) _a.call(obj1Clone_1);
657
- }
658
- finally { if (e_1) throw e_1.error; }
659
- }
660
- items.added = obj2Clone.map(function (itemAdded) {
661
- return {
662
- change: { type: exports.ChangeType.ADDED },
663
- value: itemAdded
664
- };
665
- });
666
- return items;
667
- };
668
- ChangeUtils.compareObject = function (fromItem, toItem, baseKey, ignoreKeys) {
669
- var _this = this;
670
- if (ignoreKeys === void 0) { ignoreKeys = []; }
671
- var fromItemClone = JSON.parse(JSON.stringify(fromItem));
672
- var toItemClone = JSON.parse(JSON.stringify(toItem));
673
- var keys = new Set(__spreadArray(__spreadArray([], __read(Object.keys(fromItem))), __read(Object.keys(toItem))));
674
- var keysChanged = [];
675
- keys.forEach(function (key) {
676
- var keyString = baseKey ? baseKey + "." + key : key;
677
- if (ignoreKeys.indexOf(keyString) !== -1) {
678
- return;
679
- }
680
- if (Array.isArray(fromItem[key])) {
681
- fromItem[key] = fromItem[key].join(',<br>');
682
- }
683
- if (Array.isArray(toItem[key])) {
684
- toItem[key] = toItem[key].join(',<br>');
685
- }
686
- if (typeof fromItem[key] === 'object' &&
687
- typeof toItem[key] === 'object' &&
688
- fromItem[key] !== null &&
689
- toItem[key] !== null) {
690
- keysChanged = keysChanged.concat(_this.compareObject(fromItem[key], toItem[key], keyString));
691
- }
692
- else {
693
- if (fromItem[key] !== toItem[key]) {
694
- keysChanged.push({
695
- key: keyString,
696
- oldValue: fromItemClone[key],
697
- newValue: toItemClone[key]
698
- });
699
- fromItem[key] = StringUtils.diff(fromItem[key], toItem[key]);
700
- }
701
- }
702
- });
703
- return keysChanged;
704
- };
705
- return ChangeUtils;
706
- }());
707
-
708
- /**
709
- * Trigger download of a file
710
- *
711
- * @param content File content
712
- * @param mimeType File mime type
713
- * @param fileName File name
714
- */
715
- function downloadContent(content, mimeType, fileName) {
716
- var uri = "data:" + mimeType + "," + encodeURIComponent(content);
717
- downloadFromUri(uri, fileName);
718
- }
719
- /**
720
- * Trigger download of a file
721
- *
722
- * @param content File content
723
- * @param mimeType File mime type
724
- * @param fileName File name
725
- */
726
- function downloadFromUri(uri, fileName) {
727
- var element = document.createElement('a');
728
- element.setAttribute('href', uri);
729
- element.setAttribute('download', fileName);
730
- element.style.display = 'none';
731
- document.body.appendChild(element);
732
- element.click();
733
- document.body.removeChild(element);
734
- }
735
-
736
- var ObjectUtils = /** @class */ (function () {
737
- function ObjectUtils() {
738
- }
739
- ObjectUtils.resolve = function (obj, key) {
740
- var keysArray = key
741
- .replace(/\[/g, '.')
742
- .replace(/\]/g, '')
743
- .split('.');
744
- var current = obj;
745
- while (keysArray.length) {
746
- if (typeof current !== 'object') {
747
- return undefined;
748
- }
749
- current = current[keysArray.shift()];
750
- }
751
- return current;
752
- };
753
- ObjectUtils.isObject = function (item) {
754
- return (item &&
755
- typeof item === 'object' &&
756
- !Array.isArray(item) &&
757
- item !== null &&
758
- !(item instanceof Date));
759
- };
760
- ObjectUtils.mergeDeep = function (target, source, ignoreUndefined) {
761
- if (ignoreUndefined === void 0) { ignoreUndefined = false; }
762
- var output = Object.assign({}, target);
763
- if (ObjectUtils.isObject(target) && ObjectUtils.isObject(source)) {
764
- Object.keys(source)
765
- .filter(function (key) { return !ignoreUndefined || source[key] !== undefined; })
766
- .forEach(function (key) {
767
- var _a, _b;
768
- if (ObjectUtils.isObject(source[key])) {
769
- if (!(key in target)) {
770
- Object.assign(output, (_a = {}, _a[key] = source[key], _a));
771
- }
772
- else {
773
- output[key] = ObjectUtils.mergeDeep(target[key], source[key], ignoreUndefined);
774
- }
775
- }
776
- else {
777
- Object.assign(output, (_b = {}, _b[key] = source[key], _b));
778
- }
779
- });
780
- }
781
- return output;
782
- };
783
- ObjectUtils.copyDeep = function (src) {
784
- var target = Array.isArray(src) ? [] : {};
785
- for (var prop in src) {
786
- if (src.hasOwnProperty(prop)) {
787
- var value = src[prop];
788
- if (value && typeof value === 'object') {
789
- target[prop] = this.copyDeep(value);
790
- }
791
- else {
792
- target[prop] = value;
793
- }
794
- }
795
- }
796
- return target;
797
- };
798
- ObjectUtils.removeDuplicateCaseInsensitive = function (obj) {
799
- var _a, _b;
800
- var summaryCapitalizeObject = {};
801
- var capitalizeObject = {};
802
- var upperCaseCount = [];
803
- for (var property in obj) {
804
- if (obj.hasOwnProperty(property)) {
805
- var upperCaseProperty = property.toUpperCase();
806
- if (!summaryCapitalizeObject.hasOwnProperty(upperCaseProperty)) {
807
- summaryCapitalizeObject[upperCaseProperty] = [
808
- (_a = {}, _a[property] = obj[property], _a)
809
- ];
810
- }
811
- else {
812
- summaryCapitalizeObject[upperCaseProperty].push((_b = {},
813
- _b[property] = obj[property],
814
- _b));
815
- }
816
- // counting the number of uppercase lettersMna
817
- upperCaseCount.push({
818
- key: property,
819
- count: property.replace(/[^A-Z]/g, '').length
820
- });
821
- }
822
- }
823
- var _loop_1 = function (capitalizedProperty) {
824
- if (summaryCapitalizeObject.hasOwnProperty(capitalizedProperty)) {
825
- if (summaryCapitalizeObject.hasOwnProperty(capitalizedProperty)) {
826
- var capitalizedPropertyObject = summaryCapitalizeObject[capitalizedProperty];
827
- if (capitalizedPropertyObject.length === 1) {
828
- // for single params (no duplicates)
829
- var singlePossibility = capitalizedPropertyObject[0];
830
- capitalizeObject[capitalizedProperty] =
831
- singlePossibility[Object.keys(singlePossibility)[0]];
832
- }
833
- else if (capitalizedPropertyObject.length > 1) {
834
- // defining the closest to lowercase property
835
- var paramClosestToLowercase = upperCaseCount
836
- .filter(function (f) { return f.key.toLowerCase() === capitalizedProperty.toLowerCase(); })
837
- .reduce(function (prev, current) {
838
- return prev.y < current.y ? prev : current;
839
- });
840
- capitalizeObject[paramClosestToLowercase.key.toUpperCase()] =
841
- obj[paramClosestToLowercase.key];
842
- }
843
- }
844
- }
845
- };
846
- for (var capitalizedProperty in summaryCapitalizeObject) {
847
- _loop_1(capitalizedProperty);
848
- }
849
- for (var property in obj) {
850
- if (obj.hasOwnProperty(property)) {
851
- delete obj[property];
852
- }
853
- }
854
- for (var property in capitalizeObject) {
855
- if (capitalizeObject.hasOwnProperty(property)) {
856
- obj[property] = capitalizeObject[property];
857
- }
858
- }
859
- };
860
- ObjectUtils.removeUndefined = function (obj) {
861
- var output = {};
862
- if (ObjectUtils.isObject(obj)) {
863
- Object.keys(obj)
864
- .filter(function (key) { return obj[key] !== undefined; })
865
- .forEach(function (key) {
866
- if (ObjectUtils.isObject(obj[key]) || Array.isArray(obj[key])) {
867
- output[key] = ObjectUtils.removeUndefined(obj[key]);
868
- }
869
- else {
870
- output[key] = obj[key];
871
- }
872
- });
873
- return output;
874
- }
875
- if (Array.isArray(obj)) {
876
- return obj.map(function (o) { return ObjectUtils.removeUndefined(o); });
877
- }
878
- return obj;
879
- };
880
- ObjectUtils.removeNull = function (obj) {
881
- var output = {};
882
- if (ObjectUtils.isObject(obj)) {
883
- Object.keys(obj)
884
- .filter(function (key) { return obj[key] !== null; })
885
- .forEach(function (key) {
886
- if (ObjectUtils.isObject(obj[key]) || Array.isArray(obj[key])) {
887
- output[key] = ObjectUtils.removeNull(obj[key]);
888
- }
889
- else {
890
- output[key] = obj[key];
891
- }
892
- });
893
- return output;
894
- }
895
- if (Array.isArray(obj)) {
896
- return obj.map(function (o) { return ObjectUtils.removeNull(o); });
897
- }
898
- return obj;
899
- };
900
- ObjectUtils.naturalCompare = function (a, b, direction, nullsFirst) {
901
- if (direction === void 0) { direction = 'asc'; }
902
- if (direction === 'desc') {
903
- b = [a, (a = b)][0];
904
- }
905
- // nullsFirst = undefined : end if direction = 'asc', first if direction = 'desc'
906
- // nullsFirst = true : always first
907
- // nullsFirst = false : always end
908
- if (a === null ||
909
- a === '' ||
910
- a === undefined ||
911
- b === null ||
912
- b === '' ||
913
- b === undefined) {
914
- var nullScore = a === b
915
- ? 0
916
- : a === undefined
917
- ? 3
918
- : b === undefined
919
- ? -3
920
- : a === null
921
- ? 2
922
- : b === null
923
- ? -2
924
- : a === ''
925
- ? 1
926
- : -1;
927
- if (direction === 'desc') {
928
- return nullsFirst !== false ? nullScore : nullScore * -1;
929
- }
930
- return nullsFirst === true ? nullScore * -1 : nullScore;
931
- }
932
- var ax = [];
933
- var bx = [];
934
- a = '' + a;
935
- b = '' + b;
936
- a.replace(/(\d+)|(\D+)/g, function (_, $1, $2) {
937
- ax.push([$1 || Infinity, $2 || '']);
938
- });
939
- b.replace(/(\d+)|(\D+)/g, function (_, $1, $2) {
940
- bx.push([$1 || Infinity, $2 || '']);
941
- });
942
- while (ax.length && bx.length) {
943
- var an = ax.shift();
944
- var bn = bx.shift();
945
- var nn = an[0] - bn[0] || an[1].localeCompare(bn[1]);
946
- if (nn) {
947
- return nn;
948
- }
949
- }
950
- return ax.length - bx.length;
951
- };
952
- /**
953
- * Return true if two object are equivalent.
954
- * Objects are considered equivalent if they have the same properties and
955
- * if all of their properties (first-level only) share the same value.
956
- * @param obj1 First object
957
- * @param obj2 Second object
958
- * @returns Whether two objects arer equivalent
959
- */
960
- ObjectUtils.objectsAreEquivalent = function (obj1, obj2) {
961
- var e_1, _a;
962
- if (obj1 === obj2) {
963
- return true;
964
- }
965
- var obj1Props = Object.getOwnPropertyNames(obj1);
966
- var obj2Props = Object.getOwnPropertyNames(obj2);
967
- if (obj1Props.length !== obj2Props.length) {
968
- return false;
969
- }
970
- try {
971
- for (var obj1Props_1 = __values(obj1Props), obj1Props_1_1 = obj1Props_1.next(); !obj1Props_1_1.done; obj1Props_1_1 = obj1Props_1.next()) {
972
- var prop = obj1Props_1_1.value;
973
- if (obj1[prop] !== obj2[prop]) {
974
- return false;
975
- }
976
- }
977
- }
978
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
979
- finally {
980
- try {
981
- if (obj1Props_1_1 && !obj1Props_1_1.done && (_a = obj1Props_1.return)) _a.call(obj1Props_1);
982
- }
983
- finally { if (e_1) throw e_1.error; }
984
- }
985
- return true;
986
- };
987
- /**
988
- * Return a new object with an array of keys removed
989
- * @param obj Source object
990
- * @param keys Keys to remove
991
- * @returns A new object
992
- */
993
- ObjectUtils.removeKeys = function (obj, keys) {
994
- var newObj = Object.keys(obj)
995
- .filter(function (key) { return keys.indexOf(key) < 0; })
996
- .reduce(function (_obj, key) {
997
- _obj[key] = obj[key];
998
- return _obj;
999
- }, {});
1000
- return newObj;
1001
- };
1002
- return ObjectUtils;
1003
- }());
1004
-
1005
- var NumberUtils = /** @class */ (function () {
1006
- function NumberUtils() {
1007
- }
1008
- NumberUtils.roundToNDecimal = function (num, decimal) {
1009
- if (decimal === void 0) { decimal = 3; }
1010
- var roundFactor = Math.pow(10, decimal);
1011
- return Math.round((num) * roundFactor) / roundFactor;
1012
- };
1013
- return NumberUtils;
1014
- }());
1015
-
1016
- /** Utility function to create a K:V from a list of strings */
1017
- function strEnum(o) {
1018
- return o.reduce(function (res, key) {
1019
- res[key] = key;
1020
- return res;
1021
- }, Object.create(null));
1022
- }
1023
-
1024
- function S4() {
1025
- // eslint-disable-next-line no-bitwise
1026
- return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
1027
- }
1028
- function uuid() {
1029
- var id = "" + S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4();
1030
- return id.toLowerCase();
1031
- }
1032
-
1033
- exports.SubjectStatus = void 0;
1034
- (function (SubjectStatus) {
1035
- SubjectStatus[SubjectStatus["Error"] = 0] = "Error";
1036
- SubjectStatus[SubjectStatus["Done"] = 1] = "Done";
1037
- SubjectStatus[SubjectStatus["Working"] = 2] = "Working";
1038
- SubjectStatus[SubjectStatus["Waiting"] = 3] = "Waiting";
1039
- })(exports.SubjectStatus || (exports.SubjectStatus = {}));
1040
- var Watcher = /** @class */ (function () {
1041
- function Watcher() {
1042
- this.status$ = new rxjs.Subject();
1043
- }
1044
- Object.defineProperty(Watcher.prototype, "status", {
1045
- get: function () {
1046
- return this._status;
1047
- },
1048
- set: function (value) {
1049
- this._status = value;
1050
- this.status$.next(value);
1051
- },
1052
- enumerable: false,
1053
- configurable: true
1054
- });
1055
- // eslint-disable-next-line @typescript-eslint/ban-types
1056
- Watcher.prototype.subscribe = function (callback, scope) {
1057
- var _this = this;
1058
- this.watch();
1059
- this.status$$ = this.status$
1060
- .pipe(operators.distinctUntilChanged())
1061
- .subscribe(function (status) {
1062
- _this.handleStatusChange(status);
1063
- callback.call(scope, _this);
1064
- });
1065
- };
1066
- Watcher.prototype.unsubscribe = function () {
1067
- this.unwatch();
1068
- if (this.status$$ !== undefined) {
1069
- this.status$$.unsubscribe();
1070
- this.status$$ = undefined;
1071
- }
1072
- this.status = exports.SubjectStatus.Waiting;
1073
- };
1074
- Watcher.prototype.handleStatusChange = function (status) { };
1075
- return Watcher;
1076
- }());
1077
-
1078
- /*
1079
- * Public API Surface of utils
1080
- */
1081
-
1082
- /**
1083
- * Generated bundle index. Do not edit.
1084
- */
1085
-
1086
- exports.Base64 = Base64;
1087
- exports.ChangeUtils = ChangeUtils;
1088
- exports.Clipboard = Clipboard;
1089
- exports.NumberUtils = NumberUtils;
1090
- exports.ObjectUtils = ObjectUtils;
1091
- exports.S4 = S4;
1092
- exports.StringUtils = StringUtils;
1093
- exports.Watcher = Watcher;
1094
- exports.downloadContent = downloadContent;
1095
- exports.downloadFromUri = downloadFromUri;
1096
- exports.strEnum = strEnum;
1097
- exports.userAgent = userAgent;
1098
- exports.uuid = uuid;
1099
-
1100
- Object.defineProperty(exports, '__esModule', { value: true });
1101
-
1102
- }));
1103
- //# sourceMappingURL=igo2-utils.umd.js.map