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.cjs +49 -32
- package/dist/index.d.cts +6 -2
- package/dist/index.d.mts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +26 -26
- package/dist/index.mjs +49 -32
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -7256,7 +7256,7 @@ exports.GlitchEffect = class GlitchEffect extends exports.Effect {
|
|
|
7256
7256
|
_texture;
|
|
7257
7257
|
_sizes;
|
|
7258
7258
|
_offsets;
|
|
7259
|
-
|
|
7259
|
+
_needsRedraw = false;
|
|
7260
7260
|
slices = 10;
|
|
7261
7261
|
sampleSize = 512;
|
|
7262
7262
|
offset = 100;
|
|
@@ -7294,8 +7294,8 @@ exports.GlitchEffect = class GlitchEffect extends exports.Effect {
|
|
|
7294
7294
|
texture.requestUpload();
|
|
7295
7295
|
}
|
|
7296
7296
|
apply(renderer, source) {
|
|
7297
|
-
if (!this.
|
|
7298
|
-
this.
|
|
7297
|
+
if (!this._needsRedraw) {
|
|
7298
|
+
this._needsRedraw = true;
|
|
7299
7299
|
this.redraw();
|
|
7300
7300
|
}
|
|
7301
7301
|
const width = source.width;
|
|
@@ -8085,23 +8085,28 @@ exports.CanvasItem = class CanvasItem extends exports.TimelineNode {
|
|
|
8085
8085
|
this.requestRepaint();
|
|
8086
8086
|
}
|
|
8087
8087
|
}
|
|
8088
|
+
_draw() {
|
|
8089
|
+
this.emit("draw");
|
|
8090
|
+
}
|
|
8091
|
+
_redraw() {
|
|
8092
|
+
this._tree?.log(this.name, "redrawing");
|
|
8093
|
+
this._draw();
|
|
8094
|
+
return this.context.toBatchables();
|
|
8095
|
+
}
|
|
8088
8096
|
_relayout(batchables) {
|
|
8089
|
-
|
|
8097
|
+
this._tree?.log(this.name, "relayouting");
|
|
8098
|
+
return batchables;
|
|
8090
8099
|
}
|
|
8091
8100
|
_repaint(batchables) {
|
|
8101
|
+
this._tree?.log(this.name, "repainting");
|
|
8092
8102
|
return batchables.map((batchable) => {
|
|
8093
8103
|
return {
|
|
8094
8104
|
...batchable,
|
|
8095
8105
|
modulate: this._modulate.toArgb(this.globalOpacity, true),
|
|
8096
|
-
// backgroundColor: this.style.getComputedBackgroundColor().abgr,
|
|
8097
|
-
// colorMatrix: colorMatrix.toMatrix4().toArray(true),
|
|
8098
|
-
// colorMatrixOffset: colorMatrix.toVector4().toArray(),
|
|
8099
8106
|
blendMode: this.blendMode
|
|
8100
8107
|
};
|
|
8101
8108
|
});
|
|
8102
8109
|
}
|
|
8103
|
-
_draw() {
|
|
8104
|
-
}
|
|
8105
8110
|
_update() {
|
|
8106
8111
|
const parent = this.getParent();
|
|
8107
8112
|
if (this._parentGlobalVisible !== parent?.globalVisible) {
|
|
@@ -8110,20 +8115,25 @@ exports.CanvasItem = class CanvasItem extends exports.TimelineNode {
|
|
|
8110
8115
|
if (this._parentGlobalOpacity !== parent?.globalOpacity) {
|
|
8111
8116
|
this._updateGlobalOpacity();
|
|
8112
8117
|
}
|
|
8118
|
+
const redrawing = this._redrawing;
|
|
8119
|
+
let relayouting = this._relayouting;
|
|
8120
|
+
let repainting = this._repainting;
|
|
8113
8121
|
let batchables;
|
|
8114
|
-
if (
|
|
8115
|
-
this.
|
|
8116
|
-
|
|
8117
|
-
|
|
8118
|
-
|
|
8122
|
+
if (redrawing) {
|
|
8123
|
+
this._originalBatchables = this._redraw();
|
|
8124
|
+
relayouting = true;
|
|
8125
|
+
}
|
|
8126
|
+
if (relayouting) {
|
|
8127
|
+
this._layoutedBatchables = this._relayout(this._originalBatchables);
|
|
8128
|
+
repainting = true;
|
|
8129
|
+
}
|
|
8130
|
+
if (repainting) {
|
|
8131
|
+
batchables = this._repaint(this._layoutedBatchables);
|
|
8132
|
+
}
|
|
8133
|
+
if (redrawing) {
|
|
8119
8134
|
if (this._resetContext) {
|
|
8120
8135
|
this.context.reset();
|
|
8121
8136
|
}
|
|
8122
|
-
} else if (this._relayouting) {
|
|
8123
|
-
this._layoutedBatchables = this._relayout(this._originalBatchables);
|
|
8124
|
-
batchables = this._layoutedBatchables;
|
|
8125
|
-
} else if (this._repainting) {
|
|
8126
|
-
batchables = this._repaint(this._layoutedBatchables);
|
|
8127
8137
|
}
|
|
8128
8138
|
if (batchables) {
|
|
8129
8139
|
this._batchables = batchables;
|
|
@@ -8287,6 +8297,11 @@ class SceneTree extends MainLoop {
|
|
|
8287
8297
|
break;
|
|
8288
8298
|
}
|
|
8289
8299
|
}
|
|
8300
|
+
log(...args) {
|
|
8301
|
+
if (this.debug) {
|
|
8302
|
+
console.log(`[modern-canvas]`, ...args);
|
|
8303
|
+
}
|
|
8304
|
+
}
|
|
8290
8305
|
_render(renderer, delta = 0) {
|
|
8291
8306
|
this.timeline.addTime(delta);
|
|
8292
8307
|
this.emit("processing");
|
|
@@ -8332,6 +8347,9 @@ __decorateClass$r([
|
|
|
8332
8347
|
__decorateClass$r([
|
|
8333
8348
|
property()
|
|
8334
8349
|
], SceneTree.prototype, "backgroundColor");
|
|
8350
|
+
__decorateClass$r([
|
|
8351
|
+
protectedProperty({ default: false })
|
|
8352
|
+
], SceneTree.prototype, "debug");
|
|
8335
8353
|
|
|
8336
8354
|
var __getOwnPropDesc$p = Object.getOwnPropertyDescriptor;
|
|
8337
8355
|
var __decorateClass$q = (decorators, target, key, kind) => {
|
|
@@ -8667,18 +8685,16 @@ exports.Node2D = class Node2D extends exports.CanvasItem {
|
|
|
8667
8685
|
_relayout(batchables) {
|
|
8668
8686
|
this._updateTransform();
|
|
8669
8687
|
this._updateGlobalTransform();
|
|
8670
|
-
return super._relayout(
|
|
8671
|
-
|
|
8672
|
-
|
|
8673
|
-
|
|
8674
|
-
|
|
8675
|
-
|
|
8676
|
-
})
|
|
8677
|
-
);
|
|
8688
|
+
return super._relayout(batchables).map((batchable) => {
|
|
8689
|
+
return {
|
|
8690
|
+
...batchable,
|
|
8691
|
+
vertices: this._transformVertices(batchable.vertices)
|
|
8692
|
+
};
|
|
8693
|
+
});
|
|
8678
8694
|
}
|
|
8679
8695
|
_process(delta) {
|
|
8680
8696
|
const parent = this.getParent();
|
|
8681
|
-
if (parent?.
|
|
8697
|
+
if (this._parentTransformDirtyId !== parent?.globalTransform?.dirtyId) {
|
|
8682
8698
|
this.requestRelayout();
|
|
8683
8699
|
}
|
|
8684
8700
|
super._process(delta);
|
|
@@ -8892,6 +8908,7 @@ exports.BaseElement2D = class BaseElement2D extends exports.Node2D {
|
|
|
8892
8908
|
}
|
|
8893
8909
|
}
|
|
8894
8910
|
_draw() {
|
|
8911
|
+
super._draw();
|
|
8895
8912
|
this._drawBackground();
|
|
8896
8913
|
this._drawContent();
|
|
8897
8914
|
this._drawBorder();
|
|
@@ -8947,14 +8964,12 @@ exports.BaseElement2D = class BaseElement2D extends exports.Node2D {
|
|
|
8947
8964
|
}
|
|
8948
8965
|
_repaint(batchables) {
|
|
8949
8966
|
const colorMatrix = parseCSSFilter(this.style.filter);
|
|
8950
|
-
return batchables.map((batchable) => {
|
|
8967
|
+
return super._repaint(batchables).map((batchable) => {
|
|
8951
8968
|
return {
|
|
8952
8969
|
...batchable,
|
|
8953
8970
|
backgroundColor: this.style.getComputedBackgroundColor().abgr,
|
|
8954
|
-
modulate: this._modulate.toArgb(this.globalOpacity, true),
|
|
8955
8971
|
colorMatrix: colorMatrix.toMatrix4().toArray(true),
|
|
8956
|
-
colorMatrixOffset: colorMatrix.toVector4().toArray()
|
|
8957
|
-
blendMode: this.blendMode
|
|
8972
|
+
colorMatrixOffset: colorMatrix.toVector4().toArray()
|
|
8958
8973
|
};
|
|
8959
8974
|
});
|
|
8960
8975
|
}
|
|
@@ -13049,6 +13064,7 @@ class Engine extends SceneTree {
|
|
|
13049
13064
|
}) : void 0;
|
|
13050
13065
|
constructor(options = {}) {
|
|
13051
13066
|
const {
|
|
13067
|
+
debug = false,
|
|
13052
13068
|
view,
|
|
13053
13069
|
width,
|
|
13054
13070
|
height,
|
|
@@ -13060,6 +13076,7 @@ class Engine extends SceneTree {
|
|
|
13060
13076
|
...glOptions
|
|
13061
13077
|
} = options;
|
|
13062
13078
|
super(timeline);
|
|
13079
|
+
this.debug = debug;
|
|
13063
13080
|
this.renderer = new WebGLRenderer(view, {
|
|
13064
13081
|
...defaultOptions,
|
|
13065
13082
|
...glOptions
|
package/dist/index.d.cts
CHANGED
|
@@ -1571,6 +1571,7 @@ interface SceneTree {
|
|
|
1571
1571
|
declare class SceneTree extends MainLoop {
|
|
1572
1572
|
paused: boolean;
|
|
1573
1573
|
backgroundColor?: ColorValue;
|
|
1574
|
+
debug: boolean;
|
|
1574
1575
|
readonly input: Input;
|
|
1575
1576
|
readonly renderStack: RenderStack;
|
|
1576
1577
|
readonly root: Viewport;
|
|
@@ -1581,6 +1582,7 @@ declare class SceneTree extends MainLoop {
|
|
|
1581
1582
|
setCurrentViewport(viewport: Viewport | undefined): void;
|
|
1582
1583
|
constructor(timeline?: Timeline);
|
|
1583
1584
|
protected _updateProperty(key: PropertyKey, value: any, oldValue: any, declaration?: PropertyDeclaration): void;
|
|
1585
|
+
log(...args: any[]): void;
|
|
1584
1586
|
protected _render(renderer: WebGLRenderer, delta?: number): this;
|
|
1585
1587
|
protected _renderScreen(renderer: WebGLRenderer): void;
|
|
1586
1588
|
free(): void;
|
|
@@ -1787,9 +1789,10 @@ declare class CanvasItem extends TimelineNode {
|
|
|
1787
1789
|
requestRepaint(): void;
|
|
1788
1790
|
protected _updateGlobalVisible(): void;
|
|
1789
1791
|
protected _updateGlobalOpacity(): void;
|
|
1792
|
+
protected _draw(): void;
|
|
1793
|
+
protected _redraw(): CanvasBatchable[];
|
|
1790
1794
|
protected _relayout(batchables: CanvasBatchable[]): CanvasBatchable[];
|
|
1791
1795
|
protected _repaint(batchables: CanvasBatchable[]): CanvasBatchable[];
|
|
1792
|
-
protected _draw(): void;
|
|
1793
1796
|
protected _update(): void;
|
|
1794
1797
|
protected _render(renderer: WebGLRenderer): void;
|
|
1795
1798
|
}
|
|
@@ -2662,7 +2665,7 @@ declare class GlitchEffect extends Effect {
|
|
|
2662
2665
|
protected _texture: Texture2D;
|
|
2663
2666
|
protected _sizes: Float32Array;
|
|
2664
2667
|
protected _offsets: Float32Array;
|
|
2665
|
-
protected
|
|
2668
|
+
protected _needsRedraw: boolean;
|
|
2666
2669
|
slices: number;
|
|
2667
2670
|
sampleSize: number;
|
|
2668
2671
|
offset: number;
|
|
@@ -2979,6 +2982,7 @@ declare class CanvasItemEditor extends Control {
|
|
|
2979
2982
|
}
|
|
2980
2983
|
|
|
2981
2984
|
interface EngineOptions extends WebGLContextAttributes {
|
|
2985
|
+
debug?: boolean;
|
|
2982
2986
|
view?: HTMLCanvasElement | WebGLRenderingContext | WebGL2RenderingContext;
|
|
2983
2987
|
width?: number;
|
|
2984
2988
|
height?: number;
|
package/dist/index.d.mts
CHANGED
|
@@ -1571,6 +1571,7 @@ interface SceneTree {
|
|
|
1571
1571
|
declare class SceneTree extends MainLoop {
|
|
1572
1572
|
paused: boolean;
|
|
1573
1573
|
backgroundColor?: ColorValue;
|
|
1574
|
+
debug: boolean;
|
|
1574
1575
|
readonly input: Input;
|
|
1575
1576
|
readonly renderStack: RenderStack;
|
|
1576
1577
|
readonly root: Viewport;
|
|
@@ -1581,6 +1582,7 @@ declare class SceneTree extends MainLoop {
|
|
|
1581
1582
|
setCurrentViewport(viewport: Viewport | undefined): void;
|
|
1582
1583
|
constructor(timeline?: Timeline);
|
|
1583
1584
|
protected _updateProperty(key: PropertyKey, value: any, oldValue: any, declaration?: PropertyDeclaration): void;
|
|
1585
|
+
log(...args: any[]): void;
|
|
1584
1586
|
protected _render(renderer: WebGLRenderer, delta?: number): this;
|
|
1585
1587
|
protected _renderScreen(renderer: WebGLRenderer): void;
|
|
1586
1588
|
free(): void;
|
|
@@ -1787,9 +1789,10 @@ declare class CanvasItem extends TimelineNode {
|
|
|
1787
1789
|
requestRepaint(): void;
|
|
1788
1790
|
protected _updateGlobalVisible(): void;
|
|
1789
1791
|
protected _updateGlobalOpacity(): void;
|
|
1792
|
+
protected _draw(): void;
|
|
1793
|
+
protected _redraw(): CanvasBatchable[];
|
|
1790
1794
|
protected _relayout(batchables: CanvasBatchable[]): CanvasBatchable[];
|
|
1791
1795
|
protected _repaint(batchables: CanvasBatchable[]): CanvasBatchable[];
|
|
1792
|
-
protected _draw(): void;
|
|
1793
1796
|
protected _update(): void;
|
|
1794
1797
|
protected _render(renderer: WebGLRenderer): void;
|
|
1795
1798
|
}
|
|
@@ -2662,7 +2665,7 @@ declare class GlitchEffect extends Effect {
|
|
|
2662
2665
|
protected _texture: Texture2D;
|
|
2663
2666
|
protected _sizes: Float32Array;
|
|
2664
2667
|
protected _offsets: Float32Array;
|
|
2665
|
-
protected
|
|
2668
|
+
protected _needsRedraw: boolean;
|
|
2666
2669
|
slices: number;
|
|
2667
2670
|
sampleSize: number;
|
|
2668
2671
|
offset: number;
|
|
@@ -2979,6 +2982,7 @@ declare class CanvasItemEditor extends Control {
|
|
|
2979
2982
|
}
|
|
2980
2983
|
|
|
2981
2984
|
interface EngineOptions extends WebGLContextAttributes {
|
|
2985
|
+
debug?: boolean;
|
|
2982
2986
|
view?: HTMLCanvasElement | WebGLRenderingContext | WebGL2RenderingContext;
|
|
2983
2987
|
width?: number;
|
|
2984
2988
|
height?: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -1571,6 +1571,7 @@ interface SceneTree {
|
|
|
1571
1571
|
declare class SceneTree extends MainLoop {
|
|
1572
1572
|
paused: boolean;
|
|
1573
1573
|
backgroundColor?: ColorValue;
|
|
1574
|
+
debug: boolean;
|
|
1574
1575
|
readonly input: Input;
|
|
1575
1576
|
readonly renderStack: RenderStack;
|
|
1576
1577
|
readonly root: Viewport;
|
|
@@ -1581,6 +1582,7 @@ declare class SceneTree extends MainLoop {
|
|
|
1581
1582
|
setCurrentViewport(viewport: Viewport | undefined): void;
|
|
1582
1583
|
constructor(timeline?: Timeline);
|
|
1583
1584
|
protected _updateProperty(key: PropertyKey, value: any, oldValue: any, declaration?: PropertyDeclaration): void;
|
|
1585
|
+
log(...args: any[]): void;
|
|
1584
1586
|
protected _render(renderer: WebGLRenderer, delta?: number): this;
|
|
1585
1587
|
protected _renderScreen(renderer: WebGLRenderer): void;
|
|
1586
1588
|
free(): void;
|
|
@@ -1787,9 +1789,10 @@ declare class CanvasItem extends TimelineNode {
|
|
|
1787
1789
|
requestRepaint(): void;
|
|
1788
1790
|
protected _updateGlobalVisible(): void;
|
|
1789
1791
|
protected _updateGlobalOpacity(): void;
|
|
1792
|
+
protected _draw(): void;
|
|
1793
|
+
protected _redraw(): CanvasBatchable[];
|
|
1790
1794
|
protected _relayout(batchables: CanvasBatchable[]): CanvasBatchable[];
|
|
1791
1795
|
protected _repaint(batchables: CanvasBatchable[]): CanvasBatchable[];
|
|
1792
|
-
protected _draw(): void;
|
|
1793
1796
|
protected _update(): void;
|
|
1794
1797
|
protected _render(renderer: WebGLRenderer): void;
|
|
1795
1798
|
}
|
|
@@ -2662,7 +2665,7 @@ declare class GlitchEffect extends Effect {
|
|
|
2662
2665
|
protected _texture: Texture2D;
|
|
2663
2666
|
protected _sizes: Float32Array;
|
|
2664
2667
|
protected _offsets: Float32Array;
|
|
2665
|
-
protected
|
|
2668
|
+
protected _needsRedraw: boolean;
|
|
2666
2669
|
slices: number;
|
|
2667
2670
|
sampleSize: number;
|
|
2668
2671
|
offset: number;
|
|
@@ -2979,6 +2982,7 @@ declare class CanvasItemEditor extends Control {
|
|
|
2979
2982
|
}
|
|
2980
2983
|
|
|
2981
2984
|
interface EngineOptions extends WebGLContextAttributes {
|
|
2985
|
+
debug?: boolean;
|
|
2982
2986
|
view?: HTMLCanvasElement | WebGLRenderingContext | WebGL2RenderingContext;
|
|
2983
2987
|
width?: number;
|
|
2984
2988
|
height?: number;
|