modern-canvas 0.4.50 → 0.4.51

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.cjs CHANGED
@@ -9164,7 +9164,7 @@ class BaseElement2DOutline extends BaseElement2DFill {
9164
9164
  }
9165
9165
  canDraw() {
9166
9166
  return Boolean(
9167
- this.width || super.canDraw()
9167
+ this.width || this.color || super.canDraw()
9168
9168
  );
9169
9169
  }
9170
9170
  draw() {
@@ -9411,13 +9411,6 @@ class BaseElement2DText extends CoreObject {
9411
9411
  }
9412
9412
  updateMeasure() {
9413
9413
  this.measureResult = this.measure();
9414
- const textWidth = this.measureResult.boundingBox.width;
9415
- const textHeight = this.measureResult.boundingBox.height;
9416
- const { left, top, width, height = textHeight } = this.parent.style;
9417
- this.parent.position.x = left + Math.min(0, ((width || textWidth) - textWidth) / 2);
9418
- this.parent.position.y = top + Math.min(0, ((height || textHeight) - textHeight) / 2);
9419
- this.parent.size.width = textWidth;
9420
- this.parent.size.height = textHeight;
9421
9414
  return this;
9422
9415
  }
9423
9416
  canDraw() {
@@ -9432,9 +9425,10 @@ class BaseElement2DText extends CoreObject {
9432
9425
  view: this.texture.source
9433
9426
  });
9434
9427
  this.texture.requestUpload();
9435
- const { width, height } = this.parent.size;
9428
+ const textWidth = this.measureResult?.boundingBox.width ?? this.parent.size.width;
9429
+ const textHeight = this.measureResult?.boundingBox.height ?? this.parent.size.height;
9436
9430
  ctx.fillStyle = this.texture;
9437
- ctx.textureTransform = new Transform2D().scale(1 / width, 1 / height);
9431
+ ctx.textureTransform = new Transform2D().scale(1 / textWidth, 1 / textHeight);
9438
9432
  ctx.fill();
9439
9433
  }
9440
9434
  }
@@ -10785,15 +10779,10 @@ exports.Text2D = class Text2D extends TextureRect2D {
10785
10779
  }
10786
10780
  _drawContent() {
10787
10781
  if (!this.split) {
10788
- const onText2DRender = this.children?.find((child) => "onText2DRender" in child)?.onText2DRender;
10789
- if (onText2DRender) {
10790
- onText2DRender();
10791
- } else {
10792
- this.base.render({
10793
- pixelRatio: this.texture.pixelRatio,
10794
- view: this.texture.source
10795
- });
10796
- }
10782
+ this.base.render({
10783
+ pixelRatio: this.texture.pixelRatio,
10784
+ view: this.texture.source
10785
+ });
10797
10786
  this.texture.requestUpload();
10798
10787
  super._drawContent();
10799
10788
  }