laymur 0.14.2 → 0.15.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 +98 -35
- package/dist/elements/UIAnchor/UIAnchor.d.ts +1 -2
- package/dist/elements/UIAnimatedImage/UIAnimatedImage.Internal.d.ts +0 -9
- package/dist/elements/UIAnimatedImage/UIAnimatedImage.d.ts +10 -0
- package/dist/elements/UIElement/UIElement.d.ts +1 -0
- package/dist/elements/UIGraphics/UIGraphics.d.ts +1 -1
- package/dist/elements/UIInputDummy/UIInputDummy.Internal.d.ts +12 -0
- package/dist/elements/UIInputDummy/UIInputDummy.d.ts +19 -3
- package/dist/index.d.ts +0 -1
- package/dist/index.js +150 -149
- 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/UIFullscreenLayer.Internal.d.ts +12 -0
- package/dist/layers/UIFullscreenLayer/UIFullscreenLayer.d.ts +11 -1
- package/dist/layers/UILayer/UILayer.Internal.d.ts +0 -9
- package/dist/layers/UILayer/UILayer.d.ts +11 -2
- package/dist/miscellaneous/mask-function/UIProgressMaskFunctionDirectional.d.ts +1 -1
- package/dist/miscellaneous/texture/UITextureView.Internal.d.ts +0 -5
- package/dist/miscellaneous/texture/UITextureView.d.ts +4 -2
- package/package.json +3 -3
- package/dist/miscellaneous/UIInputEvent.d.ts +0 -13
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
<a href="https://www.npmjs.com/package/laymur"><img src="https://img.shields.io/npm/v/laymur.svg" alt="npm version"></a>
|
|
10
10
|
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT"></a>
|
|
11
11
|
<a href="https://www.typescriptlang.org/"><img src="https://img.shields.io/badge/TypeScript-%5E5.8.0-blue" alt="TypeScript"></a>
|
|
12
|
-
<a href="https://threejs.org/"><img src="https://img.shields.io/badge/Three.js-0.
|
|
12
|
+
<a href="https://threejs.org/"><img src="https://img.shields.io/badge/Three.js-0.157.0--0.180.0-green" alt="Three.js"></a>
|
|
13
13
|
</p>
|
|
14
14
|
|
|
15
15
|
⚠️ **Early Alpha / Work in Progress** ⚠️
|
|
@@ -39,19 +39,19 @@ Requires Three.js >=0.175.0 <0.180.0 as a peer dependency.
|
|
|
39
39
|
## Quick Example
|
|
40
40
|
|
|
41
41
|
```typescript
|
|
42
|
-
import { UIFullscreenLayer, UIImage, UIText } from
|
|
43
|
-
import { WebGLRenderer, TextureLoader, Clock } from
|
|
42
|
+
import { UIFullscreenLayer, UIImage, UIText } from "laymur";
|
|
43
|
+
import { WebGLRenderer, TextureLoader, Clock } from "three";
|
|
44
44
|
|
|
45
45
|
const renderer = new WebGLRenderer();
|
|
46
46
|
const layer = new UIFullscreenLayer();
|
|
47
47
|
const clock = new Clock();
|
|
48
48
|
|
|
49
|
-
const texture = new TextureLoader().load(
|
|
49
|
+
const texture = new TextureLoader().load("background.jpg");
|
|
50
50
|
const background = new UIImage(layer, texture, { x: 0, y: 0 });
|
|
51
|
-
const title = new UIText(layer,
|
|
51
|
+
const title = new UIText(layer, "Mobile Ad Title", {
|
|
52
52
|
x: 100,
|
|
53
53
|
y: 100,
|
|
54
|
-
maxLineWidth: 800
|
|
54
|
+
maxLineWidth: 800,
|
|
55
55
|
});
|
|
56
56
|
|
|
57
57
|
function animate() {
|
|
@@ -65,9 +65,11 @@ animate();
|
|
|
65
65
|
## Basic Components
|
|
66
66
|
|
|
67
67
|
### Layers
|
|
68
|
+
|
|
68
69
|
- **UIFullscreenLayer** - Handles browser window scaling
|
|
69
70
|
|
|
70
71
|
### Elements
|
|
72
|
+
|
|
71
73
|
- **UIImage** - Display textures
|
|
72
74
|
- **UIAnimatedImage** - Animated texture sequences
|
|
73
75
|
- **UIText** - Text rendering with word wrapping and styled spans
|
|
@@ -78,6 +80,7 @@ animate();
|
|
|
78
80
|
- **UIAnchor** - Positioning points
|
|
79
81
|
|
|
80
82
|
### Constraints
|
|
83
|
+
|
|
81
84
|
- **UIWidthConstraint** / **UIHeightConstraint** - Fixed sizes
|
|
82
85
|
- **UIAspectConstraint** - Maintain aspect ratios
|
|
83
86
|
- **UIHorizontalDistanceConstraint** / **UIVerticalDistanceConstraint** - Spacing between elements
|
|
@@ -92,7 +95,7 @@ animate();
|
|
|
92
95
|
The constraint system automatically calculates positions and sizes based on relationships you define:
|
|
93
96
|
|
|
94
97
|
```typescript
|
|
95
|
-
import { UIImage, UIHorizontalDistanceConstraint, UIWidthConstraint } from
|
|
98
|
+
import { UIImage, UIHorizontalDistanceConstraint, UIWidthConstraint } from "laymur";
|
|
96
99
|
|
|
97
100
|
const sidebar = new UIImage(layer, sidebarTexture, { x: 0, y: 0 });
|
|
98
101
|
const content = new UIImage(layer, contentTexture, { x: 0, y: 0 });
|
|
@@ -103,8 +106,8 @@ new UIWidthConstraint(sidebar, { width: 300 });
|
|
|
103
106
|
// 20px spacing between sidebar and content
|
|
104
107
|
new UIHorizontalDistanceConstraint(sidebar, content, {
|
|
105
108
|
distance: 20,
|
|
106
|
-
anchorA: 1.0,
|
|
107
|
-
anchorB: 0.0
|
|
109
|
+
anchorA: 1.0, // Right edge of sidebar
|
|
110
|
+
anchorB: 0.0, // Left edge of content
|
|
108
111
|
});
|
|
109
112
|
```
|
|
110
113
|
|
|
@@ -113,16 +116,20 @@ new UIHorizontalDistanceConstraint(sidebar, content, {
|
|
|
113
116
|
Text supports styled spans with different fonts, sizes, and colors:
|
|
114
117
|
|
|
115
118
|
```typescript
|
|
116
|
-
import { UIText } from
|
|
117
|
-
|
|
118
|
-
const text = new UIText(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
119
|
+
import { UIText } from "laymur";
|
|
120
|
+
|
|
121
|
+
const text = new UIText(
|
|
122
|
+
layer,
|
|
123
|
+
[
|
|
124
|
+
{ text: "Download ", style: { fontSize: 24, color: "#333333" } },
|
|
125
|
+
{ text: "Now!", style: { fontSize: 32, color: "#ff0000", fontWeight: "bold" } },
|
|
126
|
+
],
|
|
127
|
+
{
|
|
128
|
+
x: 100,
|
|
129
|
+
y: 100,
|
|
130
|
+
maxLineWidth: 600,
|
|
131
|
+
},
|
|
132
|
+
);
|
|
126
133
|
```
|
|
127
134
|
|
|
128
135
|
## Transformations
|
|
@@ -136,7 +143,7 @@ const element = new UIImage(layer, texture, { x: 0, y: 0 });
|
|
|
136
143
|
element.micro.x = 10;
|
|
137
144
|
element.micro.scaleX = 1.2;
|
|
138
145
|
element.micro.rotation = 0.1;
|
|
139
|
-
element.micro.anchorX = 0.5;
|
|
146
|
+
element.micro.anchorX = 0.5; // Transform origin (0 = left/bottom, 0.5 = center, 1 = right/top)
|
|
140
147
|
|
|
141
148
|
// Reset all transformations
|
|
142
149
|
element.micro.reset();
|
|
@@ -144,40 +151,96 @@ element.micro.reset();
|
|
|
144
151
|
|
|
145
152
|
## Event Handling
|
|
146
153
|
|
|
147
|
-
UI elements
|
|
154
|
+
UI elements and layers use type-safe signals for event handling via [Ferrsign](https://github.com/jango-git/ferrsign).
|
|
155
|
+
|
|
156
|
+
### Element Input Events
|
|
157
|
+
|
|
158
|
+
Elements with area (width and height) can emit input events:
|
|
148
159
|
|
|
149
160
|
```typescript
|
|
150
|
-
import {
|
|
161
|
+
import { UIMode } from "laymur";
|
|
162
|
+
import type { UIInputEventData } from "laymur";
|
|
151
163
|
|
|
152
|
-
// Element events
|
|
153
164
|
const button = new UIImage(layer, buttonTexture, {
|
|
154
165
|
x: 0,
|
|
155
166
|
y: 0,
|
|
156
|
-
mode: UIMode.INTERACTIVE
|
|
167
|
+
mode: UIMode.INTERACTIVE,
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
button.signalPressed.on((data: UIInputEventData) => {
|
|
171
|
+
console.log("Button pressed at", data.x, data.y);
|
|
172
|
+
console.log("Element:", data.element);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
button.signalReleased.on((data: UIInputEventData) => {
|
|
176
|
+
console.log("Button released");
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
button.signalEntered.on((data: UIInputEventData) => {
|
|
180
|
+
console.log("Pointer entered button");
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
button.signalLeft.on((data: UIInputEventData) => {
|
|
184
|
+
console.log("Pointer left button");
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
button.signalMoved.on((data: UIInputEventData) => {
|
|
188
|
+
console.log("Pointer moved inside button");
|
|
157
189
|
});
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Layer Events
|
|
158
193
|
|
|
159
|
-
|
|
160
|
-
|
|
194
|
+
Fullscreen layers emit input events:
|
|
195
|
+
|
|
196
|
+
```typescript
|
|
197
|
+
import type { UIFullscreenLayerInputEventData } from "laymur";
|
|
198
|
+
|
|
199
|
+
layer.signalPressed.on((data: UIFullscreenLayerInputEventData) => {
|
|
200
|
+
console.log("Layer pressed at", data.x, data.y);
|
|
201
|
+
console.log("Layer:", data.layer);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
layer.signalMoved.on((data: UIFullscreenLayerInputEventData) => {
|
|
205
|
+
console.log("Pointer moved to", data.x, data.y);
|
|
161
206
|
});
|
|
162
207
|
|
|
163
|
-
|
|
164
|
-
console.log(
|
|
208
|
+
layer.signalReleased.on((data: UIFullscreenLayerInputEventData) => {
|
|
209
|
+
console.log("Pointer released");
|
|
165
210
|
});
|
|
211
|
+
```
|
|
166
212
|
|
|
167
|
-
|
|
168
|
-
|
|
213
|
+
### Animation Events
|
|
214
|
+
|
|
215
|
+
Animated images emit playback events:
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
const animation = new UIAnimatedImage(layer, frames);
|
|
219
|
+
|
|
220
|
+
animation.signalPlayed.on(() => {
|
|
221
|
+
console.log("Animation started or resumed");
|
|
169
222
|
});
|
|
170
223
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
console.log('Layer pressed at', x, y);
|
|
224
|
+
animation.signalPaused.on(() => {
|
|
225
|
+
console.log("Animation paused");
|
|
174
226
|
});
|
|
175
227
|
|
|
176
|
-
|
|
177
|
-
console.log(
|
|
228
|
+
animation.signalStopped.on(() => {
|
|
229
|
+
console.log("Animation stopped and reset");
|
|
178
230
|
});
|
|
179
231
|
```
|
|
180
232
|
|
|
233
|
+
### Unsubscribing from Events
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
const handler = (data: UIInputEventData) => {
|
|
237
|
+
console.log("Pressed!");
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
button.signalPressed.on(handler);
|
|
241
|
+
button.signalPressed.off(handler); // Unsubscribe
|
|
242
|
+
```
|
|
243
|
+
|
|
181
244
|
## Live Examples
|
|
182
245
|
|
|
183
246
|
🎮 **[Live Examples](https://jango-git.github.io/laymur/)** - See constraint-based layouts and responsive components in action.
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { Eventail } from "eventail";
|
|
2
1
|
import type { UILayer } from "../../layers/UILayer/UILayer";
|
|
3
2
|
import type { UILayerElement, UIPointElement } from "../../miscellaneous/shared";
|
|
4
3
|
import type { UISolverWrapperInterface } from "../../wrappers/UISolverWrapper/UISolverWrapper.Internal";
|
|
5
4
|
import type { UIAnchorOptions } from "./UIAnchor.Internal";
|
|
6
5
|
/** Point in 2D space with constraint-based positioning */
|
|
7
|
-
export declare class UIAnchor
|
|
6
|
+
export declare class UIAnchor implements UILayerElement, UIPointElement {
|
|
8
7
|
readonly layer: UILayer;
|
|
9
8
|
/** Optional identifier for debugging */
|
|
10
9
|
name: string;
|
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
import type { UIColorConfig } from "../../miscellaneous/color/UIColor.Internal";
|
|
2
2
|
import type { UIElementOptions } from "../UIElement/UIElement.Internal";
|
|
3
|
-
/** Animation playback events */
|
|
4
|
-
export declare enum UIAnimatedImageEvent {
|
|
5
|
-
/** Animation started or resumed */
|
|
6
|
-
PLAYED = 0,
|
|
7
|
-
/** Animation paused */
|
|
8
|
-
PAUSED = 1,
|
|
9
|
-
/** Animation stopped and reset */
|
|
10
|
-
STOPPED = 2
|
|
11
|
-
}
|
|
12
3
|
/** Animation loop behavior */
|
|
13
4
|
export declare enum UIAnimatedImageLoopMode {
|
|
14
5
|
/** No looping, stops at boundary frame */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { FerrsignView0 } from "ferrsign";
|
|
1
2
|
import type { WebGLRenderer } from "three";
|
|
2
3
|
import type { UILayer } from "../../layers/UILayer/UILayer";
|
|
3
4
|
import { UIColor } from "../../miscellaneous/color/UIColor";
|
|
@@ -19,6 +20,9 @@ export declare class UIAnimatedImage extends UIElement {
|
|
|
19
20
|
private sequenceFrameIndex;
|
|
20
21
|
private currentFrameIndexDirty;
|
|
21
22
|
private accumulatedTime;
|
|
23
|
+
private readonly signalPlayedInternal;
|
|
24
|
+
private readonly signalPausedInternal;
|
|
25
|
+
private readonly signalStoppedInternal;
|
|
22
26
|
/**
|
|
23
27
|
* Creates a new UIAnimatedImage instance.
|
|
24
28
|
*
|
|
@@ -41,6 +45,12 @@ export declare class UIAnimatedImage extends UIElement {
|
|
|
41
45
|
get sequence(): readonly UITextureView[];
|
|
42
46
|
/** Playback speed multiplier. Can be negative for reverse playback. */
|
|
43
47
|
get timeScale(): number;
|
|
48
|
+
/** Signal fired when animation starts or resumes */
|
|
49
|
+
get signalPlayed(): FerrsignView0;
|
|
50
|
+
/** Signal fired when animation pauses */
|
|
51
|
+
get signalPaused(): FerrsignView0;
|
|
52
|
+
/** Signal fired when animation stops and resets */
|
|
53
|
+
get signalStopped(): FerrsignView0;
|
|
44
54
|
/** Multiplicative tint. Alpha channel controls opacity. */
|
|
45
55
|
set color(value: UIColorConfig);
|
|
46
56
|
/** Animation speed in frames per second */
|
|
@@ -3,7 +3,7 @@ import type { UILayer } from "../../layers/UILayer/UILayer";
|
|
|
3
3
|
import { UIColor } from "../../miscellaneous/color/UIColor";
|
|
4
4
|
import type { UIColorConfig } from "../../miscellaneous/color/UIColor.Internal";
|
|
5
5
|
import { UIElement } from "../UIElement/UIElement";
|
|
6
|
-
import {
|
|
6
|
+
import type { UIGraphicsOptions } from "./UIGraphics.Internal";
|
|
7
7
|
/** Canvas-based 2D drawing element */
|
|
8
8
|
export declare class UIGraphics extends UIElement {
|
|
9
9
|
private readonly colorInternal;
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import type { UIArea } from "../../miscellaneous/area/UIArea";
|
|
2
2
|
import { UIMode } from "../../miscellaneous/UIMode";
|
|
3
3
|
import type { UIAnchorOptions } from "../UIAnchor/UIAnchor.Internal";
|
|
4
|
+
import type { UIInputDummy } from "./UIInputDummy";
|
|
5
|
+
/** Input event data */
|
|
6
|
+
export interface UIInputEventData {
|
|
7
|
+
/** X coordinate */
|
|
8
|
+
x: number;
|
|
9
|
+
/** Y coordinate */
|
|
10
|
+
y: number;
|
|
11
|
+
/** Pointer identifier */
|
|
12
|
+
identifier: number;
|
|
13
|
+
/** Element that emitted the event */
|
|
14
|
+
element: UIInputDummy;
|
|
15
|
+
}
|
|
4
16
|
/** Configuration options for UIInputDummy */
|
|
5
17
|
export interface UIInputDummyOptions extends UIAnchorOptions {
|
|
6
18
|
/** Width in world units */
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import type { FerrsignView1 } from "ferrsign";
|
|
2
|
+
import { Ferrsign1 } from "ferrsign";
|
|
1
3
|
import type { UILayer } from "../../layers/UILayer/UILayer";
|
|
2
4
|
import type { UIArea } from "../../miscellaneous/area/UIArea";
|
|
3
5
|
import type { UIPlaneElement } from "../../miscellaneous/shared";
|
|
4
|
-
import { UIInputEvent } from "../../miscellaneous/UIInputEvent";
|
|
5
6
|
import { UIMode } from "../../miscellaneous/UIMode";
|
|
6
7
|
import type { UIInputWrapperInterface } from "../../wrappers/UIInputWrapper/UIInputWrapper.Internal";
|
|
7
8
|
import { UIAnchor } from "../UIAnchor/UIAnchor";
|
|
8
|
-
import type { UIInputDummyOptions } from "./UIInputDummy.Internal";
|
|
9
|
+
import type { UIInputDummyOptions, UIInputEventData } from "./UIInputDummy.Internal";
|
|
9
10
|
/** Rectangular area with dimensions but no rendering */
|
|
10
11
|
export declare class UIInputDummy extends UIAnchor implements UIPlaneElement {
|
|
11
12
|
/** Shape defining interactive region in element-local space (0,0 = bottom-left, 1,1 = top-right) */
|
|
@@ -18,6 +19,11 @@ export declare class UIInputDummy extends UIAnchor implements UIPlaneElement {
|
|
|
18
19
|
protected readonly inputWrapper: UIInputWrapperInterface;
|
|
19
20
|
private readonly catcherHandler;
|
|
20
21
|
private wasPointerInside;
|
|
22
|
+
private readonly signalPressedInternal;
|
|
23
|
+
private readonly signalMovedInternal;
|
|
24
|
+
private readonly signalReleasedInternal;
|
|
25
|
+
private readonly signalEnteredInternal;
|
|
26
|
+
private readonly signalLeftInternal;
|
|
21
27
|
/**
|
|
22
28
|
* Creates a new UIInputDummy instance.
|
|
23
29
|
*
|
|
@@ -41,6 +47,16 @@ export declare class UIInputDummy extends UIAnchor implements UIPlaneElement {
|
|
|
41
47
|
get mode(): UIMode;
|
|
42
48
|
/** Rendering and input priority. Higher values on top. */
|
|
43
49
|
get zIndex(): number;
|
|
50
|
+
/** Signal fired when pointer is pressed */
|
|
51
|
+
get signalPressed(): FerrsignView1<UIInputEventData>;
|
|
52
|
+
/** Signal fired when pointer is moved */
|
|
53
|
+
get signalMoved(): FerrsignView1<UIInputEventData>;
|
|
54
|
+
/** Signal fired when pointer is released */
|
|
55
|
+
get signalReleased(): FerrsignView1<UIInputEventData>;
|
|
56
|
+
/** Signal fired when pointer enters element */
|
|
57
|
+
get signalEntered(): FerrsignView1<UIInputEventData>;
|
|
58
|
+
/** Signal fired when pointer leaves element */
|
|
59
|
+
get signalLeft(): FerrsignView1<UIInputEventData>;
|
|
44
60
|
/** Width in world units */
|
|
45
61
|
set width(value: number);
|
|
46
62
|
/** Height in world units */
|
|
@@ -62,5 +78,5 @@ export declare class UIInputDummy extends UIAnchor implements UIPlaneElement {
|
|
|
62
78
|
protected readonly catchPointerDown: (x: number, y: number, identifier: number) => boolean;
|
|
63
79
|
protected readonly catchPointerMove: (x: number, y: number, identifier: number) => boolean;
|
|
64
80
|
protected readonly catchPointerUp: (x: number, y: number, identifier: number) => boolean;
|
|
65
|
-
protected handleInputEvent(x: number, y: number, identifier: number,
|
|
81
|
+
protected handleInputEvent(x: number, y: number, identifier: number, signal: Ferrsign1<UIInputEventData>): boolean;
|
|
66
82
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -43,7 +43,6 @@ export { UIResizePolicyFixedHeight } from "./miscellaneous/resize-policy/UIResiz
|
|
|
43
43
|
export { UIResizePolicyFixedWidth } from "./miscellaneous/resize-policy/UIResizePolicyFixedWidth";
|
|
44
44
|
export { UIResizePolicyNone } from "./miscellaneous/resize-policy/UIResizePolicyNone";
|
|
45
45
|
export { UIExpression } from "./miscellaneous/UIExpression";
|
|
46
|
-
export { UIInputEvent } from "./miscellaneous/UIInputEvent";
|
|
47
46
|
export { UIMode } from "./miscellaneous/UIMode";
|
|
48
47
|
export { UIOrientation } from "./miscellaneous/UIOrientation";
|
|
49
48
|
export { UIPriority } from "./miscellaneous/UIPriority";
|