laymur 0.27.1 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -1
- package/dist/core/constraints/UIAspectConstraint/UIAspectConstraint.js +2 -1
- package/dist/core/constraints/UICustomConstraint.js +1 -1
- package/dist/core/constraints/UIHeightConstraint/UIHeightConstraint.js +2 -1
- package/dist/core/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.js +2 -1
- package/dist/core/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.js +2 -1
- package/dist/core/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.js +2 -1
- package/dist/core/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.js +2 -1
- package/dist/core/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.js +2 -1
- package/dist/core/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.js +2 -1
- package/dist/core/constraints/UIWidthConstraint/UIWidthConstraint.js +2 -1
- package/dist/core/constraints/constraintAsserts.d.ts +41 -0
- package/dist/core/constraints/constraintAsserts.js +171 -0
- package/dist/core/elements/UIDummy/UIDummy.d.ts +8 -5
- package/dist/core/elements/UIDummy/UIDummy.js +21 -10
- package/dist/core/elements/UIElement/UIElement.Internal.d.ts +6 -5
- package/dist/core/elements/UIElement/UIElement.Internal.js +0 -4
- package/dist/core/elements/UIElement/UIElement.d.ts +12 -6
- package/dist/core/elements/UIElement/UIElement.js +14 -7
- package/dist/core/elements/UIText/UIText.d.ts +6 -1
- package/dist/core/elements/UIText/UIText.js +22 -12
- package/dist/core/layers/UIViewportLayer/UIViewportLayer.js +1 -1
- package/dist/core/miscellaneous/UIBlendMode.d.ts +5 -0
- package/dist/core/miscellaneous/UIBlendMode.js +7 -0
- package/dist/core/miscellaneous/asserts.d.ts +0 -41
- package/dist/core/miscellaneous/asserts.js +0 -170
- package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionCircular.d.ts +10 -7
- package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionCircular.js +11 -8
- package/dist/core/miscellaneous/text-style/UITextStyle.Internal.d.ts +4 -1
- package/dist/core/miscellaneous/text-style/UITextStyle.d.ts +4 -1
- package/dist/core/miscellaneous/text-style/UITextStyle.js +4 -1
- package/dist/core/shaders/UIProgressMaskFunctionCircular.js +1 -2
- package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.Internal.d.ts +6 -2
- package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.d.ts +1 -0
- package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.js +18 -9
- package/dist/particles/behaviorModules/UIBehaviorAlignToVelocity.d.ts +44 -0
- package/dist/particles/behaviorModules/UIBehaviorAlignToVelocity.js +75 -0
- package/dist/particles/behaviorModules/UIBehaviorBounce.d.ts +51 -0
- package/dist/particles/behaviorModules/UIBehaviorBounce.js +107 -0
- package/dist/particles/behaviorModules/UIBehaviorOrbit.d.ts +39 -0
- package/dist/particles/behaviorModules/UIBehaviorOrbit.js +73 -0
- package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.d.ts +7 -2
- package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.js +9 -5
- package/dist/particles/behaviorModules/UIBehaviorSeek.d.ts +38 -0
- package/dist/particles/behaviorModules/UIBehaviorSeek.js +75 -0
- package/dist/particles/elements/UIEmitter.Internal.d.ts +45 -1
- package/dist/particles/elements/UIEmitter.Internal.js +25 -1
- package/dist/particles/elements/UIEmitter.Schedule.d.ts +31 -0
- package/dist/particles/elements/UIEmitter.Schedule.js +81 -0
- package/dist/particles/elements/UIEmitter.d.ts +79 -9
- package/dist/particles/elements/UIEmitter.js +239 -82
- package/dist/particles/index.d.ts +13 -1
- package/dist/particles/index.js +11 -1
- package/dist/particles/instancedParticle/UIInstancedParticle.Internal.d.ts +6 -0
- package/dist/particles/instancedParticle/UIInstancedParticle.Internal.js +27 -0
- package/dist/particles/instancedParticle/UIInstancedParticle.d.ts +7 -1
- package/dist/particles/instancedParticle/UIInstancedParticle.js +12 -1
- package/dist/particles/miscellaneous/miscellaneous.d.ts +22 -0
- package/dist/particles/miscellaneous/miscellaneous.js +38 -0
- package/dist/particles/renderingModules/UIRenderingFlipbook.d.ts +41 -0
- package/dist/particles/renderingModules/UIRenderingFlipbook.js +70 -0
- package/dist/particles/renderingModules/UIRenderingModule.d.ts +2 -1
- package/dist/particles/renderingModules/UIRenderingModule.js +2 -1
- package/dist/particles/renderingModules/UIRenderingRandomColor.d.ts +19 -0
- package/dist/particles/renderingModules/UIRenderingRandomColor.js +28 -0
- package/dist/particles/renderingModules/UIRenderingShape.d.ts +31 -0
- package/dist/particles/renderingModules/UIRenderingShape.js +54 -0
- package/dist/particles/renderingModules/UIRenderingTexture.d.ts +1 -1
- package/dist/particles/renderingModules/UIRenderingTexture.js +4 -28
- package/dist/particles/shaders/UIRenderingFlipbook.d.ts +5 -0
- package/dist/particles/shaders/UIRenderingFlipbook.js +19 -0
- package/dist/particles/shaders/UIRenderingRandomColor.d.ts +2 -0
- package/dist/particles/shaders/UIRenderingRandomColor.js +10 -0
- package/dist/particles/shaders/UIRenderingShape.d.ts +6 -0
- package/dist/particles/shaders/UIRenderingShape.js +15 -0
- package/dist/particles/shaders/UIRenderingTexture.d.ts +4 -2
- package/dist/particles/shaders/UIRenderingTexture.js +27 -2
- package/dist/particles/spawnModules/UISpawnCircle.d.ts +44 -0
- package/dist/particles/spawnModules/UISpawnCircle.js +81 -0
- package/dist/particles/spawnModules/UISpawnRadialVelocity.d.ts +37 -0
- package/dist/particles/spawnModules/UISpawnRadialVelocity.js +75 -0
- package/package.json +1 -1
|
@@ -10,6 +10,8 @@ import { detectIsRTL } from "./UIText.Bidi.js";
|
|
|
10
10
|
import { TEXT_DEFAULT_DIRECTION, TEXT_DEFAULT_MAX_LINE_WIDTH, TEXT_DEFAULT_RESIZE_MODE, UITextDirection, UITextResizeMode, } from "./UIText.Internal.js";
|
|
11
11
|
import { buildTextChunks, calculateTextContentParameters } from "./UIText.Measuring.js";
|
|
12
12
|
import { renderTextLines } from "./UIText.Rendering.js";
|
|
13
|
+
/** Smallest width and height of the element, kept by empty and whitespace-only text */
|
|
14
|
+
const TEXT_MIN_DIMENSION = 1;
|
|
13
15
|
/** Canvas-based text rendering element */
|
|
14
16
|
export class UIText extends UIElement {
|
|
15
17
|
/**
|
|
@@ -100,7 +102,10 @@ export class UIText extends UIElement {
|
|
|
100
102
|
set color(value) {
|
|
101
103
|
this.colorInternal.set(value);
|
|
102
104
|
}
|
|
103
|
-
/**
|
|
105
|
+
/**
|
|
106
|
+
* Text content as string, span config, or array. Text without visible characters keeps the
|
|
107
|
+
* element at least 1 world unit wide and high.
|
|
108
|
+
*/
|
|
104
109
|
set content(value) {
|
|
105
110
|
if (this.contentInternal !== value) {
|
|
106
111
|
if (typeof value === "string") {
|
|
@@ -196,10 +201,7 @@ export class UIText extends UIElement {
|
|
|
196
201
|
}
|
|
197
202
|
const textChunks = this.buildTextChunks();
|
|
198
203
|
const { lines, size } = calculateTextContentParameters(textChunks, this.maxLineWidthInternal, this.isRTL);
|
|
199
|
-
const
|
|
200
|
-
const paddingH = this.paddingInternal.left + this.paddingInternal.right;
|
|
201
|
-
const desiredHeight = size.height + paddingV;
|
|
202
|
-
const desiredWidth = size.width + paddingH;
|
|
204
|
+
const { width: desiredWidth, height: desiredHeight } = this.elementSize(size);
|
|
203
205
|
this.width = desiredWidth;
|
|
204
206
|
this.height = (desiredHeight / desiredWidth) * Math.round(this.width);
|
|
205
207
|
this.width = (desiredWidth / desiredHeight) * Math.round(this.height);
|
|
@@ -234,13 +236,13 @@ export class UIText extends UIElement {
|
|
|
234
236
|
}
|
|
235
237
|
const textChunks = this.buildTextChunks();
|
|
236
238
|
const { size: desiredTextSize } = calculateTextContentParameters(textChunks, this.maxLineWidthInternal, this.isRTL);
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
this.
|
|
240
|
-
this.width
|
|
241
|
-
const
|
|
242
|
-
this.height =
|
|
243
|
-
this.width =
|
|
239
|
+
const desiredSize = this.elementSize(desiredTextSize);
|
|
240
|
+
this.height = desiredSize.height;
|
|
241
|
+
this.width = desiredSize.width;
|
|
242
|
+
const { lines: realTextLines, size: realTextSize } = calculateTextContentParameters(textChunks, Math.round(this.width) - this.paddingInternal.left - this.paddingInternal.right, this.isRTL);
|
|
243
|
+
const realSize = this.elementSize(realTextSize);
|
|
244
|
+
this.height = realSize.height;
|
|
245
|
+
this.width = realSize.width;
|
|
244
246
|
const safeWidth = Math.max(Math.round(this.width), 2);
|
|
245
247
|
const safeHeight = Math.max(Math.round(this.height), 2);
|
|
246
248
|
const resolutionDirty = this.canvas.width !== safeWidth || this.canvas.height !== safeHeight;
|
|
@@ -257,6 +259,14 @@ export class UIText extends UIElement {
|
|
|
257
259
|
this.setDimensionsDirtyFalse();
|
|
258
260
|
this.setContentDirtyFalse();
|
|
259
261
|
}
|
|
262
|
+
/** The element size for a text size: the padding added, at least the minimum each way */
|
|
263
|
+
elementSize(textSize) {
|
|
264
|
+
const { left, right, top, bottom } = this.paddingInternal;
|
|
265
|
+
return {
|
|
266
|
+
width: Math.max(textSize.width + left + right, TEXT_MIN_DIMENSION),
|
|
267
|
+
height: Math.max(textSize.height + top + bottom, TEXT_MIN_DIMENSION),
|
|
268
|
+
};
|
|
269
|
+
}
|
|
260
270
|
updateProperties(resolutionDirty) {
|
|
261
271
|
let properties;
|
|
262
272
|
if (this.colorInternal.dirty) {
|
|
@@ -85,7 +85,7 @@ export class UIViewportLayer extends UILayer {
|
|
|
85
85
|
}
|
|
86
86
|
const position = this.reportPointer(event, this.signalPointerReleasedInternal);
|
|
87
87
|
if (position !== null) {
|
|
88
|
-
this.inputWrapperInternal.onPointerUp(position.x, position.y, event.pointerId);
|
|
88
|
+
this.inputWrapperInternal.onPointerUp(position.x, position.y, event.pointerId, event.pointerType === "mouse");
|
|
89
89
|
}
|
|
90
90
|
};
|
|
91
91
|
this.onPointerCancel = (event) => {
|
|
@@ -5,3 +5,8 @@ export declare enum UIBlendMode {
|
|
|
5
5
|
/** Additive blending (light accumulation). Only affects BLEND transparency. */
|
|
6
6
|
ADDITIVE = 1
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Output-alpha multiplier of a premultiplied shader: 1 composites over the destination, 0 adds
|
|
10
|
+
* to it
|
|
11
|
+
*/
|
|
12
|
+
export declare function blendModeToFactor(mode: UIBlendMode): number;
|
|
@@ -6,3 +6,10 @@ export var UIBlendMode;
|
|
|
6
6
|
/** Additive blending (light accumulation). Only affects BLEND transparency. */
|
|
7
7
|
UIBlendMode[UIBlendMode["ADDITIVE"] = 1] = "ADDITIVE";
|
|
8
8
|
})(UIBlendMode || (UIBlendMode = {}));
|
|
9
|
+
/**
|
|
10
|
+
* Output-alpha multiplier of a premultiplied shader: 1 composites over the destination, 0 adds
|
|
11
|
+
* to it
|
|
12
|
+
*/
|
|
13
|
+
export function blendModeToFactor(mode) {
|
|
14
|
+
return mode === UIBlendMode.ADDITIVE ? 0 : 1;
|
|
15
|
+
}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import type { WebGLRenderer } from "three";
|
|
2
|
-
import { UILayer } from "../layers/UILayer/UILayer.js";
|
|
3
|
-
import type { UILayerElement } from "./shared.js";
|
|
4
|
-
import type { UIExpression } from "./UIExpression.js";
|
|
5
2
|
/**
|
|
6
3
|
* Validates value is finite number within safe range.
|
|
7
4
|
* @param value Number to validate
|
|
@@ -41,44 +38,6 @@ export declare function assertValidPositiveNumber(value: number, subject: string
|
|
|
41
38
|
* @throws If value is invalid or negative
|
|
42
39
|
*/
|
|
43
40
|
export declare function assertValidNonNegativeNumber(value: number, subject: string): void;
|
|
44
|
-
/**
|
|
45
|
-
* Validates constraint arguments are from same layer.
|
|
46
|
-
* @param a First constraint subject
|
|
47
|
-
* @param b Second constraint subject
|
|
48
|
-
* @param subject Constraint name for error messages
|
|
49
|
-
* @returns Common layer for both subjects
|
|
50
|
-
* @throws If subjects are invalid or from different layers
|
|
51
|
-
*/
|
|
52
|
-
export declare function assertValidConstraintArguments(a: unknown, b: unknown, subject: string): UILayer;
|
|
53
|
-
/**
|
|
54
|
-
* Validates interpolation constraint subjects.
|
|
55
|
-
* @param subject Constraint name for error messages
|
|
56
|
-
* @param a First element
|
|
57
|
-
* @param b Second element
|
|
58
|
-
* @param c Element to interpolate
|
|
59
|
-
* @param anchorA Anchor on element A
|
|
60
|
-
* @param anchorB Anchor on element B
|
|
61
|
-
* @returns Common layer for all subjects
|
|
62
|
-
* @throws If subjects violate interpolation constraints
|
|
63
|
-
*/
|
|
64
|
-
export declare function assertValidInterpolationConstraintArguments(subject: string, a: unknown, b: unknown, c: unknown, anchorA: number, anchorB: number): UILayer;
|
|
65
|
-
/**
|
|
66
|
-
* Validates the element of a single element constraint.
|
|
67
|
-
* @param element Constrained element
|
|
68
|
-
* @param subject Constraint name for error messages
|
|
69
|
-
* @returns Layer of the element
|
|
70
|
-
* @throws If the element is destroyed
|
|
71
|
-
*/
|
|
72
|
-
export declare function assertValidConstraintElement(element: UILayerElement, subject: string): UILayer;
|
|
73
|
-
/**
|
|
74
|
-
* Validates that the expressions of a custom constraint refer only to existing variables.
|
|
75
|
-
* @param layer Layer of the constraint
|
|
76
|
-
* @param expressions Constraint expressions
|
|
77
|
-
* @param subject Constraint name for error messages
|
|
78
|
-
* @returns The layer
|
|
79
|
-
* @throws If the layer is destroyed or a variable does not exist
|
|
80
|
-
*/
|
|
81
|
-
export declare function assertValidConstraintExpressions(layer: UILayer, expressions: UIExpression[], subject: string): UILayer;
|
|
82
41
|
/**
|
|
83
42
|
* Validates value is within [0, 1].
|
|
84
43
|
* @param value Number to validate
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { UILayer } from "../layers/UILayer/UILayer.js";
|
|
2
1
|
import { EPSILON } from "./math.js";
|
|
3
|
-
import { isUILayerElement } from "./shared.js";
|
|
4
2
|
/**
|
|
5
3
|
* Validates value is finite number within safe range.
|
|
6
4
|
* @param value Number to validate
|
|
@@ -77,174 +75,6 @@ export function assertValidNonNegativeNumber(value, subject) {
|
|
|
77
75
|
}
|
|
78
76
|
}
|
|
79
77
|
}
|
|
80
|
-
/**
|
|
81
|
-
* Validates constraint arguments are from same layer.
|
|
82
|
-
* @param a First constraint subject
|
|
83
|
-
* @param b Second constraint subject
|
|
84
|
-
* @param subject Constraint name for error messages
|
|
85
|
-
* @returns Common layer for both subjects
|
|
86
|
-
* @throws If subjects are invalid or from different layers
|
|
87
|
-
*/
|
|
88
|
-
export function assertValidConstraintArguments(a, b, subject) {
|
|
89
|
-
if (process.env.NODE_ENV !== "production") {
|
|
90
|
-
assertNotDestroyed(a, "A", subject);
|
|
91
|
-
assertNotDestroyed(b, "B", subject);
|
|
92
|
-
if (a instanceof UILayer && b instanceof UILayer) {
|
|
93
|
-
throw new Error(`${subject}: layer cannot be snapped to another layer`);
|
|
94
|
-
}
|
|
95
|
-
let layerA;
|
|
96
|
-
let layerB;
|
|
97
|
-
if (a instanceof UILayer) {
|
|
98
|
-
layerA = a;
|
|
99
|
-
}
|
|
100
|
-
else if (isUILayerElement(a)) {
|
|
101
|
-
layerA = a.layer;
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
throw new Error(`${subject}: A must be a UILayer or a UILayerElement`);
|
|
105
|
-
}
|
|
106
|
-
if (b instanceof UILayer) {
|
|
107
|
-
layerB = b;
|
|
108
|
-
}
|
|
109
|
-
else if (isUILayerElement(b)) {
|
|
110
|
-
layerB = b.layer;
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
throw new Error(`${subject}: B must be a UILayer or a UILayerElement`);
|
|
114
|
-
}
|
|
115
|
-
if (layerA !== layerB) {
|
|
116
|
-
throw new Error(`${subject}: elements must be on the same layer`);
|
|
117
|
-
}
|
|
118
|
-
return layerA;
|
|
119
|
-
}
|
|
120
|
-
if (a instanceof UILayer) {
|
|
121
|
-
return a;
|
|
122
|
-
}
|
|
123
|
-
if (isUILayerElement(a)) {
|
|
124
|
-
return a.layer;
|
|
125
|
-
}
|
|
126
|
-
if (b instanceof UILayer) {
|
|
127
|
-
return b;
|
|
128
|
-
}
|
|
129
|
-
if (isUILayerElement(b)) {
|
|
130
|
-
return b.layer;
|
|
131
|
-
}
|
|
132
|
-
throw new Error(`${subject}: A or B must be a UILayer or a UILayerElement`);
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Validates interpolation constraint subjects.
|
|
136
|
-
* @param subject Constraint name for error messages
|
|
137
|
-
* @param a First element
|
|
138
|
-
* @param b Second element
|
|
139
|
-
* @param c Element to interpolate
|
|
140
|
-
* @param anchorA Anchor on element A
|
|
141
|
-
* @param anchorB Anchor on element B
|
|
142
|
-
* @returns Common layer for all subjects
|
|
143
|
-
* @throws If subjects violate interpolation constraints
|
|
144
|
-
*/
|
|
145
|
-
export function assertValidInterpolationConstraintArguments(subject, a, b, c, anchorA, anchorB) {
|
|
146
|
-
if (process.env.NODE_ENV !== "production") {
|
|
147
|
-
assertNotDestroyed(a, "A", subject);
|
|
148
|
-
assertNotDestroyed(b, "B", subject);
|
|
149
|
-
assertNotDestroyed(c, "C", subject);
|
|
150
|
-
if (c instanceof UILayer) {
|
|
151
|
-
throw new Error(`${subject}: C cannot be a layer`);
|
|
152
|
-
}
|
|
153
|
-
if (!isUILayerElement(c)) {
|
|
154
|
-
throw new Error(`${subject}: C must be a UILayerElement`);
|
|
155
|
-
}
|
|
156
|
-
let layerA;
|
|
157
|
-
let layerB;
|
|
158
|
-
if (a instanceof UILayer || isUILayerElement(a)) {
|
|
159
|
-
layerA = a instanceof UILayer ? a : a.layer;
|
|
160
|
-
}
|
|
161
|
-
else {
|
|
162
|
-
throw new Error(`${subject}: A must be a UILayer or a UILayerElement`);
|
|
163
|
-
}
|
|
164
|
-
if (b instanceof UILayer || isUILayerElement(b)) {
|
|
165
|
-
layerB = b instanceof UILayer ? b : b.layer;
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
throw new Error(`${subject}: B must be a UILayer or a UILayerElement`);
|
|
169
|
-
}
|
|
170
|
-
const layerC = c.layer;
|
|
171
|
-
if (layerA !== layerB || layerA !== layerC) {
|
|
172
|
-
throw new Error(`${subject}: all elements must be on the same layer`);
|
|
173
|
-
}
|
|
174
|
-
if (c === a || c === b) {
|
|
175
|
-
throw new Error(`${subject}: C cannot be equal to A or B`);
|
|
176
|
-
}
|
|
177
|
-
if (a === b) {
|
|
178
|
-
if (Math.abs(anchorA - anchorB) <= EPSILON) {
|
|
179
|
-
throw new Error(`${subject}: when A and B are the same, anchorA and anchorB must differ by more than ${EPSILON}`);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
return layerA;
|
|
183
|
-
}
|
|
184
|
-
if (isUILayerElement(a)) {
|
|
185
|
-
return a.layer;
|
|
186
|
-
}
|
|
187
|
-
if (isUILayerElement(b)) {
|
|
188
|
-
return b.layer;
|
|
189
|
-
}
|
|
190
|
-
if (a instanceof UILayer) {
|
|
191
|
-
return a;
|
|
192
|
-
}
|
|
193
|
-
if (b instanceof UILayer) {
|
|
194
|
-
return b;
|
|
195
|
-
}
|
|
196
|
-
throw new Error(`${subject}: A or B must be a UILayer or a UILayerElement`);
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Validates the element of a single element constraint.
|
|
200
|
-
* @param element Constrained element
|
|
201
|
-
* @param subject Constraint name for error messages
|
|
202
|
-
* @returns Layer of the element
|
|
203
|
-
* @throws If the element is destroyed
|
|
204
|
-
*/
|
|
205
|
-
export function assertValidConstraintElement(element, subject) {
|
|
206
|
-
if (process.env.NODE_ENV !== "production") {
|
|
207
|
-
assertNotDestroyed(element, "element", subject);
|
|
208
|
-
}
|
|
209
|
-
return element.layer;
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* Validates that the expressions of a custom constraint refer only to existing variables.
|
|
213
|
-
* @param layer Layer of the constraint
|
|
214
|
-
* @param expressions Constraint expressions
|
|
215
|
-
* @param subject Constraint name for error messages
|
|
216
|
-
* @returns The layer
|
|
217
|
-
* @throws If the layer is destroyed or a variable does not exist
|
|
218
|
-
*/
|
|
219
|
-
export function assertValidConstraintExpressions(layer, expressions, subject) {
|
|
220
|
-
if (process.env.NODE_ENV !== "production") {
|
|
221
|
-
assertNotDestroyed(layer, "layer", subject);
|
|
222
|
-
for (const expression of expressions) {
|
|
223
|
-
for (const [variableIndex] of expression.prepareTerms()) {
|
|
224
|
-
if (!layer.solverWrapper.hasVariable(variableIndex)) {
|
|
225
|
-
throw new Error(`${subject}: variable ${variableIndex} does not exist`);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
return layer;
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Validates that a constraint subject is not destroyed. A constraint made with a destroyed
|
|
234
|
-
* subject would stay in the layer without a solver constraint.
|
|
235
|
-
* @param value Element or layer
|
|
236
|
-
* @param name Subject name for error messages
|
|
237
|
-
* @param subject Constraint name for error messages
|
|
238
|
-
* @throws If the subject is destroyed
|
|
239
|
-
*/
|
|
240
|
-
function assertNotDestroyed(value, name, subject) {
|
|
241
|
-
if (typeof value === "object" &&
|
|
242
|
-
value !== null &&
|
|
243
|
-
"destroyed" in value &&
|
|
244
|
-
value.destroyed === true) {
|
|
245
|
-
throw new Error(`${subject}: ${name} is destroyed`);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
78
|
/**
|
|
249
79
|
* Validates value is within [0, 1].
|
|
250
80
|
* @param value Number to validate
|
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
import type { UIProperty } from "../generic-plane/shared.js";
|
|
2
2
|
import { UIProgressMaskFunction } from "./UIProgressMaskFunction.js";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Circular radial progress fill. Angles are in radians, measured counter-clockwise from the
|
|
5
|
+
* positive x axis, so 0 is the right edge and PI / 2 is the top.
|
|
6
|
+
*/
|
|
4
7
|
export declare class UIProgressMaskFunctionCircular extends UIProgressMaskFunction {
|
|
5
8
|
private startAngleInternal;
|
|
6
9
|
private inverseDirectionInternal;
|
|
7
10
|
/**
|
|
8
11
|
* Creates circular mask function.
|
|
9
12
|
*
|
|
10
|
-
* @param startAngle -
|
|
11
|
-
* @param inverseDirection - Whether to fill counter-clockwise
|
|
13
|
+
* @param startAngle - Angle the fill starts from, in radians
|
|
14
|
+
* @param inverseDirection - Whether to fill clockwise instead of counter-clockwise
|
|
12
15
|
*/
|
|
13
16
|
constructor(startAngle?: number, inverseDirection?: boolean);
|
|
14
|
-
/**
|
|
17
|
+
/** Angle the fill starts from, in radians */
|
|
15
18
|
get startAngle(): number;
|
|
16
|
-
/** Whether fill
|
|
19
|
+
/** Whether the fill goes clockwise instead of counter-clockwise */
|
|
17
20
|
get inverseDirection(): boolean;
|
|
18
|
-
/**
|
|
21
|
+
/** Angle the fill starts from, in radians */
|
|
19
22
|
set startAngle(value: number);
|
|
20
|
-
/** Whether fill
|
|
23
|
+
/** Whether the fill goes clockwise instead of counter-clockwise */
|
|
21
24
|
set inverseDirection(value: boolean);
|
|
22
25
|
enumerateProperties(): Record<string, UIProperty>;
|
|
23
26
|
}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import source from "../../shaders/UIProgressMaskFunctionCircular.js";
|
|
2
2
|
import { assertValidNumber } from "../asserts.js";
|
|
3
3
|
import { UIProgressMaskFunction } from "./UIProgressMaskFunction.js";
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Circular radial progress fill. Angles are in radians, measured counter-clockwise from the
|
|
6
|
+
* positive x axis, so 0 is the right edge and PI / 2 is the top.
|
|
7
|
+
*/
|
|
5
8
|
export class UIProgressMaskFunctionCircular extends UIProgressMaskFunction {
|
|
6
9
|
/**
|
|
7
10
|
* Creates circular mask function.
|
|
8
11
|
*
|
|
9
|
-
* @param startAngle -
|
|
10
|
-
* @param inverseDirection - Whether to fill counter-clockwise
|
|
12
|
+
* @param startAngle - Angle the fill starts from, in radians
|
|
13
|
+
* @param inverseDirection - Whether to fill clockwise instead of counter-clockwise
|
|
11
14
|
*/
|
|
12
15
|
constructor(startAngle = 0, inverseDirection = false) {
|
|
13
16
|
assertValidNumber(startAngle, "UIProgressMaskFunctionCircular.constructor.startAngle");
|
|
@@ -15,15 +18,15 @@ export class UIProgressMaskFunctionCircular extends UIProgressMaskFunction {
|
|
|
15
18
|
this.startAngleInternal = startAngle;
|
|
16
19
|
this.inverseDirectionInternal = inverseDirection;
|
|
17
20
|
}
|
|
18
|
-
/**
|
|
21
|
+
/** Angle the fill starts from, in radians */
|
|
19
22
|
get startAngle() {
|
|
20
23
|
return this.startAngleInternal;
|
|
21
24
|
}
|
|
22
|
-
/** Whether fill
|
|
25
|
+
/** Whether the fill goes clockwise instead of counter-clockwise */
|
|
23
26
|
get inverseDirection() {
|
|
24
27
|
return this.inverseDirectionInternal;
|
|
25
28
|
}
|
|
26
|
-
/**
|
|
29
|
+
/** Angle the fill starts from, in radians */
|
|
27
30
|
set startAngle(value) {
|
|
28
31
|
assertValidNumber(value, "UIProgressMaskFunctionCircular.startAngle");
|
|
29
32
|
if (this.startAngleInternal !== value) {
|
|
@@ -31,7 +34,7 @@ export class UIProgressMaskFunctionCircular extends UIProgressMaskFunction {
|
|
|
31
34
|
this.dirtyInternal = true;
|
|
32
35
|
}
|
|
33
36
|
}
|
|
34
|
-
/** Whether fill
|
|
37
|
+
/** Whether the fill goes clockwise instead of counter-clockwise */
|
|
35
38
|
set inverseDirection(value) {
|
|
36
39
|
if (this.inverseDirectionInternal !== value) {
|
|
37
40
|
this.inverseDirectionInternal = value;
|
|
@@ -41,7 +44,7 @@ export class UIProgressMaskFunctionCircular extends UIProgressMaskFunction {
|
|
|
41
44
|
enumerateProperties() {
|
|
42
45
|
return {
|
|
43
46
|
direction: this.inverseDirectionInternal ? -1 : 1,
|
|
44
|
-
startAngle: this.startAngleInternal,
|
|
47
|
+
startAngle: this.startAngleInternal / (2 * Math.PI),
|
|
45
48
|
};
|
|
46
49
|
}
|
|
47
50
|
}
|
|
@@ -14,7 +14,10 @@ export interface UITextStyleConfig {
|
|
|
14
14
|
fontStyle: "normal" | "italic" | "oblique";
|
|
15
15
|
/** Font weight */
|
|
16
16
|
fontWeight: "normal" | "bold" | "bolder" | "lighter" | number;
|
|
17
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Line height in pixels: the distance between baselines, not a multiple of the font size.
|
|
19
|
+
* Defaults to 1.2 times the font size.
|
|
20
|
+
*/
|
|
18
21
|
lineHeight: number;
|
|
19
22
|
/** Whether shadow is enabled */
|
|
20
23
|
enableShadow: boolean;
|
|
@@ -31,7 +31,10 @@ export declare class UITextStyle {
|
|
|
31
31
|
get fontStyle(): "normal" | "italic" | "oblique" | undefined;
|
|
32
32
|
/** Font weight */
|
|
33
33
|
get fontWeight(): "normal" | "bold" | "bolder" | "lighter" | number | undefined;
|
|
34
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* Line height in pixels: the distance between baselines, not a multiple of the font size.
|
|
36
|
+
* Defaults to 1.2 times the font size.
|
|
37
|
+
*/
|
|
35
38
|
get lineHeight(): number | undefined;
|
|
36
39
|
/** Whether shadow is enabled */
|
|
37
40
|
get enableShadow(): boolean | undefined;
|
|
@@ -45,7 +45,10 @@ export class UITextStyle {
|
|
|
45
45
|
get fontWeight() {
|
|
46
46
|
return this.fontWeightInternal;
|
|
47
47
|
}
|
|
48
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* Line height in pixels: the distance between baselines, not a multiple of the font size.
|
|
50
|
+
* Defaults to 1.2 times the font size.
|
|
51
|
+
*/
|
|
49
52
|
get lineHeight() {
|
|
50
53
|
return this.lineHeightInternal;
|
|
51
54
|
}
|
|
@@ -3,8 +3,7 @@ float calculateMask() {
|
|
|
3
3
|
float aspect = p_textureResolution.x / p_textureResolution.y;
|
|
4
4
|
vec2 p = (p_uv - 0.5) * vec2(aspect, 1.0);
|
|
5
5
|
|
|
6
|
-
float angle = atan(p.y, p.x);
|
|
7
|
-
angle = (angle + PI) / (2.0 * PI);
|
|
6
|
+
float angle = atan(p.y, p.x) / (2.0 * PI);
|
|
8
7
|
|
|
9
8
|
float adjusted = angle - p_startAngle;
|
|
10
9
|
adjusted = p_direction > 0.0 ? adjusted : -adjusted;
|
|
@@ -10,8 +10,12 @@ export interface UIInputCatcherCallbacks {
|
|
|
10
10
|
catchPointerDown: (x: number, y: number, identifier: number) => boolean;
|
|
11
11
|
/** Returns true to stop the event for catchers below; ignored for a captured pointer */
|
|
12
12
|
catchPointerMove: (x: number, y: number, identifier: number) => boolean;
|
|
13
|
-
/**
|
|
14
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Returns true to stop the event for catchers below; ignored for a captured pointer.
|
|
15
|
+
* `hovering` is true for a pointer that stays over the page after the release, as a mouse
|
|
16
|
+
* does: its next events come with the same identifier.
|
|
17
|
+
*/
|
|
18
|
+
catchPointerUp: (x: number, y: number, identifier: number, hovering: boolean) => boolean;
|
|
15
19
|
/**
|
|
16
20
|
* The pointer is gone for this catcher: drop what is known of it. Called when a pressed
|
|
17
21
|
* pointer is cancelled (by the browser or by the layer), on the catcher that captured it, or
|
|
@@ -20,6 +20,7 @@ export declare class UIInputWrapper implements UIInputWrapperView {
|
|
|
20
20
|
/**
|
|
21
21
|
* Passes a pointer event from the top catcher down until one catches it. A handler may
|
|
22
22
|
* destroy elements, so the catchers are walked over a copy and a destroyed one is skipped.
|
|
23
|
+
* @param catchEvent Passes the event to a catcher; true if it caught it
|
|
23
24
|
* @param pointer Pressed pointer the event belongs to: the walk stops once a handler ends it
|
|
24
25
|
* @returns The catcher that caught the event, or null
|
|
25
26
|
*/
|
|
@@ -97,7 +97,7 @@ export class UIInputWrapper {
|
|
|
97
97
|
this.hoveringPointers.delete(identifier);
|
|
98
98
|
const pointer = { catcher: null, x, y };
|
|
99
99
|
this.pointers.set(identifier, pointer);
|
|
100
|
-
const caught = this.dispatch(x, y, identifier,
|
|
100
|
+
const caught = this.dispatch(identifier, (catcher) => catcher.catchPointerDown(x, y, identifier), pointer);
|
|
101
101
|
if (this.pointers.get(identifier) !== pointer) {
|
|
102
102
|
return;
|
|
103
103
|
}
|
|
@@ -124,18 +124,26 @@ export class UIInputWrapper {
|
|
|
124
124
|
if (pointer === undefined) {
|
|
125
125
|
this.hoveringPointers.add(identifier);
|
|
126
126
|
}
|
|
127
|
-
this.cancelBelow(identifier, this.dispatch(x, y, identifier
|
|
127
|
+
this.cancelBelow(identifier, this.dispatch(identifier, (catcher) => catcher.catchPointerMove(x, y, identifier)));
|
|
128
128
|
}
|
|
129
|
-
/**
|
|
130
|
-
|
|
129
|
+
/**
|
|
130
|
+
* @param hovering Whether the pointer stays over the page after the release, as a mouse does
|
|
131
|
+
* @internal
|
|
132
|
+
*/
|
|
133
|
+
onPointerUp(x, y, identifier, hovering) {
|
|
131
134
|
const pointer = this.pointers.get(identifier);
|
|
132
135
|
this.pointers.delete(identifier);
|
|
133
|
-
|
|
136
|
+
if (hovering) {
|
|
137
|
+
this.hoveringPointers.add(identifier);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
this.hoveringPointers.delete(identifier);
|
|
141
|
+
}
|
|
134
142
|
if (pointer?.catcher) {
|
|
135
|
-
pointer.catcher.catchPointerUp(x, y, identifier);
|
|
143
|
+
pointer.catcher.catchPointerUp(x, y, identifier, hovering);
|
|
136
144
|
return;
|
|
137
145
|
}
|
|
138
|
-
this.cancelBelow(identifier, this.dispatch(x, y, identifier,
|
|
146
|
+
this.cancelBelow(identifier, this.dispatch(identifier, (catcher) => catcher.catchPointerUp(x, y, identifier, hovering)));
|
|
139
147
|
}
|
|
140
148
|
/**
|
|
141
149
|
* A captured pointer is cancelled at its catcher. Any other one goes to every active catcher,
|
|
@@ -176,10 +184,11 @@ export class UIInputWrapper {
|
|
|
176
184
|
/**
|
|
177
185
|
* Passes a pointer event from the top catcher down until one catches it. A handler may
|
|
178
186
|
* destroy elements, so the catchers are walked over a copy and a destroyed one is skipped.
|
|
187
|
+
* @param catchEvent Passes the event to a catcher; true if it caught it
|
|
179
188
|
* @param pointer Pressed pointer the event belongs to: the walk stops once a handler ends it
|
|
180
189
|
* @returns The catcher that caught the event, or null
|
|
181
190
|
*/
|
|
182
|
-
dispatch(
|
|
191
|
+
dispatch(identifier, catchEvent, pointer) {
|
|
183
192
|
this.ensureSorted();
|
|
184
193
|
const catchers = this.catchers.slice();
|
|
185
194
|
for (let index = catchers.length - 1; index >= 0; index--) {
|
|
@@ -187,7 +196,7 @@ export class UIInputWrapper {
|
|
|
187
196
|
return null;
|
|
188
197
|
}
|
|
189
198
|
const item = catchers[index];
|
|
190
|
-
if (item.active && item
|
|
199
|
+
if (item.active && catchEvent(item)) {
|
|
191
200
|
return item;
|
|
192
201
|
}
|
|
193
202
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { InstancedBufferAttribute } from "three";
|
|
2
|
+
import type { UIAspectConfig } from "../miscellaneous/miscellaneous.js";
|
|
3
|
+
import { UIBehaviorModule } from "./UIBehaviorModule.js";
|
|
4
|
+
/**
|
|
5
|
+
* Turns the X axis of particles along their velocity and stretches them along it with speed, as
|
|
6
|
+
* motion blur of sparks and streaks.
|
|
7
|
+
*
|
|
8
|
+
* Sets the rotation every frame, so torque has no effect. The length is derived from the Y scale,
|
|
9
|
+
* so the module composes with any scale source: put it after `UISpawnRandomScale` or
|
|
10
|
+
* `UIBehaviorScaleOverLife` in the sequence. A particle at rest keeps its rotation.
|
|
11
|
+
*/
|
|
12
|
+
export declare class UIBehaviorAlignToVelocity extends UIBehaviorModule<{
|
|
13
|
+
builtin: "Matrix4";
|
|
14
|
+
}> {
|
|
15
|
+
readonly requiredProperties: {
|
|
16
|
+
readonly builtin: "Matrix4";
|
|
17
|
+
};
|
|
18
|
+
private stretchInternal;
|
|
19
|
+
private rotationOffsetInternal;
|
|
20
|
+
private aspectInternal;
|
|
21
|
+
/**
|
|
22
|
+
* @param stretch - Seconds of motion added to the length: the length grows by speed * stretch
|
|
23
|
+
* @param aspect - Width/height ratio at rest, the same as given to the scale module. Accepts
|
|
24
|
+
* number or texture
|
|
25
|
+
* @param rotationOffset - Angle in radians added to the direction, for sprites drawn along
|
|
26
|
+
* another axis
|
|
27
|
+
*/
|
|
28
|
+
constructor(stretch?: number, aspect?: UIAspectConfig, rotationOffset?: number);
|
|
29
|
+
/** Seconds of motion added to the length */
|
|
30
|
+
get stretch(): number;
|
|
31
|
+
/** Width/height aspect ratio at rest */
|
|
32
|
+
get aspect(): number;
|
|
33
|
+
/** Angle in radians added to the direction */
|
|
34
|
+
get rotationOffset(): number;
|
|
35
|
+
/** Seconds of motion added to the length */
|
|
36
|
+
set stretch(value: number);
|
|
37
|
+
/** Width/height aspect ratio at rest */
|
|
38
|
+
set aspect(value: UIAspectConfig);
|
|
39
|
+
/** Angle in radians added to the direction */
|
|
40
|
+
set rotationOffset(value: number);
|
|
41
|
+
update(properties: {
|
|
42
|
+
builtin: InstancedBufferAttribute;
|
|
43
|
+
}, instanceCount: number): void;
|
|
44
|
+
}
|