modern-canvas 0.4.53 → 0.4.54

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
@@ -8904,6 +8904,7 @@ class BaseElement2DFill extends CoreObject {
8904
8904
  case "rotateWithShape":
8905
8905
  case "tile":
8906
8906
  case "opacity":
8907
+ case "enabled":
8907
8908
  this.parent.requestRedraw();
8908
8909
  break;
8909
8910
  case "image":
@@ -8932,7 +8933,7 @@ class BaseElement2DFill extends CoreObject {
8932
8933
  }
8933
8934
  canDraw() {
8934
8935
  return Boolean(
8935
- this._texture || this.color
8936
+ this.enabled && (this._texture || this.color)
8936
8937
  );
8937
8938
  }
8938
8939
  _getDrawOptions() {
@@ -8983,6 +8984,9 @@ class BaseElement2DFill extends CoreObject {
8983
8984
  });
8984
8985
  }
8985
8986
  }
8987
+ __decorateClass$u([
8988
+ property({ default: true })
8989
+ ], BaseElement2DFill.prototype, "enabled");
8986
8990
  __decorateClass$u([
8987
8991
  property()
8988
8992
  ], BaseElement2DFill.prototype, "color");
@@ -9074,13 +9078,14 @@ class BaseElement2DOutline extends BaseElement2DFill {
9074
9078
  switch (key) {
9075
9079
  case "width":
9076
9080
  case "style":
9081
+ case "enabled":
9077
9082
  this.parent.requestRedraw();
9078
9083
  break;
9079
9084
  }
9080
9085
  }
9081
9086
  canDraw() {
9082
9087
  return Boolean(
9083
- this.width || this.color || super.canDraw()
9088
+ this.enabled && (this.width || this.color || super.canDraw())
9084
9089
  );
9085
9090
  }
9086
9091
  draw() {
@@ -9092,6 +9097,9 @@ class BaseElement2DOutline extends BaseElement2DFill {
9092
9097
  ctx.stroke({ disableWrapMode });
9093
9098
  }
9094
9099
  }
9100
+ __decorateClass$r([
9101
+ property({ default: true })
9102
+ ], BaseElement2DOutline.prototype, "enabled");
9095
9103
  __decorateClass$r([
9096
9104
  property({ default: 0 })
9097
9105
  ], BaseElement2DOutline.prototype, "color");
@@ -9148,6 +9156,9 @@ class BaseElement2DShadow extends CoreObject {
9148
9156
  }
9149
9157
  }
9150
9158
  }
9159
+ __decorateClass$q([
9160
+ property({ default: true })
9161
+ ], BaseElement2DShadow.prototype, "enabled");
9151
9162
  __decorateClass$q([
9152
9163
  property({ default: "#000000" })
9153
9164
  ], BaseElement2DShadow.prototype, "color");
@@ -9188,6 +9199,7 @@ class BaseElement2DShape extends CoreObject {
9188
9199
  case "svg":
9189
9200
  case "paths":
9190
9201
  case "viewBox":
9202
+ case "enabled":
9191
9203
  this._updatePath2DSet();
9192
9204
  this.parent.requestRedraw();
9193
9205
  break;
@@ -9218,7 +9230,7 @@ class BaseElement2DShape extends CoreObject {
9218
9230
  });
9219
9231
  }
