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