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