laymur 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +353 -2
  2. package/dist/builders/UIConstraint2DBuilder.d.ts +102 -14
  3. package/dist/composer/UIComposer.d.ts +0 -0
  4. package/dist/composer/UIFullscreenQuad.d.ts +0 -0
  5. package/dist/composer/UIPass.d.ts +0 -0
  6. package/dist/constraints/UIAspectConstraint.d.ts +40 -36
  7. package/dist/constraints/UIConstraint.d.ts +17 -20
  8. package/dist/constraints/UICoverConstraint.d.ts +0 -72
  9. package/dist/constraints/UICustomConstraint.d.ts +60 -0
  10. package/dist/constraints/UIFitConstraint.d.ts +0 -72
  11. package/dist/constraints/UIHeightConstraint.d.ts +32 -38
  12. package/dist/constraints/UIHorizontalDistanceConstraint.d.ts +77 -46
  13. package/dist/constraints/UIHorizontalProportionConstraint.d.ts +49 -40
  14. package/dist/constraints/UISingleParameterConstraint.d.ts +108 -0
  15. package/dist/constraints/UIVerticalDistanceConstraint.d.ts +77 -46
  16. package/dist/constraints/UIVerticalProportionConstraint.d.ts +49 -40
  17. package/dist/constraints/UIWidthConstraint.d.ts +32 -38
  18. package/dist/elements/UIAnchor.d.ts +58 -45
  19. package/dist/elements/UIDummy.d.ts +63 -12
  20. package/dist/elements/UIElement.d.ts +81 -93
  21. package/dist/elements/UIImage.d.ts +64 -33
  22. package/dist/elements/UINineSline.d.ts +0 -0
  23. package/dist/elements/UIProgress.d.ts +7 -95
  24. package/dist/elements/UIScene.d.ts +142 -84
  25. package/dist/elements/UIText.d.ts +124 -43
  26. package/dist/index.d.ts +10 -11
  27. package/dist/index.js +2887 -2716
  28. package/dist/index.js.map +1 -1
  29. package/dist/index.min.js +1 -1
  30. package/dist/index.min.js.map +1 -1
  31. package/dist/layers/UIFullscreenLayer.d.ts +112 -0
  32. package/dist/layers/UILayer.d.ts +134 -57
  33. package/dist/materials/UIInstancedMaterial.d.ts +0 -0
  34. package/dist/materials/UIMaterial.d.ts +6 -6
  35. package/dist/materials/UINineSliceMaterial.d.ts +0 -0
  36. package/dist/materials/UIProgressMaterial.d.ts +0 -4
  37. package/dist/miscellaneous/UIExpression.d.ts +117 -0
  38. package/dist/miscellaneous/UIMicro.d.ts +73 -119
  39. package/dist/miscellaneous/UIOrientation.d.ts +2 -9
  40. package/dist/miscellaneous/UIPriority.d.ts +56 -0
  41. package/dist/miscellaneous/UIRelation.d.ts +43 -0
  42. package/dist/miscellaneous/UITextPadding.d.ts +7 -0
  43. package/dist/miscellaneous/UITextSpan.d.ts +6 -0
  44. package/dist/miscellaneous/UITextStyle.d.ts +18 -0
  45. package/dist/miscellaneous/asserts.d.ts +111 -4
  46. package/dist/miscellaneous/textInterfaces.d.ts +19 -0
  47. package/dist/miscellaneous/textTools.d.ts +8 -5
  48. package/dist/scalable/UIScalableMesh.d.ts +16 -0
  49. package/dist/scalable/UIScalablePlaneMesh.d.ts +14 -0
  50. package/dist/wrappers/UISceneWrapper.d.ts +18 -0
  51. package/dist/wrappers/UISolverWrapper.d.ts +29 -0
  52. package/package.json +1 -1
  53. package/dist/Passes/UIComposer.d.ts +0 -114
  54. package/dist/Passes/UIFullScreenQuad.d.ts +0 -51
  55. package/dist/Passes/UIPass.d.ts +0 -43
  56. package/dist/builders/UIConstraintContainerBuilder.d.ts +0 -20
  57. package/dist/builders/UIConstraintStackBuilder.d.ts +0 -24
  58. package/dist/constraints/UIConstraintPower.d.ts +0 -57
  59. package/dist/constraints/UIConstraintRule.d.ts +0 -46
  60. package/dist/layers/UIFullScreenLayer.d.ts +0 -13
  61. package/dist/miscellaneous/UIBlending.d.ts +0 -7
  62. package/dist/miscellaneous/UITextInterfaces.d.ts +0 -49
  63. package/dist/miscellaneous/math.d.ts +0 -1
  64. package/dist/miscellaneous/microTransformationTools.d.ts +0 -3
