modern-canvas 0.4.49 → 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() {
@@ -9282,9 +9282,8 @@ class BaseElement2DShape extends CoreObject {
9282
9282
  if (this.svg) {
9283
9283
  const dom = modernPath2d.svgToDOM(this.svg);
9284
9284
  this._path2DSet = modernPath2d.svgToPath2DSet(dom);
9285
- viewBox = this._path2DSet.viewBox ?? this.viewBox;
9285
+ viewBox = this._path2DSet.viewBox;
9286
9286
  } else {
9287
- viewBox = this.viewBox;
9288
9287
  this.paths?.forEach((path, i) => {
9289
9288
  const { data, ...style } = path;
9290
9289
  const path2D = new modernPath2d.Path2D();
@@ -9293,6 +9292,10 @@ class BaseElement2DShape extends CoreObject {
9293
9292
  this._path2DSet.paths[i] = path2D;
9294
9293
  });
9295
9294
  }
9295
+ if (!viewBox) {
9296
+ const bbox = this._path2DSet.getBoundingBox();
9297
+ viewBox = bbox ? [bbox.x, bbox.y, bbox.width, bbox.height] : [0, 0, 1, 1];
9298
+ }
9296
9299
  const [x, y, w, h] = viewBox;
9297
9300
  this._path2DSet.paths.forEach((path) => {
9298
9301
  path.applyTransform(new modernPath2d.Matrix3().translate(-x, -y).scale(1 / w, 1 / h));
@@ -9329,7 +9332,7 @@ __decorateClass$p([
9329
9332
  property()
9330
9333
  ], BaseElement2DShape.prototype, "svg");
9331
9334
  __decorateClass$p([
9332
- property({ default: () => [0, 0, 1, 1] })
9335
+ property()
9333
9336
  ], BaseElement2DShape.prototype, "viewBox");
9334
9337
  __decorateClass$p([
9335
9338
  property({ default: () => [] })
@@ -9408,13 +9411,6 @@ class BaseElement2DText extends CoreObject {
9408
9411
  }
9409
9412
  updateMeasure() {
9410
9413
  this.measureResult = this.measure();
9411
- const textWidth = this.measureResult.boundingBox.width;
9412
- const textHeight = this.measureResult.boundingBox.height;
9413
- const { left, top, width, height = textHeight } = this.parent.style;
9414
- this.parent.position.x = left + Math.min(0, ((width || textWidth) - textWidth) / 2);
9415
- this.parent.position.y = top + Math.min(0, ((height || textHeight) - textHeight) / 2);
9416
- this.parent.size.width = textWidth;
9417
- this.parent.size.height = textHeight;
9418
9414
  return this;
9419
9415
  }
9420
9416
  canDraw() {
@@ -9429,9 +9425,10 @@ class BaseElement2DText extends CoreObject {
9429
9425
  view: this.texture.source
9430
9426
  });
9431
9427
  this.texture.requestUpload();
9432
- 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;
9433
9430
  ctx.fillStyle = this.texture;
9434
- ctx.textureTransform = new Transform2D().scale(1 / width, 1 / height);
9431
+ ctx.textureTransform = new Transform2D().scale(1 / textWidth, 1 / textHeight);
9435
9432
  ctx.fill();
9436
9433
  }
9437
9434
  }
@@ -10782,15 +10779,10 @@ exports.Text2D = class Text2D extends TextureRect2D {
10782
10779
  }
10783
10780
  _drawContent() {
10784
10781
  if (!this.split) {
10785
- const onText2DRender = this.children?.find((child) => "onText2DRender" in child)?.onText2DRender;
10786
- if (onText2DRender) {
10787
- onText2DRender();
10788
- } else {
10789
- this.base.render({
10790
- pixelRatio: this.texture.pixelRatio,
10791
- view: this.texture.source
10792
- });
10793
- }
10782
+ this.base.render({
10783
+ pixelRatio: this.texture.pixelRatio,
10784
+ view: this.texture.source
10785
+ });
10794
10786
  this.texture.requestUpload();
10795
10787
  super._drawContent();
10796
10788
  }
package/dist/index.d.cts CHANGED
@@ -1958,7 +1958,7 @@ declare class BaseElement2DShape extends CoreObject {
1958
1958
  parent: BaseElement2D;
1959
1959
  preset?: Required<NormalizedShape>['preset'];
1960
1960
  svg?: Required<NormalizedShape>['svg'];
1961
- viewBox: Required<NormalizedShape>['viewBox'];
1961
+ viewBox?: Required<NormalizedShape>['viewBox'];
1962
1962
  paths: Required<NormalizedShape>['paths'];
1963
1963
  protected _path2DSet: Path2DSet;
1964
1964
  constructor(parent: BaseElement2D);
package/dist/index.d.mts CHANGED
@@ -1958,7 +1958,7 @@ declare class BaseElement2DShape extends CoreObject {
1958
1958
  parent: BaseElement2D;
1959
1959
  preset?: Required<NormalizedShape>['preset'];
1960
1960
  svg?: Required<NormalizedShape>['svg'];
1961
- viewBox: Required<NormalizedShape>['viewBox'];
1961
+ viewBox?: Required<NormalizedShape>['viewBox'];
1962
1962
  paths: Required<NormalizedShape>['paths'];
1963
1963
  protected _path2DSet: Path2DSet;
1964
1964
  constructor(parent: BaseElement2D);
package/dist/index.d.ts CHANGED
@@ -1958,7 +1958,7 @@ declare class BaseElement2DShape extends CoreObject {
1958
1958
  parent: BaseElement2D;
1959
1959
  preset?: Required<NormalizedShape>['preset'];
1960
1960
  svg?: Required<NormalizedShape>['svg'];
1961
- viewBox: Required<NormalizedShape>['viewBox'];
1961
+ viewBox?: Required<NormalizedShape>['viewBox'];
1962
1962
  paths: Required<NormalizedShape>['paths'];
1963
1963
  protected _path2DSet: Path2DSet;
1964
1964
  constructor(parent: BaseElement2D);