@woosh/meep-engine 2.106.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.
Files changed (73) hide show
  1. package/build/meep.cjs +320 -165
  2. package/build/meep.min.js +1 -1
  3. package/build/meep.module.js +320 -165
  4. package/package.json +1 -1
  5. package/src/core/collection/array/array_copy.spec.d.ts +2 -0
  6. package/src/core/collection/array/array_copy.spec.d.ts.map +1 -0
  7. package/src/core/collection/array/array_copy.spec.js +19 -0
  8. package/src/core/collection/list/List.d.ts.map +1 -1
  9. package/src/core/collection/list/List.js +55 -30
  10. package/src/core/collection/list/List.spec.js +101 -0
  11. package/src/core/collection/list/ListForwarder.d.ts.map +1 -1
  12. package/src/core/collection/list/ListForwarder.js +49 -53
  13. package/src/core/collection/list/ListForwarder.spec.js +2 -0
  14. package/src/core/collection/list/SortedListProjection.d.ts +4 -1
  15. package/src/core/collection/list/SortedListProjection.d.ts.map +1 -1
  16. package/src/core/collection/list/SortedListProjection.js +4 -1
  17. package/src/core/collection/map/AbstractAsyncMap.d.ts.map +1 -1
  18. package/src/core/collection/map/AbstractAsyncMap.js +0 -3
  19. package/src/core/collection/map/AsyncMapWrapper.d.ts +6 -10
  20. package/src/core/collection/map/AsyncMapWrapper.d.ts.map +1 -1
  21. package/src/core/collection/map/AsyncMapWrapper.js +14 -9
  22. package/src/core/collection/map/HashMap.d.ts.map +1 -1
  23. package/src/core/collection/map/HashMap.js +14 -0
  24. package/src/core/collection/map/ObservedMap.d.ts +12 -3
  25. package/src/core/collection/map/ObservedMap.d.ts.map +1 -1
  26. package/src/core/collection/map/ObservedMap.js +14 -4
  27. package/src/core/collection/queue/Deque.d.ts.map +1 -1
  28. package/src/core/collection/queue/Deque.js +100 -95
  29. package/src/core/collection/set/ArraySet.d.ts.map +1 -0
  30. package/src/core/collection/set/{Set.js → ArraySet.js} +2 -2
  31. package/src/core/collection/set/set_remove.d.ts +3 -3
  32. package/src/core/collection/set/set_remove.d.ts.map +1 -1
  33. package/src/core/collection/set/set_remove.js +5 -5
  34. package/src/core/color/oklab/find_gamut_intersection.js +1 -1
  35. package/src/core/geom/2d/Rectangle.d.ts +54 -5
  36. package/src/core/geom/2d/Rectangle.d.ts.map +1 -1
  37. package/src/core/geom/2d/Rectangle.js +70 -3
  38. package/src/core/geom/2d/circle/Circle.d.ts +1 -1
  39. package/src/core/geom/2d/circle/Circle.js +1 -1
  40. package/src/core/geom/2d/compute_triangle_area_2d.d.ts.map +1 -1
  41. package/src/core/geom/2d/compute_triangle_area_2d.js +7 -1
  42. package/src/core/geom/2d/shape/AbstractShape.d.ts +2 -0
  43. package/src/core/geom/2d/shape/AbstractShape.d.ts.map +1 -1
  44. package/src/core/geom/2d/shape/AbstractShape.js +8 -2
  45. package/src/core/geom/2d/shape/CircleShape.d.ts +14 -0
  46. package/src/core/geom/2d/shape/CircleShape.d.ts.map +1 -1
  47. package/src/core/geom/2d/shape/CircleShape.js +64 -22
  48. package/src/core/geom/2d/uv_map_circle_to_square.d.ts +8 -0
  49. package/src/core/geom/2d/uv_map_circle_to_square.d.ts.map +1 -0
  50. package/src/core/geom/2d/{UvUtils.js → uv_map_circle_to_square.js} +2 -17
  51. package/src/core/geom/2d/uv_map_circle_to_square.spec.d.ts +2 -0
  52. package/src/core/geom/2d/uv_map_circle_to_square.spec.d.ts.map +1 -0
  53. package/src/core/geom/2d/uv_map_circle_to_square.spec.js +28 -0
  54. package/src/core/geom/2d/uv_map_square_to_circle.d.ts +8 -0
  55. package/src/core/geom/2d/uv_map_square_to_circle.d.ts.map +1 -0
  56. package/src/core/geom/2d/uv_map_square_to_circle.js +14 -0
  57. package/src/core/geom/2d/uv_map_square_to_circle.spec.d.ts +2 -0
  58. package/src/core/geom/2d/uv_map_square_to_circle.spec.d.ts.map +1 -0
  59. package/src/core/geom/2d/uv_map_square_to_circle.spec.js +30 -0
  60. package/src/core/geom/Vector3.d.ts +13 -4
  61. package/src/core/geom/Vector3.d.ts.map +1 -1
  62. package/src/core/geom/Vector3.js +83 -36
  63. package/src/core/geom/Vector3.spec.js +113 -12
  64. package/src/core/collection/set/Set.d.ts.map +0 -1
  65. package/src/core/geom/2d/Geometry2D.d.ts +0 -31
  66. package/src/core/geom/2d/Geometry2D.d.ts.map +0 -1
  67. package/src/core/geom/2d/Geometry2D.js +0 -59
  68. package/src/core/geom/2d/UvUtils.d.ts +0 -15
  69. package/src/core/geom/2d/UvUtils.d.ts.map +0 -1
  70. package/src/core/geom/2d/UvUtils.spec.d.ts +0 -2
  71. package/src/core/geom/2d/UvUtils.spec.d.ts.map +0 -1
  72. package/src/core/geom/2d/UvUtils.spec.js +0 -55
  73. /package/src/core/collection/set/{Set.d.ts → ArraySet.d.ts} +0 -0
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Fully featured ECS game engine written in JavaScript",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.106.0",
8
+ "version": "2.106.1",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=array_copy.spec.d.ts.map
@@ -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;I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IG;IACH,4BAJsB,CAAC,6BAUtB;IAED;;;;OAIG;IACH,iBAHoB,CAAC,KAAE,OAAO,GACjB,MAAO,CAAC,CAAC,CAIrB;IAED;;;;OAIG;IACH,oBAFa,CAAC,GAAC,SAAS,CAcvB;IAED;;;;OAIG;IACH,0BAHoB,CAAC,KAAE,OAAO,GACjB,MAAM,CAiBlB;IAED;;;;OAIG;IACH,mDAWC;IAED;;;;OAIG;IACH,YAHW,CAAC,GACC,OAAO,CAInB;IAED;;;;OAIG;IACH,qBAHW,CAAC,EAAE,GACD,OAAO,CAanB;IAED;;;OAGG;IACH,WAFa,OAAO,CAInB;IAED;;;;OAIG;IACH,YAHW,CAAC,GACC,MAAM,CAIlB;IAED;;;;;OAKG;IACH,wBAJoB,CAAC,4BAkBpB;IAED;;;;OAIG;IACH,qDAoBC;IAED,cAyBC;IAED;;;;;OAKG;IACH,gBAJW,KAAK,CAAC,CAAC,kDAuCjB;IAED;;;OAGG;IACH,YAFW,KAAK,CAAC,CAAC,GAAC,CAAC,EAAE,QAarB;IAED;;;OAGG;IACH,WAFa,CAAC,EAAE,CAIf;IAED,cAEC;IAED;;;;OAIG;IACH,oDAcC;IAED;;;OAGG;IACH,2CAcC;IAED;;;;OAIG;IACH,+DAaC;IAED;;;;OAIG;IACH,qEAIC;IAED;;;;OAIG;IACH,wEAQC;IAED;;;;OAIG;IACH,gEAFuB,CAAC,QAWvB;IAED;;;OAGG;IACH,QAFa,MAAM,CAclB;IAED;;;OAGG;IACH,SAFa,CAAC,GAAC,SAAS,CAIvB;IAED;;;OAGG;IACH,QAFY,CAAC,GAAC,SAAS,CAItB;IAED;;;OAGG;IACH,kCA8BC;IAED;;;;OAIG;IACH,eAHW,KAAK,CAAC,CAAC,GACL,MAAM,CA0BlB;CACJ;mBAr8BkB,+BAA+B"}
1
+ {"version":3,"file":"List.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/list/List.js"],"names":[],"mappings":";AAaA;;;;GAIG;AACH;IAqBI;;;OA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ACH,qCASC;IAED;;;;OAIG;IACH,4BAJsB,CAAC,6BAUtB;IAED;;;;OAIG;IACH,iBAHoB,CAAC,KAAE,OAAO,GACjB,MAAO,CAAC,CAAC,CAIrB;IAED;;;;OAIG;IACH,oBAFa,CAAC,GAAC,SAAS,CAcvB;IAED;;;;OAIG;IACH,0BAHoB,CAAC,KAAE,OAAO,GACjB,MAAM,CAiBlB;IAED;;;;;OAKG;IACH,8CAFa,OAAO,CAkBnB;IAED;;;;OAIG;IACH,YAHW,CAAC,GACC,OAAO,CAInB;IAED;;;;OAIG;IACH,qBAHW,CAAC,EAAE,GACD,OAAO,CAanB;IAED;;;OAGG;IACH,WAFa,OAAO,CAInB;IAED;;;;OAIG;IACH,YAHW,CAAC,GACC,MAAM,CAIlB;IAED;;;;;OAKG;IACH,wBAJoB,CAAC,4BAkBpB;IAED;;;;OAIG;IACH,qDAoBC;IAED,cAyBC;IAED;;;;;OAKG;IACH,gBAJW,KAAK,CAAC,CAAC,kDAuCjB;IAED;;;OAGG;IACH,YAFW,KAAK,CAAC,CAAC,GAAC,CAAC,EAAE,QAarB;IAED;;;OAGG;IACH,WAFa,CAAC,EAAE,CAIf;IAED,cAEC;IAED;;;;OAIG;IACH,oDAcC;IAED;;;OAGG;IACH,2CAcC;IAED;;;;OAIG;IACH,+DAaC;IAED;;;;OAIG;IACH,qEAIC;IAED;;;;OAIG;IACH,wEAQC;IAED;;;;OAIG;IACH,gEAFuB,CAAC,QAWvB;IAED;;;OAGG;IACH,QAFa,MAAM,CAclB;IAED;;;OAGG;IACH,SAFa,CAAC,GAAC,SAAS,CAIvB;IAED;;;OAGG;IACH,QAFY,CAAC,GAAC,SAAS,CAItB;IAED;;;OAGG;IACH,kCA8BC;IAED;;;;OAIG;IACH,eAHW,KAAK,CAAC,CAAC,GACL,MAAM,CA0BlB;CACJ;mBA99BkB,+BAA+B"}
@@ -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
- * @private
42
- * @readonly
43
- * @type {T[]}
44
- */
45
- this.data = array !== undefined ? array.slice() : [];
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
- this.data.splice(index, 0, el);
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 unique = elements.filter(function (e, i) {
282
- return data.indexOf(e) === -1 && elements.indexOf(e, i + 1) === -1;
283
- });
293
+ const length = data.length;
284
294
 