@@ -1,176 +1,130 @@
1
- import type { UIElement } from "../elements/UIElement";
2
1
  /**
3
- * Internal implementation of micro-transformations for UI elements.
4
- * Stores the raw transformation values and recalculation flag.
2
+ * Micro-transformation system for non-constraint based UI element adjustments.
5
3
  *
6
- */
7
- export declare class UIMicroInternal {
8
- /** X-axis offset from element position */
9
- x: number;
10
- /** Y-axis offset from element position */
11
- y: number;
12
- /** X-axis anchor point (0-1) where transformations are applied */
13
- anchorX: number;
14
- /** Y-axis anchor point (0-1) where transformations are applied */
15
- anchorY: number;
16
- /** X-axis scaling factor */
17
- scaleX: number;
18
- /** Y-axis scaling factor */
19
- scaleY: number;
20
- /** Rotation in radians */
21
- rotation: number;
22
- /** Flag indicating whether transformations need to be recalculated */
23
- needsRecalculation: boolean;
24
- }
25
- /**
26
- * Provides fine-grained transformations for UI elements.
4
+ * UIMicro provides a lightweight transformation system that operates independently
5
+ * of the constraint solver. It manages position offsets, anchor points, scaling,
6
+ * and rotation transformations that can be applied to UI elements for animations,
7
+ * visual effects, or fine-tuned positioning without affecting the constraint-based
8
+ * layout system.
9
+ *
10
+ * All transformations are tracked with change detection to optimize rendering
11
+ * performance by only recalculating when properties have actually changed.
27
12
  *
28
- * Micro-transformations allow for detailed positioning, scaling, and rotation
29
- * adjustments relative to an element's base position and dimensions.
30
- * These transformations are applied on top of the standard element positioning
31
- * and can be used for effects like pivoting, offsetting, and animation.
13
+ * @see {@link UIElement} - Elements that use micro transformations
32
14
  */
