modern-canvas 0.6.1 → 0.6.2

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
@@ -1,4 +1,4 @@
1
- import { defineProperty, getDeclarations, parseColor, property, RawWeakMap as RawWeakMap$1, isGradient, idGenerator, normalizeFill, isNone, normalizeBackground, normalizeForeground, normalizeOutline, normalizeShadow, normalizeShape, getDefaultStyle, normalizeText } from 'modern-idoc';
1
+ import { defineProperty, getDeclarations, parseColor, property, RawWeakMap as RawWeakMap$1, isGradient, clearUndef, idGenerator, normalizeFill, isNone, normalizeBackground, normalizeForeground, normalizeOutline, normalizeShadow, normalizeShape, getDefaultStyle, normalizeText } from 'modern-idoc';
2
2
  import { extend } from 'colord';
3
3
  import namesPlugin from 'colord/plugins/names';
4
4
  import { Path2D, Path2DSet, svgToDom, svgToPath2DSet, Matrix3 as Matrix3$1 } from 'modern-path2d';
@@ -334,7 +334,7 @@ class CoreObject extends EventEmitter {
334
334
  this._updatingPromise = this._enqueueUpdate();
335
335
  }
336
336
  }
337
- toPropsJSON() {
337
+ toJSON() {
338
338
  const json = {};
339
339
  this._properties.forEach((value, key) => {
340
340
  if (value === void 0) {
@@ -352,9 +352,6 @@ class CoreObject extends EventEmitter {
352
352
  });
353
353
  return json;
354
354
  }
355
- toJSON() {
356
- return this.toPropsJSON();
357
- }
358
355
  clone() {
359
356
  return new this.constructor(this.toJSON());
360
357
  }
@@ -6003,7 +6000,9 @@ let Node = class extends CoreObject {
6003
6000
  this._children.back.push(node);
6004
6001
  break;
6005
6002
  }
6006
- node.internalMode = internalMode;
6003
+ if (node.internalMode !== internalMode) {
6004
+ node.internalMode = internalMode;
6005
+ }
6007
6006
  node.setParent(this);
6008
6007
  this.emit("appendChild", node);
6009
6008
  return node;
@@ -6031,7 +6030,9 @@ let Node = class extends CoreObject {
6031
6030
  this.emit("appendChild", node);
6032
6031
  }
6033
6032
  }
6034
- node.internalMode = internalMode;
6033
+ if (node.internalMode !== internalMode) {
6034
+ node.internalMode = internalMode;
6035
+ }
6035
6036
  return this;
6036
6037
  }
6037
6038
  removeChild(child) {
@@ -6094,16 +6095,16 @@ let Node = class extends CoreObject {
6094
6095
  }
6095
6096
  clone() {
6096
6097
  return new this.constructor(
6097
- this.toPropsJSON(),
6098
+ this.toJSON(),
6098
6099
  this._children.internal
6099
6100
  );
6100
6101
  }
6101
6102
  toJSON() {
6102
- return {
6103
+ return clearUndef({
6103
6104
  ...super.toJSON(),
6104
6105
  is: this.is,
6105
- children: [...this._children.map((child) => child.toJSON())]
6106
- };
6106
+ children: this._children.length ? [...this._children.map((child) => child.toJSON())] : void 0
6107
+ });
6107
6108
  }
6108
6109
  static parse(value) {
6109
6110
  if (Array.isArray(value)) {
@@ -9308,7 +9309,7 @@ __decorateClass$o([
9308
9309
  property()
9309
9310
  ], BaseElement2DShape.prototype, "viewBox");
9310
9311
  __decorateClass$o([
9311
- property({ default: () => [] })
9312
+ property()
9312
9313
  ], BaseElement2DShape.prototype, "paths");
9313
9314
 
9314
9315
  class BaseElement2DStyle extends Resource {
@@ -9856,19 +9857,20 @@ let BaseElement2D = class extends Node2D {
9856
9857
  }
9857
9858
  }
9858
9859
  toJSON() {
9859
- return {
9860
- is: this.is,
9861
- ...this.toPropsJSON(),
9862
- children: [...this._children.map((child) => child.toJSON())],
9863
- style: this.style.toJSON(),
9864
- background: this.background.toJSON(),
9865
- shape: this.shape.toJSON(),
9866
- fill: this.fill.toJSON(),
9867
- outline: this.outline.toJSON(),
9868
- text: this.text.toJSON(),
9869
- foreground: this.foreground.toJSON(),
9870
- shadow: this.shadow.toJSON()
9860
+ const notEmptyObjectOrUndef = (obj) => {
9861
+ return Object.keys(obj).length > 0 ? obj : void 0;
9871
9862
  };
9863
+ return clearUndef({
9864
+ ...super.toJSON(),
9865
+ style: notEmptyObjectOrUndef(this.style.toJSON()),
9866
+ background: notEmptyObjectOrUndef(this.background.toJSON()),
9867
+ shape: notEmptyObjectOrUndef(this.shape.toJSON()),
9868
+ fill: notEmptyObjectOrUndef(this.fill.toJSON()),
9869
+ outline: notEmptyObjectOrUndef(this.outline.toJSON()),
9870
+ text: notEmptyObjectOrUndef(this.text.toJSON()),
9871
+ foreground: notEmptyObjectOrUndef(this.foreground.toJSON()),
9872
+ shadow: notEmptyObjectOrUndef(this.shadow.toJSON())
9873
+ });
9872
9874
  }
9873
9875
  };
9874
9876
  BaseElement2D = __decorateClass$l([
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-canvas",
3
3
  "type": "module",
4
- "version": "0.6.1",
4
+ "version": "0.6.2",
5
5
  "packageManager": "pnpm@9.15.1",
6
6
  "description": "A JavaScript WebGL rendering engine.",
7
7
  "author": "wxm",