285
- this.addAll(unique);
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.equal(typeof index, 'number', `index must a number, instead was '${typeof index}'`);
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 els = this.data.splice(index, removeCount);
310
+ const removed_elements = this.data.splice(index, removeCount);
299
311
 
300
- const removedCount = els.length;
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
- if (this.on.removed.hasHandlers()) {
318
+ const onRemoved = this.on.removed;
319
+
320
+ if (onRemoved.hasHandlers()) {
307
321
  for (let i = 0; i < removedCount; i++) {
308
- const element = els[i];
322
+ const element = removed_elements[i];
309
323
 
310
- this.on.removed.send2(element, index + i);
324
+ onRemoved.send2(element, index + i);
311
325
  }
312
326
  }
313
327
 
314
- return els;
328
+ return removed_elements;
315
329
  }
316
330
 
317
331
  /**
@@ -394,8 +408,13 @@ class List {
394
408
  }
395
409
  }
396
410
 
397
- sort() {
398
- Array.prototype.sort.apply(this.data, arguments);
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 data = this.data;
566
- let i = 0;
567
- const l = this.length;
568
- for (; i < l; i++) {
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":"AAAA;;GAEG;AACH;IAQQ;;;;OAIG;IACH,sBAAyB;IACzB;;;;OAIG;IACH,kBAAmB;IACnB;;;;OAIG;IACH,oBAAwB;IAG5B;;;OAGG;IACH,8BAOC;IAED;;;OAGG;IACH,2BAEC;IAED;;;;OAIG;IACH,sBAFY,OAAO,CAUlB;IAED;;;;OAIG;IACH,mBAMC;IAED;;;;OAIG;IACH,qBAOC;IAED;;;;OAIG;IACH,yBAFY,OAAO,CAgBlB;IAED,aAkBC;IAED,eAeC;IAED;;;OAGG;IACH,YAFY,OAAO,CAIlB;CACJ"}
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
- * @template T
15
+ * Where to take data from
16
+ * @type {List<T>[]}
17
+ * @private
8
18
  */
