laymur 0.3.29 → 0.3.30

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.
@@ -160,13 +160,9 @@ export declare abstract class UIElement extends UIAnchor implements UIPlaneEleme
160
160
  * the element should not be used anymore.
161
161
  */
162
162
  destroy(): void;
163
- /**
164
- * Handles click events when the element is in interactive mode.
165
- * @param x - The x coordinate of the click
166
- * @param y - The y coordinate of the click
167
- * @returns True if the click was within this element's bounds
168
- */
169
- protected readonly onClick: (x: number, y: number) => boolean;
163
+ protected readonly onDown: (x: number, y: number) => boolean;
164
+ protected readonly onMove: (x: number, y: number) => boolean;
165
+ protected readonly onUp: (x: number, y: number) => boolean;
170
166
  /**
171
167
  * Called before each render frame to update the element's transform matrix.
172
168
  * Applies micro-transformations (position, rotation, scale, anchor) and updates
package/dist/index.js CHANGED
@@ -3062,22 +3062,31 @@ class UILayer extends i {
3062
3062
  this.sceneWrapper.render(renderer);
3063
3063
  }
3064
3064
  }
3065
- /**
3066
- * Internal method for handling click events on the layer.
3067
- *
3068
- * Processes click events by testing elements in reverse z-order (top to bottom)
3069
- * until one handles the click. Only processes clicks when the layer is in
3070
- * interactive mode.
3071
- *
3072
- * @param x - The x-coordinate of the click
3073
- * @param y - The y-coordinate of the click
3074
- * @protected
3075
- */
3076
- pointerClickInternal(x, y) {
3065
+ pointerDownInternal(x, y) {
3066
+ if (this.mode === UIMode.INTERACTIVE) {
3067
+ this._private_inputListeners.sort((a, b) => b.zIndex - a.zIndex);
3068
+ for (const listener of this._private_inputListeners) {
3069
+ if (listener.listener.catchDown(x, y)) {
3070
+ return;
3071
+ }
3072
+ }
3073
+ }
3074
+ }
3075
+ pointerMoveInternal(x, y) {
3077
3076
  if (this.mode === UIMode.INTERACTIVE) {
3078
3077
  this._private_inputListeners.sort((a, b) => b.zIndex - a.zIndex);
3079
3078
  for (const listener of this._private_inputListeners) {
3080
- if (listener.listener.catchClick(x, y)) {
3079
+ if (listener.listener.catchMove(x, y)) {
3080
+ return;
3081
+ }
3082
+ }
3083
+ }
3084
+ }
3085
+ pointerUpInternal(x, y) {
3086
+ if (this.mode === UIMode.INTERACTIVE) {
3087
+ this._private_inputListeners.sort((a, b) => b.zIndex - a.zIndex);
3088
+ for (const listener of this._private_inputListeners) {
3089
+ if (listener.listener.catchUp(x, y)) {
3081
3090
  return;
3082
3091
  }
3083
3092
  }
@@ -4373,8 +4382,9 @@ var source$2 = "void main() {\n vec2 transformedUV = (uvTransform * vec3(io_U
4373
4382
  */
4374
4383
  var UIInputEvent;
4375
4384
  (function (UIInputEvent) {
4376
- /** Emitted when the element is clicked. */
4377
- UIInputEvent["CLICK"] = "click";
4385
+ UIInputEvent["DOWN"] = "click";
4386
+ UIInputEvent["MOVE"] = "move";
4387
+ UIInputEvent["UP"] = "up";
4378
4388
  })(UIInputEvent || (UIInputEvent = {}));
4379
4389
 
4380
4390
  /**
@@ -4702,7 +4712,7 @@ const axis = new Vector3(0, 0, 1);
4702
4712
  * @param element - The UI element to test against
4703
4713
  * @returns True if the point is within the element's bounds
4704
4714
  */
4705
- function isElementClicked(x, y, element) {
4715
+ function isInsideElement(x, y, element) {
4706
4716
  return (x > element.x &&
4707
4717
  x < element.x + element.width &&
4708
4718
  y > element.y &&
@@ -4747,16 +4757,24 @@ class UIElement extends UIAnchor {
4747
4757
  this.transparencyInternal = UITransparencyMode.BLEND;
4748
4758
  /** Internal storage for the z-index (depth) value. */
4749
4759
  this.zIndexInternal = 0;
4750
- /**
4751
- * Handles click events when the element is in interactive mode.
4752
- * @param x - The x coordinate of the click
4753
- * @param y - The y coordinate of the click
4754
- * @returns True if the click was within this element's bounds
4755
- */
4756
- this.onClick = (x, y) => {
4757
- const clicked = isElementClicked(x, y, this);
4760
+ this.onDown = (x, y) => {
4761
+ const clicked = isInsideElement(x, y, this);
4762
+ if (clicked) {
4763
+ this.emit(UIInputEvent.DOWN, x, y, this);
4764
+ }
4765
+ return clicked;
4766
+ };
4767
+ this.onMove = (x, y) => {
4768
+ const clicked = isInsideElement(x, y, this);
4758
4769
  if (clicked) {
4759
- this.emit(UIInputEvent.CLICK, x, y, this);
4770
+ this.emit(UIInputEvent.MOVE, x, y, this);
4771
+ }
4772
+ return clicked;
4773
+ };
4774
+ this.onUp = (x, y) => {
4775
+ const clicked = isInsideElement(x, y, this);
4776
+ if (clicked) {
4777
+ this.emit(UIInputEvent.UP, x, y, this);
4760
4778
  }
4761
4779
  return clicked;
4762
4780
  };
@@ -4893,7 +4911,11 @@ class UIElement extends UIAnchor {
4893
4911
  set mode(value) {
4894
4912
  if (this.modeInternal !== value) {
4895
4913
  if (value === UIMode.INTERACTIVE) {
4896
- this.listener = { catchClick: this.onClick };
4914
+ this.listener = {
4915
+ catchDown: this.onDown,
4916
+ catchMove: this.onMove,
4917
+ catchUp: this.onUp,
4918
+ };
4897
4919
  this.layer["listenPointerInput"](this.listener, this.zIndexInternal);
4898
4920
  }
4899
4921
  else if (this.modeInternal === UIMode.INTERACTIVE && this.listener) {
@@ -6736,13 +6758,29 @@ class UIFullscreenLayer extends UILayer {
6736
6758
  const scale = this._private_resizePolicyInternal["calculateScaleInternal"](window.innerWidth, window.innerHeight);
6737
6759
  this.resizeInternal(window.innerWidth * scale, window.innerHeight * scale);
6738
6760
  };
6739
- /**
6740
- * Handles pointer down. Converts browser coordinates to layer space.
6741
- * Y-coordinate is flipped to match UI coordinate system.
6742
- *
6743
- * @param event - Browser pointer event
6744
- */
6745
- this._private_onClick = (event) => {
6761
+ this._private_onDown = (event) => {
6762
+ const rect = event.target instanceof HTMLElement
6763
+ ? event.target.getBoundingClientRect()
6764
+ : null;
6765
+ const x = rect ? event.clientX - rect.left : event.clientX;
6766
+ const y = rect
6767
+ ? rect.bottom - event.clientY
6768
+ : window.innerHeight - event.clientY;
6769
+ const scale = this._private_resizePolicyInternal["calculateScaleInternal"](window.innerWidth, window.innerHeight);
6770
+ this.pointerDownInternal(x * scale, y * scale);
6771
+ };
6772
+ this._private_onMove = (event) => {
6773
+ const rect = event.target instanceof HTMLElement
6774
+ ? event.target.getBoundingClientRect()
6775
+ : null;
6776
+ const x = rect ? event.clientX - rect.left : event.clientX;
6777
+ const y = rect
6778
+ ? rect.bottom - event.clientY
6779
+ : window.innerHeight - event.clientY;
6780
+ const scale = this._private_resizePolicyInternal["calculateScaleInternal"](window.innerWidth, window.innerHeight);
6781
+ this.pointerMoveInternal(x * scale, y * scale);
6782
+ };
6783
+ this._private_onUp = (event) => {
6746
6784
  const rect = event.target instanceof HTMLElement
6747
6785
  ? event.target.getBoundingClientRect()
6748
6786
  : null;
@@ -6751,10 +6789,12 @@ class UIFullscreenLayer extends UILayer {
6751
6789
  ? rect.bottom - event.clientY
6752
6790
  : window.innerHeight - event.clientY;
6753
6791
  const scale = this._private_resizePolicyInternal["calculateScaleInternal"](window.innerWidth, window.innerHeight);
6754
- this.pointerClickInternal(x * scale, y * scale);
6792
+ this.pointerUpInternal(x * scale, y * scale);
6755
6793
  };
6756
6794
  window.addEventListener("resize", this._private_onResize);
6757
- window.addEventListener("pointerdown", this._private_onClick);
6795
+ window.addEventListener("pointerdown", this._private_onDown);
6796
+ window.addEventListener("pointermove", this._private_onMove);
6797
+ window.addEventListener("pointerup", this._private_onUp);
6758
6798
  this.mode = mode;
6759
6799
  this._private_resizePolicyInternal = resizePolicy;
6760
6800
  this._private_resizePolicyInternal.on(UIResizePolicyEvent.CHANGE, this._private_onResize);
@@ -6782,7 +6822,7 @@ class UIFullscreenLayer extends UILayer {
6782
6822
  */
6783
6823
  destroy() {
6784
6824
  window.removeEventListener("resize", this._private_onResize);
6785
- window.removeEventListener("pointerdown", this._private_onClick);
6825
+ window.removeEventListener("pointerdown", this._private_onDown);
6786
6826
  this._private_resizePolicyInternal.off(UIResizePolicyEvent.CHANGE, this._private_onResize);
6787
6827
  }
6788
6828
  /**