@3dsource/angular-unreal-module 0.0.191 → 0.0.192

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 CHANGED
File without changes
@@ -4635,6 +4635,16 @@ const TAB_KEY_CODE = 9;
4635
4635
  const ARROW_KEY_MIN = 37;
4636
4636
  const ARROW_KEY_MAX = 40;
4637
4637
  const TEXT_ENTRY_SELECTOR = "input, textarea, select, [contenteditable]:not([contenteditable=\"false\"])";
4638
+ const MOUSE_BUTTONS = [
4639
+ [MouseButton.MainButton, MouseButtonsMask.PrimaryButton],
4640
+ [MouseButton.AuxiliaryButton, MouseButtonsMask.AuxiliaryButton],
4641
+ [MouseButton.SecondaryButton, MouseButtonsMask.SecondaryButton],
4642
+ [MouseButton.FourthButton, MouseButtonsMask.FourthButton],
4643
+ [MouseButton.FifthButton, MouseButtonsMask.FifthButton]
4644
+ ];
4645
+ function buttonMask(button) {
4646
+ return MOUSE_BUTTONS.find(([b]) => b === button)?.[1] ?? 0;
4647
+ }
4638
4648
  var InputService = class InputService extends SubService {
4639
4649
  constructor() {
4640
4650
  super();
@@ -4677,6 +4687,12 @@ var InputService = class InputService extends SubService {
4677
4687
  this.maxByteValue = 255;
4678
4688
  this.fingers = [...INITIAL_FINGER_IDS];
4679
4689
  this.heldKeys = /* @__PURE__ */ new Set();
4690
+ this.heldButtons = 0;
4691
+ this.lastMousePosition = {
4692
+ x: 0,
4693
+ y: 0
4694
+ };
4695
+ this.leavePending = false;
4680
4696
  this.mouseMoveView = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(9));
4681
4697
  this.mouseButtonView = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(6));
4682
4698
  this.mouseWheelView = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(7));
