modern-canvas 0.6.1 → 0.6.3

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
  }
@@ -5654,6 +5651,7 @@ function getNodeIid(key) {
5654
5651
  return iid;
5655
5652
  }
5656
5653
  let Node = class extends CoreObject {
5654
+ meta = {};
5657
5655
  _readyed = false;
5658
5656
  constructor(properties, nodes = []) {
5659
5657
  super();
@@ -6003,7 +6001,9 @@ let Node = class extends CoreObject {
6003
6001
  this._children.back.push(node);
6004
6002
  break;
6005
6003
  }
6006
- node.internalMode = internalMode;
6004
+ if (node.internalMode !== internalMode) {
6005
+ node.internalMode = internalMode;
6006
+ }
6007
6007
  node.setParent(this);
6008
6008
  this.emit("appendChild", node);
6009
6009
  return node;
@@ -6031,7 +6031,9 @@ let Node = class extends CoreObject {
6031
6031
  this.emit("appendChild", node);
6032
6032
  }
6033
6033
  }
6034
- node.internalMode = internalMode;
6034
+ if (node.internalMode !== internalMode) {
6035
+ node.internalMode = internalMode;
6036
+ }
6035
6037
  return this;
6036
6038
  }
6037
6039
  removeChild(child) {
@@ -6094,16 +6096,17 @@ let Node = class extends CoreObject {
6094
6096
  }
6095
6097
  clone() {
6096
6098
  return new this.constructor(
6097
- this.toPropsJSON(),
6099
+ this.toJSON(),
6098
6100
  this._children.internal
6099
6101
  );
6100
6102
  }
6101
6103
  toJSON() {
6102
- return {
6104
+ return clearUndef({
6103
6105
  ...super.toJSON(),
6104
6106
  is: this.is,
6105
- children: [...this._children.map((child) => child.toJSON())]
6106
- };
6107
+ children: this._children.length ? [...this._children.map((child) => child.toJSON())] : void 0,
6108
+ meta: Object.keys(this.meta).length ? { ...this.meta } : void 0
6109
+ });
6107
6110
  }
6108
6111
  static parse(value) {
6109
6112
  if (Array.isArray(value)) {
@@ -6134,9 +6137,6 @@ __decorateClass$Q([
6134
6137
  __decorateClass$Q([
6135
6138
  property({ fallback: "default" })
6136
6139
  ], Node.prototype, "internalMode", 2);
6137
- __decorateClass$Q([
6138
- property({ default: () => ({}) })
6139
- ], Node.prototype, "meta", 2);
6140
6140
  __decorateClass$Q([
6141
6141
  property({ protected: true })
6142
6142
  ], Node.prototype, "mask", 2);
@@ -9308,7 +9308,7 @@ __decorateClass$o([
9308
9308
  property()
9309
9309
  ], BaseElement2DShape.prototype, "viewBox");
9310
9310
  __decorateClass$o([
9311
- property({ default: () => [] })
9311
+ property()
9312
9312
  ], BaseElement2DShape.prototype, "paths");
9313
9313
 
9314
9314
  class BaseElement2DStyle extends Resource {
@@ -9856,19 +9856,20 @@ let BaseElement2D = class extends Node2D {
9856
9856
  }
9857
9857
  }
9858
9858
  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()
9859
+ const notEmptyObjectOrUndef = (obj) => {
9860
+ return Object.keys(obj).length > 0 ? obj : void 0;
9871
9861
  };
9862
+ return clearUndef({
9863
+ ...super.toJSON(),
9864
+ style: notEmptyObjectOrUndef(this.style.toJSON()),
9865
+ background: notEmptyObjectOrUndef(this.background.toJSON()),
9866
+ shape: notEmptyObjectOrUndef(this.shape.toJSON()),
9867
+ fill: notEmptyObjectOrUndef(this.fill.toJSON()),
9868
+ outline: notEmptyObjectOrUndef(this.outline.toJSON()),
9869
+ text: notEmptyObjectOrUndef(this.text.toJSON()),
9870
+ foreground: notEmptyObjectOrUndef(this.foreground.toJSON()),
9871
+ shadow: notEmptyObjectOrUndef(this.shadow.toJSON())
9872
+ });
9872
9873
  }
9873
9874
  };
9874
9875
  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.3",
5
5
  "packageManager": "pnpm@9.15.1",
6
6
  "description": "A JavaScript WebGL rendering engine.",
7
7
  "author": "wxm",