laymur 0.3.25 → 0.3.27

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
@@ -6244,6 +6244,9 @@ function isUITextStyle(obj) {
6244
6244
  }
6245
6245
  const candidate = obj;
6246
6246
  return (typeof candidate.color === "string" &&
6247
+ (candidate.align === "left" ||
6248
+ candidate.align === "center" ||
6249
+ candidate.align === "right") &&
6247
6250
  typeof candidate.fontFamily === "string" &&
6248
6251
  typeof candidate.fontSize === "number" &&
6249
6252
  (candidate.fontStyle === "normal" ||
@@ -6266,9 +6269,11 @@ function isUITextStyle(obj) {
6266
6269
  }
6267
6270
  const DEFAULT_TEXT_STYLE = {
6268
6271
  color: "#000000",
6272
+ align: "left",
6269
6273
  fontFamily: "Arial",
6270
6274
  fontSize: 16,
6271
6275
  fontStyle: "normal",
6276
+ fontWeight: "normal",
6272
6277
  lineHeight: 1.2,
6273
6278
  enableShadow: false,
6274
6279
  shadowOffsetX: 0,
@@ -6308,6 +6313,7 @@ function resolveTextStyle(style, commonStyle) {
6308
6313
  assertValidNonNegativeNumber(strokeWidth, "Stroke width");
6309
6314
  return {
6310
6315
  color: style?.color ?? commonStyle?.color ?? DEFAULT_TEXT_STYLE.color,
6316
+ align: style?.align ?? commonStyle?.align ?? DEFAULT_TEXT_STYLE.align,
6311
6317
  fontFamily: style?.fontFamily ??
6312
6318
  commonStyle?.fontFamily ??
6313
6319
  DEFAULT_TEXT_STYLE.fontFamily,
@@ -6446,11 +6452,21 @@ function renderText(x, y, text, style, context) {
6446
6452
  context.fillStyle = style.color;
6447
6453
  context.fillText(text, x, y);
6448
6454
  }
6449
- function renderTextLines(paddingTop, paddingLeft, lines, context) {
6455
+ function renderTextLines(paddingTop, paddingLeft, lines, context, maxWidth) {
6450
6456
  let currentY = paddingTop;
6451
6457
  for (let i = 0; i < lines.length; i++) {
6452
6458
  const line = lines[i];
6453
- let currentX = paddingLeft;
6459
+ const firstAlign = line.chunks[0]?.style.align ?? DEFAULT_TEXT_STYLE.align;
6460
+ const isUniformAlign = line.chunks.every((c) => c.style.align === firstAlign);
6461
+ const lineAlign = isUniformAlign ? firstAlign : DEFAULT_TEXT_STYLE.align;
6462
+ let offsetX = 0;
6463
+ if (lineAlign === "center") {
6464
+ offsetX = (maxWidth - line.width) / 2;
6465
+ }
6466
+ else if (lineAlign === "right") {
6467
+ offsetX = maxWidth - line.width;
6468
+ }
6469
+ let currentX = paddingLeft + offsetX;
6454
6470
  currentY += i === 0 ? line.height : line.lineHeight;
6455
6471
  for (const chunk of line.chunks) {
6456
6472
  renderText(currentX, currentY, chunk.text, chunk.style, context);
@@ -6664,7 +6680,7 @@ class UIText extends UIElement {
6664
6680
  this.width = this._private_canvas.width;
6665
6681
  this.height = this._private_canvas.height;
6666
6682
  this._private_targetAspectRatio = this._private_canvas.width / this._private_canvas.height;
6667
- renderTextLines(this._private_paddingInternal.top, this._private_paddingInternal.left, lines, this._private_context);
6683
+ renderTextLines(this._private_paddingInternal.top, this._private_paddingInternal.left, lines, this._private_context, this.maxWidth);
6668
6684
  this._private_texture.dispose();
6669
6685
  this._private_texture = new CanvasTexture(this._private_canvas);
6670
6686
  this._private_texture.needsUpdate = true;
@@ -7359,5 +7375,5 @@ function isUITextSpan(obj) {
7359
7375
  (!("style" in obj) || isUITextStyle(obj.style)));
7360
7376
  }
7361
7377
 
7362
- export { UIAnchor, UIAnimatedImage, UIAnimatedImageEvent, UIAspectConstraint, UIColor, UIColorEvent, UIConstraint, UIConstraint2DBuilder, UICoverConstraintBuilder, UICustomConstraint, UIDummy, UIElement, UIExpression, UIFitConstraintBuilder, UIFullscreenLayer, UIGenericInstancedPlane, UIGraphics, UIHeightConstraint, UIHorizontalDistanceConstraint, UIHorizontalProportionConstraint, UIImage, UIInputEvent, UILayer, UILayerEvent, UIMicro, UIMicroAnchorMode, UIMicroEvent, UIMode, UINineSlice, UIOrientation, UIPriority, UIProgress, UIProgressMaskFunction, UIRelation, UIResizePolicy, UIResizePolicyCross, UIResizePolicyCrossInverted, UIResizePolicyEvent, UIResizePolicyFixedHeight, UIResizePolicyFixedWidth, UIResizePolicyNone, UIScene, UISceneUpdateMode, UISingleParameterConstraint, UIText, UITransparencyMode, UIVerticalDistanceConstraint, UIVerticalProportionConstraint, UIWidthConstraint, convertPriority, convertRelation, isUITextSpan, isUITextStyle, resolveOrientation, resolvePriority, resolveRelation, resolveTextPadding, resolveTextStyle };
7378
+ export { DEFAULT_TEXT_STYLE, UIAnchor, UIAnimatedImage, UIAnimatedImageEvent, UIAspectConstraint, UIColor, UIColorEvent, UIConstraint, UIConstraint2DBuilder, UICoverConstraintBuilder, UICustomConstraint, UIDummy, UIElement, UIExpression, UIFitConstraintBuilder, UIFullscreenLayer, UIGenericInstancedPlane, UIGraphics, UIHeightConstraint, UIHorizontalDistanceConstraint, UIHorizontalProportionConstraint, UIImage, UIInputEvent, UILayer, UILayerEvent, UIMicro, UIMicroAnchorMode, UIMicroEvent, UIMode, UINineSlice, UIOrientation, UIPriority, UIProgress, UIProgressMaskFunction, UIRelation, UIResizePolicy, UIResizePolicyCross, UIResizePolicyCrossInverted, UIResizePolicyEvent, UIResizePolicyFixedHeight, UIResizePolicyFixedWidth, UIResizePolicyNone, UIScene, UISceneUpdateMode, UISingleParameterConstraint, UIText, UITransparencyMode, UIVerticalDistanceConstraint, UIVerticalProportionConstraint, UIWidthConstraint, convertPriority, convertRelation, isUITextSpan, isUITextStyle, resolveOrientation, resolvePriority, resolveRelation, resolveTextPadding, resolveTextStyle };
7363
7379
  //# sourceMappingURL=index.js.map