laymur 0.3.27 → 0.3.28

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/dist/index.js CHANGED
@@ -6452,8 +6452,12 @@ function renderText(x, y, text, style, context) {
6452
6452
  context.fillStyle = style.color;
6453
6453
  context.fillText(text, x, y);
6454
6454
  }
6455
- function renderTextLines(paddingTop, paddingLeft, lines, context, maxWidth) {
6455
+ function renderTextLines(paddingTop, paddingLeft, lines, context) {
6456
6456
  let currentY = paddingTop;
6457
+ let textWidth = 0;
6458
+ for (const line of lines) {
6459
+ textWidth = Math.max(line.width, textWidth);
6460
+ }
6457
6461
  for (let i = 0; i < lines.length; i++) {
6458
6462
  const line = lines[i];
6459
6463
  const firstAlign = line.chunks[0]?.style.align ?? DEFAULT_TEXT_STYLE.align;
@@ -6461,10 +6465,10 @@ function renderTextLines(paddingTop, paddingLeft, lines, context, maxWidth) {
6461
6465
  const lineAlign = isUniformAlign ? firstAlign : DEFAULT_TEXT_STYLE.align;
6462
6466
  let offsetX = 0;
6463
6467
  if (lineAlign === "center") {
6464
- offsetX = (maxWidth - line.width) / 2;
6468
+ offsetX = (textWidth - line.width) / 2;
6465
6469
  }
6466
6470
  else if (lineAlign === "right") {
6467
- offsetX = maxWidth - line.width;
6471
+ offsetX = textWidth - line.width;
6468
6472
  }
6469
6473
  let currentX = paddingLeft + offsetX;
6470
6474
  currentY += i === 0 ? line.height : line.lineHeight;
@@ -6680,7 +6684,7 @@ class UIText extends UIElement {
6680
6684
  this.width = this._private_canvas.width;
6681
6685
  this.height = this._private_canvas.height;
6682
6686
  this._private_targetAspectRatio = this._private_canvas.width / this._private_canvas.height;
6683
- renderTextLines(this._private_paddingInternal.top, this._private_paddingInternal.left, lines, this._private_context, this.maxWidth);
6687
+ renderTextLines(this._private_paddingInternal.top, this._private_paddingInternal.left, lines, this._private_context);
6684
6688
  this._private_texture.dispose();
6685
6689
  this._private_texture = new CanvasTexture(this._private_canvas);
6686
6690
  this._private_texture.needsUpdate = true;