@@ -4716,6 +4732,8 @@ var InputService = class InputService extends SubService {
4716
4732
  this.fingerIds.clear();
4717
4733
  this.fingers = [...INITIAL_FINGER_IDS];
4718
4734
  this.heldKeys.clear();
4735
+ this.heldButtons = 0;
4736
+ this.leavePending = false;
4719
4737
  merge(fromResizeObserver(video), this.actions$.pipe(ofType(videoAdaptedToContainer))).pipe(debounceTime$1(RESIZE_DEBOUNCE_MS), takeUntil(this.deactivatedVideoTrigger$)).subscribe(() => this.setupNormalizeAndQuantize(video));
4720
4738
  this.setupNormalizeAndQuantize(video);
4721
4739
  this.registerInputs(video);
@@ -4770,8 +4788,9 @@ var InputService = class InputService extends SubService {
4770
4788
  this.commandsSender.sendInputData(data);
4771
4789
  }
4772
4790
  registerInputs(video) {
4773
- fromEvent(window, "blur").pipe(filter$1(() => !!video), takeUntil(this.deactivatedVideoTrigger$)).subscribe(() => this.releaseMouseButtons(255, 0, 0));
4774
- merge(fromEvent(window, "blur"), fromEvent(document, "visibilitychange").pipe(filter$1(() => document.visibilityState === "hidden"))).pipe(takeUntil(merge(this.reInit$, this.destroy$))).subscribe(() => this.releaseKeys());
4791
+ const focusLost$ = merge(fromEvent(window, "blur"), fromEvent(document, "visibilitychange").pipe(filter$1(() => document.visibilityState === "hidden")));
4792
+ focusLost$.pipe(takeUntil(merge(this.reInit$, this.destroy$))).subscribe(() => this.releaseKeys());
4793
+ focusLost$.pipe(takeUntil(merge(this.disconnect$, this.reInit$, this.destroy$))).subscribe(() => this.releaseMouseButtons(this.heldButtons));
4775
4794
  this.registerMouseEnterAndLeaveEvents(video);
4776
4795
  this.registerHoveringMouseEvents(video);
4777
4796
  this.registerKeyboardEvents();
@@ -4875,6 +4894,7 @@ var InputService = class InputService extends SubService {
4875
4894
  data.setUint16(2, coord.x, true);
4876
4895
  data.setUint16(4, coord.y, true);
4877
4896
  this.sendInputData(data.buffer);
4897
+ this.heldButtons |= buttonMask(button);
4878
4898
  }
4879
4899
  emitMouseUp(button, x, y) {
4880
4900
  const coord = this.normalizeAndQuantizeUnsigned(x, y);
@@ -4884,6 +4904,7 @@ var InputService = class InputService extends SubService {
4884
4904
  data.setUint16(2, coord.x, true);
4885
4905
  data.setUint16(4, coord.y, true);
4886
4906
  this.sendInputData(data.buffer);
4907
+ this.heldButtons &= ~buttonMask(button);
4887
4908
  }
4888
4909
  emitMouseWheel(delta, x, y) {
4889
4910
  const coord = this.normalizeAndQuantizeUnsigned(x, y);
@@ -4894,36 +4915,52 @@ var InputService = class InputService extends SubService {
4894
4915
  data.setUint16(5, coord.y, true);
4895
4916
  this.sendInputData(data.buffer);
4896
4917
  }
4897
- releaseMouseButtons(buttons, x, y) {
4898
- if (buttons & MouseButtonsMask.PrimaryButton) this.emitMouseUp(MouseButton.MainButton, x, y);
4899
- if (buttons & MouseButtonsMask.SecondaryButton) this.emitMouseUp(MouseButton.SecondaryButton, x, y);
4900
- if (buttons & MouseButtonsMask.AuxiliaryButton) this.emitMouseUp(MouseButton.AuxiliaryButton, x, y);
4901
- if (buttons & MouseButtonsMask.FourthButton) this.emitMouseUp(MouseButton.FourthButton, x, y);
4902
- if (buttons & MouseButtonsMask.FifthButton) this.emitMouseUp(MouseButton.FifthButton, x, y);
4918
+ releaseMouseButtons(buttons) {
4919
+ const { x, y } = this.lastMousePosition;
4920
+ for (const [button, mask] of MOUSE_BUTTONS) if (buttons & mask & this.heldButtons) this.emitMouseUp(button, x, y);
4921
+ if (this.leavePending && !this.heldButtons) {
4922
+ this.leavePending = false;
4923
+ this.sendMouseLeave();
4924
+ }
4903
4925
  }
4904
4926
  pressMouseButtons(buttons, x, y) {
4905
- if (buttons & MouseButtonsMask.PrimaryButton) this.emitMouseDown(MouseButton.MainButton, x, y);
4906
- if (buttons & MouseButtonsMask.SecondaryButton) this.emitMouseDown(MouseButton.SecondaryButton, x, y);
4907
- if (buttons & MouseButtonsMask.AuxiliaryButton) this.emitMouseDown(MouseButton.AuxiliaryButton, x, y);
4908
- if (buttons & MouseButtonsMask.FourthButton) this.emitMouseDown(MouseButton.FourthButton, x, y);
4909
- if (buttons & MouseButtonsMask.FifthButton) this.emitMouseDown(MouseButton.FifthButton, x, y);
4927
+ for (const [button, mask] of MOUSE_BUTTONS) if (buttons & mask & ~this.heldButtons) this.emitMouseDown(button, x, y);
4928
+ }
4929
+ sendMouseEnter() {
4930
+ const data = this.singleByteView;
4931
+ data.setUint8(0, MessageType.MouseEnter);
4932
+ this.sendInputData(data.buffer);
4933
+ }
4934
+ sendMouseLeave() {
4935
+ const data = this.singleByteView;
4936
+ data.setUint8(0, MessageType.MouseLeave);
4937
+ this.sendInputData(data.buffer);
4910
4938
  }
4911
4939
  registerHoveringMouseEvents(htmlVideoElement) {
4912
4940
  fromEvent(htmlVideoElement, "mousemove").pipe(takeUntil(this.deactivatedVideoTrigger$)).subscribe((e) => {
4913
- const { x, y } = this.getMousePositionWithOffset(e);
4941
+ this.leavePending = false;
4942
+ this.releaseMouseButtons(this.heldButtons & ~e.buttons);
4943
+ this.lastMousePosition = this.getMousePositionWithOffset(e);
4944
+ const { x, y } = this.lastMousePosition;
4914
4945
  this.emitMouseMove(x, y, e.movementX, e.movementY);
4915
4946
  e.preventDefault();
4916
4947
  });
4917
4948
  fromEvent(htmlVideoElement, "mousedown").pipe(takeUntil(this.deactivatedVideoTrigger$)).subscribe((e) => {
4918
- const { x, y } = this.getMousePositionWithOffset(e);
4949
+ this.leavePending = false;
4919
4950
  this.focusWindow();
4920
- this.emitMouseDown(e.button, x, y);
4921
4951
  e.preventDefault();
4952
+ if (!buttonMask(e.button)) return;
4953
+ this.lastMousePosition = this.getMousePositionWithOffset(e);
4954
+ const { x, y } = this.lastMousePosition;
4955
+ this.emitMouseDown(e.button, x, y);
4922
4956
  });
4923
4957
  fromEvent(htmlVideoElement, "mouseup").pipe(takeUntil(this.deactivatedVideoTrigger$)).subscribe((e) => {
4924
- const { x, y } = this.getMousePositionWithOffset(e);
4925
- this.emitMouseUp(e.button, x, y);
4958
+ this.leavePending = false;
4926
4959
  e.preventDefault();
4960
+ if (this.heldButtons & buttonMask(e.button)) {
4961
+ const { x, y } = this.getMousePositionWithOffset(e);
4962
+ this.emitMouseUp(e.button, x, y);
4963
+ }
4927
4964
  });
4928
4965
  fromEvent(htmlVideoElement, "wheel").pipe(takeUntil(this.deactivatedVideoTrigger$)).subscribe((e) => {
4929
4966
  this.emitMouseWheel(e.deltaY * WHEEL_DELTA_SCALE, e.offsetX, e.offsetY);
@@ -4933,17 +4970,22 @@ var InputService = class InputService extends SubService {
4933
4970
  registerMouseEnterAndLeaveEvents(htmlVideoElement) {
4934
4971
  fromEvent(htmlVideoElement, "mouseenter").pipe(takeUntil(this.deactivatedVideoTrigger$)).subscribe((e) => {
4935
4972
  this.focusWindow();
4936
- const data = this.singleByteView;
4937
- data.setUint8(0, MessageType.MouseEnter);
4938
- this.sendInputData(data.buffer);
4939
- this.pressMouseButtons(e.buttons, e.offsetX, e.offsetY);
4940
- });
4941
- fromEvent(htmlVideoElement, "mouseleave").pipe(takeUntil(this.deactivatedVideoTrigger$)).subscribe((e) => {
4942
- const data = this.singleByteView;
4943
- data.setUint8(0, MessageType.MouseLeave);
4944
- this.sendInputData(data.buffer);
4945
- this.releaseMouseButtons(e.buttons, e.offsetX, e.offsetY);
4973
+ const dragReturned = this.leavePending;
4974
+ this.leavePending = false;
4975
+ this.releaseMouseButtons(this.heldButtons & ~e.buttons);
4976
+ if (!dragReturned) this.sendMouseEnter();
4977
+ this.lastMousePosition = this.getMousePositionWithOffset(e);
4978
+ const { x, y } = this.lastMousePosition;
4979
+ this.pressMouseButtons(e.buttons, x, y);
4980
+ });
4981
+ fromEvent(htmlVideoElement, "mouseleave").pipe(takeUntil(this.deactivatedVideoTrigger$)).subscribe(() => {
4982
+ if (this.heldButtons) this.leavePending = true;
4983
+ else {
4984
+ this.leavePending = false;
4985
+ this.sendMouseLeave();
4986
+ }
4946
4987
  });
4988
+ fromEvent(window, "mouseup", { capture: true }).pipe(filter$1((e) => e.composedPath()[0] !== htmlVideoElement), takeUntil(this.deactivatedVideoTrigger$)).subscribe((e) => this.releaseMouseButtons(buttonMask(e.button) | ~e.buttons));
4947
4989
  }
4948
4990
  isBrowserKey(keyCode) {
4949
4991
  return keyCode >= FUNCTION_KEY_MIN && keyCode <= FUNCTION_KEY_MAX || keyCode >= ARROW_KEY_MIN && keyCode <= ARROW_KEY_MAX || keyCode === TAB_KEY_CODE;