modern-canvas 0.4.12 → 0.4.14

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
1
  import { colord, extend } from 'colord';
2
2
  import namesPlugin from 'colord/plugins/names';
3
- import { getDefaultTextStyle, getDefaultTransformStyle } from 'modern-idoc';
3
+ import { getDefaultStyle } from 'modern-idoc';
4
4
  import { Path2D } from 'modern-path2d';
5
5
  import { loadYoga, BoxSizing, PositionType, Edge, Overflow, Gutter, Justify, Wrap, FlexDirection, Display, Direction, Align } from 'yoga-layout/load';
6
6
  import { Text, textDefaultStyle } from 'modern-text';
@@ -8636,38 +8636,20 @@ class BaseElement2DStyle extends Resource {
8636
8636
  return this._backgroundColor;
8637
8637
  }
8638
8638
  async loadBackgroundImage() {
8639
- if (this.backgroundImage !== "none") {
8639
+ if (this.backgroundImage && this.backgroundImage !== "none") {
8640
8640
  return await assets.texture.load(this.backgroundImage);
8641
8641
  }
8642
8642
  }
8643
8643
  }
8644
- const defaultStyles$2 = {
8645
- ...getDefaultTransformStyle(),
8646
- ...getDefaultTextStyle(),
8647
- backgroundColor: "none",
8648
- backgroundImage: "none",
8649
- filter: "none",
8650
- boxShadow: "none",
8651
- maskImage: "none",
8652
- opacity: 1,
8653
- borderWidth: 0,
8654
- borderRadius: 0,
8655
- borderColor: "#000000",
8656
- borderStyle: "none",
8657
- outlineWidth: 0,
8658
- outlineOffset: 0,
8659
- outlineColor: "#000000",
8660
- outlineStyle: "none",
8661
- visibility: "visible",
8662
- overflow: "visible",
8663
- pointerEvents: "auto"
8664
- };
8665
- delete defaultStyles$2.top;
8666
- delete defaultStyles$2.left;
8667
- delete defaultStyles$2.width;
8668
- delete defaultStyles$2.height;
8669
- for (const key in defaultStyles$2) {
8670
- defineProperty(BaseElement2DStyle, key, { default: defaultStyles$2[key] });
8644
+ const defaultStyles$1 = getDefaultStyle();
8645
+ delete defaultStyles$1.top;
8646
+ delete defaultStyles$1.left;
8647
+ delete defaultStyles$1.width;
8648
+ delete defaultStyles$1.height;
8649
+ for (const key in defaultStyles$1) {
8650
+ defineProperty(BaseElement2DStyle, key, {
8651
+ default: defaultStyles$1[key]
8652
+ });
8671
8653
  }
8672
8654
 
8673
8655
  var __getOwnPropDesc$m = Object.getOwnPropertyDescriptor;
@@ -9089,14 +9071,14 @@ class Element2DStyle extends BaseElement2DStyle {
9089
9071
  this.setProperties(properties);
9090
9072
  }
9091
9073
  }
