modern-canvas 0.4.6 → 0.4.8

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
@@ -5892,6 +5892,17 @@ let Node = class extends CoreObject {
5892
5892
  this._parent.moveChild(sibling, this.getIndex(true) + 1);
5893
5893
  return this;
5894
5894
  }
5895
+ prepend(...nodes) {
5896
+ let _nodes;
5897
+ if (Array.isArray(nodes[0])) {
5898
+ _nodes = nodes[0];
5899
+ } else {
5900
+ _nodes = nodes;
5901
+ }
5902
+ _nodes.forEach((node) => {
5903
+ this.moveChild(node, 0);
5904
+ });
5905
+ }
5895
5906
  append(...nodes) {
5896
5907
  let _nodes;
5897
5908
  if (Array.isArray(nodes[0])) {
@@ -5903,6 +5914,35 @@ let Node = class extends CoreObject {
5903
5914
  this.appendChild(node);
5904
5915
  });
5905
5916
  }
5917
+ before(...nodes) {
5918
+ let _nodes;
5919
+ if (Array.isArray(nodes[0])) {
5920
+ _nodes = nodes[0];
5921
+ } else {
5922
+ _nodes = nodes;
5923
+ }
5924
+ _nodes.forEach((node) => {
5925
+ this._parent?.moveChild(node, this.getIndex(true));
5926
+ });
5927
+ }
5928
+ after(...nodes) {
5929
+ let _nodes;
5930
+ if (Array.isArray(nodes[0])) {
5931
+ _nodes = nodes[0];
5932
+ } else {
5933
+ _nodes = nodes;
5934
+ }
5935
+ _nodes.forEach((node) => {
5936
+ this._parent?.moveChild(node, this.getIndex(true) + 1);
5937
+ });
5938
+ }
5939
+ insertBefore(node, child) {
5940
+ if (!child.hasParent() || !this.is(child.parent)) {
5941
+ return node;
5942
+ }
5943
+ this.moveChild(node, child.getIndex(true));
5944
+ return node;
5945
+ }
5906
5946
  appendChild(node, internalMode = node.internalMode) {
5907
5947
  if (this.is(node) || node.hasParent()) {
5908
5948
  return node;
@@ -7250,7 +7290,7 @@ let GlitchEffect = class extends Effect {
7250
7290
  _texture;
7251
7291
  _sizes;
7252
7292
  _offsets;
7253
- _redraw = false;
7293
+ _needsRedraw = false;
7254
7294
  slices = 10;
7255
7295
  sampleSize = 512;
7256
7296
  offset = 100;
@@ -7288,8 +7328,8 @@ let GlitchEffect = class extends Effect {
7288
7328
  texture.requestUpload();
7289
7329
  }
7290
7330
  apply(renderer, source) {
7291
- if (!this._redraw) {
7292
- this._redraw = true;
7331
+ if (!this._needsRedraw) {
7332
+ this._needsRedraw = true;
7293
7333
  this.redraw();
7294
7334
  }
7295
7335
  const width = source.width;
@@ -8079,22 +8119,37 @@ let CanvasItem = class extends TimelineNode {
8079
8119
  this.requestRepaint();
8080
8120
  }
8081
8121
  }
8122
+ _draw() {
8123
+ this.emit("draw");
8124
+ }
8125
+ _redraw() {
8126
+ this._tree?.log(this.name, "redrawing");
8127
+ this._draw();
8128
+ return this.context.toBatchables();
8129
+ }
8082
8130
  _relayout(batchables) {
8083
- return this._repaint(batchables);
8131
+ this._tree?.log(this.name, "relayouting");
8132
+ return batchables;
8084
8133
  }
8085
8134
  _repaint(batchables) {
8135
+ this._tree?.log(this.name, "repainting");
8086
8136
  return batchables.map((batchable) => {
8087
8137
  return {
8088
8138
  ...batchable,
8089
8139
  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
8140
  blendMode: this.blendMode
8094
8141
  };
8095
8142
  });
8096
8143
  }
8097
- _draw() {
8144
+ _process(delta) {
8145
+ super._process(delta);
8146
+ const parent = this.getParent();
8147
+ if (this._parentGlobalVisible !== parent?.globalVisible) {
8148
+ this.requestUpdate();
8149
+ }
8150
+ if (this._parentGlobalOpacity !== parent?.globalOpacity) {
8151
+ this.requestUpdate();
8152
+ }
8098
8153
  }
8099
8154
  _update() {
8100
8155
  const parent = this.getParent();
@@ -8104,20 +8159,25 @@ let CanvasItem = class extends TimelineNode {
8104
8159
  if (this._parentGlobalOpacity !== parent?.globalOpacity) {
8105
8160
  this._updateGlobalOpacity();
8106
8161
  }
8162
+ const redrawing = this._redrawing;
8163
+ let relayouting = this._relayouting;
8164
+ let repainting = this._repainting;
8107
8165
  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);
8166
+ if (redrawing) {
8167
+ this._originalBatchables = this._redraw();
8168
+ relayouting = true;
8169
+ }
8170
+ if (relayouting) {
8171
+ this._layoutedBatchables = this._relayout(this._originalBatchables);
8172
+ repainting = true;
8173
+ }
8174
+ if (repainting) {
8175
+ batchables = this._repaint(this._layoutedBatchables);
8176
+ }
8177
+ if (redrawing) {
8113
8178
  if (this._resetContext) {
8114
8179
  this.context.reset();
8115
8180
  }
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
8181
  }
8122
8182
  if (batchables) {
8123
8183
  this._batchables = batchables;
@@ -8281,6 +8341,11 @@ class SceneTree extends MainLoop {
8281
8341
  break;
8282
8342
  }
8283
8343
  }
8344
+ log(...args) {
8345
+ if (this.debug) {
8346
+ console.log(`[modern-canvas]`, ...args);
8347
+ }
8348
+ }
8284
8349
  _render(renderer, delta = 0) {
8285
8350
  this.timeline.addTime(delta);
8286
8351
  this.emit("processing");
@@ -8326,6 +8391,9 @@ __decorateClass$r([
8326
8391
  __decorateClass$r([
8327
8392
  property()
8328
8393
  ], SceneTree.prototype, "backgroundColor");
8394
+ __decorateClass$r([
8395
+ protectedProperty({ default: false })
8396
+ ], SceneTree.prototype, "debug");
8329
8397
 
8330
8398
  var __getOwnPropDesc$p = Object.getOwnPropertyDescriptor;
8331
8399
  var __decorateClass$q = (decorators, target, key, kind) => {
@@ -8661,21 +8729,19 @@ let Node2D = class extends CanvasItem {
8661
8729
  _relayout(batchables) {
8662
8730
  this._updateTransform();
8663
8731
  this._updateGlobalTransform();
8664
- return super._relayout(
8665
- batchables.map((batchable) => {
8666
- return {
8667
- ...batchable,
8668
- vertices: this._transformVertices(batchable.vertices)
8669
- };
8670
- })
8671
- );
8732
+ return super._relayout(batchables).map((batchable) => {
8733
+ return {
8734
+ ...batchable,
8735
+ vertices: this._transformVertices(batchable.vertices)
8736
+ };
8737
+ });
8672
8738
  }
8673
8739
  _process(delta) {
8740
+ super._process(delta);
8674
8741
  const parent = this.getParent();
8675
- if (parent?.transform?.dirtyId !== this._parentTransformDirtyId) {
8742
+ if (this._parentTransformDirtyId !== parent?.globalTransform?.dirtyId) {
8676
8743
  this.requestRelayout();
8677
8744
  }
8678
- super._process(delta);
8679
8745
  }
8680
8746
  };
8681
8747
  Node2D = __decorateClass$n([
@@ -8886,6 +8952,7 @@ let BaseElement2D = class extends Node2D {
8886
8952
  }
8887
8953
  }
8888
8954
  _draw() {
8955
+ super._draw();
8889
8956
  this._drawBackground();
8890
8957
  this._drawContent();
8891
8958
  this._drawBorder();
@@ -8941,14 +9008,12 @@ let BaseElement2D = class extends Node2D {
8941
9008
  }
8942
9009
  _repaint(batchables) {
8943
9010
  const colorMatrix = parseCSSFilter(this.style.filter);
8944
- return batchables.map((batchable) => {
9011
+ return super._repaint(batchables).map((batchable) => {
8945
9012
  return {
8946
9013
  ...batchable,
8947
9014
  backgroundColor: this.style.getComputedBackgroundColor().abgr,
8948
- modulate: this._modulate.toArgb(this.globalOpacity, true),
8949
9015
  colorMatrix: colorMatrix.toMatrix4().toArray(true),
8950
- colorMatrixOffset: colorMatrix.toVector4().toArray(),
8951
- blendMode: this.blendMode
9016
+ colorMatrixOffset: colorMatrix.toVector4().toArray()
8952
9017
  };
8953
9018
  });
8954
9019
  }
@@ -13043,6 +13108,7 @@ class Engine extends SceneTree {
13043
13108
  }) : void 0;
13044
13109
  constructor(options = {}) {
13045
13110
  const {
13111
+ debug = false,
13046
13112
  view,
13047
13113
  width,
13048
13114
  height,
@@ -13054,6 +13120,7 @@ class Engine extends SceneTree {
13054
13120
  ...glOptions
13055
13121
  } = options;
13056
13122
  super(timeline);
13123
+ this.debug = debug;
13057
13124
  this.renderer = new WebGLRenderer(view, {
13058
13125
  ...defaultOptions,
13059
13126
  ...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.8",
5
5
  "packageManager": "pnpm@9.15.1",
6
6
  "description": "A JavaScript WebGL rendering engine.",
7
7
  "author": "wxm",