@woosh/meep-engine 2.105.0 → 2.106.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/build/bundle-worker-image-decoder.js +1 -1
- package/build/bundle-worker-terrain.js +1 -1
- package/build/meep.cjs +358 -188
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +358 -188
- package/package.json +1 -1
- package/src/core/assert.d.ts.map +1 -1
- package/src/core/assert.js +3 -1
- package/src/core/cache/Cache.d.ts.map +1 -1
- package/src/core/cache/Cache.js +23 -19
- package/src/core/collection/array/array_copy.spec.d.ts +2 -0
- package/src/core/collection/array/array_copy.spec.d.ts.map +1 -0
- package/src/core/collection/array/array_copy.spec.js +19 -0
- package/src/core/collection/list/List.d.ts.map +1 -1
- package/src/core/collection/list/List.js +55 -30
- package/src/core/collection/list/List.spec.js +101 -0
- package/src/core/collection/list/ListForwarder.d.ts.map +1 -1
- package/src/core/collection/list/ListForwarder.js +49 -53
- package/src/core/collection/list/ListForwarder.spec.js +2 -0
- package/src/core/collection/list/SortedListProjection.d.ts +4 -1
- package/src/core/collection/list/SortedListProjection.d.ts.map +1 -1
- package/src/core/collection/list/SortedListProjection.js +4 -1
- package/src/core/collection/map/AbstractAsyncMap.d.ts.map +1 -1
- package/src/core/collection/map/AbstractAsyncMap.js +0 -3
- package/src/core/collection/map/AsyncMapWrapper.d.ts +6 -10
- package/src/core/collection/map/AsyncMapWrapper.d.ts.map +1 -1
- package/src/core/collection/map/AsyncMapWrapper.js +14 -9
- package/src/core/collection/map/HashMap.d.ts.map +1 -1
- package/src/core/collection/map/HashMap.js +30 -3
- package/src/core/collection/map/ObservedMap.d.ts +12 -3
- package/src/core/collection/map/ObservedMap.d.ts.map +1 -1
- package/src/core/collection/map/ObservedMap.js +14 -4
- package/src/core/collection/queue/Deque.d.ts.map +1 -1
- package/src/core/collection/queue/Deque.js +100 -95
- package/src/core/collection/set/ArraySet.d.ts.map +1 -0
- package/src/core/collection/set/{Set.js → ArraySet.js} +2 -2
- package/src/core/collection/set/set_remove.d.ts +3 -3
- package/src/core/collection/set/set_remove.d.ts.map +1 -1
- package/src/core/collection/set/set_remove.js +5 -5
- package/src/core/color/oklab/find_gamut_intersection.js +1 -1
- package/src/core/geom/2d/Rectangle.d.ts +54 -5
- package/src/core/geom/2d/Rectangle.d.ts.map +1 -1
- package/src/core/geom/2d/Rectangle.js +70 -3
- package/src/core/geom/2d/circle/Circle.d.ts +1 -1
- package/src/core/geom/2d/circle/Circle.js +1 -1
- package/src/core/geom/2d/compute_triangle_area_2d.d.ts.map +1 -1
- package/src/core/geom/2d/compute_triangle_area_2d.js +7 -1
- package/src/core/geom/2d/shape/AbstractShape.d.ts +2 -0
- package/src/core/geom/2d/shape/AbstractShape.d.ts.map +1 -1
- package/src/core/geom/2d/shape/AbstractShape.js +8 -2
- package/src/core/geom/2d/shape/CircleShape.d.ts +14 -0
- package/src/core/geom/2d/shape/CircleShape.d.ts.map +1 -1
- package/src/core/geom/2d/shape/CircleShape.js +64 -22
- package/src/core/geom/2d/uv_map_circle_to_square.d.ts +8 -0
- package/src/core/geom/2d/uv_map_circle_to_square.d.ts.map +1 -0
- package/src/core/geom/2d/{UvUtils.js → uv_map_circle_to_square.js} +2 -17
- package/src/core/geom/2d/uv_map_circle_to_square.spec.d.ts +2 -0
- package/src/core/geom/2d/uv_map_circle_to_square.spec.d.ts.map +1 -0
- package/src/core/geom/2d/uv_map_circle_to_square.spec.js +28 -0
- package/src/core/geom/2d/uv_map_square_to_circle.d.ts +8 -0
- package/src/core/geom/2d/uv_map_square_to_circle.d.ts.map +1 -0
- package/src/core/geom/2d/uv_map_square_to_circle.js +14 -0
- package/src/core/geom/2d/uv_map_square_to_circle.spec.d.ts +2 -0
- package/src/core/geom/2d/uv_map_square_to_circle.spec.d.ts.map +1 -0
- package/src/core/geom/2d/uv_map_square_to_circle.spec.js +30 -0
- package/src/core/geom/Vector3.d.ts +13 -4
- package/src/core/geom/Vector3.d.ts.map +1 -1
- package/src/core/geom/Vector3.js +83 -36
- package/src/core/geom/Vector3.spec.js +113 -12
- package/src/core/collection/set/Set.d.ts.map +0 -1
- package/src/core/geom/2d/Geometry2D.d.ts +0 -31
- package/src/core/geom/2d/Geometry2D.d.ts.map +0 -1
- package/src/core/geom/2d/Geometry2D.js +0 -59
- package/src/core/geom/2d/UvUtils.d.ts +0 -15
- package/src/core/geom/2d/UvUtils.d.ts.map +0 -1
- package/src/core/geom/2d/UvUtils.spec.d.ts +0 -2
- package/src/core/geom/2d/UvUtils.spec.d.ts.map +0 -1
- package/src/core/geom/2d/UvUtils.spec.js +0 -55
- /package/src/core/collection/set/{Set.d.ts → ArraySet.d.ts} +0 -0
package/package.json
CHANGED
package/src/core/assert.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../../src/core/assert.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../../src/core/assert.js"],"names":[],"mappings":"AA+BA,6CAIC;;IAsJD;;;;;OAKG;IACH,kEAQC;;;;;;;;;;;;;;;IAmBD;;;;;;OAMG;IACH,uGAGC;IAGD;;;;OAIG;IACH,0DAMC;IAED;;;;OAIG;IACH,0DAMC;IAED;;;;OAIG;IACH,2DAMC;IAED;;;;OAIG;IACH,4DAMC;IAED;;;;OAIG;IACH,0DAMC;IAED;;;;OAIG;IACH,2DAMC;IAED;;;;OAIG;IACH,sEAMC;IAED;;;;OAIG;IACH,4DAKC;IAED;;;;OAIG;IACH,+EAKC;IAGD;;;;OAIG;IACH,yDAMC;IAED;;;;OAIG;IACH,wDAIC;IAED;;;;OAIG;IACH,yDAMC;IAED;;;;OAIG;IACH,2DAIC;IAED;;;;OAIG;IACH,mEAIC;IAED;;;;;OAKG;IACH,2EAgBC;;AA/ZD,wDAEC;AAED,6CAEC;AAfD,qDAOC;AAUD;;;;;GAKG;AACH,kCAJW,MAAM,KACN,MAAM,MACN,MAAM,QAIhB;AAQD;;;;;GAKG;AACH,gCAJW,MAAM,KACN,MAAM,MACN,MAAM,QAiBhB;AAyBD;;;;;GAKG;AACH,uCAJW,MAAM,KACN,MAAM,MACN,MAAM,QAiBhB;AA5CD;;;;;GAKG;AACH,6BAJW,MAAM,KACN,MAAM,MACN,MAAM,QAiBhB;AAyBD;;;;;GAKG;AACH,oCAJW,MAAM,KACN,MAAM,MACN,MAAM,QAiBhB;AAKD;;;;;GAKG;AACH,0CAHW,MAAM,cACN,MAAM,QAehB;AAED;;;;;GAKG;AACH,iEAFW,MAAM,QAIhB;AAED;;;;;GAKG;AACH,mEAFW,MAAM,QAIhB;AAED;;;;;GAKG;AACH,+IAFW,MAAM,QAMhB"}
|
package/src/core/assert.js
CHANGED
|
@@ -4,7 +4,9 @@ import { InMemoryDescriptor } from "./debug/InMemoryDescriptor.js";
|
|
|
4
4
|
|
|
5
5
|
function equal(a, b, m) {
|
|
6
6
|
if (a !== b) {
|
|
7
|
-
const
|
|
7
|
+
const details = `${a} !== ${b}`;
|
|
8
|
+
|
|
9
|
+
const message = (m !== undefined && m !== "") ? `${m}. ${details}` : details;
|
|
8
10
|
throw new Error(message);
|
|
9
11
|
}
|
|
10
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Cache.d.ts","sourceRoot":"","sources":["../../../../src/core/cache/Cache.js"],"names":[],"mappings":"AASA;;;;;GAKG;AACH;IASI;;;;;;;;OAQG;IACH,sGARW,MAAM,EAuFhB;IAxDG;;;;OAIG;IACH,mBAA4B;IAE5B;;;;OAIG;IACH,qBAAgC;IAEhC;;;;OAIG;IACH,gBAAmB;IACnB;;;;OAIG;IACH,eAAkB;IAGlB;;;;OAIG;IACH,aAIE;IAEF;;;OAGG;IACH,WAFU,OAAO,GAAG,EAAC,KAAK,CAAC,CAEE;IAE7B;;;OAGG;IACH,WAFU,OAAO,GAAG,EAAC,KAAK,CAAC,CAEE;IAE7B;;;OAGG;IACH,OAFU,OAAO,GAAG,EAAC,KAAK,CAAC,CAEF;IAG7B;;;;;OAKG;IACH,kBAyBC;IAED;;;OAGG;IACH,QAFa,MAAM,CAIlB;IAED;;OAEG;IACH,+BAEC;IAUD;;;OAGG;IACH,2BAQC;IAED,wBAEC;IAxBD;;;OAGG;IACH,qBAEC;IAoBD;;;;OAIG;IACH,wBAaC;IAED;;;;;;OAMG;IACH,yBAHW,GAAG,GACD,OAAO,CAgCnB;IAED;;;;;OAKG;IACH,6BAUC;IAED;;;OAGG;IACH,sBAFa,aAAa,GAAG,EAAC,KAAK,CAAC,GAAC,IAAI,CAIxC;IAED;;;OAGG;IACH,YAFa,OAAO,CAkBnB;IAED;;;OAGG;IACH,+BAFW,MAAM,QAWhB;IAED;;;;OAIG;IACH,SAHW,GAAG,SACH,KAAK,
|
|
1
|
+
{"version":3,"file":"Cache.d.ts","sourceRoot":"","sources":["../../../../src/core/cache/Cache.js"],"names":[],"mappings":"AASA;;;;;GAKG;AACH;IASI;;;;;;;;OAQG;IACH,sGARW,MAAM,EAuFhB;IAxDG;;;;OAIG;IACH,mBAA4B;IAE5B;;;;OAIG;IACH,qBAAgC;IAEhC;;;;OAIG;IACH,gBAAmB;IACnB;;;;OAIG;IACH,eAAkB;IAGlB;;;;OAIG;IACH,aAIE;IAEF;;;OAGG;IACH,WAFU,OAAO,GAAG,EAAC,KAAK,CAAC,CAEE;IAE7B;;;OAGG;IACH,WAFU,OAAO,GAAG,EAAC,KAAK,CAAC,CAEE;IAE7B;;;OAGG;IACH,OAFU,OAAO,GAAG,EAAC,KAAK,CAAC,CAEF;IAG7B;;;;;OAKG;IACH,kBAyBC;IAED;;;OAGG;IACH,QAFa,MAAM,CAIlB;IAED;;OAEG;IACH,+BAEC;IAUD;;;OAGG;IACH,2BAQC;IAED,wBAEC;IAxBD;;;OAGG;IACH,qBAEC;IAoBD;;;;OAIG;IACH,wBAaC;IAED;;;;;;OAMG;IACH,yBAHW,GAAG,GACD,OAAO,CAgCnB;IAED;;;;;OAKG;IACH,6BAUC;IAED;;;OAGG;IACH,sBAFa,aAAa,GAAG,EAAC,KAAK,CAAC,GAAC,IAAI,CAIxC;IAED;;;OAGG;IACH,YAFa,OAAO,CAkBnB;IAED;;;OAGG;IACH,+BAFW,MAAM,QAWhB;IAED;;;;OAIG;IACH,SAHW,GAAG,SACH,KAAK,QAwEf;IAED;;;;OAIG;IACH,cAHW,GAAG,GACD,OAAO,CAInB;IAED;;;;OAIG;IACH,SAHW,GAAG,GACD,KAAK,GAAC,IAAI,CAYtB;IAGD;;;;;;OAMG;IACH,kBALW,GAAG,kBACM,GAAG,KAAE,KAAK,0BAElB,KAAK,CAchB;IAED;;;;OAIG;IACH,wBAqBC;IAED;;;;OAIG;IACH,YAHW,GAAG,GACD,OAAO,CAgBnB;IAED;;;;;OAKG;IACH,kBAHW,GAAG,GACD,OAAO,CAanB;IAED;;OAEG;IACH,cAcC;IAED;;;OAGG;IACH,aAOC;IAED;;;;;OAKG;IACH,wCAFa,OAAO,CAMnB;IAGL;;;OAGG;IACH,6CAAmB;IAEnB;;;OAGG;IACH,+BA5FiB,OAAO,CA4FF;IAEtB;;;OAGG;IACH,4BA9KiB,OAAO,CA8KL;;CAlBlB;mBA/hBkB,4BAA4B;6BAIlB,mBAAmB"}
|
package/src/core/cache/Cache.js
CHANGED
|
@@ -317,6 +317,22 @@ export class Cache {
|
|
|
317
317
|
let element = this.data.get(key);
|
|
318
318
|
|
|
319
319
|
if (element === undefined) {
|
|
320
|
+
//compute weight
|
|
321
|
+
const elementWeight = this.computeElementWeight(key, value);
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* It's possible that element being added is larger than cache's capacity,
|
|
325
|
+
* in which case entire cache will be evicted, but there still won't be enough space
|
|
326
|
+
* @type {number}
|
|
327
|
+
*/
|
|
328
|
+
const weightTarget = this.#maxWeight - elementWeight;
|
|
329
|
+
|
|
330
|
+
if (weightTarget < 0) {
|
|
331
|
+
// Special case
|
|
332
|
+
// element does not fit into cache, attempting to insert it forcibly would result in a full flush and overflow
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
|
|
320
336
|
element = new CacheElement();
|
|
321
337
|
|
|
322
338
|
element.key = key;
|
|
@@ -334,25 +350,8 @@ export class Cache {
|
|
|
334
350
|
this.__last = element;
|
|
335
351
|
}
|
|
336
352
|
|
|
337
|
-
//compute weight
|
|
338
|
-
const elementWeight = this.computeElementWeight(key, value);
|
|
339
|
-
|
|
340
353
|
element.weight = elementWeight;
|
|
341
354
|
|
|
342
|
-
|
|
343
|
-
/**
|
|
344
|
-
* It's possible that element being added is larger than cache's capacity,
|
|
345
|
-
* in which case entire cache will be evicted, but there still won't be enough space
|
|
346
|
-
* @type {number}
|
|
347
|
-
*/
|
|
348
|
-
const weightTarget = this.#maxWeight - elementWeight;
|
|
349
|
-
|
|
350
|
-
if (weightTarget < 0) {
|
|
351
|
-
// Special case
|
|
352
|
-
// element does not fit into cache, attempting to insert it forcibly would result in a full flush and overflow
|
|
353
|
-
return;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
355
|
//evict elements until there is enough space for the element
|
|
357
356
|
this.evictUntilWeight(weightTarget);
|
|
358
357
|
|
|
@@ -367,9 +366,14 @@ export class Cache {
|
|
|
367
366
|
// same value, no action required
|
|
368
367
|
} else {
|
|
369
368
|
// replace value, adjust weight
|
|
370
|
-
this.#weight -=
|
|
371
|
-
|
|
369
|
+
this.#weight -= element.weight;
|
|
370
|
+
|
|
371
|
+
const elementWeight = this.computeElementWeight(key, value);
|
|
372
|
+
|
|
373
|
+
this.#weight += elementWeight;
|
|
372
374
|
|
|
375
|
+
// assign new values
|
|
376
|
+
element.weight = elementWeight;
|
|
373
377
|
element.value = value;
|
|
374
378
|
}
|
|
375
379
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array_copy.spec.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/array/array_copy.spec.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { array_copy } from "./array_copy.js";
|
|
2
|
+
|
|
3
|
+
test("empty array copy", () => {
|
|
4
|
+
|
|
5
|
+
const target = [];
|
|
6
|
+
|
|
7
|
+
array_copy([], 0, target, 0, 0);
|
|
8
|
+
|
|
9
|
+
expect(target).toEqual([]);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test("copy portion", () => {
|
|
13
|
+
|
|
14
|
+
const target = [7, 8, 9];
|
|
15
|
+
|
|
16
|
+
array_copy([1, 2, 3, 4], 1, target, 1, 2);
|
|
17
|
+
|
|
18
|
+
expect(target).toEqual([7, 2, 3])
|
|
19
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"List.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/list/List.js"],"names":[],"mappings":";AAaA;;;;GAIG;AACH;
|
|
1
|
+
{"version":3,"file":"List.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/list/List.js"],"names":[],"mappings":"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"}
|
|
@@ -31,18 +31,28 @@ class List {
|
|
|
31
31
|
removed: new Signal()
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* @type {T[]}
|
|
37
|
+
*/
|
|
38
|
+
data = []
|
|
39
|
+
|
|
34
40
|
/**
|
|
35
41
|
* @param {[]} [array]
|
|
36
42
|
* @constructor
|
|
37
43
|
*/
|
|
38
44
|
constructor(array) {
|
|
39
45
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
if (array !== undefined) {
|
|
47
|
+
assert.isArray(array, 'array');
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @private
|
|
51
|
+
* @readonly
|
|
52
|
+
* @type {T[]}
|
|
53
|
+
*/
|
|
54
|
+
this.data = array.slice();
|
|
55
|
+
}
|
|
46
56
|
|
|
47
57
|
/**
|
|
48
58
|
* Number of elements in the list
|
|
@@ -138,9 +148,11 @@ class List {
|
|
|
138
148
|
if (index > this.length) {
|
|
139
149
|
console.error(`Overflow, attempted to insert element at ${index} past the list length(=${this.length})`);
|
|
140
150
|
this.length = index;
|
|
141
|
-
}
|
|
142
151
|
|
|
143
|
-
|
|
152
|
+
this.data[index] = el;
|
|
153
|
+
} else {
|
|
154
|
+
this.data.splice(index, 0, el);
|
|
155
|
+
}
|
|
144
156
|
|
|
145
157
|
this.length++;
|
|
146
158
|
|
|
@@ -278,11 +290,11 @@ class List {
|
|
|
278
290
|
addAllUnique(elements) {
|
|
279
291
|
const data = this.data;
|
|
280
292
|
|
|
281
|
-
const
|
|
282
|
-
return data.indexOf(e) === -1 && elements.indexOf(e, i + 1) === -1;
|
|
283
|
-
});
|
|
293
|
+
const length = data.length;
|
|
284
294
|
|
|
285
|
-
|
|
295
|
+
for (let i = 0; i < length; i++) {
|
|
296
|
+
this.addUnique(data[i]);
|
|
297
|
+
}
|
|
286
298
|
}
|
|
287
299
|
|
|
288
300
|
/**
|
|
@@ -292,26 +304,28 @@ class List {
|
|
|
292
304
|
* @returns {T[]}
|
|
293
305
|
*/
|
|
294
306
|
removeMany(index, removeCount) {
|
|
295
|
-
assert.
|
|
307
|
+
assert.isNonNegativeInteger(index, "index");
|
|
296
308
|
assert.ok(index < this.length || index < 0, `index(=${index}) out of range (${this.length})`);
|
|
297
309
|
|
|
298
|
-
const
|
|
310
|
+
const removed_elements = this.data.splice(index, removeCount);
|
|
299
311
|
|
|
300
|
-
const removedCount =
|
|
312
|
+
const removedCount = removed_elements.length;
|
|
301
313
|
|
|
302
314
|
this.length -= removedCount;
|
|
303
315
|
|
|
304
316
|
assert.equal(this.length, this.data.length, `length(=${this.length}) is inconsistent with underlying data array length(=${this.data.length})`)
|
|
305
317
|
|
|
306
|
-
|
|
318
|
+
const onRemoved = this.on.removed;
|
|
319
|
+
|
|
320
|
+
if (onRemoved.hasHandlers()) {
|
|
307
321
|
for (let i = 0; i < removedCount; i++) {
|
|
308
|
-
const element =
|
|
322
|
+
const element = removed_elements[i];
|
|
309
323
|
|
|
310
|
-
|
|
324
|
+
onRemoved.send2(element, index + i);
|
|
311
325
|
}
|
|
312
326
|
}
|
|
313
327
|
|
|
314
|
-
return
|
|
328
|
+
return removed_elements;
|
|
315
329
|
}
|
|
316
330
|
|
|
317
331
|
/**
|
|
@@ -394,8 +408,13 @@ class List {
|
|
|
394
408
|
}
|
|
395
409
|
}
|
|
396
410
|
|
|
397
|
-
|
|
398
|
-
|
|
411
|
+
/**
|
|
412
|
+
*
|
|
413
|
+
* @param {function(a:T, b:T):number} [compare_function]
|
|
414
|
+
* @returns {List}
|
|
415
|
+
*/
|
|
416
|
+
sort(compare_function) {
|
|
417
|
+
Array.prototype.sort.call(this.data, compare_function);
|
|
399
418
|
return this;
|
|
400
419
|
}
|
|
401
420
|
|
|
@@ -560,18 +579,24 @@ class List {
|
|
|
560
579
|
*
|
|
561
580
|
* @param {function(el:T):boolean} matcher
|
|
562
581
|
* @param {function(el:T, index:number):*} callback
|
|
582
|
+
* @returns {boolean}
|
|
563
583
|
*/
|
|
564
584
|
visitFirstMatch(matcher, callback) {
|
|
565
|
-
const
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
const el = data[i];
|
|
570
|
-
if (matcher(el)) {
|
|
571
|
-
callback(el, i);
|
|
572
|
-
return;
|
|
573
|
-
}
|
|
585
|
+
const index = this.findIndex(matcher);
|
|
586
|
+
|
|
587
|
+
if (index === -1) {
|
|
588
|
+
return false;
|
|
574
589
|
}
|
|
590
|
+
|
|
591
|
+
const el = this.data[index];
|
|
592
|
+
|
|
593
|
+
if (matcher(el)) {
|
|
594
|
+
callback(el, index);
|
|
595
|
+
return true;
|
|
596
|
+
} else {
|
|
597
|
+
return false;
|
|
598
|
+
}
|
|
599
|
+
|
|
575
600
|
}
|
|
576
601
|
|
|
577
602
|
/**
|
|
@@ -141,6 +141,29 @@ test("add increases length", () => {
|
|
|
141
141
|
expect(list.length).toBe(2);
|
|
142
142
|
});
|
|
143
143
|
|
|
144
|
+
test("add dispatches relevant signal", () => {
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
*
|
|
148
|
+
* @type {List<number>}
|
|
149
|
+
*/
|
|
150
|
+
const list = new List();
|
|
151
|
+
|
|
152
|
+
const callback = jest.fn();
|
|
153
|
+
|
|
154
|
+
list.on.added.add(callback);
|
|
155
|
+
|
|
156
|
+
list.add(7);
|
|
157
|
+
|
|
158
|
+
expect(callback).toHaveBeenCalledTimes(1);
|
|
159
|
+
expect(callback).toHaveBeenLastCalledWith(7, 0);
|
|
160
|
+
|
|
161
|
+
list.add(11);
|
|
162
|
+
|
|
163
|
+
expect(callback).toHaveBeenCalledTimes(2);
|
|
164
|
+
expect(callback).toHaveBeenLastCalledWith(11, 1);
|
|
165
|
+
});
|
|
166
|
+
|
|
144
167
|
|
|
145
168
|
test("removeIf", () => {
|
|
146
169
|
const list = new List([1, 3, 1]);
|
|
@@ -226,6 +249,12 @@ test("insert", () => {
|
|
|
226
249
|
expect(list.get(1)).toBe("x");
|
|
227
250
|
expect(list.get(2)).toBe("z");
|
|
228
251
|
expect(add_callback).toHaveBeenLastCalledWith("z", 2);
|
|
252
|
+
|
|
253
|
+
// try insert past end
|
|
254
|
+
list.insert(4, "outside");
|
|
255
|
+
|
|
256
|
+
expect(list.length).toEqual(5);
|
|
257
|
+
expect(list.get(4)).toBe("outside");
|
|
229
258
|
});
|
|
230
259
|
|
|
231
260
|
test("map", () => {
|
|
@@ -309,6 +338,20 @@ test("last", () => {
|
|
|
309
338
|
|
|
310
339
|
});
|
|
311
340
|
|
|
341
|
+
test("containsAny", () => {
|
|
342
|
+
|
|
343
|
+
const list = new List([1, 3, 7, 13]);
|
|
344
|
+
|
|
345
|
+
expect(list.containsAny([])).toBe(false);
|
|
346
|
+
expect(list.containsAny([2])).toBe(false);
|
|
347
|
+
expect(list.containsAny([2, 4, 5])).toBe(false);
|
|
348
|
+
expect(list.containsAny([1])).toBe(true);
|
|
349
|
+
expect(list.containsAny([2, 1])).toBe(true);
|
|
350
|
+
expect(list.containsAny([2, 3])).toBe(true);
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
});
|
|
354
|
+
|
|
312
355
|
test("deepCopy", () => {
|
|
313
356
|
|
|
314
357
|
const a = new List();
|
|
@@ -334,4 +377,62 @@ test("slice", () => {
|
|
|
334
377
|
expect(new List([1, 2, 3, 4]).slice(1, 3)).toEqual([2, 3]);
|
|
335
378
|
expect(new List([3, 7, 11]).slice()).toEqual([3, 7, 11]);
|
|
336
379
|
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
test("addAll triggers signals", () => {
|
|
383
|
+
|
|
384
|
+
const list = new List();
|
|
385
|
+
|
|
386
|
+
const callback = jest.fn();
|
|
387
|
+
|
|
388
|
+
list.on.added.add(callback);
|
|
389
|
+
|
|
390
|
+
list.addAll([1, 3, 7]);
|
|
391
|
+
|
|
392
|
+
expect(callback).toHaveBeenCalledTimes(3);
|
|
393
|
+
|
|
394
|
+
expect(callback).toHaveBeenCalledWith(1, 0);
|
|
395
|
+
expect(callback).toHaveBeenCalledWith(3, 1);
|
|
396
|
+
expect(callback).toHaveBeenCalledWith(7, 2);
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
test("compare method", () => {
|
|
400
|
+
|
|
401
|
+
class Thing {
|
|
402
|
+
v = 0
|
|
403
|
+
|
|
404
|
+
constructor(v) {
|
|
405
|
+
this.v = v;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
compare(other) {
|
|
409
|
+
return this.v - other.v;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
expect(new List().compare(new List())).toEqual(0);
|
|
414
|
+
expect(
|
|
415
|
+
new List([new Thing(7)])
|
|
416
|
+
.compare(new List())
|
|
417
|
+
).toBeGreaterThan(0);
|
|
418
|
+
|
|
419
|
+
expect(
|
|
420
|
+
new List()
|
|
421
|
+
.compare(new List([new Thing(7)]))
|
|
422
|
+
).toBeLessThan(0);
|
|
423
|
+
|
|
424
|
+
expect(
|
|
425
|
+
new List([new Thing(7)])
|
|
426
|
+
.compare(new List([new Thing(7)]))
|
|
427
|
+
).toBe(0);
|
|
428
|
+
|
|
429
|
+
expect(
|
|
430
|
+
new List([new Thing(7)])
|
|
431
|
+
.compare(new List([new Thing(3)]))
|
|
432
|
+
).toBeGreaterThan(0);
|
|
433
|
+
|
|
434
|
+
expect(
|
|
435
|
+
new List([new Thing(3)])
|
|
436
|
+
.compare(new List([new Thing(7)]))
|
|
437
|
+
).toBeLessThan(0);
|
|
337
438
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ListForwarder.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/list/ListForwarder.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ListForwarder.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/list/ListForwarder.js"],"names":[],"mappings":"AAEA;;GAEG;AACH;IAsBI;;;OAGG;IACH,8BAOC;IAED;;;OAGG;IACH,2BAEC;IAED;;;;OAIG;IACH,YAHW,KAAK,CAAC,CAAC,GACN,OAAO,CAUlB;IA6BD;;;;OAIG;IACH,eAHW,KAAK,CAAC,CAAC,GACN,OAAO,CAgBlB;IAED,aAkBC;IAED,eAeC;IAED;;;OAGG;IACH,YAFY,OAAO,CAIlB;;CACJ;iBA3JgB,WAAW"}
|
|
@@ -1,45 +1,41 @@
|
|
|
1
|
+
import List from "./List.js";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* @template T
|
|
3
5
|
*/
|
|
4
6
|
export class ListForwarder {
|
|
7
|
+
/**
|
|
8
|
+
* Where the data ends up
|
|
9
|
+
* @type {List<T>}
|
|
10
|
+
* @private
|
|
11
|
+
*/
|
|
12
|
+
#destination = new List();
|
|
5
13
|
|
|
6
14
|
/**
|
|
7
|
-
*
|
|
15
|
+
* Where to take data from
|
|
16
|
+
* @type {List<T>[]}
|
|
17
|
+
* @private
|
|
8
18
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
this.__destination = null;
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
* @type {List<T>[]}
|
|
21
|
-
* @private
|
|
22
|
-
*/
|
|
23
|
-
this.__sources = [];
|
|
24
|
-
/**
|
|
25
|
-
*
|
|
26
|
-
* @type {boolean}
|
|
27
|
-
* @private
|
|
28
|
-
*/
|
|
29
|
-
this.__is_linked = false;
|
|
30
|
-
}
|
|
19
|
+
#sources = [];
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @type {boolean}
|
|
24
|
+
* @private
|
|
25
|
+
*/
|
|
26
|
+
#is_linked = false;
|
|
31
27
|
|
|
32
28
|
/**
|
|
33
29
|
*
|
|
34
30
|
* @param {List<T>} v
|
|
35
31
|
*/
|
|
36
32
|
set destination(v) {
|
|
37
|
-
if (this
|
|
33
|
+
if (this.#is_linked) {
|
|
38
34
|
// already linked
|
|
39
35
|
throw new Error('Invalid state: linked');
|
|
40
36
|
}
|
|
41
37
|
|
|
42
|
-
this
|
|
38
|
+
this.#destination = v;
|
|
43
39
|
}
|
|
44
40
|
|
|
45
41
|
/**
|
|
@@ -47,7 +43,7 @@ export class ListForwarder {
|
|
|
47
43
|
* @return {List<T>}
|
|
48
44
|
*/
|
|
49
45
|
get destination() {
|
|
50
|
-
return this
|
|
46
|
+
return this.#destination;
|
|
51
47
|
}
|
|
52
48
|
|
|
53
49
|
/**
|
|
@@ -56,10 +52,10 @@ export class ListForwarder {
|
|
|
56
52
|
* @return {boolean}
|
|
57
53
|
*/
|
|
58
54
|
add(source) {
|
|
59
|
-
this.
|
|
55
|
+
this.#sources.push(source);
|
|
60
56
|
|
|
61
|
-
if (this
|
|
62
|
-
this
|
|
57
|
+
if (this.#is_linked) {
|
|
58
|
+
this.#link_one(source);
|
|
63
59
|
}
|
|
64
60
|
|
|
65
61
|
return true;
|
|
@@ -70,12 +66,12 @@ export class ListForwarder {
|
|
|
70
66
|
* @param {List<T>} source
|
|
71
67
|
* @private
|
|
72
68
|
*/
|
|
73
|
-
|
|
74
|
-
source.on.added.add(this.
|
|
75
|
-
source.on.removed.add(this.
|
|
69
|
+
#link_one(source) {
|
|
70
|
+
source.on.added.add(this.#destination.add, this.#destination);
|
|
71
|
+
source.on.removed.add(this.#destination.removeOneOf, this.#destination);
|
|
76
72
|
|
|
77
|
-
//
|
|
78
|
-
source.forEach(this.
|
|
73
|
+
// move data to destination
|
|
74
|
+
source.forEach(this.#destination.add, this.#destination);
|
|
79
75
|
}
|
|
80
76
|
|
|
81
77
|
/**
|
|
@@ -83,13 +79,13 @@ export class ListForwarder {
|
|
|
83
79
|
* @param {List<T>} source
|
|
84
80
|
* @private
|
|
85
81
|
*/
|
|
86
|
-
|
|
82
|
+
#unlink_one(source) {
|
|
87
83
|
|
|
88
|
-
source.on.added.remove(this.
|
|
89
|
-
source.on.removed.remove(this.
|
|
84
|
+
source.on.added.remove(this.#destination.add, this.#destination);
|
|
85
|
+
source.on.removed.remove(this.#destination.removeOneOf, this.#destination);
|
|
90
86
|
|
|
91
|
-
//
|
|
92
|
-
source.forEach(this.
|
|
87
|
+
// remove all data from destination
|
|
88
|
+
source.forEach(this.#destination.removeOneOf, this.#destination);
|
|
93
89
|
}
|
|
94
90
|
|
|
95
91
|
/**
|
|
@@ -98,55 +94,55 @@ export class ListForwarder {
|
|
|
98
94
|
* @return {boolean}
|
|
99
95
|
*/
|
|
100
96
|
remove(source) {
|
|
101
|
-
const i = this.
|
|
97
|
+
const i = this.#sources.indexOf(source);
|
|
102
98
|
|
|
103
99
|
if (i === -1) {
|
|
104
100
|
return false;
|
|
105
101
|
}
|
|
106
102
|
|
|
107
|
-
if (this
|
|
108
|
-
this
|
|
103
|
+
if (this.#is_linked) {
|
|
104
|
+
this.#unlink_one(source);
|
|
109
105
|
}
|
|
110
106
|
|
|
111
|
-
this.
|
|
107
|
+
this.#sources.splice(i, 1);
|
|
112
108
|
|
|
113
109
|
return true;
|
|
114
110
|
}
|
|
115
111
|
|
|
116
112
|
link() {
|
|
117
|
-
if (this
|
|
113
|
+
if (this.#is_linked) {
|
|
118
114
|
return;
|
|
119
115
|
}
|
|
120
116
|
|
|
121
|
-
if (this
|
|
117
|
+
if (this.#destination === null) {
|
|
122
118
|
throw new Error('Illegal state: destination not set');
|
|
123
119
|
}
|
|
124
120
|
|
|
125
|
-
this
|
|
121
|
+
this.#is_linked = true;
|
|
126
122
|
|
|
127
|
-
const sources = this
|
|
123
|
+
const sources = this.#sources;
|
|
128
124
|
const n = sources.length;
|
|
129
125
|
for (let i = 0; i < n; i++) {
|
|
130
126
|
const source = sources[i];
|
|
131
127
|
|
|
132
|
-
this
|
|
128
|
+
this.#link_one(source);
|
|
133
129
|
}
|
|
134
130
|
}
|
|
135
131
|
|
|
136
132
|
unlink() {
|
|
137
|
-
if (!this
|
|
133
|
+
if (!this.#is_linked) {
|
|
138
134
|
return;
|
|
139
135
|
}
|
|
140
136
|
|
|
141
|
-
this
|
|
137
|
+
this.#is_linked = false;
|
|
142
138
|
|
|
143
|
-
const sources = this
|
|
139
|
+
const sources = this.#sources;
|
|
144
140
|
const n = sources.length;
|
|
145
141
|
|
|
146
142
|
for (let i = 0; i < n; i++) {
|
|
147
143
|
const source = sources[i];
|
|
148
144
|
|
|
149
|
-
this
|
|
145
|
+
this.#unlink_one(source);
|
|
150
146
|
}
|
|
151
147
|
}
|
|
152
148
|
|
|
@@ -155,6 +151,6 @@ export class ListForwarder {
|
|
|
155
151
|
* @return {boolean}
|
|
156
152
|
*/
|
|
157
153
|
isLinked() {
|
|
158
|
-
return this
|
|
154
|
+
return this.#is_linked;
|
|
159
155
|
}
|
|
160
156
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SortedListProjection.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/list/SortedListProjection.js"],"names":[],"mappings":"AAGA;IACI;;;;OAIG;IACH,mBAHW,
|
|
1
|
+
{"version":3,"file":"SortedListProjection.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/list/SortedListProjection.js"],"names":[],"mappings":"AAGA;;GAEG;AACH;IACI;;;;OAIG;IACH,mBAHW,KAAK,CAAC,CAAC,qBACE,CAAC,QAAC,CAAC,KAAE,MAAM,EAoB9B;IAjBG;;;OAGG;IACH,OAFU,KAAK,CAAC,CAAC,CAEC;IAElB;;;OAGG;IACH,QAFU,KAAK,CAAC,CAAC,CAEO;IAExB;;;OAGG;IACH,mBAFmB,CAAC,QAAE,CAAC,KAAG,MAAM,CAEJ;IAGhC,aAIC;IAED,eAEC;IAED;;;OAGG;IACH,mBAFW,CAAC,QAMX;IAGD,cAUC;CAEJ;iBAhEgB,WAAW"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractAsyncMap.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/map/AbstractAsyncMap.js"],"names":[],"mappings":"AAGA;;GAEG;AACH;
|
|
1
|
+
{"version":3,"file":"AbstractAsyncMap.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/map/AbstractAsyncMap.js"],"names":[],"mappings":"AAGA;;GAEG;AACH;IAEI;;;;OAIG;IACH,SAHW,GAAG,GACF,QAAQ,KAAK,GAAC,SAAS,CAAC,CAInC;IAED;;;;;OAKG;IACH,SAJW,GAAG,SACH,KAAK,GACJ,QAAQ,IAAI,CAAC,CAIxB;CACJ"}
|