modern-canvas 0.4.6 → 0.4.7

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
@@ -7250,7 +7250,7 @@ let GlitchEffect = class extends Effect {
7250
7250
  _texture;
7251
7251
  _sizes;
7252
7252
  _offsets;
7253
- _redraw = false;
7253
+ _needsRedraw = false;
7254
7254
  slices = 10;
7255
7255
  sampleSize = 512;
7256
7256
  offset = 100;
@@ -7288,8 +7288,8 @@ let GlitchEffect = class extends Effect {
7288
7288
  texture.requestUpload();
7289
7289
  }
7290
7290
  apply(renderer, source) {
7291
- if (!this._redraw) {
7292
- this._redraw = true;
7291
+ if (!this._needsRedraw) {
7292
+ this._needsRedraw = true;
7293
7293
  this.redraw();
7294
7294
  }
7295
7295
  const width = source.width;
@@ -8079,23 +8079,28 @@ let CanvasItem = class extends TimelineNode {
8079
8079
  this.requestRepaint();
8080
8080
  }
8081
8081
  }
8082
+ _draw() {
8083
+ this.emit("draw");
8084
+ }
8085
+ _redraw() {
8086
+ this._tree?.log(this.name, "redrawing");
8087
+ this._draw();
8088
+ return this.context.toBatchables();
8089
+ }
8082
8090
  _relayout(batchables) {
8083
- return this._repaint(batchables);
8091
+ this._tree?.log(this.name, "relayouting");
8092
+ return batchables;
8084
8093
  }
8085
8094
  _repaint(batchables) {
8095
+ this._tree?.log(this.name, "repainting");
8086
8096
  return batchables.map((batchable) => {
8087
8097
  return {
8088
8098
  ...batchable,
8089
8099
  modulate: this._modulate.toArgb(this.globalOpacity, true),
8090
- // backgroundColor: this.style.getComputedBackgroundColor().abgr,
8091
- // colorMatrix: colorMatrix.toMatrix4().toArray(true),
8092
- // colorMatrixOffset: colorMatrix.toVector4().toArray(),
8093
8100
  blendMode: this.blendMode
8094
8101
  };
8095
8102
  });
8096
8103
  }
8097
- _draw() {
8098
- }
8099
8104
  _update() {
8100
8105
  const parent = this.getParent();
8101
8106
  if (this._parentGlobalVisible !== parent?.globalVisible) {
@@ -8104,20 +8109,25 @@ let CanvasItem = class extends TimelineNode {
8104
8109
  if (this._parentGlobalOpacity !== parent?.globalOpacity) {
8105
8110
  this._updateGlobalOpacity();
8106
8111
  }
8112
+ const redrawing = this._redrawing;
8113
+ let relayouting = this._relayouting;
8114
+ let repainting = this._repainting;
8107
8115
  let batchables;
8108
- if (this._redrawing) {
8109
- this.emit("draw");
8110
- this._draw();
8111
- this._originalBatchables = this.context.toBatchables();
8112
- batchables = this._relayout(this._originalBatchables);
8116
+ if (redrawing) {
8117
+ this._originalBatchables = this._redraw();
8118
+ relayouting = true;
8119
+ }
8120
+ if (relayouting) {
8121
+ this._layoutedBatchables = this._relayout(this._originalBatchables);
8122
+ repainting = true;
8123
+ }
8124
+ if (repainting) {
8125
+ batchables = this._repaint(this._layoutedBatchables);
8126
+ }
8127
+ if (redrawing) {
8113
8128
  if (this._resetContext) {
8114
8129
  this.context.reset();
8115
8130
  }
8116
- } else if (this._relayouting) {
8117
- this._layoutedBatchables = this._relayout(this._originalBatchables);
8118
- batchables = this._layoutedBatchables;
8119
- } else if (this._repainting) {
8120
- batchables = this._repaint(this._layoutedBatchables);
8121
8131
  }
8122
8132
  if (batchables) {
8123
8133
  this._batchables = batchables;
@@ -8281,6 +8291,11 @@ class SceneTree extends MainLoop {
8281
8291
  break;
8282
8292
  }
8283
8293
  }
8294
+ log(...args) {
8295
+ if (this.debug) {
8296
+ console.log(`[modern-canvas]`, ...args);
8297
+ }
8298
+ }
8284
8299
  _render(renderer, delta = 0) {
8285
8300
  this.timeline.addTime(delta);
8286
8301
  this.emit("processing");
@@ -8326,6 +8341,9 @@ __decorateClass$r([
8326
8341
  __decorateClass$r([
8327
8342
  property()
8328
8343
  ], SceneTree.prototype, "backgroundColor");
8344
+ __decorateClass$r([
8345
+ protectedProperty({ default: false })
8346
+ ], SceneTree.prototype, "debug");
8329
8347
 
8330
8348
  var __getOwnPropDesc$p = Object.getOwnPropertyDescriptor;
8331
8349
  var __decorateClass$q = (decorators, target, key, kind) => {
@@ -8661,18 +8679,16 @@ let Node2D = class extends CanvasItem {
8661
8679
  _relayout(batchables) {
8662
8680
  this._updateTransform();
8663
8681
  this._updateGlobalTransform();
8664
- return super._relayout(
8665
- batchables.map((batchable) => {
8666
- return {
8667
- ...batchable,
8668
- vertices: this._transformVertices(batchable.vertices)
8669
- };
8670
- })
8671
- );
8682
+ return super._relayout(batchables).map((batchable) => {
8683
+ return {
8684
+ ...batchable,
8685
+ vertices: this._transformVertices(batchable.vertices)
8686
+ };
8687
+ });
8672
8688
  }
8673
8689
  _process(delta) {
8674
8690
  const parent = this.getParent();
8675
- if (parent?.transform?.dirtyId !== this._parentTransformDirtyId) {
8691
+ if (this._parentTransformDirtyId !== parent?.globalTransform?.dirtyId) {
8676
8692
  this.requestRelayout();
8677
8693
  }
8678
8694
  super._process(delta);
@@ -8886,6 +8902,7 @@ let BaseElement2D = class extends Node2D {
8886
8902
  }
8887
8903
  }
8888
8904
  _draw() {
8905
+ super._draw();
8889
8906
  this._drawBackground();
8890
8907
  this._drawContent();
8891
8908
  this._drawBorder();
@@ -8941,14 +8958,12 @@ let BaseElement2D = class extends Node2D {
8941
8958
  }
8942
8959
  _repaint(batchables) {
8943
8960
  const colorMatrix = parseCSSFilter(this.style.filter);
8944
- return batchables.map((batchable) => {
8961
+ return super._repaint(batchables).map((batchable) => {
8945
8962
  return {
8946
8963
  ...batchable,
8947
8964
  backgroundColor: this.style.getComputedBackgroundColor().abgr,
8948
- modulate: this._modulate.toArgb(this.globalOpacity, true),
8949
8965
  colorMatrix: colorMatrix.toMatrix4().toArray(true),
8950
- colorMatrixOffset: colorMatrix.toVector4().toArray(),
8951
- blendMode: this.blendMode
8966
+ colorMatrixOffset: colorMatrix.toVector4().toArray()
8952
8967
  };
8953
8968
  });
8954
8969
  }
@@ -13043,6 +13058,7 @@ class Engine extends SceneTree {
13043
13058
  }) : void 0;
13044
13059
  constructor(options = {}) {
13045
13060
  const {
13061
+ debug = false,
13046
13062
  view,
13047
13063
  width,
13048
13064
  height,
@@ -13054,6 +13070,7 @@ class Engine extends SceneTree {
13054
13070
  ...glOptions
13055
13071
  } = options;
13056
13072
  super(timeline);
13073
+ this.debug = debug;
13057
13074
  this.renderer = new WebGLRenderer(view, {
13058
13075
  ...defaultOptions,
13059
13076
  ...glOptions
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-canvas",
3
3
  "type": "module",
4
- "version": "0.4.6",
4
+ "version": "0.4.7",
5
5
  "packageManager": "pnpm@9.15.1",
6
6
  "description": "A JavaScript WebGL rendering engine.",
7
7
  "author": "wxm",