modern-canvas 0.4.31 → 0.4.33

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,6 +1,6 @@
1
- import { colord, extend } from 'colord';
1
+ import { extend } from 'colord';
2
2
  import namesPlugin from 'colord/plugins/names';
3
- import { normalizeFill, normalizeBackground, normalizeForeground, normalizeGeometry, normalizeOutline, normalizeShadow, getDefaultStyle, normalizeText } from 'modern-idoc';
3
+ import { parseColor, normalizeFill, normalizeBackground, normalizeForeground, normalizeGeometry, normalizeOutline, normalizeShadow, getDefaultStyle, normalizeText } from 'modern-idoc';
4
4
  import { Path2D, Path2DSet, svgToDOM, svgToPath2DSet, Matrix3 as Matrix3$1 } from 'modern-path2d';
5
5
  import { Text, textDefaultStyle } from 'modern-text';
6
6
  import { loadYoga, BoxSizing, PositionType, Edge, Overflow, Gutter, Justify, Wrap, FlexDirection, Display, Direction, Align } from 'yoga-layout/load';
@@ -555,7 +555,17 @@ class CoreObject extends EventEmitter {
555
555
  }
556
556
  }
557
557
  toJSON() {
558
- return this.getProperties(Array.from(this._changedProperties));
558
+ const json = {};
559
+ const properties = this.getProperties(Array.from(this._changedProperties));
560
+ for (const key in properties) {
561
+ const value = properties[key];
562
+ if (value && typeof value === "object" && "toJSON" in value && typeof value.toJSON === "function") {
563
+ json[key] = value.toJSON();
564
+ } else {
565
+ json[key] = value;
566
+ }
567
+ }
568
+ return json;
559
569
  }
560
570
  clone() {
561
571
  return new this.constructor(this.toJSON());
@@ -1058,27 +1068,7 @@ class Color {
1058
1068
  return this._value;
1059
1069
  }
1060
1070
  set value(value) {
1061
- if (value === void 0 || this._value === value)
1062
- return;
1063
- this._value = value;
1064
- let input;
1065
- if (typeof value === "number") {
1066
- input = {
1067
- r: value >> 24 & 255,
1068
- g: value >> 16 & 255,
1069
- b: value >> 8 & 255,
1070
- a: (value & 255) / 255
1071
- };
1072
- } else {
1073
- input = value;
1074
- }
1075
- const parsed = colord(input);
1076
- if (parsed.isValid()) {
1077
- this._colord = parsed;
1078
- } else {
1079
- this._colord = colord("#000000");
1080
- console.warn(`Unable to convert color ${value}`);
1081
- }
1071
+ this._colord = parseColor(value ?? "none");
1082
1072
  }
1083
1073
  get r8() {
1084
1074
  return this._colord.rgba.r;
@@ -5996,14 +5986,14 @@ let Node = class extends CoreObject {
5996
5986
  remove() {
5997
5987
  this._parent?.removeChild(this);
5998
5988
  }
5999
- forEach(fn) {
6000
- this.getChildren().forEach(fn);
5989
+ forEachChild(callbackfn) {
5990
+ this.getChildren().forEach(callbackfn);
6001
5991
  return this;
6002
5992
  }
6003
- deepForEach(fn) {
5993
+ forEachDescendant(callbackfn) {
6004
5994
  this.getChildren().forEach((child) => {
6005
- fn(child);
6006
- child.deepForEach(fn);
5995
+ callbackfn(child);
5996
+ child.forEachDescendant(callbackfn);
6007
5997
  });
6008
5998
  return this;
6009
5999
  }
@@ -7306,6 +7296,11 @@ let CanvasItem = class extends TimelineNode {
7306
7296
  requestRelayout() {
7307
7297
  this._relayouting = true;
7308
7298
  this.requestUpdate();
7299
+ this.forEachChild((node) => {
7300
+ if (node instanceof CanvasItem) {
7301
+ node.requestRelayout();
7302
+ }
7303
+ });
7309
7304
  }
7310
7305
  requestRepaint() {
7311
7306
  this._repainting = true;
@@ -9203,12 +9198,6 @@ __decorateClass$q([
9203
9198
  __decorateClass$q([
9204
9199
  property({ default: "solid" })
9205
9200
  ], BaseElement2DOutline.prototype, "style");
9206
- __decorateClass$q([
9207
- property()
9208
- ], BaseElement2DOutline.prototype, "src");
9209
- __decorateClass$q([
9210
- property({ default: 1 })
9211
- ], BaseElement2DOutline.prototype, "opacity");
9212
9201
 
9213
9202
  var __defProp$i = Object.defineProperty;
9214
9203
  var __decorateClass$p = (decorators, target, key, kind) => {
@@ -9797,13 +9786,13 @@ let BaseElement2D = class extends Node2D {
9797
9786
  return {
9798
9787
  ...json,
9799
9788
  props: {
9789
+ ...json.props,
9800
9790
  style: this.style.toJSON(),
9801
9791
  text: this.text.toJSON(),
9802
9792
  geometry: this.geometry.toJSON(),
9803
9793
  fill: this.fill.toJSON(),
9804
9794
  outline: this.outline.toJSON(),
9805
- shadow: this.shadow.toJSON(),
9806
- ...json.props
9795
+ shadow: this.shadow.toJSON()
9807
9796
  }
9808
9797
  };
9809
9798
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-canvas",
3
3
  "type": "module",
4
- "version": "0.4.31",
4
+ "version": "0.4.33",
5
5
  "packageManager": "pnpm@9.15.1",
6
6
  "description": "A JavaScript WebGL rendering engine.",
7
7
  "author": "wxm",
@@ -70,26 +70,26 @@
70
70
  "colord": "^2.9.3",
71
71
  "earcut": "^3.0.1",
72
72
  "modern-font": "^0.4.1",
73
- "modern-idoc": "^0.4.0",
74
- "modern-path2d": "^1.2.18",
75
- "modern-text": "^1.3.5",
73
+ "modern-idoc": "^0.5.3",
74
+ "modern-path2d": "^1.2.19",
75
+ "modern-text": "^1.3.10",
76
76
  "yoga-layout": "^3.2.1"
77
77
  },
78
78
  "devDependencies": {
79
- "@antfu/eslint-config": "^4.12.0",
79
+ "@antfu/eslint-config": "^4.13.0",
80
80
  "@types/earcut": "^3.0.0",
81
- "@types/node": "^22.14.0",
81
+ "@types/node": "^22.15.17",
82
82
  "bumpp": "^10.1.0",
83
83
  "conventional-changelog-cli": "^5.0.0",
84
- "eslint": "^9.24.0",
85
- "lint-staged": "^15.5.0",
84
+ "eslint": "^9.26.0",
85
+ "lint-staged": "^15.5.2",
86
86
  "lottie-web": "^5.12.2",
87
87
  "modern-gif": "^2.0.4",
88
- "simple-git-hooks": "^2.12.1",
88
+ "simple-git-hooks": "^2.13.0",
89
89
  "typescript": "^5.8.3",
90
90
  "unbuild": "^3.5.0",
91
- "vite": "^6.2.5",
92
- "vitest": "^3.1.1"
91
+ "vite": "^6.3.5",
92
+ "vitest": "^3.1.3"
93
93
  },
94
94
  "simple-git-hooks": {
95
95
  "pre-commit": "pnpm lint-staged"