modern-canvas 0.4.5 → 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.cjs +70 -47
- package/dist/index.d.cts +8 -2
- package/dist/index.d.mts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +30 -30
- package/dist/index.mjs +70 -47
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -6133,6 +6133,7 @@ let TimelineNode = class extends Node {
|
|
|
6133
6133
|
this.computedDuration = parent?.computedDuration ? Math.min(this._startTime + this.duration, parent.endTime) - this._startTime : this.duration;
|
|
6134
6134
|
this._currentTime = this.timelineCurrentTime - this._startTime;
|
|
6135
6135
|
this.emit("updateCurrentTime", this._currentTime);
|
|
6136
|
+
this.insideTimeRange = this.isInsideTimeRange();
|
|
6136
6137
|
}
|
|
6137
6138
|
}
|
|
6138
6139
|
_process(delta) {
|
|
@@ -6149,6 +6150,9 @@ __decorateClass$H([
|
|
|
6149
6150
|
__decorateClass$H([
|
|
6150
6151
|
property({ default: false })
|
|
6151
6152
|
], TimelineNode.prototype, "paused", 2);
|
|
6153
|
+
__decorateClass$H([
|
|
6154
|
+
protectedProperty()
|
|
6155
|
+
], TimelineNode.prototype, "insideTimeRange", 2);
|
|
6152
6156
|
TimelineNode = __decorateClass$H([
|
|
6153
6157
|
customNode("TimelineNode")
|
|
6154
6158
|
], TimelineNode);
|
|
@@ -7246,7 +7250,7 @@ let GlitchEffect = class extends Effect {
|
|
|
7246
7250
|
_texture;
|
|
7247
7251
|
_sizes;
|
|
7248
7252
|
_offsets;
|
|
7249
|
-
|
|
7253
|
+
_needsRedraw = false;
|
|
7250
7254
|
slices = 10;
|
|
7251
7255
|
sampleSize = 512;
|
|
7252
7256
|
offset = 100;
|
|
@@ -7284,8 +7288,8 @@ let GlitchEffect = class extends Effect {
|
|
|
7284
7288
|
texture.requestUpload();
|
|
7285
7289
|
}
|
|
7286
7290
|
apply(renderer, source) {
|
|
7287
|
-
if (!this.
|
|
7288
|
-
this.
|
|
7291
|
+
if (!this._needsRedraw) {
|
|
7292
|
+
this._needsRedraw = true;
|
|
7289
7293
|
this.redraw();
|
|
7290
7294
|
}
|
|
7291
7295
|
const width = source.width;
|
|
@@ -8034,6 +8038,7 @@ let CanvasItem = class extends TimelineNode {
|
|
|
8034
8038
|
this._updateGlobalOpacity();
|
|
8035
8039
|
break;
|
|
8036
8040
|
case "visible":
|
|
8041
|
+
case "insideTimeRange":
|
|
8037
8042
|
this._updateGlobalVisible();
|
|
8038
8043
|
break;
|
|
8039
8044
|
}
|
|
@@ -8064,7 +8069,7 @@ let CanvasItem = class extends TimelineNode {
|
|
|
8064
8069
|
}
|
|
8065
8070
|
_updateGlobalVisible() {
|
|
8066
8071
|
this._parentGlobalVisible = this.getParent()?.globalVisible;
|
|
8067
|
-
this._globalVisible = this.
|
|
8072
|
+
this._globalVisible = (this._parentGlobalVisible ?? true) && this.visible && this.insideTimeRange;
|
|
8068
8073
|
}
|
|
8069
8074
|
_updateGlobalOpacity() {
|
|
8070
8075
|
this._parentGlobalOpacity = this.getParent()?.opacity;
|
|
@@ -8074,23 +8079,28 @@ let CanvasItem = class extends TimelineNode {
|
|
|
8074
8079
|
this.requestRepaint();
|
|
8075
8080
|
}
|
|
8076
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
|
+
}
|
|
8077
8090
|
_relayout(batchables) {
|
|
8078
|
-
|
|
8091
|
+
this._tree?.log(this.name, "relayouting");
|
|
8092
|
+
return batchables;
|
|
8079
8093
|
}
|
|
8080
8094
|
_repaint(batchables) {
|
|
8095
|
+
this._tree?.log(this.name, "repainting");
|
|
8081
8096
|
return batchables.map((batchable) => {
|
|
8082
8097
|
return {
|
|
8083
8098
|
...batchable,
|
|
8084
8099
|
modulate: this._modulate.toArgb(this.globalOpacity, true),
|
|
8085
|
-
// backgroundColor: this.style.getComputedBackgroundColor().abgr,
|
|
8086
|
-
// colorMatrix: colorMatrix.toMatrix4().toArray(true),
|
|
8087
|
-
// colorMatrixOffset: colorMatrix.toVector4().toArray(),
|
|
8088
8100
|
blendMode: this.blendMode
|
|
8089
8101
|
};
|
|
8090
8102
|
});
|
|
8091
8103
|
}
|
|
8092
|
-
_draw() {
|
|
8093
|
-
}
|
|
8094
8104
|
_update() {
|
|
8095
8105
|
const parent = this.getParent();
|
|
8096
8106
|
if (this._parentGlobalVisible !== parent?.globalVisible) {
|
|
@@ -8099,20 +8109,25 @@ let CanvasItem = class extends TimelineNode {
|
|
|
8099
8109
|
if (this._parentGlobalOpacity !== parent?.globalOpacity) {
|
|
8100
8110
|
this._updateGlobalOpacity();
|
|
8101
8111
|
}
|
|
8112
|
+
const redrawing = this._redrawing;
|
|
8113
|
+
let relayouting = this._relayouting;
|
|
8114
|
+
let repainting = this._repainting;
|
|
8102
8115
|
let batchables;
|
|
8103
|
-
if (
|
|
8104
|
-
this.
|
|
8105
|
-
|
|
8106
|
-
|
|
8107
|
-
|
|
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) {
|
|
8108
8128
|
if (this._resetContext) {
|
|
8109
8129
|
this.context.reset();
|
|
8110
8130
|
}
|
|
8111
|
-
} else if (this._relayouting) {
|
|
8112
|
-
this._layoutedBatchables = this._relayout(this._originalBatchables);
|
|
8113
|
-
batchables = this._layoutedBatchables;
|
|
8114
|
-
} else if (this._repainting) {
|
|
8115
|
-
batchables = this._repaint(this._layoutedBatchables);
|
|
8116
8131
|
}
|
|
8117
8132
|
if (batchables) {
|
|
8118
8133
|
this._batchables = batchables;
|
|
@@ -8276,6 +8291,11 @@ class SceneTree extends MainLoop {
|
|
|
8276
8291
|
break;
|
|
8277
8292
|
}
|
|
8278
8293
|
}
|
|
8294
|
+
log(...args) {
|
|
8295
|
+
if (this.debug) {
|
|
8296
|
+
console.log(`[modern-canvas]`, ...args);
|
|
8297
|
+
}
|
|
8298
|
+
}
|
|
8279
8299
|
_render(renderer, delta = 0) {
|
|
8280
8300
|
this.timeline.addTime(delta);
|
|
8281
8301
|
this.emit("processing");
|
|
@@ -8321,6 +8341,9 @@ __decorateClass$r([
|
|
|
8321
8341
|
__decorateClass$r([
|
|
8322
8342
|
property()
|
|
8323
8343
|
], SceneTree.prototype, "backgroundColor");
|
|
8344
|
+
__decorateClass$r([
|
|
8345
|
+
protectedProperty({ default: false })
|
|
8346
|
+
], SceneTree.prototype, "debug");
|
|
8324
8347
|
|
|
8325
8348
|
var __getOwnPropDesc$p = Object.getOwnPropertyDescriptor;
|
|
8326
8349
|
var __decorateClass$q = (decorators, target, key, kind) => {
|
|
@@ -8656,18 +8679,16 @@ let Node2D = class extends CanvasItem {
|
|
|
8656
8679
|
_relayout(batchables) {
|
|
8657
8680
|
this._updateTransform();
|
|
8658
8681
|
this._updateGlobalTransform();
|
|
8659
|
-
return super._relayout(
|
|
8660
|
-
|
|
8661
|
-
|
|
8662
|
-
|
|
8663
|
-
|
|
8664
|
-
|
|
8665
|
-
})
|
|
8666
|
-
);
|
|
8682
|
+
return super._relayout(batchables).map((batchable) => {
|
|
8683
|
+
return {
|
|
8684
|
+
...batchable,
|
|
8685
|
+
vertices: this._transformVertices(batchable.vertices)
|
|
8686
|
+
};
|
|
8687
|
+
});
|
|
8667
8688
|
}
|
|
8668
8689
|
_process(delta) {
|
|
8669
8690
|
const parent = this.getParent();
|
|
8670
|
-
if (parent?.
|
|
8691
|
+
if (this._parentTransformDirtyId !== parent?.globalTransform?.dirtyId) {
|
|
8671
8692
|
this.requestRelayout();
|
|
8672
8693
|
}
|
|
8673
8694
|
super._process(delta);
|
|
@@ -8881,6 +8902,7 @@ let BaseElement2D = class extends Node2D {
|
|
|
8881
8902
|
}
|
|
8882
8903
|
}
|
|
8883
8904
|
_draw() {
|
|
8905
|
+
super._draw();
|
|
8884
8906
|
this._drawBackground();
|
|
8885
8907
|
this._drawContent();
|
|
8886
8908
|
this._drawBorder();
|
|
@@ -8936,14 +8958,12 @@ let BaseElement2D = class extends Node2D {
|
|
|
8936
8958
|
}
|
|
8937
8959
|
_repaint(batchables) {
|
|
8938
8960
|
const colorMatrix = parseCSSFilter(this.style.filter);
|
|
8939
|
-
return batchables.map((batchable) => {
|
|
8961
|
+
return super._repaint(batchables).map((batchable) => {
|
|
8940
8962
|
return {
|
|
8941
8963
|
...batchable,
|
|
8942
8964
|
backgroundColor: this.style.getComputedBackgroundColor().abgr,
|
|
8943
|
-
modulate: this._modulate.toArgb(this.globalOpacity, true),
|
|
8944
8965
|
colorMatrix: colorMatrix.toMatrix4().toArray(true),
|
|
8945
|
-
colorMatrixOffset: colorMatrix.toVector4().toArray()
|
|
8946
|
-
blendMode: this.blendMode
|
|
8966
|
+
colorMatrixOffset: colorMatrix.toVector4().toArray()
|
|
8947
8967
|
};
|
|
8948
8968
|
});
|
|
8949
8969
|
}
|
|
@@ -13038,6 +13058,7 @@ class Engine extends SceneTree {
|
|
|
13038
13058
|
}) : void 0;
|
|
13039
13059
|
constructor(options = {}) {
|
|
13040
13060
|
const {
|
|
13061
|
+
debug = false,
|
|
13041
13062
|
view,
|
|
13042
13063
|
width,
|
|
13043
13064
|
height,
|
|
@@ -13049,6 +13070,7 @@ class Engine extends SceneTree {
|
|
|
13049
13070
|
...glOptions
|
|
13050
13071
|
} = options;
|
|
13051
13072
|
super(timeline);
|
|
13073
|
+
this.debug = debug;
|
|
13052
13074
|
this.renderer = new WebGLRenderer(view, {
|
|
13053
13075
|
...defaultOptions,
|
|
13054
13076
|
...glOptions
|
|
@@ -13136,25 +13158,25 @@ class Engine extends SceneTree {
|
|
|
13136
13158
|
}
|
|
13137
13159
|
toCanvas2D() {
|
|
13138
13160
|
const imageData = this.toImageData();
|
|
13139
|
-
const
|
|
13140
|
-
|
|
13141
|
-
|
|
13142
|
-
|
|
13143
|
-
const
|
|
13144
|
-
|
|
13145
|
-
|
|
13146
|
-
|
|
13147
|
-
|
|
13161
|
+
const canvas1 = document.createElement("canvas");
|
|
13162
|
+
canvas1.width = imageData.width;
|
|
13163
|
+
canvas1.height = imageData.height;
|
|
13164
|
+
canvas1.getContext("2d")?.putImageData(imageData, 0, 0);
|
|
13165
|
+
const canvas2 = document.createElement("canvas");
|
|
13166
|
+
canvas2.width = this.width;
|
|
13167
|
+
canvas2.height = this.height;
|
|
13168
|
+
canvas2.getContext("2d")?.drawImage(
|
|
13169
|
+
canvas1,
|
|
13148
13170
|
0,
|
|
13149
13171
|
0,
|
|
13150
|
-
|
|
13151
|
-
|
|
13172
|
+
canvas1.width,
|
|
13173
|
+
canvas1.height,
|
|
13152
13174
|
0,
|
|
13153
13175
|
0,
|
|
13154
|
-
|
|
13155
|
-
|
|
13176
|
+
canvas2.width,
|
|
13177
|
+
canvas2.height
|
|
13156
13178
|
);
|
|
13157
|
-
return
|
|
13179
|
+
return canvas2;
|
|
13158
13180
|
}
|
|
13159
13181
|
}
|
|
13160
13182
|
|
|
@@ -13189,6 +13211,7 @@ async function performRender(options) {
|
|
|
13189
13211
|
}
|
|
13190
13212
|
});
|
|
13191
13213
|
await engine.waitUntilLoad();
|
|
13214
|
+
await options.onBeforeRender?.(engine);
|
|
13192
13215
|
return engine.toCanvas2D();
|
|
13193
13216
|
}
|
|
13194
13217
|
async function render(options) {
|