@woosh/meep-engine 2.109.26 → 2.110.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 (40) hide show
  1. package/build/meep.cjs +207 -436
  2. package/build/meep.min.js +1 -1
  3. package/build/meep.module.js +207 -436
  4. package/editor/tools/GridPaintTool.js +12 -11
  5. package/editor/tools/engine/ToolEngine.js +2 -1
  6. package/package.json +1 -1
  7. package/src/core/graph/Edge.js +1 -1
  8. package/src/core/math/interval/NumericInterval.d.ts +13 -7
  9. package/src/core/math/interval/NumericInterval.d.ts.map +1 -1
  10. package/src/core/math/interval/NumericInterval.js +35 -15
  11. package/src/core/process/executor/ConcurrentExecutor.d.ts.map +1 -1
  12. package/src/core/process/executor/ConcurrentExecutor.js +11 -2
  13. package/src/engine/graphics/camera/makeOrbitalCameraController.d.ts.map +1 -1
  14. package/src/engine/graphics/camera/makeOrbitalCameraController.js +4 -4
  15. package/src/engine/graphics/geometry/VertexDataSpec.d.ts.map +1 -1
  16. package/src/engine/graphics/geometry/VertexDataSpec.js +4 -7
  17. package/src/engine/input/devices/LocationalInteractionMetadata.d.ts +4 -0
  18. package/src/engine/input/devices/LocationalInteractionMetadata.d.ts.map +1 -1
  19. package/src/engine/input/devices/LocationalInteractionMetadata.js +6 -1
  20. package/src/engine/input/devices/PointerDevice.d.ts +0 -3
  21. package/src/engine/input/devices/PointerDevice.d.ts.map +1 -1
  22. package/src/engine/input/devices/PointerDevice.js +49 -306
  23. package/src/engine/input/devices/events/PointerEvents.d.ts +14 -0
  24. package/src/engine/input/devices/events/PointerEvents.d.ts.map +1 -0
  25. package/src/engine/input/devices/events/PointerEvents.js +16 -0
  26. package/src/engine/input/devices/mouse/decodeMouseEventButtons.d.ts +10 -0
  27. package/src/engine/input/devices/mouse/decodeMouseEventButtons.d.ts.map +1 -0
  28. package/src/engine/input/devices/mouse/decodeMouseEventButtons.js +19 -0
  29. package/src/engine/input/devices/mouse/suppressContextMenu.d.ts +7 -0
  30. package/src/engine/input/devices/mouse/suppressContextMenu.d.ts.map +1 -0
  31. package/src/engine/input/devices/mouse/suppressContextMenu.js +11 -0
  32. package/src/engine/input/devices/touch/TouchDevice.d.ts +20 -0
  33. package/src/engine/input/devices/touch/TouchDevice.d.ts.map +1 -0
  34. package/src/engine/input/devices/touch/TouchDevice.js +95 -0
  35. package/src/engine/input/devices/touch/getTouchCenter.d.ts +7 -0
  36. package/src/engine/input/devices/touch/getTouchCenter.d.ts.map +1 -0
  37. package/src/engine/input/devices/touch/getTouchCenter.js +32 -0
  38. package/src/engine/input/devices/touch/observePinch.d.ts +12 -0
  39. package/src/engine/input/devices/touch/observePinch.d.ts.map +1 -0
  40. package/src/engine/input/devices/touch/observePinch.js +128 -0
