laymur 0.27.0 → 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.
Files changed (98) hide show
  1. package/README.md +48 -3
  2. package/dist/core/constraints/UIAspectConstraint/UIAspectConstraint.js +2 -1
  3. package/dist/core/constraints/UICustomConstraint.js +1 -1
  4. package/dist/core/constraints/UIHeightConstraint/UIHeightConstraint.js +2 -1
  5. package/dist/core/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.js +2 -1
  6. package/dist/core/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.js +2 -1
  7. package/dist/core/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.js +2 -1
  8. package/dist/core/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.js +2 -1
  9. package/dist/core/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.js +2 -1
  10. package/dist/core/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.js +2 -1
  11. package/dist/core/constraints/UIWidthConstraint/UIWidthConstraint.js +2 -1
  12. package/dist/core/constraints/constraintAsserts.d.ts +41 -0
  13. package/dist/core/constraints/constraintAsserts.js +171 -0
  14. package/dist/core/elements/UIDummy/UIDummy.d.ts +8 -5
  15. package/dist/core/elements/UIDummy/UIDummy.js +21 -10
  16. package/dist/core/elements/UIElement/UIElement.Internal.d.ts +6 -5
  17. package/dist/core/elements/UIElement/UIElement.Internal.js +0 -4
  18. package/dist/core/elements/UIElement/UIElement.d.ts +12 -6
  19. package/dist/core/elements/UIElement/UIElement.js +14 -7
  20. package/dist/core/elements/UIText/UIText.d.ts +6 -1
  21. package/dist/core/elements/UIText/UIText.js +22 -12
  22. package/dist/core/layers/UIViewportLayer/UIViewportLayer.js +1 -1
  23. package/dist/core/miscellaneous/UIBlendMode.d.ts +5 -0
  24. package/dist/core/miscellaneous/UIBlendMode.js +7 -0
  25. package/dist/core/miscellaneous/asserts.d.ts +0 -41
  26. package/dist/core/miscellaneous/asserts.js +0 -170
  27. package/dist/core/miscellaneous/canvas.js +3 -0
  28. package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Internal.js +2 -1
  29. package/dist/core/miscellaneous/mask/UIMaskMaterialPatch.js +2 -1
  30. package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionCircular.d.ts +10 -7
  31. package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionCircular.js +11 -8
  32. package/dist/core/miscellaneous/resize-policy/UIResizePolicyCover.d.ts +1 -1
  33. package/dist/core/miscellaneous/resize-policy/UIResizePolicyCover.js +1 -1
  34. package/dist/core/miscellaneous/resize-policy/UIResizePolicyFit.d.ts +1 -1
  35. package/dist/core/miscellaneous/resize-policy/UIResizePolicyFit.js +1 -1
  36. package/dist/core/miscellaneous/text-style/UITextStyle.Internal.d.ts +4 -1
  37. package/dist/core/miscellaneous/text-style/UITextStyle.d.ts +4 -1
  38. package/dist/core/miscellaneous/text-style/UITextStyle.js +4 -1
  39. package/dist/core/shaders/UIProgressMaskFunctionCircular.js +1 -2
  40. package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.Internal.d.ts +6 -2
  41. package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.d.ts +1 -0
  42. package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.js +18 -9
  43. package/dist/debug/UIAspectDebug.js +4 -7
  44. package/dist/debug/UIHeightDebug.js +4 -4
  45. package/dist/debug/UIHorizontalDistanceDebug.js +4 -7
  46. package/dist/debug/UIHorizontalInterpolationDebug.js +11 -10
  47. package/dist/debug/UIVerticalDistanceDebug.js +4 -7
  48. package/dist/debug/UIVerticalInterpolationDebug.js +11 -10
  49. package/dist/debug/UIWidthDebug.js +4 -4
  50. package/dist/debug/miscellaneous.d.ts +7 -0
  51. package/dist/debug/miscellaneous.js +11 -1
  52. package/dist/particles/behaviorModules/UIBehaviorAlignToVelocity.d.ts +44 -0
  53. package/dist/particles/behaviorModules/UIBehaviorAlignToVelocity.js +75 -0
  54. package/dist/particles/behaviorModules/UIBehaviorBounce.d.ts +51 -0
  55. package/dist/particles/behaviorModules/UIBehaviorBounce.js +107 -0
  56. package/dist/particles/behaviorModules/UIBehaviorOrbit.d.ts +39 -0
  57. package/dist/particles/behaviorModules/UIBehaviorOrbit.js +73 -0
  58. package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.d.ts +7 -2
  59. package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.js +9 -5
  60. package/dist/particles/behaviorModules/UIBehaviorSeek.d.ts +38 -0
  61. package/dist/particles/behaviorModules/UIBehaviorSeek.js +75 -0
  62. package/dist/particles/elements/UIEmitter.Internal.d.ts +45 -1
  63. package/dist/particles/elements/UIEmitter.Internal.js +25 -1
  64. package/dist/particles/elements/UIEmitter.Schedule.d.ts +31 -0
  65. package/dist/particles/elements/UIEmitter.Schedule.js +81 -0
  66. package/dist/particles/elements/UIEmitter.d.ts +79 -9
  67. package/dist/particles/elements/UIEmitter.js +239 -82
  68. package/dist/particles/index.d.ts +13 -1
  69. package/dist/particles/index.js +11 -1
  70. package/dist/particles/instancedParticle/UIInstancedParticle.Internal.d.ts +6 -0
  71. package/dist/particles/instancedParticle/UIInstancedParticle.Internal.js +27 -0
  72. package/dist/particles/instancedParticle/UIInstancedParticle.d.ts +7 -1
  73. package/dist/particles/instancedParticle/UIInstancedParticle.js +12 -1
  74. package/dist/particles/miscellaneous/miscellaneous.d.ts +22 -0
  75. package/dist/particles/miscellaneous/miscellaneous.js +38 -0
  76. package/dist/particles/renderingModules/UIRenderingFlipbook.d.ts +41 -0
  77. package/dist/particles/renderingModules/UIRenderingFlipbook.js +70 -0
  78. package/dist/particles/renderingModules/UIRenderingModule.d.ts +2 -1
  79. package/dist/particles/renderingModules/UIRenderingModule.js +2 -1
  80. package/dist/particles/renderingModules/UIRenderingRandomColor.d.ts +19 -0
  81. package/dist/particles/renderingModules/UIRenderingRandomColor.js +28 -0
  82. package/dist/particles/renderingModules/UIRenderingShape.d.ts +31 -0
  83. package/dist/particles/renderingModules/UIRenderingShape.js +54 -0
  84. package/dist/particles/renderingModules/UIRenderingTexture.d.ts +1 -1
  85. package/dist/particles/renderingModules/UIRenderingTexture.js +4 -28
  86. package/dist/particles/shaders/UIRenderingFlipbook.d.ts +5 -0
  87. package/dist/particles/shaders/UIRenderingFlipbook.js +19 -0
  88. package/dist/particles/shaders/UIRenderingRandomColor.d.ts +2 -0
  89. package/dist/particles/shaders/UIRenderingRandomColor.js +10 -0
  90. package/dist/particles/shaders/UIRenderingShape.d.ts +6 -0
  91. package/dist/particles/shaders/UIRenderingShape.js +15 -0
  92. package/dist/particles/shaders/UIRenderingTexture.d.ts +4 -2
  93. package/dist/particles/shaders/UIRenderingTexture.js +27 -2
  94. package/dist/particles/spawnModules/UISpawnCircle.d.ts +44 -0
  95. package/dist/particles/spawnModules/UISpawnCircle.js +81 -0
  96. package/dist/particles/spawnModules/UISpawnRadialVelocity.d.ts +37 -0
  97. package/dist/particles/spawnModules/UISpawnRadialVelocity.js +75 -0
  98. package/package.json +24 -21
