laymur 0.3.16 → 0.3.19

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.
@@ -1,116 +1,49 @@
1
1
  import { type Camera, type Vector3, type WebGLRenderer } from "three";
2
+ import type { UIResizePolicy } from "../miscellaneous/resizePolicies";
2
3
  import { UILayer } from "./UILayer";
3
4
  /**
4
- * UI layer that manages fullscreen interfaces with optional fixed dimensions and automatic scaling.
5
+ * UI layer that covers the full browser window.
5
6
  *
6
- * UIFullscreenLayer extends UILayer to provide automatic browser window integration,
7
- * handling window resize events and pointer interactions. It supports optional fixed
8
- * width or height constraints that enable responsive scaling while maintaining
9
- * design proportions across different screen sizes.
7
+ * Handles window resize and pointer events automatically. Scaling is controlled
8
+ * by the assigned resize policy.
10
9
  *
11
- * The layer automatically calculates scaling factors based on the orientation and
12
- * fixed dimension constraints, ensuring consistent layout appearance regardless
13
- * of the actual browser window size.
14
- *
15
- * @see {@link UILayer} - Base layer functionality
16
- * @see {@link UIOrientation} - Orientation-based scaling behavior
10
+ * @see {@link UILayer}
11
+ * @see {@link UIResizePolicy}
17
12
  */
18
13
  export declare class UIFullscreenLayer extends UILayer {
19
- /** Internal storage for the optional fixed width constraint. */
20
- private fixedWidthInternal?;
21
- /** Internal storage for the optional fixed height constraint. */
22
- private fixedHeightInternal?;
23
- /**
24
- * Creates a new UIFullscreenLayer instance with optional fixed dimensions.
25
- *
26
- * The layer will automatically resize to match the browser window and set up
27
- * event listeners for window resize and pointer events. Fixed dimensions
28
- * enable proportional scaling while maintaining design aspect ratios.
29
- *
30
- * @param fixedWidth - Optional fixed width for proportional scaling
31
- * @param fixedHeight - Optional fixed height for proportional scaling
32
- * @throws Will throw an error if fixed dimensions are not valid positive numbers
33
- * @see {@link assertValidPositiveNumber}
34
- */
35
- constructor(fixedWidth: number | undefined, fixedHeight: number | undefined);
14
+ resizePolicy: UIResizePolicy;
36
15
  /**
37
- * Gets the current fixed width constraint.
38
- * @returns The fixed width in pixels, or undefined if not set
16
+ * Creates a fullscreen layer and sets up window event listeners.
39
17
  */
40
- get fixedWidth(): number | undefined;
18
+ constructor();
41
19
  /**
42
- * Gets the current fixed height constraint.
43
- * @returns The fixed height in pixels, or undefined if not set
44
- */
45
- get fixedHeight(): number | undefined;
46
- /**
47
- * Sets a new fixed width constraint and triggers resize recalculation.
48
- * @param value - The new fixed width in pixels, or undefined to remove constraint
49
- * @throws Will throw an error if value is not a valid positive number
50
- * @see {@link assertValidPositiveNumber}
51
- */
52
- set fixedWidth(value: number | undefined);
53
- /**
54
- * Sets a new fixed height constraint and triggers resize recalculation.
55
- * @param value - The new fixed height in pixels, or undefined to remove constraint
56
- * @throws Will throw an error if value is not a valid positive number
57
- * @see {@link assertValidPositiveNumber}
58
- */
59
- set fixedHeight(value: number | undefined);
60
- /**
61
- * Destroys the fullscreen layer by removing all event listeners.
62
- *
63
- * This method cleans up window event listeners for resize and pointer events.
64
- * After calling this method, the layer will no longer respond to window
65
- * changes and should not be used anymore.
20
+ * Removes window event listeners. The layer should not be used after this.
66
21
  */
67
22
  destroy(): void;
68
23
  /**
69
- * Renders the fullscreen layer and all its contained elements.
70
- *
71
- * Clears the depth and stencil buffers and delegates rendering to the
72
- * parent layer's render method. This ensures proper rendering order
73
- * and buffer management for fullscreen interfaces.
24
+ * Renders the layer.
74
25
  *
75
- * @param renderer - The WebGL renderer instance
76
- * @param deltaTime - Time elapsed since the last frame in seconds
77
- * @throws Will throw an error if deltaTime is not a valid number
78
- * @see {@link assertValidNumber}
26
+ * @param renderer - WebGL renderer
27
+ * @param deltaTime - Time since last frame in seconds
79
28
  */
80
29
  render(renderer: WebGLRenderer, deltaTime: number): void;
81
30
  /**
82
- * Projects a 3D world position to 2D screen coordinates within this layer.
31
+ * Projects 3D world position to 2D layer coordinates.
83
32
  *
84
- * @param position - The 3D world position to project
85
- * @param camera - The camera used for projection
86
- * @returns The projected 2D position in layer coordinates
33
+ * @param position - 3D world position
34
+ * @param camera - Camera for projection
35
+ * @returns 2D position in layer space
87
36
  */
88
37
  projectWorldPosition(position: Vector3, camera: Camera): Vector3;
89
38
  /**
90
- * Calculates the scaling factor based on orientation and fixed dimensions.
91
- *
92
- * The scaling factor is determined by the current orientation and which
93
- * fixed dimension constraint is active. In horizontal orientation, fixed
94
- * width takes precedence; in vertical orientation, fixed height takes precedence.
95
- *
96
- * @returns The scaling factor to apply to window dimensions
97
- */
98
- private calculateScale;
99
- /**
100
- * Event handler for window resize events.
101
- *
102
- * Recalculates the scaling factor and updates the layer dimensions
103
- * based on the new window size and fixed dimension constraints.
39
+ * Handles window resize. Updates layer dimensions according to resize policy.
104
40
  */
105
41
  private readonly onResize;
106
42
  /**
107
- * Event handler for pointer down events.
108
- *
109
- * Converts browser pointer coordinates to layer coordinates by accounting
110
- * for element positioning and applying the appropriate scaling factor.
111
- * The y-coordinate is flipped to match the UI coordinate system.
43
+ * Handles pointer down. Converts browser coordinates to layer space.
44
+ * Y-coordinate is flipped to match UI coordinate system.
112
45
  *
113
- * @param event - The pointer event from the browser
46
+ * @param event - Browser pointer event
114
47
  */
115
48
  private readonly onClick;
116
49
  }
