modern-canvas 0.4.11 → 0.4.13

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';
@@ -3213,8 +3213,8 @@ class WebGLFramebufferModule extends WebGLModule {
3213
3213
  this._renderer.viewport.bind({
3214
3214
  x: 0,
3215
3215
  y: 0,
3216
- width: this._renderer.screen.width,
3217
- height: this._renderer.screen.height
3216
+ width: this._renderer.screen.width * this._renderer.pixelRatio,
3217
+ height: this._renderer.screen.height * this._renderer.pixelRatio
3218
3218
  });
3219
3219
  }
3220
3220
  }
@@ -5788,6 +5788,14 @@ let Node = class extends CoreObject {
5788
5788
  return false;
5789
5789
  }
5790
5790
  }
5791
+ _update(changed) {
5792
+ this._tree?.log(this.name, "updating");
5793
+ super._update(changed);
5794
+ }
5795
+ _updateProperty(key, value, oldValue, declaration) {
5796
+ this._tree?.log(this.name, `updating [${String(key)}]`);
5797
+ super._updateProperty(key, value, oldValue, declaration);
5798
+ }
5791
5799
  _onTreeEnter(tree) {
5792
5800
  this._treeEnter(tree);
5793
5801
  this.emit("treeEntered", tree);
@@ -6291,8 +6299,8 @@ let Viewport = class extends Node {
6291
6299
  if (this.valid) {
6292
6300
  renderer.flush();
6293
6301
  this._tree?.setCurrentViewport(this);
6294
- renderer.framebuffer.bind(this._glFramebuffer(renderer));
6295
6302
  this.upload(renderer);
6303
+ renderer.framebuffer.bind(this._glFramebuffer(renderer));
6296
6304
  return true;
6297
6305
  }
6298
6306
  return false;
@@ -8359,14 +8367,12 @@ class SceneTree extends MainLoop {
8359
8367
  }
8360
8368
  _renderScreen(renderer) {
8361
8369
  renderer.state.reset();
8362
- const { pixelRatio } = renderer;
8363
- const { width, height } = this.root;
8364
8370
  renderer.framebuffer.bind(null);
8365
8371
  renderer.viewport.bind({
8366
8372
  x: 0,
8367
8373
  y: 0,
8368
- width: width * pixelRatio,
8369
- height: height * pixelRatio
8374
+ width: this.root.width * renderer.pixelRatio,
8375
+ height: this.root.height * renderer.pixelRatio
8370
8376
  });
8371
8377
  if (this.backgroundColor) {
8372
8378
  renderer.gl.clearColor(...this._backgroundColor.toArray());
@@ -8630,38 +8636,20 @@ class BaseElement2DStyle extends Resource {
8630
8636
  return this._backgroundColor;
8631
8637
  }
8632
8638
  async loadBackgroundImage() {
8633
- if (this.backgroundImage !== "none") {
8639
+ if (this.backgroundImage && this.backgroundImage !== "none") {
8634
8640
  return await assets.texture.load(this.backgroundImage);
8635
8641
  }
8636
8642
  }
8637
8643
  }
8638
- const defaultStyles$2 = {
8639
- ...getDefaultTransformStyle(),
8640
- ...getDefaultTextStyle(),
8641
- backgroundColor: "none",
8642
- backgroundImage: "none",
8643
- filter: "none",
8644
- boxShadow: "none",
8645
- maskImage: "none",
8646
- opacity: 1,
8647
- borderWidth: 0,
8648
- borderRadius: 0,
8649
- borderColor: "#000000",
8650
- borderStyle: "none",
8651
- outlineWidth: 0,
8652
- outlineOffset: 0,
8653
- outlineColor: "#000000",
8654
- outlineStyle: "none",
8655
- visibility: "visible",
8656
- overflow: "visible",
8657
- pointerEvents: "auto"
8658
- };
8659
- delete defaultStyles$2.top;
8660
- delete defaultStyles$2.left;
8661
- delete defaultStyles$2.width;
8662
- delete defaultStyles$2.height;
8663
- for (const key in defaultStyles$2) {
8664
- 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
+ });
8665
8653
  }
8666
8654
 
8667
8655
  var __getOwnPropDesc$m = Object.getOwnPropertyDescriptor;
@@ -9083,14 +9071,14 @@ class Element2DStyle extends BaseElement2DStyle {
9083
9071
  this.setProperties(properties);
9084
9072
  }
9085
9073
  }
9086
- const defaultStyles$1 = {
9074
+ const defaultStyles = {
9087
9075
  left: 0,
9088
9076
  top: 0,
9089
9077
  width: 0,
9090
9078
  height: 0
9091
9079
  };
9092
- for (const key in defaultStyles$1) {
9093
- defineProperty(Element2DStyle, key, { default: defaultStyles$1[key] });
9080
+ for (const key in defaultStyles) {
9081
+ defineProperty(Element2DStyle, key, { default: defaultStyles[key] });
9094
9082
  }
9095
9083
 
9096
9084
  var __getOwnPropDesc$k = Object.getOwnPropertyDescriptor;
@@ -9123,19 +9111,19 @@ let Element2D = class extends BaseElement2D {
9123
9111
  super._updateStyleProperty(key, value, oldValue, declaration);
9124
9112
  switch (key) {
9125
9113
  case "left":
9126
- this.position.x = this.style.left;
9114
+ this.position.x = Number(value);
9127
9115
  this.requestRelayout();
9128
9116
  break;
9129
9117
  case "top":
9130
- this.position.y = this.style.top;
9118
+ this.position.y = Number(value);
9131
9119
  this.requestRelayout();
9132
9120
  break;
9133
9121
  case "width":
9134
- this.size.width = this.style.width;
9122
+ this.size.width = Number(value);
9135
9123
  this.requestRelayout();
9136
9124
  break;
9137
9125
  case "height":
9138
- this.size.height = this.style.height;
9126
+ this.size.height = Number(value);
9139
9127
  this.requestRelayout();
9140
9128
  break;
9141
9129
  }
@@ -9151,52 +9139,6 @@ class FlexElement2DStyle extends BaseElement2DStyle {
9151
9139
  this.setProperties(properties);
9152
9140
  }
9153
9141
  }
9154
- const defaultStyles = {
9155
- alignContent: "stretch",
9156
- alignItems: "stretch",
9157
- alignSelf: "auto",
9158
- borderTop: "none",
9159
- borderLeft: "none",
9160
- borderRight: "none",
9161
- borderBottom: "none",
9162
- borderWidth: 0,
9163
- border: "none",
9164
- direction: "inherit",
9165
- display: "flex",
9166
- flex: 0,
9167
- flexBasis: "auto",
9168
- flexDirection: "row",
9169
- flexGrow: 0,
9170
- flexShrink: 1,
9171
- flexWrap: "nowrap",
9172
- height: "auto",
9173
- justifyContent: "flex-start",
9174
- gap: 0,
9175
- marginTop: 0,
9176
- marginLeft: 0,
9177
- marginRight: 0,
9178
- marginBottom: 0,
9179
- margin: 0,
9180
- maxHeight: 0,
9181
- maxWidth: 0,
9182
- minHeight: 0,
9183
- minWidth: 0,
9184
- paddingTop: 0,
9185
- paddingLeft: 0,
9186
- paddingRight: 0,
9187
- paddingBottom: 0,
9188
- padding: 0,
9189
- top: 0,
9190
- bottom: 0,
9191
- left: 0,
9192
- right: 0,
9193
- position: "static",
9194
- boxSizing: "content-box",
9195
- width: "auto"
9196
- };
9197
- for (const key in defaultStyles) {
9198
- defineProperty(FlexElement2DStyle, key, { default: defaultStyles[key] });
9199
- }
9200
9142
 
9201
9143
  const alignMap = {
9202
9144
  "auto": Align.Auto,
@@ -9286,13 +9228,19 @@ class FlexLayout {
9286
9228
  updateStyleProperty(key, value, oldValue, declaration) {
9287
9229
  switch (key) {
9288
9230
  case "alignContent":
9289
- this._node.setAlignContent(alignMap[this._style.alignContent]);
9231
+ this._node.setAlignContent(
9232
+ value ? alignMap[value] : alignMap["flex-start"]
9233
+ );
9290
9234
  break;
9291
9235
  case "alignItems":
9292
- this._node.setAlignItems(alignMap[this._style.alignItems]);
9236
+ this._node.setAlignItems(
9237
+ value ? alignMap[value] : alignMap["flex-start"]
9238
+ );
9293
9239
  break;
9294
9240
  case "alignSelf":
9295
- this._node.setAlignSelf(alignMap[this._style.alignSelf]);
9241
+ this._node.setAlignSelf(
9242
+ value ? alignMap[value] : alignMap["flex-start"]
9243
+ );
9296
9244
  break;
9297
9245
  case "aspectRatio":
9298
9246
  this._node.setAspectRatio(value);
@@ -9313,10 +9261,14 @@ class FlexLayout {
9313
9261
  this._node.setBorder(Edge.All, this._style.borderWidth);
9314
9262
  break;
9315
9263
  case "direction":
9316
- this._node.setDirection(directionMap[this._style.direction]);
9264
+ this._node.setDirection(
9265
+ value ? directionMap[value] : directionMap.inherit
9266
+ );
9317
9267
  break;
9318
9268
  case "display":
9319
- this._node.setDisplay(displayMap[this._style.display]);
9269
+ this._node.setDisplay(
9270
+ value ? displayMap[value] : displayMap.flex
9271
+ );
9320
9272
  break;
9321
9273
  case "flex":
9322
9274
  this._node.setFlex(this._style.flex);
@@ -9325,7 +9277,9 @@ class FlexLayout {
9325
9277
  this._node.setFlexBasis(this._style.flexBasis);
9326
9278
  break;
9327
9279
  case "flexDirection":
9328
- this._node.setFlexDirection(flexDirectionMap[this._style.flexDirection]);
9280
+ this._node.setFlexDirection(
9281
+ value ? flexDirectionMap[value] : flexDirectionMap.row
9282
+ );
9329
9283
  break;
9330
9284
  case "flexGrow":
9331
9285
  this._node.setFlexGrow(this._style.flexGrow);
@@ -9334,37 +9288,41 @@ class FlexLayout {
9334
9288
  this._node.setFlexShrink(this._style.flexShrink);
9335
9289
  break;
9336
9290
  case "flexWrap":
9337
- this._node.setFlexWrap(flexWrapMap[this._style.flexWrap]);
9291
+ this._node.setFlexWrap(
9292
+ value ? flexWrapMap[value] : flexWrapMap.wrap
9293
+ );
9338
9294
  break;
9339
9295
  case "height":
9340
9296
  this._node.setHeight(this._style.height);
9341
9297
  break;
9342
9298
  case "justifyContent":
9343
- this._node.setJustifyContent(justifyMap[this._style.justifyContent]);
9299
+ this._node.setJustifyContent(
9300
+ value ? justifyMap[value] : justifyMap["flex-start"]
9301
+ );
9344
9302
  break;
9345
9303
  case "gap":
9346
- this._node.setGap(Gutter.All, this._style.gap);
9304
+ value !== void 0 && this._node.setGap(Gutter.All, value);
9347
9305
  break;
9348
9306
  case "marginTop":
9349
- this._node.setMargin(Edge.Top, this._style.marginTop);
9307
+ this._node.setMargin(Edge.Top, value);
9350
9308
  break;
9351
9309
  case "marginBottom":
9352
- this._node.setMargin(Edge.Top, this._style.marginBottom);
9310
+ this._node.setMargin(Edge.Top, value);
9353
9311
  break;
9354
9312
  case "marginLeft":
9355
- this._node.setMargin(Edge.Left, this._style.marginLeft);
9313
+ this._node.setMargin(Edge.Left, value);
9356
9314
  break;
9357
9315
  case "marginRight":
9358
- this._node.setMargin(Edge.Top, this._style.marginRight);
9316
+ this._node.setMargin(Edge.Top, value);
9359
9317
  break;
9360
9318
  case "margin":
9361
- this._node.setMargin(Edge.All, this._style.margin);
9319
+ this._node.setMargin(Edge.All, value);
9362
9320
  break;
9363
9321
  case "maxHeight":
9364
- this._node.setMaxHeight(this._style.maxHeight);
9322
+ this._node.setMaxHeight(value);
9365
9323
  break;
9366
9324
  case "maxWidth":
9367
- this._node.setMaxWidth(this._style.maxWidth);
9325
+ this._node.setMaxWidth(value);
9368
9326
  break;
9369
9327
  // setDirtiedFunc(dirtiedFunc: DirtiedFunction | null): void;
9370
9328
  // setMeasureFunc(measureFunc: MeasureFunction | null): void;
@@ -9375,7 +9333,9 @@ class FlexLayout {
9375
9333
  this._node.setMinWidth(this._style.minWidth);
9376
9334
  break;
9377
9335
  case "overflow":
9378
- this._node.setOverflow(overflowMap[this._style.overflow]);
9336
+ this._node.setOverflow(
9337
+ value ? overflowMap[value] : overflowMap.visible
9338
+ );
9379
9339
  break;
9380
9340
  case "paddingTop":
9381
9341
  this._node.setPadding(Edge.Top, this._style.paddingTop);
@@ -9405,10 +9365,14 @@ class FlexLayout {
9405
9365
  this._node.setPosition(Edge.Right, this._style.right);
9406
9366
  break;
9407
9367
  case "position":
9408
- this._node.setPositionType(positionTypeMap[this._style.position]);
9368
+ this._node.setPositionType(
9369
+ value ? positionTypeMap[value] : positionTypeMap.static
9370
+ );
9409
9371
  break;
9410
9372
  case "boxSizing":
9411
- this._node.setBoxSizing(boxSizingMap[this._style.boxSizing]);
9373
+ this._node.setBoxSizing(
9374
+ value ? boxSizingMap[value] : boxSizingMap["content-box"]
9375
+ );
9412
9376
  break;
9413
9377
  case "width":
9414
9378
  this._node.setWidth(this._style.width);
@@ -13187,8 +13151,9 @@ class Engine extends SceneTree {
13187
13151
  await this.nextTick();
13188
13152
  }
13189
13153
  async waitAndRender(delta = 0) {
13154
+ await assets.waitUntilLoad();
13190
13155
  this._process(delta);
13191
- await this.waitUntilLoad();
13156
+ await this.nextTick();
13192
13157
  this._render(this.renderer);
13193
13158
  }
13194
13159
  render(delta = 0) {
@@ -13260,11 +13225,16 @@ async function start(sleep = 100) {
13260
13225
  starting = false;
13261
13226
  }
13262
13227
  async function task(options) {
13263
- const { data, width, height, time = 0 } = options;
13264
- engine ??= new Engine({ width: 1, height: 1 });
13228
+ const { data, width, height, debug = false, time = 0 } = options;
13229
+ engine ??= new Engine({
13230
+ width: 1,
13231
+ height: 1,
13232
+ preserveDrawingBuffer: true
13233
+ });
13234
+ engine.debug = debug;
13265
13235
  engine.root.removeChildren();
13266
13236
  engine.timeline.currentTime = time;
13267
- engine.resize(width, height);
13237
+ engine.resize(width, height, true);
13268
13238
  (Array.isArray(data) ? data : [data]).forEach((v) => {
13269
13239
  if (v instanceof Node) {
13270
13240
  engine.root.appendChild(v);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-canvas",
3
3
  "type": "module",
4
- "version": "0.4.11",
4
+ "version": "0.4.13",
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"