laymur 0.28.0 → 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.
Files changed (81) hide show
  1. package/README.md +53 -4
  2. package/dist/core/constraints/UIAspectConstraint/UIAspectConstraint.d.ts +14 -3
  3. package/dist/core/constraints/UIAspectConstraint/UIAspectConstraint.js +38 -5
  4. package/dist/core/constraints/UICustomConstraint.js +1 -1
  5. package/dist/core/constraints/UIHeightConstraint/UIHeightConstraint.js +1 -1
  6. package/dist/core/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.js +1 -1
  7. package/dist/core/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.js +1 -1
  8. package/dist/core/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.js +1 -1
  9. package/dist/core/constraints/UISingleParameterConstraint/UISingleParameterConstraint.d.ts +6 -0
  10. package/dist/core/constraints/UISingleParameterConstraint/UISingleParameterConstraint.js +8 -0
  11. package/dist/core/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.js +1 -1
  12. package/dist/core/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.js +1 -1
  13. package/dist/core/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.js +1 -1
  14. package/dist/core/constraints/UIWidthConstraint/UIWidthConstraint.js +1 -1
  15. package/dist/core/elements/UICanvasElement/UICanvasElement.d.ts +54 -0
  16. package/dist/core/elements/UICanvasElement/UICanvasElement.js +70 -0
  17. package/dist/core/elements/UIDummy/UIDummy.Internal.d.ts +2 -0
  18. package/dist/core/elements/UIDummy/UIDummy.js +3 -1
  19. package/dist/core/elements/UIGraphics/UIGraphics.Internal.d.ts +42 -2
  20. package/dist/core/elements/UIGraphics/UIGraphics.Internal.js +2 -2
  21. package/dist/core/elements/UIGraphics/UIGraphics.d.ts +48 -34
  22. package/dist/core/elements/UIGraphics/UIGraphics.js +196 -93
  23. package/dist/core/elements/UIImage/UIImage.d.ts +11 -1
  24. package/dist/core/elements/UIImage/UIImage.js +14 -0
  25. package/dist/core/elements/UIScene/UIScene.Internal.d.ts +10 -1
  26. package/dist/core/elements/UIScene/UIScene.Internal.js +1 -0
  27. package/dist/core/elements/UIScene/UIScene.d.ts +11 -1
  28. package/dist/core/elements/UIScene/UIScene.js +29 -5
  29. package/dist/core/elements/UIText/UIText.Interfaces.d.ts +2 -2
  30. package/dist/core/elements/UIText/UIText.Internal.d.ts +14 -1
  31. package/dist/core/elements/UIText/UIText.Internal.js +12 -0
  32. package/dist/core/elements/UIText/UIText.Measuring.d.ts +9 -4
  33. package/dist/core/elements/UIText/UIText.Measuring.js +17 -6
  34. package/dist/core/elements/UIText/UIText.Rendering.d.ts +7 -16
  35. package/dist/core/elements/UIText/UIText.Rendering.js +212 -46
  36. package/dist/core/elements/UIText/UIText.d.ts +58 -28
  37. package/dist/core/elements/UIText/UIText.js +113 -138
  38. package/dist/core/index.d.ts +10 -4
  39. package/dist/core/index.js +5 -1
  40. package/dist/core/layers/UILayer/UILayer.d.ts +17 -3
  41. package/dist/core/layers/UILayer/UILayer.js +35 -4
  42. package/dist/core/layers/UIViewportLayer/UIViewportLayer.d.ts +2 -0
  43. package/dist/core/layers/UIViewportLayer/UIViewportLayer.js +3 -0
  44. package/dist/core/miscellaneous/canvas-surface/UICanvasSurface.d.ts +46 -0
  45. package/dist/core/miscellaneous/canvas-surface/UICanvasSurface.js +86 -0
  46. package/dist/core/miscellaneous/color/UIColor.d.ts +17 -0
  47. package/dist/core/miscellaneous/color/UIColor.js +22 -0
  48. package/dist/core/miscellaneous/color/canvasColor.d.ts +9 -0
  49. package/dist/core/miscellaneous/color/canvasColor.js +15 -0
  50. package/dist/core/miscellaneous/insets/UIInsets.d.ts +3 -0
  51. package/dist/core/miscellaneous/insets/UIInsets.js +15 -0
  52. package/dist/core/miscellaneous/paint/UIGradient.Internal.d.ts +37 -0
  53. package/dist/core/miscellaneous/paint/UIGradient.Internal.js +14 -0
  54. package/dist/core/miscellaneous/paint/UIGradient.d.ts +18 -0
  55. package/dist/core/miscellaneous/paint/UIGradient.js +35 -0
  56. package/dist/core/miscellaneous/paint/UILinearGradient.d.ts +14 -0
  57. package/dist/core/miscellaneous/paint/UILinearGradient.js +22 -0
  58. package/dist/core/miscellaneous/paint/UIPaint.Internal.d.ts +21 -0
  59. package/dist/core/miscellaneous/paint/UIPaint.Internal.js +1 -0
  60. package/dist/core/miscellaneous/paint/UIPaint.d.ts +17 -0
  61. package/dist/core/miscellaneous/paint/UIPaint.js +21 -0
  62. package/dist/core/miscellaneous/paint/UIRadialGradient.d.ts +18 -0
  63. package/dist/core/miscellaneous/paint/UIRadialGradient.js +33 -0
  64. package/dist/core/miscellaneous/shared.d.ts +14 -0
  65. package/dist/core/miscellaneous/shared.js +11 -0
  66. package/dist/core/miscellaneous/text-style/UITextStyle.Internal.d.ts +88 -30
  67. package/dist/core/miscellaneous/text-style/UITextStyle.Internal.js +12 -8
  68. package/dist/core/miscellaneous/text-style/UITextStyle.d.ts +41 -66
  69. package/dist/core/miscellaneous/text-style/UITextStyle.js +165 -294
  70. package/dist/core/miscellaneous/texture/UITextureView.Internal.d.ts +2 -1
  71. package/dist/core/miscellaneous/texture/UITextureView.Internal.js +12 -3
  72. package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.Internal.d.ts +1 -1
  73. package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.d.ts +1 -1
  74. package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.js +1 -1
  75. package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.Internal.d.ts +6 -2
  76. package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.d.ts +41 -9
  77. package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.js +97 -35
  78. package/dist/particles/elements/UIEmitter.Internal.d.ts +3 -0
  79. package/dist/particles/elements/UIEmitter.Internal.js +1 -0
  80. package/dist/particles/elements/UIEmitter.js +3 -2
  81. package/package.json +1 -1