9
- constructor() {
10
-
11
-
12
- /**
13
- *
14
- * @type {List<T>}
15
- * @private
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.__is_linked) {
33
+ if (this.#is_linked) {
38
34
  // already linked
39
35
  throw new Error('Invalid state: linked');
40
36
  }
41
37
 
42
- this.__destination = v;
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.__destination;
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.__sources.push(source);
55
+ this.#sources.push(source);
60
56
 
61
- if (this.__is_linked) {
62
- this.__link_one(source);
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
- __link_one(source) {
74
- source.on.added.add(this.__destination.add, this.__destination);
75
- source.on.removed.add(this.__destination.removeOneOf, this.__destination);
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
- // remove all data from destination
78
- source.forEach(this.__destination.add, this.__destination);
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
- __unlink_one(source) {
82
+ #unlink_one(source) {
87
83
 
88
- source.on.added.remove(this.__destination.add, this.__destination);
89
- source.on.removed.remove(this.__destination.removeOneOf, this.__destination);
84
+ source.on.added.remove(this.#destination.add, this.#destination);
85
+ source.on.removed.remove(this.#destination.removeOneOf, this.#destination);
90
86
 
91
- // move data to destination
92
- source.forEach(this.__destination.removeOneOf, this.__destination);
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.__sources.indexOf(source);
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.__is_linked) {
108
- this.__unlink_one(source);
103
+ if (this.#is_linked) {
104
+ this.#unlink_one(source);
109
105
  }
110
106
 
111
- this.__sources.splice(i, 1);
107
+ this.#sources.splice(i, 1);
112
108
 
113
109
  return true;
114
110
  }
115
111
 
116
112
  link() {
117
- if (this.__is_linked) {
113
+ if (this.#is_linked) {
118
114
  return;
119
115
  }
120
116
 
121
- if (this.__destination === null) {
117
+ if (this.#destination === null) {
122
118
  throw new Error('Illegal state: destination not set');
123
119
  }
124
120
 
125
- this.__is_linked = true;
121
+ this.#is_linked = true;
126
122
 
127
- const sources = this.__sources;
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.__link_one(source);
128
+ this.#link_one(source);
133
129
  }
134
130
  }
135
131
 
136
132
  unlink() {
137
- if (!this.__is_linked) {
133
+ if (!this.#is_linked) {
138
134
  return;
139
135
  }
140
136
 
141
- this.__is_linked = false;
137
+ this.#is_linked = false;
142
138
 
143
- const sources = this.__sources;
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.__unlink_one(source);
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.__is_linked;
154
+ return this.#is_linked;
159
155
  }
160
156
  }
@@ -14,6 +14,8 @@ test('isLinked returns false for new instance', () => {
14
14
  test('link without destination throws', () => {
15
15
  const sut = new ListForwarder();
16
16
 
17
+ sut.destination = null;
18
+
17
19
  expect(() => sut.link()).toThrow();
18
20
  });
19
21
 
@@ -1,4 +1,7 @@
1
- export class SortedListProjection {
1
+ /**
2
+ * @template T
3
+ */
4
+ export class SortedListProjection<T> {
2
5
  /**
3
6
  *
4
7
  * @param {List<T>} input
@@ -1 +1 @@
1
- {"version":3,"file":"SortedListProjection.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/list/SortedListProjection.js"],"names":[],"mappings":"AAGA;IACI;;;;OAIG;IACH,mBAHW,OAAO,oCACO,MAAM,EAoB9B;IAjBG;;;OAGG;IACH,OAFU,OAAO,CAEC;IAElB;;;OAGG;IACH,QAFU,OAAO,CAEO;IAExB;;;OAGG;IACH,kCAF0B,MAAM,CAEJ;IAGhC,aAIC;IAED,eAEC;IAED;;;OAGG;IACH,4BAIC;IAGD,cAUC;CAEJ;iBA9DgB,WAAW"}
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,6 +1,9 @@
1
- import List from "./List.js";
2
1
  import { binarySearchLowIndex } from "../array/binarySearchLowIndex.js";
2
+ import List from "./List.js";
3
3
 
4
+ /**
5
+ * @template T
6
+ */
4
7
  export class SortedListProjection {
5
8
  /**
6
9
  *
@@ -1 +1 @@
1
- {"version":3,"file":"AbstractAsyncMap.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/map/AbstractAsyncMap.js"],"names":[],"mappings":"AAGA;;GAEG;AACH;IAKI;;;;OAIG;IACH,SAHW,GAAG,GACF,QAAQ,KAAK,GAAC,SAAS,CAAC,CAInC;IAED;;;;;OAKG;IACH,SAJW,GAAG,SACH,KAAK,GACJ,QAAQ,IAAI,CAAC,CAIxB;CACJ"}
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"}
@@ -5,9 +5,6 @@
5
5
  * @template Key,Value
6
6
  */
7
7
  export class AbstractAsyncMap {
8
- constructor() {
9
-
10
- }
11
8
 
12
9
  /**
13
10
  *
@@ -1,20 +1,16 @@
1
1
  /**
2
2
  * Wraps synchronous {@link Map}-implementing object
3
+ * @template K,V
3
4
  */
4
- export class AsyncMapWrapper extends AbstractAsyncMap<any, any> {
5
+ export class AsyncMapWrapper<K, V> extends AbstractAsyncMap<any, any> {
5
6
  /**
6
7
  *
7
- * @param {Map} [source]
8
+ * @param {Map<K,V>} [source]
8
9
  */
9
- constructor(source?: Map<any, any>);
10
- /**
11
- *
12
- * @type {Map}
13
- * @private
14
- */
15
- private _source;
16
- get(key: any): Promise<any>;
10
+ constructor(source?: Map<K, V>);
11
+ get(key: any): Promise<V>;
17
12
  set(key: any, value: any): Promise<void>;
13
+ #private;
18
14
  }
19
15
  import { AbstractAsyncMap } from "./AbstractAsyncMap.js";
20
16
  //# sourceMappingURL=AsyncMapWrapper.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AsyncMapWrapper.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/map/AsyncMapWrapper.js"],"names":[],"mappings":"AAEA;;GAEG;AACH;IACI;;;OAGG;IACH,oCAQC;IANG;;;;OAIG;IACH,gBAAqB;IAGzB,4BAEC;IAED,yCAEC;CACJ;iCA3BgC,uBAAuB"}
1
+ {"version":3,"file":"AsyncMapWrapper.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/map/AsyncMapWrapper.js"],"names":[],"mappings":"AAEA;;;GAGG;AACH;IAUI;;;OAGG;IACH,qBAFW,IAAI,CAAC,EAAC,CAAC,CAAC,EAKlB;IAED,0BAEC;IAED,yCAEC;;CACJ;iCAhCgC,uBAAuB"}
@@ -2,27 +2,32 @@ import { AbstractAsyncMap } from "./AbstractAsyncMap.js";
2
2
 
3
3
  /**
4
4
  * Wraps synchronous {@link Map}-implementing object
5
+ * @template K,V
5
6
  */
6
7
  export class AsyncMapWrapper extends AbstractAsyncMap {
8
+
9
+ /**
10
+ *
11
+ * @type {Map<K,V>}
12
+ * @private
13
+ */
14
+ #source = null;
15
+
16
+
7
17
  /**
8
18
  *
9
- * @param {Map} [source]
19
+ * @param {Map<K,V>} [source]
10
20
  */
11
21
  constructor(source = new Map()) {
12
22
  super();
13
- /**
14
- *
15
- * @type {Map}
16
- * @private
17
- */
18
- this._source = source;
23
+ this.#source = source;
19
24
  }
20
25
 
21
26
  async get(key) {
22
- return this._source.get(key);
27
+ return this.#source.get(key);
23
28
  }
24
29
 
25
30
  async set(key, value) {
26
- this._source.set(key, value);
31
+ this.#source.set(key, value);
27
32
  }
28
33
  }
@@ -1 +1 @@
1
- {"version":3,"file":"HashMap.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/map/HashMap.js"],"names":[],"mappings":"AAiBA;;;;;;;;;;;;GAYG;AACH,uFAIC;AA8FD;;;;;;;GAOG;AACH;IA+DI;;;;;;OAMG;IACH,4FALuB,MAAM,EAsC5B;IAlBG;;;;;OAKG;IACH,iCAAsC;IACtC;;;;;OAKG;IACH,qCAA8C;IAOlD,mBAEC;IAED;;;OAGG;IACH,kBAFa,MAAM,CAIlB;IAuJD;;;;OAIG;IACH,SAHW,CAAC,SACD,CAAC,QA0EX;IAED;;;;OAIG;IACH,SAHW,CAAC,GACC,CAAC,GAAC,SAAS,CA+BvB;IAED;;;;;;;;OAQG;IACH,kBALW,CAAC,kBACQ,CAAC,KAAE,CAAC,0BAEZ,CAAC,CAcZ;IAED;;;;;OAKG;IACH,cAJW,CAAC,SACD,CAAC,GACA,CAAC,CAYZ;IAuBD;;;;OAIG;IACH,YAHW,CAAC,GACC,OAAO,CA+CnB;IAED;;;;;OAKG;IACH,4CAFa,OAAO,CA+BnB;IAOD;;OAEG;IACH,gBAsDC;IAmBD,2CAwBC;IAED;;;;OAIG;IACH,SAHW,CAAC,GACC,OAAO,CAInB;IAED;;OAEG;IACH,cA6BC;IA+BD;;;OAGG;IACH,UAFa,SAAS,CAAC,CAAC,CAOvB;IAED;;;OAGG;IACH,QAFa,SAAS,CAAC,CAAC,CAMvB;IAhDD,yDA2BC;;CAsBJ"}
1
+ {"version":3,"file":"HashMap.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/map/HashMap.js"],"names":[],"mappings":"AAiBA;;;;;;;;;;;;GAYG;AACH,uFAIC;AA8FD;;;;;;;GAOG;AACH;IA+DI;;;;;;OAMG;IACH,4FALuB,MAAM,EAsC5B;IAlBG;;;;;OAKG;IACH,iCAAsC;IACtC;;;;;OAKG;IACH,qCAA8C;IAOlD,mBAEC;IAED;;;OAGG;IACH,kBAFa,MAAM,CAIlB;IAiKD;;;;OAIG;IACH,SAHW,CAAC,SACD,CAAC,QA0EX;IAED;;;;OAIG;IACH,SAHW,CAAC,GACC,CAAC,GAAC,SAAS,CA+BvB;IAED;;;;;;;;OAQG;IACH,kBALW,CAAC,kBACQ,CAAC,KAAE,CAAC,0BAEZ,CAAC,CAgBZ;IAED;;;;;OAKG;IACH,cAJW,CAAC,SACD,CAAC,GACA,CAAC,CAYZ;IAuBD;;;;OAIG;IACH,YAHW,CAAC,GACC,OAAO,CA+CnB;IAED;;;;;OAKG;IACH,4CAFa,OAAO,CA+BnB;IAOD;;OAEG;IACH,gBAsDC;IAmBD,2CA0BC;IAED;;;;OAIG;IACH,SAHW,CAAC,GACC,OAAO,CAInB;IAED;;OAEG;IACH,cA6BC;IA+BD;;;OAGG;IACH,UAFa,SAAS,CAAC,CAAC,CAOvB;IAED;;;OAGG;IACH,QAFa,SAAS,CAAC,CAAC,CAMvB;IAhDD,yDA2BC;;CAsBJ"}