laymur 0.16.0 → 0.17.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/.claude/settings.local.json +9 -0
- package/.editorconfig +14 -0
- package/CLAUDE.md +181 -0
- package/README.md +84 -208
- package/assets/logotype.png +0 -0
- package/eslint.config.js +111 -0
- package/package.json +20 -36
- package/rollup.config.js +52 -0
- package/{dist/constraints/UIAspectConstraint/UIAspectConstraint.Internal.d.ts → src/core/constraints/UIAspectConstraint/UIAspectConstraint.Internal.ts} +3 -2
- package/src/core/constraints/UIAspectConstraint/UIAspectConstraint.ts +60 -0
- package/src/core/constraints/UIConstraint.ts +20 -0
- package/src/core/constraints/UICustomConstraint.ts +62 -0
- package/{dist/constraints/UIHeightConstraint/UIHeightConstraint.Internal.d.ts → src/core/constraints/UIHeightConstraint/UIHeightConstraint.Internal.ts} +3 -2
- package/src/core/constraints/UIHeightConstraint/UIHeightConstraint.ts +52 -0
- package/src/core/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.Internal.ts +13 -0
- package/src/core/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.ts +139 -0
- package/src/core/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.Internal.ts +16 -0
- package/src/core/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.ts +189 -0
- package/{dist/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.Internal.d.ts → src/core/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.Internal.ts} +3 -2
- package/src/core/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.ts +68 -0
- package/{dist/constraints/UISingleParameterConstraint/UISingleParameterConstraint.Internal.d.ts → src/core/constraints/UISingleParameterConstraint/UISingleParameterConstraint.Internal.ts} +9 -8
- package/src/core/constraints/UISingleParameterConstraint/UISingleParameterConstraint.ts +94 -0
- package/src/core/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.Internal.ts +13 -0
- package/src/core/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.ts +135 -0
- package/src/core/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.Internal.ts +16 -0
- package/src/core/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.ts +189 -0
- package/{dist/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.Internal.d.ts → src/core/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.Internal.ts} +3 -2
- package/src/core/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.ts +68 -0
- package/{dist/constraints/UIWidthConstraint/UIWidthConstraint.Internal.d.ts → src/core/constraints/UIWidthConstraint/UIWidthConstraint.Internal.ts} +3 -2
- package/src/core/constraints/UIWidthConstraint/UIWidthConstraint.ts +52 -0
- package/src/core/constraints/builders/UIConstraint2DBuilder.Internal.ts +84 -0
- package/src/core/constraints/builders/UIConstraint2DBuilder.ts +168 -0
- package/src/core/constraints/builders/UICoverConstraintBuilder.Internal.ts +15 -0
- package/src/core/constraints/builders/UICoverConstraintBuilder.ts +84 -0
- package/src/core/constraints/builders/UIFitConstraintBuilder.Internal.ts +15 -0
- package/src/core/constraints/builders/UIFitConstraintBuilder.ts +84 -0
- package/src/core/elements/UIAnchor/UIAnchor.Internal.ts +13 -0
- package/src/core/elements/UIAnchor/UIAnchor.ts +70 -0
- package/src/core/elements/UIAnimatedImage/UIAnimatedImage.Internal.ts +30 -0
- package/src/core/elements/UIAnimatedImage/UIAnimatedImage.ts +355 -0
- package/src/core/elements/UIDummy/UIDummy.Internal.ts +33 -0
- package/src/core/elements/UIDummy/UIDummy.ts +244 -0
- package/{dist/elements/UIElement/UIElement.Internal.d.ts → src/core/elements/UIElement/UIElement.Internal.ts} +7 -5
- package/src/core/elements/UIElement/UIElement.ts +127 -0
- package/{dist/elements/UIGraphics/UIGraphics.Internal.d.ts → src/core/elements/UIGraphics/UIGraphics.Internal.ts} +7 -5
- package/src/core/elements/UIGraphics/UIGraphics.ts +168 -0
- package/{dist/elements/UIImage/UIImage.Internal.d.ts → src/core/elements/UIImage/UIImage.Internal.ts} +3 -2
- package/src/core/elements/UIImage/UIImage.ts +138 -0
- package/src/core/elements/UINineSlice/UINineSlice.Internal.ts +26 -0
- package/src/core/elements/UINineSlice/UINineSlice.ts +296 -0
- package/src/core/elements/UIProgress/UIProgress.Internal.ts +24 -0
- package/src/core/elements/UIProgress/UIProgress.ts +259 -0
- package/src/core/elements/UIScene/UIScene.Internal.ts +46 -0
- package/src/core/elements/UIScene/UIScene.ts +259 -0
- package/{dist/elements/UIText/UIText.Interfaces.d.ts → src/core/elements/UIText/UIText.Interfaces.ts} +21 -16
- package/src/core/elements/UIText/UIText.Internal.ts +29 -0
- package/src/core/elements/UIText/UIText.Measuring.ts +183 -0
- package/src/core/elements/UIText/UIText.Rendering.ts +83 -0
- package/src/core/elements/UIText/UIText.ts +376 -0
- package/{dist/layers/UIFullscreenLayer/UIFullscreenLayer.Internal.d.ts → src/core/layers/UIFullscreenLayer/UIFullscreenLayer.Internal.ts} +14 -11
- package/src/core/layers/UIFullscreenLayer/UIFullscreenLayer.ts +233 -0
- package/{dist/layers/UILayer/UILayer.Internal.d.ts → src/core/layers/UILayer/UILayer.Internal.ts} +15 -11
- package/src/core/layers/UILayer/UILayer.ts +156 -0
- package/src/core/miscellaneous/UIExpression.ts +142 -0
- package/src/core/miscellaneous/UIMode.ts +29 -0
- package/src/core/miscellaneous/UIOrientation.ts +18 -0
- package/src/core/miscellaneous/UIPriority.ts +63 -0
- package/src/core/miscellaneous/UIRelation.ts +39 -0
- package/src/core/miscellaneous/UITransparencyMode.ts +9 -0
- package/src/core/miscellaneous/area/UIArea.ts +5 -0
- package/src/core/miscellaneous/area/UIAreaCircle.ts +32 -0
- package/src/core/miscellaneous/area/UIAreaPolygon.ts +50 -0
- package/src/core/miscellaneous/area/UIAreaRectangle.ts +38 -0
- package/src/core/miscellaneous/area/UIAreaRoundedRectangle.ts +78 -0
- package/src/core/miscellaneous/asserts.ts +187 -0
- package/src/core/miscellaneous/canvas.ts +73 -0
- package/src/core/miscellaneous/color/UIColor.Internal.ts +89 -0
- package/src/core/miscellaneous/color/UIColor.ts +844 -0
- package/src/core/miscellaneous/computeTransform.ts +127 -0
- package/src/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Internal.ts +235 -0
- package/src/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.ts +524 -0
- package/{dist/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.Internal.d.ts → src/core/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.Internal.ts} +10 -8
- package/src/core/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.ts +448 -0
- package/src/core/miscellaneous/generic-plane/shared.ts +323 -0
- package/src/core/miscellaneous/insets/UIInsets.Internal.ts +9 -0
- package/src/core/miscellaneous/insets/UIInsets.ts +248 -0
- package/src/core/miscellaneous/mask-function/UIProgressMaskFunction.ts +24 -0
- package/src/core/miscellaneous/mask-function/UIProgressMaskFunctionCircular.ts +58 -0
- package/src/core/miscellaneous/mask-function/UIProgressMaskFunctionDirectional.ts +52 -0
- package/src/core/miscellaneous/math.ts +16 -0
- package/src/core/miscellaneous/micro/UIMicro.Internal.ts +33 -0
- package/src/core/miscellaneous/micro/UIMicro.ts +222 -0
- package/src/core/miscellaneous/resize-policy/UIResizePolicy.ts +8 -0
- package/src/core/miscellaneous/resize-policy/UIResizePolicyCover.ts +57 -0
- package/src/core/miscellaneous/resize-policy/UIResizePolicyCross.ts +65 -0
- package/src/core/miscellaneous/resize-policy/UIResizePolicyCrossInverted.ts +65 -0
- package/src/core/miscellaneous/resize-policy/UIResizePolicyFit.ts +57 -0
- package/src/core/miscellaneous/resize-policy/UIResizePolicyFixedHeight.ts +65 -0
- package/src/core/miscellaneous/resize-policy/UIResizePolicyFixedWidth.ts +65 -0
- package/src/core/miscellaneous/resize-policy/UIResizePolicyNone.ts +11 -0
- package/src/core/miscellaneous/shared.ts +73 -0
- package/{dist/miscellaneous/text-span/UITextSpan.Internal.d.ts → src/core/miscellaneous/text-span/UITextSpan.Internal.ts} +5 -4
- package/src/core/miscellaneous/text-span/UITextSpan.ts +43 -0
- package/src/core/miscellaneous/text-style/UITextStyle.Internal.ts +52 -0
- package/src/core/miscellaneous/text-style/UITextStyle.ts +479 -0
- package/src/core/miscellaneous/texture/UITextureView.Internal.ts +55 -0
- package/src/core/miscellaneous/texture/UITextureView.ts +308 -0
- package/src/core/miscellaneous/webglCapabilities.ts +129 -0
- package/src/core/shaders/UIImage.glsl +10 -0
- package/src/core/shaders/UINineSlice.glsl +53 -0
- package/src/core/shaders/UIProgress.glsl +15 -0
- package/src/core/shaders/UIProgressMaskFunctionCircular.glsl +13 -0
- package/src/core/shaders/UIProgressMaskFunctionDirectional.glsl +12 -0
- package/src/core/shaders/glsl.d.ts +27 -0
- package/src/core/wrappers/UIInputWrapper/UIInputWrapper.Internal.ts +23 -0
- package/src/core/wrappers/UIInputWrapper/UIInputWrapper.ts +124 -0
- package/src/core/wrappers/UISceneWrapper/UISceneWrapper.Internal.ts +22 -0
- package/src/core/wrappers/UISceneWrapper/UISceneWrapper.ts +101 -0
- package/src/core/wrappers/UISolverWrapper/UISolverWrapper.Internal.ts +58 -0
- package/src/core/wrappers/UISolverWrapper/UISolverWrapper.ts +605 -0
- package/src/particles/behaviorModules/UIBehaviorDirectionalGravity.ts +70 -0
- package/src/particles/behaviorModules/UIBehaviorModule.ts +20 -0
- package/src/particles/behaviorModules/UIBehaviorPointGravity.ts +173 -0
- package/src/particles/behaviorModules/UIBehaviorScaleOverLife.ts +104 -0
- package/src/particles/behaviorModules/UIBehaviorTorqueDamping.ts +75 -0
- package/src/particles/behaviorModules/UIBehaviorTorqueNoise.ts +115 -0
- package/src/particles/behaviorModules/UIBehaviorVelocityDamping.ts +77 -0
- package/src/particles/behaviorModules/UIBehaviorVelocityNoise.ts +118 -0
- package/src/particles/elements/UIEmitter.Internal.ts +22 -0
- package/src/particles/elements/UIEmitter.ts +313 -0
- package/src/particles/index.ts +18 -0
- package/src/particles/instancedParticle/UIInstancedParticle.Internal.ts +263 -0
- package/src/particles/instancedParticle/UIInstancedParticle.ts +138 -0
- package/src/particles/miscellaneous/miscellaneous.ts +115 -0
- package/src/particles/renderingModules/UIRenderingColorOverLife.ts +39 -0
- package/src/particles/renderingModules/UIRenderingColorOverVelocity.ts +49 -0
- package/src/particles/renderingModules/UIRenderingModule.ts +17 -0
- package/src/particles/renderingModules/UIRenderingTexture.ts +30 -0
- package/src/particles/shaders/UIRenderingColorOverLife.glsl +4 -0
- package/src/particles/shaders/UIRenderingColorOverVelocity.glsl +6 -0
- package/src/particles/shaders/UIRenderingTexture.glsl +4 -0
- package/src/particles/spawnModules/UISpawnModule.ts +22 -0
- package/src/particles/spawnModules/UISpawnOffset.ts +62 -0
- package/src/particles/spawnModules/UISpawnRandomLifetime.ts +68 -0
- package/src/particles/spawnModules/UISpawnRandomRotation.ts +60 -0
- package/src/particles/spawnModules/UISpawnRandomScale.ts +81 -0
- package/src/particles/spawnModules/UISpawnRandomTorque.ts +62 -0
- package/src/particles/spawnModules/UISpawnRandomVelocity.ts +92 -0
- package/src/particles/spawnModules/UISpawnRectangle.ts +81 -0
- package/tsconfig.json +29 -0
- package/dist/constraints/UIAspectConstraint/UIAspectConstraint.d.ts +0 -22
- package/dist/constraints/UIConstraint.d.ts +0 -12
- package/dist/constraints/UICustomConstraint.d.ts +0 -28
- package/dist/constraints/UIHeightConstraint/UIHeightConstraint.d.ts +0 -20
- package/dist/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.Internal.d.ts +0 -11
- package/dist/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.d.ts +0 -36
- package/dist/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.Internal.d.ts +0 -14
- package/dist/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.d.ts +0 -44
- package/dist/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.d.ts +0 -22
- package/dist/constraints/UISingleParameterConstraint/UISingleParameterConstraint.d.ts +0 -43
- package/dist/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.Internal.d.ts +0 -11
- package/dist/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.d.ts +0 -32
- package/dist/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.Internal.d.ts +0 -14
- package/dist/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.d.ts +0 -44
- package/dist/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.d.ts +0 -22
- package/dist/constraints/UIWidthConstraint/UIWidthConstraint.d.ts +0 -20
- package/dist/constraints/builders/UIConstraint2DBuilder.Internal.d.ts +0 -64
- package/dist/constraints/builders/UIConstraint2DBuilder.d.ts +0 -46
- package/dist/constraints/builders/UICoverConstraintBuilder.Internal.d.ts +0 -13
- package/dist/constraints/builders/UICoverConstraintBuilder.d.ts +0 -29
- package/dist/constraints/builders/UIFitConstraintBuilder.Internal.d.ts +0 -13
- package/dist/constraints/builders/UIFitConstraintBuilder.d.ts +0 -29
- package/dist/elements/UIAnchor/UIAnchor.Internal.d.ts +0 -9
- package/dist/elements/UIAnchor/UIAnchor.d.ts +0 -32
- package/dist/elements/UIAnimatedImage/UIAnimatedImage.Internal.d.ts +0 -27
- package/dist/elements/UIAnimatedImage/UIAnimatedImage.d.ts +0 -77
- package/dist/elements/UIDummy/UIDummy.Internal.d.ts +0 -30
- package/dist/elements/UIDummy/UIDummy.d.ts +0 -82
- package/dist/elements/UIElement/UIElement.d.ts +0 -38
- package/dist/elements/UIGraphics/UIGraphics.d.ts +0 -51
- package/dist/elements/UIImage/UIImage.d.ts +0 -32
- package/dist/elements/UINineSlice/UINineSlice.Internal.d.ts +0 -23
- package/dist/elements/UINineSlice/UINineSlice.d.ts +0 -60
- package/dist/elements/UIProgress/UIProgress.Internal.d.ts +0 -14
- package/dist/elements/UIProgress/UIProgress.d.ts +0 -45
- package/dist/elements/UIScene/UIScene.Internal.d.ts +0 -43
- package/dist/elements/UIScene/UIScene.d.ts +0 -59
- package/dist/elements/UIText/UIText.Internal.d.ts +0 -26
- package/dist/elements/UIText/UIText.Measuring.d.ts +0 -50
- package/dist/elements/UIText/UIText.Rendering.d.ts +0 -20
- package/dist/elements/UIText/UIText.d.ts +0 -71
- package/dist/index.js +0 -9246
- package/dist/index.js.map +0 -1
- package/dist/index.min.js +0 -2
- package/dist/index.min.js.map +0 -1
- package/dist/layers/UIFullscreenLayer/UIFullscreenLayer.d.ts +0 -63
- package/dist/layers/UILayer/UILayer.d.ts +0 -49
- package/dist/miscellaneous/UIExpression.d.ts +0 -69
- package/dist/miscellaneous/UIMode.d.ts +0 -23
- package/dist/miscellaneous/UIOrientation.d.ts +0 -15
- package/dist/miscellaneous/UIPriority.d.ts +0 -32
- package/dist/miscellaneous/UIRelation.d.ts +0 -23
- package/dist/miscellaneous/UITransparencyMode.d.ts +0 -9
- package/dist/miscellaneous/area/UIArea.d.ts +0 -3
- package/dist/miscellaneous/area/UIAreaCircle.d.ts +0 -15
- package/dist/miscellaneous/area/UIAreaPolygon.d.ts +0 -12
- package/dist/miscellaneous/area/UIAreaRectangle.d.ts +0 -17
- package/dist/miscellaneous/area/UIAreaRoundedRectangle.d.ts +0 -21
- package/dist/miscellaneous/asserts.d.ts +0 -43
- package/dist/miscellaneous/canvas.d.ts +0 -31
- package/dist/miscellaneous/color/UIColor.Internal.d.ts +0 -7
- package/dist/miscellaneous/color/UIColor.d.ts +0 -234
- package/dist/miscellaneous/computeTransform.d.ts +0 -18
- package/dist/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Internal.d.ts +0 -19
- package/dist/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.d.ts +0 -1
- package/dist/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.d.ts +0 -1
- package/dist/miscellaneous/generic-plane/shared.d.ts +0 -38
- package/dist/miscellaneous/insets/UIInsets.Internal.d.ts +0 -11
- package/dist/miscellaneous/insets/UIInsets.d.ts +0 -48
- package/dist/miscellaneous/mask-function/UIProgressMaskFunction.d.ts +0 -9
- package/dist/miscellaneous/mask-function/UIProgressMaskFunctionCircular.d.ts +0 -21
- package/dist/miscellaneous/mask-function/UIProgressMaskFunctionDirectional.d.ts +0 -16
- package/dist/miscellaneous/math.d.ts +0 -5
- package/dist/miscellaneous/micro/UIMicro.Internal.d.ts +0 -31
- package/dist/miscellaneous/micro/UIMicro.d.ts +0 -59
- package/dist/miscellaneous/resize-policy/UIResizePolicy.d.ts +0 -3
- package/dist/miscellaneous/resize-policy/UIResizePolicyCover.d.ts +0 -22
- package/dist/miscellaneous/resize-policy/UIResizePolicyCross.d.ts +0 -22
- package/dist/miscellaneous/resize-policy/UIResizePolicyCrossInverted.d.ts +0 -22
- package/dist/miscellaneous/resize-policy/UIResizePolicyFit.d.ts +0 -22
- package/dist/miscellaneous/resize-policy/UIResizePolicyFixedHeight.d.ts +0 -22
- package/dist/miscellaneous/resize-policy/UIResizePolicyFixedWidth.d.ts +0 -22
- package/dist/miscellaneous/resize-policy/UIResizePolicyNone.d.ts +0 -5
- package/dist/miscellaneous/shared.d.ts +0 -46
- package/dist/miscellaneous/text-span/UITextSpan.d.ts +0 -14
- package/dist/miscellaneous/text-style/UITextStyle.Internal.d.ts +0 -48
- package/dist/miscellaneous/text-style/UITextStyle.d.ts +0 -85
- package/dist/miscellaneous/texture/UITextureView.Internal.d.ts +0 -49
- package/dist/miscellaneous/texture/UITextureView.d.ts +0 -67
- package/dist/miscellaneous/webglCapabilities.d.ts +0 -2
- package/dist/wrappers/UIInputWrapper/UIInputWrapper.Internal.d.ts +0 -17
- package/dist/wrappers/UIInputWrapper/UIInputWrapper.d.ts +0 -13
- package/dist/wrappers/UISceneWrapper/UISceneWrapper.Internal.d.ts +0 -13
- package/dist/wrappers/UISceneWrapper/UISceneWrapper.d.ts +0 -20
- package/dist/wrappers/UISolverWrapper/UISolverWrapper.Internal.d.ts +0 -49
- package/dist/wrappers/UISolverWrapper/UISolverWrapper.d.ts +0 -215
- /package/{dist/index.d.ts → src/core/index.ts} +0 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import type { FerrsignView1 } from "ferrsign";
|
|
2
|
+
import { Ferrsign1 } from "ferrsign";
|
|
3
|
+
import type { Camera, Vector2, WebGLRenderer } from "three";
|
|
4
|
+
import { MathUtils, Ray, Vector3 } from "three";
|
|
5
|
+
import { assertValidNumber } from "../../miscellaneous/asserts";
|
|
6
|
+
import type { UIResizePolicy } from "../../miscellaneous/resize-policy/UIResizePolicy";
|
|
7
|
+
import { isUIModeInteractive } from "../../miscellaneous/UIMode";
|
|
8
|
+
import { UILayer } from "../UILayer/UILayer";
|
|
9
|
+
import type {
|
|
10
|
+
UIFullscreenLayerInputEventData,
|
|
11
|
+
UIFullscreenLayerOptions,
|
|
12
|
+
} from "./UIFullscreenLayer.Internal";
|
|
13
|
+
import { FULLSCREEN_LAYER_DEFAULT_RESIZE_POLICY } from "./UIFullscreenLayer.Internal";
|
|
14
|
+
|
|
15
|
+
/** Layer that automatically handles browser window resizing and input events */
|
|
16
|
+
export class UIFullscreenLayer extends UILayer {
|
|
17
|
+
private resizePolicyInternal: UIResizePolicy;
|
|
18
|
+
private resizePolicyDirty = false;
|
|
19
|
+
|
|
20
|
+
private readonly signalPointerPressedInternal =
|
|
21
|
+
new Ferrsign1<UIFullscreenLayerInputEventData>();
|
|
22
|
+
private readonly signalPointerMovedInternal =
|
|
23
|
+
new Ferrsign1<UIFullscreenLayerInputEventData>();
|
|
24
|
+
private readonly signalPointerReleasedInternal =
|
|
25
|
+
new Ferrsign1<UIFullscreenLayerInputEventData>();
|
|
26
|
+
|
|
27
|
+
constructor(options?: Partial<UIFullscreenLayerOptions>) {
|
|
28
|
+
const resizePolicy =
|
|
29
|
+
options?.resizePolicy ?? FULLSCREEN_LAYER_DEFAULT_RESIZE_POLICY;
|
|
30
|
+
|
|
31
|
+
const scale = resizePolicy.calculateScale(
|
|
32
|
+
window.innerWidth,
|
|
33
|
+
window.innerHeight,
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
super({
|
|
37
|
+
width: window.innerWidth * scale,
|
|
38
|
+
height: window.innerHeight * scale,
|
|
39
|
+
...options,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
this.resizePolicyInternal = resizePolicy;
|
|
43
|
+
window.addEventListener("resize", this.onResize);
|
|
44
|
+
window.addEventListener("pointerdown", this.onPointerDown);
|
|
45
|
+
window.addEventListener("pointermove", this.onPointerMove);
|
|
46
|
+
window.addEventListener("pointerup", this.onPointerUp);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Current resize policy */
|
|
50
|
+
public get resizePolicy(): UIResizePolicy {
|
|
51
|
+
return this.resizePolicyInternal;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Signal fired when pointer is pressed */
|
|
55
|
+
public get signalPointerPressed(): FerrsignView1<UIFullscreenLayerInputEventData> {
|
|
56
|
+
return this.signalPointerPressedInternal;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Signal fired when pointer is moved */
|
|
60
|
+
public get signalPointerMoved(): FerrsignView1<UIFullscreenLayerInputEventData> {
|
|
61
|
+
return this.signalPointerMovedInternal;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Signal fired when pointer is released */
|
|
65
|
+
public get signalPointerReleased(): FerrsignView1<UIFullscreenLayerInputEventData> {
|
|
66
|
+
return this.signalPointerReleasedInternal;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Updates resize policy */
|
|
70
|
+
public set resizePolicy(value: UIResizePolicy) {
|
|
71
|
+
if (this.resizePolicyInternal !== value) {
|
|
72
|
+
this.resizePolicyInternal = value;
|
|
73
|
+
this.resizePolicyDirty = true;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Removes event listeners and frees resources */
|
|
78
|
+
public destroy(): void {
|
|
79
|
+
window.removeEventListener("resize", this.onResize);
|
|
80
|
+
window.removeEventListener("pointerdown", this.onPointerDown);
|
|
81
|
+
window.removeEventListener("pointermove", this.onPointerMove);
|
|
82
|
+
window.removeEventListener("pointerup", this.onPointerUp);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Renders layer and all visible elements
|
|
87
|
+
* @param renderer Three.js WebGL renderer
|
|
88
|
+
* @param deltaTime Time since last frame in seconds
|
|
89
|
+
*/
|
|
90
|
+
public render(renderer: WebGLRenderer, deltaTime: number): void {
|
|
91
|
+
assertValidNumber(deltaTime, "UIFullscreenLayer.render.deltaTime");
|
|
92
|
+
if (this.resizePolicy.dirty || this.resizePolicyDirty) {
|
|
93
|
+
this.onResize();
|
|
94
|
+
}
|
|
95
|
+
super.renderInternal(renderer, deltaTime);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Projects 3D world position to 2D layer coordinates
|
|
100
|
+
* @param position World position
|
|
101
|
+
* @param camera Three.js camera
|
|
102
|
+
* @param result Reusable vector instance
|
|
103
|
+
* @returns Layer coordinates
|
|
104
|
+
*/
|
|
105
|
+
public projectWorldPosition(
|
|
106
|
+
position: Vector3,
|
|
107
|
+
camera: Camera,
|
|
108
|
+
result = new Vector3(),
|
|
109
|
+
): Vector3 {
|
|
110
|
+
result.copy(position).project(camera);
|
|
111
|
+
result.x = MathUtils.mapLinear(result.x, -1, 1, this.x, this.width);
|
|
112
|
+
result.y = MathUtils.mapLinear(result.y, -1, 1, this.y, this.height);
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Projects 2D layer coordinates to 3D world position
|
|
118
|
+
* @param position Layer coordinates
|
|
119
|
+
* @param camera Three.js camera
|
|
120
|
+
* @param z Depth coordinate
|
|
121
|
+
* @param result Reusable vector instance
|
|
122
|
+
* @returns World position
|
|
123
|
+
*/
|
|
124
|
+
public projectLayerPosition(
|
|
125
|
+
position: Vector2,
|
|
126
|
+
camera: Camera,
|
|
127
|
+
z = -1,
|
|
128
|
+
result = new Vector3(),
|
|
129
|
+
): Vector3 {
|
|
130
|
+
return result
|
|
131
|
+
.set(
|
|
132
|
+
MathUtils.mapLinear(position.x, this.x, this.width, -1, 1),
|
|
133
|
+
MathUtils.mapLinear(position.y, this.y, this.height, -1, 1),
|
|
134
|
+
z,
|
|
135
|
+
)
|
|
136
|
+
.unproject(camera);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Builds ray from layer position through camera
|
|
141
|
+
* @param position Layer coordinates
|
|
142
|
+
* @param camera Three.js camera
|
|
143
|
+
* @param result Reusable ray instance
|
|
144
|
+
* @returns Ray from near to far plane
|
|
145
|
+
*/
|
|
146
|
+
public buildRay(position: Vector2, camera: Camera, result = new Ray()): Ray {
|
|
147
|
+
const near = new Vector3(
|
|
148
|
+
MathUtils.mapLinear(position.x, this.x, this.width, -1, 1),
|
|
149
|
+
MathUtils.mapLinear(position.y, this.y, this.height, -1, 1),
|
|
150
|
+
-1,
|
|
151
|
+
).unproject(camera);
|
|
152
|
+
|
|
153
|
+
const far = new Vector3(
|
|
154
|
+
MathUtils.mapLinear(position.x, this.x, this.width, -1, 1),
|
|
155
|
+
MathUtils.mapLinear(position.y, this.y, this.height, -1, 1),
|
|
156
|
+
1,
|
|
157
|
+
).unproject(camera);
|
|
158
|
+
|
|
159
|
+
const direction = far.sub(near).normalize();
|
|
160
|
+
return result.set(near, direction);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
private readonly onResize = (): void => {
|
|
164
|
+
const scale = this.resizePolicy.calculateScale(
|
|
165
|
+
window.innerWidth,
|
|
166
|
+
window.innerHeight,
|
|
167
|
+
);
|
|
168
|
+
this.resizePolicy.dirty = false;
|
|
169
|
+
this.resizePolicyDirty = false;
|
|
170
|
+
this.resizeInternal(window.innerWidth * scale, window.innerHeight * scale);
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
private readonly onPointerDown = (event: PointerEvent): void => {
|
|
174
|
+
this.handleWindowInput(
|
|
175
|
+
event,
|
|
176
|
+
"onPointerDown",
|
|
177
|
+
this.signalPointerPressedInternal,
|
|
178
|
+
);
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
private readonly onPointerMove = (event: PointerEvent): void => {
|
|
182
|
+
this.handleWindowInput(
|
|
183
|
+
event,
|
|
184
|
+
"onPointerMove",
|
|
185
|
+
this.signalPointerMovedInternal,
|
|
186
|
+
);
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
private readonly onPointerUp = (event: PointerEvent): void => {
|
|
190
|
+
this.handleWindowInput(
|
|
191
|
+
event,
|
|
192
|
+
"onPointerUp",
|
|
193
|
+
this.signalPointerReleasedInternal,
|
|
194
|
+
);
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
private handleWindowInput(
|
|
198
|
+
event: PointerEvent,
|
|
199
|
+
pointerFunctionName: "onPointerDown" | "onPointerMove" | "onPointerUp",
|
|
200
|
+
signal: Ferrsign1<UIFullscreenLayerInputEventData>,
|
|
201
|
+
): void {
|
|
202
|
+
const rect =
|
|
203
|
+
event.target instanceof HTMLElement
|
|
204
|
+
? event.target.getBoundingClientRect()
|
|
205
|
+
: null;
|
|
206
|
+
|
|
207
|
+
const x = rect ? event.clientX - rect.left : event.clientX;
|
|
208
|
+
const y = rect
|
|
209
|
+
? rect.bottom - event.clientY
|
|
210
|
+
: window.innerHeight - event.clientY;
|
|
211
|
+
|
|
212
|
+
const scale = this.resizePolicy.calculateScale(
|
|
213
|
+
window.innerWidth,
|
|
214
|
+
window.innerHeight,
|
|
215
|
+
);
|
|
216
|
+
const scaledX = x * scale;
|
|
217
|
+
const scaledY = y * scale;
|
|
218
|
+
|
|
219
|
+
if (isUIModeInteractive(this.mode)) {
|
|
220
|
+
signal.emit({
|
|
221
|
+
x: scaledX,
|
|
222
|
+
y: scaledY,
|
|
223
|
+
identifier: event.pointerId,
|
|
224
|
+
layer: this,
|
|
225
|
+
});
|
|
226
|
+
this.inputWrapperInternal[pointerFunctionName](
|
|
227
|
+
scaledX,
|
|
228
|
+
scaledY,
|
|
229
|
+
event.pointerId,
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
package/{dist/layers/UILayer/UILayer.Internal.d.ts → src/core/layers/UILayer/UILayer.Internal.ts}
RENAMED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import { UIMode } from "../../miscellaneous/UIMode";
|
|
2
2
|
import type { UIOrientation } from "../../miscellaneous/UIOrientation";
|
|
3
|
+
|
|
3
4
|
/** Layer visibility and interactivity state */
|
|
4
5
|
export type UILayerMode = UIMode.HIDDEN | UIMode.VISIBLE | UIMode.INTERACTIVE;
|
|
6
|
+
|
|
5
7
|
/** Layer orientation state */
|
|
6
8
|
export type UILayerOrientation = UIOrientation.VERTICAL | UIOrientation.HORIZONTAL;
|
|
9
|
+
|
|
7
10
|
/** Configuration options for UILayer */
|
|
8
11
|
export interface UILayerOptions {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
/** Initial width */
|
|
13
|
+
width: number;
|
|
14
|
+
/** Initial height */
|
|
15
|
+
height: number;
|
|
16
|
+
/** Optional layer name */
|
|
17
|
+
name: string;
|
|
18
|
+
/** Initial visibility and interactivity mode */
|
|
19
|
+
mode: UILayerMode;
|
|
17
20
|
}
|
|
18
|
-
|
|
19
|
-
export
|
|
20
|
-
export
|
|
21
|
+
|
|
22
|
+
export const LAYER_DEFAULT_SIZE = 1024;
|
|
23
|
+
export const LAYER_DEFAULT_NAME = "";
|
|
24
|
+
export const LAYER_DEFAULT_MODE: UILayerMode = UIMode.VISIBLE;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import type { FerrsignView2, FerrsignView3 } from "ferrsign";
|
|
2
|
+
import { Ferrsign2, Ferrsign3 } from "ferrsign";
|
|
3
|
+
import type { WebGLRenderer } from "three";
|
|
4
|
+
import type { UIPlaneElement } from "../../miscellaneous/shared";
|
|
5
|
+
|
|
6
|
+
import { assertValidPositiveNumber } from "../../miscellaneous/asserts";
|
|
7
|
+
import { isUIModeVisible } from "../../miscellaneous/UIMode";
|
|
8
|
+
import { UIOrientation } from "../../miscellaneous/UIOrientation";
|
|
9
|
+
import { UIPriority } from "../../miscellaneous/UIPriority";
|
|
10
|
+
import { UIInputWrapper } from "../../wrappers/UIInputWrapper/UIInputWrapper";
|
|
11
|
+
import type { UIInputWrapperView } from "../../wrappers/UIInputWrapper/UIInputWrapper.Internal";
|
|
12
|
+
import { UISceneWrapper } from "../../wrappers/UISceneWrapper/UISceneWrapper";
|
|
13
|
+
import type { UISceneWrapperView } from "../../wrappers/UISceneWrapper/UISceneWrapper.Internal";
|
|
14
|
+
import { UISolverWrapper } from "../../wrappers/UISolverWrapper/UISolverWrapper";
|
|
15
|
+
import type { UISolverWrapperView } from "../../wrappers/UISolverWrapper/UISolverWrapper.Internal";
|
|
16
|
+
import type { UILayerMode, UILayerOptions, UILayerOrientation } from "./UILayer.Internal";
|
|
17
|
+
import { LAYER_DEFAULT_MODE, LAYER_DEFAULT_NAME, LAYER_DEFAULT_SIZE } from "./UILayer.Internal";
|
|
18
|
+
|
|
19
|
+
/** Base layer for UI rendering and layout management */
|
|
20
|
+
export abstract class UILayer implements UIPlaneElement {
|
|
21
|
+
/** Optional layer name */
|
|
22
|
+
public name = "";
|
|
23
|
+
/** Solver variable for x coordinate */
|
|
24
|
+
public readonly xVariable: number;
|
|
25
|
+
/** Solver variable for y coordinate */
|
|
26
|
+
public readonly yVariable: number;
|
|
27
|
+
/** Solver variable for width */
|
|
28
|
+
public readonly wVariable: number;
|
|
29
|
+
/** Solver variable for height */
|
|
30
|
+
public readonly hVariable: number;
|
|
31
|
+
|
|
32
|
+
protected readonly inputWrapperInternal = new UIInputWrapper();
|
|
33
|
+
private readonly solverWrapperInternal = new UISolverWrapper();
|
|
34
|
+
private readonly sceneWrapperInternal: UISceneWrapper;
|
|
35
|
+
|
|
36
|
+
private modeInternal: UILayerMode;
|
|
37
|
+
private orientationInternal: UILayerOrientation;
|
|
38
|
+
|
|
39
|
+
private readonly signalOrientationChangedInternal = new Ferrsign2<UILayerOrientation, UILayer>();
|
|
40
|
+
private readonly signalModeChangedInternal = new Ferrsign2<UILayerMode, UILayer>();
|
|
41
|
+
private readonly signalRenderingInternal = new Ferrsign3<WebGLRenderer, number, UILayer>();
|
|
42
|
+
|
|
43
|
+
constructor(options: Partial<UILayerOptions>) {
|
|
44
|
+
if (options.width !== undefined) {
|
|
45
|
+
assertValidPositiveNumber(options.width, "UILayer.constructor.options.width");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (options.height !== undefined) {
|
|
49
|
+
assertValidPositiveNumber(options.height, "UILayer.constructor.options.height");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const width = options.width ?? LAYER_DEFAULT_SIZE;
|
|
53
|
+
const height = options.height ?? LAYER_DEFAULT_SIZE;
|
|
54
|
+
|
|
55
|
+
this.sceneWrapperInternal = new UISceneWrapper(width, height);
|
|
56
|
+
this.name = options.name ?? LAYER_DEFAULT_NAME;
|
|
57
|
+
this.modeInternal = options.mode ?? LAYER_DEFAULT_MODE;
|
|
58
|
+
this.orientationInternal = width > height ? UIOrientation.HORIZONTAL : UIOrientation.VERTICAL;
|
|
59
|
+
|
|
60
|
+
this.xVariable = this.solverWrapperInternal.createVariable(0, UIPriority.P0);
|
|
61
|
+
this.yVariable = this.solverWrapperInternal.createVariable(0, UIPriority.P0);
|
|
62
|
+
this.wVariable = this.solverWrapperInternal.createVariable(width, UIPriority.P0);
|
|
63
|
+
this.hVariable = this.solverWrapperInternal.createVariable(height, UIPriority.P0);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** @internal */
|
|
67
|
+
public get sceneWrapper(): UISceneWrapperView {
|
|
68
|
+
return this.sceneWrapperInternal;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** @internal */
|
|
72
|
+
public get solverWrapper(): UISolverWrapperView {
|
|
73
|
+
return this.solverWrapperInternal;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** @internal */
|
|
77
|
+
public get inputWrapper(): UIInputWrapperView {
|
|
78
|
+
return this.inputWrapperInternal;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** X coordinate in world units (always 0 for layers) */
|
|
82
|
+
public get x(): number {
|
|
83
|
+
return this.solverWrapperInternal.readVariableValue(this.xVariable);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Y coordinate in world units (always 0 for layers) */
|
|
87
|
+
public get y(): number {
|
|
88
|
+
return this.solverWrapperInternal.readVariableValue(this.yVariable);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Layer width in world units */
|
|
92
|
+
public get width(): number {
|
|
93
|
+
return this.solverWrapperInternal.readVariableValue(this.wVariable);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Layer height in world units */
|
|
97
|
+
public get height(): number {
|
|
98
|
+
return this.solverWrapperInternal.readVariableValue(this.hVariable);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Current visibility and interactivity mode */
|
|
102
|
+
public get mode(): UILayerMode {
|
|
103
|
+
return this.modeInternal;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Current orientation based on aspect ratio */
|
|
107
|
+
public get orientation(): UILayerOrientation {
|
|
108
|
+
return this.orientationInternal;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Signal fired when orientation changes */
|
|
112
|
+
public get signalOrientationChanged(): FerrsignView2<UILayerOrientation, UILayer> {
|
|
113
|
+
return this.signalOrientationChangedInternal;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Signal fired when mode changes */
|
|
117
|
+
public get signalModeChanged(): FerrsignView2<UILayerMode, UILayer> {
|
|
118
|
+
return this.signalModeChangedInternal;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Signal fired during rendering */
|
|
122
|
+
public get signalRendering(): FerrsignView3<WebGLRenderer, number, UILayer> {
|
|
123
|
+
return this.signalRenderingInternal;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Updates visibility and interactivity mode */
|
|
127
|
+
public set mode(value: UILayerMode) {
|
|
128
|
+
if (value !== this.modeInternal) {
|
|
129
|
+
this.modeInternal = value;
|
|
130
|
+
this.signalModeChangedInternal.emit(this.modeInternal, this);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
protected resizeInternal(width: number, height: number): void {
|
|
135
|
+
this.solverWrapperInternal.suggestVariableValue(this.wVariable, width);
|
|
136
|
+
this.solverWrapperInternal.suggestVariableValue(this.hVariable, height);
|
|
137
|
+
this.sceneWrapperInternal.resize(width, height);
|
|
138
|
+
|
|
139
|
+
const orientation = width > height ? UIOrientation.HORIZONTAL : UIOrientation.VERTICAL;
|
|
140
|
+
|
|
141
|
+
if (orientation !== this.orientationInternal) {
|
|
142
|
+
this.orientationInternal = orientation;
|
|
143
|
+
this.signalOrientationChangedInternal.emit(this.orientationInternal, this);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
protected renderInternal(renderer: WebGLRenderer, deltaTime: number): void {
|
|
148
|
+
if (isUIModeVisible(this.mode)) {
|
|
149
|
+
this.signalRenderingInternal.emit(renderer, deltaTime, this);
|
|
150
|
+
this.sceneWrapperInternal.render(renderer);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
this.solverWrapperInternal.dirty = false;
|
|
154
|
+
this.inputWrapperInternal.dirty = false;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { assertValidNumber } from "./asserts";
|
|
2
|
+
|
|
3
|
+
/** Linear expression for constraint equations */
|
|
4
|
+
export class UIExpression {
|
|
5
|
+
/** Constant term */
|
|
6
|
+
public constant: number;
|
|
7
|
+
/** Variable coefficients */
|
|
8
|
+
private readonly terms: Map<number, number>;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param constant Constant term
|
|
12
|
+
* @param terms Variable-coefficient pairs
|
|
13
|
+
*/
|
|
14
|
+
constructor(constant = 0, terms?: [number, number][]) {
|
|
15
|
+
assertValidNumber(constant, "UIExpression.constructor.constant");
|
|
16
|
+
this.constant = constant;
|
|
17
|
+
this.terms = terms ? new Map(terms) : new Map();
|
|
18
|
+
|
|
19
|
+
if (terms) {
|
|
20
|
+
for (let i = 0; i < terms.length; i++) {
|
|
21
|
+
assertValidNumber(terms[i][1], `UIExpression.constructor.terms[${i}][1]`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Creates expression representing a + b.
|
|
28
|
+
* @param a First expression
|
|
29
|
+
* @param b Second expression
|
|
30
|
+
* @returns Sum of expressions
|
|
31
|
+
*/
|
|
32
|
+
public static plus(a: UIExpression, b: UIExpression): UIExpression {
|
|
33
|
+
const result = new UIExpression(a.constant + b.constant, Array.from(a.terms.entries()));
|
|
34
|
+
for (const [variableIndex, coefficient] of b.terms) {
|
|
35
|
+
result.plus(variableIndex, coefficient);
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Creates expression representing a - b.
|
|
42
|
+
* @param a First expression
|
|
43
|
+
* @param b Second expression
|
|
44
|
+
* @returns Difference of expressions
|
|
45
|
+
*/
|
|
46
|
+
public static minus(a: UIExpression, b: UIExpression): UIExpression {
|
|
47
|
+
const result = new UIExpression(a.constant - b.constant, Array.from(a.terms.entries()));
|
|
48
|
+
for (const [variableIndex, coefficient] of b.terms) {
|
|
49
|
+
result.minus(variableIndex, coefficient);
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Adds variable term to expression.
|
|
56
|
+
* @param variableIndex Variable descriptor
|
|
57
|
+
* @param coefficient Coefficient to add
|
|
58
|
+
* @returns This instance for chaining
|
|
59
|
+
*/
|
|
60
|
+
public plus(variableIndex: number, coefficient: number): this {
|
|
61
|
+
assertValidNumber(coefficient, "UIExpression.plus.coefficient");
|
|
62
|
+
this.terms.set(variableIndex, (this.terms.get(variableIndex) ?? 0) + coefficient);
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Subtracts variable term from expression.
|
|
68
|
+
* @param variableIndex Variable descriptor
|
|
69
|
+
* @param coefficient Coefficient to subtract
|
|
70
|
+
* @returns This instance for chaining
|
|
71
|
+
*/
|
|
72
|
+
public minus(variableIndex: number, coefficient: number): this {
|
|
73
|
+
return this.plus(variableIndex, -coefficient);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Multiplies all terms by scalar.
|
|
78
|
+
* @param value Scalar multiplier
|
|
79
|
+
* @returns This instance for chaining
|
|
80
|
+
*/
|
|
81
|
+
public multiply(value: number): this {
|
|
82
|
+
assertValidNumber(value, "UIExpression.multiply.value");
|
|
83
|
+
this.constant *= value;
|
|
84
|
+
for (const [variableIndex, coefficient] of this.terms) {
|
|
85
|
+
this.terms.set(variableIndex, coefficient * value);
|
|
86
|
+
}
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Divides all terms by scalar.
|
|
92
|
+
* @param value Scalar divisor
|
|
93
|
+
* @returns This instance for chaining
|
|
94
|
+
*/
|
|
95
|
+
public divide(value: number): this {
|
|
96
|
+
assertValidNumber(value, "UIExpression.divide.value");
|
|
97
|
+
if (value === 0) {
|
|
98
|
+
throw new Error("UIExpression.divide.value: cannot divide by zero");
|
|
99
|
+
}
|
|
100
|
+
return this.multiply(1 / value);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Checks if expression contains variable term.
|
|
105
|
+
* @param variableIndex Variable descriptor
|
|
106
|
+
* @returns True if variable has term
|
|
107
|
+
*/
|
|
108
|
+
public hasTerm(variableIndex: number): boolean {
|
|
109
|
+
return this.terms.has(variableIndex);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Copies from another expression.
|
|
114
|
+
* @param expression Source expression
|
|
115
|
+
* @returns This instance for chaining
|
|
116
|
+
*/
|
|
117
|
+
public copy(expression: UIExpression): this {
|
|
118
|
+
this.constant = expression.constant;
|
|
119
|
+
this.terms.clear();
|
|
120
|
+
for (const [variableIndex, coefficient] of expression.terms) {
|
|
121
|
+
this.terms.set(variableIndex, coefficient);
|
|
122
|
+
}
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Creates independent copy.
|
|
128
|
+
* @returns New expression with same content
|
|
129
|
+
*/
|
|
130
|
+
public clone(): UIExpression {
|
|
131
|
+
return new UIExpression(this.constant, Array.from(this.terms.entries()));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Prepares terms for solver.
|
|
136
|
+
* @returns Variable-coefficient pairs
|
|
137
|
+
* @internal
|
|
138
|
+
*/
|
|
139
|
+
public prepareTerms(): [number, number][] {
|
|
140
|
+
return Array.from(this.terms.entries());
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Visibility and interactivity state */
|
|
2
|
+
export enum UIMode {
|
|
3
|
+
/** Not rendered, no input */
|
|
4
|
+
HIDDEN = 0,
|
|
5
|
+
/** Rendered, no input */
|
|
6
|
+
VISIBLE = 1,
|
|
7
|
+
/** Rendered, receives input, blocks input to elements behind */
|
|
8
|
+
INTERACTIVE = 2,
|
|
9
|
+
/** Rendered, receives input, passes input to elements behind */
|
|
10
|
+
INTERACTIVE_TRANSPARENT = 3,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Checks if mode allows input events.
|
|
15
|
+
* @param mode Mode to check
|
|
16
|
+
* @returns True if interactive
|
|
17
|
+
*/
|
|
18
|
+
export function isUIModeInteractive(mode: UIMode): boolean {
|
|
19
|
+
return mode === UIMode.INTERACTIVE || mode === UIMode.INTERACTIVE_TRANSPARENT;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Checks if mode is rendered.
|
|
24
|
+
* @param mode Mode to check
|
|
25
|
+
* @returns True if visible
|
|
26
|
+
*/
|
|
27
|
+
export function isUIModeVisible(mode: UIMode): boolean {
|
|
28
|
+
return mode !== UIMode.HIDDEN;
|
|
29
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Screen orientation for conditional constraints */
|
|
2
|
+
export enum UIOrientation {
|
|
3
|
+
/** Landscape (width > height) */
|
|
4
|
+
HORIZONTAL = 0,
|
|
5
|
+
/** Portrait (height > width) */
|
|
6
|
+
VERTICAL = 1,
|
|
7
|
+
/** Active in any orientation */
|
|
8
|
+
ALWAYS = 2,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Resolves optional orientation.
|
|
13
|
+
* @param orientation Orientation to resolve
|
|
14
|
+
* @returns Orientation or ALWAYS if undefined
|
|
15
|
+
*/
|
|
16
|
+
export function resolveOrientation(orientation?: UIOrientation): UIOrientation {
|
|
17
|
+
return orientation ?? UIOrientation.ALWAYS;
|
|
18
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Strength } from "@lume/kiwi";
|
|
2
|
+
|
|
3
|
+
const HIGH_PRIORITY = 1000;
|
|
4
|
+
const MEDIUM_PRIORITY = 100;
|
|
5
|
+
const LOW_PRIORITY = 10;
|
|
6
|
+
|
|
7
|
+
/** Constraint solver priority levels */
|
|
8
|
+
export enum UIPriority {
|
|
9
|
+
/** Highest priority */
|
|
10
|
+
P0 = 0,
|
|
11
|
+
/** High priority */
|
|
12
|
+
P1 = 1,
|
|
13
|
+
/** Medium-high priority */
|
|
14
|
+
P2 = 2,
|
|
15
|
+
/** Medium priority */
|
|
16
|
+
P3 = 3,
|
|
17
|
+
/** Medium-low priority */
|
|
18
|
+
P4 = 4,
|
|
19
|
+
/** Low priority */
|
|
20
|
+
P5 = 5,
|
|
21
|
+
/** Very low priority */
|
|
22
|
+
P6 = 6,
|
|
23
|
+
/** Lowest priority */
|
|
24
|
+
P7 = 7,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Converts priority to solver strength.
|
|
29
|
+
* @param priority Priority level
|
|
30
|
+
* @returns Solver strength value
|
|
31
|
+
* @throws If priority is invalid
|
|
32
|
+
*/
|
|
33
|
+
export function convertPriority(priority: UIPriority): number {
|
|
34
|
+
switch (priority) {
|
|
35
|
+
case UIPriority.P0:
|
|
36
|
+
return Strength.create(HIGH_PRIORITY, HIGH_PRIORITY, HIGH_PRIORITY);
|
|
37
|
+
case UIPriority.P1:
|
|
38
|
+
return Strength.create(MEDIUM_PRIORITY, 0, 0);
|
|
39
|
+
case UIPriority.P2:
|
|
40
|
+
return Strength.create(LOW_PRIORITY, 0, 0);
|
|
41
|
+
case UIPriority.P3:
|
|
42
|
+
return Strength.create(0, MEDIUM_PRIORITY, 0);
|
|
43
|
+
case UIPriority.P4:
|
|
44
|
+
return Strength.create(0, LOW_PRIORITY, 0);
|
|
45
|
+
case UIPriority.P5:
|
|
46
|
+
return Strength.create(0, 0, MEDIUM_PRIORITY);
|
|
47
|
+
case UIPriority.P6:
|
|
48
|
+
return Strength.create(0, 0, LOW_PRIORITY);
|
|
49
|
+
case UIPriority.P7:
|
|
50
|
+
return Strength.create(0, 0, 1);
|
|
51
|
+
default:
|
|
52
|
+
throw new Error(`convertPriority.priority: invalid priority`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Resolves optional priority.
|
|
58
|
+
* @param priority Priority to resolve
|
|
59
|
+
* @returns Priority or P0 if undefined
|
|
60
|
+
*/
|
|
61
|
+
export function resolvePriority(priority?: UIPriority): UIPriority {
|
|
62
|
+
return priority ?? UIPriority.P0;
|
|
63
|
+
}
|