@@ -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
- /** Text content as string, span config, or array */
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 paddingV = this.paddingInternal.top + this.paddingInternal.bottom;
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 paddingV = this.paddingInternal.top + this.paddingInternal.bottom;
238
- const paddingH = this.paddingInternal.left + this.paddingInternal.right;
239
- this.height = desiredTextSize.height + paddingV;
240
- this.width = desiredTextSize.width + paddingH;
241
- const { lines: realTextLines, size: realTextSize } = calculateTextContentParameters(textChunks, Math.round(this.width) - paddingH, this.isRTL);
242
- this.height = realTextSize.height + paddingV;
243
- this.width = realTextSize.width + paddingH;
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
@@ -44,5 +44,8 @@ export function createCanvasTexture(canvas) {
44
44
  const texture = new CanvasTexture(canvas, UVMapping, ClampToEdgeWrapping, ClampToEdgeWrapping, LinearFilter, LinearFilter, RGBAFormat, UnsignedByteType, 1);
45
45
  texture.colorSpace = checkSRGBSupport() ? SRGBColorSpace : NoColorSpace;
46
46
  texture.generateMipmaps = false;
47
+ // The typings of three 0.181 and later make CanvasTexture generic over its image, with
48
+ // HTMLCanvasElement as the default; earlier ones have no type parameter to name UICanvas
49
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- needed from three 0.181 on
47
50
  return texture;
48
51
  }
@@ -212,7 +212,8 @@ export function buildMaterial(source, uniformProperties, layout, transparency, m
212
212
  premultipliedAlpha,
213
213
  });
214
214
  if (masked) {
215
- // fwidth on WebGL1 (three.js before r163); WebGL2 has derivatives built in
215
+ // fwidth on WebGL1 (three.js before r163); WebGL2 has derivatives built in. The typings of
216
+ // r163 and later no longer declare the flag
216
217
  material.extensions.derivatives = true;
217
218
  }
