@hpcc-js/util 3.4.1 → 3.4.2

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/dist/index.js CHANGED
@@ -1,2224 +1,2 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
- var _a, _b, _c, _d;
6
- const PKG_NAME = "@hpcc-js/util";
7
- const PKG_VERSION = "3.4.1";
8
- const BUILD_VERSION = "3.15.1";
9
- function find(o, predicate) {
10
- if (o == null) {
11
- throw new TypeError('"o" is null or not defined');
12
- }
13
- const len = o.length >>> 0;
14
- if (typeof predicate !== "function") {
15
- throw new TypeError("predicate must be a function");
16
- }
17
- const thisArg = arguments[1];
18
- let k = 0;
19
- while (k < len) {
20
- const kValue = o[k];
21
- if (predicate.call(thisArg, kValue, k)) {
22
- return kValue;
23
- }
24
- k++;
25
- }
26
- return void 0;
27
- }
28
- __name(find, "find");
29
- function compare(before, after) {
30
- const retVal = {
31
- update: [],
32
- exit: [],
33
- enter: [...after]
34
- };
35
- for (const row of before) {
36
- const otherIdx = retVal.enter.indexOf(row);
37
- if (otherIdx >= 0) {
38
- retVal.update.push(row);
39
- retVal.enter.splice(otherIdx, 1);
40
- } else {
41
- retVal.exit.push(row);
42
- }
43
- }
44
- return retVal;
45
- }
46
- __name(compare, "compare");
47
- function compare2(before, after, idFunc, updateFunc = (before2, after2) => after2) {
48
- const retVal = {
49
- update: [],
50
- exit: [],
51
- enter: []
52
- };
53
- if (before === after) {
54
- retVal.update = before;
55
- return retVal;
56
- }
57
- const unknownMap = {};
58
- after.forEach((item) => {
59
- unknownMap[idFunc(item)] = item;
60
- });
61
- for (const row of before) {
62
- const id = idFunc(row);
63
- const item = unknownMap[id];
64
- if (item !== void 0) {
65
- delete unknownMap[id];
66
- retVal.update.push(updateFunc(row, item));
67
- } else {
68
- retVal.exit.push(row);
69
- }
70
- }
71
- for (const key in unknownMap) {
72
- retVal.enter.push(unknownMap[key]);
73
- }
74
- return retVal;
75
- }
76
- __name(compare2, "compare2");
77
- function pad(hash, len) {
78
- while (hash.length < len) {
79
- hash = "0" + hash;
80
- }
81
- return hash;
82
- }
83
- __name(pad, "pad");
84
- function fold(hash, text) {
85
- if (text.length === 0) {
86
- return hash;
87
- }
88
- for (let i = 0; i < text.length; ++i) {
89
- const chr = text.charCodeAt(i);
90
- hash = (hash << 5) - hash + chr;
91
- hash |= 0;
92
- }
93
- return hash < 0 ? hash * -2 : hash;
94
- }
95
- __name(fold, "fold");
96
- function foldObject(hash, o, seen) {
97
- if (typeof o.hashSum === "function") {
98
- return o.hashSum();
99
- }
100
- return Object.keys(o).sort().reduce((input, key) => {
101
- return foldValue(input, o[key], key, seen);
102
- }, hash);
103
- }
104
- __name(foldObject, "foldObject");
105
- function foldValue(input, value, key, seen) {
106
- const hash = fold(fold(fold(input, key), toString(value)), typeof value);
107
- if (value === null) {
108
- return fold(hash, "null");
109
- }
110
- if (value === void 0) {
111
- return fold(hash, "undefined");
112
- }
113
- if (typeof value === "object") {
114
- if (seen.indexOf(value) !== -1) {
115
- return fold(hash, "[Circular]" + key);
116
- }
117
- seen.push(value);
118
- return foldObject(hash, value, seen);
119
- }
120
- return fold(hash, value.toString());
121
- }
122
- __name(foldValue, "foldValue");
123
- function toString(o) {
124
- return Object.prototype.toString.call(o);
125
- }
126
- __name(toString, "toString");
127
- function hashSum(o) {
128
- return pad(foldValue(0, o, "", []).toString(16), 8);
129
- }
130
- __name(hashSum, "hashSum");
131
- const _Cache = class _Cache {
132
- _cache = {};
133
- _calcID;
134
- static hash(...args) {
135
- return hashSum({ ...args });
136
- }
137
- constructor(calcID) {
138
- this._calcID = calcID;
139
- }
140
- has(espObj) {
141
- return this._calcID(espObj) in this._cache;
142
- }
143
- set(obj) {
144
- this._cache[this._calcID(obj)] = obj;
145
- return obj;
146
- }
147
- get(espObj, factory) {
148
- const retVal = this._cache[this._calcID(espObj)];
149
- if (!retVal) {
150
- return factory ? this.set(factory()) : null;
151
- }
152
- return retVal;
153
- }
154
- };
155
- __name(_Cache, "Cache");
156
- let Cache = _Cache;
157
- const _AsyncCache = class _AsyncCache {
158
- _cache = {};
159
- _calcID;
160
- static hash(...args) {
161
- return hashSum({ ...args });
162
- }
163
- constructor(calcID) {
164
- this._calcID = calcID;
165
- }
166
- has(espObj) {
167
- return this._calcID(espObj) in this._cache;
168
- }
169
- set(espObj, obj) {
170
- this._cache[this._calcID(espObj)] = obj;
171
- return obj;
172
- }
173
- get(espObj, factory) {
174
- const retVal = this._cache[this._calcID(espObj)];
175
- if (!retVal) {
176
- return factory ? this.set(espObj, factory()) : Promise.resolve(null);
177
- }
178
- return retVal;
179
- }
180
- };
181
- __name(_AsyncCache, "AsyncCache");
182
- let AsyncCache = _AsyncCache;
183
- function debounce(fn, timeout) {
184
- const promises = {};
185
- return (...params) => {
186
- const hash = hashSum(params);
187
- if (!promises[hash]) {
188
- promises[hash] = {
189
- clockStart: Date.now(),
190
- promise: fn(...params).then((response) => {
191
- if (timeout === void 0) {
192
- promises[hash] = null;
193
- } else {
194
- setTimeout(() => {
195
- promises[hash] = null;
196
- }, Math.max(timeout - (Date.now() - promises[hash].clockStart), 0));
197
- }
198
- return response;
199
- }).catch((e) => {
200
- promises[hash] = null;
201
- throw e;
202
- })
203
- };
204
- }
205
- return promises[hash].promise;
206
- };
207
- }
208
- __name(debounce, "debounce");
209
- function promiseTimeout(ms, promise) {
210
- let id;
211
- const timeout = new Promise((resolve, reject) => {
212
- id = setTimeout(() => {
213
- clearTimeout(id);
214
- reject("Timed out in " + ms + "ms.");
215
- }, ms);
216
- });
217
- return Promise.race([
218
- promise,
219
- timeout
220
- ]).then((response) => {
221
- clearTimeout(id);
222
- return response;
223
- }).catch((e) => {
224
- clearTimeout(id);
225
- throw e;
226
- });
227
- }
228
- __name(promiseTimeout, "promiseTimeout");
229
- const _AsyncOrderedQueue = class _AsyncOrderedQueue {
230
- _q = [];
231
- isTop(p) {
232
- return this._q[0] === p;
233
- }
234
- push(p) {
235
- const retVal = p.then((response) => {
236
- if (this.isTop(retVal)) {
237
- this._q.shift();
238
- return response;
239
- }
240
- return new Promise((resolve, reject) => {
241
- const intervalHandler = setInterval(() => {
242
- if (this.isTop(retVal)) {
243
- clearInterval(intervalHandler);
244
- this._q.shift();
245
- resolve(response);
246
- }
247
- }, 20);
248
- });
249
- });
250
- this._q.push(retVal);
251
- return retVal;
252
- }
253
- };
254
- __name(_AsyncOrderedQueue, "AsyncOrderedQueue");
255
- let AsyncOrderedQueue = _AsyncOrderedQueue;
256
- function sleep(ms) {
257
- return new Promise((resolve) => {
258
- setTimeout(() => resolve(), ms);
259
- });
260
- }
261
- __name(sleep, "sleep");
262
- const _Dictionary = class _Dictionary {
263
- store = {};
264
- constructor(attrs) {
265
- if (attrs) {
266
- for (const key in attrs) {
267
- this.set(key, attrs[key]);
268
- }
269
- }
270
- }
271
- set(key, value) {
272
- const retVal = this.store[key];
273
- this.store[key] = value;
274
- return retVal;
275
- }
276
- get(key) {
277
- return this.store[key];
278
- }
279
- has(key) {
280
- return this.store[key] !== void 0;
281
- }
282
- remove(key) {
283
- delete this.store[key];
284
- }
285
- keys() {
286
- const retVal = [];
287
- for (const key in this.store) {
288
- retVal.push(key);
289
- }
290
- return retVal;
291
- }
292
- values() {
293
- const retVal = [];
294
- for (const key in this.store) {
295
- retVal.push(this.store[key]);
296
- }
297
- return retVal;
298
- }
299
- };
300
- __name(_Dictionary, "Dictionary");
301
- let Dictionary = _Dictionary;
302
- const _DictionaryNoCase = class _DictionaryNoCase extends Dictionary {
303
- constructor(attrs) {
304
- super(attrs);
305
- }
306
- set(key, value) {
307
- return super.set(key.toLowerCase(), value);
308
- }
309
- get(key) {
310
- return super.get(key.toLowerCase());
311
- }
312
- has(key) {
313
- return super.has(key.toLowerCase());
314
- }
315
- remove(key) {
316
- return super.remove(key.toLowerCase());
317
- }
318
- };
319
- __name(_DictionaryNoCase, "DictionaryNoCase");
320
- let DictionaryNoCase = _DictionaryNoCase;
321
- function espTime2Seconds(duration) {
322
- if (!duration) {
323
- return 0;
324
- } else {
325
- if (!isNaN(Number(duration))) {
326
- return Number(duration);
327
- }
328
- }
329
- const nsIndex = duration.indexOf("ns");
330
- if (nsIndex !== -1) {
331
- return parseFloat(duration.substr(0, nsIndex)) / 1e9;
332
- }
333
- const msIndex = duration.indexOf("ms");
334
- if (msIndex !== -1) {
335
- return parseFloat(duration.substr(0, msIndex)) / 1e3;
336
- }
337
- const sIndex = duration.indexOf("s");
338
- if (sIndex !== -1 && duration.indexOf("days") === -1) {
339
- return parseFloat(duration.substr(0, sIndex));
340
- }
341
- const dayTimeParts = duration.split(" days ");
342
- const days = dayTimeParts.length > 1 ? parseFloat(dayTimeParts[0]) : 0;
343
- const time = dayTimeParts.length > 1 ? dayTimeParts[1] : dayTimeParts[0];
344
- let secs = 0;
345
- const timeParts = time.split(":").reverse();
346
- for (let j = 0; j < timeParts.length; ++j) {
347
- secs += parseFloat(timeParts[j]) * Math.pow(60, j);
348
- }
349
- return days * 24 * 60 * 60 + secs;
350
- }
351
- __name(espTime2Seconds, "espTime2Seconds");
352
- let GraphItem$1 = (_a = class {
353
- _graph;
354
- parent;
355
- props = {};
356
- constructor(graph, parent) {
357
- this._graph = graph;
358
- this.parent = parent;
359
- }
360
- }, __name(_a, "GraphItem"), _a);
361
- let Subgraph$1 = (_b = class extends GraphItem$1 {
362
- subgraphs = [];
363
- vertices = [];
364
- edges = [];
365
- _;
366
- constructor(graph, parent, _) {
367
- super(graph, parent);
368
- if (parent) {
369
- parent._addSubgraph(this);
370
- }
371
- this._ = _;
372
- }
373
- remove(full = true) {
374
- this._graph.removeSubgraph(this, full);
375
- }
376
- createSubgraph(_) {
377
- return this._graph.createSubgraph(this, _);
378
- }
379
- _addSubgraph(subgraph) {
380
- if (this.subgraphs.indexOf(subgraph) >= 0) {
381
- throw new Error("Subgraph already exists");
382
- }
383
- this.subgraphs.push(subgraph);
384
- }
385
- _removeSubgraph(subgraph) {
386
- const idx = this.subgraphs.indexOf(subgraph);
387
- if (idx < 0) {
388
- throw new Error("Subgraph does not exist");
389
- }
390
- this.subgraphs.splice(idx, 1);
391
- }
392
- removeAllSubgraphs() {
393
- for (let i = this.subgraphs.length - 1; i >= 0; --i) {
394
- this._graph.removeSubgraph(this.subgraphs[i], true);
395
- }
396
- }
397
- createVertex(_) {
398
- return this._graph.createVertex(this, _);
399
- }
400
- _addVertex(vertex) {
401
- if (this.vertices.indexOf(vertex) >= 0) {
402
- throw new Error("Vertex already exists");
403
- }
404
- this.vertices.push(vertex);
405
- }
406
- _removeVertex(vertex) {
407
- const idx = this.vertices.indexOf(vertex);
408
- if (idx < 0) {
409
- throw new Error("Vertex does not exist");
410
- }
411
- this.vertices.splice(idx, 1);
412
- }
413
- removeAllVertices() {
414
- for (let i = this.vertices.length - 1; i >= 0; --i) {
415
- this._graph.removeVertex(this.vertices[i], true);
416
- }
417
- }
418
- createEdge(source, target, _) {
419
- return this._graph.createEdge(this, source, target, _);
420
- }
421
- _addEdge(edge) {
422
- if (this.edges.indexOf(edge) >= 0) {
423
- throw new Error("Edge already exists");
424
- }
425
- this.edges.push(edge);
426
- }
427
- _removeEdge(edge) {
428
- const idx = this.edges.indexOf(edge);
429
- if (idx < 0) {
430
- throw new Error("Edge does not exist");
431
- }
432
- this.edges.splice(idx, 1);
433
- }
434
- _add(item) {
435
- if (item instanceof _b) {
436
- this._addSubgraph(item);
437
- } else if (item instanceof Vertex$1) {
438
- this._addVertex(item);
439
- } else {
440
- this._addEdge(item);
441
- }
442
- }
443
- }, __name(_b, "Subgraph"), _b);
444
- let Vertex$1 = (_c = class extends GraphItem$1 {
445
- inEdges = [];
446
- outEdges = [];
447
- get edges() {
448
- return [...this.inEdges, ...this.outEdges];
449
- }
450
- _;
451
- constructor(graph, parent, _) {
452
- super(graph, parent);
453
- parent._addVertex(this);
454
- this._ = _;
455
- }
456
- remove(full = true, _) {
457
- return this._graph.removeVertex(this, full, _);
458
- }
459
- addInEdge(edge) {
460
- this.inEdges.push(edge);
461
- }
462
- removeInEdge(edge) {
463
- const idx = this.inEdges.indexOf(edge);
464
- if (idx < 0) {
465
- throw new Error("In edge does not exist");
466
- }
467
- this.inEdges.splice(idx, 1);
468
- }
469
- addOutEdge(edge) {
470
- this.outEdges.push(edge);
471
- }
472
- removeOutEdge(edge) {
473
- const idx = this.outEdges.indexOf(edge);
474
- if (idx < 0) {
475
- throw new Error("Out edge does not exist");
476
- }
477
- this.outEdges.splice(idx, 1);
478
- }
479
- }, __name(_c, "Vertex"), _c);
480
- let Edge$1 = (_d = class extends GraphItem$1 {
481
- source;
482
- target;
483
- _;
484
- constructor(graph, parent, source, target, _) {
485
- super(graph, parent);
486
- if (!source) {
487
- throw new Error("Missing source vertex");
488
- }
489
- if (!target) {
490
- throw new Error("Missing target vertex");
491
- }
492
- parent._addEdge(this);
493
- this.source = source;
494
- this.source.addOutEdge(this);
495
- this.target = target;
496
- this.target.addInEdge(this);
497
- this._ = _;
498
- }
499
- remove() {
500
- this._graph.removeEdge(this);
501
- }
502
- }, __name(_d, "Edge"), _d);
503
- const _Graph = class _Graph {
504
- root;
505
- _allSubgraphs = [];
506
- _allSubgraphsMap = {};
507
- _allVertices = [];
508
- _allVerticesMap = {};
509
- _allEdges = [];
510
- _allEdgesMap = {};
511
- idOf;
512
- constructor(idOf = (item) => "" + item._, _) {
513
- this.root = new Subgraph$1(this, null, _);
514
- this.idOf = idOf;
515
- }
516
- createSubgraph(parent, _) {
517
- const retVal = new Subgraph$1(this, parent || this.root, _);
518
- this._allSubgraphs.push(retVal);
519
- this._allSubgraphsMap[this.idOf(retVal)] = retVal;
520
- return retVal;
521
- }
522
- removeSubgraph(subgraph, full = true) {
523
- const idx = this._allSubgraphs.indexOf(subgraph);
524
- if (idx < 0) {
525
- throw new Error("Subgraph does not exist");
526
- }
527
- this._allSubgraphs.splice(idx, 1);
528
- delete this._allSubgraphsMap[this.idOf(subgraph)];
529
- if (subgraph.parent) {
530
- subgraph.parent._removeSubgraph(subgraph);
531
- }
532
- subgraph.edges.forEach((edge) => full ? this.removeEdge(edge) : subgraph.parent._addEdge(edge));
533
- subgraph.vertices.forEach((vertex) => full ? this.removeVertex(vertex, full) : subgraph.parent._addVertex(vertex));
534
- subgraph.subgraphs.forEach(
535
- (childSubgraph) => full ? this.removeSubgraph(childSubgraph, full) : subgraph.parent._addSubgraph(childSubgraph)
536
- );
537
- }
538
- get subgraphs() {
539
- return this._allSubgraphs;
540
- }
541
- subgraph(id) {
542
- return this._allSubgraphsMap[id];
543
- }
544
- createVertex(parent, _) {
545
- const retVal = new Vertex$1(this, parent, _);
546
- this._allVertices.push(retVal);
547
- this._allVerticesMap[this.idOf(retVal)] = retVal;
548
- return retVal;
549
- }
550
- removeVertex(vertex, full = true, _) {
551
- const idx = this._allVertices.indexOf(vertex);
552
- if (idx < 0) {
553
- throw new Error("Vertex does not exist");
554
- }
555
- this._allVertices.splice(idx, 1);
556
- delete this._allVerticesMap[this.idOf(vertex)];
557
- if (vertex.parent) {
558
- vertex.parent._removeVertex(vertex);
559
- }
560
- if (!full) {
561
- vertex.inEdges.forEach((inEdge) => {
562
- vertex.outEdges.forEach((outEdge) => {
563
- this.createEdge(this.root, inEdge.source, outEdge.target, _ ? _(inEdge.source._, outEdge.target._) : void 0);
564
- });
565
- });
566
- }
567
- vertex.inEdges.forEach((edge) => this.removeEdge(edge));
568
- vertex.outEdges.forEach((edge) => this.removeEdge(edge));
569
- }
570
- get vertices() {
571
- return this._allVertices;
572
- }
573
- vertex(id) {
574
- return this._allVerticesMap[id];
575
- }
576
- createEdge(parent, source, target, _) {
577
- const retVal = new Edge$1(this, parent, source, target, _);
578
- this._allEdges.push(retVal);
579
- this._allEdgesMap[this.idOf(retVal)] = retVal;
580
- return retVal;
581
- }
582
- removeEdge(edge) {
583
- const idx = this._allEdges.indexOf(edge);
584
- if (idx < 0) {
585
- throw new Error("Edge does not exist");
586
- }
587
- this._allEdges.splice(idx, 1);
588
- delete this._allEdgesMap[this.idOf(edge)];
589
- if (edge.parent) {
590
- edge.parent._removeEdge(edge);
591
- }
592
- edge.source.removeOutEdge(edge);
593
- edge.target.removeInEdge(edge);
594
- }
595
- get edges() {
596
- return this._allEdges;
597
- }
598
- edge(id) {
599
- return this._allEdgesMap[id];
600
- }
601
- _walk(parent, visitor) {
602
- for (const subgraph of parent.subgraphs) {
603
- switch (visitor(subgraph)) {
604
- case "abort":
605
- return true;
606
- case "stepover":
607
- break;
608
- default:
609
- if (this._walk(subgraph, visitor)) return true;
610
- }
611
- }
612
- for (const vertex of parent.vertices) {
613
- if (visitor(vertex) === "abort") return true;
614
- }
615
- }
616
- walk(visitor) {
617
- this._walk(this.root, visitor);
618
- for (const edge of this._allEdges) {
619
- if (visitor(edge) === "abort") return true;
620
- }
621
- }
622
- clone() {
623
- const ctor = this.constructor;
624
- const retVal = new ctor(this.idOf, this.root._);
625
- const map = ObjMap();
626
- map.put(this.root, retVal.root);
627
- this.walk((item) => {
628
- const parent = map.get(item.parent);
629
- if (item instanceof Subgraph$1) {
630
- map.put(item, parent.createSubgraph(item._));
631
- } else if (item instanceof Vertex$1) {
632
- map.put(item, parent.createVertex(item._));
633
- } else if (item instanceof Edge$1) {
634
- const source = map.get(item.source);
635
- const target = map.get(item.target);
636
- parent.createEdge(source, target, item._);
637
- }
638
- });
639
- return retVal;
640
- }
641
- };
642
- __name(_Graph, "Graph");
643
- let Graph = _Graph;
644
- function ObjMap() {
645
- const keys = [];
646
- const values = [];
647
- return {
648
- put(key, value) {
649
- const index = keys.indexOf(key);
650
- if (index === -1) {
651
- keys.push(key);
652
- values.push(value);
653
- } else {
654
- values[index] = value;
655
- }
656
- },
657
- get(key) {
658
- return values[keys.indexOf(key)];
659
- }
660
- };
661
- }
662
- __name(ObjMap, "ObjMap");
663
- const _GraphItem = class _GraphItem {
664
- _graph;
665
- _;
666
- id() {
667
- return this._graph.id(this._);
668
- }
669
- constructor(g, _) {
670
- this._graph = g;
671
- this._ = _;
672
- }
673
- };
674
- __name(_GraphItem, "GraphItem");
675
- let GraphItem = _GraphItem;
676
- const _ChildGraphItem = class _ChildGraphItem extends GraphItem {
677
- _parent;
678
- constructor(g, _) {
679
- super(g, _);
680
- }
681
- clearParent() {
682
- if (this._parent) {
683
- this._parent.removeChild(this);
684
- delete this._parent;
685
- }
686
- return this;
687
- }
688
- parent(_) {
689
- if (arguments.length === 0) return this._parent;
690
- if (this._parent !== _) {
691
- if (this._parent) {
692
- this._parent.removeChild(this);
693
- }
694
- this._parent = _;
695
- if (this._parent) {
696
- this._parent.addChild(this);
697
- }
698
- }
699
- return this;
700
- }
701
- };
702
- __name(_ChildGraphItem, "ChildGraphItem");
703
- let ChildGraphItem = _ChildGraphItem;
704
- const _Subgraph = class _Subgraph extends ChildGraphItem {
705
- _children = [];
706
- constructor(g, _) {
707
- super(g, _);
708
- }
709
- children() {
710
- return this._children;
711
- }
712
- addChild(_) {
713
- this._children.push(_);
714
- }
715
- removeChild(_) {
716
- this._children = this._children.filter((row) => row.id !== _.id);
717
- }
718
- };
719
- __name(_Subgraph, "Subgraph");
720
- let Subgraph = _Subgraph;
721
- const _Vertex = class _Vertex extends ChildGraphItem {
722
- _inEdges = [];
723
- _outEdges = [];
724
- constructor(g, _) {
725
- super(g, _);
726
- }
727
- edges() {
728
- return [...this._inEdges, ...this._outEdges];
729
- }
730
- edgeCount() {
731
- return this._outEdges.length + this._inEdges.length;
732
- }
733
- inEdges() {
734
- return this._inEdges;
735
- }
736
- addInEdge(e) {
737
- this._inEdges.push(e);
738
- }
739
- removeInEdge(id) {
740
- this._inEdges = this._inEdges.filter((e) => e._.id !== id);
741
- }
742
- outEdges() {
743
- return this._outEdges;
744
- }
745
- addOutEdge(e) {
746
- this._outEdges.push(e);
747
- }
748
- removeOutEdge(id) {
749
- this._outEdges = this._outEdges.filter((e) => e._.id !== id);
750
- }
751
- };
752
- __name(_Vertex, "Vertex");
753
- let Vertex = _Vertex;
754
- const _Edge = class _Edge extends ChildGraphItem {
755
- _source;
756
- _target;
757
- constructor(g, _, source, target) {
758
- super(g, _);
759
- this._source = source;
760
- this._target = target;
761
- }
762
- };
763
- __name(_Edge, "Edge");
764
- let Edge = _Edge;
765
- const _Graph2 = class _Graph2 {
766
- _directed;
767
- _subgraphMap = {};
768
- _vertexMap = {};
769
- _edgeMap = {};
770
- constructor(directed = true) {
771
- this._directed = directed;
772
- }
773
- clear() {
774
- this._subgraphMap = {};
775
- this._vertexMap = {};
776
- this._edgeMap = {};
777
- return this;
778
- }
779
- clearParents() {
780
- for (const key in this._subgraphMap) {
781
- this._subgraphMap[key].clearParent();
782
- }
783
- for (const key in this._vertexMap) {
784
- this._vertexMap[key].clearParent();
785
- }
786
- return this;
787
- }
788
- isDirected() {
789
- return this._directed;
790
- }
791
- _idFunc = /* @__PURE__ */ __name((_) => typeof _.id === "function" ? _.id() : _.id, "_idFunc");
792
- idFunc(_) {
793
- this._idFunc = _;
794
- return this;
795
- }
796
- _sourceFunc = /* @__PURE__ */ __name((_) => typeof _.source === "function" ? _.source() : _.source, "_sourceFunc");
797
- sourceFunc(_) {
798
- this._sourceFunc = _;
799
- return this;
800
- }
801
- _targetFunc = /* @__PURE__ */ __name((_) => typeof _.target === "function" ? _.target() : _.target, "_targetFunc");
802
- targetFunc(_) {
803
- this._targetFunc = _;
804
- return this;
805
- }
806
- _updateFunc = /* @__PURE__ */ __name((before, after) => after, "_updateFunc");
807
- updateFunc(_) {
808
- this._updateFunc = _;
809
- return this;
810
- }
811
- id(_) {
812
- return this._idFunc(_);
813
- }
814
- type(id) {
815
- if (this.subgraphExists(id)) return "S";
816
- if (this.vertexExists(id)) return "V";
817
- if (this.edgeExists(id)) return "E";
818
- return "";
819
- }
820
- isSubgraph(_) {
821
- return this.subgraphExists(this.id(_));
822
- }
823
- isVertex(_) {
824
- return this.vertexExists(this.id(_));
825
- }
826
- isEdge(_) {
827
- return this.edgeExists(this.id(_));
828
- }
829
- allItems() {
830
- return [...this.allSubgraphs(), ...this.allVertices(), ...this.allEdges()];
831
- }
832
- item(id) {
833
- if (this.subgraphExists(id)) return this.subgraph(id);
834
- if (this.vertexExists(id)) return this.vertex(id);
835
- if (this.edgeExists(id)) return this.edge(id);
836
- return void 0;
837
- }
838
- itemExists(id) {
839
- return this.edgeExists(id) || this.vertexExists(id) || this.subgraphExists(id);
840
- }
841
- // Subgraphs ---
842
- allSubgraphs() {
843
- const retVal = [];
844
- for (const key in this._subgraphMap) {
845
- retVal.push(this._subgraphMap[key]._);
846
- }
847
- return retVal;
848
- }
849
- subgraphs() {
850
- const retVal = [];
851
- for (const key in this._subgraphMap) {
852
- if (this._subgraphMap[key].parent() === void 0) {
853
- retVal.push(this._subgraphMap[key]._);
854
- }
855
- }
856
- return retVal;
857
- }
858
- subgraphExists(id) {
859
- return !!this._subgraphMap[id];
860
- }
861
- subgraph(id) {
862
- return this._subgraphMap[id]._;
863
- }
864
- subgraphSubgraphs(id) {
865
- return this._subgraphMap[id].children().filter((child) => this.isSubgraph(child._)).map((child) => child._);
866
- }
867
- subgraphVertices(id) {
868
- return this._subgraphMap[id].children().filter((child) => this.isVertex(child._)).map((child) => child._);
869
- }
870
- subgraphEdges(id) {
871
- return this._subgraphMap[id].children().filter((child) => this.isEdge(child._)).map((child) => child._);
872
- }
873
- addSubgraph(s, parent) {
874
- const s_id = this._idFunc(s);
875
- if (this._subgraphMap[s_id]) throw new Error(`Subgraph '${s_id}' already exists.`);
876
- const subgraph = new Subgraph(this, s);
877
- if (parent) {
878
- const p_id = this._idFunc(parent);
879
- if (!this._subgraphMap[p_id]) throw new Error(`Subgraph '${p_id}' does not exist.`);
880
- subgraph.parent(this._subgraphMap[p_id]);
881
- }
882
- this._subgraphMap[s_id] = subgraph;
883
- return this;
884
- }
885
- mergeSubgraphs(_subgraphs = []) {
886
- const sgDiff = compare2(this.allSubgraphs(), _subgraphs, (sg) => this._idFunc(sg), this._updateFunc);
887
- sgDiff.exit.forEach((sg) => this.removeSubgraph(this._idFunc(sg)));
888
- sgDiff.enter.forEach((sg) => this.addSubgraph(sg));
889
- sgDiff.update.forEach((sg) => this.updateSubgraph(sg));
890
- return this;
891
- }
892
- updateSubgraph(sg) {
893
- const sg_id = this._idFunc(sg);
894
- const subgraph = this._subgraphMap[sg_id];
895
- if (!subgraph) throw new Error(`Subgraph '${sg_id}' does not exist.`);
896
- subgraph._ = sg;
897
- return this;
898
- }
899
- removeSubgraph(id, promoteChildren = true) {
900
- const sg = this._subgraphMap[id];
901
- if (!sg) throw new Error(`Subgraph '${id}' does not exist.`);
902
- sg.children().forEach((child) => {
903
- if (promoteChildren) {
904
- child.parent(sg.parent());
905
- } else {
906
- if (child instanceof Subgraph) {
907
- this.removeSubgraph(child.id());
908
- } else {
909
- this.removeVertex(child.id());
910
- }
911
- }
912
- });
913
- delete this._subgraphMap[id];
914
- return this;
915
- }
916
- subgraphParent(id, parentID) {
917
- const item = this._subgraphMap[id];
918
- if (!item) throw new Error(`Subgraph '${id}' does not exist.`);
919
- if (parentID === void 0) {
920
- const parent2 = item.parent();
921
- return parent2 ? parent2._ : void 0;
922
- }
923
- const parent = this._subgraphMap[parentID];
924
- if (!parent) throw new Error(`Vertex parent '${parent}' does not exist.`);
925
- item.parent(parent);
926
- return this;
927
- }
928
- // Vertices ---
929
- allVertices() {
930
- const retVal = [];
931
- for (const key in this._vertexMap) {
932
- retVal.push(this._vertexMap[key]._);
933
- }
934
- return retVal;
935
- }
936
- vertices() {
937
- const retVal = [];
938
- for (const key in this._vertexMap) {
939
- if (this._vertexMap[key].parent() === void 0) {
940
- retVal.push(this._vertexMap[key]._);
941
- }
942
- }
943
- return retVal;
944
- }
945
- vertexExists(id) {
946
- return !!this._vertexMap[id];
947
- }
948
- vertex(id) {
949
- return this._vertexMap[id]._;
950
- }
951
- allEdges() {
952
- const retVal = [];
953
- for (const key in this._edgeMap) {
954
- retVal.push(this._edgeMap[key]._);
955
- }
956
- return retVal;
957
- }
958
- edges() {
959
- const retVal = [];
960
- for (const key in this._edgeMap) {
961
- if (this._edgeMap[key].parent() === void 0) {
962
- retVal.push(this._edgeMap[key]._);
963
- }
964
- }
965
- return retVal;
966
- }
967
- vertexEdges(vertexID) {
968
- return this._vertexMap[vertexID].edges().map((e) => e._);
969
- }
970
- inEdges(vertexID) {
971
- return this._vertexMap[vertexID].inEdges().map((e) => e._);
972
- }
973
- outEdges(vertexID) {
974
- return this._vertexMap[vertexID].outEdges().map((e) => e._);
975
- }
976
- _neighbors(id) {
977
- return [...this._vertexMap[id].outEdges().map((e) => e._target), ...this._vertexMap[id].inEdges().map((e) => e._source)];
978
- }
979
- neighbors(id) {
980
- return this._neighbors(id).map((n) => n._);
981
- }
982
- singleNeighbors(id) {
983
- return this._neighbors(id).filter((n) => n.edgeCount() === 1).map((n) => n._);
984
- }
985
- addVertex(v, parent) {
986
- const v_id = this._idFunc(v);
987
- if (this._vertexMap[v_id]) throw new Error(`Vertex '${v_id}' already exists.`);
988
- const vertex = new Vertex(this, v);
989
- if (parent) {
990
- const p_id = this._idFunc(parent);
991
- if (!this.subgraphExists(p_id)) throw new Error(`Subgraph '${p_id}' does not exist.`);
992
- vertex.parent(this._subgraphMap[p_id]);
993
- }
994
- this._vertexMap[v_id] = vertex;
995
- return this;
996
- }
997
- mergeVertices(_vertices) {
998
- const vDiff = compare2(this.allVertices(), _vertices, (v) => this._idFunc(v), this._updateFunc);
999
- vDiff.exit.forEach((v) => this.removeVertex(this._idFunc(v)));
1000
- vDiff.enter.forEach((v) => this.addVertex(v));
1001
- vDiff.update.forEach((v) => this.updateVertex(v));
1002
- return this;
1003
- }
1004
- updateVertex(v) {
1005
- const v_id = this._idFunc(v);
1006
- const vertex = this._vertexMap[v_id];
1007
- if (!vertex) throw new Error(`Vertex '${v_id}' does not exist.`);
1008
- vertex._ = v;
1009
- return this;
1010
- }
1011
- removeVertex(id) {
1012
- const v = this._vertexMap[id];
1013
- if (!v) throw new Error(`Vertex '${id}' does not exist.`);
1014
- v.edges().forEach((e) => {
1015
- this.removeEdge(e.id());
1016
- });
1017
- delete this._vertexMap[id];
1018
- return this;
1019
- }
1020
- vertexParent(id, parentID) {
1021
- const item = this._vertexMap[id];
1022
- if (!item) throw new Error(`Vertex '${id}' does not exist.`);
1023
- if (parentID === void 0) {
1024
- const parent2 = item.parent();
1025
- return parent2 ? parent2._ : void 0;
1026
- }
1027
- const parent = this._subgraphMap[parentID];
1028
- if (!parent) throw new Error(`Vertex parent '${parent}' does not exist.`);
1029
- item.parent(parent);
1030
- return this;
1031
- }
1032
- // Edges ---
1033
- edgeExists(id) {
1034
- return !!this._edgeMap[id];
1035
- }
1036
- edge(id) {
1037
- return this._edgeMap[id]._;
1038
- }
1039
- addEdge(e, parent) {
1040
- const e_id = this._idFunc(e);
1041
- const e_source = this._sourceFunc(e);
1042
- const e_target = this._targetFunc(e);
1043
- if (this._edgeMap[e_id]) throw new Error(`Edge '${e_id}' already exists.`);
1044
- if (!this.vertexExists(e_source)) throw new Error(`Edge Source '${e_source}' does not exist.`);
1045
- if (!this.vertexExists(e_target)) throw new Error(`Edge Target '${e_target}' does not exist.`);
1046
- const edge = new Edge(this, e, this._vertexMap[e_source], this._vertexMap[e_target]);
1047
- if (parent) {
1048
- const p_id = this._idFunc(parent);
1049
- if (!this.subgraphExists(p_id)) throw new Error(`Subgraph '${p_id}' does not exist.`);
1050
- edge.parent(this._subgraphMap[p_id]);
1051
- }
1052
- this._edgeMap[e_id] = edge;
1053
- this._vertexMap[e_source].addOutEdge(edge);
1054
- this._vertexMap[e_target].addInEdge(edge);
1055
- return this;
1056
- }
1057
- mergeEdges(_edges) {
1058
- const eDiff = compare2(this.allEdges(), _edges, (e) => this._idFunc(e), this._updateFunc);
1059
- eDiff.exit.forEach((e) => this.removeEdge(this._idFunc(e)));
1060
- eDiff.enter.forEach((e) => this.addEdge(e));
1061
- eDiff.update.forEach((e) => this.updateEdge(e));
1062
- return this;
1063
- }
1064
- updateEdge(e) {
1065
- const e_id = this._idFunc(e);
1066
- const edge = this._edgeMap[e_id];
1067
- if (!edge) throw new Error(`Edge '${e_id}' does not exist.`);
1068
- const old_source = edge._source.id();
1069
- const new_source = this._sourceFunc(e);
1070
- if (old_source !== new_source) {
1071
- this._vertexMap[old_source]?.removeOutEdge(e_id);
1072
- this._vertexMap[new_source]?.addOutEdge(edge);
1073
- }
1074
- const old_target = edge._target.id();
1075
- const new_target = this._targetFunc(e);
1076
- if (old_target !== new_target) {
1077
- this._vertexMap[old_target]?.removeInEdge(e_id);
1078
- this._vertexMap[new_target]?.addInEdge(edge);
1079
- }
1080
- edge._ = e;
1081
- edge._source = this._vertexMap[new_source];
1082
- edge._target = this._vertexMap[new_target];
1083
- return this;
1084
- }
1085
- removeEdge(id) {
1086
- const e = this._edgeMap[id];
1087
- if (!e) throw new Error(`Edge '${id}' does not exist.`);
1088
- const e_sourceID = this._idFunc(e._source._);
1089
- if (!this.vertexExists(e_sourceID)) throw new Error(`Edge Source'${e_sourceID}' does not exist.`);
1090
- this._vertexMap[e_sourceID].removeOutEdge(id);
1091
- const e_targetID = this._idFunc(e._target._);
1092
- if (!this.vertexExists(e_targetID)) throw new Error(`Edge Target'${e_targetID}' does not exist.`);
1093
- this._vertexMap[e_targetID].removeInEdge(id);
1094
- delete this._edgeMap[id];
1095
- return this;
1096
- }
1097
- _hwalk(item, formatter) {
1098
- if (item instanceof Subgraph) {
1099
- return formatter("subgraph", item._, item.children().map((child) => this._hwalk(child, formatter)));
1100
- } else {
1101
- return formatter("vertex", item._);
1102
- }
1103
- }
1104
- hierarchy(formatter) {
1105
- const retVal = [];
1106
- for (const id in this._subgraphMap) {
1107
- const sg = this._subgraphMap[id];
1108
- if (sg.parent() === void 0) {
1109
- retVal.push(this._hwalk(sg, formatter));
1110
- }
1111
- }
1112
- for (const id in this._vertexMap) {
1113
- const v = this._vertexMap[id];
1114
- if (v.parent() === void 0) {
1115
- retVal.push(this._hwalk(v, formatter));
1116
- }
1117
- }
1118
- return retVal;
1119
- }
1120
- dijkstra(source, target) {
1121
- const edges = this.allEdges();
1122
- const Q = new Set();
1123
- const prev = {};
1124
- const dist = {};
1125
- const adj = {};
1126
- function vertex_with_min_dist(Q2, dist2) {
1127
- let min_distance = Infinity;
1128
- let u2 = null;
1129
- Q2.forEach((v) => {
1130
- if (dist2[v] < min_distance) {
1131
- min_distance = dist2[v];
1132
- u2 = v;
1133
- }
1134
- });
1135
- return u2;
1136
- }
1137
- __name(vertex_with_min_dist, "vertex_with_min_dist");
1138
- for (let i = 0; i < edges.length; i++) {
1139
- const v1 = this._sourceFunc(edges[i]);
1140
- const v2 = this._targetFunc(edges[i]);
1141
- const len2 = 1;
1142
- Q.add(v1);
1143
- Q.add(v2);
1144
- dist[v1] = Infinity;
1145
- dist[v2] = Infinity;
1146
- if (adj[v1] === void 0) adj[v1] = {};
1147
- if (adj[v2] === void 0) adj[v2] = {};
1148
- adj[v1][v2] = len2;
1149
- adj[v2][v1] = len2;
1150
- }
1151
- dist[source] = 0;
1152
- while (Q.size) {
1153
- const u2 = vertex_with_min_dist(Q, dist);
1154
- if (u2 === null) break;
1155
- const neighbors = Object.keys(adj[u2]).filter((v) => Q.has(v));
1156
- Q.delete(u2);
1157
- if (u2 === target) break;
1158
- for (const v of neighbors) {
1159
- const alt = dist[u2] + adj[u2][v];
1160
- if (alt < dist[v]) {
1161
- dist[v] = alt;
1162
- prev[v] = u2;
1163
- }
1164
- }
1165
- }
1166
- let u = target;
1167
- const ids = [u];
1168
- let len = 0;
1169
- while (prev[u] !== void 0) {
1170
- ids.unshift(prev[u]);
1171
- len += adj[u][prev[u]];
1172
- u = prev[u];
1173
- }
1174
- return { ids, len };
1175
- }
1176
- sort(v_id) {
1177
- const retVal = [];
1178
- const visited = {};
1179
- const visit = /* @__PURE__ */ __name((vertex, ancestors = []) => {
1180
- const v_id2 = vertex.id();
1181
- if (visited[v_id2]) return;
1182
- visited[v_id2] = true;
1183
- ancestors.push(vertex);
1184
- vertex.outEdges().forEach((e) => {
1185
- if (ancestors.indexOf(e._target) < 0) {
1186
- visit(e._target, [...ancestors]);
1187
- }
1188
- });
1189
- retVal.unshift(vertex._);
1190
- }, "visit");
1191
- if (v_id) {
1192
- visit(this._vertexMap[v_id]);
1193
- } else {
1194
- for (const key in this._vertexMap) {
1195
- visit(this._vertexMap[key]);
1196
- }
1197
- }
1198
- return retVal;
1199
- }
1200
- };
1201
- __name(_Graph2, "Graph2");
1202
- let Graph2 = _Graph2;
1203
- const _Set = class _Set {
1204
- _content = [];
1205
- get size() {
1206
- return this._content.length;
1207
- }
1208
- has(_) {
1209
- return this._content.indexOf(_) >= 0;
1210
- }
1211
- add(_) {
1212
- if (!this.has(_)) {
1213
- this._content.push(_);
1214
- }
1215
- }
1216
- delete(_) {
1217
- const idx = this._content.indexOf(_);
1218
- if (idx >= 0) {
1219
- this._content.splice(idx, 1);
1220
- }
1221
- }
1222
- forEach(_) {
1223
- this._content.forEach(_);
1224
- }
1225
- };
1226
- __name(_Set, "Set");
1227
- let Set = _Set;
1228
- const isArray$1 = Array.isArray;
1229
- const keyList = Object.keys;
1230
- const hasProp = Object.prototype.hasOwnProperty;
1231
- function verboseDeepEquals(a, b, functionRefCompare = false) {
1232
- if (a === b) return true;
1233
- if (a && b) {
1234
- if (typeof a === "object" && typeof b === "object") {
1235
- const arrA = isArray$1(a);
1236
- const arrB = isArray$1(b);
1237
- let i;
1238
- let length;
1239
- let key;
1240
- if (arrA && arrB) {
1241
- length = a.length;
1242
- if (length !== b.length) {
1243
- console.warn(`lengths not equal: ${length} !== ${b.length}`);
1244
- return false;
1245
- }
1246
- for (i = length; i-- !== 0; )
1247
- if (!verboseDeepEquals(a[i], b[i], functionRefCompare)) {
1248
- return false;
1249
- }
1250
- return true;
1251
- }
1252
- if (arrA !== arrB) {
1253
- console.warn(`arrays not equal: ${arrA} !== ${arrB}`);
1254
- return false;
1255
- }
1256
- const dateA = a instanceof Date;
1257
- const dateB = b instanceof Date;
1258
- if (dateA !== dateB) {
1259
- console.warn(`dates not equal: ${dateA} !== ${dateB}`);
1260
- return false;
1261
- }
1262
- if (dateA && dateB) {
1263
- const retVal2 = a.getTime() === b.getTime();
1264
- if (!retVal2) {
1265
- console.warn(`dates not equal: ${a.getTime()} !== ${b.getTime()}`);
1266
- }
1267
- return retVal2;
1268
- }
1269
- const regexpA = a instanceof RegExp;
1270
- const regexpB = b instanceof RegExp;
1271
- if (regexpA !== regexpB) {
1272
- console.warn(`regexps not equal: ${regexpA} !== ${regexpB}`);
1273
- return false;
1274
- }
1275
- if (regexpA && regexpB) {
1276
- const retVal2 = a.toString() === b.toString();
1277
- if (!retVal2) {
1278
- console.warn(`regexps not equal: ${a.toString()} !== ${b.toString()}`);
1279
- }
1280
- return retVal2;
1281
- }
1282
- const keys = keyList(a);
1283
- length = keys.length;
1284
- if (length !== keyList(b).length) {
1285
- console.warn(`key lengths not equal: ${length} !== ${keyList(b).length}`);
1286
- return false;
1287
- }
1288
- for (i = length; i-- !== 0; )
1289
- if (!hasProp.call(b, keys[i])) {
1290
- console.warn(`${keys[i]} in a but not b`);
1291
- return false;
1292
- }
1293
- for (i = length; i-- !== 0; ) {
1294
- key = keys[i];
1295
- if (!verboseDeepEquals(a[key], b[key], functionRefCompare)) {
1296
- return false;
1297
- }
1298
- }
1299
- return true;
1300
- } else if (!functionRefCompare && typeof a === "function" && typeof b === "function") {
1301
- const retVal2 = a.toString() === b.toString();
1302
- if (!retVal2) {
1303
- console.warn(`functions not equal: ${a.toString()} !== ${b.toString()}`);
1304
- }
1305
- return retVal2;
1306
- }
1307
- }
1308
- const retVal = a !== a && b !== b;
1309
- if (!retVal) {
1310
- console.warn(`values not equal: ${a} !== ${b}`);
1311
- }
1312
- return retVal;
1313
- }
1314
- __name(verboseDeepEquals, "verboseDeepEquals");
1315
- function deepEquals(a, b, functionRefCompare = false) {
1316
- if (a === b) return true;
1317
- if (a && b) {
1318
- if (typeof a === "object" && typeof b === "object") {
1319
- const arrA = isArray$1(a);
1320
- const arrB = isArray$1(b);
1321
- let i;
1322
- let length;
1323
- let key;
1324
- if (arrA && arrB) {
1325
- length = a.length;
1326
- if (length !== b.length) return false;
1327
- for (i = length; i-- !== 0; )
1328
- if (!deepEquals(a[i], b[i], functionRefCompare)) return false;
1329
- return true;
1330
- }
1331
- if (arrA !== arrB) return false;
1332
- const dateA = a instanceof Date;
1333
- const dateB = b instanceof Date;
1334
- if (dateA !== dateB) return false;
1335
- if (dateA && dateB) return a.getTime() === b.getTime();
1336
- const regexpA = a instanceof RegExp;
1337
- const regexpB = b instanceof RegExp;
1338
- if (regexpA !== regexpB) return false;
1339
- if (regexpA && regexpB) return a.toString() === b.toString();
1340
- const keys = keyList(a);
1341
- length = keys.length;
1342
- if (length !== keyList(b).length)
1343
- return false;
1344
- for (i = length; i-- !== 0; )
1345
- if (!hasProp.call(b, keys[i])) return false;
1346
- for (i = length; i-- !== 0; ) {
1347
- key = keys[i];
1348
- if (!deepEquals(a[key], b[key], functionRefCompare)) return false;
1349
- }
1350
- return true;
1351
- } else if (!functionRefCompare && typeof a === "function" && typeof b === "function") {
1352
- return a.toString() === b.toString();
1353
- }
1354
- }
1355
- return a !== a && b !== b;
1356
- }
1357
- __name(deepEquals, "deepEquals");
1358
- function update(origItem, newItem, functionRefCompare = false) {
1359
- return deepEquals(origItem, newItem, functionRefCompare) ? origItem : newItem;
1360
- }
1361
- __name(update, "update");
1362
- const root = typeof globalThis !== "undefined" ? globalThis : window;
1363
- const isBrowser = typeof window !== "undefined" && root === window;
1364
- const isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
1365
- const isCI = isNode && process.env != null && (process.env.TRAVIS != null || process.env.GITHUB_ACTIONS != null || process.env.CI != null);
1366
- function getScriptSrc(partial) {
1367
- const scripts = document.scripts || [];
1368
- for (let i = document.scripts.length - 1; i >= 0; --i) {
1369
- const script = scripts[i];
1370
- if (script.src) {
1371
- const idx = script.src.indexOf(partial);
1372
- if (idx >= 0) {
1373
- return script.src.substring(0, idx);
1374
- }
1375
- }
1376
- }
1377
- return "";
1378
- }
1379
- __name(getScriptSrc, "getScriptSrc");
1380
- const _Stack = class _Stack {
1381
- stack = [];
1382
- /**
1383
- * Push element onto the stack
1384
- *
1385
- * @param e - element to push
1386
- */
1387
- push(e) {
1388
- this.stack.push(e);
1389
- return e;
1390
- }
1391
- /**
1392
- * Pop element off the stack
1393
- */
1394
- pop() {
1395
- return this.stack.pop();
1396
- }
1397
- /**
1398
- * Top item on the stack
1399
- *
1400
- * @returns Top element on the stack
1401
- */
1402
- top() {
1403
- return this.stack.length ? this.stack[this.stack.length - 1] : void 0;
1404
- }
1405
- /**
1406
- * Depth of stack
1407
- *
1408
- * @returns Depth
1409
- */
1410
- depth() {
1411
- return this.stack.length;
1412
- }
1413
- };
1414
- __name(_Stack, "Stack");
1415
- let Stack = _Stack;
1416
- var Level = /* @__PURE__ */ ((Level2) => {
1417
- Level2[Level2["debug"] = 0] = "debug";
1418
- Level2[Level2["info"] = 1] = "info";
1419
- Level2[Level2["notice"] = 2] = "notice";
1420
- Level2[Level2["warning"] = 3] = "warning";
1421
- Level2[Level2["error"] = 4] = "error";
1422
- Level2[Level2["critical"] = 5] = "critical";
1423
- Level2[Level2["alert"] = 6] = "alert";
1424
- Level2[Level2["emergency"] = 7] = "emergency";
1425
- return Level2;
1426
- })(Level || {});
1427
- const colours = {
1428
- debug: "cyan",
1429
- info: "green",
1430
- notice: "grey",
1431
- warning: "blue",
1432
- error: "red",
1433
- critical: "magenta",
1434
- alert: "magenta",
1435
- emergency: "magenta"
1436
- };
1437
- const _ConsoleWriter = class _ConsoleWriter {
1438
- write(dateTime, level, id, msg) {
1439
- if (isNode) {
1440
- console.log(`[${dateTime}] ${Level[level].toUpperCase()} ${id}: ${msg}`);
1441
- } else {
1442
- console.log(`[${dateTime}] %c${Level[level].toUpperCase()}%c ${id}: ${msg}`, `color:${colours[Level[level]]}`, "");
1443
- }
1444
- }
1445
- };
1446
- __name(_ConsoleWriter, "ConsoleWriter");
1447
- let ConsoleWriter = _ConsoleWriter;
1448
- const _Logging = class _Logging {
1449
- _levelStack = new Stack();
1450
- _level = 1;
1451
- _filter = "";
1452
- _writer = new ConsoleWriter();
1453
- static Instance() {
1454
- return this._instance || (this._instance = new this());
1455
- }
1456
- constructor() {
1457
- }
1458
- stringify(obj) {
1459
- const cache = [];
1460
- return JSON.stringify(obj, function(_key, value) {
1461
- if (typeof value === "object" && value !== null) {
1462
- if (cache.indexOf(value) !== -1) {
1463
- return;
1464
- }
1465
- cache.push(value);
1466
- }
1467
- return value;
1468
- }, 2);
1469
- }
1470
- writer(_) {
1471
- if (_ === void 0) return this._writer;
1472
- this._writer = _;
1473
- return this;
1474
- }
1475
- log(level, id, msg) {
1476
- if (level < this._level) return;
1477
- if (this._filter && this._filter !== id) return;
1478
- const dateTime = (/* @__PURE__ */ new Date()).toISOString();
1479
- if (this._writer.rawWrite) {
1480
- this._writer.rawWrite(dateTime, level, id, msg);
1481
- } else {
1482
- if (typeof msg !== "string") {
1483
- msg = this.stringify(msg);
1484
- }
1485
- if (this._writer.write) {
1486
- this._writer.write(dateTime, level, id, msg);
1487
- }
1488
- }
1489
- }
1490
- debug(id, msg) {
1491
- this.log(0, id, msg);
1492
- }
1493
- info(id, msg) {
1494
- this.log(1, id, msg);
1495
- }
1496
- notice(id, msg) {
1497
- this.log(2, id, msg);
1498
- }
1499
- warning(id, msg) {
1500
- this.log(3, id, msg);
1501
- }
1502
- error(id, msg) {
1503
- this.log(4, id, msg);
1504
- }
1505
- critical(id, msg) {
1506
- this.log(5, id, msg);
1507
- }
1508
- alert(id, msg) {
1509
- this.log(6, id, msg);
1510
- }
1511
- emergency(id, msg) {
1512
- this.log(7, id, msg);
1513
- }
1514
- level(_) {
1515
- if (_ === void 0) return this._level;
1516
- this._level = _;
1517
- return this;
1518
- }
1519
- pushLevel(_) {
1520
- this._levelStack.push(this._level);
1521
- this._level = _;
1522
- return this;
1523
- }
1524
- popLevel() {
1525
- this._level = this._levelStack.pop();
1526
- return this;
1527
- }
1528
- filter(_) {
1529
- if (_ === void 0) return this._filter;
1530
- this._filter = _;
1531
- return this;
1532
- }
1533
- };
1534
- __name(_Logging, "Logging");
1535
- __publicField(_Logging, "_instance");
1536
- let Logging = _Logging;
1537
- const logger = Logging.Instance();
1538
- const _ScopedLogging = class _ScopedLogging {
1539
- _scopeID;
1540
- constructor(scopeID) {
1541
- this._scopeID = scopeID;
1542
- }
1543
- debug(msg) {
1544
- logger.debug(this._scopeID, msg);
1545
- }
1546
- info(msg) {
1547
- logger.info(this._scopeID, msg);
1548
- }
1549
- notice(msg) {
1550
- logger.notice(this._scopeID, msg);
1551
- }
1552
- warning(msg) {
1553
- logger.warning(this._scopeID, msg);
1554
- }
1555
- error(msg) {
1556
- logger.error(this._scopeID, msg);
1557
- }
1558
- critical(msg) {
1559
- logger.critical(this._scopeID, msg);
1560
- }
1561
- alert(msg) {
1562
- logger.alert(this._scopeID, msg);
1563
- }
1564
- emergency(msg) {
1565
- logger.emergency(this._scopeID, msg);
1566
- }
1567
- pushLevel(_) {
1568
- logger.pushLevel(_);
1569
- return this;
1570
- }
1571
- popLevel() {
1572
- logger.popLevel();
1573
- return this;
1574
- }
1575
- };
1576
- __name(_ScopedLogging, "ScopedLogging");
1577
- let ScopedLogging = _ScopedLogging;
1578
- function scopedLogger(scopeID, filter = false) {
1579
- if (filter) {
1580
- logger.filter(scopeID);
1581
- }
1582
- return new ScopedLogging(scopeID);
1583
- }
1584
- __name(scopedLogger, "scopedLogger");
1585
- function degreesToRadians(degrees) {
1586
- return degrees * (Math.PI / 180);
1587
- }
1588
- __name(degreesToRadians, "degreesToRadians");
1589
- function radiansToDegrees(radians) {
1590
- return radians * (180 / Math.PI);
1591
- }
1592
- __name(radiansToDegrees, "radiansToDegrees");
1593
- function polarToCartesian(r, theta) {
1594
- return {
1595
- x: r * Math.cos(theta),
1596
- y: r * Math.sin(theta)
1597
- };
1598
- }
1599
- __name(polarToCartesian, "polarToCartesian");
1600
- function cartesianToPolar(x, y) {
1601
- return {
1602
- r: Math.sqrt(x * x + y * y),
1603
- theta: Math.atan2(y, x)
1604
- };
1605
- }
1606
- __name(cartesianToPolar, "cartesianToPolar");
1607
- function normalizeRadians(radians, min = -Math.PI, max = Math.PI) {
1608
- return normalize(radians, min, max);
1609
- }
1610
- __name(normalizeRadians, "normalizeRadians");
1611
- function normalizeDegrees(degrees, min = -180, max = 180) {
1612
- return normalize(degrees, min, max);
1613
- }
1614
- __name(normalizeDegrees, "normalizeDegrees");
1615
- function normalize(value, min, max) {
1616
- const spread = max - min;
1617
- const offsetValue = value - min;
1618
- return offsetValue - Math.floor(offsetValue / spread) * spread + min;
1619
- }
1620
- __name(normalize, "normalize");
1621
- function inner(prop, obj) {
1622
- if (prop === void 0 || obj === void 0) return void 0;
1623
- for (const item of prop.split(".")) {
1624
- if (!obj.hasOwnProperty(item)) {
1625
- return void 0;
1626
- }
1627
- obj = obj[item];
1628
- }
1629
- return obj;
1630
- }
1631
- __name(inner, "inner");
1632
- function exists(prop, obj) {
1633
- return inner(prop, obj) !== void 0;
1634
- }
1635
- __name(exists, "exists");
1636
- function _mixin(dest, source) {
1637
- const empty = {};
1638
- for (const key in source) {
1639
- if (!source.hasOwnProperty(key)) continue;
1640
- if (key === "__proto__" || key === "constructor") continue;
1641
- let s = source[key];
1642
- if (s instanceof Array) ;
1643
- else if (typeof s === "object") {
1644
- s = deepMixin(dest[key], s);
1645
- }
1646
- if (!(key in dest) || dest[key] !== s && (!(key in empty) || empty[key] !== s)) {
1647
- dest[key] = s;
1648
- }
1649
- }
1650
- return dest;
1651
- }
1652
- __name(_mixin, "_mixin");
1653
- function deepMixin(dest = {}, ...sources) {
1654
- if (typeof dest !== "object") throw new Error(`Destination "${dest}" must be an object.`);
1655
- for (const source of sources) {
1656
- _mixin(dest, source);
1657
- }
1658
- return dest;
1659
- }
1660
- __name(deepMixin, "deepMixin");
1661
- function deepMixinT(dest = {}, ...sources) {
1662
- return deepMixin(dest, ...sources);
1663
- }
1664
- __name(deepMixinT, "deepMixinT");
1665
- function safeStringify(obj) {
1666
- const cache = [];
1667
- return JSON.stringify(obj, function(key, value) {
1668
- if (typeof value === "object" && value !== null) {
1669
- if (cache.indexOf(value) !== -1) {
1670
- return;
1671
- }
1672
- cache.push(value);
1673
- }
1674
- return value;
1675
- });
1676
- }
1677
- __name(safeStringify, "safeStringify");
1678
- function isArray(arg) {
1679
- if (Array.isArray !== void 0) {
1680
- return Array.isArray(arg);
1681
- }
1682
- return Object.prototype.toString.call(arg) === "[object Array]";
1683
- }
1684
- __name(isArray, "isArray");
1685
- function classID2Meta(classID) {
1686
- const info = classID.split("_");
1687
- const classInfo = info[1].split(".");
1688
- return {
1689
- module: `@hpcc-js/${info[0]}`,
1690
- file: classInfo[0],
1691
- class: classInfo[1] || classInfo[0]
1692
- };
1693
- }
1694
- __name(classID2Meta, "classID2Meta");
1695
- const _ObserverHandle = class _ObserverHandle {
1696
- eventTarget;
1697
- eventID;
1698
- callback;
1699
- constructor(eventTarget, eventID, callback) {
1700
- this.eventTarget = eventTarget;
1701
- this.eventID = eventID;
1702
- this.callback = callback;
1703
- }
1704
- release() {
1705
- this.eventTarget.removeObserver(this.eventID, this.callback);
1706
- }
1707
- unwatch() {
1708
- this.release();
1709
- }
1710
- };
1711
- __name(_ObserverHandle, "ObserverHandle");
1712
- let ObserverHandle = _ObserverHandle;
1713
- const _Observable = class _Observable {
1714
- _eventObservers = {};
1715
- constructor(...events) {
1716
- }
1717
- addObserver(eventID, callback) {
1718
- let eventObservers = this._eventObservers[eventID];
1719
- if (!eventObservers) {
1720
- eventObservers = [];
1721
- this._eventObservers[eventID] = eventObservers;
1722
- }
1723
- eventObservers.push(callback);
1724
- return new ObserverHandle(this, eventID, callback);
1725
- }
1726
- removeObserver(eventID, callback) {
1727
- const eventObservers = this._eventObservers[eventID];
1728
- if (eventObservers) {
1729
- for (let i = eventObservers.length - 1; i >= 0; --i) {
1730
- if (eventObservers[i] === callback) {
1731
- eventObservers.splice(i, 1);
1732
- }
1733
- }
1734
- }
1735
- return this;
1736
- }
1737
- dispatchEvent(eventID, ...args) {
1738
- const eventObservers = this._eventObservers[eventID];
1739
- if (eventObservers) {
1740
- for (const observer of eventObservers) {
1741
- observer(...args);
1742
- }
1743
- }
1744
- return this;
1745
- }
1746
- _hasObserver(eventID) {
1747
- const eventObservers = this._eventObservers[eventID];
1748
- for (const observer in eventObservers) {
1749
- if (eventObservers[observer]) {
1750
- return true;
1751
- }
1752
- }
1753
- return false;
1754
- }
1755
- hasObserver(_eventID) {
1756
- if (_eventID !== void 0) {
1757
- return this._hasObserver(_eventID);
1758
- }
1759
- for (const eventID in this._eventObservers) {
1760
- if (this._hasObserver(eventID)) {
1761
- return true;
1762
- }
1763
- }
1764
- return false;
1765
- }
1766
- };
1767
- __name(_Observable, "Observable");
1768
- let Observable = _Observable;
1769
- let requestAnimationFrame;
1770
- (function() {
1771
- if (root.requestAnimationFrame) {
1772
- requestAnimationFrame = root.requestAnimationFrame;
1773
- } else {
1774
- let lastTime = 0;
1775
- requestAnimationFrame = /* @__PURE__ */ __name(function(callback) {
1776
- const currTime = (/* @__PURE__ */ new Date()).getTime();
1777
- const timeToCall = Math.max(0, 16 - (currTime - lastTime));
1778
- const id = setTimeout(() => callback(currTime + timeToCall), timeToCall);
1779
- lastTime = currTime + timeToCall;
1780
- return id;
1781
- }, "requestAnimationFrame");
1782
- }
1783
- })();
1784
- const _Message = class _Message {
1785
- get canConflate() {
1786
- return false;
1787
- }
1788
- conflate(other) {
1789
- return false;
1790
- }
1791
- void() {
1792
- return false;
1793
- }
1794
- };
1795
- __name(_Message, "Message");
1796
- let Message = _Message;
1797
- const _Dispatch = class _Dispatch {
1798
- _observerID = 0;
1799
- _observers = [];
1800
- _messageBuffer = [];
1801
- constructor() {
1802
- }
1803
- observers() {
1804
- return this._observers;
1805
- }
1806
- messages() {
1807
- const retVal = [];
1808
- this._messageBuffer.forEach((msg) => {
1809
- if (!retVal.some((msg2) => msg2.canConflate && msg2.conflate(msg))) {
1810
- retVal.push(msg);
1811
- }
1812
- });
1813
- return retVal;
1814
- }
1815
- dispatchAll() {
1816
- this.dispatch(this.messages());
1817
- this.flush();
1818
- }
1819
- dispatch(messages) {
1820
- if (messages.length === 0) return;
1821
- this.observers().forEach((o) => {
1822
- const msgs = messages.filter((m) => !m.void() && (o.type === void 0 || m instanceof o.type));
1823
- if (msgs.length) {
1824
- o.callback(msgs);
1825
- }
1826
- });
1827
- }
1828
- hasObserver() {
1829
- return this._observers.length > 0;
1830
- }
1831
- flush() {
1832
- this._messageBuffer = [];
1833
- }
1834
- send(msg) {
1835
- this.dispatch([msg]);
1836
- }
1837
- post(msg) {
1838
- this._messageBuffer.push(msg);
1839
- requestAnimationFrame(() => this.dispatchAll());
1840
- }
1841
- attach(callback, type) {
1842
- const context = this;
1843
- const id = ++this._observerID;
1844
- this._observers.push({ id, type, callback });
1845
- return {
1846
- release() {
1847
- context._observers = context._observers.filter((o) => o.id !== id);
1848
- },
1849
- unwatch() {
1850
- this.release();
1851
- }
1852
- };
1853
- }
1854
- };
1855
- __name(_Dispatch, "Dispatch");
1856
- let Dispatch = _Dispatch;
1857
- const _XMLNode = class _XMLNode {
1858
- name = "";
1859
- $ = {};
1860
- _children = [];
1861
- content = "";
1862
- constructor(name) {
1863
- this.name = name;
1864
- }
1865
- appendAttribute(key, val) {
1866
- this.$[key] = val;
1867
- }
1868
- appendContent(content) {
1869
- this.content += content;
1870
- }
1871
- appendChild(child) {
1872
- this._children.push(child);
1873
- }
1874
- children(tag) {
1875
- if (tag === void 0) {
1876
- return this._children;
1877
- }
1878
- return this._children.filter((xmlNode) => {
1879
- return xmlNode.name === tag;
1880
- });
1881
- }
1882
- };
1883
- __name(_XMLNode, "XMLNode");
1884
- let XMLNode = _XMLNode;
1885
- const _SAXStackParser = class _SAXStackParser {
1886
- root;
1887
- stack = new Stack();
1888
- constructor() {
1889
- }
1890
- walkDoc(node) {
1891
- const xmlNode = this._startXMLNode(node);
1892
- if (node.attributes) {
1893
- for (let i = 0; i < node.attributes.length; ++i) {
1894
- const attribute = node.attributes.item(i);
1895
- this.attributes(attribute.nodeName, attribute.nodeValue);
1896
- }
1897
- }
1898
- this.startXMLNode(xmlNode);
1899
- if (node.childNodes) {
1900
- for (let i = 0; i < node.childNodes.length; ++i) {
1901
- const childNode = node.childNodes.item(i);
1902
- if (childNode.nodeType === childNode.TEXT_NODE) {
1903
- this.characters(childNode.nodeValue);
1904
- } else {
1905
- this.walkDoc(childNode);
1906
- }
1907
- }
1908
- }
1909
- this.endXMLNode(this.stack.pop());
1910
- }
1911
- _startXMLNode(node) {
1912
- const newNode = new XMLNode(node.nodeName);
1913
- if (!this.stack.depth()) {
1914
- this.root = newNode;
1915
- } else {
1916
- this.stack.top().appendChild(newNode);
1917
- }
1918
- return this.stack.push(newNode);
1919
- }
1920
- parse(xml) {
1921
- const domParser = new DOMParser();
1922
- const doc = domParser.parseFromString(xml, "application/xml");
1923
- this.startDocument();
1924
- this.walkDoc(doc);
1925
- this.endDocument();
1926
- }
1927
- // Callbacks ---
1928
- startDocument() {
1929
- }
1930
- endDocument() {
1931
- }
1932
- startXMLNode(node) {
1933
- }
1934
- endXMLNode(node) {
1935
- }
1936
- attributes(key, val) {
1937
- this.stack.top().appendAttribute(key, val);
1938
- }
1939
- characters(text) {
1940
- this.stack.top().appendContent(text);
1941
- }
1942
- };
1943
- __name(_SAXStackParser, "SAXStackParser");
1944
- let SAXStackParser = _SAXStackParser;
1945
- const _XML2JSONParser = class _XML2JSONParser extends SAXStackParser {
1946
- startXMLNode(node) {
1947
- super.startXMLNode(node);
1948
- switch (node.name) {
1949
- }
1950
- }
1951
- endXMLNode(node) {
1952
- switch (node.name) {
1953
- }
1954
- super.endXMLNode(node);
1955
- }
1956
- };
1957
- __name(_XML2JSONParser, "XML2JSONParser");
1958
- let XML2JSONParser = _XML2JSONParser;
1959
- function xml2json(xml) {
1960
- const saxParser = new XML2JSONParser();
1961
- saxParser.parse(xml);
1962
- return saxParser.root;
1963
- }
1964
- __name(xml2json, "xml2json");
1965
- const _PropChangedMessage = class _PropChangedMessage extends Message {
1966
- constructor(property, newValue, oldValue) {
1967
- super();
1968
- this.property = property;
1969
- this.newValue = newValue;
1970
- this.oldValue = oldValue;
1971
- }
1972
- get canConflate() {
1973
- return true;
1974
- }
1975
- conflate(other) {
1976
- if (this.property === other.property) {
1977
- this.newValue = other.newValue;
1978
- return true;
1979
- }
1980
- return false;
1981
- }
1982
- void() {
1983
- return deepEquals(this.newValue, this.oldValue);
1984
- }
1985
- };
1986
- __name(_PropChangedMessage, "PropChangedMessage");
1987
- let PropChangedMessage = _PropChangedMessage;
1988
- const _StateObject = class _StateObject {
1989
- _espState = {};
1990
- _dispatch = new Dispatch();
1991
- _monitorHandle;
1992
- _monitorTickCount = 0;
1993
- clear(newVals) {
1994
- this._espState = {};
1995
- if (newVals !== void 0) {
1996
- this.set(newVals);
1997
- }
1998
- this._monitorTickCount = 0;
1999
- }
2000
- get(key, defValue) {
2001
- if (key === void 0) {
2002
- return this._espState;
2003
- }
2004
- return this.has(key) ? this._espState[key] : defValue;
2005
- }
2006
- set(keyOrNewVals, newVal) {
2007
- if (typeof keyOrNewVals === "string") {
2008
- return this.setSingle(keyOrNewVals, newVal);
2009
- }
2010
- this.setAll(keyOrNewVals);
2011
- }
2012
- setSingle(key, newVal) {
2013
- const oldVal = this._espState[key];
2014
- this._espState[key] = newVal;
2015
- this._dispatch.post(new PropChangedMessage(key, newVal, oldVal));
2016
- }
2017
- setAll(_) {
2018
- for (const key in _) {
2019
- if (_.hasOwnProperty(key)) {
2020
- this.setSingle(key, _[key]);
2021
- }
2022
- }
2023
- }
2024
- has(key) {
2025
- return this._espState[key] !== void 0;
2026
- }
2027
- addObserver(eventID, propIDOrCallback, callback) {
2028
- if (this.isCallback(propIDOrCallback)) {
2029
- if (eventID !== "changed") throw new Error("Invalid eventID: " + eventID);
2030
- return this._dispatch.attach((messages) => {
2031
- propIDOrCallback(messages.map((m) => ({
2032
- id: m.property,
2033
- oldValue: m.oldValue,
2034
- newValue: m.newValue
2035
- })));
2036
- });
2037
- } else {
2038
- if (eventID !== "propChanged") throw new Error("Invalid eventID: " + eventID);
2039
- return this._dispatch.attach((messages) => {
2040
- const filteredMessages = messages.filter((m) => m.property === propIDOrCallback);
2041
- if (filteredMessages.length) {
2042
- if (filteredMessages.length > 1) {
2043
- console.warn("Should only be 1 message?");
2044
- }
2045
- const event = filteredMessages[filteredMessages.length - 1];
2046
- callback({
2047
- id: event.property,
2048
- oldValue: event.oldValue,
2049
- newValue: event.newValue
2050
- });
2051
- }
2052
- });
2053
- }
2054
- }
2055
- on(eventID, propIDOrCallback, callback) {
2056
- this.addObserver(eventID, propIDOrCallback, callback);
2057
- return this;
2058
- }
2059
- isCallback(propIDOrCallback) {
2060
- return typeof propIDOrCallback === "function";
2061
- }
2062
- hasEventListener() {
2063
- return this._dispatch.hasObserver();
2064
- }
2065
- // Monitoring ---
2066
- async refresh(full = false) {
2067
- await Promise.resolve();
2068
- return this;
2069
- }
2070
- _monitor() {
2071
- if (this._monitorHandle) {
2072
- this._monitorTickCount = 0;
2073
- return;
2074
- }
2075
- this._monitorHandle = setTimeout(() => {
2076
- const refreshPromise = this.hasEventListener() ? this.refresh() : Promise.resolve();
2077
- refreshPromise.then(() => {
2078
- this._monitor();
2079
- });
2080
- delete this._monitorHandle;
2081
- }, this._monitorTimeoutDuration());
2082
- }
2083
- _monitorTimeoutDuration() {
2084
- ++this._monitorTickCount;
2085
- if (this._monitorTickCount <= 1) {
2086
- return 0;
2087
- }
2088
- return 3e4;
2089
- }
2090
- watch(callback, triggerChange = true) {
2091
- if (typeof callback !== "function") {
2092
- throw new Error("Invalid Callback");
2093
- }
2094
- if (triggerChange) {
2095
- setTimeout(() => {
2096
- const props = this.get();
2097
- const changes = [];
2098
- for (const key in props) {
2099
- if (props.hasOwnProperty(props)) {
2100
- changes.push({ id: key, newValue: props[key], oldValue: void 0 });
2101
- }
2102
- }
2103
- callback(changes);
2104
- }, 0);
2105
- }
2106
- const retVal = this.addObserver("changed", callback);
2107
- this._monitor();
2108
- return retVal;
2109
- }
2110
- };
2111
- __name(_StateObject, "StateObject");
2112
- let StateObject = _StateObject;
2113
- function trim(str, char) {
2114
- if (typeof char !== "string") return str;
2115
- if (char.length === 0) return str;
2116
- while (str.indexOf(char) === 0) {
2117
- str = str.substring(1);
2118
- }
2119
- while (endsWith(str, char)) {
2120
- str = str.substring(0, str.length - 1);
2121
- }
2122
- return str;
2123
- }
2124
- __name(trim, "trim");
2125
- function endsWith(origString, searchString, position) {
2126
- const subjectString = origString.toString();
2127
- if (typeof position !== "number" || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) {
2128
- position = subjectString.length;
2129
- }
2130
- position -= searchString.length;
2131
- const lastIndex = subjectString.lastIndexOf(searchString, position);
2132
- return lastIndex !== -1 && lastIndex === position;
2133
- }
2134
- __name(endsWith, "endsWith");
2135
- function join(...segments) {
2136
- const parts = segments.reduce((parts2, segment) => {
2137
- if (parts2.length > 0) {
2138
- segment = segment.replace(/^\//, "");
2139
- }
2140
- segment = segment.replace(/\/$/, "");
2141
- return [...parts2, ...segment.split("/")];
2142
- }, []);
2143
- const resultParts = [];
2144
- for (const part of parts) {
2145
- if (part === ".") {
2146
- continue;
2147
- }
2148
- if (part === "..") {
2149
- resultParts.pop();
2150
- continue;
2151
- }
2152
- resultParts.push(part);
2153
- }
2154
- return resultParts.join("/");
2155
- }
2156
- __name(join, "join");
2157
- function dirname(path) {
2158
- return join(path, "..");
2159
- }
2160
- __name(dirname, "dirname");
2161
- export {
2162
- AsyncCache,
2163
- AsyncOrderedQueue,
2164
- BUILD_VERSION,
2165
- Cache,
2166
- Dictionary,
2167
- DictionaryNoCase,
2168
- Dispatch,
2169
- Edge$1 as Edge,
2170
- Graph,
2171
- Graph2,
2172
- GraphItem$1 as GraphItem,
2173
- Level,
2174
- Logging,
2175
- Message,
2176
- Observable,
2177
- PKG_NAME,
2178
- PKG_VERSION,
2179
- SAXStackParser,
2180
- ScopedLogging,
2181
- Stack,
2182
- StateObject,
2183
- Subgraph$1 as Subgraph,
2184
- Vertex$1 as Vertex,
2185
- XMLNode,
2186
- cartesianToPolar,
2187
- classID2Meta,
2188
- compare,
2189
- compare2,
2190
- debounce,
2191
- deepEquals,
2192
- deepMixin,
2193
- deepMixinT,
2194
- degreesToRadians,
2195
- dirname,
2196
- endsWith,
2197
- espTime2Seconds,
2198
- exists,
2199
- find,
2200
- getScriptSrc,
2201
- hashSum,
2202
- inner,
2203
- isArray,
2204
- isBrowser,
2205
- isCI,
2206
- isNode,
2207
- join,
2208
- logger,
2209
- normalize,
2210
- normalizeDegrees,
2211
- normalizeRadians,
2212
- polarToCartesian,
2213
- promiseTimeout,
2214
- radiansToDegrees,
2215
- root,
2216
- safeStringify,
2217
- scopedLogger,
2218
- sleep,
2219
- trim,
2220
- update,
2221
- verboseDeepEquals,
2222
- xml2json
2223
- };
1
+ var t,e,r,s,i=Object.defineProperty,n=(t,e)=>i(t,"name",{value:e,configurable:!0});const o="@hpcc-js/util",a="3.4.2",h="3.16.0";function c(t,e){if(null==t)throw new TypeError('"o" is null or not defined');const r=t.length>>>0;if("function"!=typeof e)throw new TypeError("predicate must be a function");const s=arguments[1];let i=0;for(;i<r;){const r=t[i];if(e.call(s,r,i))return r;i++}}function u(t,e){const r={update:[],exit:[],enter:[...e]};for(const s of t){const t=r.enter.indexOf(s);t>=0?(r.update.push(s),r.enter.splice(t,1)):r.exit.push(s)}return r}function d(t,e,r,s=(t,e)=>e){const i={update:[],exit:[],enter:[]};if(t===e)return i.update=t,i;const n={};e.forEach(t=>{n[r(t)]=t});for(const o of t){const t=r(o),e=n[t];void 0!==e?(delete n[t],i.update.push(s(o,e))):i.exit.push(o)}for(const o in n)i.enter.push(n[o]);return i}function l(t,e){for(;t.length<e;)t="0"+t;return t}function p(t,e){if(0===e.length)return t;for(let r=0;r<e.length;++r){t=(t<<5)-t+e.charCodeAt(r),t|=0}return t<0?-2*t:t}function g(t,e,r){return"function"==typeof e.hashSum?e.hashSum():Object.keys(e).sort().reduce((t,s)=>_(t,e[s],s,r),t)}function _(t,e,r,s){const i=p(p(p(t,r),f(e)),typeof e);return null===e?p(i,"null"):void 0===e?p(i,"undefined"):"object"==typeof e?-1!==s.indexOf(e)?p(i,"[Circular]"+r):(s.push(e),g(i,e,s)):p(i,e.toString())}function f(t){return Object.prototype.toString.call(t)}function v(t){return l(_(0,t,"",[]).toString(16),8)}n(c,"find"),n(u,"compare"),n(d,"compare2"),n(l,"pad"),n(p,"fold"),n(g,"foldObject"),n(_,"foldValue"),n(f,"toString"),n(v,"hashSum");const b=class _Cache{_cache={};_calcID;static hash(...t){return v({...t})}constructor(t){this._calcID=t}has(t){return this._calcID(t)in this._cache}set(t){return this._cache[this._calcID(t)]=t,t}get(t,e){const r=this._cache[this._calcID(t)];return r||(e?this.set(e()):null)}};n(b,"Cache");let E=b;const x=class _AsyncCache{_cache={};_calcID;static hash(...t){return v({...t})}constructor(t){this._calcID=t}has(t){return this._calcID(t)in this._cache}set(t,e){return this._cache[this._calcID(t)]=e,e}get(t,e){const r=this._cache[this._calcID(t)];return r||(e?this.set(t,e()):Promise.resolve(null))}};n(x,"AsyncCache");let m=x;function w(t,e){const r={};return(...s)=>{const i=v(s);return r[i]||(r[i]={clockStart:Date.now(),promise:t(...s).then(t=>(void 0===e?r[i]=null:setTimeout(()=>{r[i]=null},Math.max(e-(Date.now()-r[i].clockStart),0)),t)).catch(t=>{throw r[i]=null,t})}),r[i].promise}}function M(t,e){let r;const s=new Promise((e,s)=>{r=setTimeout(()=>{clearTimeout(r),s("Timed out in "+t+"ms.")},t)});return Promise.race([e,s]).then(t=>(clearTimeout(r),t)).catch(t=>{throw clearTimeout(r),t})}n(w,"debounce"),n(M,"promiseTimeout");const S=class _AsyncOrderedQueue{_q=[];isTop(t){return this._q[0]===t}push(t){const e=t.then(t=>this.isTop(e)?(this._q.shift(),t):new Promise((r,s)=>{const i=setInterval(()=>{this.isTop(e)&&(clearInterval(i),this._q.shift(),r(t))},20)}));return this._q.push(e),e}};n(S,"AsyncOrderedQueue");let y=S;function O(t){return new Promise(e=>{setTimeout(()=>e(),t)})}n(O,"sleep");const V=class _Dictionary{store={};constructor(t){if(t)for(const e in t)this.set(e,t[e])}set(t,e){const r=this.store[t];return this.store[t]=e,r}get(t){return this.store[t]}has(t){return void 0!==this.store[t]}remove(t){delete this.store[t]}keys(){const t=[];for(const e in this.store)t.push(e);return t}values(){const t=[];for(const e in this.store)t.push(this.store[e]);return t}};n(V,"Dictionary");let I=V;const D=class _DictionaryNoCase extends I{constructor(t){super(t)}set(t,e){return super.set(t.toLowerCase(),e)}get(t){return super.get(t.toLowerCase())}has(t){return super.has(t.toLowerCase())}remove(t){return super.remove(t.toLowerCase())}};n(D,"DictionaryNoCase");let k=D;function F(t){if(!t)return 0;if(!isNaN(Number(t)))return Number(t);const e=t.indexOf("ns");if(-1!==e)return parseFloat(t.substr(0,e))/1e9;const r=t.indexOf("ms");if(-1!==r)return parseFloat(t.substr(0,r))/1e3;const s=t.indexOf("s");if(-1!==s&&-1===t.indexOf("days"))return parseFloat(t.substr(0,s));const i=t.split(" days "),n=i.length>1?parseFloat(i[0]):0;let o=0;const a=(i.length>1?i[1]:i[0]).split(":").reverse();for(let h=0;h<a.length;++h)o+=parseFloat(a[h])*Math.pow(60,h);return 24*n*60*60+o}n(F,"espTime2Seconds");let $=(n(t=class{_graph;parent;props={};constructor(t,e){this._graph=t,this.parent=e}},"GraphItem"),t),T=(n(e=class extends ${subgraphs=[];vertices=[];edges=[];_;constructor(t,e,r){super(t,e),e&&e._addSubgraph(this),this._=r}remove(t=!0){this._graph.removeSubgraph(this,t)}createSubgraph(t){return this._graph.createSubgraph(this,t)}_addSubgraph(t){if(this.subgraphs.indexOf(t)>=0)throw new Error("Subgraph already exists");this.subgraphs.push(t)}_removeSubgraph(t){const e=this.subgraphs.indexOf(t);if(e<0)throw new Error("Subgraph does not exist");this.subgraphs.splice(e,1)}removeAllSubgraphs(){for(let t=this.subgraphs.length-1;t>=0;--t)this._graph.removeSubgraph(this.subgraphs[t],!0)}createVertex(t){return this._graph.createVertex(this,t)}_addVertex(t){if(this.vertices.indexOf(t)>=0)throw new Error("Vertex already exists");this.vertices.push(t)}_removeVertex(t){const e=this.vertices.indexOf(t);if(e<0)throw new Error("Vertex does not exist");this.vertices.splice(e,1)}removeAllVertices(){for(let t=this.vertices.length-1;t>=0;--t)this._graph.removeVertex(this.vertices[t],!0)}createEdge(t,e,r){return this._graph.createEdge(this,t,e,r)}_addEdge(t){if(this.edges.indexOf(t)>=0)throw new Error("Edge already exists");this.edges.push(t)}_removeEdge(t){const e=this.edges.indexOf(t);if(e<0)throw new Error("Edge does not exist");this.edges.splice(e,1)}_add(t){t instanceof e?this._addSubgraph(t):t instanceof C?this._addVertex(t):this._addEdge(t)}},"Subgraph"),e),C=(n(r=class extends ${inEdges=[];outEdges=[];get edges(){return[...this.inEdges,...this.outEdges]}_;constructor(t,e,r){super(t,e),e._addVertex(this),this._=r}remove(t=!0,e){return this._graph.removeVertex(this,t,e)}addInEdge(t){this.inEdges.push(t)}removeInEdge(t){const e=this.inEdges.indexOf(t);if(e<0)throw new Error("In edge does not exist");this.inEdges.splice(e,1)}addOutEdge(t){this.outEdges.push(t)}removeOutEdge(t){const e=this.outEdges.indexOf(t);if(e<0)throw new Error("Out edge does not exist");this.outEdges.splice(e,1)}},"Vertex"),r),L=(n(s=class extends ${source;target;_;constructor(t,e,r,s,i){if(super(t,e),!r)throw new Error("Missing source vertex");if(!s)throw new Error("Missing target vertex");e._addEdge(this),this.source=r,this.source.addOutEdge(this),this.target=s,this.target.addInEdge(this),this._=i}remove(){this._graph.removeEdge(this)}},"Edge"),s);const P=class _Graph{root;_allSubgraphs=[];_allSubgraphsMap={};_allVertices=[];_allVerticesMap={};_allEdges=[];_allEdgesMap={};idOf;constructor(t=t=>""+t._,e){this.root=new T(this,null,e),this.idOf=t}createSubgraph(t,e){const r=new T(this,t||this.root,e);return this._allSubgraphs.push(r),this._allSubgraphsMap[this.idOf(r)]=r,r}removeSubgraph(t,e=!0){const r=this._allSubgraphs.indexOf(t);if(r<0)throw new Error("Subgraph does not exist");this._allSubgraphs.splice(r,1),delete this._allSubgraphsMap[this.idOf(t)],t.parent&&t.parent._removeSubgraph(t),t.edges.forEach(r=>e?this.removeEdge(r):t.parent._addEdge(r)),t.vertices.forEach(r=>e?this.removeVertex(r,e):t.parent._addVertex(r)),t.subgraphs.forEach(r=>e?this.removeSubgraph(r,e):t.parent._addSubgraph(r))}get subgraphs(){return this._allSubgraphs}subgraph(t){return this._allSubgraphsMap[t]}createVertex(t,e){const r=new C(this,t,e);return this._allVertices.push(r),this._allVerticesMap[this.idOf(r)]=r,r}removeVertex(t,e=!0,r){const s=this._allVertices.indexOf(t);if(s<0)throw new Error("Vertex does not exist");this._allVertices.splice(s,1),delete this._allVerticesMap[this.idOf(t)],t.parent&&t.parent._removeVertex(t),e||t.inEdges.forEach(e=>{t.outEdges.forEach(t=>{this.createEdge(this.root,e.source,t.target,r?r(e.source._,t.target._):void 0)})}),t.inEdges.forEach(t=>this.removeEdge(t)),t.outEdges.forEach(t=>this.removeEdge(t))}get vertices(){return this._allVertices}vertex(t){return this._allVerticesMap[t]}createEdge(t,e,r,s){const i=new L(this,t,e,r,s);return this._allEdges.push(i),this._allEdgesMap[this.idOf(i)]=i,i}removeEdge(t){const e=this._allEdges.indexOf(t);if(e<0)throw new Error("Edge does not exist");this._allEdges.splice(e,1),delete this._allEdgesMap[this.idOf(t)],t.parent&&t.parent._removeEdge(t),t.source.removeOutEdge(t),t.target.removeInEdge(t)}get edges(){return this._allEdges}edge(t){return this._allEdgesMap[t]}_walk(t,e){for(const r of t.subgraphs)switch(e(r)){case"abort":return!0;case"stepover":break;default:if(this._walk(r,e))return!0}for(const r of t.vertices)if("abort"===e(r))return!0}walk(t){this._walk(this.root,t);for(const e of this._allEdges)if("abort"===t(e))return!0}clone(){const t=new(0,this.constructor)(this.idOf,this.root._),e=A();return e.put(this.root,t.root),this.walk(t=>{const r=e.get(t.parent);if(t instanceof T)e.put(t,r.createSubgraph(t._));else if(t instanceof C)e.put(t,r.createVertex(t._));else if(t instanceof L){const s=e.get(t.source),i=e.get(t.target);r.createEdge(s,i,t._)}}),t}};n(P,"Graph");let N=P;function A(){const t=[],e=[];return{put(r,s){const i=t.indexOf(r);-1===i?(t.push(r),e.push(s)):e[i]=s},get:r=>e[t.indexOf(r)]}}n(A,"ObjMap");const j=class _GraphItem{_graph;_;id(){return this._graph.id(this._)}constructor(t,e){this._graph=t,this._=e}};n(j,"GraphItem");let q=j;const X=class _ChildGraphItem extends q{_parent;constructor(t,e){super(t,e)}clearParent(){return this._parent&&(this._parent.removeChild(this),delete this._parent),this}parent(t){return 0===arguments.length?this._parent:(this._parent!==t&&(this._parent&&this._parent.removeChild(this),this._parent=t,this._parent&&this._parent.addChild(this)),this)}};n(X,"ChildGraphItem");let G=X;const H=class _Subgraph extends G{_children=[];constructor(t,e){super(t,e)}children(){return this._children}addChild(t){this._children.push(t)}removeChild(t){this._children=this._children.filter(e=>e.id!==t.id)}};n(H,"Subgraph");let R=H;const z=class _Vertex extends G{_inEdges=[];_outEdges=[];constructor(t,e){super(t,e)}edges(){return[...this._inEdges,...this._outEdges]}edgeCount(){return this._outEdges.length+this._inEdges.length}inEdges(){return this._inEdges}addInEdge(t){this._inEdges.push(t)}removeInEdge(t){this._inEdges=this._inEdges.filter(e=>e._.id!==t)}outEdges(){return this._outEdges}addOutEdge(t){this._outEdges.push(t)}removeOutEdge(t){this._outEdges=this._outEdges.filter(e=>e._.id!==t)}};n(z,"Vertex");let B=z;const W=class _Edge extends G{_source;_target;constructor(t,e,r,s){super(t,e),this._source=r,this._target=s}};n(W,"Edge");let J=W;const U=class _Graph2{_directed;_subgraphMap={};_vertexMap={};_edgeMap={};constructor(t=!0){this._directed=t}clear(){return this._subgraphMap={},this._vertexMap={},this._edgeMap={},this}clearParents(){for(const t in this._subgraphMap)this._subgraphMap[t].clearParent();for(const t in this._vertexMap)this._vertexMap[t].clearParent();return this}isDirected(){return this._directed}_idFunc=/* @__PURE__ */n(t=>"function"==typeof t.id?t.id():t.id,"_idFunc");idFunc(t){return this._idFunc=t,this}_sourceFunc=/* @__PURE__ */n(t=>"function"==typeof t.source?t.source():t.source,"_sourceFunc");sourceFunc(t){return this._sourceFunc=t,this}_targetFunc=/* @__PURE__ */n(t=>"function"==typeof t.target?t.target():t.target,"_targetFunc");targetFunc(t){return this._targetFunc=t,this}_updateFunc=/* @__PURE__ */n((t,e)=>e,"_updateFunc");updateFunc(t){return this._updateFunc=t,this}id(t){return this._idFunc(t)}type(t){return this.subgraphExists(t)?"S":this.vertexExists(t)?"V":this.edgeExists(t)?"E":""}isSubgraph(t){return this.subgraphExists(this.id(t))}isVertex(t){return this.vertexExists(this.id(t))}isEdge(t){return this.edgeExists(this.id(t))}allItems(){return[...this.allSubgraphs(),...this.allVertices(),...this.allEdges()]}item(t){return this.subgraphExists(t)?this.subgraph(t):this.vertexExists(t)?this.vertex(t):this.edgeExists(t)?this.edge(t):void 0}itemExists(t){return this.edgeExists(t)||this.vertexExists(t)||this.subgraphExists(t)}allSubgraphs(){const t=[];for(const e in this._subgraphMap)t.push(this._subgraphMap[e]._);return t}subgraphs(){const t=[];for(const e in this._subgraphMap)void 0===this._subgraphMap[e].parent()&&t.push(this._subgraphMap[e]._);return t}subgraphExists(t){return!!this._subgraphMap[t]}subgraph(t){return this._subgraphMap[t]._}subgraphSubgraphs(t){return this._subgraphMap[t].children().filter(t=>this.isSubgraph(t._)).map(t=>t._)}subgraphVertices(t){return this._subgraphMap[t].children().filter(t=>this.isVertex(t._)).map(t=>t._)}subgraphEdges(t){return this._subgraphMap[t].children().filter(t=>this.isEdge(t._)).map(t=>t._)}addSubgraph(t,e){const r=this._idFunc(t);if(this._subgraphMap[r])throw new Error(`Subgraph '${r}' already exists.`);const s=new R(this,t);if(e){const t=this._idFunc(e);if(!this._subgraphMap[t])throw new Error(`Subgraph '${t}' does not exist.`);s.parent(this._subgraphMap[t])}return this._subgraphMap[r]=s,this}mergeSubgraphs(t=[]){const e=d(this.allSubgraphs(),t,t=>this._idFunc(t),this._updateFunc);return e.exit.forEach(t=>this.removeSubgraph(this._idFunc(t))),e.enter.forEach(t=>this.addSubgraph(t)),e.update.forEach(t=>this.updateSubgraph(t)),this}updateSubgraph(t){const e=this._idFunc(t),r=this._subgraphMap[e];if(!r)throw new Error(`Subgraph '${e}' does not exist.`);return r._=t,this}removeSubgraph(t,e=!0){const r=this._subgraphMap[t];if(!r)throw new Error(`Subgraph '${t}' does not exist.`);return r.children().forEach(t=>{e?t.parent(r.parent()):t instanceof R?this.removeSubgraph(t.id()):this.removeVertex(t.id())}),delete this._subgraphMap[t],this}subgraphParent(t,e){const r=this._subgraphMap[t];if(!r)throw new Error(`Subgraph '${t}' does not exist.`);if(void 0===e){const t=r.parent();return t?t._:void 0}const s=this._subgraphMap[e];if(!s)throw new Error(`Vertex parent '${s}' does not exist.`);return r.parent(s),this}allVertices(){const t=[];for(const e in this._vertexMap)t.push(this._vertexMap[e]._);return t}vertices(){const t=[];for(const e in this._vertexMap)void 0===this._vertexMap[e].parent()&&t.push(this._vertexMap[e]._);return t}vertexExists(t){return!!this._vertexMap[t]}vertex(t){return this._vertexMap[t]._}allEdges(){const t=[];for(const e in this._edgeMap)t.push(this._edgeMap[e]._);return t}edges(){const t=[];for(const e in this._edgeMap)void 0===this._edgeMap[e].parent()&&t.push(this._edgeMap[e]._);return t}vertexEdges(t){return this._vertexMap[t].edges().map(t=>t._)}inEdges(t){return this._vertexMap[t].inEdges().map(t=>t._)}outEdges(t){return this._vertexMap[t].outEdges().map(t=>t._)}_neighbors(t){return[...this._vertexMap[t].outEdges().map(t=>t._target),...this._vertexMap[t].inEdges().map(t=>t._source)]}neighbors(t){return this._neighbors(t).map(t=>t._)}singleNeighbors(t){return this._neighbors(t).filter(t=>1===t.edgeCount()).map(t=>t._)}addVertex(t,e){const r=this._idFunc(t);if(this._vertexMap[r])throw new Error(`Vertex '${r}' already exists.`);const s=new B(this,t);if(e){const t=this._idFunc(e);if(!this.subgraphExists(t))throw new Error(`Subgraph '${t}' does not exist.`);s.parent(this._subgraphMap[t])}return this._vertexMap[r]=s,this}mergeVertices(t){const e=d(this.allVertices(),t,t=>this._idFunc(t),this._updateFunc);return e.exit.forEach(t=>this.removeVertex(this._idFunc(t))),e.enter.forEach(t=>this.addVertex(t)),e.update.forEach(t=>this.updateVertex(t)),this}updateVertex(t){const e=this._idFunc(t),r=this._vertexMap[e];if(!r)throw new Error(`Vertex '${e}' does not exist.`);return r._=t,this}removeVertex(t){const e=this._vertexMap[t];if(!e)throw new Error(`Vertex '${t}' does not exist.`);return e.edges().forEach(t=>{this.removeEdge(t.id())}),delete this._vertexMap[t],this}vertexParent(t,e){const r=this._vertexMap[t];if(!r)throw new Error(`Vertex '${t}' does not exist.`);if(void 0===e){const t=r.parent();return t?t._:void 0}const s=this._subgraphMap[e];if(!s)throw new Error(`Vertex parent '${s}' does not exist.`);return r.parent(s),this}edgeExists(t){return!!this._edgeMap[t]}edge(t){return this._edgeMap[t]._}addEdge(t,e){const r=this._idFunc(t),s=this._sourceFunc(t),i=this._targetFunc(t);if(this._edgeMap[r])throw new Error(`Edge '${r}' already exists.`);if(!this.vertexExists(s))throw new Error(`Edge Source '${s}' does not exist.`);if(!this.vertexExists(i))throw new Error(`Edge Target '${i}' does not exist.`);const n=new J(this,t,this._vertexMap[s],this._vertexMap[i]);if(e){const t=this._idFunc(e);if(!this.subgraphExists(t))throw new Error(`Subgraph '${t}' does not exist.`);n.parent(this._subgraphMap[t])}return this._edgeMap[r]=n,this._vertexMap[s].addOutEdge(n),this._vertexMap[i].addInEdge(n),this}mergeEdges(t){const e=d(this.allEdges(),t,t=>this._idFunc(t),this._updateFunc);return e.exit.forEach(t=>this.removeEdge(this._idFunc(t))),e.enter.forEach(t=>this.addEdge(t)),e.update.forEach(t=>this.updateEdge(t)),this}updateEdge(t){const e=this._idFunc(t),r=this._edgeMap[e];if(!r)throw new Error(`Edge '${e}' does not exist.`);const s=r._source.id(),i=this._sourceFunc(t);s!==i&&(this._vertexMap[s]?.removeOutEdge(e),this._vertexMap[i]?.addOutEdge(r));const n=r._target.id(),o=this._targetFunc(t);return n!==o&&(this._vertexMap[n]?.removeInEdge(e),this._vertexMap[o]?.addInEdge(r)),r._=t,r._source=this._vertexMap[i],r._target=this._vertexMap[o],this}removeEdge(t){const e=this._edgeMap[t];if(!e)throw new Error(`Edge '${t}' does not exist.`);const r=this._idFunc(e._source._);if(!this.vertexExists(r))throw new Error(`Edge Source'${r}' does not exist.`);this._vertexMap[r].removeOutEdge(t);const s=this._idFunc(e._target._);if(!this.vertexExists(s))throw new Error(`Edge Target'${s}' does not exist.`);return this._vertexMap[s].removeInEdge(t),delete this._edgeMap[t],this}_hwalk(t,e){return t instanceof R?e("subgraph",t._,t.children().map(t=>this._hwalk(t,e))):e("vertex",t._)}hierarchy(t){const e=[];for(const r in this._subgraphMap){const s=this._subgraphMap[r];void 0===s.parent()&&e.push(this._hwalk(s,t))}for(const r in this._vertexMap){const s=this._vertexMap[r];void 0===s.parent()&&e.push(this._hwalk(s,t))}return e}dijkstra(t,e){const r=this.allEdges(),s=new Y,i={},o={},a={};function h(t,e){let r=1/0,s=null;return t.forEach(t=>{e[t]<r&&(r=e[t],s=t)}),s}n(h,"vertex_with_min_dist");for(let n=0;n<r.length;n++){const t=this._sourceFunc(r[n]),e=this._targetFunc(r[n]),i=1;s.add(t),s.add(e),o[t]=1/0,o[e]=1/0,void 0===a[t]&&(a[t]={}),void 0===a[e]&&(a[e]={}),a[t][e]=i,a[e][t]=i}for(o[t]=0;s.size;){const t=h(s,o);if(null===t)break;const r=Object.keys(a[t]).filter(t=>s.has(t));if(s.delete(t),t===e)break;for(const e of r){const r=o[t]+a[t][e];r<o[e]&&(o[e]=r,i[e]=t)}}let c=e;const u=[c];let d=0;for(;void 0!==i[c];)u.unshift(i[c]),d+=a[c][i[c]],c=i[c];return{ids:u,len:d}}sort(t){const e=[],r={},s=/* @__PURE__ */n((t,i=[])=>{const n=t.id();r[n]||(r[n]=!0,i.push(t),t.outEdges().forEach(t=>{i.indexOf(t._target)<0&&s(t._target,[...i])}),e.unshift(t._))},"visit");if(t)s(this._vertexMap[t]);else for(const i in this._vertexMap)s(this._vertexMap[i]);return e}};n(U,"Graph2");let Q=U;const K=class _Set{_content=[];get size(){return this._content.length}has(t){return this._content.indexOf(t)>=0}add(t){this.has(t)||this._content.push(t)}delete(t){const e=this._content.indexOf(t);e>=0&&this._content.splice(e,1)}forEach(t){this._content.forEach(t)}};n(K,"Set");let Y=K;const Z=Array.isArray,tt=Object.keys,et=Object.prototype.hasOwnProperty;function rt(t,e,r=!1){if(t===e)return!0;if(t&&e){if("object"==typeof t&&"object"==typeof e){const s=Z(t),i=Z(e);let n,o,a;if(s&&i){if(o=t.length,o!==e.length)return console.warn(`lengths not equal: ${o} !== ${e.length}`),!1;for(n=o;0!==n--;)if(!rt(t[n],e[n],r))return!1;return!0}if(s!==i)return console.warn(`arrays not equal: ${s} !== ${i}`),!1;const h=t instanceof Date,c=e instanceof Date;if(h!==c)return console.warn(`dates not equal: ${h} !== ${c}`),!1;if(h&&c){const r=t.getTime()===e.getTime();return r||console.warn(`dates not equal: ${t.getTime()} !== ${e.getTime()}`),r}const u=t instanceof RegExp,d=e instanceof RegExp;if(u!==d)return console.warn(`regexps not equal: ${u} !== ${d}`),!1;if(u&&d){const r=t.toString()===e.toString();return r||console.warn(`regexps not equal: ${t.toString()} !== ${e.toString()}`),r}const l=tt(t);if(o=l.length,o!==tt(e).length)return console.warn(`key lengths not equal: ${o} !== ${tt(e).length}`),!1;for(n=o;0!==n--;)if(!et.call(e,l[n]))return console.warn(`${l[n]} in a but not b`),!1;for(n=o;0!==n--;)if(a=l[n],!rt(t[a],e[a],r))return!1;return!0}if(!r&&"function"==typeof t&&"function"==typeof e){const r=t.toString()===e.toString();return r||console.warn(`functions not equal: ${t.toString()} !== ${e.toString()}`),r}}const s=t!=t&&e!=e;return s||console.warn(`values not equal: ${t} !== ${e}`),s}function st(t,e,r=!1){if(t===e)return!0;if(t&&e){if("object"==typeof t&&"object"==typeof e){const s=Z(t),i=Z(e);let n,o,a;if(s&&i){if(o=t.length,o!==e.length)return!1;for(n=o;0!==n--;)if(!st(t[n],e[n],r))return!1;return!0}if(s!==i)return!1;const h=t instanceof Date,c=e instanceof Date;if(h!==c)return!1;if(h&&c)return t.getTime()===e.getTime();const u=t instanceof RegExp,d=e instanceof RegExp;if(u!==d)return!1;if(u&&d)return t.toString()===e.toString();const l=tt(t);if(o=l.length,o!==tt(e).length)return!1;for(n=o;0!==n--;)if(!et.call(e,l[n]))return!1;for(n=o;0!==n--;)if(a=l[n],!st(t[a],e[a],r))return!1;return!0}if(!r&&"function"==typeof t&&"function"==typeof e)return t.toString()===e.toString()}return t!=t&&e!=e}function it(t,e,r=!1){return st(t,e,r)?t:e}n(rt,"verboseDeepEquals"),n(st,"deepEquals"),n(it,"update");const nt="undefined"!=typeof globalThis?globalThis:window,ot="undefined"!=typeof window&&nt===window,at="undefined"!=typeof process&&null!=process.versions&&null!=process.versions.node,ht=at&&null!=process.env&&(null!=process.env.TRAVIS||null!=process.env.GITHUB_ACTIONS||null!=process.env.CI);function ct(t){const e=document.scripts||[];for(let r=document.scripts.length-1;r>=0;--r){const s=e[r];if(s.src){const e=s.src.indexOf(t);if(e>=0)return s.src.substring(0,e)}}return""}n(ct,"getScriptSrc");const ut=class _Stack{stack=[];push(t){return this.stack.push(t),t}pop(){return this.stack.pop()}top(){return this.stack.length?this.stack[this.stack.length-1]:void 0}depth(){return this.stack.length}};n(ut,"Stack");let dt=ut;var lt=/* @__PURE__ */(t=>(t[t.debug=0]="debug",t[t.info=1]="info",t[t.notice=2]="notice",t[t.warning=3]="warning",t[t.error=4]="error",t[t.critical=5]="critical",t[t.alert=6]="alert",t[t.emergency=7]="emergency",t))(lt||{});const pt={debug:"cyan",info:"green",notice:"grey",warning:"blue",error:"red",critical:"magenta",alert:"magenta",emergency:"magenta"},gt=class _ConsoleWriter{write(t,e,r,s){at?console.log(`[${t}] ${lt[e].toUpperCase()} ${r}: ${s}`):console.log(`[${t}] %c${lt[e].toUpperCase()}%c ${r}: ${s}`,`color:${pt[lt[e]]}`,"")}};n(gt,"ConsoleWriter");let _t=gt;const ft=class _Logging{_levelStack=new dt;_level=1;_filter="";_writer=new _t;static Instance(){return this._instance||(this._instance=new this)}constructor(){}stringify(t){const e=[];return JSON.stringify(t,function(t,r){if("object"==typeof r&&null!==r){if(-1!==e.indexOf(r))return;e.push(r)}return r},2)}writer(t){return void 0===t?this._writer:(this._writer=t,this)}log(t,e,r){if(t<this._level)return;if(this._filter&&this._filter!==e)return;const s=/* @__PURE__ */(new Date).toISOString();this._writer.rawWrite?this._writer.rawWrite(s,t,e,r):("string"!=typeof r&&(r=this.stringify(r)),this._writer.write&&this._writer.write(s,t,e,r))}debug(t,e){this.log(0,t,e)}info(t,e){this.log(1,t,e)}notice(t,e){this.log(2,t,e)}warning(t,e){this.log(3,t,e)}error(t,e){this.log(4,t,e)}critical(t,e){this.log(5,t,e)}alert(t,e){this.log(6,t,e)}emergency(t,e){this.log(7,t,e)}level(t){return void 0===t?this._level:(this._level=t,this)}pushLevel(t){return this._levelStack.push(this._level),this._level=t,this}popLevel(){return this._level=this._levelStack.pop(),this}filter(t){return void 0===t?this._filter:(this._filter=t,this)}};var vt,bt;n(ft,"Logging"),((t,e,r)=>{e in t?i(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r})(ft,"symbol"!=typeof(vt="_instance")?vt+"":vt,bt);let Et=ft;const xt=Et.Instance(),mt=class _ScopedLogging{_scopeID;constructor(t){this._scopeID=t}debug(t){xt.debug(this._scopeID,t)}info(t){xt.info(this._scopeID,t)}notice(t){xt.notice(this._scopeID,t)}warning(t){xt.warning(this._scopeID,t)}error(t){xt.error(this._scopeID,t)}critical(t){xt.critical(this._scopeID,t)}alert(t){xt.alert(this._scopeID,t)}emergency(t){xt.emergency(this._scopeID,t)}pushLevel(t){return xt.pushLevel(t),this}popLevel(){return xt.popLevel(),this}};n(mt,"ScopedLogging");let wt=mt;function Mt(t,e=!1){return e&&xt.filter(t),new wt(t)}function St(t){return t*(Math.PI/180)}function yt(t){return t*(180/Math.PI)}function Ot(t,e){return{x:t*Math.cos(e),y:t*Math.sin(e)}}function Vt(t,e){return{r:Math.sqrt(t*t+e*e),theta:Math.atan2(e,t)}}function It(t,e=-Math.PI,r=Math.PI){return kt(t,e,r)}function Dt(t,e=-180,r=180){return kt(t,e,r)}function kt(t,e,r){const s=r-e,i=t-e;return i-Math.floor(i/s)*s+e}function Ft(t,e){if(void 0!==t&&void 0!==e){for(const r of t.split(".")){if(!e.hasOwnProperty(r))return;e=e[r]}return e}}function $t(t,e){return void 0!==Ft(t,e)}function Tt(t,e){const r={};for(const s in e){if(!e.hasOwnProperty(s))continue;if("__proto__"===s||"constructor"===s)continue;let i=e[s];i instanceof Array||"object"==typeof i&&(i=Ct(t[s],i)),s in t&&(t[s]===i||s in r&&r[s]===i)||(t[s]=i)}return t}function Ct(t={},...e){if("object"!=typeof t)throw new Error(`Destination "${t}" must be an object.`);for(const r of e)Tt(t,r);return t}function Lt(t={},...e){return Ct(t,...e)}function Pt(t){const e=[];return JSON.stringify(t,function(t,r){if("object"==typeof r&&null!==r){if(-1!==e.indexOf(r))return;e.push(r)}return r})}function Nt(t){return void 0!==Array.isArray?Array.isArray(t):"[object Array]"===Object.prototype.toString.call(t)}function At(t){const e=t.split("_"),r=e[1].split(".");return{module:`@hpcc-js/${e[0]}`,file:r[0],class:r[1]||r[0]}}n(Mt,"scopedLogger"),n(St,"degreesToRadians"),n(yt,"radiansToDegrees"),n(Ot,"polarToCartesian"),n(Vt,"cartesianToPolar"),n(It,"normalizeRadians"),n(Dt,"normalizeDegrees"),n(kt,"normalize"),n(Ft,"inner"),n($t,"exists"),n(Tt,"_mixin"),n(Ct,"deepMixin"),n(Lt,"deepMixinT"),n(Pt,"safeStringify"),n(Nt,"isArray"),n(At,"classID2Meta");const jt=class _ObserverHandle{eventTarget;eventID;callback;constructor(t,e,r){this.eventTarget=t,this.eventID=e,this.callback=r}release(){this.eventTarget.removeObserver(this.eventID,this.callback)}unwatch(){this.release()}};n(jt,"ObserverHandle");let qt=jt;const Xt=class _Observable{_eventObservers={};constructor(...t){}addObserver(t,e){let r=this._eventObservers[t];return r||(r=[],this._eventObservers[t]=r),r.push(e),new qt(this,t,e)}removeObserver(t,e){const r=this._eventObservers[t];if(r)for(let s=r.length-1;s>=0;--s)r[s]===e&&r.splice(s,1);return this}dispatchEvent(t,...e){const r=this._eventObservers[t];if(r)for(const s of r)s(...e);return this}_hasObserver(t){const e=this._eventObservers[t];for(const r in e)if(e[r])return!0;return!1}hasObserver(t){if(void 0!==t)return this._hasObserver(t);for(const e in this._eventObservers)if(this._hasObserver(e))return!0;return!1}};n(Xt,"Observable");let Gt,Ht=Xt;!function(){if(nt.requestAnimationFrame)Gt=nt.requestAnimationFrame;else{let t=0;Gt=/* @__PURE__ */n(function(e){const r=/* @__PURE__ */(new Date).getTime(),s=Math.max(0,16-(r-t)),i=setTimeout(()=>e(r+s),s);return t=r+s,i},"requestAnimationFrame")}}();const Rt=class _Message{get canConflate(){return!1}conflate(t){return!1}void(){return!1}};n(Rt,"Message");let zt=Rt;const Bt=class _Dispatch{_observerID=0;_observers=[];_messageBuffer=[];_rafHandle=void 0;constructor(){}observers(){return this._observers}messages(){const t=[];return this._messageBuffer.forEach(e=>{t.some(t=>t.canConflate&&t.conflate(e))||t.push(e)}),t}dispatchAll(){this._rafHandle=void 0,this.dispatch(this.messages()),this.flush()}dispatch(t){0!==t.length&&this.observers().forEach(e=>{const r=t.filter(t=>!t.void()&&(void 0===e.type||t instanceof e.type));r.length&&e.callback(r)})}hasObserver(){return this._observers.length>0}flush(){this._messageBuffer=[]}send(t){this.hasObserver()&&this.dispatch([t])}post(t){this.hasObserver()&&(this._messageBuffer.push(t),void 0===this._rafHandle&&(this._rafHandle=Gt(()=>this.dispatchAll())))}attach(t,e){const r=this,s=++this._observerID;return this._observers.push({id:s,type:e,callback:t}),{release(){r._observers=r._observers.filter(t=>t.id!==s)},unwatch(){this.release()}}}};n(Bt,"Dispatch");let Wt=Bt;const Jt=class _XMLNode{name="";$={};_children=[];content="";constructor(t){this.name=t}appendAttribute(t,e){this.$[t]=e}appendContent(t){this.content+=t}appendChild(t){this._children.push(t)}children(t){return void 0===t?this._children:this._children.filter(e=>e.name===t)}};n(Jt,"XMLNode");let Ut=Jt;const Qt=class _SAXStackParser{root;stack=new dt;constructor(){}walkDoc(t){const e=this._startXMLNode(t);if(t.attributes)for(let r=0;r<t.attributes.length;++r){const e=t.attributes.item(r);this.attributes(e.nodeName,e.nodeValue)}if(this.startXMLNode(e),t.childNodes)for(let r=0;r<t.childNodes.length;++r){const e=t.childNodes.item(r);e.nodeType===e.TEXT_NODE?this.characters(e.nodeValue):this.walkDoc(e)}this.endXMLNode(this.stack.pop())}_startXMLNode(t){const e=new Ut(t.nodeName);return this.stack.depth()?this.stack.top().appendChild(e):this.root=e,this.stack.push(e)}parse(t){const e=(new DOMParser).parseFromString(t,"application/xml");this.startDocument(),this.walkDoc(e),this.endDocument()}startDocument(){}endDocument(){}startXMLNode(t){}endXMLNode(t){}attributes(t,e){this.stack.top().appendAttribute(t,e)}characters(t){this.stack.top().appendContent(t)}};n(Qt,"SAXStackParser");let Kt=Qt;const Yt=class _XML2JSONParser extends Kt{startXMLNode(t){super.startXMLNode(t),t.name}endXMLNode(t){t.name,super.endXMLNode(t)}};n(Yt,"XML2JSONParser");let Zt=Yt;function te(t){const e=new Zt;return e.parse(t),e.root}n(te,"xml2json");const ee=class _PropChangedMessage extends zt{constructor(t,e,r){super(),this.property=t,this.newValue=e,this.oldValue=r}get canConflate(){return!0}conflate(t){return this.property===t.property&&(this.newValue=t.newValue,!0)}void(){return st(this.newValue,this.oldValue)}};n(ee,"PropChangedMessage");let re=ee;const se=class _StateObject{_espState={};_dispatch=new Wt;_monitorHandle;_monitorTickCount=0;clear(t){this._espState={},void 0!==t&&this.set(t),this._monitorTickCount=0}get(t,e){return void 0===t?this._espState:this.has(t)?this._espState[t]:e}set(t,e){if("string"==typeof t)return this.setSingle(t,e);this.setAll(t)}setSingle(t,e){const r=this._espState[t];this._espState[t]=e,this._dispatch.post(new re(t,e,r))}setAll(t){for(const e in t)t.hasOwnProperty(e)&&this.setSingle(e,t[e])}has(t){return void 0!==this._espState[t]}addObserver(t,e,r){if(this.isCallback(e)){if("changed"!==t)throw new Error("Invalid eventID: "+t);return this._dispatch.attach(t=>{e(t.map(t=>({id:t.property,oldValue:t.oldValue,newValue:t.newValue})))})}if("propChanged"!==t)throw new Error("Invalid eventID: "+t);return this._dispatch.attach(t=>{const s=t.filter(t=>t.property===e);if(s.length){s.length>1&&console.warn("Should only be 1 message?");const t=s[s.length-1];r({id:t.property,oldValue:t.oldValue,newValue:t.newValue})}})}on(t,e,r){return this.addObserver(t,e,r),this}isCallback(t){return"function"==typeof t}hasEventListener(){return this._dispatch.hasObserver()}async refresh(t=!1){return await Promise.resolve(),this}_monitor(){this._monitorHandle?this._monitorTickCount=0:this._monitorHandle=setTimeout(()=>{(this.hasEventListener()?this.refresh():Promise.resolve()).then(()=>{this._monitor()}),delete this._monitorHandle},this._monitorTimeoutDuration())}_monitorTimeoutDuration(){return++this._monitorTickCount,this._monitorTickCount<=1?0:3e4}watch(t,e=!0){if("function"!=typeof t)throw new Error("Invalid Callback");e&&setTimeout(()=>{const e=this.get(),r=[];for(const t in e)e.hasOwnProperty(e)&&r.push({id:t,newValue:e[t],oldValue:void 0});t(r)},0);const r=this.addObserver("changed",t);return this._monitor(),r}};n(se,"StateObject");let ie=se;function ne(t,e){if("string"!=typeof e)return t;if(0===e.length)return t;for(;0===t.indexOf(e);)t=t.substring(1);for(;oe(t,e);)t=t.substring(0,t.length-1);return t}function oe(t,e,r){const s=t.toString();("number"!=typeof r||!isFinite(r)||Math.floor(r)!==r||r>s.length)&&(r=s.length),r-=e.length;const i=s.lastIndexOf(e,r);return-1!==i&&i===r}function ae(...t){const e=t.reduce((t,e)=>(t.length>0&&(e=e.replace(/^\//,"")),e=e.replace(/\/$/,""),[...t,...e.split("/")]),[]),r=[];for(const s of e)"."!==s&&(".."!==s?r.push(s):r.pop());return r.join("/")}function he(t){return ae(t,"..")}n(ne,"trim"),n(oe,"endsWith"),n(ae,"join"),n(he,"dirname");export{m as AsyncCache,y as AsyncOrderedQueue,h as BUILD_VERSION,E as Cache,I as Dictionary,k as DictionaryNoCase,Wt as Dispatch,L as Edge,N as Graph,Q as Graph2,$ as GraphItem,lt as Level,Et as Logging,zt as Message,Ht as Observable,o as PKG_NAME,a as PKG_VERSION,Kt as SAXStackParser,wt as ScopedLogging,dt as Stack,ie as StateObject,T as Subgraph,C as Vertex,Ut as XMLNode,Vt as cartesianToPolar,At as classID2Meta,u as compare,d as compare2,w as debounce,st as deepEquals,Ct as deepMixin,Lt as deepMixinT,St as degreesToRadians,he as dirname,oe as endsWith,F as espTime2Seconds,$t as exists,c as find,ct as getScriptSrc,v as hashSum,Ft as inner,Nt as isArray,ot as isBrowser,ht as isCI,at as isNode,ae as join,xt as logger,kt as normalize,Dt as normalizeDegrees,It as normalizeRadians,Ot as polarToCartesian,M as promiseTimeout,yt as radiansToDegrees,nt as root,Pt as safeStringify,Mt as scopedLogger,O as sleep,ne as trim,it as update,rt as verboseDeepEquals,te as xml2json};
2224
2
  //# sourceMappingURL=index.js.map