@@ -1,4 +1,8 @@
1
+ import { Eventail } from "eventail";
1
2
  import { UIMicroAnchorMode } from "./UIMicroAnchorMode";
3
+ export declare enum UIMicroEvent {
4
+ CHANGE = 0
5
+ }
2
6
  /**
3
7
  * Micro-transformation system for non-constraint based UI element adjustments.
4
8
  *
@@ -13,7 +17,7 @@ import { UIMicroAnchorMode } from "./UIMicroAnchorMode";
13
17
  *
14
18
  * @see {@link UIElement} - Elements that use micro transformations
15
19
  */
16
- export declare class UIMicro {
20
+ export declare class UIMicro extends Eventail {
17
21
  /** Internal storage for x-coordinate offset. */
18
22
  private xInternal;
19
23
  /** Internal storage for y-coordinate offset. */
@@ -140,4 +144,5 @@ export declare class UIMicro {
140
144
  * if any values actually change.
141
145
  */
142
146
  reset(): void;
147
+ copy(value: UIMicro): void;
143
148
  }
@@ -1,7 +1,7 @@
1
- export interface UITextPadding {
1
+ export interface UIPadding {
2
2
  left: number;
3
3
  right: number;
4
4
  top: number;
5
5
  bottom: number;
6
6
  }
7
- export declare function resolveTextPadding(value: unknown): UITextPadding;
7
+ export declare function resolveTextPadding(value: unknown): UIPadding;
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Base class for UI resize policies.
3
+ *
4
+ * Calculates scale factors based on viewport dimensions. Different policies
5
+ * implement different scaling strategies.
6
+ */
7
+ export declare abstract class UIResizePolicy {
8
+ /**
9
+ * Calculates scale factor for given dimensions.
10
+ *
11
+ * @param width - Viewport width in pixels
12
+ * @param height - Viewport height in pixels
13
+ * @returns Scale factor to apply
14
+ * @protected
15
+ */
16
+ abstract calculateScaleInternal(width: number, height: number): number;
17
+ }
18
+ /**
19
+ * No scaling applied, always returns 1:1 scale.
20
+ */
21
+ export declare class UIResizePolicyNone extends UIResizePolicy {
22
+ calculateScaleInternal(width: number, height: number): number;
23
+ }
24
+ /**
25
+ * Maintains fixed width, scales based on window width.
26
+ *
27
+ * Uses different widths for landscape vs portrait orientation.
28
+ */
29
+ export declare class UIResizePolicyFixedWidth extends UIResizePolicy {
30
+ fixedWidthLandscape: number;
31
+ fixedWidthPortrait: number;
32
+ /**
33
+ * @param fixedWidthLandscape - Target width for landscape (width > height)
34
+ * @param fixedWidthPortrait - Target width for portrait (width <= height)
35
+ */
36
+ constructor(fixedWidthLandscape: number, fixedWidthPortrait: number);
37
+ calculateScaleInternal(width: number, height: number): number;
38
+ }
39
+ /**
40
+ * Maintains fixed height, scales based on window height.
41
+ *
42
+ * Uses different heights for landscape vs portrait orientation.
43
+ */
44
+ export declare class UIResizePolicyFixedHeight extends UIResizePolicy {
45
+ fixedHeightLandscape: number;
46
+ fixedHeightPortrait: number;
47
+ /**
48
+ * @param fixedHeightLandscape - Target height for landscape (width > height)
49
+ * @param fixedHeightPortrait - Target height for portrait (width <= height)
50
+ */
51
+ constructor(fixedHeightLandscape: number, fixedHeightPortrait: number);
52
+ calculateScaleInternal(width: number, height: number): number;
53
+ }
54
+ /**
55
+ * Scales by width in landscape, by height in portrait.
56
+ */
57
+ export declare class UIResizePolicyCross extends UIResizePolicy {
58
+ fixedWidthLandscape: number;
59
+ fixedHeightPortrait: number;
60
+ /**
61
+ * @param fixedWidthLandscape - Target width for landscape
62
+ * @param fixedHeightPortrait - Target height for portrait
63
+ */
64
+ constructor(fixedWidthLandscape: number, fixedHeightPortrait: number);
65
+ calculateScaleInternal(width: number, height: number): number;
66
+ }
67
+ /**
68
+ * Scales by height in landscape, by width in portrait.
69
+ */
70
+ export declare class UIResizePolicyCrossInverted extends UIResizePolicy {
71
+ fixedHeightLandscape: number;
72
+ fixedWidthPortrait: number;
73
+ /**
74
+ * @param fixedHeightLandscape - Target height for landscape
75
+ * @param fixedWidthPortrait - Target width for portrait
76
+ */
77
+ constructor(fixedHeightLandscape: number, fixedWidthPortrait: number);
78
+ calculateScaleInternal(width: number, height: number): number;
79
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "laymur",
3
- "version": "0.3.16",
3
+ "version": "0.3.19",
4
4
  "description": "Constraint-based UI library for Three.js mobile advertisements",
5
5
  "scripts": {
6
6
  "clean": "rm -rf dist",