laymur 0.25.2 → 0.27.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.
Files changed (186) hide show
  1. package/README.md +114 -34
  2. package/dist/core/constraints/UICustomConstraint.d.ts +1 -1
  3. package/dist/core/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.js +1 -1
  4. package/dist/core/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.js +1 -1
  5. package/dist/core/constraints/builders/UIConstraint2DBuilder.d.ts +2 -3
  6. package/dist/core/elements/UIAnchor/UIAnchor.d.ts +2 -2
  7. package/dist/core/elements/UIAnchor/UIAnchor.js +3 -2
  8. package/dist/core/elements/UIAnimatedImage/UIAnimatedImage.d.ts +2 -2
  9. package/dist/core/elements/UIAnimatedImage/UIAnimatedImage.js +24 -12
  10. package/dist/core/elements/UIDummy/UIDummy.Internal.d.ts +13 -0
  11. package/dist/core/elements/UIDummy/UIDummy.d.ts +74 -5
  12. package/dist/core/elements/UIDummy/UIDummy.js +222 -29
  13. package/dist/core/elements/UIElement/UIElement.Internal.d.ts +1 -1
  14. package/dist/core/elements/UIElement/UIElement.d.ts +37 -1
  15. package/dist/core/elements/UIElement/UIElement.js +84 -6
  16. package/dist/core/elements/UIGraphics/UIGraphics.Internal.d.ts +1 -1
  17. package/dist/core/elements/UIGraphics/UIGraphics.d.ts +1 -1
  18. package/dist/core/elements/UIGraphics/UIGraphics.js +4 -4
  19. package/dist/core/elements/UIImage/UIImage.d.ts +2 -2
  20. package/dist/core/elements/UIImage/UIImage.js +10 -8
  21. package/dist/core/elements/UINineSlice/UINineSlice.d.ts +4 -4
  22. package/dist/core/elements/UINineSlice/UINineSlice.js +11 -9
  23. package/dist/core/elements/UIProgress/UIProgress.d.ts +2 -2
  24. package/dist/core/elements/UIProgress/UIProgress.js +17 -15
  25. package/dist/core/elements/UIScene/UIScene.Internal.d.ts +1 -1
  26. package/dist/core/elements/UIScene/UIScene.d.ts +3 -2
  27. package/dist/core/elements/UIScene/UIScene.js +21 -14
  28. package/dist/core/elements/UIText/UIText.Measuring.d.ts +1 -1
  29. package/dist/core/elements/UIText/UIText.d.ts +3 -3
  30. package/dist/core/elements/UIText/UIText.js +8 -8
  31. package/dist/core/index.d.ts +60 -11
  32. package/dist/core/index.js +22 -7
  33. package/dist/core/layers/UILayer/UILayer.d.ts +45 -5
  34. package/dist/core/layers/UILayer/UILayer.js +103 -10
  35. package/dist/core/layers/UIViewportLayer/UIViewportLayer.Internal.d.ts +27 -0
  36. package/dist/core/layers/{UIFullscreenLayer/UIFullscreenLayer.Internal.js → UIViewportLayer/UIViewportLayer.Internal.js} +1 -1
  37. package/dist/core/layers/UIViewportLayer/UIViewportLayer.d.ts +98 -0
  38. package/dist/core/layers/UIViewportLayer/UIViewportLayer.js +251 -0
  39. package/dist/core/miscellaneous/UIAffineMatrix3.d.ts +13 -0
  40. package/dist/core/miscellaneous/UIAffineMatrix3.js +13 -0
  41. package/dist/core/miscellaneous/area/UIArea.d.ts +10 -1
  42. package/dist/core/miscellaneous/area/UIArea.js +4 -1
  43. package/dist/core/miscellaneous/area/UIAreaCircle.d.ts +1 -0
  44. package/dist/core/miscellaneous/area/UIAreaCircle.js +0 -1
  45. package/dist/core/miscellaneous/area/UIAreaPolygon.d.ts +1 -0
  46. package/dist/core/miscellaneous/area/UIAreaPolygon.js +0 -1
  47. package/dist/core/miscellaneous/area/UIAreaRectangle.d.ts +1 -0
  48. package/dist/core/miscellaneous/area/UIAreaRectangle.js +0 -1
  49. package/dist/core/miscellaneous/area/UIAreaRoundedRectangle.d.ts +1 -0
  50. package/dist/core/miscellaneous/area/UIAreaRoundedRectangle.js +0 -1
  51. package/dist/core/miscellaneous/asserts.d.ts +23 -0
  52. package/dist/core/miscellaneous/asserts.js +44 -0
  53. package/dist/core/miscellaneous/canvas.js +7 -2
  54. package/dist/core/miscellaneous/color/UIColor.js +5 -2
  55. package/dist/core/miscellaneous/computeTransform.d.ts +12 -0
  56. package/dist/core/miscellaneous/computeTransform.js +20 -0
  57. package/dist/core/miscellaneous/context-monitor/UIContextMonitor.d.ts +1 -0
  58. package/dist/core/miscellaneous/context-monitor/UIContextMonitor.js +60 -0
  59. package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Internal.d.ts +17 -3
  60. package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Internal.js +88 -26
  61. package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Layout.d.ts +9 -0
  62. package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Layout.js +29 -6
  63. package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.js +51 -11
  64. package/dist/core/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.Internal.d.ts +2 -0
  65. package/dist/core/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.js +47 -6
  66. package/dist/core/miscellaneous/generic-plane/shared.d.ts +15 -3
  67. package/dist/core/miscellaneous/generic-plane/shared.js +38 -7
  68. package/dist/core/miscellaneous/generic-plane/varyingPacking.d.ts +46 -0
  69. package/dist/core/miscellaneous/generic-plane/varyingPacking.js +170 -0
  70. package/dist/core/miscellaneous/mask/UIMask.Internal.d.ts +61 -0
  71. package/dist/core/miscellaneous/mask/UIMask.Internal.js +56 -0
  72. package/dist/core/miscellaneous/mask/UIMask.d.ts +84 -0
  73. package/dist/core/miscellaneous/mask/UIMask.js +265 -0
  74. package/dist/core/miscellaneous/mask/UIMaskMaterialPatch.d.ts +50 -0
  75. package/dist/core/miscellaneous/mask/UIMaskMaterialPatch.js +233 -0
  76. package/dist/core/miscellaneous/mask-function/UIProgressMaskFunction.d.ts +10 -1
  77. package/dist/core/miscellaneous/mask-function/UIProgressMaskFunction.js +7 -1
  78. package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionCircular.d.ts +2 -0
  79. package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionCircular.js +0 -1
  80. package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionDirectional.d.ts +2 -0
  81. package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionDirectional.js +0 -1
  82. package/dist/core/miscellaneous/micro/UIMicro.Internal.d.ts +3 -0
  83. package/dist/core/miscellaneous/micro/UIMicro.Internal.js +1 -0
  84. package/dist/core/miscellaneous/micro/UIMicro.d.ts +18 -1
  85. package/dist/core/miscellaneous/micro/UIMicro.js +23 -2
  86. package/dist/core/miscellaneous/resize-policy/UIResizePolicy.d.ts +19 -1
  87. package/dist/core/miscellaneous/resize-policy/UIResizePolicy.js +16 -3
  88. package/dist/core/miscellaneous/resize-policy/UIResizePolicyCover.js +2 -2
  89. package/dist/core/miscellaneous/resize-policy/UIResizePolicyCross.js +2 -2
  90. package/dist/core/miscellaneous/resize-policy/UIResizePolicyCrossInverted.js +2 -2
  91. package/dist/core/miscellaneous/resize-policy/UIResizePolicyFit.js +2 -2
  92. package/dist/core/miscellaneous/resize-policy/UIResizePolicyFixedHeight.js +2 -2
  93. package/dist/core/miscellaneous/resize-policy/UIResizePolicyFixedWidth.js +2 -2
  94. package/dist/core/miscellaneous/text-style/UITextStyle.js +2 -2
  95. package/dist/core/miscellaneous/texture/UITextureView.d.ts +6 -2
  96. package/dist/core/miscellaneous/texture/UITextureView.js +13 -9
  97. package/dist/core/miscellaneous/viewport/UIElementViewport.d.ts +31 -0
  98. package/dist/core/miscellaneous/viewport/UIElementViewport.js +54 -0
  99. package/dist/core/miscellaneous/viewport/UIViewport.d.ts +37 -0
  100. package/dist/core/miscellaneous/viewport/UIViewport.js +31 -0
  101. package/dist/core/miscellaneous/viewport/UIWindowViewport.d.ts +13 -0
  102. package/dist/core/miscellaneous/viewport/UIWindowViewport.js +25 -0
  103. package/dist/core/miscellaneous/webglCapabilities.js +61 -55
  104. package/dist/core/shaders/UIMask.d.ts +15 -0
  105. package/dist/core/shaders/UIMask.js +45 -0
  106. package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.Internal.d.ts +36 -5
  107. package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.d.ts +23 -2
  108. package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.js +153 -15
  109. package/dist/core/wrappers/UISceneWrapper/UISceneWrapper.Internal.d.ts +3 -1
  110. package/dist/core/wrappers/UISceneWrapper/UISceneWrapper.d.ts +1 -0
  111. package/dist/core/wrappers/UISceneWrapper/UISceneWrapper.js +3 -0
  112. package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.Internal.d.ts +2 -0
  113. package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.d.ts +3 -0
  114. package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.js +36 -16
  115. package/dist/debug/UIAspectDebug.js +4 -0
  116. package/dist/debug/UIHeightDebug.js +4 -0
  117. package/dist/debug/UIHorizontalDistanceDebug.js +5 -0
  118. package/dist/debug/UIHorizontalInterpolationDebug.js +5 -0
  119. package/dist/debug/UILayerDebug.d.ts +7 -0
  120. package/dist/debug/UILayerDebug.js +21 -0
  121. package/dist/debug/UIVerticalDistanceDebug.js +5 -0
  122. package/dist/debug/UIVerticalInterpolationDebug.js +5 -0
  123. package/dist/debug/UIWidthDebug.js +4 -0
  124. package/dist/debug/index.d.ts +2 -0
  125. package/dist/particles/behaviorModules/UIBehaviorDirectionalGravity.d.ts +8 -1
  126. package/dist/particles/behaviorModules/UIBehaviorDirectionalGravity.js +0 -2
  127. package/dist/particles/behaviorModules/UIBehaviorModule.d.ts +12 -2
  128. package/dist/particles/behaviorModules/UIBehaviorModule.js +2 -1
  129. package/dist/particles/behaviorModules/UIBehaviorPointGravity.d.ts +8 -1
  130. package/dist/particles/behaviorModules/UIBehaviorPointGravity.js +13 -12
  131. package/dist/particles/behaviorModules/UIBehaviorScaleOscillation.d.ts +7 -0
  132. package/dist/particles/behaviorModules/UIBehaviorScaleOscillation.js +6 -6
  133. package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.d.ts +7 -0
  134. package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.js +4 -5
  135. package/dist/particles/behaviorModules/UIBehaviorTorqueDamping.d.ts +8 -1
  136. package/dist/particles/behaviorModules/UIBehaviorTorqueDamping.js +8 -10
  137. package/dist/particles/behaviorModules/UIBehaviorTorqueNoise.d.ts +10 -2
  138. package/dist/particles/behaviorModules/UIBehaviorTorqueNoise.js +8 -7
  139. package/dist/particles/behaviorModules/UIBehaviorVelocityDamping.d.ts +7 -0
  140. package/dist/particles/behaviorModules/UIBehaviorVelocityDamping.js +8 -10
  141. package/dist/particles/behaviorModules/UIBehaviorVelocityNoise.d.ts +13 -4
  142. package/dist/particles/behaviorModules/UIBehaviorVelocityNoise.js +12 -10
  143. package/dist/particles/elements/UIEmitter.Internal.d.ts +21 -1
  144. package/dist/particles/elements/UIEmitter.Internal.js +6 -0
  145. package/dist/particles/elements/UIEmitter.d.ts +20 -11
  146. package/dist/particles/elements/UIEmitter.js +100 -54
  147. package/dist/particles/index.d.ts +7 -1
  148. package/dist/particles/index.js +4 -0
  149. package/dist/particles/instancedParticle/UIInstancedParticle.Internal.d.ts +19 -4
  150. package/dist/particles/instancedParticle/UIInstancedParticle.Internal.js +117 -83
  151. package/dist/particles/instancedParticle/UIInstancedParticle.d.ts +8 -0
  152. package/dist/particles/instancedParticle/UIInstancedParticle.js +41 -4
  153. package/dist/particles/miscellaneous/miscellaneous.d.ts +34 -0
  154. package/dist/particles/miscellaneous/miscellaneous.js +72 -0
  155. package/dist/particles/renderingModules/UIRenderingColorOverLife.d.ts +4 -0
  156. package/dist/particles/renderingModules/UIRenderingColorOverLife.js +2 -4
  157. package/dist/particles/renderingModules/UIRenderingColorOverVelocity.d.ts +4 -0
  158. package/dist/particles/renderingModules/UIRenderingColorOverVelocity.js +2 -5
  159. package/dist/particles/renderingModules/UIRenderingModule.d.ts +11 -1
  160. package/dist/particles/renderingModules/UIRenderingModule.js +4 -1
  161. package/dist/particles/renderingModules/UIRenderingTexture.d.ts +4 -0
  162. package/dist/particles/renderingModules/UIRenderingTexture.js +2 -1
  163. package/dist/particles/shaders/UIRenderingColorOverLife.d.ts +1 -2
  164. package/dist/particles/shaders/UIRenderingColorOverLife.js +5 -3
  165. package/dist/particles/shaders/UIRenderingColorOverVelocity.d.ts +1 -9
  166. package/dist/particles/shaders/UIRenderingColorOverVelocity.js +6 -13
  167. package/dist/particles/spawnModules/UISpawnModule.d.ts +16 -1
  168. package/dist/particles/spawnModules/UISpawnModule.js +3 -1
  169. package/dist/particles/spawnModules/UISpawnOffset.d.ts +7 -0
  170. package/dist/particles/spawnModules/UISpawnOffset.js +0 -2
  171. package/dist/particles/spawnModules/UISpawnRandomLifetime.d.ts +8 -1
  172. package/dist/particles/spawnModules/UISpawnRandomLifetime.js +5 -7
  173. package/dist/particles/spawnModules/UISpawnRandomRotation.d.ts +7 -0
  174. package/dist/particles/spawnModules/UISpawnRandomRotation.js +5 -5
  175. package/dist/particles/spawnModules/UISpawnRandomScale.d.ts +7 -0
  176. package/dist/particles/spawnModules/UISpawnRandomScale.js +4 -5
  177. package/dist/particles/spawnModules/UISpawnRandomTorque.d.ts +7 -0
  178. package/dist/particles/spawnModules/UISpawnRandomTorque.js +5 -5
  179. package/dist/particles/spawnModules/UISpawnRandomVelocity.d.ts +7 -0
  180. package/dist/particles/spawnModules/UISpawnRandomVelocity.js +6 -6
  181. package/dist/particles/spawnModules/UISpawnRectangle.d.ts +7 -0
  182. package/dist/particles/spawnModules/UISpawnRectangle.js +6 -6
  183. package/package.json +13 -4
  184. package/dist/core/layers/UIFullscreenLayer/UIFullscreenLayer.Internal.d.ts +0 -21
  185. package/dist/core/layers/UIFullscreenLayer/UIFullscreenLayer.d.ts +0 -63
  186. package/dist/core/layers/UIFullscreenLayer/UIFullscreenLayer.js +0 -144