@@ -1,19 +1,19 @@
1
- import { createCanvas, createCanvasTexture, getCanvas2DContext, } from "../../miscellaneous/canvas.js";
2
- import { UIColor } from "../../miscellaneous/color/UIColor.js";
1
+ import { Ferrsign1 } from "ferrsign";
3
2
  import { UIInsets } from "../../miscellaneous/insets/UIInsets.js";
4
3
  import { UITextSpan } from "../../miscellaneous/text-span/UITextSpan.js";
5
4
  import { UITextStyle } from "../../miscellaneous/text-style/UITextStyle.js";
6
- import { UIAffineMatrix3 } from "../../miscellaneous/UIAffineMatrix3.js";
7
- import source from "../../shaders/UIImage.js";
8
- import { UIElement } from "../UIElement/UIElement.js";
5
+ import { UICanvasElement } from "../UICanvasElement/UICanvasElement.js";
9
6
  import { detectIsRTL } from "./UIText.Bidi.js";
10
- import { TEXT_DEFAULT_DIRECTION, TEXT_DEFAULT_MAX_LINE_WIDTH, TEXT_DEFAULT_RESIZE_MODE, UITextDirection, UITextResizeMode, } from "./UIText.Internal.js";
7
+ import { TEXT_DEFAULT_DIRECTION, TEXT_DEFAULT_LINE_BOX, TEXT_DEFAULT_MAX_LINE_WIDTH, TEXT_DEFAULT_RESIZE_MODE, UITextDirection, UITextResizeMode, } from "./UIText.Internal.js";
11
8
  import { buildTextChunks, calculateTextContentParameters } from "./UIText.Measuring.js";
12
9
  import { renderTextLines } from "./UIText.Rendering.js";
13
10
  /** Smallest width and height of the element, kept by empty and whitespace-only text */
14
11
  const TEXT_MIN_DIMENSION = 1;
