laymur 0.1.73 → 0.2.1
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/README.md +367 -0
- package/dist/builders/UIConstraint2DBuilder.d.ts +130 -0
- package/dist/composer/UIComposer.d.ts +0 -0
- package/dist/composer/UIFullscreenQuad.d.ts +0 -0
- package/dist/composer/UIPass.d.ts +0 -0
- package/dist/constraints/UIAspectConstraint.d.ts +60 -0
- package/dist/constraints/UIConstraint.d.ts +29 -0
- package/dist/constraints/UICoverConstraint.d.ts +0 -0
- package/dist/constraints/UICustomConstraint.d.ts +60 -0
- package/dist/constraints/UIFitConstraint.d.ts +0 -0
- package/dist/constraints/UIHeightConstraint.d.ts +49 -0
- package/dist/constraints/UIHorizontalDistanceConstraint.d.ts +94 -0
- package/dist/constraints/UIHorizontalProportionConstraint.d.ts +67 -0
- package/dist/constraints/UISingleParameterConstraint.d.ts +108 -0
- package/dist/constraints/UIVerticalDistanceConstraint.d.ts +94 -0
- package/dist/constraints/UIVerticalProportionConstraint.d.ts +67 -0
- package/dist/constraints/UIWidthConstraint.d.ts +49 -0
- package/dist/elements/UIAnchor.d.ts +78 -0
- package/dist/elements/UIDummy.d.ts +72 -0
- package/dist/elements/UIElement.d.ts +121 -0
- package/dist/elements/UIImage.d.ts +88 -0
- package/dist/elements/UINineSline.d.ts +0 -0
- package/dist/elements/UIProgress.d.ts +39 -0
- package/dist/elements/UIScene.d.ts +199 -0
- package/dist/elements/UIText.d.ts +157 -0
- package/dist/index.d.ts +29 -31
- package/dist/index.js +3320 -3251
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/layers/UIFullscreenLayer.d.ts +112 -0
- package/dist/layers/UILayer.d.ts +144 -0
- package/dist/materials/UIInstancedMaterial.d.ts +0 -0
- package/dist/materials/UIMaterial.d.ts +13 -0
- package/dist/materials/UINineSliceMaterial.d.ts +0 -0
- package/dist/{Materials → materials}/UIProgressMaterial.d.ts +0 -4
- package/dist/miscellaneous/UIExpression.d.ts +117 -0
- package/dist/miscellaneous/UIMicro.d.ts +130 -0
- package/dist/{Miscellaneous → miscellaneous}/UIOrientation.d.ts +2 -9
- package/dist/miscellaneous/UIPriority.d.ts +56 -0
- package/dist/miscellaneous/UIRelation.d.ts +43 -0
- package/dist/miscellaneous/UITextPadding.d.ts +7 -0
- package/dist/miscellaneous/UITextSpan.d.ts +6 -0
- package/dist/miscellaneous/UITextStyle.d.ts +18 -0
- package/dist/miscellaneous/asserts.d.ts +112 -0
- package/dist/miscellaneous/textInterfaces.d.ts +19 -0
- package/dist/miscellaneous/textTools.d.ts +12 -0
- package/dist/scalable/UIScalableMesh.d.ts +16 -0
- package/dist/scalable/UIScalablePlaneMesh.d.ts +14 -0
- package/dist/wrappers/UISceneWrapper.d.ts +18 -0
- package/dist/wrappers/UISolverWrapper.d.ts +29 -0
- package/package.json +3 -3
- package/dist/Builders/UIConstraint2DBuilder.d.ts +0 -42
- package/dist/Builders/UIConstraintContainerBuilder.d.ts +0 -20
- package/dist/Builders/UIConstraintStackBuilder.d.ts +0 -24
- package/dist/Constraints/UIAspectConstraint.d.ts +0 -56
- package/dist/Constraints/UIConstraint.d.ts +0 -32
- package/dist/Constraints/UIConstraintPower.d.ts +0 -57
- package/dist/Constraints/UIConstraintRule.d.ts +0 -46
- package/dist/Constraints/UICoverConstraint.d.ts +0 -72
- package/dist/Constraints/UIFitConstraint.d.ts +0 -72
- package/dist/Constraints/UIHeightConstraint.d.ts +0 -55
- package/dist/Constraints/UIHorizontalDistanceConstraint.d.ts +0 -63
- package/dist/Constraints/UIHorizontalProportionConstraint.d.ts +0 -58
- package/dist/Constraints/UIVerticalDistanceConstraint.d.ts +0 -63
- package/dist/Constraints/UIVerticalProportionConstraint.d.ts +0 -58
- package/dist/Constraints/UIWidthConstraint.d.ts +0 -55
- package/dist/Elements/UIAnchor.d.ts +0 -66
- package/dist/Elements/UIDummy.d.ts +0 -21
- package/dist/Elements/UIElement.d.ts +0 -134
- package/dist/Elements/UIImage.d.ts +0 -57
- package/dist/Elements/UIProgress.d.ts +0 -127
- package/dist/Elements/UIScene.d.ts +0 -141
- package/dist/Elements/UIText.d.ts +0 -76
- package/dist/Layers/UIFullScreenLayer.d.ts +0 -13
- package/dist/Layers/UILayer.d.ts +0 -68
- package/dist/Materials/UIMaterial.d.ts +0 -13
- package/dist/Miscellaneous/UIBlending.d.ts +0 -7
- package/dist/Miscellaneous/UIMicro.d.ts +0 -176
- package/dist/Miscellaneous/UITextInterfaces.d.ts +0 -49
- package/dist/Miscellaneous/asserts.d.ts +0 -5
- package/dist/Miscellaneous/math.d.ts +0 -1
- package/dist/Miscellaneous/microTransformationTools.d.ts +0 -3
- package/dist/Miscellaneous/symbols.d.ts +0 -1
- package/dist/Miscellaneous/textTools.d.ts +0 -9
- package/dist/Passes/UIComposer.d.ts +0 -114
- package/dist/Passes/UIFullScreenQuad.d.ts +0 -51
- package/dist/Passes/UIPass.d.ts +0 -43
- /package/dist/{Miscellaneous → miscellaneous}/UIMode.d.ts +0 -0
- /package/dist/{Miscellaneous → miscellaneous}/threeInstances.d.ts +0 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface UITextStyle {
|
|
2
|
+
color: string;
|
|
3
|
+
fontFamily: string;
|
|
4
|
+
fontSize: number;
|
|
5
|
+
fontStyle: "normal" | "italic" | "oblique";
|
|
6
|
+
fontWeight: "normal" | "bold" | "bolder" | "lighter" | number;
|
|
7
|
+
lineHeight: number;
|
|
8
|
+
enableShadow: boolean;
|
|
9
|
+
shadowOffsetX: number;
|
|
10
|
+
shadowOffsetY: number;
|
|
11
|
+
shadowBlur: number;
|
|
12
|
+
shadowColor: string;
|
|
13
|
+
enableStroke: boolean;
|
|
14
|
+
strokeColor: string;
|
|
15
|
+
strokeWidth: number;
|
|
16
|
+
}
|
|
17
|
+
export declare function isUITextStyle(obj: unknown): obj is UITextStyle;
|
|
18
|
+
export declare function resolveTextStyle(style?: Partial<UITextStyle>, commonStyle?: Partial<UITextStyle>): UITextStyle;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { UILayer } from "../layers/UILayer";
|
|
2
|
+
/** Small epsilon value for floating-point comparisons and minimum positive number validation. */
|
|
3
|
+
export declare const EPSILON = 0.000001;
|
|
4
|
+
/**
|
|
5
|
+
* Interface for objects that belong to a UI layer.
|
|
6
|
+
*
|
|
7
|
+
* Elements implementing this interface are associated with a specific layer
|
|
8
|
+
* for constraint solving and rendering management.
|
|
9
|
+
*/
|
|
10
|
+
export interface UILayerElement {
|
|
11
|
+
/** The UI layer that contains this element. */
|
|
12
|
+
layer: UILayer;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Interface for UI elements that have a position in 2D space.
|
|
16
|
+
*
|
|
17
|
+
* Point elements are characterized by x and y coordinates represented
|
|
18
|
+
* as solver variable descriptors for constraint-based positioning.
|
|
19
|
+
*/
|
|
20
|
+
export interface UIPointElement {
|
|
21
|
+
/** Solver variable descriptor for the x-coordinate. */
|
|
22
|
+
xVariable: number;
|
|
23
|
+
/** Solver variable descriptor for the y-coordinate. */
|
|
24
|
+
yVariable: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Interface for UI elements that have both position and dimensions in 2D space.
|
|
28
|
+
*
|
|
29
|
+
* Plane elements extend point elements with width and height properties,
|
|
30
|
+
* enabling rectangular area constraints and positioning.
|
|
31
|
+
*/
|
|
32
|
+
export interface UIPlaneElement extends UIPointElement {
|
|
33
|
+
/** Solver variable descriptor for the width dimension. */
|
|
34
|
+
wVariable: number;
|
|
35
|
+
/** Solver variable descriptor for the height dimension. */
|
|
36
|
+
hVariable: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Type guard to check if an object implements the UILayerElement interface.
|
|
40
|
+
*
|
|
41
|
+
* @param obj - The object to check
|
|
42
|
+
* @returns True if the object has a valid layer property, false otherwise
|
|
43
|
+
*/
|
|
44
|
+
export declare function isUILayerElement(obj: unknown): obj is UILayerElement;
|
|
45
|
+
/**
|
|
46
|
+
* Type guard to check if an object implements the UIPointElement interface.
|
|
47
|
+
*
|
|
48
|
+
* @param obj - The object to check
|
|
49
|
+
* @returns True if the object has valid xVariable and yVariable properties, false otherwise
|
|
50
|
+
*/
|
|
51
|
+
export declare function isUIPointElement(obj: unknown): obj is UIPointElement;
|
|
52
|
+
/**
|
|
53
|
+
* Type guard to check if an object implements the UIPlaneElement interface.
|
|
54
|
+
*
|
|
55
|
+
* Note: This function only checks for width and height variables. Objects
|
|
56
|
+
* should also satisfy UIPointElement requirements for complete validation.
|
|
57
|
+
*
|
|
58
|
+
* @param obj - The object to check
|
|
59
|
+
* @returns True if the object has valid wVariable and hVariable properties, false otherwise
|
|
60
|
+
*/
|
|
61
|
+
export declare function isUIPlaneElement(obj: unknown): obj is UIPlaneElement;
|
|
62
|
+
/**
|
|
63
|
+
* Validates that two objects are valid constraint subjects from the same layer.
|
|
64
|
+
*
|
|
65
|
+
* Ensures that both objects are either UILayer instances or UILayerElement instances,
|
|
66
|
+
* that they are not both layers (which cannot be constrained to each other),
|
|
67
|
+
* and that they belong to the same layer for constraint solving.
|
|
68
|
+
*
|
|
69
|
+
* @param a - The first constraint subject
|
|
70
|
+
* @param b - The second constraint subject
|
|
71
|
+
* @param subject - The name of the constraint for error messages
|
|
72
|
+
* @returns The common layer that both subjects belong to
|
|
73
|
+
* @throws Will throw an error if subjects are invalid or from different layers
|
|
74
|
+
*/
|
|
75
|
+
export declare function assertValidConstraintSubjects(a: unknown, b: unknown, subject: string): UILayer;
|
|
76
|
+
/**
|
|
77
|
+
* Validates that a value is a finite number within safe integer range.
|
|
78
|
+
*
|
|
79
|
+
* Checks that the value is finite (not NaN, Infinity, or -Infinity) and
|
|
80
|
+
* within the safe integer range for reliable mathematical operations.
|
|
81
|
+
*
|
|
82
|
+
* @param value - The number to validate
|
|
83
|
+
* @param subject - The name of the value for error messages
|
|
84
|
+
* @throws Will throw an error if the value is not finite or exceeds safe range
|
|
85
|
+
*/
|
|
86
|
+
export declare function assertValidNumber(value: number, subject: string): void;
|
|
87
|
+
/**
|
|
88
|
+
* Validates that a value is a positive number above the epsilon threshold.
|
|
89
|
+
*
|
|
90
|
+
* First validates that the value is a finite number, then ensures it is
|
|
91
|
+
* greater than or equal to EPSILON to avoid numerical precision issues
|
|
92
|
+
* with very small positive values.
|
|
93
|
+
*
|
|
94
|
+
* @param value - The number to validate
|
|
95
|
+
* @param subject - The name of the value for error messages
|
|
96
|
+
* @throws Will throw an error if the value is invalid or not sufficiently positive
|
|
97
|
+
* @see {@link assertValidNumber}
|
|
98
|
+
*/
|
|
99
|
+
export declare function assertValidPositiveNumber(value: number, subject: string): void;
|
|
100
|
+
/**
|
|
101
|
+
* Validates that a value is a non-negative number (including zero).
|
|
102
|
+
*
|
|
103
|
+
* First validates that the value is a finite number, then ensures it is
|
|
104
|
+
* greater than or equal to zero. Unlike assertValidPositiveNumber, this
|
|
105
|
+
* function allows zero as a valid value.
|
|
106
|
+
*
|
|
107
|
+
* @param value - The number to validate
|
|
108
|
+
* @param subject - The name of the value for error messages
|
|
109
|
+
* @throws Will throw an error if the value is invalid or negative
|
|
110
|
+
* @see {@link assertValidNumber}
|
|
111
|
+
*/
|
|
112
|
+
export declare function assertValidNonNegativeNumber(value: number, subject: string): void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { UITextSpan } from "./UITextSpan";
|
|
2
|
+
import type { UITextStyle } from "./UITextStyle";
|
|
3
|
+
export type UITextContent = (UITextSpan | string)[] | UITextSpan | string;
|
|
4
|
+
export interface UITextSize {
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
}
|
|
8
|
+
export interface UIChunkMetrics extends UITextSize {
|
|
9
|
+
baseline: number;
|
|
10
|
+
lineHeight: number;
|
|
11
|
+
}
|
|
12
|
+
export interface UITextChunk {
|
|
13
|
+
text: string;
|
|
14
|
+
style: UITextStyle;
|
|
15
|
+
metrics: UIChunkMetrics;
|
|
16
|
+
}
|
|
17
|
+
export interface UITextLine extends UIChunkMetrics {
|
|
18
|
+
chunks: UITextChunk[];
|
|
19
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { UIChunkMetrics, UITextChunk, UITextContent, UITextLine, UITextSize } from "./textInterfaces";
|
|
2
|
+
import { type UITextStyle } from "./UITextStyle";
|
|
3
|
+
export declare function splitText(text: string): string[];
|
|
4
|
+
export declare function measureTextChunk(context: CanvasRenderingContext2D, chunk: string, style: UITextStyle): UIChunkMetrics;
|
|
5
|
+
export declare function buildLines(maxWidth: number, chunks: UITextChunk[]): UITextLine[];
|
|
6
|
+
export declare function calculateTextSize(lines: UITextLine[]): UITextSize;
|
|
7
|
+
export declare function renderText(x: number, y: number, text: string, style: UITextStyle, context: CanvasRenderingContext2D): void;
|
|
8
|
+
export declare function renderTextLines(paddingTop: number, paddingLeft: number, lines: UITextLine[], context: CanvasRenderingContext2D): void;
|
|
9
|
+
export declare function calculateTextContentParameters(context: CanvasRenderingContext2D, content: UITextContent, maxLineWidth: number, commonStyle?: Partial<UITextStyle>): {
|
|
10
|
+
lines: UITextLine[];
|
|
11
|
+
size: UITextSize;
|
|
12
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { InstancedBufferGeometry, Material } from "three";
|
|
2
|
+
import { Mesh } from "three";
|
|
3
|
+
export declare const SCALABLE_MESH_CAPACITY_STEP = 32;
|
|
4
|
+
export declare abstract class UIScalableMesh extends Mesh {
|
|
5
|
+
private readonly users;
|
|
6
|
+
private lastUserIndex;
|
|
7
|
+
private capacity;
|
|
8
|
+
constructor(geometry: InstancedBufferGeometry, material: Material);
|
|
9
|
+
createInstance(): number;
|
|
10
|
+
removeInstance(index: number): void;
|
|
11
|
+
protected getGeometryDataIndex(userIndex: number): number;
|
|
12
|
+
private resizeInstancedGeometry;
|
|
13
|
+
protected abstract buildGeometry(capacity: number): InstancedBufferGeometry;
|
|
14
|
+
protected abstract copyGeometryToGeometry(from: InstancedBufferGeometry, to: InstancedBufferGeometry): void;
|
|
15
|
+
protected abstract copyIndexToIndex(geometry: InstancedBufferGeometry, from: number, to: number): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Color, Material, Matrix3, Matrix4 } from "three";
|
|
2
|
+
import { InstancedBufferGeometry } from "three";
|
|
3
|
+
import { UIScalableMesh } from "./UIScalableMesh";
|
|
4
|
+
export declare class UIScalablePlaneMesh extends UIScalableMesh {
|
|
5
|
+
constructor(material: Material);
|
|
6
|
+
private static buildPlaneGeometry;
|
|
7
|
+
setTransform(userIndex: number, matrix: Matrix4): this;
|
|
8
|
+
setUVTransform(userIndex: number, matrix: Matrix3): this;
|
|
9
|
+
setColor(userIndex: number, color: Color): this;
|
|
10
|
+
setMisc(userIndex: number, alphaTest: number): this;
|
|
11
|
+
protected buildGeometry(capacity: number): InstancedBufferGeometry;
|
|
12
|
+
protected copyGeometryToGeometry(from: InstancedBufferGeometry, to: InstancedBufferGeometry): void;
|
|
13
|
+
protected copyIndexToIndex(geometry: InstancedBufferGeometry, from: number, to: number): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Object3D, WebGLRenderer } from "three";
|
|
2
|
+
import type { UIElement } from "../elements/UIElement";
|
|
3
|
+
export declare class UISceneWrapper {
|
|
4
|
+
private readonly scene;
|
|
5
|
+
private readonly camera;
|
|
6
|
+
private readonly elements;
|
|
7
|
+
constructor(w: number, h: number);
|
|
8
|
+
insertObject(element: UIElement, object: Object3D): void;
|
|
9
|
+
replaceObject(element: UIElement, object: Object3D): void;
|
|
10
|
+
removeObject(element: UIElement): void;
|
|
11
|
+
resize(w: number, h: number): void;
|
|
12
|
+
getVisibility(element: UIElement): boolean;
|
|
13
|
+
getZIndex(element: UIElement): number;
|
|
14
|
+
setZIndex(element: UIElement, zIndex: number): void;
|
|
15
|
+
setVisibility(element: UIElement, visible: boolean): void;
|
|
16
|
+
getSortedVisibleElements(): UIElement[];
|
|
17
|
+
render(renderer: WebGLRenderer, deltaTime: number): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { UIExpression } from "../miscellaneous/UIExpression";
|
|
2
|
+
import { UIPriority } from "../miscellaneous/UIPriority";
|
|
3
|
+
import { UIRelation } from "../miscellaneous/UIRelation";
|
|
4
|
+
export declare class UISolverWrapper {
|
|
5
|
+
private solver;
|
|
6
|
+
private recalculationRequired;
|
|
7
|
+
private readonly variables;
|
|
8
|
+
private lastVariableIndex;
|
|
9
|
+
private readonly constraints;
|
|
10
|
+
private lastConstraintIndex;
|
|
11
|
+
createVariable(value: number, priority: UIPriority): number;
|
|
12
|
+
removeVariable(index: number): void;
|
|
13
|
+
suggestVariableValue(index: number, value: number): void;
|
|
14
|
+
setVariablePriority(index: number, priority: UIPriority): void;
|
|
15
|
+
readVariableValue(index: number): number;
|
|
16
|
+
createConstraint(lhs: UIExpression, rhs: UIExpression, relation: UIRelation, priority: UIPriority, enabled: boolean): number;
|
|
17
|
+
removeConstraint(index: number): void;
|
|
18
|
+
setConstraintLHS(index: number, lhs: UIExpression): void;
|
|
19
|
+
setConstraintRHS(index: number, rhs: UIExpression): void;
|
|
20
|
+
setConstraintRelation(index: number, relation: UIRelation): void;
|
|
21
|
+
setConstraintPriority(index: number, priority: UIPriority): void;
|
|
22
|
+
setConstraintEnabled(index: number, enabled: boolean): void;
|
|
23
|
+
private convertExpression;
|
|
24
|
+
private rebuildVariable;
|
|
25
|
+
private rebuildConstraintByDescription;
|
|
26
|
+
private rebuildRawConstraint;
|
|
27
|
+
private buildConstraint;
|
|
28
|
+
private rebuildSolver;
|
|
29
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "laymur",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Lightweight Three.js UI toolkit mainly for mobile ads",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"clean": "rm -rf dist",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"typescript": "^5.8.3"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"
|
|
60
|
-
"
|
|
59
|
+
"@lume/kiwi": "^0.4.4",
|
|
60
|
+
"eventail": "^0.2.9"
|
|
61
61
|
}
|
|
62
62
|
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { UIConstraintPower } from "../Constraints/UIConstraintPower";
|
|
2
|
-
import type { UIConstraintRule } from "../Constraints/UIConstraintRule";
|
|
3
|
-
import { UIHeightConstraint } from "../Constraints/UIHeightConstraint";
|
|
4
|
-
import { UIHorizontalDistanceConstraint } from "../Constraints/UIHorizontalDistanceConstraint";
|
|
5
|
-
import { UIHorizontalProportionConstraint } from "../Constraints/UIHorizontalProportionConstraint";
|
|
6
|
-
import { UIVerticalDistanceConstraint } from "../Constraints/UIVerticalDistanceConstraint";
|
|
7
|
-
import { UIVerticalProportionConstraint } from "../Constraints/UIVerticalProportionConstraint";
|
|
8
|
-
import { UIWidthConstraint } from "../Constraints/UIWidthConstraint";
|
|
9
|
-
import type { UIAnchor } from "../Elements/UIAnchor";
|
|
10
|
-
import type { UIElement } from "../Elements/UIElement";
|
|
11
|
-
import type { UILayer } from "../Layers/UILayer";
|
|
12
|
-
import type { UIOrientation } from "../Miscellaneous/UIOrientation";
|
|
13
|
-
export interface UIType2D<T> {
|
|
14
|
-
x?: T;
|
|
15
|
-
y?: T;
|
|
16
|
-
}
|
|
17
|
-
interface UIConstraint2DOptions {
|
|
18
|
-
power: UIType2D<UIConstraintPower>;
|
|
19
|
-
rule: UIType2D<UIConstraintRule>;
|
|
20
|
-
orientation: UIType2D<UIOrientation>;
|
|
21
|
-
}
|
|
22
|
-
export interface UIConstraintSize2DOptions extends UIConstraint2DOptions {
|
|
23
|
-
size: UIType2D<number>;
|
|
24
|
-
}
|
|
25
|
-
export interface UIConstraintSize2DOptions extends UIConstraint2DOptions {
|
|
26
|
-
anchorOne: UIType2D<number>;
|
|
27
|
-
anchorTwo: UIType2D<number>;
|
|
28
|
-
distance: UIType2D<number>;
|
|
29
|
-
}
|
|
30
|
-
export interface UIConstraintProportion2DOptions extends UIConstraint2DOptions {
|
|
31
|
-
proportion: UIType2D<number>;
|
|
32
|
-
}
|
|
33
|
-
export interface UIConstraint2DResult<TX, TY> {
|
|
34
|
-
x: TX;
|
|
35
|
-
y: TY;
|
|
36
|
-
}
|
|
37
|
-
export declare class UIConstraint2DBuilder {
|
|
38
|
-
static size(element: UIElement, options?: Partial<UIConstraintSize2DOptions>): UIConstraint2DResult<UIWidthConstraint, UIHeightConstraint>;
|
|
39
|
-
static distance(elementOne: UIElement | UIAnchor | UILayer, elementTwo: UIElement | UIAnchor, options?: Partial<UIConstraintSize2DOptions>): UIConstraint2DResult<UIHorizontalDistanceConstraint, UIVerticalDistanceConstraint>;
|
|
40
|
-
static proportion(elementOne: UIElement | UILayer, elementTwo: UIElement, options?: Partial<UIConstraintProportion2DOptions>): UIConstraint2DResult<UIHorizontalProportionConstraint, UIVerticalProportionConstraint>;
|
|
41
|
-
}
|
|
42
|
-
export {};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { UIConstraintPower } from "../Constraints/UIConstraintPower";
|
|
2
|
-
import { UIHorizontalDistanceConstraint } from "../Constraints/UIHorizontalDistanceConstraint";
|
|
3
|
-
import { UIVerticalDistanceConstraint } from "../Constraints/UIVerticalDistanceConstraint";
|
|
4
|
-
import type { UIElement } from "../Elements/UIElement";
|
|
5
|
-
import type { UIOrientation } from "../Miscellaneous/UIOrientation";
|
|
6
|
-
export declare enum UIConstraintContainerDirection {
|
|
7
|
-
FROM_LEFT_TOP = 0,
|
|
8
|
-
FROM_LEFT_BOTTOM = 1
|
|
9
|
-
}
|
|
10
|
-
export interface UIConstraintContainerBuilderOptions {
|
|
11
|
-
direction: UIConstraintContainerDirection;
|
|
12
|
-
power: UIConstraintPower;
|
|
13
|
-
orientation: UIOrientation;
|
|
14
|
-
}
|
|
15
|
-
export declare class UIConstraintContainerBuilder {
|
|
16
|
-
static build(container: UIElement, elementOne: UIElement, elementTwo: UIElement, options?: Partial<UIConstraintContainerBuilderOptions>): {
|
|
17
|
-
horizontalDistances: UIHorizontalDistanceConstraint[];
|
|
18
|
-
verticalDistances: UIVerticalDistanceConstraint[];
|
|
19
|
-
};
|
|
20
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { UIConstraintPower } from "../Constraints/UIConstraintPower";
|
|
2
|
-
import { UIHorizontalDistanceConstraint } from "../Constraints/UIHorizontalDistanceConstraint";
|
|
3
|
-
import { UIHorizontalProportionConstraint } from "../Constraints/UIHorizontalProportionConstraint";
|
|
4
|
-
import { UIVerticalDistanceConstraint } from "../Constraints/UIVerticalDistanceConstraint";
|
|
5
|
-
import { UIVerticalProportionConstraint } from "../Constraints/UIVerticalProportionConstraint";
|
|
6
|
-
import type { UIElement } from "../Elements/UIElement";
|
|
7
|
-
import type { UIOrientation } from "../Miscellaneous/UIOrientation";
|
|
8
|
-
export interface UIConstraintStackBuilderOptions {
|
|
9
|
-
distance: number;
|
|
10
|
-
keepProportions: boolean;
|
|
11
|
-
keepAlignment: boolean;
|
|
12
|
-
power: UIConstraintPower;
|
|
13
|
-
orientation: UIOrientation;
|
|
14
|
-
}
|
|
15
|
-
export interface UIConstraintStackBuilderResult<TDistance, TProportion, TCenter> {
|
|
16
|
-
distanceConstraints: TDistance[];
|
|
17
|
-
proportionConstraints: TProportion[];
|
|
18
|
-
alignmentConstraints: TCenter[];
|
|
19
|
-
}
|
|
20
|
-
export declare class UIConstraintStackBuilder {
|
|
21
|
-
static buildHorizontal(elements: UIElement[], options: Partial<UIConstraintStackBuilderOptions>): UIConstraintStackBuilderResult<UIHorizontalDistanceConstraint, UIHorizontalProportionConstraint, UIVerticalDistanceConstraint>;
|
|
22
|
-
static buildVertical(elements: UIElement[], options: Partial<UIConstraintStackBuilderOptions>): UIConstraintStackBuilderResult<UIVerticalDistanceConstraint, UIVerticalProportionConstraint, UIHorizontalDistanceConstraint>;
|
|
23
|
-
private static buildStack;
|
|
24
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type { UIElement } from "../Elements/UIElement";
|
|
2
|
-
import { UIOrientation } from "../Miscellaneous/UIOrientation";
|
|
3
|
-
import { UIConstraint } from "./UIConstraint";
|
|
4
|
-
import type { UIConstraintPower } from "./UIConstraintPower";
|
|
5
|
-
import type { UIConstraintRule } from "./UIConstraintRule";
|
|
6
|
-
/**
|
|
7
|
-
* Configuration options for aspect ratio constraints.
|
|
8
|
-
*/
|
|
9
|
-
export interface UIAspectOptions {
|
|
10
|
-
/** The aspect ratio to maintain (width / height) */
|
|
11
|
-
aspect: number;
|
|
12
|
-
/** Priority level for this constraint */
|
|
13
|
-
power: UIConstraintPower;
|
|
14
|
-
/** Rule for the constraint relationship (equal, less than, greater than) */
|
|
15
|
-
rule: UIConstraintRule;
|
|
16
|
-
/** Screen orientation when this constraint should be active */
|
|
17
|
-
orientation: UIOrientation;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Constraint that maintains a specific aspect ratio for a UI element.
|
|
21
|
-
*
|
|
22
|
-
* The aspect ratio is defined as width divided by height (w/h).
|
|
23
|
-
* This constraint ensures that an element maintains its proportions
|
|
24
|
-
* during layout calculations.
|
|
25
|
-
*/
|
|
26
|
-
export declare class UIAspectConstraint extends UIConstraint {
|
|
27
|
-
private readonly element;
|
|
28
|
-
/** The configuration options for this constraint */
|
|
29
|
-
private readonly parameters;
|
|
30
|
-
/** The Kiwi.js constraint object */
|
|
31
|
-
private constraint?;
|
|
32
|
-
/**
|
|
33
|
-
* Creates a new aspect ratio constraint.
|
|
34
|
-
*
|
|
35
|
-
* @param element - The UI element to constrain
|
|
36
|
-
* @param parameters - Configuration options
|
|
37
|
-
*/
|
|
38
|
-
constructor(element: UIElement, parameters?: Partial<UIAspectOptions>);
|
|
39
|
-
/**
|
|
40
|
-
* Destroys this constraint, removing it from the constraint system.
|
|
41
|
-
*/
|
|
42
|
-
destroy(): void;
|
|
43
|
-
/**
|
|
44
|
-
* Builds and adds the aspect ratio constraint to the constraint solver.
|
|
45
|
-
*
|
|
46
|
-
* Creates a constraint expression in the form: width - (height * aspect) = 0
|
|
47
|
-
* This ensures that width/height = aspect.
|
|
48
|
-
*
|
|
49
|
-
*/
|
|
50
|
-
protected buildConstraints(): void;
|
|
51
|
-
/**
|
|
52
|
-
* Removes the aspect ratio constraint from the constraint solver.
|
|
53
|
-
*
|
|
54
|
-
*/
|
|
55
|
-
protected destroyConstraints(): void;
|
|
56
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { UIAnchor } from "../Elements/UIAnchor";
|
|
2
|
-
import type { UIElement } from "../Elements/UIElement";
|
|
3
|
-
import type { UILayer } from "../Layers/UILayer";
|
|
4
|
-
/**
|
|
5
|
-
* Abstract base class for all UI constraints in the system.
|
|
6
|
-
*
|
|
7
|
-
* Constraints control the layout of UI elements by establishing relationships
|
|
8
|
-
* between their properties (position, size) and other elements or the screen.
|
|
9
|
-
*
|
|
10
|
-
* The constraint system uses Kiwi.js under the hood for solving the constraint system.
|
|
11
|
-
* Each constraint adds specific rules to the solver that determine element positioning.
|
|
12
|
-
*/
|
|
13
|
-
export declare abstract class UIConstraint {
|
|
14
|
-
readonly layer: UILayer;
|
|
15
|
-
/**
|
|
16
|
-
* Optional identifier for the constraint.
|
|
17
|
-
* Useful for debugging and identifying constraints.
|
|
18
|
-
*/
|
|
19
|
-
name: string;
|
|
20
|
-
/**
|
|
21
|
-
* Creates a new UI constraint.
|
|
22
|
-
*
|
|
23
|
-
* @param layer - The UI layer that will manage this constraint
|
|
24
|
-
* @param elements - The set of UI elements affected by this constraint
|
|
25
|
-
*/
|
|
26
|
-
constructor(layer: UILayer, elements: Set<UIElement | UIAnchor>);
|
|
27
|
-
/**
|
|
28
|
-
* Destroys the constraint, removing it from the layer and solver.
|
|
29
|
-
* This should be called when the constraint is no longer needed.
|
|
30
|
-
*/
|
|
31
|
-
destroy(): void;
|
|
32
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Defines the strength/priority levels for UI constraints.
|
|
3
|
-
*
|
|
4
|
-
* Constraints with higher power (lower index) take precedence over
|
|
5
|
-
* those with lower power when the constraint solver can't satisfy all constraints.
|
|
6
|
-
*
|
|
7
|
-
* The enum values map to different strength configurations in the Kiwi.js solver:
|
|
8
|
-
* - P0: Highest priority, "required" constraint that must be satisfied
|
|
9
|
-
* - P1-P7: Decreasing levels of priority
|
|
10
|
-
*/
|
|
11
|
-
export declare enum UIConstraintPower {
|
|
12
|
-
/** Highest priority - must be satisfied (required constraint) */
|
|
13
|
-
P0 = 0,
|
|
14
|
-
/** Very high priority */
|
|
15
|
-
P1 = 1,
|
|
16
|
-
/** High priority */
|
|
17
|
-
P2 = 2,
|
|
18
|
-
/** Medium-high priority */
|
|
19
|
-
P3 = 3,
|
|
20
|
-
/** Medium priority */
|
|
21
|
-
P4 = 4,
|
|
22
|
-
/** Medium-low priority */
|
|
23
|
-
P5 = 5,
|
|
24
|
-
/** Low priority */
|
|
25
|
-
P6 = 6,
|
|
26
|
-
/** Lowest priority */
|
|
27
|
-
P7 = 7
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Type guard to check if a value is a valid UIConstraintPower.
|
|
31
|
-
*
|
|
32
|
-
* @param obj - The value to check
|
|
33
|
-
* @returns True if the value is a valid UIConstraintPower enum value
|
|
34
|
-
*/
|
|
35
|
-
export declare function isUIConstraintPower(obj: unknown): obj is UIConstraintPower;
|
|
36
|
-
/**
|
|
37
|
-
* Resolves an optional power level to a definite value.
|
|
38
|
-
*
|
|
39
|
-
* @param power - The constraint power to resolve, or undefined
|
|
40
|
-
* @returns The provided power level, or P0 (highest) if none was provided
|
|
41
|
-
*/
|
|
42
|
-
export declare function resolvePower(power?: UIConstraintPower): UIConstraintPower;
|
|
43
|
-
/**
|
|
44
|
-
* Converts a UIConstraintPower enum value to a Kiwi.js strength value.
|
|
45
|
-
*
|
|
46
|
-
* The Kiwi.js constraint solver uses a three-tiered strength system.
|
|
47
|
-
* This function maps our power levels to appropriate strength values:
|
|
48
|
-
*
|
|
49
|
-
* - P0: Maximum strength in all tiers (required constraint)
|
|
50
|
-
* - P1-P2: Varying strengths in the first tier
|
|
51
|
-
* - P3-P4: Varying strengths in the second tier
|
|
52
|
-
* - P5-P7: Varying strengths in the third tier
|
|
53
|
-
*
|
|
54
|
-
* @param power - The constraint power to convert, or undefined
|
|
55
|
-
* @returns A Kiwi.js strength value corresponding to the power level
|
|
56
|
-
*/
|
|
57
|
-
export declare function convertPowerToStrength(power?: UIConstraintPower): number;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { Operator } from "kiwi.js";
|
|
2
|
-
/**
|
|
3
|
-
* Defines the type of relationship between values in a constraint.
|
|
4
|
-
*
|
|
5
|
-
* Maps directly to Kiwi.js Operators for the constraint solver.
|
|
6
|
-
* Used to specify whether values should be equal, less than, or greater than each other.
|
|
7
|
-
*/
|
|
8
|
-
export declare enum UIConstraintRule {
|
|
9
|
-
/**
|
|
10
|
-
* Values must be equal (x = y).
|
|
11
|
-
* Creates an equality constraint in the solver.
|
|
12
|
-
*/
|
|
13
|
-
EQUAL = 2,
|
|
14
|
-
/**
|
|
15
|
-
* Left value must be less than or equal to right value (x ≤ y).
|
|
16
|
-
* Creates an inequality constraint in the solver.
|
|
17
|
-
*/
|
|
18
|
-
LESS = 0,
|
|
19
|
-
/**
|
|
20
|
-
* Left value must be greater than or equal to right value (x ≥ y).
|
|
21
|
-
* Creates an inequality constraint in the solver.
|
|
22
|
-
*/
|
|
23
|
-
GREATER = 1
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Type guard to check if a value is a valid UIConstraintRule.
|
|
27
|
-
*
|
|
28
|
-
* @param obj - The value to check
|
|
29
|
-
* @returns True if the value is a valid UIConstraintRule enum value
|
|
30
|
-
*/
|
|
31
|
-
export declare function isUIConstraintRule(obj: unknown): obj is UIConstraintRule;
|
|
32
|
-
/**
|
|
33
|
-
* Resolves an optional rule to a definite value.
|
|
34
|
-
*
|
|
35
|
-
* @param rule - The constraint rule to resolve, or undefined
|
|
36
|
-
* @returns The provided rule, or EQUAL if none was provided
|
|
37
|
-
*/
|
|
38
|
-
export declare function resolveRule(rule?: UIConstraintRule): UIConstraintRule;
|
|
39
|
-
/**
|
|
40
|
-
* Converts a UIConstraintRule to the corresponding Kiwi.js Operator.
|
|
41
|
-
* This function provides a safe way to convert between our enum and Kiwi's enum.
|
|
42
|
-
*
|
|
43
|
-
* @param rule - The constraint rule to convert, or undefined
|
|
44
|
-
* @returns The corresponding Kiwi.js Operator value
|
|
45
|
-
*/
|
|
46
|
-
export declare function convertRuleToOperator(rule?: UIConstraintRule): Operator;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { UIElement } from "../Elements/UIElement";
|
|
2
|
-
import type { UILayer } from "../Layers/UILayer";
|
|
3
|
-
import { UIOrientation } from "../Miscellaneous/UIOrientation";
|
|
4
|
-
import { UIConstraint } from "./UIConstraint";
|
|
5
|
-
/**
|
|
6
|
-
* Configuration options for cover constraints.
|
|
7
|
-
*/
|
|
8
|
-
export interface UICoverOptions {
|
|
9
|
-
/** Whether to force equal height (true) or allow stretching (false) */
|
|
10
|
-
isStrict: boolean;
|
|
11
|
-
/** Horizontal anchor point (0-1) for alignment between elements */
|
|
12
|
-
horizontalAnchor: number;
|
|
13
|
-
/** Vertical anchor point (0-1) for alignment between elements */
|
|
14
|
-
verticalAnchor: number;
|
|
15
|
-
/** Screen orientation when this constraint should be active */
|
|
16
|
-
orientation: UIOrientation;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Constraint that makes an element cover another element or layer.
|
|
20
|
-
*
|
|
21
|
-
* The covering element will:
|
|
22
|
-
* - Be aligned with the covered element using the specified anchors
|
|
23
|
-
* - Have at least the same width and height as the covered element
|
|
24
|
-
* - Optionally maintain strict proportions
|
|
25
|
-
*
|
|
26
|
-
* This is similar to CSS's "cover" object-fit behavior.
|
|
27
|
-
*/
|
|
28
|
-
export declare class UICoverConstraint extends UIConstraint {
|
|
29
|
-
private readonly elementOne;
|
|
30
|
-
private readonly elementTwo;
|
|
31
|
-
/** The configuration options for this constraint */
|
|
32
|
-
private readonly parameters;
|
|
33
|
-
/** Constraint for X-axis alignment */
|
|
34
|
-
private constraintX?;
|
|
35
|
-
/** Constraint for Y-axis alignment */
|
|
36
|
-
private constraintY?;
|
|
37
|
-
/** Constraint for width relationship */
|
|
38
|
-
private constraintW?;
|
|
39
|
-
/** Constraint for height relationship */
|
|
40
|
-
private constraintH?;
|
|
41
|
-
/** Optional constraint for maintaining strict proportions */
|
|
42
|
-
private constraintStrict?;
|
|
43
|
-
/**
|
|
44
|
-
* Creates a new cover constraint.
|
|
45
|
-
*
|
|
46
|
-
* @param elementOne - The element or layer to be covered (the reference)
|
|
47
|
-
* @param elementTwo - The element that will cover the reference
|
|
48
|
-
* @param parameters - Configuration options
|
|
49
|
-
*/
|
|
50
|
-
constructor(elementOne: UIElement | UILayer, elementTwo: UIElement, parameters?: Partial<UICoverOptions>);
|
|
51
|
-
/**
|
|
52
|
-
* Destroys this constraint, removing it from the constraint system.
|
|
53
|
-
*/
|
|
54
|
-
destroy(): void;
|
|
55
|
-
/**
|
|
56
|
-
* Builds and adds the cover constraints to the constraint solver.
|
|
57
|
-
*
|
|
58
|
-
* Creates five constraints:
|
|
59
|
-
* 1. X alignment between the elements
|
|
60
|
-
* 2. Y alignment between the elements
|
|
61
|
-
* 3. Width covering (elementTwo width ≥ elementOne width)
|
|
62
|
-
* 4. Height covering (elementTwo height ≥ elementOne height)
|
|
63
|
-
* 5. Optional strict proportions (if isStrict = false)
|
|
64
|
-
*
|
|
65
|
-
*/
|
|
66
|
-
protected buildConstraints(): void;
|
|
67
|
-
/**
|
|
68
|
-
* Removes all cover constraints from the constraint solver.
|
|
69
|
-
*
|
|
70
|
-
*/
|
|
71
|
-
protected destroyConstraints(): void;
|
|
72
|
-
}
|