@@ -1,8 +1,9 @@
1
- import type { FerrsignView2, FerrsignView3 } from "ferrsign";
1
+ import type { FerrsignView1, FerrsignView2, FerrsignView3 } from "ferrsign";
2
2
  import type { WebGLRenderer } from "three";
3
- import type { UIPlaneElement } from "../../miscellaneous/shared.js";
4
3
  import type { UIConstraint } from "../../constraints/UIConstraint.js";
5
4
  import type { UIAnchor } from "../../elements/UIAnchor/UIAnchor.js";
5
+ import type { UIMask } from "../../miscellaneous/mask/UIMask.js";
6
+ import type { UIPlaneElement } from "../../miscellaneous/shared.js";
6
7
  import { UIInputWrapper } from "../../wrappers/UIInputWrapper/UIInputWrapper.js";
7
8
  import type { UISceneWrapperView } from "../../wrappers/UISceneWrapper/UISceneWrapper.Internal.js";
8
9
  import type { UILayerMode, UILayerOptions, UILayerOrientation } from "./UILayer.Internal.js";
@@ -27,10 +28,14 @@ export declare abstract class UILayer implements UIPlaneElement {
27
28
  private readonly signalModeChangedInternal;
28
29
  private readonly signalRenderingInternal;
29
30
  private readonly signalResizedInternal;
31
+ private readonly signalContextLostInternal;
32
+ private readonly signalContextRestoredInternal;
30
33
  private readonly signalConstraintAddedInternal;
31
34
  private readonly signalConstraintRemovedInternal;
32
35
  private readonly constraintRegistryInternal;
33
36
  private readonly elementRegistryInternal;
37
+ private readonly maskRegistryInternal;
38
+ private contextMonitor;
34
39
  private destroyedInternal;
35
40
  constructor(options: Partial<UILayerOptions>);
36
41
  /**
@@ -66,7 +71,20 @@ export declare abstract class UILayer implements UIPlaneElement {
66
71
  get signalRendering(): FerrsignView3<WebGLRenderer, number, UILayer>;
67
72
  /** Signal fired when layer resized */
68
73
  get signalResized(): FerrsignView3<number, number, UILayer>;
69
- /** Signal fired when a constraint is added */
74
+ /**
75
+ * Signal fired when the WebGL context of the renderer the layer is drawn with is lost. The
76
+ * layer draws nothing until the context is restored; pause what depends on frames being shown.
77
+ */
78
+ get signalContextLost(): FerrsignView1<UILayer>;
79
+ /**
80
+ * Signal fired when the WebGL context is restored. The renderer has recreated its GL state by
81
+ * then; content that lives on the GPU only, such as render targets, has to be redrawn.
82
+ */
83
+ get signalContextRestored(): FerrsignView1<UILayer>;
84
+ /**
85
+ * Signal fired when a constraint is added. It fires from the base constructor, before the
86
+ * fields of the subclass are set: read them no sooner than in a microtask or on the next frame.
87
+ */
70
88
  get signalConstraintAdded(): FerrsignView2<UILayer, UIConstraint>;
71
89
  /** Signal fired when a constraint is removed */
72
90
  get signalConstraintRemoved(): FerrsignView2<UILayer, UIConstraint>;
@@ -74,18 +92,40 @@ export declare abstract class UILayer implements UIPlaneElement {
74
92
  get constraintRegistry(): readonly UIConstraint[];
75
93
  /** Elements created on the layer and not destroyed yet */
76
94
  get elementRegistry(): readonly UIAnchor[];
95
+ /** Masks whose source is the layer or one of its elements, not destroyed yet */
96
+ get maskRegistry(): readonly UIMask[];
77
97
  /** Whether the layer is destroyed */
78
98
  get destroyed(): boolean;
79
- /** Updates visibility and interactivity mode */
99
+ /**
100
+ * Updates visibility and interactivity mode. A layer that stops taking input cancels the
101
+ * pressed pointers: their releases would never arrive.
102
+ */
80
103
  set mode(value: UILayerMode);
81
104
  /**
82
- * Destroys all elements and constraints of the layer, those snapped to the layer itself
105
+ * Destroys all elements, constraints and masks of the layer, those tied to the layer itself
83
106
  * included, and frees the GPU resources of the layer. Textures are left to their owners.
84
107
  * Does nothing if the layer is already destroyed.
85
108
  */
86
109
  destroy(): void;
87
110
  protected resizeInternal(width: number, height: number): void;
88
111
  protected renderInternal(renderer: WebGLRenderer, deltaTime: number): void;
112
+ /**
113
+ * Cancels every pressed pointer, for its elements and for the layer: no release of those
114
+ * pointers will be reported.
115
+ */
116
+ protected cancelPointers(): void;
117
+ /** Follows the context of the renderer the layer is drawn with; null to stop following */
118
+ private bindContextMonitor;
119
+ private readonly onContextLost;
120
+ private readonly onContextRestored;
89
121
  /** A removal signal handler may destroy other constraints, so the registry is walked over a copy */
90
122
  private destroyConstraints;
123
+ /**
124
+ * Called for each pointer the layer cancels, before its elements are told: the subclass that
125
+ * takes the input reports the cancel to the users of the layer.
126
+ * @param x Last known horizontal position in layer coordinates
127
+ * @param y Last known vertical position in layer coordinates
128
+ * @param identifier Pointer identifier
129
+ */
130
+ protected abstract reportPointerCancelledByLayer(x: number, y: number, identifier: number): void;
91
131
  }
@@ -1,6 +1,7 @@
1
- import { Ferrsign2, Ferrsign3 } from "ferrsign";
1
+ import { Ferrsign1, Ferrsign2, Ferrsign3 } from "ferrsign";
2
2
  import { assertValidPositiveNumber } from "../../miscellaneous/asserts.js";
3
- import { isUIModeVisible } from "../../miscellaneous/UIMode.js";
3
+ import { UIContextMonitor } from "../../miscellaneous/context-monitor/UIContextMonitor.js";
4
+ import { isUIModeInteractive, isUIModeVisible } from "../../miscellaneous/UIMode.js";
4
5
  import { UIOrientation } from "../../miscellaneous/UIOrientation.js";
5
6
  import { UIPriority } from "../../miscellaneous/UIPriority.js";
6
7
  import { UIInputWrapper } from "../../wrappers/UIInputWrapper/UIInputWrapper.js";
@@ -18,11 +19,21 @@ export class UILayer {
18
19
  this.signalModeChangedInternal = new Ferrsign2();
19
20
  this.signalRenderingInternal = new Ferrsign3();
20
21
  this.signalResizedInternal = new Ferrsign3();
22
+ this.signalContextLostInternal = new Ferrsign1();
23
+ this.signalContextRestoredInternal = new Ferrsign1();
21
24
  this.signalConstraintAddedInternal = new Ferrsign2();
22
25
  this.signalConstraintRemovedInternal = new Ferrsign2();
23
26
  this.constraintRegistryInternal = [];
24
27
  this.elementRegistryInternal = [];
28
+ this.maskRegistryInternal = [];
29
+ this.contextMonitor = null;
25
30
  this.destroyedInternal = false;
31
+ this.onContextLost = () => {
32
+ this.signalContextLostInternal.emit(this);
33
+ };
34
+ this.onContextRestored = () => {
35
+ this.signalContextRestoredInternal.emit(this);
36
+ };
26
37
  if (options.width !== undefined) {
27
38
  assertValidPositiveNumber(options.width, "UILayer.constructor.options.width");
28
39
  }
@@ -111,7 +122,24 @@ export class UILayer {
111
122
  get signalResized() {
112
123
  return this.signalResizedInternal;
113
124
  }
114
- /** Signal fired when a constraint is added */
125
+ /**
126
+ * Signal fired when the WebGL context of the renderer the layer is drawn with is lost. The
127
+ * layer draws nothing until the context is restored; pause what depends on frames being shown.
128
+ */
129
+ get signalContextLost() {
130
+ return this.signalContextLostInternal;
131
+ }
132
+ /**
133
+ * Signal fired when the WebGL context is restored. The renderer has recreated its GL state by
134
+ * then; content that lives on the GPU only, such as render targets, has to be redrawn.
135
+ */
136
+ get signalContextRestored() {
137
+ return this.signalContextRestoredInternal;
138
+ }
139
+ /**
140
+ * Signal fired when a constraint is added. It fires from the base constructor, before the
141
+ * fields of the subclass are set: read them no sooner than in a microtask or on the next frame.
142
+ */
115
143
  get signalConstraintAdded() {
116
144
  return this.signalConstraintAddedInternal;
117
145
  }
@@ -127,19 +155,29 @@ export class UILayer {
127
155
  get elementRegistry() {
128
156
  return this.elementRegistryInternal;
129
157
  }
158
+ /** Masks whose source is the layer or one of its elements, not destroyed yet */
159
+ get maskRegistry() {
160
+ return this.maskRegistryInternal;
161
+ }
130
162
  /** Whether the layer is destroyed */
131
163
  get destroyed() {
132
164
  return this.destroyedInternal;
133
165
  }
134
- /** Updates visibility and interactivity mode */
166
+ /**
167
+ * Updates visibility and interactivity mode. A layer that stops taking input cancels the
168
+ * pressed pointers: their releases would never arrive.
169
+ */
135
170
  set mode(value) {
136
171
  if (value !== this.modeInternal) {
137
172
  this.modeInternal = value;
173
+ if (!isUIModeInteractive(value)) {
174
+ this.cancelPointers();
175
+ }
138
176
  this.signalModeChangedInternal.emit(this.modeInternal, this);
139
177
  }
140
178
  }
141
179
  /**
142
- * Destroys all elements and constraints of the layer, those snapped to the layer itself
180
+ * Destroys all elements, constraints and masks of the layer, those tied to the layer itself
143
181
  * included, and frees the GPU resources of the layer. Textures are left to their owners.
144
182
  * Does nothing if the layer is already destroyed.
145
183
  */
@@ -148,9 +186,11 @@ export class UILayer {
148
186
  return;
149
187
  }
150
188
  this.destroyedInternal = true;
189
+ this.bindContextMonitor(null);
151
190
  for (const element of [...this.elementRegistryInternal]) {
152
191
  element.destroy();
153
192
  }
193
+ this.destroyMasksUsingSource(this);
154
194
  this.destroyConstraints(() => true);
155
195
  this.sceneWrapperInternal.destroy();
156
196
  }
@@ -162,6 +202,32 @@ export class UILayer {
162
202
  destroyConstraintsUsingVariables(variables) {
163
203
  this.destroyConstraints((constraint) => variables.some((variable) => constraint.isUsingVariable(variable)));
164
204
  }
205
+ /**
206
+ * Destroys the masks that follow the given source, so that the source can be removed.
207
+ * @internal
208
+ */
209
+ destroyMasksUsingSource(source) {
210
+ for (const mask of [...this.maskRegistryInternal]) {
211
+ if (mask.source === source) {
212
+ mask.destroy();
213
+ }
214
+ }
215
+ }
216
+ /** @internal */
217
+ addMask(mask) {
218
+ if (this.destroyedInternal) {
219
+ throw new Error(`UILayer.addMask: layer is destroyed`);
220
+ }
221
+ this.maskRegistryInternal.push(mask);
222
+ }
223
+ /** @internal */
224
+ removeMask(mask) {
225
+ const index = this.maskRegistryInternal.indexOf(mask);
226
+ if (index === -1) {
227
+ throw new Error(`UILayer.removeMask: mask is not found in this layer`);
228
+ }
229
+ this.maskRegistryInternal.splice(index, 1);
230
+ }
165
231
  /** @internal */
166
232
  addElement(element) {
167
233
  if (this.destroyedInternal) {
@@ -201,10 +267,12 @@ export class UILayer {
201
267
  this.solverWrapperInternal.suggestVariableValue(this.wVariable, width);
202
268
  this.solverWrapperInternal.suggestVariableValue(this.hVariable, height);
203
269
  this.sceneWrapperInternal.resize(width, height);
204
- this.signalResizedInternal.emit(width, height, this);
270
+ // Updated before the signals, so that a resize handler reads the new orientation
205
271
  const orientation = width > height ? UIOrientation.HORIZONTAL : UIOrientation.VERTICAL;
206
- if (orientation !== this.orientationInternal) {
207
- this.orientationInternal = orientation;
272
+ const orientationChanged = orientation !== this.orientationInternal;
273
+ this.orientationInternal = orientation;
274
+ this.signalResizedInternal.emit(width, height, this);
275
+ if (orientationChanged) {
208
276
  this.signalOrientationChangedInternal.emit(this.orientationInternal, this);
209
277
  }
210
278
  }
@@ -212,6 +280,13 @@ export class UILayer {
212
280
  if (this.destroyedInternal) {
213
281
  return;
214
282
  }
283
+ // While the context is lost the frame is skipped as a whole: elements compare versions, so
284
+ // nothing changed meanwhile is lost once drawing resumes
285
+ const contextMonitor = UIContextMonitor.for(renderer);
286
+ this.bindContextMonitor(contextMonitor);
287
+ if (contextMonitor.lost) {
288
+ return;
289
+ }
215
290
  if (isUIModeVisible(this.mode)) {
216
291
  this.signalRenderingInternal.emit(renderer, deltaTime, this);
217
292
  if (this.destroyed) {
@@ -219,8 +294,26 @@ export class UILayer {
219
294
  }
220
295
  this.sceneWrapperInternal.render(renderer);
221
296
  }
222
- this.solverWrapperInternal.dirty = false;
223
- this.inputWrapperInternal.dirty = false;
297
+ }
298
+ /**
299
+ * Cancels every pressed pointer, for its elements and for the layer: no release of those
300
+ * pointers will be reported.
301
+ */
302
+ cancelPointers() {
303
+ this.inputWrapperInternal.cancelPointers((x, y, identifier) => {
304
+ this.reportPointerCancelledByLayer(x, y, identifier);
305
+ });
306
+ }
307
+ /** Follows the context of the renderer the layer is drawn with; null to stop following */
308
+ bindContextMonitor(monitor) {
309
+ if (monitor === this.contextMonitor) {
310
+ return;
311
+ }
312
+ this.contextMonitor?.signalLost.off(this.onContextLost);
313
+ this.contextMonitor?.signalRestored.off(this.onContextRestored);
314
+ this.contextMonitor = monitor;
315
+ monitor?.signalLost.on(this.onContextLost);
316
+ monitor?.signalRestored.on(this.onContextRestored);
224
317
  }
225
318
  /** A removal signal handler may destroy other constraints, so the registry is walked over a copy */
226
319
  destroyConstraints(predicate) {
@@ -0,0 +1,27 @@
1
+ import type { UIResizePolicy } from "../../miscellaneous/resize-policy/UIResizePolicy.js";
2
+ import { UIResizePolicyNone } from "../../miscellaneous/resize-policy/UIResizePolicyNone.js";
3
+ import type { UIViewport } from "../../miscellaneous/viewport/UIViewport.js";
4
+ import type { UILayerOptions } from "../UILayer/UILayer.Internal.js";
5
+ import type { UIViewportLayer } from "./UIViewportLayer.js";
6
+ /** Viewport layer input event data */
7
+ export interface UIViewportLayerInputEventData {
8
+ /** X coordinate */
9
+ x: number;
10
+ /** Y coordinate */
11
+ y: number;
12
+ /** Pointer identifier */
13
+ identifier: number;
14
+ /** Layer that emitted the event */
15
+ layer: UIViewportLayer;
16
+ }
17
+ /** Configuration for viewport layer */
18
+ export interface UIViewportLayerOptions extends Omit<UILayerOptions, "width" | "height"> {
19
+ /** Strategy for scaling the viewport size to the layer size */
20
+ resizePolicy: UIResizePolicy;
21
+ /**
22
+ * Part of the page the layer covers; the whole window by default. A viewport passed here
23
+ * belongs to the caller and is not destroyed with the layer.
24
+ */
25
+ viewport: UIViewport;
26
+ }
27
+ export declare const VIEWPORT_LAYER_DEFAULT_RESIZE_POLICY: UIResizePolicyNone;
@@ -1,2 +1,2 @@
1
1
  import { UIResizePolicyNone } from "../../miscellaneous/resize-policy/UIResizePolicyNone.js";
2
- export const FULLSCREEN_LAYER_DEFAULT_RESIZE_POLICY = new UIResizePolicyNone();
2
+ export const VIEWPORT_LAYER_DEFAULT_RESIZE_POLICY = new UIResizePolicyNone();
@@ -0,0 +1,98 @@
1
+ import type { FerrsignView1 } from "ferrsign";
2
+ import type { Camera, Vector2, WebGLRenderer } from "three";
3
+ import { Ray, Vector3 } from "three";
4
+ import type { UIResizePolicy } from "../../miscellaneous/resize-policy/UIResizePolicy.js";
5
+ import type { UIViewport } from "../../miscellaneous/viewport/UIViewport.js";
6
+ import { UILayer } from "../UILayer/UILayer.js";
7
+ import type { UIViewportLayerInputEventData, UIViewportLayerOptions } from "./UIViewportLayer.Internal.js";
8
+ /**
9
+ * Layer covering a part of the page given by its viewport, the whole window by default. Follows
10
+ * the viewport size through the resize policy and takes pointer input from the window, relative
11
+ * to the viewport.
12
+ */
13
+ export declare class UIViewportLayer extends UILayer {
14
+ private readonly viewportInternal;
15
+ private readonly ownsViewport;
16
+ private resizePolicyInternal;
17
+ /** Policy version the layer was last sized by; -1 forces a resize */
18
+ private appliedPolicyVersion;
19
+ /** Pointers the layer cancelled while pressed: their late release is not reported */
20
+ private readonly abandonedPointers;
21
+ private readonly signalPointerPressedInternal;
22
+ private readonly signalPointerMovedInternal;
23
+ private readonly signalPointerReleasedInternal;
24
+ private readonly signalPointerCancelledInternal;
25
+ constructor(options?: Partial<UIViewportLayerOptions>);
26
+ /** Part of the page the layer covers */
27
+ get viewport(): UIViewport;
28
+ /** Current resize policy */
29
+ get resizePolicy(): UIResizePolicy;
30
+ /** Signal fired when pointer is pressed */
31
+ get signalPointerPressed(): FerrsignView1<UIViewportLayerInputEventData>;
32
+ /** Signal fired when pointer is moved */
33
+ get signalPointerMoved(): FerrsignView1<UIViewportLayerInputEventData>;
34
+ /** Signal fired when pointer is released */
35
+ get signalPointerReleased(): FerrsignView1<UIViewportLayerInputEventData>;
36
+ /**
37
+ * Signal fired when a pressed pointer is cancelled and no release follows: by the browser (a
38
+ * system gesture, scrolling, a popup), or by the layer when the page is hidden or the window
39
+ * loses focus, since the browser may then never report the release. The position is the last
40
+ * known one and may be meaningless.
41
+ */
42
+ get signalPointerCancelled(): FerrsignView1<UIViewportLayerInputEventData>;
43
+ /** Updates resize policy */
44
+ set resizePolicy(value: UIResizePolicy);
45
+ /**
46
+ * Removes event listeners and destroys the layer with its elements and constraints. The
47
+ * viewport is destroyed too, unless it was passed in the options.
48
+ */
49
+ destroy(): void;
50
+ /**
51
+ * Renders layer and all visible elements
52
+ * @param renderer Three.js WebGL renderer
53
+ * @param deltaTime Time since last frame in seconds
54
+ */
55
+ render(renderer: WebGLRenderer, deltaTime: number): void;
56
+ /**
57
+ * Projects 3D world position to 2D layer coordinates
58
+ * @param position World position
59
+ * @param camera Three.js camera
60
+ * @param result Reusable vector instance
61
+ * @returns Layer coordinates
62
+ */
63
+ projectWorldPosition(position: Vector3, camera: Camera, result?: Vector3): Vector3;
64
+ /**
65
+ * Projects 2D layer coordinates to 3D world position
66
+ * @param position Layer coordinates
67
+ * @param camera Three.js camera
68
+ * @param z Depth coordinate
69
+ * @param result Reusable vector instance
70
+ * @returns World position
71
+ */
72
+ projectLayerPosition(position: Vector2, camera: Camera, z?: number, result?: Vector3): Vector3;
73
+ /**
74
+ * Builds ray from layer position through camera
75
+ * @param position Layer coordinates
76
+ * @param camera Three.js camera
77
+ * @param result Reusable ray instance
78
+ * @returns Ray from near to far plane
79
+ */
80
+ buildRay(position: Vector2, camera: Camera, result?: Ray): Ray;
81
+ protected reportPointerCancelledByLayer(x: number, y: number, identifier: number): void;
82
+ private readonly onResize;
83
+ /**
84
+ * The release of a pointer pressed when the page is hidden or the window loses focus is often
85
+ * never reported, leaving it captured: such pointers are cancelled right away
86
+ */
87
+ private readonly onFocusLost;
88
+ private readonly onVisibilityChange;
89
+ private readonly onPointerDown;
90
+ private readonly onPointerMove;
91
+ private readonly onPointerUp;
92
+ private readonly onPointerCancel;
93
+ /**
94
+ * Fires the layer signal of a window pointer event, if the layer takes input
95
+ * @returns Position in layer coordinates, to pass on to the elements; null if ignored
96
+ */
97
+ private reportPointer;
98
+ }
@@ -0,0 +1,251 @@
1
+ import { Ferrsign1 } from "ferrsign";
2
+ import { MathUtils, Ray, Vector3 } from "three";
3
+ import { assertValidNumber } from "../../miscellaneous/asserts.js";
4
+ import { isUIModeInteractive } from "../../miscellaneous/UIMode.js";
5
+ import { UIWindowViewport } from "../../miscellaneous/viewport/UIWindowViewport.js";
6
+ import { UILayer } from "../UILayer/UILayer.js";
7
+ import { VIEWPORT_LAYER_DEFAULT_RESIZE_POLICY } from "./UIViewportLayer.Internal.js";
8
+ const TEMP_RAY_NEAR = new Vector3();
9
+ const TEMP_RAY_FAR = new Vector3();
10
+ /**
11
+ * Layer covering a part of the page given by its viewport, the whole window by default. Follows
12
+ * the viewport size through the resize policy and takes pointer input from the window, relative
13
+ * to the viewport.
14
+ */
15
+ export class UIViewportLayer extends UILayer {
16
+ constructor(options) {
17
+ const resizePolicy = options?.resizePolicy ?? VIEWPORT_LAYER_DEFAULT_RESIZE_POLICY;
18
+ const viewport = options?.viewport ?? new UIWindowViewport();
19
+ if (viewport.destroyed) {
20
+ throw new Error("UIViewportLayer.constructor.options.viewport: viewport is destroyed");
21
+ }
22
+ // A viewport not laid out yet has no size: the layer starts with the default one and
23
+ // resizes once the viewport gets its size
24
+ const hasSize = viewport.width > 0 && viewport.height > 0;
25
+ const scale = hasSize ? resizePolicy.calculateScale(viewport.width, viewport.height) : 1;
26
+ super({
27
+ ...(hasSize ? { width: viewport.width * scale, height: viewport.height * scale } : {}),
28
+ ...options,
29
+ });
30
+ /** Pointers the layer cancelled while pressed: their late release is not reported */
31
+ this.abandonedPointers = new Set();
32
+ this.signalPointerPressedInternal = new Ferrsign1();
33
+ this.signalPointerMovedInternal = new Ferrsign1();
34
+ this.signalPointerReleasedInternal = new Ferrsign1();
35
+ this.signalPointerCancelledInternal = new Ferrsign1();
36
+ this.onResize = () => {
37
+ const { width, height } = this.viewportInternal;
38
+ if (width <= 0 || height <= 0) {
39
+ // Hidden or not laid out: keep the last size until the viewport gets one. Input is
40
+ // ignored meanwhile, so a press held now would never end
41
+ this.cancelPointers();
42
+ return;
43
+ }
44
+ const scale = this.resizePolicy.calculateScale(width, height);
45
+ this.appliedPolicyVersion = this.resizePolicy.version;
46
+ this.resizeInternal(width * scale, height * scale);
47
+ };
48
+ /**
49
+ * The release of a pointer pressed when the page is hidden or the window loses focus is often
50
+ * never reported, leaving it captured: such pointers are cancelled right away
51
+ */
52
+ this.onFocusLost = () => {
53
+ this.cancelPointers();
54
+ };
55
+ this.onVisibilityChange = () => {
56
+ if (document.visibilityState === "hidden") {
57
+ this.onFocusLost();
58
+ }
59
+ };
60
+ this.onPointerDown = (event) => {
61
+ this.abandonedPointers.delete(event.pointerId);
62
+ const position = this.reportPointer(event, this.signalPointerPressedInternal);
63
+ if (position !== null) {
64
+ this.inputWrapperInternal.onPointerDown(position.x, position.y, event.pointerId);
65
+ }
66
+ };
67
+ this.onPointerMove = (event) => {
68
+ // A cancelled press stays cancelled until it ends: its moves would bring it back over the
69
+ // elements, while its release is not reported. A move with no button down means the press
70
+ // ended unseen, as when released outside the window
71
+ if (this.abandonedPointers.has(event.pointerId)) {
72
+ if (event.buttons !== 0) {
73
+ return;
74
+ }
75
+ this.abandonedPointers.delete(event.pointerId);
76
+ }
77
+ const position = this.reportPointer(event, this.signalPointerMovedInternal);
78
+ if (position !== null) {
79
+ this.inputWrapperInternal.onPointerMove(position.x, position.y, event.pointerId);
80
+ }
81
+ };
82
+ this.onPointerUp = (event) => {
83
+ if (this.abandonedPointers.delete(event.pointerId)) {
84
+ return;
85
+ }
86
+ const position = this.reportPointer(event, this.signalPointerReleasedInternal);
87
+ if (position !== null) {
88
+ this.inputWrapperInternal.onPointerUp(position.x, position.y, event.pointerId);
89
+ }
90
+ };
91
+ this.onPointerCancel = (event) => {
92
+ if (this.abandonedPointers.delete(event.pointerId)) {
93
+ return;
94
+ }
95
+ if (this.reportPointer(event, this.signalPointerCancelledInternal) !== null) {
96
+ this.inputWrapperInternal.onPointerCancel(event.pointerId);
97
+ }
98
+ };
99
+ this.viewportInternal = viewport;
100
+ this.ownsViewport = options?.viewport === undefined;
101
+ this.resizePolicyInternal = resizePolicy;
102
+ this.appliedPolicyVersion = hasSize ? resizePolicy.version : -1;
103
+ viewport.signalResized.on(this.onResize);
104
+ window.addEventListener("pointerdown", this.onPointerDown);
105
+ window.addEventListener("pointermove", this.onPointerMove);
106
+ window.addEventListener("pointerup", this.onPointerUp);
107
+ window.addEventListener("pointercancel", this.onPointerCancel);
108
+ window.addEventListener("blur", this.onFocusLost);
109
+ document.addEventListener("visibilitychange", this.onVisibilityChange);
110
+ }
111
+ /** Part of the page the layer covers */
112
+ get viewport() {
113
+ return this.viewportInternal;
114
+ }
115
+ /** Current resize policy */
116
+ get resizePolicy() {
117
+ return this.resizePolicyInternal;
118
+ }
119
+ /** Signal fired when pointer is pressed */
120
+ get signalPointerPressed() {
121
+ return this.signalPointerPressedInternal;
122
+ }
123
+ /** Signal fired when pointer is moved */
124
+ get signalPointerMoved() {
125
+ return this.signalPointerMovedInternal;
126
+ }
127
+ /** Signal fired when pointer is released */
128
+ get signalPointerReleased() {
129
+ return this.signalPointerReleasedInternal;
130
+ }
131
+ /**
132
+ * Signal fired when a pressed pointer is cancelled and no release follows: by the browser (a
133
+ * system gesture, scrolling, a popup), or by the layer when the page is hidden or the window
134
+ * loses focus, since the browser may then never report the release. The position is the last
135
+ * known one and may be meaningless.
136
+ */
137
+ get signalPointerCancelled() {
138
+ return this.signalPointerCancelledInternal;
139
+ }
140
+ /** Updates resize policy */
141
+ set resizePolicy(value) {
142
+ if (this.resizePolicyInternal !== value) {
143
+ this.resizePolicyInternal = value;
144
+ this.appliedPolicyVersion = -1;
145
+ }
146
+ }
147
+ /**
148
+ * Removes event listeners and destroys the layer with its elements and constraints. The
149
+ * viewport is destroyed too, unless it was passed in the options.
150
+ */
151
+ destroy() {
152
+ if (this.destroyed) {
153
+ return;
154
+ }
155
+ this.viewportInternal.signalResized.off(this.onResize);
156
+ if (this.ownsViewport) {
157
+ this.viewportInternal.destroy();
158
+ }
159
+ window.removeEventListener("pointerdown", this.onPointerDown);
160
+ window.removeEventListener("pointermove", this.onPointerMove);
161
+ window.removeEventListener("pointerup", this.onPointerUp);
162
+ window.removeEventListener("pointercancel", this.onPointerCancel);
163
+ window.removeEventListener("blur", this.onFocusLost);
164
+ document.removeEventListener("visibilitychange", this.onVisibilityChange);
165
+ this.abandonedPointers.clear();
166
+ super.destroy();
167
+ }
168
+ /**
169
+ * Renders layer and all visible elements
170
+ * @param renderer Three.js WebGL renderer
171
+ * @param deltaTime Time since last frame in seconds
172
+ */
173
+ render(renderer, deltaTime) {
174
+ assertValidNumber(deltaTime, "UIViewportLayer.render.deltaTime");
175
+ if (this.destroyed) {
176
+ return;
177
+ }
178
+ if (this.resizePolicy.version !== this.appliedPolicyVersion) {
179
+ this.onResize();
180
+ }
181
+ super.renderInternal(renderer, deltaTime);
182
+ }
183
+ /**
184
+ * Projects 3D world position to 2D layer coordinates
185
+ * @param position World position
186
+ * @param camera Three.js camera
187
+ * @param result Reusable vector instance
188
+ * @returns Layer coordinates
189
+ */
190
+ projectWorldPosition(position, camera, result = new Vector3()) {
191
+ result.copy(position).project(camera);
192
+ result.x = MathUtils.mapLinear(result.x, -1, 1, this.x, this.oppositeX);
193
+ result.y = MathUtils.mapLinear(result.y, -1, 1, this.y, this.oppositeY);
194
+ return result;
195
+ }
196
+ /**
197
+ * Projects 2D layer coordinates to 3D world position
198
+ * @param position Layer coordinates
199
+ * @param camera Three.js camera
200
+ * @param z Depth coordinate
201
+ * @param result Reusable vector instance
202
+ * @returns World position
203
+ */
204
+ projectLayerPosition(position, camera, z = -1, result = new Vector3()) {
205
+ return result
206
+ .set(MathUtils.mapLinear(position.x, this.x, this.oppositeX, -1, 1), MathUtils.mapLinear(position.y, this.y, this.oppositeY, -1, 1), z)
207
+ .unproject(camera);
208
+ }
209
+ /**
210
+ * Builds ray from layer position through camera
211
+ * @param position Layer coordinates
212
+ * @param camera Three.js camera
213
+ * @param result Reusable ray instance
214
+ * @returns Ray from near to far plane
215
+ */
216
+ buildRay(position, camera, result = new Ray()) {
217
+ const near = this.projectLayerPosition(position, camera, -1, TEMP_RAY_NEAR);
218
+ const far = this.projectLayerPosition(position, camera, 1, TEMP_RAY_FAR);
219
+ return result.set(near, far.sub(near).normalize());
220
+ }
221
+ reportPointerCancelledByLayer(x, y, identifier) {
222
+ this.abandonedPointers.add(identifier);
223
+ this.signalPointerCancelledInternal.emit({ x, y, identifier, layer: this });
224
+ }
225
+ /**
226
+ * Fires the layer signal of a window pointer event, if the layer takes input
227
+ * @returns Position in layer coordinates, to pass on to the elements; null if ignored
228
+ */
229
+ reportPointer(event, signal) {
230
+ // Relative to the viewport, not to event.target: an HTML element over the canvas (a store
231
+ // button, an ad network overlay) would shift the position by its own offset
232
+ const viewport = this.viewportInternal;
233
+ if (viewport.width <= 0 || viewport.height <= 0 || !isUIModeInteractive(this.mode)) {
234
+ return null;
235
+ }
236
+ // A new object: a signal handler may cause another pointer event before it is passed on
237
+ const position = viewport.toLocal(event.clientX, event.clientY, { x: 0, y: 0 });
238
+ // Reading the box may have resized the viewport
239
+ if (viewport.width <= 0 || viewport.height <= 0) {
240
+ return null;
241
+ }
242
+ position.x *= this.width / viewport.width;
243
+ position.y *= this.height / viewport.height;
244
+ signal.emit({ x: position.x, y: position.y, identifier: event.pointerId, layer: this });
245
+ // A handler may have turned input off or destroyed the layer
246
+ if (this.destroyed || !isUIModeInteractive(this.mode)) {
247
+ return null;
248
+ }
249
+ return position;
250
+ }
251
+ }