9092
- const defaultStyles$1 = {
9074
+ const defaultStyles = {
9093
9075
  left: 0,
9094
9076
  top: 0,
9095
9077
  width: 0,
9096
9078
  height: 0
9097
9079
  };
9098
- for (const key in defaultStyles$1) {
9099
- defineProperty(Element2DStyle, key, { default: defaultStyles$1[key] });
9080
+ for (const key in defaultStyles) {
9081
+ defineProperty(Element2DStyle, key, { default: defaultStyles[key] });
9100
9082
  }
9101
9083
 
9102
9084
  var __getOwnPropDesc$k = Object.getOwnPropertyDescriptor;
@@ -9129,19 +9111,19 @@ let Element2D = class extends BaseElement2D {
9129
9111
  super._updateStyleProperty(key, value, oldValue, declaration);
9130
9112
  switch (key) {
9131
9113
  case "left":
9132
- this.position.x = this.style.left;
9114
+ this.position.x = Number(value);
9133
9115
  this.requestRelayout();
9134
9116
  break;
9135
9117
  case "top":
9136
- this.position.y = this.style.top;
9118
+ this.position.y = Number(value);
9137
9119
  this.requestRelayout();
9138
9120
  break;
9139
9121
  case "width":
9140
- this.size.width = this.style.width;
9122
+ this.size.width = Number(value);
9141
9123
  this.requestRelayout();
9142
9124
  break;
9143
9125
  case "height":
9144
- this.size.height = this.style.height;
9126
+ this.size.height = Number(value);
9145
9127
  this.requestRelayout();
9146
9128
  break;
9147
9129
  }
@@ -9157,52 +9139,6 @@ class FlexElement2DStyle extends BaseElement2DStyle {
9157
9139
  this.setProperties(properties);
9158
9140
  }
9159
9141
  }
9160
- const defaultStyles = {
9161
- alignContent: "stretch",
9162
- alignItems: "stretch",
9163
- alignSelf: "auto",
9164
- borderTop: "none",
9165
- borderLeft: "none",
9166
- borderRight: "none",
9167
- borderBottom: "none",
9168
- borderWidth: 0,
9169
- border: "none",
9170
- direction: "inherit",
9171
- display: "flex",
9172
- flex: 0,
9173
- flexBasis: "auto",
9174
- flexDirection: "row",
9175
- flexGrow: 0,
9176
- flexShrink: 1,
9177
- flexWrap: "nowrap",
9178
- height: "auto",
9179
- justifyContent: "flex-start",
9180
- gap: 0,
9181
- marginTop: 0,
9182
- marginLeft: 0,
9183
- marginRight: 0,
9184
- marginBottom: 0,
9185
- margin: 0,
9186
- maxHeight: 0,
9187
- maxWidth: 0,
9188
- minHeight: 0,
9189
- minWidth: 0,
9190
- paddingTop: 0,
9191
- paddingLeft: 0,
9192
- paddingRight: 0,
9193
- paddingBottom: 0,
9194
- padding: 0,
9195
- top: 0,
9196
- bottom: 0,
9197
- left: 0,
9198
- right: 0,
9199
- position: "static",
9200
- boxSizing: "content-box",
9201
- width: "auto"
9202
- };
9203
- for (const key in defaultStyles) {
9204
- defineProperty(FlexElement2DStyle, key, { default: defaultStyles[key] });
9205
- }
9206
9142
 
9207
9143
  const alignMap = {
9208
9144
  "auto": Align.Auto,
@@ -9292,13 +9228,19 @@ class FlexLayout {
9292
9228
  updateStyleProperty(key, value, oldValue, declaration) {
9293
9229
  switch (key) {
9294
9230
  case "alignContent":
9295
- this._node.setAlignContent(alignMap[this._style.alignContent]);
9231
+ this._node.setAlignContent(
9232
+ value ? alignMap[value] : alignMap["flex-start"]
9233
+ );
9296
9234
  break;
9297
9235
  case "alignItems":
9298
- this._node.setAlignItems(alignMap[this._style.alignItems]);
9236
+ this._node.setAlignItems(
9237
+ value ? alignMap[value] : alignMap["flex-start"]
9238
+ );
9299
9239
  break;
9300
9240
  case "alignSelf":
9301
- this._node.setAlignSelf(alignMap[this._style.alignSelf]);
9241
+ this._node.setAlignSelf(
9242
+ value ? alignMap[value] : alignMap["flex-start"]
9243
+ );
9302
9244
  break;
9303
9245
  case "aspectRatio":
9304
9246
  this._node.setAspectRatio(value);
@@ -9319,10 +9261,14 @@ class FlexLayout {
9319
9261
  this._node.setBorder(Edge.All, this._style.borderWidth);
9320
9262
  break;
9321
9263
  case "direction":
9322
- this._node.setDirection(directionMap[this._style.direction]);
9264
+ this._node.setDirection(
9265
+ value ? directionMap[value] : directionMap.inherit
9266
+ );
9323
9267
  break;
9324
9268
  case "display":
9325
- this._node.setDisplay(displayMap[this._style.display]);
9269
+ this._node.setDisplay(
9270
+ value ? displayMap[value] : displayMap.flex
9271
+ );
9326
9272
  break;
9327
9273
  case "flex":
9328
9274
  this._node.setFlex(this._style.flex);
@@ -9331,7 +9277,9 @@ class FlexLayout {
9331
9277
  this._node.setFlexBasis(this._style.flexBasis);
9332
9278
  break;
9333
9279
  case "flexDirection":
9334
- this._node.setFlexDirection(flexDirectionMap[this._style.flexDirection]);
9280
+ this._node.setFlexDirection(
9281
+ value ? flexDirectionMap[value] : flexDirectionMap.row
9282
+ );
9335
9283
  break;
9336
9284
  case "flexGrow":
9337
9285
  this._node.setFlexGrow(this._style.flexGrow);
@@ -9340,37 +9288,41 @@ class FlexLayout {
9340
9288
  this._node.setFlexShrink(this._style.flexShrink);
9341
9289
  break;
9342
9290
  case "flexWrap":
9343
- this._node.setFlexWrap(flexWrapMap[this._style.flexWrap]);
9291
+ this._node.setFlexWrap(
9292
+ value ? flexWrapMap[value] : flexWrapMap.wrap
9293
+ );
9344
9294
  break;
9345
9295
  case "height":
9346
9296
  this._node.setHeight(this._style.height);
9347
9297
  break;
9348
9298
  case "justifyContent":
9349
- this._node.setJustifyContent(justifyMap[this._style.justifyContent]);
9299
+ this._node.setJustifyContent(
9300
+ value ? justifyMap[value] : justifyMap["flex-start"]
9301
+ );
9350
9302
  break;
9351
9303
  case "gap":
9352
- this._node.setGap(Gutter.All, this._style.gap);
9304
+ value !== void 0 && this._node.setGap(Gutter.All, value);
9353
9305
  break;
9354
9306
  case "marginTop":
9355
- this._node.setMargin(Edge.Top, this._style.marginTop);
9307
+ this._node.setMargin(Edge.Top, value);
9356
9308
  break;
9357
9309
  case "marginBottom":
9358
- this._node.setMargin(Edge.Top, this._style.marginBottom);
9310
+ this._node.setMargin(Edge.Top, value);
9359
9311
  break;
9360
9312
  case "marginLeft":
9361
- this._node.setMargin(Edge.Left, this._style.marginLeft);
9313
+ this._node.setMargin(Edge.Left, value);
9362
9314
  break;
9363
9315
  case "marginRight":
9364
- this._node.setMargin(Edge.Top, this._style.marginRight);
9316
+ this._node.setMargin(Edge.Top, value);
9365
9317
  break;
9366
9318
  case "margin":
9367
- this._node.setMargin(Edge.All, this._style.margin);
9319
+ this._node.setMargin(Edge.All, value);
9368
9320
  break;
9369
9321
  case "maxHeight":
9370
- this._node.setMaxHeight(this._style.maxHeight);
9322
+ this._node.setMaxHeight(value);
9371
9323
  break;
9372
9324
  case "maxWidth":
9373
- this._node.setMaxWidth(this._style.maxWidth);
9325
+ this._node.setMaxWidth(value);
9374
9326
  break;
9375
9327
  // setDirtiedFunc(dirtiedFunc: DirtiedFunction | null): void;
9376
9328
  // setMeasureFunc(measureFunc: MeasureFunction | null): void;
@@ -9381,7 +9333,9 @@ class FlexLayout {
9381
9333
  this._node.setMinWidth(this._style.minWidth);
9382
9334
  break;
9383
9335
  case "overflow":
9384
- this._node.setOverflow(overflowMap[this._style.overflow]);
9336
+ this._node.setOverflow(
9337
+ value ? overflowMap[value] : overflowMap.visible
9338
+ );
9385
9339
  break;
9386
9340
  case "paddingTop":
9387
9341
  this._node.setPadding(Edge.Top, this._style.paddingTop);
@@ -9411,10 +9365,14 @@ class FlexLayout {
9411
9365
  this._node.setPosition(Edge.Right, this._style.right);
9412
9366
  break;
9413
9367
  case "position":
9414
- this._node.setPositionType(positionTypeMap[this._style.position]);
9368
+ this._node.setPositionType(
9369
+ value ? positionTypeMap[value] : positionTypeMap.static
9370
+ );
9415
9371
  break;
9416
9372
  case "boxSizing":
9417
- this._node.setBoxSizing(boxSizingMap[this._style.boxSizing]);
9373
+ this._node.setBoxSizing(
9374
+ value ? boxSizingMap[value] : boxSizingMap["content-box"]
9375
+ );
9418
9376
  break;
9419
9377
  case "width":
9420
9378
  this._node.setWidth(this._style.width);
@@ -10388,6 +10346,10 @@ let Animation = class extends TimelineNode {
10388
10346
  _getDiffValue(name, previous, current, weight, context) {
10389
10347
  let from;
10390
10348
  let to;
10349
+ if (previous === "none")
10350
+ previous = void 0;
10351
+ if (current === "none")
10352
+ current = void 0;
10391
10353
  if (previous === void 0 || current === void 0) {
10392
10354
  if (previous !== void 0) {
10393
10355
  from = parseCssProperty(name, String(previous), context);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-canvas",
3
3
  "type": "module",
4
- "version": "0.4.12",
4
+ "version": "0.4.14",
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.0",
73
- "modern-idoc": "^0.2.8",
73
+ "modern-idoc": "^0.2.12",
74
74
  "modern-path2d": "^1.2.10",
75
- "modern-text": "^1.2.3",
75
+ "modern-text": "^1.3.1",
76
76
  "yoga-layout": "^3.2.1"
77
77
  },
78
78
  "devDependencies": {
79
- "@antfu/eslint-config": "^4.3.0",
79
+ "@antfu/eslint-config": "^4.8.1",
80
80
  "@types/earcut": "^3.0.0",
81
- "@types/node": "^22.13.5",
81
+ "@types/node": "^22.13.10",
82
82
  "bumpp": "^10.0.3",
83
83
  "conventional-changelog-cli": "^5.0.0",
84
- "eslint": "^9.21.0",
84
+ "eslint": "^9.22.0",
85
85
  "lint-staged": "^15.4.3",
86
86
  "lottie-web": "^5.12.2",
87
87
  "modern-gif": "^2.0.4",
88
88
  "simple-git-hooks": "^2.11.1",
89
- "typescript": "^5.7.3",
89
+ "typescript": "^5.8.2",
90
90
  "unbuild": "^3.5.0",
91
- "vite": "^6.2.0",
92
- "vitest": "^3.0.7"
91
+ "vite": "^6.2.1",
92
+ "vitest": "^3.0.8"
93
93
  },
94
94
  "simple-git-hooks": {
95
95
  "pre-commit": "pnpm lint-staged"