@@ -0,0 +1,95 @@
1
+ import Signal from "../../../../core/events/signal/Signal.js";
2
+ import Vector2 from "../../../../core/geom/Vector2.js";
3
+ import { getTouchCenter } from "./getTouchCenter.js";
4
+ import { observePinch } from "./observePinch.js";
5
+
6
+ export class TouchDevice{
7
+
8
+ /**
9
+ * Current live position of the pointer
10
+ * @readonly
11
+ * @type {Vector2}
12
+ */
13
+ position = new Vector2();
14
+
15
+ /**
16
+ * @readonly
17
+ * @type {Vector2}
18
+ */
19
+ #anchor_touch_last = new Vector2();
20
+
21
+ #globalUp = new Signal();
22
+
23
+
24
+ #touchStart = new Signal();
25
+ #touchEnd = new Signal();
26
+ #touchMove = new Signal();
27
+
28
+ /**
29
+ * @readonly
30
+ */
31
+ on = {
32
+ pinch: new Signal(),
33
+ pinchStart: new Signal(),
34
+ pinchEnd: new Signal(),
35
+ };
36
+
37
+ constructor() {
38
+ observePinch({
39
+ touchStart: this.#touchStart,
40
+ touchEnd: this.#touchEnd,
41
+ touchMove: this.#touchMove,
42
+ pinch: this.on.pinch,
43
+ pinchStart: this.on.pinchStart,
44
+ pinchEnd: this.on.pinchEnd,
45
+ device: this
46
+ });
47
+ }
48
+
49
+ /**
50
+ *
51
+ * @param {TouchEvent} event
52
+ */
53
+ #eventHandlerGlobalTouchEnd = (event) => {
54
+ getTouchCenter(event.touches, this.position);
55
+ this.#globalUp.send2(this.position, event);
56
+ }
57
+
58
+ /**
59
+ *
60
+ * @param {TouchEvent} event
61
+ */
62
+ #eventHandlerTouchEnd = (event) => {
63
+ getTouchCenter(event.touches, this.position);
64
+ this.#touchEnd.send2(this.position, event);
65
+ }
66
+
67
+ /**
68
+ *
69
+ * @param {TouchEvent} event
70
+ */
71
+ #eventHandlerTouchMove = (event) => {
72
+ event.preventDefault();
73
+
74
+ getTouchCenter(event.touches, this.position);
75
+
76
+ const delta = new Vector2();
77
+
78
+ delta.subVectors(this.position, this.#anchor_touch_last);
79
+
80
+ this.#touchMove.send3(this.position, event, delta);
81
+
82
+ this.#anchor_touch_last.copy(this.position);
83
+ }
84
+
85
+ /**
86
+ *
87
+ * @param {TouchEvent} event
88
+ */
89
+ #eventHandlerTouchStart = (event) => {
90
+ getTouchCenter(event.touches, this.position);
91
+ this.#touchStart.send2(this.position, event);
92
+
93
+ this.#anchor_touch_last.copy(this.position);
94
+ }
95
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ *
3
+ * @param {TouchList} touchList
4
+ * @param {Vector2} result
5
+ */
6
+ export function getTouchCenter(touchList: TouchList, result: Vector2): void;
7
+ //# sourceMappingURL=getTouchCenter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getTouchCenter.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/input/devices/touch/getTouchCenter.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,0CAHW,SAAS,yBA6BnB"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ *
3
+ * @param {TouchList} touchList
4
+ * @param {Vector2} result
5
+ */
6
+ export function getTouchCenter(touchList, result) {
7
+ const length = touchList.length;
8
+
9
+ let x = 0, y = 0;
10
+
11
+ if (length > 0) {
12
+
13
+ for (let i = 0; i < length; i++) {
14
+ const touch = touchList.item(i);
15
+
16
+ if (touch === null) {
17
+ continue;
18
+ }
19
+
20
+ x += touch.clientX;
21
+ y += touch.clientY;
22
+ }
23
+
24
+ // average to get center
25
+ x /= length;
26
+ y /= length;
27
+
28
+ }
29
+
30
+ result.set(x, y);
31
+
32
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ *
3
+ * @param {Signal} touchStart
4
+ * @param {Signal} touchEnd
5
+ * @param {Signal} touchMove
6
+ * @param {Signal} pinch
7
+ * @param {Signal} pinchStart
8
+ * @param {Signal} pinchEnd
9
+ * @param {PointerDevice} device
10
+ */
11
+ export function observePinch({ touchStart, touchEnd, touchMove, pinch, pinchStart, pinchEnd, device }: Signal): void;
12
+ //# sourceMappingURL=observePinch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observePinch.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/input/devices/touch/observePinch.js"],"names":[],"mappings":"AAgBA;;;;;;;;;GASG;AACH,qHAqGC"}
@@ -0,0 +1,128 @@
1
+ import Vector2 from "../../../../core/geom/Vector2.js";
2
+ import { getTouchCenter } from "./getTouchCenter.js";
3
+
4
+ /**
5
+ *
6
+ * @param {TouchList} touchList
7
+ * @param {function(Touch,number)} callback
8
+ */
9
+ function forEachTouch(touchList, callback) {
10
+ const length = touchList.length;
11
+ for (let i = 0; i < length; i++) {
12
+ const touch = touchList.item(i);
13
+ callback(touch, i);
14
+ }
15
+ }
16
+
17
+ /**
18
+ *
19
+ * @param {Signal} touchStart
20
+ * @param {Signal} touchEnd
21
+ * @param {Signal} touchMove
22
+ * @param {Signal} pinch
23
+ * @param {Signal} pinchStart
24
+ * @param {Signal} pinchEnd
25
+ * @param {PointerDevice} device
26
+ */
27
+ export function observePinch({
28
+ touchStart,
29
+ touchEnd,
30
+ touchMove,
31
+ pinch,
32
+ pinchStart,
33
+ pinchEnd,
34
+ device
35
+ }) {
36
+ const center = new Vector2();
37
+
38
+ const v2 = new Vector2();
39
+
40
+ const pinchBox0 = new Vector2();
41
+ const pinchBox1 = new Vector2();
42
+
43
+ let pinchActive = false;
44
+ let touchCount = 0;
45
+
46
+
47
+ /**
48
+ *
49
+ * @param {TouchList} touchList
50
+ * @param {Vector2} pinchDimensions
51
+ */
52
+ function computeTouchRadius(touchList, pinchDimensions) {
53
+ getTouchCenter(touchList, center);
54
+
55
+ const length = touchList.length;
56
+
57
+ pinchDimensions.set(0, 0);
58
+
59
+ for (let i = 0; i < length; i++) {
60
+ const touch = touchList.item(i);
61
+
62
+ device.readPointerPositionFromEvent(v2, touch);
63
+
64
+ v2.sub(center);
65
+ v2.abs();
66
+
67
+ pinchDimensions.add(v2);
68
+ }
69
+
70
+ return pinchDimensions.multiplyScalar(1 / length);
71
+ }
72
+
73
+ function touchRemoved(touch, event) {
74
+ touchCount--;
75
+ if (touchCount < 2 && pinchActive) {
76
+ handlePinchEnd(event);
77
+ }
78
+ }
79
+
80
+ function touchAdded(touch, event) {
81
+ touchCount++;
82
+ if (touchCount > 1 && !pinchActive) {
83
+ handlePinchStart(event);
84
+ }
85
+ }
86
+
87
+ function handlePinchStart(event) {
88
+ pinchActive = true;
89
+
90
+ computeTouchRadius(event.touches, pinchBox0);
91
+
92
+ touchMove.add(handleMove);
93
+
94
+ pinchStart.send1(pinchBox0);
95
+ }
96
+
97
+ /**
98
+ *
99
+ * @param {TouchEvent} event
100
+ */
101
+ function handlePinchEnd(event) {
102
+ pinchActive = false;
103
+
104
+ touchMove.remove(handleMove);
105
+
106
+ pinchEnd.send0();
107
+ }
108
+
109
+ function handleDown(position, event) {
110
+ forEachTouch(event.changedTouches, function (touch) {
111
+ touchAdded(touch, event);
112
+ });
113
+ }
114
+
115
+ function handleUp(position, event) {
116
+ forEachTouch(event.changedTouches, function (touch) {
117
+ touchRemoved(touch, event);
118
+ });
119
+ }
120
+
121
+ function handleMove(position, event) {
122
+ computeTouchRadius(event.touches, pinchBox1);
123
+ pinch.send2(pinchBox1, pinchBox0);
124
+ }
125
+
126
+ touchEnd.add(handleUp);
127
+ touchStart.add(handleDown);
128
+ }