laymur 0.27.1 → 0.29.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 +99 -5
- package/dist/core/constraints/UIAspectConstraint/UIAspectConstraint.d.ts +14 -3
- package/dist/core/constraints/UIAspectConstraint/UIAspectConstraint.js +40 -6
- package/dist/core/constraints/UICustomConstraint.js +2 -2
- package/dist/core/constraints/UIHeightConstraint/UIHeightConstraint.js +3 -2
- package/dist/core/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.js +3 -2
- package/dist/core/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.js +3 -2
- package/dist/core/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.js +3 -2
- package/dist/core/constraints/UISingleParameterConstraint/UISingleParameterConstraint.d.ts +6 -0
- package/dist/core/constraints/UISingleParameterConstraint/UISingleParameterConstraint.js +8 -0
- package/dist/core/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.js +3 -2
- package/dist/core/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.js +3 -2
- package/dist/core/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.js +3 -2
- package/dist/core/constraints/UIWidthConstraint/UIWidthConstraint.js +3 -2
- package/dist/core/constraints/constraintAsserts.d.ts +41 -0
- package/dist/core/constraints/constraintAsserts.js +171 -0
- package/dist/core/elements/UICanvasElement/UICanvasElement.d.ts +54 -0
- package/dist/core/elements/UICanvasElement/UICanvasElement.js +70 -0
- package/dist/core/elements/UIDummy/UIDummy.Internal.d.ts +2 -0
- package/dist/core/elements/UIDummy/UIDummy.d.ts +8 -5
- package/dist/core/elements/UIDummy/UIDummy.js +24 -11
- 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/UIGraphics/UIGraphics.Internal.d.ts +42 -2
- package/dist/core/elements/UIGraphics/UIGraphics.Internal.js +2 -2
- package/dist/core/elements/UIGraphics/UIGraphics.d.ts +48 -34
- package/dist/core/elements/UIGraphics/UIGraphics.js +196 -93
- package/dist/core/elements/UIImage/UIImage.d.ts +11 -1
- package/dist/core/elements/UIImage/UIImage.js +14 -0
- package/dist/core/elements/UIScene/UIScene.Internal.d.ts +10 -1
- package/dist/core/elements/UIScene/UIScene.Internal.js +1 -0
- package/dist/core/elements/UIScene/UIScene.d.ts +11 -1
- package/dist/core/elements/UIScene/UIScene.js +29 -5
- package/dist/core/elements/UIText/UIText.Interfaces.d.ts +2 -2
- package/dist/core/elements/UIText/UIText.Internal.d.ts +14 -1
- package/dist/core/elements/UIText/UIText.Internal.js +12 -0
- package/dist/core/elements/UIText/UIText.Measuring.d.ts +9 -4
- package/dist/core/elements/UIText/UIText.Measuring.js +17 -6
- package/dist/core/elements/UIText/UIText.Rendering.d.ts +7 -16
- package/dist/core/elements/UIText/UIText.Rendering.js +212 -46
- package/dist/core/elements/UIText/UIText.d.ts +64 -29
- package/dist/core/elements/UIText/UIText.js +134 -149
- package/dist/core/index.d.ts +10 -4
- package/dist/core/index.js +5 -1
- package/dist/core/layers/UILayer/UILayer.d.ts +17 -3
- package/dist/core/layers/UILayer/UILayer.js +35 -4
- package/dist/core/layers/UIViewportLayer/UIViewportLayer.d.ts +2 -0
- package/dist/core/layers/UIViewportLayer/UIViewportLayer.js +4 -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/canvas-surface/UICanvasSurface.d.ts +46 -0
- package/dist/core/miscellaneous/canvas-surface/UICanvasSurface.js +86 -0
- package/dist/core/miscellaneous/color/UIColor.d.ts +17 -0
- package/dist/core/miscellaneous/color/UIColor.js +22 -0
- package/dist/core/miscellaneous/color/canvasColor.d.ts +9 -0
- package/dist/core/miscellaneous/color/canvasColor.js +15 -0
- package/dist/core/miscellaneous/insets/UIInsets.d.ts +3 -0
- package/dist/core/miscellaneous/insets/UIInsets.js +15 -0
- 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/paint/UIGradient.Internal.d.ts +37 -0
- package/dist/core/miscellaneous/paint/UIGradient.Internal.js +14 -0
- package/dist/core/miscellaneous/paint/UIGradient.d.ts +18 -0
- package/dist/core/miscellaneous/paint/UIGradient.js +35 -0
- package/dist/core/miscellaneous/paint/UILinearGradient.d.ts +14 -0
- package/dist/core/miscellaneous/paint/UILinearGradient.js +22 -0
- package/dist/core/miscellaneous/paint/UIPaint.Internal.d.ts +21 -0
- package/dist/core/miscellaneous/paint/UIPaint.Internal.js +1 -0
- package/dist/core/miscellaneous/paint/UIPaint.d.ts +17 -0
- package/dist/core/miscellaneous/paint/UIPaint.js +21 -0
- package/dist/core/miscellaneous/paint/UIRadialGradient.d.ts +18 -0
- package/dist/core/miscellaneous/paint/UIRadialGradient.js +33 -0
- package/dist/core/miscellaneous/shared.d.ts +14 -0
- package/dist/core/miscellaneous/shared.js +11 -0
- package/dist/core/miscellaneous/text-style/UITextStyle.Internal.d.ts +91 -30
- package/dist/core/miscellaneous/text-style/UITextStyle.Internal.js +12 -8
- package/dist/core/miscellaneous/text-style/UITextStyle.d.ts +41 -63
- package/dist/core/miscellaneous/text-style/UITextStyle.js +165 -291
- package/dist/core/miscellaneous/texture/UITextureView.Internal.d.ts +2 -1
- package/dist/core/miscellaneous/texture/UITextureView.Internal.js +12 -3
- package/dist/core/shaders/UIProgressMaskFunctionCircular.js +1 -2
- package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.Internal.d.ts +7 -3
- package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.d.ts +2 -1
- package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.js +19 -10
- package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.Internal.d.ts +6 -2
- package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.d.ts +41 -9
- package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.js +97 -35
- 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 +48 -1
- package/dist/particles/elements/UIEmitter.Internal.js +26 -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 +241 -83
- 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
|
@@ -43,6 +43,7 @@ export class UIViewportLayer extends UILayer {
|
|
|
43
43
|
}
|
|
44
44
|
const scale = this.resizePolicy.calculateScale(width, height);
|
|
45
45
|
this.appliedPolicyVersion = this.resizePolicy.version;
|
|
46
|
+
this.appliedScale = scale;
|
|
46
47
|
this.resizeInternal(width * scale, height * scale);
|
|
47
48
|
};
|
|
48
49
|
/**
|
|
@@ -85,7 +86,7 @@ export class UIViewportLayer extends UILayer {
|
|
|
85
86
|
}
|
|
86
87
|
const position = this.reportPointer(event, this.signalPointerReleasedInternal);
|
|
87
88
|
if (position !== null) {
|
|
88
|
-
this.inputWrapperInternal.onPointerUp(position.x, position.y, event.pointerId);
|
|
89
|
+
this.inputWrapperInternal.onPointerUp(position.x, position.y, event.pointerId, event.pointerType === "mouse");
|
|
89
90
|
}
|
|
90
91
|
};
|
|
91
92
|
this.onPointerCancel = (event) => {
|
|
@@ -100,6 +101,7 @@ export class UIViewportLayer extends UILayer {
|
|
|
100
101
|
this.ownsViewport = options?.viewport === undefined;
|
|
101
102
|
this.resizePolicyInternal = resizePolicy;
|
|
102
103
|
this.appliedPolicyVersion = hasSize ? resizePolicy.version : -1;
|
|
104
|
+
this.appliedScale = scale;
|
|
103
105
|
viewport.signalResized.on(this.onResize);
|
|
104
106
|
window.addEventListener("pointerdown", this.onPointerDown);
|
|
105
107
|
window.addEventListener("pointermove", this.onPointerMove);
|
|
@@ -178,6 +180,7 @@ export class UIViewportLayer extends UILayer {
|
|
|
178
180
|
if (this.resizePolicy.version !== this.appliedPolicyVersion) {
|
|
179
181
|
this.onResize();
|
|
180
182
|
}
|
|
183
|
+
this.setPixelDensity(renderer.getPixelRatio() / this.appliedScale);
|
|
181
184
|
super.renderInternal(renderer, deltaTime);
|
|
182
185
|
}
|
|
183
186
|
/**
|
|
@@ -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
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { CanvasTexture } from "three";
|
|
2
|
+
import type { UICanvas, UICanvasRenderingContext2D } from "../canvas.js";
|
|
3
|
+
/**
|
|
4
|
+
* Calculates the scale content is rasterized at. The required scale is rounded up to a step,
|
|
5
|
+
* so content that resizes smoothly is redrawn only when it crosses a step, and at most about 19%
|
|
6
|
+
* sharper than needed. The scale is then lowered until the longer side fits the raster limit.
|
|
7
|
+
* @param width Content width in content units
|
|
8
|
+
* @param height Content height in content units
|
|
9
|
+
* @param requiredScale Raster pixels per content unit needed for the content to look sharp
|
|
10
|
+
* @returns Raster pixels per content unit
|
|
11
|
+
*/
|
|
12
|
+
export declare function calculateRasterScale(width: number, height: number, requiredScale: number): number;
|
|
13
|
+
/**
|
|
14
|
+
* Canvas drawn into a texture. Owns the canvas, its 2D context and the texture. A texture of
|
|
15
|
+
* another size is created anew, since three.js cannot resize an uploaded texture.
|
|
16
|
+
*/
|
|
17
|
+
export declare class UICanvasSurface {
|
|
18
|
+
readonly canvas: UICanvas;
|
|
19
|
+
readonly context: UICanvasRenderingContext2D;
|
|
20
|
+
private textureInternal;
|
|
21
|
+
private scaleXInternal;
|
|
22
|
+
private scaleYInternal;
|
|
23
|
+
/**
|
|
24
|
+
* @param subject Name of the owner, used in errors
|
|
25
|
+
* @throws If the browser gives no 2D context
|
|
26
|
+
*/
|
|
27
|
+
constructor(subject: string);
|
|
28
|
+
/** Texture showing the canvas */
|
|
29
|
+
get texture(): CanvasTexture;
|
|
30
|
+
/** Canvas pixels per content unit horizontally, as set by the last `begin` */
|
|
31
|
+
get scaleX(): number;
|
|
32
|
+
/** Canvas pixels per content unit vertically, as set by the last `begin` */
|
|
33
|
+
get scaleY(): number;
|
|
34
|
+
/**
|
|
35
|
+
* Sizes the canvas for content rasterized at a scale and clears it. The canvas sides are whole
|
|
36
|
+
* pixels, so the transform the context is left with maps the content exactly onto them, and the
|
|
37
|
+
* content is drawn in content units.
|
|
38
|
+
* @param width Content width in content units
|
|
39
|
+
* @param height Content height in content units
|
|
40
|
+
* @param scale Raster pixels per content unit
|
|
41
|
+
* @returns True when the texture was replaced and the new one has to be passed to the plane
|
|
42
|
+
*/
|
|
43
|
+
begin(width: number, height: number, scale: number): boolean;
|
|
44
|
+
/** Frees the texture */
|
|
45
|
+
dispose(): void;
|
|
46
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { createCanvas, createCanvasTexture, getCanvas2DContext } from "../canvas.js";
|
|
2
|
+
/** Raster scales are rounded up to powers of two in steps of a quarter */
|
|
3
|
+
const RASTER_SCALE_STEPS_PER_OCTAVE = 4;
|
|
4
|
+
/** Longest side of a raster in pixels, kept within canvas limits of mobile browsers */
|
|
5
|
+
const RASTER_MAX_SIDE = 4096;
|
|
6
|
+
/** Smallest side of a raster in pixels */
|
|
7
|
+
const RASTER_MIN_SIDE = 2;
|
|
8
|
+
/**
|
|
9
|
+
* Calculates the scale content is rasterized at. The required scale is rounded up to a step,
|
|
10
|
+
* so content that resizes smoothly is redrawn only when it crosses a step, and at most about 19%
|
|
11
|
+
* sharper than needed. The scale is then lowered until the longer side fits the raster limit.
|
|
12
|
+
* @param width Content width in content units
|
|
13
|
+
* @param height Content height in content units
|
|
14
|
+
* @param requiredScale Raster pixels per content unit needed for the content to look sharp
|
|
15
|
+
* @returns Raster pixels per content unit
|
|
16
|
+
*/
|
|
17
|
+
export function calculateRasterScale(width, height, requiredScale) {
|
|
18
|
+
const steps = Math.ceil(Math.log2(requiredScale) * RASTER_SCALE_STEPS_PER_OCTAVE - 1e-6);
|
|
19
|
+
const scale = Math.pow(2, steps / RASTER_SCALE_STEPS_PER_OCTAVE);
|
|
20
|
+
return Math.min(scale, RASTER_MAX_SIDE / Math.max(width, height, 1));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Canvas drawn into a texture. Owns the canvas, its 2D context and the texture. A texture of
|
|
24
|
+
* another size is created anew, since three.js cannot resize an uploaded texture.
|
|
25
|
+
*/
|
|
26
|
+
export class UICanvasSurface {
|
|
27
|
+
/**
|
|
28
|
+
* @param subject Name of the owner, used in errors
|
|
29
|
+
* @throws If the browser gives no 2D context
|
|
30
|
+
*/
|
|
31
|
+
constructor(subject) {
|
|
32
|
+
this.scaleXInternal = 1;
|
|
33
|
+
this.scaleYInternal = 1;
|
|
34
|
+
this.canvas = createCanvas(RASTER_MIN_SIDE, RASTER_MIN_SIDE);
|
|
35
|
+
const context = getCanvas2DContext(this.canvas);
|
|
36
|
+
if (!context) {
|
|
37
|
+
throw new Error(`${subject}: failed to create canvas context`);
|
|
38
|
+
}
|
|
39
|
+
this.context = context;
|
|
40
|
+
this.textureInternal = createCanvasTexture(this.canvas);
|
|
41
|
+
this.textureInternal.needsUpdate = true;
|
|
42
|
+
}
|
|
43
|
+
/** Texture showing the canvas */
|
|
44
|
+
get texture() {
|
|
45
|
+
return this.textureInternal;
|
|
46
|
+
}
|
|
47
|
+
/** Canvas pixels per content unit horizontally, as set by the last `begin` */
|
|
48
|
+
get scaleX() {
|
|
49
|
+
return this.scaleXInternal;
|
|
50
|
+
}
|
|
51
|
+
/** Canvas pixels per content unit vertically, as set by the last `begin` */
|
|
52
|
+
get scaleY() {
|
|
53
|
+
return this.scaleYInternal;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Sizes the canvas for content rasterized at a scale and clears it. The canvas sides are whole
|
|
57
|
+
* pixels, so the transform the context is left with maps the content exactly onto them, and the
|
|
58
|
+
* content is drawn in content units.
|
|
59
|
+
* @param width Content width in content units
|
|
60
|
+
* @param height Content height in content units
|
|
61
|
+
* @param scale Raster pixels per content unit
|
|
62
|
+
* @returns True when the texture was replaced and the new one has to be passed to the plane
|
|
63
|
+
*/
|
|
64
|
+
begin(width, height, scale) {
|
|
65
|
+
const canvasWidth = Math.max(Math.ceil(width * scale), RASTER_MIN_SIDE);
|
|
66
|
+
const canvasHeight = Math.max(Math.ceil(height * scale), RASTER_MIN_SIDE);
|
|
67
|
+
const resized = this.canvas.width !== canvasWidth || this.canvas.height !== canvasHeight;
|
|
68
|
+
if (resized) {
|
|
69
|
+
this.canvas.width = canvasWidth;
|
|
70
|
+
this.canvas.height = canvasHeight;
|
|
71
|
+
this.textureInternal.dispose();
|
|
72
|
+
this.textureInternal = createCanvasTexture(this.canvas);
|
|
73
|
+
}
|
|
74
|
+
this.context.setTransform(1, 0, 0, 1, 0, 0);
|
|
75
|
+
this.context.clearRect(0, 0, canvasWidth, canvasHeight);
|
|
76
|
+
this.scaleXInternal = canvasWidth / width;
|
|
77
|
+
this.scaleYInternal = canvasHeight / height;
|
|
78
|
+
this.context.setTransform(this.scaleXInternal, 0, 0, this.scaleYInternal, 0, 0);
|
|
79
|
+
this.textureInternal.needsUpdate = true;
|
|
80
|
+
return resized;
|
|
81
|
+
}
|
|
82
|
+
/** Frees the texture */
|
|
83
|
+
dispose() {
|
|
84
|
+
this.textureInternal.dispose();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -189,6 +189,23 @@ export declare class UIColor {
|
|
|
189
189
|
set(uiColorConfig?: UIColorConfig): this;
|
|
190
190
|
/** Sets RGBA components directly */
|
|
191
191
|
setRGBA(r: number, g: number, b: number, a?: number): this;
|
|
192
|
+
/**
|
|
193
|
+
* Moves toward another color by a fraction, componentwise in RGBA as the components are stored
|
|
194
|
+
* (sRGB, like CSS transitions)
|
|
195
|
+
*
|
|
196
|
+
* @param color - Target color
|
|
197
|
+
* @param t - Fraction of the way, 0 keeps this color and 1 gives the target
|
|
198
|
+
*/
|
|
199
|
+
lerp(color: UIColor, t: number): this;
|
|
200
|
+
/**
|
|
201
|
+
* Sets to a color between two others, componentwise in RGBA as the components are stored
|
|
202
|
+
* (sRGB, like CSS transitions)
|
|
203
|
+
*
|
|
204
|
+
* @param from - Color at 0
|
|
205
|
+
* @param to - Color at 1
|
|
206
|
+
* @param t - Fraction of the way from `from` to `to`
|
|
207
|
+
*/
|
|
208
|
+
lerpColors(from: UIColor, to: UIColor, t: number): this;
|
|
192
209
|
/** Returns RGBA as 32-bit hex (RRGGBBAA) */
|
|
193
210
|
getHexRGBA(): number;
|
|
194
211
|
/** Returns RGB as 24-bit hex (RRGGBB) */
|
|
@@ -338,6 +338,28 @@ export class UIColor {
|
|
|
338
338
|
}
|
|
339
339
|
return this;
|
|
340
340
|
}
|
|
341
|
+
/**
|
|
342
|
+
* Moves toward another color by a fraction, componentwise in RGBA as the components are stored
|
|
343
|
+
* (sRGB, like CSS transitions)
|
|
344
|
+
*
|
|
345
|
+
* @param color - Target color
|
|
346
|
+
* @param t - Fraction of the way, 0 keeps this color and 1 gives the target
|
|
347
|
+
*/
|
|
348
|
+
lerp(color, t) {
|
|
349
|
+
return this.lerpColors(this, color, t);
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Sets to a color between two others, componentwise in RGBA as the components are stored
|
|
353
|
+
* (sRGB, like CSS transitions)
|
|
354
|
+
*
|
|
355
|
+
* @param from - Color at 0
|
|
356
|
+
* @param to - Color at 1
|
|
357
|
+
* @param t - Fraction of the way from `from` to `to`
|
|
358
|
+
*/
|
|
359
|
+
lerpColors(from, to, t) {
|
|
360
|
+
assertValidNumber(t, "UIColor.lerpColors.t");
|
|
361
|
+
return this.setRGBA(MathUtils.lerp(from.r, to.r, t), MathUtils.lerp(from.g, to.g, t), MathUtils.lerp(from.b, to.b, t), MathUtils.lerp(from.a, to.a, t));
|
|
362
|
+
}
|
|
341
363
|
/** Returns RGBA as 32-bit hex (RRGGBBAA) */
|
|
342
364
|
getHexRGBA() {
|
|
343
365
|
this.ensureRGBUpdatedFromHSL();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { UIColorConfig } from "./UIColor.Internal.js";
|
|
2
|
+
/**
|
|
3
|
+
* Converts a color to a canvas color. A `UIColor` name means the color `UIColor` gives it, any
|
|
4
|
+
* other string is taken as a CSS color and passed as it is, and any other value is converted
|
|
5
|
+
* through `UIColor`.
|
|
6
|
+
* @param color Color to convert
|
|
7
|
+
* @returns CSS color string
|
|
8
|
+
*/
|
|
9
|
+
export declare function toCanvasColor(color: UIColorConfig): string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { COLORS } from "./UIColor.Internal.js";
|
|
2
|
+
import { UIColor } from "./UIColor.js";
|
|
3
|
+
const TEMP_COLOR = new UIColor();
|
|
4
|
+
/**
|
|
5
|
+
* Converts a color to a canvas color. A `UIColor` name means the color `UIColor` gives it, any
|
|
6
|
+
* other string is taken as a CSS color and passed as it is, and any other value is converted
|
|
7
|
+
* through `UIColor`.
|
|
8
|
+
* @param color Color to convert
|
|
9
|
+
* @returns CSS color string
|
|
10
|
+
*/
|
|
11
|
+
export function toCanvasColor(color) {
|
|
12
|
+
return typeof color === "string" && COLORS[color] === undefined
|
|
13
|
+
? color
|
|
14
|
+
: TEMP_COLOR.set(color).toCSSColor();
|
|
15
|
+
}
|
|
@@ -7,6 +7,7 @@ export declare class UIInsets {
|
|
|
7
7
|
private tInternal;
|
|
8
8
|
private bInternal;
|
|
9
9
|
private dirtyInternal;
|
|
10
|
+
private versionInternal;
|
|
10
11
|
/**
|
|
11
12
|
* Creates UIInsets instance.
|
|
12
13
|
*
|
|
@@ -21,6 +22,8 @@ export declare class UIInsets {
|
|
|
21
22
|
get top(): number;
|
|
22
23
|
/** Bottom inset */
|
|
23
24
|
get bottom(): number;
|
|
25
|
+
/** Bumped by every change of a value, to compare with a value seen before */
|
|
26
|
+
get version(): number;
|
|
24
27
|
/** Left inset */
|
|
25
28
|
set left(value: number);
|
|
26
29
|
/** Right inset */
|
|
@@ -14,6 +14,7 @@ export class UIInsets {
|
|
|
14
14
|
this.tInternal = INSETS_DEFAULT_VALUE;
|
|
15
15
|
this.bInternal = INSETS_DEFAULT_VALUE;
|
|
16
16
|
this.dirtyInternal = false;
|
|
17
|
+
this.versionInternal = 0;
|
|
17
18
|
this.set(config);
|
|
18
19
|
}
|
|
19
20
|
/** Left inset */
|
|
@@ -32,6 +33,10 @@ export class UIInsets {
|
|
|
32
33
|
get bottom() {
|
|
33
34
|
return this.bInternal;
|
|
34
35
|
}
|
|
36
|
+
/** Bumped by every change of a value, to compare with a value seen before */
|
|
37
|
+
get version() {
|
|
38
|
+
return this.versionInternal;
|
|
39
|
+
}
|
|
35
40
|
/** @internal */
|
|
36
41
|
get dirty() {
|
|
37
42
|
return this.dirtyInternal;
|
|
@@ -42,6 +47,7 @@ export class UIInsets {
|
|
|
42
47
|
if (this.lInternal !== value) {
|
|
43
48
|
this.lInternal = value;
|
|
44
49
|
this.dirtyInternal = true;
|
|
50
|
+
this.versionInternal++;
|
|
45
51
|
}
|
|
46
52
|
}
|
|
47
53
|
/** Right inset */
|
|
@@ -50,6 +56,7 @@ export class UIInsets {
|
|
|
50
56
|
if (this.rInternal !== value) {
|
|
51
57
|
this.rInternal = value;
|
|
52
58
|
this.dirtyInternal = true;
|
|
59
|
+
this.versionInternal++;
|
|
53
60
|
}
|
|
54
61
|
}
|
|
55
62
|
/** Top inset */
|
|
@@ -58,6 +65,7 @@ export class UIInsets {
|
|
|
58
65
|
if (this.tInternal !== value) {
|
|
59
66
|
this.tInternal = value;
|
|
60
67
|
this.dirtyInternal = true;
|
|
68
|
+
this.versionInternal++;
|
|
61
69
|
}
|
|
62
70
|
}
|
|
63
71
|
/** Bottom inset */
|
|
@@ -66,6 +74,7 @@ export class UIInsets {
|
|
|
66
74
|
if (this.bInternal !== value) {
|
|
67
75
|
this.bInternal = value;
|
|
68
76
|
this.dirtyInternal = true;
|
|
77
|
+
this.versionInternal++;
|
|
69
78
|
}
|
|
70
79
|
}
|
|
71
80
|
/** Sets left and right to same value */
|
|
@@ -75,6 +84,7 @@ export class UIInsets {
|
|
|
75
84
|
this.lInternal = value;
|
|
76
85
|
this.rInternal = value;
|
|
77
86
|
this.dirtyInternal = true;
|
|
87
|
+
this.versionInternal++;
|
|
78
88
|
}
|
|
79
89
|
}
|
|
80
90
|
/** Sets top and bottom to same value */
|
|
@@ -84,6 +94,7 @@ export class UIInsets {
|
|
|
84
94
|
this.tInternal = value;
|
|
85
95
|
this.bInternal = value;
|
|
86
96
|
this.dirtyInternal = true;
|
|
97
|
+
this.versionInternal++;
|
|
87
98
|
}
|
|
88
99
|
}
|
|
89
100
|
/** Sets all sides to same value */
|
|
@@ -98,6 +109,7 @@ export class UIInsets {
|
|
|
98
109
|
this.tInternal = value;
|
|
99
110
|
this.bInternal = value;
|
|
100
111
|
this.dirtyInternal = true;
|
|
112
|
+
this.versionInternal++;
|
|
101
113
|
}
|
|
102
114
|
}
|
|
103
115
|
/** Sets insets */
|
|
@@ -174,6 +186,7 @@ export class UIInsets {
|
|
|
174
186
|
this.tInternal !== tOld ||
|
|
175
187
|
this.bInternal !== bOld) {
|
|
176
188
|
this.dirtyInternal = true;
|
|
189
|
+
this.versionInternal++;
|
|
177
190
|
}
|
|
178
191
|
}
|
|
179
192
|
/** Sets from Vector4 (x=left, y=right, z=top, w=bottom) */
|
|
@@ -191,6 +204,7 @@ export class UIInsets {
|
|
|
191
204
|
this.tInternal = vector.z;
|
|
192
205
|
this.bInternal = vector.w;
|
|
193
206
|
this.dirtyInternal = true;
|
|
207
|
+
this.versionInternal++;
|
|
194
208
|
}
|
|
195
209
|
}
|
|
196
210
|
/** Converts to Vector4 (left, right, top, bottom) */
|
|
@@ -212,6 +226,7 @@ export class UIInsets {
|
|
|
212
226
|
this.tInternal = other.tInternal;
|
|
213
227
|
this.bInternal = other.bInternal;
|
|
214
228
|
this.dirtyInternal = true;
|
|
229
|
+
this.versionInternal++;
|
|
215
230
|
}
|
|
216
231
|
}
|
|
217
232
|
/** @internal */
|
|
@@ -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
|
}
|