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
package/src/core/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.ts
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertValidInterpolationConstraintArguments,
|
|
3
|
+
assertValidNumber,
|
|
4
|
+
} from "../../miscellaneous/asserts";
|
|
5
|
+
import type { UIPlaneElement, UIPointElement } from "../../miscellaneous/shared";
|
|
6
|
+
import { isUIPlaneElement, isUIPointElement } from "../../miscellaneous/shared";
|
|
7
|
+
import { UIExpression } from "../../miscellaneous/UIExpression";
|
|
8
|
+
import { UISingleParameterConstraint } from "../UISingleParameterConstraint/UISingleParameterConstraint";
|
|
9
|
+
import type { UIVerticalInterpolationConstraintOptions } from "./UIVerticalInterpolationConstraint.Internal";
|
|
10
|
+
import { DEFAULT_ANCHOR, DEFAULT_T } from "./UIVerticalInterpolationConstraint.Internal";
|
|
11
|
+
|
|
12
|
+
/** Positions element C vertically between A and B based on interpolation factor */
|
|
13
|
+
export class UIVerticalInterpolationConstraint extends UISingleParameterConstraint {
|
|
14
|
+
/** Solver constraint descriptor */
|
|
15
|
+
protected override readonly constraint: number;
|
|
16
|
+
|
|
17
|
+
/** Anchor on element A */
|
|
18
|
+
private anchorAInternal: number;
|
|
19
|
+
/** Anchor on element B */
|
|
20
|
+
private anchorBInternal: number;
|
|
21
|
+
/** Anchor on element C */
|
|
22
|
+
private anchorCInternal: number;
|
|
23
|
+
/** Interpolation factor */
|
|
24
|
+
private tInternal: number;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param a First element
|
|
28
|
+
* @param b Second element
|
|
29
|
+
* @param c Element to position between A and B
|
|
30
|
+
* @param options Interpolation configuration
|
|
31
|
+
*/
|
|
32
|
+
constructor(
|
|
33
|
+
private readonly a: UIPointElement | UIPlaneElement,
|
|
34
|
+
private readonly b: UIPointElement | UIPlaneElement,
|
|
35
|
+
private readonly c: UIPointElement | UIPlaneElement,
|
|
36
|
+
options: Partial<UIVerticalInterpolationConstraintOptions> = {},
|
|
37
|
+
) {
|
|
38
|
+
if (options.anchorA !== undefined) {
|
|
39
|
+
assertValidNumber(
|
|
40
|
+
options.anchorA,
|
|
41
|
+
"UIVerticalInterpolationConstraint.constructor.options.anchorA",
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
if (options.anchorB !== undefined) {
|
|
45
|
+
assertValidNumber(
|
|
46
|
+
options.anchorB,
|
|
47
|
+
"UIVerticalInterpolationConstraint.constructor.options.anchorB",
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
if (options.anchorC !== undefined) {
|
|
51
|
+
assertValidNumber(
|
|
52
|
+
options.anchorC,
|
|
53
|
+
"UIVerticalInterpolationConstraint.constructor.options.anchorC",
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
if (options.t !== undefined) {
|
|
57
|
+
assertValidNumber(options.t, "UIVerticalInterpolationConstraint.constructor.options.t");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const anchorA = options.anchorA ?? DEFAULT_ANCHOR;
|
|
61
|
+
const anchorB = options.anchorB ?? DEFAULT_ANCHOR;
|
|
62
|
+
|
|
63
|
+
super(
|
|
64
|
+
assertValidInterpolationConstraintArguments(
|
|
65
|
+
"UIVerticalInterpolationConstraint.constructor",
|
|
66
|
+
a,
|
|
67
|
+
b,
|
|
68
|
+
c,
|
|
69
|
+
anchorA,
|
|
70
|
+
anchorB,
|
|
71
|
+
),
|
|
72
|
+
options,
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
this.anchorAInternal = anchorA;
|
|
76
|
+
this.anchorBInternal = anchorA;
|
|
77
|
+
this.anchorCInternal = options.anchorC ?? DEFAULT_ANCHOR;
|
|
78
|
+
this.tInternal = options.t ?? DEFAULT_T;
|
|
79
|
+
|
|
80
|
+
this.constraint = this.solverWrapper.createConstraint(
|
|
81
|
+
this.buildLHS(),
|
|
82
|
+
new UIExpression(0),
|
|
83
|
+
this.relation,
|
|
84
|
+
this.priority,
|
|
85
|
+
this.isConstraintEnabled(),
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Interpolation factor (0 = A position, 1 = B position) */
|
|
90
|
+
public get t(): number {
|
|
91
|
+
return this.tInternal;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Anchor on element A (0 = bottom, 0.5 = center, 1 = top) */
|
|
95
|
+
public get anchorA(): number {
|
|
96
|
+
return this.anchorAInternal;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Anchor on element B (0 = bottom, 0.5 = center, 1 = top) */
|
|
100
|
+
public get anchorB(): number {
|
|
101
|
+
return this.anchorBInternal;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Anchor on element C (0 = bottom, 0.5 = center, 1 = top) */
|
|
105
|
+
public get anchorC(): number {
|
|
106
|
+
return this.anchorCInternal;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Updates interpolation factor */
|
|
110
|
+
public set t(value: number) {
|
|
111
|
+
assertValidNumber(value, "UIVerticalInterpolationConstraint.t");
|
|
112
|
+
if (this.tInternal !== value) {
|
|
113
|
+
this.tInternal = value;
|
|
114
|
+
this.solverWrapper.setConstraintLHS(this.constraint, this.buildLHS());
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Updates anchor on element A */
|
|
119
|
+
public set anchorA(value: number) {
|
|
120
|
+
assertValidNumber(value, "UIVerticalInterpolationConstraint.anchorA");
|
|
121
|
+
if (this.anchorAInternal !== value) {
|
|
122
|
+
this.anchorAInternal = value;
|
|
123
|
+
this.solverWrapper.setConstraintLHS(this.constraint, this.buildLHS());
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Updates anchor on element B */
|
|
128
|
+
public set anchorB(value: number) {
|
|
129
|
+
assertValidNumber(value, "UIVerticalInterpolationConstraint.anchorB");
|
|
130
|
+
if (this.anchorBInternal !== value) {
|
|
131
|
+
this.anchorBInternal = value;
|
|
132
|
+
this.solverWrapper.setConstraintLHS(this.constraint, this.buildLHS());
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Updates anchor on element C */
|
|
137
|
+
public set anchorC(value: number) {
|
|
138
|
+
assertValidNumber(value, "UIVerticalInterpolationConstraint.anchorC");
|
|
139
|
+
if (this.anchorCInternal !== value) {
|
|
140
|
+
this.anchorCInternal = value;
|
|
141
|
+
this.solverWrapper.setConstraintLHS(this.constraint, this.buildLHS());
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Builds constraint expression: C - A*(1-t) - B*t = 0 */
|
|
146
|
+
private buildLHS(): UIExpression {
|
|
147
|
+
let aExpression: UIExpression;
|
|
148
|
+
let bExpression: UIExpression;
|
|
149
|
+
let cExpression: UIExpression;
|
|
150
|
+
|
|
151
|
+
if (isUIPlaneElement(this.a)) {
|
|
152
|
+
aExpression = new UIExpression(0, [
|
|
153
|
+
[this.a.yVariable, 1],
|
|
154
|
+
[this.a.hVariable, this.anchorAInternal],
|
|
155
|
+
]);
|
|
156
|
+
} else if (isUIPointElement(this.a)) {
|
|
157
|
+
aExpression = new UIExpression().plus(this.a.yVariable, 1);
|
|
158
|
+
} else {
|
|
159
|
+
throw new Error("UIVerticalInterpolationConstraint.buildLHS.a: invalid element type");
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (isUIPlaneElement(this.b)) {
|
|
163
|
+
bExpression = new UIExpression(0, [
|
|
164
|
+
[this.b.yVariable, 1],
|
|
165
|
+
[this.b.hVariable, this.anchorBInternal],
|
|
166
|
+
]);
|
|
167
|
+
} else if (isUIPointElement(this.b)) {
|
|
168
|
+
bExpression = new UIExpression().plus(this.b.yVariable, 1);
|
|
169
|
+
} else {
|
|
170
|
+
throw new Error("UIVerticalInterpolationConstraint.buildLHS.b: invalid element type");
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (isUIPlaneElement(this.c)) {
|
|
174
|
+
cExpression = new UIExpression(0, [
|
|
175
|
+
[this.c.yVariable, 1],
|
|
176
|
+
[this.c.hVariable, this.anchorCInternal],
|
|
177
|
+
]);
|
|
178
|
+
} else if (isUIPointElement(this.c)) {
|
|
179
|
+
cExpression = new UIExpression().plus(this.c.yVariable, 1);
|
|
180
|
+
} else {
|
|
181
|
+
throw new Error("UIVerticalInterpolationConstraint.buildLHS.c: invalid element type");
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// C - A*(1-t) - B*t = 0
|
|
185
|
+
const aScaled = aExpression.clone().multiply(1 - this.tInternal);
|
|
186
|
+
const bScaled = bExpression.clone().multiply(this.tInternal);
|
|
187
|
+
return UIExpression.minus(UIExpression.minus(cExpression, aScaled), bScaled);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { UISingleParameterConstraintOptions } from "../UISingleParameterConstraint/UISingleParameterConstraint.Internal";
|
|
2
|
+
|
|
2
3
|
/** Vertical proportion constraint options */
|
|
3
4
|
export interface UIVerticalProportionConstraintOptions extends UISingleParameterConstraintOptions {
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
/** Proportion multiplier (A.height * proportion = B.height) */
|
|
6
|
+
proportion: number;
|
|
6
7
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertValidConstraintArguments,
|
|
3
|
+
assertValidPositiveNumber,
|
|
4
|
+
} from "../../miscellaneous/asserts";
|
|
5
|
+
import type { UIPlaneElement } from "../../miscellaneous/shared";
|
|
6
|
+
import { UIExpression } from "../../miscellaneous/UIExpression";
|
|
7
|
+
import { UISingleParameterConstraint } from "../UISingleParameterConstraint/UISingleParameterConstraint";
|
|
8
|
+
import type { UIVerticalProportionConstraintOptions } from "./UIVerticalProportionConstraint.Internal";
|
|
9
|
+
|
|
10
|
+
/** Maintains proportional height relationship (A.height * proportion = B.height) */
|
|
11
|
+
export class UIVerticalProportionConstraint extends UISingleParameterConstraint {
|
|
12
|
+
protected override readonly constraint: number;
|
|
13
|
+
private proportionInternal: number;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param a First element
|
|
17
|
+
* @param b Second element
|
|
18
|
+
* @param options Proportion configuration
|
|
19
|
+
*/
|
|
20
|
+
constructor(
|
|
21
|
+
private readonly a: UIPlaneElement,
|
|
22
|
+
private readonly b: UIPlaneElement,
|
|
23
|
+
options: Partial<UIVerticalProportionConstraintOptions> = {},
|
|
24
|
+
) {
|
|
25
|
+
if (options.proportion !== undefined) {
|
|
26
|
+
assertValidPositiveNumber(
|
|
27
|
+
options.proportion,
|
|
28
|
+
"UIVerticalProportionConstraint.constructor.options.proportion",
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
super(
|
|
33
|
+
assertValidConstraintArguments(a, b, "UIVerticalProportionConstraint.constructor"),
|
|
34
|
+
options,
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
this.proportionInternal = options.proportion ?? 1;
|
|
38
|
+
this.constraint = this.solverWrapper.createConstraint(
|
|
39
|
+
new UIExpression(0),
|
|
40
|
+
this.buildRHS(),
|
|
41
|
+
this.relation,
|
|
42
|
+
this.priority,
|
|
43
|
+
this.isConstraintEnabled(),
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Current proportion multiplier */
|
|
48
|
+
public get proportion(): number {
|
|
49
|
+
return this.proportionInternal;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Updates proportion multiplier */
|
|
53
|
+
public set proportion(value: number) {
|
|
54
|
+
assertValidPositiveNumber(value, "UIVerticalProportionConstraint.proportion");
|
|
55
|
+
if (this.proportionInternal !== value) {
|
|
56
|
+
this.proportionInternal = value;
|
|
57
|
+
this.solverWrapper.setConstraintRHS(this.constraint, this.buildRHS());
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Builds constraint expression for proportional relationship */
|
|
62
|
+
private buildRHS(): UIExpression {
|
|
63
|
+
return UIExpression.minus(
|
|
64
|
+
new UIExpression(0, [[this.a.hVariable, this.proportionInternal]]),
|
|
65
|
+
new UIExpression(0, [[this.b.hVariable, 1]]),
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { UISingleParameterConstraintOptions } from "../UISingleParameterConstraint/UISingleParameterConstraint.Internal";
|
|
2
|
+
|
|
2
3
|
/** Width constraint options */
|
|
3
4
|
export interface UIWidthConstraintOptions extends UISingleParameterConstraintOptions {
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
/** Target width in world units */
|
|
6
|
+
width: number;
|
|
6
7
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { assertValidPositiveNumber } from "../../miscellaneous/asserts";
|
|
2
|
+
import type { UILayerElement, UIPlaneElement } from "../../miscellaneous/shared";
|
|
3
|
+
import { UIExpression } from "../../miscellaneous/UIExpression";
|
|
4
|
+
import { UISingleParameterConstraint } from "../UISingleParameterConstraint/UISingleParameterConstraint";
|
|
5
|
+
import type { UIWidthConstraintOptions } from "./UIWidthConstraint.Internal";
|
|
6
|
+
|
|
7
|
+
/** Fixes element width to constant value */
|
|
8
|
+
export class UIWidthConstraint extends UISingleParameterConstraint {
|
|
9
|
+
/** Solver constraint descriptor */
|
|
10
|
+
protected override readonly constraint: number;
|
|
11
|
+
|
|
12
|
+
/** Current width value */
|
|
13
|
+
private widthInternal: number;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param element Element to constrain
|
|
17
|
+
* @param options Width configuration. Defaults to element's current width.
|
|
18
|
+
*/
|
|
19
|
+
constructor(
|
|
20
|
+
private readonly element: UIPlaneElement & UILayerElement,
|
|
21
|
+
options: Partial<UIWidthConstraintOptions> = {},
|
|
22
|
+
) {
|
|
23
|
+
if (options.width !== undefined) {
|
|
24
|
+
assertValidPositiveNumber(options.width, "UIWidthConstraint.constructor.options.width");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
super(element.layer, options);
|
|
28
|
+
|
|
29
|
+
this.widthInternal = options.width ?? element.width;
|
|
30
|
+
this.constraint = this.solverWrapper.createConstraint(
|
|
31
|
+
new UIExpression(0, [[this.element.wVariable, 1]]),
|
|
32
|
+
new UIExpression(this.widthInternal),
|
|
33
|
+
this.relation,
|
|
34
|
+
this.priority,
|
|
35
|
+
this.isConstraintEnabled(),
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Current width in world units */
|
|
40
|
+
public get width(): number {
|
|
41
|
+
return this.widthInternal;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Updates width */
|
|
45
|
+
public set width(value: number) {
|
|
46
|
+
assertValidPositiveNumber(value, "UIWidthConstraint.width");
|
|
47
|
+
if (this.widthInternal !== value) {
|
|
48
|
+
this.widthInternal = value;
|
|
49
|
+
this.solverWrapper.setConstraintRHS(this.constraint, new UIExpression(value));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { UIOrientation } from "../../miscellaneous/UIOrientation";
|
|
2
|
+
import type { UIPriority } from "../../miscellaneous/UIPriority";
|
|
3
|
+
import type { UIRelation } from "../../miscellaneous/UIRelation";
|
|
4
|
+
|
|
5
|
+
/** Horizontal and vertical values object */
|
|
6
|
+
export interface UIType2DObject<T> {
|
|
7
|
+
/** Horizontal value */
|
|
8
|
+
h?: T;
|
|
9
|
+
/** Vertical value */
|
|
10
|
+
v?: T;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Horizontal and vertical values as object, tuple, or single value */
|
|
14
|
+
export type UIType2D<T> = UIType2DObject<T> | [T, T] | T;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Normalizes UIType2D input to object form.
|
|
18
|
+
* @param value Object, tuple, or single value
|
|
19
|
+
* @returns Normalized object with h and v properties
|
|
20
|
+
*/
|
|
21
|
+
export function normalizeUIType2D<T>(value: UIType2D<T> | undefined): UIType2DObject<T> {
|
|
22
|
+
if (value === undefined) {
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
if (Array.isArray(value)) {
|
|
26
|
+
return { h: value[0], v: value[1] };
|
|
27
|
+
}
|
|
28
|
+
if (typeof value === "object" && value !== null && ("h" in value || "v" in value)) {
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
return { h: value as T, v: value as T };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Base 2D constraint options */
|
|
35
|
+
export interface UIConstraint2DOptions {
|
|
36
|
+
/** Priority for each axis */
|
|
37
|
+
priority: UIType2D<UIPriority>;
|
|
38
|
+
/** Relation for each axis */
|
|
39
|
+
relation: UIType2D<UIRelation>;
|
|
40
|
+
/** Orientation for each axis */
|
|
41
|
+
orientation: UIType2D<UIOrientation>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** 2D size constraint options */
|
|
45
|
+
export interface UIConstraintSize2DOptions extends UIConstraint2DOptions {
|
|
46
|
+
/** Width and height */
|
|
47
|
+
size: UIType2D<number>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** 2D distance constraint options */
|
|
51
|
+
export interface UIConstraintDistance2DOptions extends UIConstraint2DOptions {
|
|
52
|
+
/** Anchor on element A for each axis */
|
|
53
|
+
anchorA: UIType2D<number>;
|
|
54
|
+
/** Anchor on element B for each axis */
|
|
55
|
+
anchorB: UIType2D<number>;
|
|
56
|
+
/** Distance for each axis */
|
|
57
|
+
distance: UIType2D<number>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** 2D proportion constraint options */
|
|
61
|
+
export interface UIConstraintProportion2DOptions extends UIConstraint2DOptions {
|
|
62
|
+
/** Proportion for each axis */
|
|
63
|
+
proportion: UIType2D<number>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** 2D interpolation constraint options */
|
|
67
|
+
export interface UIConstraintInterpolation2DOptions extends UIConstraint2DOptions {
|
|
68
|
+
/** Anchor on element A for each axis */
|
|
69
|
+
anchorA: UIType2D<number>;
|
|
70
|
+
/** Anchor on element B for each axis */
|
|
71
|
+
anchorB: UIType2D<number>;
|
|
72
|
+
/** Anchor on element C for each axis */
|
|
73
|
+
anchorC: UIType2D<number>;
|
|
74
|
+
/** Interpolation factor for each axis */
|
|
75
|
+
t: UIType2D<number>;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Horizontal and vertical constraint pair */
|
|
79
|
+
export interface UIConstraint2DResult<TH, TV> {
|
|
80
|
+
/** Horizontal constraint */
|
|
81
|
+
h: TH;
|
|
82
|
+
/** Vertical constraint */
|
|
83
|
+
v: TV;
|
|
84
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import type { UIElement } from "../../elements/UIElement/UIElement";
|
|
2
|
+
import type { UIPlaneElement, UIPointElement } from "../../miscellaneous/shared";
|
|
3
|
+
import { UIHeightConstraint } from "../UIHeightConstraint/UIHeightConstraint";
|
|
4
|
+
import { UIHorizontalDistanceConstraint } from "../UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint";
|
|
5
|
+
import { UIHorizontalInterpolationConstraint } from "../UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint";
|
|
6
|
+
import { UIHorizontalProportionConstraint } from "../UIHorizontalProportionConstraint/UIHorizontalProportionConstraint";
|
|
7
|
+
import { UIVerticalDistanceConstraint } from "../UIVerticalDistanceConstraint/UIVerticalDistanceConstraint";
|
|
8
|
+
import { UIVerticalInterpolationConstraint } from "../UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint";
|
|
9
|
+
import { UIVerticalProportionConstraint } from "../UIVerticalProportionConstraint/UIVerticalProportionConstraint";
|
|
10
|
+
import { UIWidthConstraint } from "../UIWidthConstraint/UIWidthConstraint";
|
|
11
|
+
import type {
|
|
12
|
+
UIConstraint2DResult,
|
|
13
|
+
UIConstraintDistance2DOptions,
|
|
14
|
+
UIConstraintInterpolation2DOptions,
|
|
15
|
+
UIConstraintProportion2DOptions,
|
|
16
|
+
UIConstraintSize2DOptions,
|
|
17
|
+
} from "./UIConstraint2DBuilder.Internal";
|
|
18
|
+
import { normalizeUIType2D } from "./UIConstraint2DBuilder.Internal";
|
|
19
|
+
|
|
20
|
+
/** Builder for paired horizontal and vertical constraints */
|
|
21
|
+
export class UIConstraint2DBuilder {
|
|
22
|
+
/**
|
|
23
|
+
* Creates width and height constraints.
|
|
24
|
+
* @param element Element to constrain
|
|
25
|
+
* @param options Size configuration for both axes
|
|
26
|
+
* @returns Width and height constraints
|
|
27
|
+
*/
|
|
28
|
+
public static size(
|
|
29
|
+
element: UIElement,
|
|
30
|
+
options: Partial<UIConstraintSize2DOptions> = {},
|
|
31
|
+
): UIConstraint2DResult<UIWidthConstraint, UIHeightConstraint> {
|
|
32
|
+
const size = normalizeUIType2D(options.size);
|
|
33
|
+
const priority = normalizeUIType2D(options.priority);
|
|
34
|
+
const relation = normalizeUIType2D(options.relation);
|
|
35
|
+
const orientation = normalizeUIType2D(options.orientation);
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
h: new UIWidthConstraint(element, {
|
|
39
|
+
width: size.h,
|
|
40
|
+
priority: priority.h,
|
|
41
|
+
relation: relation.h,
|
|
42
|
+
orientation: orientation.h,
|
|
43
|
+
}),
|
|
44
|
+
v: new UIHeightConstraint(element, {
|
|
45
|
+
height: size.v,
|
|
46
|
+
priority: priority.v,
|
|
47
|
+
relation: relation.v,
|
|
48
|
+
orientation: orientation.v,
|
|
49
|
+
}),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Creates horizontal and vertical distance constraints.
|
|
55
|
+
* @param a First element
|
|
56
|
+
* @param b Second element
|
|
57
|
+
* @param options Distance configuration for both axes
|
|
58
|
+
* @returns Horizontal and vertical distance constraints
|
|
59
|
+
*/
|
|
60
|
+
public static distance(
|
|
61
|
+
a: UIPointElement | UIPlaneElement,
|
|
62
|
+
b: UIPointElement | UIPlaneElement,
|
|
63
|
+
options: Partial<UIConstraintDistance2DOptions> = {},
|
|
64
|
+
): UIConstraint2DResult<UIHorizontalDistanceConstraint, UIVerticalDistanceConstraint> {
|
|
65
|
+
const anchorA = normalizeUIType2D(options.anchorA);
|
|
66
|
+
const anchorB = normalizeUIType2D(options.anchorB);
|
|
67
|
+
const distance = normalizeUIType2D(options.distance);
|
|
68
|
+
const priority = normalizeUIType2D(options.priority);
|
|
69
|
+
const relation = normalizeUIType2D(options.relation);
|
|
70
|
+
const orientation = normalizeUIType2D(options.orientation);
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
h: new UIHorizontalDistanceConstraint(a, b, {
|
|
74
|
+
anchorA: anchorA.h,
|
|
75
|
+
anchorB: anchorB.h,
|
|
76
|
+
distance: distance.h,
|
|
77
|
+
priority: priority.h,
|
|
78
|
+
relation: relation.h,
|
|
79
|
+
orientation: orientation.h,
|
|
80
|
+
}),
|
|
81
|
+
v: new UIVerticalDistanceConstraint(a, b, {
|
|
82
|
+
anchorA: anchorA.v,
|
|
83
|
+
anchorB: anchorB.v,
|
|
84
|
+
distance: distance.v,
|
|
85
|
+
priority: priority.v,
|
|
86
|
+
relation: relation.v,
|
|
87
|
+
orientation: orientation.v,
|
|
88
|
+
}),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Creates horizontal and vertical proportion constraints.
|
|
94
|
+
* @param a Element with proportional dimensions
|
|
95
|
+
* @param b Target element
|
|
96
|
+
* @param options Proportion configuration for both axes
|
|
97
|
+
* @returns Horizontal and vertical proportion constraints
|
|
98
|
+
*/
|
|
99
|
+
public static proportion(
|
|
100
|
+
a: UIPlaneElement,
|
|
101
|
+
b: UIPlaneElement,
|
|
102
|
+
options: Partial<UIConstraintProportion2DOptions> = {},
|
|
103
|
+
): UIConstraint2DResult<UIHorizontalProportionConstraint, UIVerticalProportionConstraint> {
|
|
104
|
+
const proportion = normalizeUIType2D(options.proportion);
|
|
105
|
+
const priority = normalizeUIType2D(options.priority);
|
|
106
|
+
const relation = normalizeUIType2D(options.relation);
|
|
107
|
+
const orientation = normalizeUIType2D(options.orientation);
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
h: new UIHorizontalProportionConstraint(a, b, {
|
|
111
|
+
proportion: proportion.h,
|
|
112
|
+
priority: priority.h,
|
|
113
|
+
relation: relation.h,
|
|
114
|
+
orientation: orientation.h,
|
|
115
|
+
}),
|
|
116
|
+
v: new UIVerticalProportionConstraint(a, b, {
|
|
117
|
+
proportion: proportion.v,
|
|
118
|
+
priority: priority.v,
|
|
119
|
+
relation: relation.v,
|
|
120
|
+
orientation: orientation.v,
|
|
121
|
+
}),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Creates horizontal and vertical interpolation constraints.
|
|
127
|
+
* @param a First element
|
|
128
|
+
* @param b Second element
|
|
129
|
+
* @param c Element to position between A and B
|
|
130
|
+
* @param options Interpolation configuration for both axes
|
|
131
|
+
* @returns Horizontal and vertical interpolation constraints
|
|
132
|
+
*/
|
|
133
|
+
public static interpolation(
|
|
134
|
+
a: UIPointElement | UIPlaneElement,
|
|
135
|
+
b: UIPointElement | UIPlaneElement,
|
|
136
|
+
c: UIPointElement | UIPlaneElement,
|
|
137
|
+
options: Partial<UIConstraintInterpolation2DOptions> = {},
|
|
138
|
+
): UIConstraint2DResult<UIHorizontalInterpolationConstraint, UIVerticalInterpolationConstraint> {
|
|
139
|
+
const anchorA = normalizeUIType2D(options.anchorA);
|
|
140
|
+
const anchorB = normalizeUIType2D(options.anchorB);
|
|
141
|
+
const anchorC = normalizeUIType2D(options.anchorC);
|
|
142
|
+
const t = normalizeUIType2D(options.t);
|
|
143
|
+
const priority = normalizeUIType2D(options.priority);
|
|
144
|
+
const relation = normalizeUIType2D(options.relation);
|
|
145
|
+
const orientation = normalizeUIType2D(options.orientation);
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
h: new UIHorizontalInterpolationConstraint(a, b, c, {
|
|
149
|
+
anchorA: anchorA.h,
|
|
150
|
+
anchorB: anchorB.h,
|
|
151
|
+
anchorC: anchorC.h,
|
|
152
|
+
t: t.h,
|
|
153
|
+
priority: priority.h,
|
|
154
|
+
relation: relation.h,
|
|
155
|
+
orientation: orientation.h,
|
|
156
|
+
}),
|
|
157
|
+
v: new UIVerticalInterpolationConstraint(a, b, c, {
|
|
158
|
+
anchorA: anchorA.v,
|
|
159
|
+
anchorB: anchorB.v,
|
|
160
|
+
anchorC: anchorC.v,
|
|
161
|
+
t: t.v,
|
|
162
|
+
priority: priority.v,
|
|
163
|
+
relation: relation.v,
|
|
164
|
+
orientation: orientation.v,
|
|
165
|
+
}),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { UIOrientation } from "../../miscellaneous/UIOrientation";
|
|
2
|
+
|
|
3
|
+
export const COVER_CONSTRAINT_DEFAULT_ANCHOR = 0.5;
|
|
4
|
+
|
|
5
|
+
/** Cover constraint builder options */
|
|
6
|
+
export interface UICoverConstraintBuilderOptions {
|
|
7
|
+
/** Whether to maintain active element aspect ratio */
|
|
8
|
+
keepActiveAspect: boolean;
|
|
9
|
+
/** Horizontal anchor (0 = left, 0.5 = center, 1 = right) */
|
|
10
|
+
anchorH: number;
|
|
11
|
+
/** Vertical anchor (0 = bottom, 0.5 = center, 1 = top) */
|
|
12
|
+
anchorV: number;
|
|
13
|
+
/** Orientation for constraints */
|
|
14
|
+
orientation: UIOrientation;
|
|
15
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { assertValidNumber } from "../../miscellaneous/asserts";
|
|
2
|
+
import type { UILayerElement, UIPlaneElement } from "../../miscellaneous/shared";
|
|
3
|
+
import { UIPriority } from "../../miscellaneous/UIPriority";
|
|
4
|
+
import { UIRelation } from "../../miscellaneous/UIRelation";
|
|
5
|
+
import { UIAspectConstraint } from "../UIAspectConstraint/UIAspectConstraint";
|
|
6
|
+
import { UIHorizontalDistanceConstraint } from "../UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint";
|
|
7
|
+
import { UIHorizontalProportionConstraint } from "../UIHorizontalProportionConstraint/UIHorizontalProportionConstraint";
|
|
8
|
+
import { UIVerticalDistanceConstraint } from "../UIVerticalDistanceConstraint/UIVerticalDistanceConstraint";
|
|
9
|
+
import { UIVerticalProportionConstraint } from "../UIVerticalProportionConstraint/UIVerticalProportionConstraint";
|
|
10
|
+
import type { UICoverConstraintBuilderOptions } from "./UICoverConstraintBuilder.Internal";
|
|
11
|
+
import { COVER_CONSTRAINT_DEFAULT_ANCHOR } from "./UICoverConstraintBuilder.Internal";
|
|
12
|
+
|
|
13
|
+
/** Builder for cover layout (like CSS object-fit: cover) */
|
|
14
|
+
export class UICoverConstraintBuilder {
|
|
15
|
+
/**
|
|
16
|
+
* Creates cover layout constraints.
|
|
17
|
+
* @param passive Container element
|
|
18
|
+
* @param active Content element that covers container
|
|
19
|
+
* @param options Cover configuration
|
|
20
|
+
* @returns Created constraints
|
|
21
|
+
*/
|
|
22
|
+
public static build(
|
|
23
|
+
passive: UIPlaneElement,
|
|
24
|
+
active: UIPlaneElement & UILayerElement,
|
|
25
|
+
options: Partial<UICoverConstraintBuilderOptions> = {},
|
|
26
|
+
): {
|
|
27
|
+
/** Aspect constraint if keepActiveAspect is true */
|
|
28
|
+
activeAspectConstraint?: UIAspectConstraint;
|
|
29
|
+
/** Horizontal position constraint */
|
|
30
|
+
xConstraint: UIHorizontalDistanceConstraint;
|
|
31
|
+
/** Vertical position constraint */
|
|
32
|
+
yConstraint: UIVerticalDistanceConstraint;
|
|
33
|
+
/** Width constraint (ensures coverage) */
|
|
34
|
+
widthConstraint: UIHorizontalProportionConstraint;
|
|
35
|
+
/** Height constraint (ensures coverage) */
|
|
36
|
+
heightConstraint: UIVerticalProportionConstraint;
|
|
37
|
+
} {
|
|
38
|
+
if (options.anchorH !== undefined) {
|
|
39
|
+
assertValidNumber(options.anchorH, "UICoverConstraintBuilder.build.anchorH");
|
|
40
|
+
}
|
|
41
|
+
if (options.anchorV !== undefined) {
|
|
42
|
+
assertValidNumber(options.anchorV, "UICoverConstraintBuilder.build.anchorV");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let activeAspectConstraint: UIAspectConstraint | undefined;
|
|
46
|
+
if (options.keepActiveAspect !== false) {
|
|
47
|
+
activeAspectConstraint = new UIAspectConstraint(active, {
|
|
48
|
+
orientation: options.orientation,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const xConstraint = new UIHorizontalDistanceConstraint(passive, active, {
|
|
53
|
+
anchorA: options.anchorH ?? COVER_CONSTRAINT_DEFAULT_ANCHOR,
|
|
54
|
+
anchorB: options.anchorH ?? COVER_CONSTRAINT_DEFAULT_ANCHOR,
|
|
55
|
+
orientation: options.orientation,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const yConstraint = new UIVerticalDistanceConstraint(passive, active, {
|
|
59
|
+
anchorA: options.anchorV ?? COVER_CONSTRAINT_DEFAULT_ANCHOR,
|
|
60
|
+
anchorB: options.anchorV ?? COVER_CONSTRAINT_DEFAULT_ANCHOR,
|
|
61
|
+
orientation: options.orientation,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const widthConstraint = new UIHorizontalProportionConstraint(passive, active, {
|
|
65
|
+
proportion: 1,
|
|
66
|
+
relation: UIRelation.GREATER_THAN,
|
|
67
|
+
orientation: options.orientation,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const heightConstraint = new UIVerticalProportionConstraint(passive, active, {
|
|
71
|
+
proportion: 1,
|
|
72
|
+
priority: UIPriority.P1,
|
|
73
|
+
orientation: options.orientation,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
activeAspectConstraint,
|
|
78
|
+
xConstraint,
|
|
79
|
+
yConstraint,
|
|
80
|
+
widthConstraint,
|
|
81
|
+
heightConstraint,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}
|