laymur 0.3.31 → 0.4.0
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/dist/elements/UIElement.d.ts +3 -3
- package/dist/index.js +64 -124
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/layers/UIFullscreenLayer.d.ts +1 -0
- package/dist/layers/UILayer.d.ts +10 -19
- package/dist/miscellaneous/UIInputEvent.d.ts +5 -5
- package/package.json +1 -1
|
@@ -162,9 +162,9 @@ export declare abstract class UIElement extends UIAnchor implements UIPlaneEleme
|
|
|
162
162
|
* the element should not be used anymore.
|
|
163
163
|
*/
|
|
164
164
|
destroy(): void;
|
|
165
|
-
protected readonly
|
|
166
|
-
protected readonly
|
|
167
|
-
protected readonly
|
|
165
|
+
protected readonly catchPointerDown: (x: number, y: number) => boolean;
|
|
166
|
+
protected readonly catchPointerMove: (x: number, y: number) => boolean;
|
|
167
|
+
protected readonly catchPointerUp: (x: number, y: number) => boolean;
|
|
168
168
|
protected handleInputEvent(x: number, y: number, inputEvent: UIInputEvent): boolean;
|
|
169
169
|
/**
|
|
170
170
|
* Called before each render frame to update the element's transform matrix.
|
package/dist/index.js
CHANGED
|
@@ -3001,18 +3001,6 @@ class UILayer extends i {
|
|
|
3001
3001
|
get orientation() {
|
|
3002
3002
|
return this.orientationInternal;
|
|
3003
3003
|
}
|
|
3004
|
-
// public set x(value: number) {
|
|
3005
|
-
// throw new Error("You cannot set the x position of a UI layer.");
|
|
3006
|
-
// }
|
|
3007
|
-
// public set y(value: number) {
|
|
3008
|
-
// throw new Error("You cannot set the y position of a UI layer.");
|
|
3009
|
-
// }
|
|
3010
|
-
// public set width(value: number) {
|
|
3011
|
-
// throw new Error("You cannot set the width of a UI layer.");
|
|
3012
|
-
// }
|
|
3013
|
-
// public set height(value: number) {
|
|
3014
|
-
// throw new Error("You cannot set the height of a UI layer.");
|
|
3015
|
-
// }
|
|
3016
3004
|
/**
|
|
3017
3005
|
* Sets the visibility and interaction mode and emits change event.
|
|
3018
3006
|
* @param value - The new UIMode setting
|
|
@@ -3062,35 +3050,14 @@ class UILayer extends i {
|
|
|
3062
3050
|
this.sceneWrapper.render(renderer);
|
|
3063
3051
|
}
|
|
3064
3052
|
}
|
|
3065
|
-
|
|
3066
|
-
|
|
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
|
-
}
|
|
3053
|
+
onPointerDownInternal(x, y) {
|
|
3054
|
+
this._private_handleInputEvent(x, y, "catchPointerDown");
|
|
3074
3055
|
}
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
this._private_inputListeners.sort((a, b) => b.zIndex - a.zIndex);
|
|
3078
|
-
for (const listener of this._private_inputListeners) {
|
|
3079
|
-
if (listener.listener.catchMove(x, y)) {
|
|
3080
|
-
return;
|
|
3081
|
-
}
|
|
3082
|
-
}
|
|
3083
|
-
}
|
|
3056
|
+
onPointerMoveInternal(x, y) {
|
|
3057
|
+
this._private_handleInputEvent(x, y, "catchPointerMove");
|
|
3084
3058
|
}
|
|
3085
|
-
|
|
3086
|
-
|
|
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)) {
|
|
3090
|
-
return;
|
|
3091
|
-
}
|
|
3092
|
-
}
|
|
3093
|
-
}
|
|
3059
|
+
onPointerUpInternal(x, y) {
|
|
3060
|
+
this._private_handleInputEvent(x, y, "catchPointerUp");
|
|
3094
3061
|
}
|
|
3095
3062
|
/**
|
|
3096
3063
|
* Internal method for accessing the constraint solver wrapper.
|
|
@@ -3124,28 +3091,11 @@ class UILayer extends i {
|
|
|
3124
3091
|
* @param zIndex - The z-index priority for event handling order
|
|
3125
3092
|
* @throws Will throw an error if the listener is already registered
|
|
3126
3093
|
*/
|
|
3127
|
-
["
|
|
3128
|
-
if (this._private_inputListeners.find((l) => l
|
|
3094
|
+
["subscribePointerInput"](listener) {
|
|
3095
|
+
if (this._private_inputListeners.find((l) => l === listener)) {
|
|
3129
3096
|
throw new Error("Listener already exists");
|
|
3130
3097
|
}
|
|
3131
|
-
this._private_inputListeners.push(
|
|
3132
|
-
}
|
|
3133
|
-
/**
|
|
3134
|
-
* Internal method for updating the z-index of an existing input listener.
|
|
3135
|
-
*
|
|
3136
|
-
* Changes the priority order for event handling of an already registered listener.
|
|
3137
|
-
* The listener must already exist in the system.
|
|
3138
|
-
*
|
|
3139
|
-
* @param listener - The input listener to update
|
|
3140
|
-
* @param zIndex - The new z-index priority
|
|
3141
|
-
* @throws Will throw an error if the listener is not found
|
|
3142
|
-
*/
|
|
3143
|
-
["setListenerZIndex"](listener, zIndex) {
|
|
3144
|
-
const index = this._private_inputListeners.findIndex((l) => l.listener === listener);
|
|
3145
|
-
if (index === -1) {
|
|
3146
|
-
throw new Error("Listener not found");
|
|
3147
|
-
}
|
|
3148
|
-
this._private_inputListeners[index].zIndex = zIndex;
|
|
3098
|
+
this._private_inputListeners.push(listener);
|
|
3149
3099
|
}
|
|
3150
3100
|
/**
|
|
3151
3101
|
* Internal method for unregistering an input listener.
|
|
@@ -3156,13 +3106,23 @@ class UILayer extends i {
|
|
|
3156
3106
|
* @param listener - The input listener to remove
|
|
3157
3107
|
* @throws Will throw an error if the listener is not found
|
|
3158
3108
|
*/
|
|
3159
|
-
["
|
|
3160
|
-
const index = this._private_inputListeners.findIndex((l) => l
|
|
3109
|
+
["unsubscribePointerInput"](listener) {
|
|
3110
|
+
const index = this._private_inputListeners.findIndex((l) => l === listener);
|
|
3161
3111
|
if (index === -1) {
|
|
3162
3112
|
throw new Error("Listener not found");
|
|
3163
3113
|
}
|
|
3164
3114
|
this._private_inputListeners.splice(index, 1);
|
|
3165
3115
|
}
|
|
3116
|
+
_private_handleInputEvent(x, y, catchFunctionName) {
|
|
3117
|
+
if (this.mode === UIMode.INTERACTIVE) {
|
|
3118
|
+
this._private_inputListeners.sort((a, b) => b.zIndex - a.zIndex);
|
|
3119
|
+
for (const listener of this._private_inputListeners) {
|
|
3120
|
+
if (listener[catchFunctionName](x, y)) {
|
|
3121
|
+
return;
|
|
3122
|
+
}
|
|
3123
|
+
}
|
|
3124
|
+
}
|
|
3125
|
+
}
|
|
3166
3126
|
}
|
|
3167
3127
|
|
|
3168
3128
|
/**
|
|
@@ -4382,11 +4342,11 @@ var source$2 = "void main() {\n vec2 transformedUV = (uvTransform * vec3(io_U
|
|
|
4382
4342
|
*/
|
|
4383
4343
|
var UIInputEvent;
|
|
4384
4344
|
(function (UIInputEvent) {
|
|
4385
|
-
UIInputEvent["DOWN"] = "
|
|
4386
|
-
UIInputEvent["MOVE"] = "
|
|
4387
|
-
UIInputEvent["UP"] = "
|
|
4388
|
-
UIInputEvent["
|
|
4389
|
-
UIInputEvent["
|
|
4345
|
+
UIInputEvent["DOWN"] = "pointerdown";
|
|
4346
|
+
UIInputEvent["MOVE"] = "pointermove";
|
|
4347
|
+
UIInputEvent["UP"] = "pointerup";
|
|
4348
|
+
UIInputEvent["ENTER"] = "pointerenter";
|
|
4349
|
+
UIInputEvent["LEAVE"] = "pointerleave";
|
|
4390
4350
|
})(UIInputEvent || (UIInputEvent = {}));
|
|
4391
4351
|
|
|
4392
4352
|
/**
|
|
@@ -4707,19 +4667,6 @@ const quaternion = new Quaternion();
|
|
|
4707
4667
|
const scale = new Vector3();
|
|
4708
4668
|
const matrix = new Matrix4();
|
|
4709
4669
|
const axis = new Vector3(0, 0, 1);
|
|
4710
|
-
/**
|
|
4711
|
-
* Checks if a point (x, y) is within the bounds of a UI element.
|
|
4712
|
-
* @param x - The x coordinate to test
|
|
4713
|
-
* @param y - The y coordinate to test
|
|
4714
|
-
* @param element - The UI element to test against
|
|
4715
|
-
* @returns True if the point is within the element's bounds
|
|
4716
|
-
*/
|
|
4717
|
-
function isInsideElement(x, y, element) {
|
|
4718
|
-
return (x > element.x &&
|
|
4719
|
-
x < element.x + element.width &&
|
|
4720
|
-
y > element.y &&
|
|
4721
|
-
y < element.y + element.height);
|
|
4722
|
-
}
|
|
4723
4670
|
/**
|
|
4724
4671
|
* Abstract base class for all renderable UI elements with dimensions.
|
|
4725
4672
|
*
|
|
@@ -4760,13 +4707,13 @@ class UIElement extends UIAnchor {
|
|
|
4760
4707
|
/** Internal storage for the z-index (depth) value. */
|
|
4761
4708
|
this.zIndexInternal = 0;
|
|
4762
4709
|
this.isPointerInside = false;
|
|
4763
|
-
this.
|
|
4710
|
+
this.catchPointerDown = (x, y) => {
|
|
4764
4711
|
return this.handleInputEvent(x, y, UIInputEvent.DOWN);
|
|
4765
4712
|
};
|
|
4766
|
-
this.
|
|
4713
|
+
this.catchPointerMove = (x, y) => {
|
|
4767
4714
|
return this.handleInputEvent(x, y, UIInputEvent.MOVE);
|
|
4768
4715
|
};
|
|
4769
|
-
this.
|
|
4716
|
+
this.catchPointerUp = (x, y) => {
|
|
4770
4717
|
return this.handleInputEvent(x, y, UIInputEvent.UP);
|
|
4771
4718
|
};
|
|
4772
4719
|
this.layer.on(UILayerEvent.WILL_RENDER, this.onWillRender, this);
|
|
@@ -4867,7 +4814,7 @@ class UIElement extends UIAnchor {
|
|
|
4867
4814
|
assertValidNumber(value, "UIElement zIndex");
|
|
4868
4815
|
this.zIndexInternal = value;
|
|
4869
4816
|
if (this.listener) {
|
|
4870
|
-
this.
|
|
4817
|
+
this.listener.zIndex = this.zIndexInternal;
|
|
4871
4818
|
}
|
|
4872
4819
|
}
|
|
4873
4820
|
/**
|
|
@@ -4903,14 +4850,15 @@ class UIElement extends UIAnchor {
|
|
|
4903
4850
|
if (this.modeInternal !== value) {
|
|
4904
4851
|
if (value === UIMode.INTERACTIVE) {
|
|
4905
4852
|
this.listener = {
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
|
|
4853
|
+
catchPointerDown: this.catchPointerDown,
|
|
4854
|
+
catchPointerMove: this.catchPointerMove,
|
|
4855
|
+
catchPointerUp: this.catchPointerUp,
|
|
4856
|
+
zIndex: this.zIndexInternal,
|
|
4909
4857
|
};
|
|
4910
|
-
this.layer["
|
|
4858
|
+
this.layer["subscribePointerInput"](this.listener);
|
|
4911
4859
|
}
|
|
4912
4860
|
else if (this.modeInternal === UIMode.INTERACTIVE && this.listener) {
|
|
4913
|
-
this.layer["
|
|
4861
|
+
this.layer["unsubscribePointerInput"](this.listener);
|
|
4914
4862
|
this.listener = undefined;
|
|
4915
4863
|
}
|
|
4916
4864
|
this.modeInternal = value;
|
|
@@ -4937,7 +4885,7 @@ class UIElement extends UIAnchor {
|
|
|
4937
4885
|
destroy() {
|
|
4938
4886
|
this.layer.off(UILayerEvent.WILL_RENDER, this.onWillRender, this);
|
|
4939
4887
|
if (this.listener) {
|
|
4940
|
-
this.layer["
|
|
4888
|
+
this.layer["unsubscribePointerInput"](this.listener);
|
|
4941
4889
|
}
|
|
4942
4890
|
this.solverWrapper.removeVariable(this.hVariable);
|
|
4943
4891
|
this.solverWrapper.removeVariable(this.wVariable);
|
|
@@ -4945,18 +4893,21 @@ class UIElement extends UIAnchor {
|
|
|
4945
4893
|
super.destroy();
|
|
4946
4894
|
}
|
|
4947
4895
|
handleInputEvent(x, y, inputEvent) {
|
|
4948
|
-
const
|
|
4949
|
-
|
|
4896
|
+
const isPointerInside = x > this.x &&
|
|
4897
|
+
x < this.x + this.width &&
|
|
4898
|
+
y > this.y &&
|
|
4899
|
+
y < this.y + this.height;
|
|
4900
|
+
if (isPointerInside) {
|
|
4950
4901
|
this.emit(inputEvent, x, y, this);
|
|
4951
4902
|
}
|
|
4952
|
-
if (this.isPointerInside && !
|
|
4953
|
-
this.emit(UIInputEvent.
|
|
4903
|
+
if (this.isPointerInside && !isPointerInside) {
|
|
4904
|
+
this.emit(UIInputEvent.LEAVE, x, y, this);
|
|
4954
4905
|
}
|
|
4955
|
-
else if (!this.isPointerInside &&
|
|
4956
|
-
this.emit(UIInputEvent.
|
|
4906
|
+
else if (!this.isPointerInside && isPointerInside) {
|
|
4907
|
+
this.emit(UIInputEvent.ENTER, x, y, this);
|
|
4957
4908
|
}
|
|
4958
|
-
this.isPointerInside =
|
|
4959
|
-
return
|
|
4909
|
+
this.isPointerInside = isPointerInside;
|
|
4910
|
+
return isPointerInside;
|
|
4960
4911
|
}
|
|
4961
4912
|
/**
|
|
4962
4913
|
* Called before each render frame to update the element's transform matrix.
|
|
@@ -6764,37 +6715,13 @@ class UIFullscreenLayer extends UILayer {
|
|
|
6764
6715
|
this.resizeInternal(window.innerWidth * scale, window.innerHeight * scale);
|
|
6765
6716
|
};
|
|
6766
6717
|
this._private_onDown = (event) => {
|
|
6767
|
-
|
|
6768
|
-
? event.target.getBoundingClientRect()
|
|
6769
|
-
: null;
|
|
6770
|
-
const x = rect ? event.clientX - rect.left : event.clientX;
|
|
6771
|
-
const y = rect
|
|
6772
|
-
? rect.bottom - event.clientY
|
|
6773
|
-
: window.innerHeight - event.clientY;
|
|
6774
|
-
const scale = this._private_resizePolicyInternal["calculateScaleInternal"](window.innerWidth, window.innerHeight);
|
|
6775
|
-
this.pointerDownInternal(x * scale, y * scale);
|
|
6718
|
+
this._private_handleWindowInput(event, "onPointerDownInternal");
|
|
6776
6719
|
};
|
|
6777
6720
|
this._private_onMove = (event) => {
|
|
6778
|
-
|
|
6779
|
-
? event.target.getBoundingClientRect()
|
|
6780
|
-
: null;
|
|
6781
|
-
const x = rect ? event.clientX - rect.left : event.clientX;
|
|
6782
|
-
const y = rect
|
|
6783
|
-
? rect.bottom - event.clientY
|
|
6784
|
-
: window.innerHeight - event.clientY;
|
|
6785
|
-
const scale = this._private_resizePolicyInternal["calculateScaleInternal"](window.innerWidth, window.innerHeight);
|
|
6786
|
-
this.pointerMoveInternal(x * scale, y * scale);
|
|
6721
|
+
this._private_handleWindowInput(event, "onPointerMoveInternal");
|
|
6787
6722
|
};
|
|
6788
6723
|
this._private_onUp = (event) => {
|
|
6789
|
-
|
|
6790
|
-
? event.target.getBoundingClientRect()
|
|
6791
|
-
: null;
|
|
6792
|
-
const x = rect ? event.clientX - rect.left : event.clientX;
|
|
6793
|
-
const y = rect
|
|
6794
|
-
? rect.bottom - event.clientY
|
|
6795
|
-
: window.innerHeight - event.clientY;
|
|
6796
|
-
const scale = this._private_resizePolicyInternal["calculateScaleInternal"](window.innerWidth, window.innerHeight);
|
|
6797
|
-
this.pointerUpInternal(x * scale, y * scale);
|
|
6724
|
+
this._private_handleWindowInput(event, "onPointerUpInternal");
|
|
6798
6725
|
};
|
|
6799
6726
|
window.addEventListener("resize", this._private_onResize);
|
|
6800
6727
|
window.addEventListener("pointerdown", this._private_onDown);
|
|
@@ -6828,6 +6755,8 @@ class UIFullscreenLayer extends UILayer {
|
|
|
6828
6755
|
destroy() {
|
|
6829
6756
|
window.removeEventListener("resize", this._private_onResize);
|
|
6830
6757
|
window.removeEventListener("pointerdown", this._private_onDown);
|
|
6758
|
+
window.removeEventListener("pointermove", this._private_onMove);
|
|
6759
|
+
window.removeEventListener("pointerup", this._private_onUp);
|
|
6831
6760
|
this._private_resizePolicyInternal.off(UIResizePolicyEvent.CHANGE, this._private_onResize);
|
|
6832
6761
|
}
|
|
6833
6762
|
/**
|
|
@@ -6853,6 +6782,17 @@ class UIFullscreenLayer extends UILayer {
|
|
|
6853
6782
|
projectedPosition.y = MathUtils.mapLinear(projectedPosition.y, -1, 1, this.y, this.height);
|
|
6854
6783
|
return projectedPosition;
|
|
6855
6784
|
}
|
|
6785
|
+
_private_handleWindowInput(event, pointerFunctionName) {
|
|
6786
|
+
const rect = event.target instanceof HTMLElement
|
|
6787
|
+
? event.target.getBoundingClientRect()
|
|
6788
|
+
: null;
|
|
6789
|
+
const x = rect ? event.clientX - rect.left : event.clientX;
|
|
6790
|
+
const y = rect
|
|
6791
|
+
? rect.bottom - event.clientY
|
|
6792
|
+
: window.innerHeight - event.clientY;
|
|
6793
|
+
const scale = this._private_resizePolicyInternal["calculateScaleInternal"](window.innerWidth, window.innerHeight);
|
|
6794
|
+
this[pointerFunctionName](x * scale, y * scale);
|
|
6795
|
+
}
|
|
6856
6796
|
}
|
|
6857
6797
|
|
|
6858
6798
|
const INSTANCED_GEOMETRY = (() => {
|