33
15
  export declare class UIMicro {
34
- private readonly raw;
35
- private readonly owner;
36
- /**
37
- * Creates a new micro-transformation interface.
38
- *
39
- * @param raw - The internal state object that stores transformation values
40
- * @param owner - The UI element that owns these transformations
41
- */
42
- constructor(raw: UIMicroInternal, owner: UIElement);
43
- /**
44
- * Gets the X-axis offset from the element's position.
16
+ /** Internal storage for x-coordinate offset. */
17
+ private xInternal;
18
+ /** Internal storage for y-coordinate offset. */
19
+ private yInternal;
20
+ /** Internal storage for x-axis anchor point. */
21
+ private anchorXInternal;
22
+ /** Internal storage for y-axis anchor point. */
23
+ private anchorYInternal;
24
+ /** Internal storage for x-axis scale factor. */
25
+ private scaleXInternal;
26
+ /** Internal storage for y-axis scale factor. */
27
+ private scaleYInternal;
28
+ /** Internal storage for rotation in radians. */
29
+ private rotationInternal;
30
+ /** Flag indicating if any transformation properties have changed. */
31
+ private recalculationRequired;
32
+ /**
33
+ * Gets the x-coordinate offset for micro positioning.
34
+ * @returns The x-offset value
45
35
  */
46
36
  get x(): number;
47
37
  /**
48
- * Gets the Y-axis offset from the element's position.
38
+ * Gets the y-coordinate offset for micro positioning.
39
+ * @returns The y-offset value
49
40
  */
50
41
  get y(): number;
51
42
  /**
52
- * Gets the X-axis anchor point (0-1) where transformations are applied.
53
- *
54
- * - 0.0 = left edge
55
- * - 0.5 = center (default)
56
- * - 1.0 = right edge
43
+ * Gets the x-axis anchor point for transformations.
44
+ * @returns The anchor point (0.0 = left, 0.5 = center, 1.0 = right)
57
45
  */
58
46
  get anchorX(): number;
59
47
  /**
60
- * Gets the Y-axis anchor point (0-1) where transformations are applied.
61
- *
62
- * - 0.0 = top edge
63
- * - 0.5 = center (default)
64
- * - 1.0 = bottom edge
48
+ * Gets the y-axis anchor point for transformations.
49
+ * @returns The anchor point (0.0 = top, 0.5 = center, 1.0 = bottom)
65
50
  */
66
51
  get anchorY(): number;
67
52
  /**
68
- * Gets the X-axis scaling factor.
69
- *
70
- * - 1.0 = normal size (default)
71
- * - > 1.0 = enlarged
72
- * - < 1.0 = reduced
53
+ * Gets the x-axis scale factor.
54
+ * @returns The scale factor (1.0 = normal size)
73
55
  */
74
56
  get scaleX(): number;
75
57
  /**
76
- * Gets the Y-axis scaling factor.
77
- *
78
- * - 1.0 = normal size (default)
79
- * - > 1.0 = enlarged
80
- * - < 1.0 = reduced
58
+ * Gets the y-axis scale factor.
59
+ * @returns The scale factor (1.0 = normal size)
81
60
  */
82
61
  get scaleY(): number;
83
62
  /**
84
- * Gets the rotation in degrees.
85
- * Converted from the internal radians value.
63
+ * Gets the uniform scale factor (maximum of scaleX and scaleY).
64
+ * @returns The larger of the two scale factors
65
+ */
66
+ get size(): number;
67
+ /**
68
+ * Gets the rotation angle in degrees.
69
+ * @returns The rotation angle in degrees
86
70
  */
87
71
  get angle(): number;
88
72
  /**
89
- * Gets the rotation in radians.
73
+ * Gets the rotation angle in radians.
74
+ * @returns The rotation angle in radians
90
75
  */
91
76
  get rotation(): number;
92
77
  /**
93
- * Sets the X-axis offset from the element's position.
94
- *
95
- * @param value - X offset in pixels
78
+ * Sets the x-coordinate offset for micro positioning.
79
+ * @param value - The new x-offset value
96
80
  */
97
81
  set x(value: number);
98
82
  /**
99
- * Sets the Y-axis offset from the element's position.
100
- *
101
- * @param value - Y offset in pixels
83
+ * Sets the y-coordinate offset for micro positioning.
84
+ * @param value - The new y-offset value
102
85
  */
103
86
  set y(value: number);
104
87
  /**
105
- * Sets the X-axis anchor point where transformations are applied.
106
- *
107
- * @param value - X anchor (0-1):
108
- * - 0.0 = left edge
109
- * - 0.5 = center (default)
110
- * - 1.0 = right edge
88
+ * Sets the x-axis anchor point for transformations.
89
+ * @param value - The anchor point (0.0 = left, 0.5 = center, 1.0 = right)
111
90
  */
112
91
  set anchorX(value: number);
113
92
  /**
114
- * Sets the Y-axis anchor point where transformations are applied.
115
- *
116
- * @param value - Y anchor (0-1):
117
- * - 0.0 = top edge
118
- * - 0.5 = center (default)
119
- * - 1.0 = bottom edge
93
+ * Sets the y-axis anchor point for transformations.
94
+ * @param value - The anchor point (0.0 = top, 0.5 = center, 1.0 = bottom)
120
95
  */
121
96
  set anchorY(value: number);
122
97
  /**
123
- * Sets the X-axis scaling factor.
124
- *
125
- * @param value - X scale factor:
126
- * - 1.0 = normal size (default)
127
- * - > 1.0 = enlarged
128
- * - < 1.0 = reduced
98
+ * Sets the x-axis scale factor.
99
+ * @param value - The scale factor (1.0 = normal size)
129
100
  */
130
101
  set scaleX(value: number);
131
102
  /**
132
- * Sets the Y-axis scaling factor.
133
- *
134
- * @param value - Y scale factor:
135
- * - 1.0 = normal size (default)
136
- * - > 1.0 = enlarged
137
- * - < 1.0 = reduced
103
+ * Sets the y-axis scale factor.
104
+ * @param value - The scale factor (1.0 = normal size)
138
105
  */
139
106
  set scaleY(value: number);
140
107
  /**
141
- * Sets the rotation in degrees.
142
- * Automatically converts to radians for internal storage.
143
- *
144
- * @param value - Rotation angle in degrees
108
+ * Sets both scale factors to the same value for uniform scaling.
109
+ * @param value - The uniform scale factor (1.0 = normal size)
145
110
  */
146
- set angle(value: number);
111
+ set size(value: number);
147
112
  /**
148
- * Sets the rotation in radians.
149
- *
150
- * @param value - Rotation angle in radians
113
+ * Sets the rotation angle in degrees.
114
+ * @param value - The rotation angle in degrees
151
115
  */
152
- set rotation(value: number);
116
+ set angle(value: number);
153
117
  /**
154
- * Sets the anchor point based on global coordinates relative to the element.
155
- * Converts the global position to a normalized anchor point (0-1 range).
156
- *
157
- * This is useful for setting the pivot point to a specific position,
158
- * such as making an element rotate around a particular point.
159
- *
160
- * @param x - Global X coordinate to set as anchor
161
- * @param y - Global Y coordinate to set as anchor
118
+ * Sets the rotation angle in radians.
119
+ * @param value - The rotation angle in radians
162
120
  */
163
- setAnchorByGlobalPosition(x: number, y: number): void;
121
+ set rotation(value: number);
164
122
  /**
165
- * Resets all micro-transformations to their default values.
166
- *
167
- * Default values:
168
- * - Position (x, y): 0
169
- * - Anchor (anchorX, anchorY): 0.5 (centered)
170
- * - Scale (scaleX, scaleY): 1.0 (original size)
171
- * - Rotation: 0 (no rotation)
123
+ * Resets all transformation properties to their default values.
172
124
  *
173
- * Only triggers recalculation if any values were changed.
125
+ * This method restores position (0,0), anchor (0,0), scale (1,1),
126
+ * and rotation (0) to their initial states. Only triggers recalculation
127
+ * if any values actually change.
174
128
  */
175
129
  reset(): void;
176
130
  }