9220
9232
  draw() {
9221
- if (this._path2DSet.paths.length) {
9233
+ if (this.enabled && this._path2DSet.paths.length) {
9222
9234
  const ctx = this.parent.context;
9223
9235
  const { width, height } = this.parent.size;
9224
9236
  this._path2DSet.paths.forEach((path) => {
@@ -9241,6 +9253,9 @@ class BaseElement2DShape extends CoreObject {
9241
9253
  }
9242
9254
  }
9243
9255
  }
9256
+ __decorateClass$p([
9257
+ property({ default: true })
9258
+ ], BaseElement2DShape.prototype, "enabled");
9244
9259
  __decorateClass$p([
9245
9260
  property()
9246
9261
  ], BaseElement2DShape.prototype, "preset");
@@ -9301,6 +9316,7 @@ class BaseElement2DText extends CoreObject {
9301
9316
  case "measureDOM":
9302
9317
  case "fonts":
9303
9318
  case "split":
9319
+ case "enabled":
9304
9320
  this.parent.requestRedraw();
9305
9321
  break;
9306
9322
  }
@@ -9324,7 +9340,7 @@ class BaseElement2DText extends CoreObject {
9324
9340
  }
9325
9341
  canDraw() {
9326
9342
  return Boolean(
9327
- !/^\s*$/.test(this.base.toString()) && this.texture?.valid
9343
+ this.enabled && !/^\s*$/.test(this.base.toString()) && this.texture?.valid
9328
9344
  );
9329
9345
  }
9330
9346
  draw() {
@@ -9349,6 +9365,9 @@ class BaseElement2DText extends CoreObject {
9349
9365
  ctx.fill();
9350
9366
  }
9351
9367
  }
9368
+ __decorateClass$o([
9369
+ property({ default: true })
9370
+ ], BaseElement2DText.prototype, "enabled");
9352
9371
  __decorateClass$o([
9353
9372
  property({ alias: "base.content" })
9354
9373
  ], BaseElement2DText.prototype, "content");
@@ -13516,9 +13535,26 @@ class Assets {
13516
13535
  return fetch(url);
13517
13536
  }
13518
13537
  _fixSVG(dataURI) {
13519
- const svg = new DOMParser().parseFromString(decodeURIComponent(dataURI.split(",")[1]), "image/svg+xml").documentElement;
13520
- svg.setAttribute("width", "512");
13521
- svg.setAttribute("height", "512");
13538
+ let xml;
13539
+ if (dataURI.includes(";base64,")) {
13540
+ xml = atob(dataURI.split(",")[1]);
13541
+ } else {
13542
+ xml = decodeURIComponent(dataURI.split(",")[1]);
13543
+ }
13544
+ const svg = new DOMParser().parseFromString(xml, "image/svg+xml").documentElement;
13545
+ const width = svg.getAttribute("width");
13546
+ const height = svg.getAttribute("height");
13547
+ const isValidWidth = width && /^[\d.]+$/.test(width);
13548
+ const isValidHeight = height && /^[\d.]+$/.test(height);
13549
+ if (!isValidWidth || !isValidHeight) {
13550
+ const viewBox = svg.getAttribute("viewBox")?.split(" ").map((v) => Number(v));
13551
+ if (!isValidWidth) {
13552
+ svg.setAttribute("width", String(viewBox ? viewBox[2] - viewBox[0] : 512));
13553
+ }
13554
+ if (!isValidHeight) {
13555
+ svg.setAttribute("height", String(viewBox ? viewBox[3] - viewBox[1] : 512));
13556
+ }
13557
+ }
13522
13558
  return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg.outerHTML)}`;
13523
13559
  }
13524
13560
  async fetchImageBitmap(url, options) {
@@ -13535,7 +13571,7 @@ class Assets {
13535
13571
  return createImageBitmap(blob, options);
13536
13572
  });
13537
13573
  } else {
13538
- if (url.startsWith("data:image/svg+xml;charset=utf-8,")) {
13574
+ if (url.startsWith("data:image/svg+xml;")) {
13539
13575
  url = this._fixSVG(url);
13540
13576
  }
13541
13577
  return new Promise((resolve) => {
@@ -14010,6 +14046,7 @@ async function task(options) {
14010
14046
  engine.resize(width, height, true);
14011
14047
  (Array.isArray(data) ? data : [data]).forEach((v) => {
14012
14048
  if (v instanceof Node) {
14049
+ v.parent = void 0;
14013
14050
  engine.root.appendChild(v);
14014
14051
  } else {
14015
14052
  engine.root.appendChild(Node.parse(v));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-canvas",
3
3
  "type": "module",
4
- "version": "0.4.53",
4
+ "version": "0.4.54",
5
5
  "packageManager": "pnpm@9.15.1",
6
6
  "description": "A JavaScript WebGL rendering engine.",
7
7
  "author": "wxm",