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.mjs CHANGED
@@ -9158,7 +9158,7 @@ class BaseElement2DOutline extends BaseElement2DFill {
9158
9158
  }
9159
9159
  canDraw() {
9160
9160
  return Boolean(
9161
- this.width || super.canDraw()
9161
+ this.width || this.color || super.canDraw()
9162
9162
  );
9163
9163
  }
9164
9164
  draw() {
@@ -9276,9 +9276,8 @@ class BaseElement2DShape extends CoreObject {
9276
9276
  if (this.svg) {
9277
9277
  const dom = svgToDOM(this.svg);
9278
9278
  this._path2DSet = svgToPath2DSet(dom);
9279
- viewBox = this._path2DSet.viewBox ?? this.viewBox;
9279
+ viewBox = this._path2DSet.viewBox;
9280
9280
  } else {
9281
- viewBox = this.viewBox;
9282
9281
  this.paths?.forEach((path, i) => {
9283
9282
  const { data, ...style } = path;
9284
9283
  const path2D = new Path2D();
@@ -9287,6 +9286,10 @@ class BaseElement2DShape extends CoreObject {
9287
9286
  this._path2DSet.paths[i] = path2D;
9288
9287
  });
9289
9288
  }
9289
+ if (!viewBox) {
9290
+ const bbox = this._path2DSet.getBoundingBox();
9291
+ viewBox = bbox ? [bbox.x, bbox.y, bbox.width, bbox.height] : [0, 0, 1, 1];
9292
+ }
9290
9293
  const [x, y, w, h] = viewBox;
9291
9294
  this._path2DSet.paths.forEach((path) => {
9292
9295
  path.applyTransform(new Matrix3$1().translate(-x, -y).scale(1 / w, 1 / h));
@@ -9323,7 +9326,7 @@ __decorateClass$p([
9323
9326
  property()
9324
9327
  ], BaseElement2DShape.prototype, "svg");
9325
9328
  __decorateClass$p([
9326
- property({ default: () => [0, 0, 1, 1] })
9329
+ property()
9327
9330
  ], BaseElement2DShape.prototype, "viewBox");
9328
9331
  __decorateClass$p([
9329
9332
  property({ default: () => [] })
@@ -9402,13 +9405,6 @@ class BaseElement2DText extends CoreObject {
9402
9405
  }
9403
9406
  updateMeasure() {
9404
9407
  this.measureResult = this.measure();
9405
- const textWidth = this.measureResult.boundingBox.width;
9406
- const textHeight = this.measureResult.boundingBox.height;
9407
- const { left, top, width, height = textHeight } = this.parent.style;
9408
- this.parent.position.x = left + Math.min(0, ((width || textWidth) - textWidth) / 2);
9409
- this.parent.position.y = top + Math.min(0, ((height || textHeight) - textHeight) / 2);
9410
- this.parent.size.width = textWidth;
9411
- this.parent.size.height = textHeight;
9412
9408
  return this;
9413
9409
  }
9414
9410
  canDraw() {
@@ -9423,9 +9419,10 @@ class BaseElement2DText extends CoreObject {
9423
9419
  view: this.texture.source
9424
9420
  });
9425
9421
  this.texture.requestUpload();
9426
- const { width, height } = this.parent.size;
9422
+ const textWidth = this.measureResult?.boundingBox.width ?? this.parent.size.width;
9423
+ const textHeight = this.measureResult?.boundingBox.height ?? this.parent.size.height;
9427
9424
  ctx.fillStyle = this.texture;
9428
- ctx.textureTransform = new Transform2D().scale(1 / width, 1 / height);
9425
+ ctx.textureTransform = new Transform2D().scale(1 / textWidth, 1 / textHeight);
9429
9426
  ctx.fill();
9430
9427
  }
9431
9428
  }
@@ -10776,15 +10773,10 @@ let Text2D = class extends TextureRect2D {
10776
10773
  }
10777
10774
  _drawContent() {
10778
10775
  if (!this.split) {
10779
- const onText2DRender = this.children?.find((child) => "onText2DRender" in child)?.onText2DRender;
10780
- if (onText2DRender) {
10781
- onText2DRender();
10782
- } else {
10783
- this.base.render({
10784
- pixelRatio: this.texture.pixelRatio,
10785
- view: this.texture.source
10786
- });
10787
- }
10776
+ this.base.render({
10777
+ pixelRatio: this.texture.pixelRatio,
10778
+ view: this.texture.source
10779
+ });
10788
10780
  this.texture.requestUpload();
10789
10781
  super._drawContent();
10790
10782
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-canvas",
3
3
  "type": "module",
4
- "version": "0.4.49",
4
+ "version": "0.4.51",
5
5
  "packageManager": "pnpm@9.15.1",
6
6
  "description": "A JavaScript WebGL rendering engine.",
7
7
  "author": "wxm",
@@ -71,17 +71,17 @@
71
71
  "earcut": "^3.0.1",
72
72
  "modern-font": "^0.4.1",
73
73
  "modern-idoc": "^0.6.9",
74
- "modern-path2d": "^1.3.2",
74
+ "modern-path2d": "^1.3.3",
75
75
  "modern-text": "^1.4.2",
76
76
  "yoga-layout": "^3.2.1"
77
77
  },
78
78
  "devDependencies": {
79
79
  "@antfu/eslint-config": "^4.13.2",
80
80
  "@types/earcut": "^3.0.0",
81
- "@types/node": "^22.15.23",
81
+ "@types/node": "^22.15.29",
82
82
  "bumpp": "^10.1.1",
83
83
  "conventional-changelog-cli": "^5.0.0",
84
- "eslint": "^9.27.0",
84
+ "eslint": "^9.28.0",
85
85
  "lint-staged": "^16.1.0",
86
86
  "lottie-web": "^5.13.0",
87
87
  "modern-gif": "^2.0.4",
@@ -89,7 +89,7 @@
89
89
  "typescript": "^5.8.3",
90
90
  "unbuild": "^3.5.0",
91
91
  "vite": "^6.3.5",
92
- "vitest": "^3.1.4"
92
+ "vitest": "^3.2.0"
93
93
  },
94
94
  "simple-git-hooks": {
95
95
  "pre-commit": "pnpm lint-staged"