modern-canvas 0.4.7 → 0.4.9
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 +86 -26
- package/dist/index.d.cts +19 -8
- package/dist/index.d.mts +19 -8
- package/dist/index.d.ts +19 -8
- package/dist/index.js +29 -29
- package/dist/index.mjs +86 -26
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2231,14 +2231,12 @@ class MainLoop extends CoreObject {
|
|
|
2231
2231
|
this.on("process", process);
|
|
2232
2232
|
Ticker.on(this._onNextTick, { sort: 0 });
|
|
2233
2233
|
}
|
|
2234
|
-
return this;
|
|
2235
2234
|
}
|
|
2236
2235
|
stop() {
|
|
2237
2236
|
if (this._starting) {
|
|
2238
2237
|
this._starting = false;
|
|
2239
2238
|
Ticker.off(this._onNextTick, { sort: 0 });
|
|
2240
2239
|
}
|
|
2241
|
-
return this;
|
|
2242
2240
|
}
|
|
2243
2241
|
_onNextTick() {
|
|
2244
2242
|
const elapsed = Ticker.elapsed * this.speed;
|
|
@@ -5767,9 +5765,9 @@ let Node = class extends CoreObject {
|
|
|
5767
5765
|
case "inherit":
|
|
5768
5766
|
return this._parent?.canProcess() ?? true;
|
|
5769
5767
|
case "pausable":
|
|
5770
|
-
return !this._tree.
|
|
5768
|
+
return !this._tree.processPaused;
|
|
5771
5769
|
case "when_paused":
|
|
5772
|
-
return this._tree.
|
|
5770
|
+
return this._tree.processPaused;
|
|
5773
5771
|
case "always":
|
|
5774
5772
|
return true;
|
|
5775
5773
|
case "disabled":
|
|
@@ -5892,6 +5890,17 @@ let Node = class extends CoreObject {
|
|
|
5892
5890
|
this._parent.moveChild(sibling, this.getIndex(true) + 1);
|
|
5893
5891
|
return this;
|
|
5894
5892
|
}
|
|
5893
|
+
prepend(...nodes) {
|
|
5894
|
+
let _nodes;
|
|
5895
|
+
if (Array.isArray(nodes[0])) {
|
|
5896
|
+
_nodes = nodes[0];
|
|
5897
|
+
} else {
|
|
5898
|
+
_nodes = nodes;
|
|
5899
|
+
}
|
|
5900
|
+
_nodes.forEach((node) => {
|
|
5901
|
+
this.moveChild(node, 0);
|
|
5902
|
+
});
|
|
5903
|
+
}
|
|
5895
5904
|
append(...nodes) {
|
|
5896
5905
|
let _nodes;
|
|
5897
5906
|
if (Array.isArray(nodes[0])) {
|
|
@@ -5903,6 +5912,35 @@ let Node = class extends CoreObject {
|
|
|
5903
5912
|
this.appendChild(node);
|
|
5904
5913
|
});
|
|
5905
5914
|
}
|
|
5915
|
+
before(...nodes) {
|
|
5916
|
+
let _nodes;
|
|
5917
|
+
if (Array.isArray(nodes[0])) {
|
|
5918
|
+
_nodes = nodes[0];
|
|
5919
|
+
} else {
|
|
5920
|
+
_nodes = nodes;
|
|
5921
|
+
}
|
|
5922
|
+
_nodes.forEach((node) => {
|
|
5923
|
+
this._parent?.moveChild(node, this.getIndex(true));
|
|
5924
|
+
});
|
|
5925
|
+
}
|
|
5926
|
+
after(...nodes) {
|
|
5927
|
+
let _nodes;
|
|
5928
|
+
if (Array.isArray(nodes[0])) {
|
|
5929
|
+
_nodes = nodes[0];
|
|
5930
|
+
} else {
|
|
5931
|
+
_nodes = nodes;
|
|
5932
|
+
}
|
|
5933
|
+
_nodes.forEach((node) => {
|
|
5934
|
+
this._parent?.moveChild(node, this.getIndex(true) + 1);
|
|
5935
|
+
});
|
|
5936
|
+
}
|
|
5937
|
+
insertBefore(node, child) {
|
|
5938
|
+
if (!child.hasParent() || !this.is(child.parent)) {
|
|
5939
|
+
return node;
|
|
5940
|
+
}
|
|
5941
|
+
this.moveChild(node, child.getIndex(true));
|
|
5942
|
+
return node;
|
|
5943
|
+
}
|
|
5906
5944
|
appendChild(node, internalMode = node.internalMode) {
|
|
5907
5945
|
if (this.is(node) || node.hasParent()) {
|
|
5908
5946
|
return node;
|
|
@@ -8101,6 +8139,16 @@ let CanvasItem = class extends TimelineNode {
|
|
|
8101
8139
|
};
|
|
8102
8140
|
});
|
|
8103
8141
|
}
|
|
8142
|
+
_process(delta) {
|
|
8143
|
+
super._process(delta);
|
|
8144
|
+
const parent = this.getParent();
|
|
8145
|
+
if (this._parentGlobalVisible !== parent?.globalVisible) {
|
|
8146
|
+
this.requestUpdate();
|
|
8147
|
+
}
|
|
8148
|
+
if (this._parentGlobalOpacity !== parent?.globalOpacity) {
|
|
8149
|
+
this.requestUpdate();
|
|
8150
|
+
}
|
|
8151
|
+
}
|
|
8104
8152
|
_update() {
|
|
8105
8153
|
const parent = this.getParent();
|
|
8106
8154
|
if (this._parentGlobalVisible !== parent?.globalVisible) {
|
|
@@ -8296,15 +8344,16 @@ class SceneTree extends MainLoop {
|
|
|
8296
8344
|
console.log(`[modern-canvas]`, ...args);
|
|
8297
8345
|
}
|
|
8298
8346
|
}
|
|
8299
|
-
|
|
8347
|
+
_process(delta = 0) {
|
|
8300
8348
|
this.timeline.addTime(delta);
|
|
8301
8349
|
this.emit("processing");
|
|
8302
8350
|
this.root.emit("process", delta);
|
|
8303
8351
|
this.emit("processed");
|
|
8352
|
+
}
|
|
8353
|
+
_render(renderer) {
|
|
8304
8354
|
renderer.program.uniforms.projectionMatrix = this.root.toProjectionArray(true);
|
|
8305
8355
|
this.renderStack.render(renderer);
|
|
8306
8356
|
this._renderScreen(renderer);
|
|
8307
|
-
return this;
|
|
8308
8357
|
}
|
|
8309
8358
|
_renderScreen(renderer) {
|
|
8310
8359
|
renderer.state.reset();
|
|
@@ -8337,7 +8386,7 @@ class SceneTree extends MainLoop {
|
|
|
8337
8386
|
}
|
|
8338
8387
|
__decorateClass$r([
|
|
8339
8388
|
property({ default: false })
|
|
8340
|
-
], SceneTree.prototype, "
|
|
8389
|
+
], SceneTree.prototype, "processPaused");
|
|
8341
8390
|
__decorateClass$r([
|
|
8342
8391
|
property()
|
|
8343
8392
|
], SceneTree.prototype, "backgroundColor");
|
|
@@ -8687,11 +8736,11 @@ let Node2D = class extends CanvasItem {
|
|
|
8687
8736
|
});
|
|
8688
8737
|
}
|
|
8689
8738
|
_process(delta) {
|
|
8739
|
+
super._process(delta);
|
|
8690
8740
|
const parent = this.getParent();
|
|
8691
8741
|
if (this._parentTransformDirtyId !== parent?.globalTransform?.dirtyId) {
|
|
8692
8742
|
this.requestRelayout();
|
|
8693
8743
|
}
|
|
8694
|
-
super._process(delta);
|
|
8695
8744
|
}
|
|
8696
8745
|
};
|
|
8697
8746
|
Node2D = __decorateClass$n([
|
|
@@ -13135,13 +13184,20 @@ class Engine extends SceneTree {
|
|
|
13135
13184
|
await assets.waitUntilLoad();
|
|
13136
13185
|
await this.nextTick();
|
|
13137
13186
|
}
|
|
13187
|
+
async waitAndRender(delta = 0) {
|
|
13188
|
+
this._process(delta);
|
|
13189
|
+
await this.waitUntilLoad();
|
|
13190
|
+
this._render(this.renderer);
|
|
13191
|
+
}
|
|
13138
13192
|
render(delta = 0) {
|
|
13139
|
-
|
|
13193
|
+
this._process(delta);
|
|
13194
|
+
this._render(this.renderer);
|
|
13140
13195
|
}
|
|
13141
|
-
start() {
|
|
13142
|
-
this.
|
|
13143
|
-
|
|
13144
|
-
this.
|
|
13196
|
+
async start() {
|
|
13197
|
+
await this.waitAndRender();
|
|
13198
|
+
super.start((delta) => {
|
|
13199
|
+
this._process(delta);
|
|
13200
|
+
this._render(this.renderer);
|
|
13145
13201
|
});
|
|
13146
13202
|
}
|
|
13147
13203
|
free() {
|
|
@@ -13150,7 +13206,6 @@ class Engine extends SceneTree {
|
|
|
13150
13206
|
this.renderer.free();
|
|
13151
13207
|
}
|
|
13152
13208
|
toPixels() {
|
|
13153
|
-
this.render();
|
|
13154
13209
|
return this.renderer.toPixels();
|
|
13155
13210
|
}
|
|
13156
13211
|
toImageData() {
|
|
@@ -13181,10 +13236,14 @@ class Engine extends SceneTree {
|
|
|
13181
13236
|
}
|
|
13182
13237
|
|
|
13183
13238
|
let engine;
|
|
13184
|
-
let renderLoop;
|
|
13185
13239
|
const queue = [];
|
|
13186
|
-
|
|
13187
|
-
|
|
13240
|
+
let starting = false;
|
|
13241
|
+
async function start(sleep = 100) {
|
|
13242
|
+
if (starting) {
|
|
13243
|
+
return;
|
|
13244
|
+
}
|
|
13245
|
+
starting = true;
|
|
13246
|
+
while (queue.length) {
|
|
13188
13247
|
const cb = queue.shift();
|
|
13189
13248
|
if (cb) {
|
|
13190
13249
|
try {
|
|
@@ -13196,28 +13255,29 @@ async function startRenderLoop(sleep = 100) {
|
|
|
13196
13255
|
await new Promise((r) => setTimeout(r, sleep));
|
|
13197
13256
|
}
|
|
13198
13257
|
}
|
|
13258
|
+
starting = false;
|
|
13199
13259
|
}
|
|
13200
|
-
async function
|
|
13260
|
+
async function task(options) {
|
|
13261
|
+
const { data, width, height, time = 0 } = options;
|
|
13201
13262
|
engine ??= new Engine({ width: 1, height: 1 });
|
|
13202
|
-
|
|
13203
|
-
|
|
13204
|
-
const { data, width, height } = options;
|
|
13263
|
+
engine.root.removeChildren();
|
|
13264
|
+
engine.timeline.currentTime = time;
|
|
13205
13265
|
engine.resize(width, height);
|
|
13206
13266
|
(Array.isArray(data) ? data : [data]).forEach((v) => {
|
|
13207
13267
|
if (v instanceof Node) {
|
|
13208
|
-
root.appendChild(v);
|
|
13268
|
+
engine.root.appendChild(v);
|
|
13209
13269
|
} else {
|
|
13210
|
-
root.appendChild(Node.parse(v));
|
|
13270
|
+
engine.root.appendChild(Node.parse(v));
|
|
13211
13271
|
}
|
|
13212
13272
|
});
|
|
13213
|
-
await engine.waitUntilLoad();
|
|
13214
13273
|
await options.onBeforeRender?.(engine);
|
|
13274
|
+
await engine.waitAndRender();
|
|
13215
13275
|
return engine.toCanvas2D();
|
|
13216
13276
|
}
|
|
13217
13277
|
async function render(options) {
|
|
13218
|
-
renderLoop ??= startRenderLoop();
|
|
13219
13278
|
return new Promise((r) => {
|
|
13220
|
-
queue.push(async () => r(await
|
|
13279
|
+
queue.push(async () => r(await task(options)));
|
|
13280
|
+
start();
|
|
13221
13281
|
});
|
|
13222
13282
|
}
|
|
13223
13283
|
|