15
- /** Canvas-based text rendering element */
16
- export class UIText extends UIElement {
12
+ /**
13
+ * Text element. The text is laid out in pixels of its style, which are the content units of the
14
+ * canvas it is drawn on.
15
+ */
16
+ export class UIText extends UICanvasElement {
17
17
  /**
18
18
  * Creates a new UIText instance.
19
19
  *
@@ -22,54 +22,33 @@ export class UIText extends UIElement {
22
22
  * @param options - Configuration options
23
23
  */
24
24
  constructor(layer, content, options = {}) {
25
- const canvas = createCanvas(2, 2);
26
- const context = getCanvas2DContext(canvas);
27
- if (!context) {
28
- throw new Error("UIText.constructor: failed to create canvas context");
29
- }
30
- const texture = createCanvasTexture(canvas);
31
- texture.needsUpdate = true;
32
- const color = new UIColor(options.color);
33
- super(layer, source, {
34
- texture: texture,
35
- textureTransform: new UIAffineMatrix3(),
36
- color,
37
- }, options);
38
- /** Padding last set by auto padding; any other value means it was changed by hand */
39
- this.lastAutoPadding = 0;
25
+ super(layer, "UIText.constructor", options);
26
+ /** Size of the laid out text with its padding, in pixels of the style */
27
+ this.contentWidth = TEXT_MIN_DIMENSION;
28
+ this.contentHeight = TEXT_MIN_DIMENSION;
40
29
  this.contentInternal = [];
41
30
  this.contentDirty = false;
42
31
  this.maxLineWidthDirty = false;
43
32
  this.resizeModeDirty = false;
44
33
  this.directionDirty = false;
45
34
  this.isRTL = false;
35
+ this.lineBoxDirty = false;
46
36
  this.textChunks = [];
47
- this.colorInternal = color;
37
+ this.textLines = [];
38
+ this.contentAspectInternal = 1;
39
+ this.signalContentAspectChangedInternal = new Ferrsign1();
48
40
  this.paddingInternal = new UIInsets(options.padding);
49
41
  this.autoPaddingInternal = options.padding === undefined;
42
+ this.autoPaddingVersion = this.paddingInternal.version;
50
43
  this.commonStyle = new UITextStyle(options.commonStyle);
51
44
  this.maxLineWidthInternal = options.maxLineWidth ?? TEXT_DEFAULT_MAX_LINE_WIDTH;
52
45
  this.resizeModeInternal = options.resizeMode ?? TEXT_DEFAULT_RESIZE_MODE;
53
46
  this.directionInternal = options.direction ?? TEXT_DEFAULT_DIRECTION;
54
- this.canvas = canvas;
55
- this.context = context;
56
- this.texture = texture;
47
+ this.lineBoxInternal = options.lineBox ?? TEXT_DEFAULT_LINE_BOX;
57
48
  this.content = content;
58
49
  this.lastWidth = this.width;
59
50
  this.lastHeight = this.height;
60
- this.updateAutoPadding();
61
- switch (this.resizeModeInternal) {
62
- case UITextResizeMode.SCALE:
63
- this.tryToRenderTextScaleMode();
64
- break;
65
- case UITextResizeMode.BREAK:
66
- this.tryToRenderTextBreakMode();
67
- break;
68
- }
69
- }
70
- /** Multiplicative tint. Alpha channel controls opacity. */
71
- get color() {
72
- return this.colorInternal;
51
+ this.layout(false);
73
52
  }
74
53
  /** Text content as array of styled spans */
75
54
  get content() {
@@ -79,16 +58,16 @@ export class UIText extends UIElement {
79
58
  get maxLineWidth() {
80
59
  return this.maxLineWidthInternal;
81
60
  }
82
- /** Text padding in world units */
61
+ /** Text padding in pixels of the style */
83
62
  get padding() {
84
63
  return this.paddingInternal;
85
64
  }
86
65
  /**
87
- * Whether the padding follows the stroke and shadow of the styles. On by default, off once
66
+ * Whether the padding follows the outlines and shadows of the styles. On by default, off once
88
67
  * the padding is set by hand.
89
68
  */
90
69
  get autoPadding() {
91
- return this.autoPaddingInternal;
70
+ return this.autoPaddingInternal && this.paddingInternal.version === this.autoPaddingVersion;
92
71
  }
93
72
  /** Controls how text adapts to element size */
94
73
  get resizeMode() {
@@ -98,9 +77,20 @@ export class UIText extends UIElement {
98
77
  get direction() {
99
78
  return this.directionInternal;
100
79
  }
101
- /** Multiplicative tint. Alpha channel controls opacity. */
102
- set color(value) {
103
- this.colorInternal.set(value);
80
+ /** What sets the height of a line */
81
+ get lineBox() {
82
+ return this.lineBoxInternal;
83
+ }
84
+ /**
85
+ * Aspect of the text laid out at `maxLineWidth` with its padding. A `UIAspectConstraint`
86
+ * created without an aspect follows it as the text changes.
87
+ */
88
+ get contentAspect() {
89
+ return this.contentAspectInternal;
90
+ }
91
+ /** Signal fired with the new aspect when the content aspect changes */
92
+ get signalContentAspectChanged() {
93
+ return this.signalContentAspectChangedInternal;
104
94
  }
105
95
  /**
106
96
  * Text content as string, span config, or array. Text without visible characters keeps the
@@ -137,20 +127,20 @@ export class UIText extends UIElement {
137
127
  this.maxLineWidthDirty = true;
138
128
  }
139
129
  }
140
- /** Text padding in world units. Turns auto padding off. */
130
+ /** Text padding in pixels of the style. Turns auto padding off. */
141
131
  set padding(value) {
142
132
  this.autoPaddingInternal = false;
143
133
  this.paddingInternal.set(value);
144
134
  }
145
135
  /**
146
- * Whether the padding follows the stroke and shadow of the styles. On by default, off once
136
+ * Whether the padding follows the outlines and shadows of the styles. On by default, off once
147
137
  * the padding is set by hand.
148
138
  */
149
139
  set autoPadding(value) {
150
- if (this.autoPaddingInternal !== value) {
140
+ if (this.autoPadding !== value) {
151
141
  this.autoPaddingInternal = value;
152
142
  if (value) {
153
- this.lastAutoPadding = Number.NaN;
143
+ this.autoPaddingVersion = this.paddingInternal.version;
154
144
  this.updateAutoPadding();
155
145
  }
156
146
  }
@@ -169,95 +159,108 @@ export class UIText extends UIElement {
169
159
  this.directionDirty = true;
170
160
  }
171
161
  }
172
- /** Frees resources of the text */
173
- destroyInternal() {
174
- this.texture.dispose();
175
- super.destroyInternal();
176
- }
177
- onWillRender(renderer, deltaTime) {
178
- switch (this.resizeModeInternal) {
179
- case UITextResizeMode.SCALE:
180
- this.tryToRenderTextScaleMode();
181
- break;
182
- case UITextResizeMode.BREAK:
183
- this.tryToRenderTextBreakMode();
184
- break;
162
+ /** What sets the height of a line */
163
+ set lineBox(value) {
164
+ if (this.lineBoxInternal !== value) {
165
+ this.lineBoxInternal = value;
166
+ this.lineBoxDirty = true;
185
167
  }
186
- super.onWillRender(renderer, deltaTime);
187
168
  }
188
- tryToRenderTextScaleMode() {
169
+ updateContent(layoutChanged) {
170
+ return this.layout(layoutChanged);
171
+ }
172
+ drawContent(context) {
173
+ renderTextLines(context, this.textLines, this.isRTL, this.paddingInternal.top, this.paddingInternal.left);
174
+ }
175
+ /**
176
+ * Lays the text out again when anything it depends on changed.
177
+ * @param layoutChanged Whether the solver changed the layout since the last call
178
+ * @returns True when the text was laid out again
179
+ */
180
+ layout(layoutChanged) {
189
181
  if (this.checkContentDirty()) {
190
182
  this.updateAutoPadding();
191
183
  }
192
- if (!this.colorInternal.dirty &&
193
- !this.resizeModeDirty &&
184
+ const laidOut = this.resizeModeInternal === UITextResizeMode.SCALE
185
+ ? this.layoutScaleMode(layoutChanged)
186
+ : this.layoutBreakMode(layoutChanged);
187
+ if (laidOut) {
188
+ this.resizeModeDirty = false;
189
+ this.directionDirty = false;
190
+ this.maxLineWidthDirty = false;
191
+ this.lineBoxDirty = false;
192
+ this.paddingInternal.setDirtyFalse();
193
+ this.setDimensionsDirtyFalse();
194
+ this.setContentDirtyFalse();
195
+ }
196
+ return laidOut;
197
+ }
198
+ layoutScaleMode(layoutChanged) {
199
+ if (!this.resizeModeDirty &&
194
200
  !this.directionDirty &&
195
201
  !this.maxLineWidthDirty &&
202
+ !this.lineBoxDirty &&
196
203
  !this.paddingInternal.dirty &&
197
- !(this.consumeLayoutChange() &&
204
+ !(layoutChanged &&
198
205
  this.lastWidth / this.lastHeight !== Math.round(this.width) / Math.round(this.height)) &&
199
206
  !this.checkContentDirty()) {
200
- return;
207
+ return false;
201
208
  }
202
209
  const textChunks = this.buildTextChunks();
203
210
  const { lines, size } = calculateTextContentParameters(textChunks, this.maxLineWidthInternal, this.isRTL);
204
211
  const { width: desiredWidth, height: desiredHeight } = this.elementSize(size);
212
+ this.updateContentAspect(desiredWidth / desiredHeight);
205
213
  this.width = desiredWidth;
206
214
  this.height = (desiredHeight / desiredWidth) * Math.round(this.width);
207
215
  this.width = (desiredWidth / desiredHeight) * Math.round(this.height);
208
- const safeWidth = Math.max(Math.round(desiredWidth), 2);
209
- const safeHeight = Math.max(Math.round(desiredHeight), 2);
210
- const resolutionDirty = this.canvas.width !== safeWidth || this.canvas.height !== safeHeight;
211
- if (resolutionDirty) {
212
- this.canvas.width = safeWidth;
213
- this.canvas.height = safeHeight;
214
- }
215
- renderTextLines(this.paddingInternal.top, this.paddingInternal.left, lines, this.isRTL, this.context);
216
- this.updateProperties(resolutionDirty);
217
- this.resizeModeDirty = false;
218
- this.directionDirty = false;
219
- this.maxLineWidthDirty = false;
220
- this.paddingInternal.setDirtyFalse();
221
- this.setDimensionsDirtyFalse();
222
- this.setContentDirtyFalse();
216
+ this.setContent(lines, desiredWidth, desiredHeight);
217
+ return true;
223
218
  }
224
- tryToRenderTextBreakMode() {
225
- if (this.checkContentDirty()) {
226
- this.updateAutoPadding();
227
- }
228
- if (!this.colorInternal.dirty &&
229
- !this.resizeModeDirty &&
219
+ layoutBreakMode(layoutChanged) {
220
+ if (!this.resizeModeDirty &&
230
221
  !this.directionDirty &&
231
222
  !this.maxLineWidthDirty &&
223
+ !this.lineBoxDirty &&
232
224
  !this.paddingInternal.dirty &&
233
- !this.consumeDimensionsChange() &&
225
+ !(layoutChanged &&
226
+ (this.lastWidth !== Math.round(this.width) || this.lastHeight !== Math.round(this.height))) &&
234
227
  !this.checkContentDirty()) {
235
- return;
228
+ return false;
236
229
  }
237
230
  const textChunks = this.buildTextChunks();
238
231
  const { size: desiredTextSize } = calculateTextContentParameters(textChunks, this.maxLineWidthInternal, this.isRTL);
239
232
  const desiredSize = this.elementSize(desiredTextSize);
233
+ this.updateContentAspect(desiredSize.width / desiredSize.height);
240
234
  this.height = desiredSize.height;
241
235
  this.width = desiredSize.width;
242
236
  const { lines: realTextLines, size: realTextSize } = calculateTextContentParameters(textChunks, Math.round(this.width) - this.paddingInternal.left - this.paddingInternal.right, this.isRTL);
243
237
  const realSize = this.elementSize(realTextSize);
244
238
  this.height = realSize.height;
245
239
  this.width = realSize.width;
246
- const safeWidth = Math.max(Math.round(this.width), 2);
247
- const safeHeight = Math.max(Math.round(this.height), 2);
248
- const resolutionDirty = this.canvas.width !== safeWidth || this.canvas.height !== safeHeight;
249
- if (resolutionDirty) {
250
- this.canvas.width = safeWidth;
251
- this.canvas.height = safeHeight;
240
+ this.setContent(realTextLines, this.width, this.height);
241
+ return true;
242
+ }
243
+ /**
244
+ * Reports a new content aspect. Called before the element suggests its size, so constraints
245
+ * following the aspect are updated by then.
246
+ * @param aspect Aspect of the text laid out at `maxLineWidth`
247
+ */
248
+ updateContentAspect(aspect) {
249
+ if (aspect !== this.contentAspectInternal) {
250
+ this.contentAspectInternal = aspect;
251
+ this.signalContentAspectChangedInternal.emit(aspect);
252
252
  }
253
- renderTextLines(this.paddingInternal.top, this.paddingInternal.left, realTextLines, this.isRTL, this.context);
254
- this.updateProperties(resolutionDirty);
255
- this.resizeModeDirty = false;
256
- this.directionDirty = false;
257
- this.maxLineWidthDirty = false;
258
- this.paddingInternal.setDirtyFalse();
259
- this.setDimensionsDirtyFalse();
260
- this.setContentDirtyFalse();
253
+ }
254
+ /**
255
+ * Keeps the result of a layout.
256
+ * @param lines Laid out lines
257
+ * @param width Width of the content with its padding in pixels
258
+ * @param height Height of the content with its padding in pixels
259
+ */
260
+ setContent(lines, width, height) {
261
+ this.textLines = lines;
262
+ this.contentWidth = Math.max(Math.round(width), TEXT_MIN_DIMENSION);
263
+ this.contentHeight = Math.max(Math.round(height), TEXT_MIN_DIMENSION);
261
264
  }
262
265
  /** The element size for a text size: the padding added, at least the minimum each way */
263
266
  elementSize(textSize) {
@@ -267,53 +270,25 @@ export class UIText extends UIElement {
267
270
  height: Math.max(textSize.height + top + bottom, TEXT_MIN_DIMENSION),
268
271
  };
269
272
  }
270
- updateProperties(resolutionDirty) {
271
- let properties;
272
- if (this.colorInternal.dirty) {
273
- properties ?? (properties = {});
274
- properties["color"] = this.colorInternal;
275
- this.colorInternal.setDirtyFalse();
276
- }
277
- if (resolutionDirty) {
278
- this.texture.dispose();
279
- this.texture = createCanvasTexture(this.canvas);
280
- properties ?? (properties = {});
281
- properties["texture"] = this.texture;
282
- }
283
- this.texture.needsUpdate = true;
284
- if (properties) {
285
- this.sceneWrapper.setProperties(this.planeHandler, properties);
286
- }
287
- }
288
273
  updateAutoPadding() {
289
- if (!this.autoPaddingInternal) {
290
- return;
291
- }
292
- const { left, right, top, bottom } = this.paddingInternal;
293
- const last = this.lastAutoPadding;
294
- if (!Number.isNaN(last) &&
295
- (left !== last || right !== last || top !== last || bottom !== last)) {
274
+ if (!this.autoPadding) {
296
275
  this.autoPaddingInternal = false;
297
276
  return;
298
277
  }
299
278
  const padding = this.content.reduce((result, span) => Math.max(result, span.style.calculatePadding(this.commonStyle)), this.commonStyle.calculatePadding());
300
279
  this.paddingInternal.setUnified(padding);
301
- this.lastAutoPadding = padding;
280
+ this.autoPaddingVersion = this.paddingInternal.version;
302
281
  }
303
282
  buildTextChunks() {
304
- if (this.directionDirty || this.checkContentDirty()) {
283
+ if (this.directionDirty || this.lineBoxDirty || this.checkContentDirty()) {
305
284
  this.isRTL =
306
285
  this.directionInternal === UITextDirection.AUTO
307
286
  ? detectIsRTL(this.contentInternal)
308
287
  : this.directionInternal === UITextDirection.RTL;
309
- this.textChunks = buildTextChunks(this.context, this.contentInternal, this.commonStyle, this.isRTL);
288
+ this.textChunks = buildTextChunks(this.surface.context, this.contentInternal, this.commonStyle, this.isRTL, this.lineBoxInternal);
310
289
  }
311
290
  return this.textChunks;
312
291
  }
313
- consumeDimensionsChange() {
314
- return (this.consumeLayoutChange() &&
315
- (this.lastWidth !== Math.round(this.width) || this.lastHeight !== Math.round(this.height)));
316
- }
317
292
  setDimensionsDirtyFalse() {
318
293
  this.lastWidth = Math.round(this.width);
319
294
  this.lastHeight = Math.round(this.height);
@@ -35,7 +35,7 @@ export type { UIDummyOptions, UIInputEventData } from "./elements/UIDummy/UIDumm
35
35
  export { UIDummy } from "./elements/UIDummy/UIDummy.js";
36
36
  export type { UIElementOptions } from "./elements/UIElement/UIElement.Internal.js";
37
37
  export { UIElement } from "./elements/UIElement/UIElement.js";
38
- export type { UIGraphicsOptions } from "./elements/UIGraphics/UIGraphics.Internal.js";
38
+ export type { UIGraphicsCornerRadius, UIGraphicsOptions, UIGraphicsStrokeConfig, UIGraphicsStyle, } from "./elements/UIGraphics/UIGraphics.Internal.js";
39
39
  export { UIGraphics } from "./elements/UIGraphics/UIGraphics.js";
40
40
  export type { UIImageOptions } from "./elements/UIImage/UIImage.Internal.js";
41
41
  export { UIImage } from "./elements/UIImage/UIImage.js";
@@ -49,7 +49,7 @@ export { UISceneUpdateMode } from "./elements/UIScene/UIScene.Internal.js";
49
49
  export { UIScene } from "./elements/UIScene/UIScene.js";
50
50
  export type { UITextContent } from "./elements/UIText/UIText.Interfaces.js";
51
51
  export type { UITextOptions } from "./elements/UIText/UIText.Internal.js";
52
- export { UITextDirection, UITextResizeMode } from "./elements/UIText/UIText.Internal.js";
52
+ export { UITextDirection, UITextLineBox, UITextResizeMode, } from "./elements/UIText/UIText.Internal.js";
53
53
  export { UIText } from "./elements/UIText/UIText.js";
54
54
  export type { UILayerMode, UILayerOptions, UILayerOrientation, } from "./layers/UILayer/UILayer.Internal.js";
55
55
  export { UILayer } from "./layers/UILayer/UILayer.js";
@@ -78,6 +78,11 @@ export type { Vector2Like } from "./miscellaneous/math.js";
78
78
  export type { UIMicroConfig } from "./miscellaneous/micro/UIMicro.Internal.js";
79
79
  export { UIMicroAnchorMode } from "./miscellaneous/micro/UIMicro.Internal.js";
80
80
  export { UIMicro } from "./miscellaneous/micro/UIMicro.js";
81
+ export type { UIGradientStop, UILinearGradientOptions, UIRadialGradientOptions, } from "./miscellaneous/paint/UIGradient.Internal.js";
82
+ export { UIGradient } from "./miscellaneous/paint/UIGradient.js";
83
+ export { UILinearGradient } from "./miscellaneous/paint/UILinearGradient.js";
84
+ export type { UILineCap, UILineJoin, UIPaint, UIPaintBox, UIPaintConfig, } from "./miscellaneous/paint/UIPaint.Internal.js";
85
+ export { UIRadialGradient } from "./miscellaneous/paint/UIRadialGradient.js";
81
86
  export { UIResizePolicy } from "./miscellaneous/resize-policy/UIResizePolicy.js";
82
87
  export { UIResizePolicyCover } from "./miscellaneous/resize-policy/UIResizePolicyCover.js";
83
88
  export { UIResizePolicyCross } from "./miscellaneous/resize-policy/UIResizePolicyCross.js";
@@ -86,10 +91,11 @@ export { UIResizePolicyFit } from "./miscellaneous/resize-policy/UIResizePolicyF
86
91
  export { UIResizePolicyFixedHeight } from "./miscellaneous/resize-policy/UIResizePolicyFixedHeight.js";
87
92
  export { UIResizePolicyFixedWidth } from "./miscellaneous/resize-policy/UIResizePolicyFixedWidth.js";
88
93
  export { UIResizePolicyNone } from "./miscellaneous/resize-policy/UIResizePolicyNone.js";
89
- export type { UILayerElement, UIPlaneElement, UIPointElement } from "./miscellaneous/shared.js";
94
+ export type { UIContentAspectElement, UILayerElement, UIPlaneElement, UIPointElement, } from "./miscellaneous/shared.js";
90
95
  export type { UITextSpanConfig } from "./miscellaneous/text-span/UITextSpan.Internal.js";
91
96
  export { UITextSpan } from "./miscellaneous/text-span/UITextSpan.js";
92
- export type { UITextAlign, UITextStyleConfig, } from "./miscellaneous/text-style/UITextStyle.Internal.js";
97
+ export type { UITextAlign, UITextFontStyle, UITextFontWeight, UITextShadow, UITextShadowConfig, UITextStroke, UITextStrokeConfig, UITextStyleConfig, } from "./miscellaneous/text-style/UITextStyle.Internal.js";
98
+ export { UITextPaintBox } from "./miscellaneous/text-style/UITextStyle.Internal.js";
93
99
  export { UITextStyle } from "./miscellaneous/text-style/UITextStyle.js";
94
100
  export type { UITextureAtlasConfig, UITextureConfig, UITextureRect, UITextureSize, UITextureTrim, } from "./miscellaneous/texture/UITextureView.Internal.js";
95
101
  export { UITextureView } from "./miscellaneous/texture/UITextureView.js";
@@ -25,7 +25,7 @@ export { UINineSlice } from "./elements/UINineSlice/UINineSlice.js";
25
25
  export { UIProgress } from "./elements/UIProgress/UIProgress.js";
26
26
  export { UISceneUpdateMode } from "./elements/UIScene/UIScene.Internal.js";
27
27
  export { UIScene } from "./elements/UIScene/UIScene.js";
28
- export { UITextDirection, UITextResizeMode } from "./elements/UIText/UIText.Internal.js";
28
+ export { UITextDirection, UITextLineBox, UITextResizeMode, } from "./elements/UIText/UIText.Internal.js";
29
29
  export { UIText } from "./elements/UIText/UIText.js";
30
30
  export { UILayer } from "./layers/UILayer/UILayer.js";
31
31
  export { UIViewportLayer } from "./layers/UIViewportLayer/UIViewportLayer.js";
@@ -45,6 +45,9 @@ export { UIProgressMaskFunctionCircular } from "./miscellaneous/mask-function/UI
45
45
  export { UIProgressMaskFunctionDirectional } from "./miscellaneous/mask-function/UIProgressMaskFunctionDirectional.js";
46
46
  export { UIMicroAnchorMode } from "./miscellaneous/micro/UIMicro.Internal.js";
47
47
  export { UIMicro } from "./miscellaneous/micro/UIMicro.js";
48
+ export { UIGradient } from "./miscellaneous/paint/UIGradient.js";
49
+ export { UILinearGradient } from "./miscellaneous/paint/UILinearGradient.js";
50
+ export { UIRadialGradient } from "./miscellaneous/paint/UIRadialGradient.js";
48
51
  export { UIResizePolicy } from "./miscellaneous/resize-policy/UIResizePolicy.js";
49
52
  export { UIResizePolicyCover } from "./miscellaneous/resize-policy/UIResizePolicyCover.js";
50
53
  export { UIResizePolicyCross } from "./miscellaneous/resize-policy/UIResizePolicyCross.js";
@@ -54,6 +57,7 @@ export { UIResizePolicyFixedHeight } from "./miscellaneous/resize-policy/UIResiz
54
57
  export { UIResizePolicyFixedWidth } from "./miscellaneous/resize-policy/UIResizePolicyFixedWidth.js";
55
58
  export { UIResizePolicyNone } from "./miscellaneous/resize-policy/UIResizePolicyNone.js";
56
59
  export { UITextSpan } from "./miscellaneous/text-span/UITextSpan.js";
60
+ export { UITextPaintBox } from "./miscellaneous/text-style/UITextStyle.Internal.js";
57
61
  export { UITextStyle } from "./miscellaneous/text-style/UITextStyle.js";
58
62
  export { UITextureView } from "./miscellaneous/texture/UITextureView.js";
59
63
  export { UIAffineMatrix3 } from "./miscellaneous/UIAffineMatrix3.js";
@@ -24,6 +24,7 @@ export declare abstract class UILayer implements UIPlaneElement {
24
24
  private readonly sceneWrapperInternal;
25
25
  private modeInternal;
26
26
  private orientationInternal;
27
+ private pixelDensityInternal;
27
28
  private readonly signalOrientationChangedInternal;
28
29
  private readonly signalModeChangedInternal;
29
30
  private readonly signalRenderingInternal;
@@ -73,12 +74,12 @@ export declare abstract class UILayer implements UIPlaneElement {
73
74
  get signalResized(): FerrsignView3<number, number, UILayer>;
74
75
  /**
75
76
  * Signal fired when the WebGL context of the renderer the layer is drawn with is lost. The
76
- * layer draws nothing until the context is restored; pause what depends on frames being shown.
77
+ * layer draws nothing until the context is restored, so pause what depends on frames being shown.
77
78
  */
78
79
  get signalContextLost(): FerrsignView1<UILayer>;
79
80
  /**
80
81
  * Signal fired when the WebGL context is restored. The renderer has recreated its GL state by
81
- * then; content that lives on the GPU only, such as render targets, has to be redrawn.
82
+ * then. Content that lives on the GPU only, such as render targets, has to be redrawn.
82
83
  */
83
84
  get signalContextRestored(): FerrsignView1<UILayer>;
84
85
  /**
@@ -96,6 +97,12 @@ export declare abstract class UILayer implements UIPlaneElement {
96
97
  get maskRegistry(): readonly UIMask[];
97
98
  /** Whether the layer is destroyed */
98
99
  get destroyed(): boolean;
100
+ /**
101
+ * Screen pixels per world unit, as of the last render. Canvas-drawn elements and `UIScene`
102
+ * rasterize at this density, so their content stays sharp on high-DPI screens. 1 for a layer
103
+ * that does not know its screen size.
104
+ */
105
+ get pixelDensity(): number;
99
106
  /**
100
107
  * Updates visibility and interactivity mode. A layer that stops taking input cancels the
101
108
  * pressed pointers: their releases would never arrive.
@@ -108,18 +115,25 @@ export declare abstract class UILayer implements UIPlaneElement {
108
115
  */
109
116
  destroy(): void;
110
117
  protected resizeInternal(width: number, height: number): void;
118
+ /** Sets the screen pixels per world unit, read by elements on their next render */
119
+ protected setPixelDensity(value: number): void;
111
120
  protected renderInternal(renderer: WebGLRenderer, deltaTime: number): void;
112
121
  /**
113
122
  * Cancels every pressed pointer, for its elements and for the layer: no release of those
114
123
  * pointers will be reported.
115
124
  */
116
125
  protected cancelPointers(): void;
117
- /** Follows the context of the renderer the layer is drawn with; null to stop following */
126
+ /** Follows the context of the renderer the layer is drawn with, or stops following with null */
118
127
  private bindContextMonitor;
119
128
  private readonly onContextLost;
120
129
  private readonly onContextRestored;
121
130
  /** A removal signal handler may destroy other constraints, so the registry is walked over a copy */
122
131
  private destroyConstraints;
132
+ /**
133
+ * Reports constraints the solver rejected for conflicting with required constraints. Throws in
134
+ * development builds. Warns in production builds, where the layout goes on without them.
135
+ */
136
+ private reportRejectedConstraints;
123
137
  /**
124
138
  * Called for each pointer the layer cancels, before its elements are told: the subclass that
125
139
  * takes the input reports the cancel to the users of the layer.
@@ -14,7 +14,10 @@ export class UILayer {
14
14
  /** Optional layer name */
15
15
  this.name = "";
16
16
  this.inputWrapperInternal = new UIInputWrapper();
17
- this.solverWrapperInternal = new UISolverWrapper();
17
+ this.solverWrapperInternal = new UISolverWrapper((constraints) => {
18
+ this.reportRejectedConstraints(constraints);
19
+ });
20
+ this.pixelDensityInternal = 1;
18
21
  this.signalOrientationChangedInternal = new Ferrsign2();
19
22
  this.signalModeChangedInternal = new Ferrsign2();
20
23
  this.signalRenderingInternal = new Ferrsign3();
@@ -124,14 +127,14 @@ export class UILayer {
124
127
  }
125
128
  /**
126
129
  * Signal fired when the WebGL context of the renderer the layer is drawn with is lost. The
127
- * layer draws nothing until the context is restored; pause what depends on frames being shown.
130
+ * layer draws nothing until the context is restored, so pause what depends on frames being shown.
128
131
  */
129
132
  get signalContextLost() {
130
133
  return this.signalContextLostInternal;
131
134
  }
132
135
  /**
133
136
  * Signal fired when the WebGL context is restored. The renderer has recreated its GL state by
134
- * then; content that lives on the GPU only, such as render targets, has to be redrawn.
137
+ * then. Content that lives on the GPU only, such as render targets, has to be redrawn.
135
138
  */
136
139
  get signalContextRestored() {
137
140
  return this.signalContextRestoredInternal;
@@ -163,6 +166,14 @@ export class UILayer {
163
166
  get destroyed() {
164
167
  return this.destroyedInternal;
165
168
  }
169
+ /**
170
+ * Screen pixels per world unit, as of the last render. Canvas-drawn elements and `UIScene`
171
+ * rasterize at this density, so their content stays sharp on high-DPI screens. 1 for a layer
172
+ * that does not know its screen size.
173
+ */
174
+ get pixelDensity() {
175
+ return this.pixelDensityInternal;
176
+ }
166
177
  /**
167
178
  * Updates visibility and interactivity mode. A layer that stops taking input cancels the
168
179
  * pressed pointers: their releases would never arrive.
@@ -276,6 +287,11 @@ export class UILayer {
276
287
  this.signalOrientationChangedInternal.emit(this.orientationInternal, this);
277
288
  }
278
289
  }
290
+ /** Sets the screen pixels per world unit, read by elements on their next render */
291
+ setPixelDensity(value) {
292
+ assertValidPositiveNumber(value, "UILayer.setPixelDensity.value");
293
+ this.pixelDensityInternal = value;
294
+ }
279
295
  renderInternal(renderer, deltaTime) {
280
296
  if (this.destroyedInternal) {
281
297
  return;
@@ -304,7 +320,7 @@ export class UILayer {
304
320
  this.reportPointerCancelledByLayer(x, y, identifier);
305
321
  });
306
322
  }
307
- /** Follows the context of the renderer the layer is drawn with; null to stop following */
323
+ /** Follows the context of the renderer the layer is drawn with, or stops following with null */
308
324
  bindContextMonitor(monitor) {
309
325
  if (monitor === this.contextMonitor) {
310
326
  return;
@@ -323,4 +339,19 @@ export class UILayer {
323
339
  }
324
340
  }
325
341
  }
342
+ /**
343
+ * Reports constraints the solver rejected for conflicting with required constraints. Throws in
344
+ * development builds. Warns in production builds, where the layout goes on without them.
345
+ */
346
+ reportRejectedConstraints(constraints) {
347
+ const names = constraints.map((constraint) => constraint.name === ""
348
+ ? constraint.constructor.name
349
+ : `${constraint.constructor.name} "${constraint.name}"`);
350
+ const message = `UILayer "${this.name}": constraints conflict with required (P0) constraints and are not applied: ${names.join(", ")}`;
351
+ if (process.env.NODE_ENV !== "production") {
352
+ throw new Error(message);
353
+ }
354
+ // eslint-disable-next-line no-console -- The only report of a broken layout in production builds
355
+ console.warn(message);
356
+ }
326
357
  }
@@ -16,6 +16,8 @@ export declare class UIViewportLayer extends UILayer {
16
16
  private resizePolicyInternal;
17
17
  /** Policy version the layer was last sized by; -1 forces a resize */
18
18
  private appliedPolicyVersion;
19
+ /** World units per viewport pixel the layer was last sized by */
20
+ private appliedScale;
19
21
  /** Pointers the layer cancelled while pressed: their late release is not reported */
20
22
  private readonly abandonedPointers;
21
23
  private readonly signalPointerPressedInternal;
@@ -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
  /**
@@ -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
  /**