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