@@ -9,25 +9,18 @@ export declare enum UIOrientation {
9
9
  * Indicates a landscape orientation (width > height).
10
10
  * Constraints using this value will only be active in landscape mode.
11
11
  */
12
- LANDSCAPE = 0,
12
+ HORIZONTAL = 0,
13
13
  /**
14
14
  * Indicates a portrait orientation (height > width).
15
15
  * Constraints using this value will only be active in portrait mode.
16
16
  */
17
- PORTRAIT = 1,
17
+ VERTICAL = 1,
18
18
  /**
19
19
  * Indicates that the constraint should always be active,
20
20
  * regardless of screen orientation.
21
21
  */
22
22
  ALWAYS = 2
23
23
  }
24
- /**
25
- * Type guard to check if a value is a valid UIOrientation.
26
- *
27
- * @param obj - The value to check
28
- * @returns True if the value is a valid UIOrientation enum value
29
- */
30
- export declare function isUIOrientation(obj: unknown): obj is UIOrientation;
31
24
  /**
32
25
  * Resolves an optional orientation to a definite value.
33
26
  *
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Priority levels for UI layout constraints and variables.
3
+ *
4
+ * UIPriority defines a hierarchical system of priority levels used by the
5
+ * constraint solver to determine which constraints should take precedence
6
+ * when conflicts arise. Lower numeric values represent higher priority,
7
+ * with P0 being the highest priority and P7 being the lowest.
8
+ *
9
+ * The priority system maps to Kiwi solver strength values with different
10
+ * strength components (required, strong, medium, weak) to create a nuanced
11
+ * priority hierarchy for layout solving.
12
+ *
13
+ * @see {@link convertPriority} - Converts to Kiwi solver strength values
14
+ */
15
+ export declare enum UIPriority {
16
+ /** Highest priority - required constraints that must be satisfied. */
17
+ P0 = 0,
18
+ /** High priority - strong constraints with medium strength. */
19
+ P1 = 1,
20
+ /** Medium-high priority - strong constraints with low strength. */
21
+ P2 = 2,
22
+ /** Medium priority - medium strength constraints. */
23
+ P3 = 3,
24
+ /** Medium-low priority - medium strength constraints with low weight. */
25
+ P4 = 4,
26
+ /** Low priority - weak strength constraints with medium weight. */
27
+ P5 = 5,
28
+ /** Very low priority - weak strength constraints with low weight. */
29
+ P6 = 6,
30
+ /** Lowest priority - weak strength constraints with minimal weight. */
31
+ P7 = 7
32
+ }
33
+ /**
34
+ * Converts UIPriority enum values to Kiwi solver strength values.
35
+ *
36
+ * This function maps the UI priority levels to the three-component strength
37
+ * system used by the Kiwi constraint solver (required, strong, medium, weak).
38
+ * Higher priority levels get stronger constraint strength values.
39
+ *
40
+ * @param priority - The UI priority level to convert
41
+ * @returns The corresponding Kiwi solver strength value
42
+ * @throws Will throw an error if an invalid priority is provided
43
+ * @see {@link UIPriority} - Priority level definitions
44
+ */
45
+ export declare function convertPriority(priority: UIPriority): number;
46
+ /**
47
+ * Resolves an optional priority value to a concrete UIPriority.
48
+ *
49
+ * If no priority is provided, returns the default highest priority (P0).
50
+ * This function is commonly used in constraint creation where priority
51
+ * is an optional parameter.
52
+ *
53
+ * @param priority - The optional priority value to resolve
54
+ * @returns The resolved priority, defaulting to P0 if undefined
55
+ */
56
+ export declare function resolvePriority(priority?: UIPriority): UIPriority;
@@ -0,0 +1,43 @@
1
+ import { Operator } from "@lume/kiwi";
2
+ /**
3
+ * Relational operators for UI layout constraints.
4
+ *
5
+ * UIRelation defines the mathematical relationship between the left-hand
6
+ * and right-hand sides of constraint equations. These relations are used
7
+ * by the constraint solver to determine how expressions should be compared
8
+ * when solving layout constraints.
9
+ *
10
+ * @see {@link convertRelation} - Converts to Kiwi solver operators
11
+ */
12
+ export declare enum UIRelation {
13
+ /** Equality relation: left-hand side equals right-hand side. */
14
+ EQUAL = 0,
15
+ /** Less than or equal relation: left-hand side ≤ right-hand side. */
16
+ LESS_THAN = 1,
17
+ /** Greater than or equal relation: left-hand side ≥ right-hand side. */
18
+ GREATER_THAN = 2
19
+ }
20
+ /**
21
+ * Converts UIRelation enum values to Kiwi solver operator values.
22
+ *
23
+ * This function maps the UI relation types to the corresponding operators
24
+ * used by the Kiwi constraint solver for mathematical comparisons in
25
+ * constraint equations.
26
+ *
27
+ * @param relation - The UI relation type to convert
28
+ * @returns The corresponding Kiwi solver operator
29
+ * @throws Will throw an error if an invalid relation is provided
30
+ * @see {@link UIRelation} - Relation type definitions
31
+ */
32
+ export declare function convertRelation(relation: UIRelation): Operator;
33
+ /**
34
+ * Resolves an optional relation value to a concrete UIRelation.
35
+ *
36
+ * If no relation is provided, returns the default equality relation.
37
+ * This function is commonly used in constraint creation where relation
38
+ * is an optional parameter.
39
+ *
40
+ * @param relation - The optional relation value to resolve
41
+ * @returns The resolved relation, defaulting to EQUAL if undefined
42
+ */
43
+ export declare function resolveRelation(relation?: UIRelation): UIRelation;
@@ -0,0 +1,7 @@
1
+ export interface UITextPadding {
2
+ left: number;
3
+ right: number;
4
+ top: number;
5
+ bottom: number;
6
+ }
7
+ export declare function resolvePadding(value: unknown): UITextPadding;
@@ -0,0 +1,6 @@
1
+ import { type UITextStyle } from "./UITextStyle";
2
+ export interface UITextSpan {
3
+ text: string;
4
+ style?: Partial<UITextStyle>;
5
+ }
6
+ export declare function isUITextSpan(obj?: unknown): obj is UITextSpan;
@@ -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;
@@ -1,5 +1,112 @@
1
- import type { UIAnchor } from "../elements/UIAnchor";
2
- import type { UIElement } from "../elements/UIElement";
3
1
  import { UILayer } from "../layers/UILayer";