218
219
  return { material, varyingRowCount: packed.rowCount };
@@ -101,7 +101,8 @@ function install(material, uniforms, baseCacheKey) {
101
101
  ? previousCompile.toString()
102
102
  : baseCacheKey.call(material)) + CACHE_KEY_SUFFIX;
103
103
  if (material instanceof ShaderMaterial) {
104
- // fwidth on WebGL1 (three.js before r163); built-in materials fall back to world units
104
+ // fwidth on WebGL1 (three.js before r163); built-in materials fall back to world units.
105
+ // The typings of r163 and later no longer declare the flag
105
106
  material.extensions.derivatives = true;
106
107
  material.defines = { ...material.defines };
107
108
  material.defines["LAYMUR_MASK_DERIVATIVES"] = "";
@@ -1,23 +1,26 @@
1
1
  import type { UIProperty } from "../generic-plane/shared.js";
2
2
  import { UIProgressMaskFunction } from "./UIProgressMaskFunction.js";
3
- /** Circular radial progress fill */
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 - Starting angle in radians
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
- /** Starting angle in radians */
17
+ /** Angle the fill starts from, in radians */
15
18
  get startAngle(): number;
16
- /** Whether fill is counter-clockwise */
19
+ /** Whether the fill goes clockwise instead of counter-clockwise */
17
20
  get inverseDirection(): boolean;
18
- /** Starting angle in radians */
21
+ /** Angle the fill starts from, in radians */
19
22
  set startAngle(value: number);
20
- /** Whether fill is counter-clockwise */
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
- /** Circular radial progress fill */
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 - Starting angle in radians
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
- /** Starting angle in radians */
21
+ /** Angle the fill starts from, in radians */
19
22
  get startAngle() {
20
23
  return this.startAngleInternal;
21
24
  }
22
- /** Whether fill is counter-clockwise */
25
+ /** Whether the fill goes clockwise instead of counter-clockwise */
23
26
  get inverseDirection() {
24
27
  return this.inverseDirectionInternal;
25
28
  }
26
- /** Starting angle in radians */
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 is counter-clockwise */
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
  }
@@ -1,5 +1,5 @@
1
1
  import { UIResizePolicy } from "./UIResizePolicy.js";
2
- /** Scales area to cover rect preserving proportions */
2
+ /** Scales area so the rect covers it preserving proportions (like CSS object-fit: cover) */
3
3
  export declare class UIResizePolicyCover extends UIResizePolicy {
4
4
  private rectWidthInternal;
5
5
  private rectHeightInternal;
@@ -1,6 +1,6 @@
1
1
  import { assertValidPositiveNumber } from "../asserts.js";
2
2
  import { UIResizePolicy } from "./UIResizePolicy.js";
3
- /** Scales area to cover rect preserving proportions */
3
+ /** Scales area so the rect covers it preserving proportions (like CSS object-fit: cover) */
4
4
  export class UIResizePolicyCover extends UIResizePolicy {
5
5
  /**
6
6
  * Creates cover resize policy.
@@ -1,5 +1,5 @@
1
1
  import { UIResizePolicy } from "./UIResizePolicy.js";
2
- /** Scales area to fit around rect preserving proportions */
2
+ /** Scales area so the rect fits inside it preserving proportions (like CSS object-fit: contain) */
3
3
  export declare class UIResizePolicyFit extends UIResizePolicy {
4
4
  private rectWidthInternal;
5
5
  private rectHeightInternal;
@@ -1,6 +1,6 @@
1
1
  import { assertValidPositiveNumber } from "../asserts.js";
2
2
  import { UIResizePolicy } from "./UIResizePolicy.js";
3
- /** Scales area to fit around rect preserving proportions */
3
+ /** Scales area so the rect fits inside it preserving proportions (like CSS object-fit: contain) */
4
4
  export class UIResizePolicyFit extends UIResizePolicy {
5
5
  /**
6
6
  * Creates fit resize policy.
@@ -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
- /** Line height in pixels */
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
- /** Line height in pixels */
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
- /** Line height in pixels */
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
- /** Returns true to stop the event for catchers below; ignored for a captured pointer */
14
- catchPointerUp: (x: number, y: number, identifier: number) => boolean;
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, "catchPointerDown", pointer);
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, "catchPointerMove"));
127
+ this.cancelBelow(identifier, this.dispatch(identifier, (catcher) => catcher.catchPointerMove(x, y, identifier)));
128
128
  }
129
- /** @internal */
130
- onPointerUp(x, y, identifier) {
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
- this.hoveringPointers.delete(identifier);
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, "catchPointerUp"));
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(x, y, identifier, name, pointer) {
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[name](x, y, identifier)) {
199
+ if (item.active && catchEvent(item)) {
191
200
  return item;
192
201
  }
193
202
  }