4
- export declare function assertSameLayer(elementOne: UIElement | UIAnchor | UILayer, elementTwo: UIElement | UIAnchor, message?: string): void;
5
- export declare function assertSize(width: number, height: number, message?: string): void;
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
+ }
@@ -1,9 +1,12 @@
1
- import type { UIChunkMetrics, UITextChunk, UITextLine, UITextPadding, UITextSize, UITextStyle } from "./UITextInterfaces";
2
- export declare function resolvePadding(padding?: Partial<UITextPadding> | number): UITextPadding;
3
- export declare function resolveTextStyle(currentStyle?: Partial<UITextStyle>, baseStyle?: Partial<UITextStyle>): UITextStyle;
1
+ import type { UIChunkMetrics, UITextChunk, UITextContent, UITextLine, UITextSize } from "./textInterfaces";
2
+ import { type UITextStyle } from "./UITextStyle";
4
3
  export declare function splitText(text: string): string[];
5
4
  export declare function measureTextChunk(context: CanvasRenderingContext2D, chunk: string, style: UITextStyle): UIChunkMetrics;
6
- export declare function wrapTextLines(maxWidth: number, chunks: UITextChunk[]): UITextLine[];
7
- export declare function calculateTextBlockSize(lines: UITextLine[]): UITextSize;
5
+ export declare function buildLines(maxWidth: number, chunks: UITextChunk[]): UITextLine[];
6
+ export declare function calculateTextSize(lines: UITextLine[]): UITextSize;
8
7
  export declare function renderText(x: number, y: number, text: string, style: UITextStyle, context: CanvasRenderingContext2D): void;
9
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.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Lightweight Three.js UI toolkit mainly for mobile ads",
5
5
  "scripts": {
6
6
  "clean": "rm -rf dist",