modern-canvas 0.4.8 → 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 +35 -25
- package/dist/index.d.cts +9 -6
- package/dist/index.d.mts +9 -6
- package/dist/index.d.ts +9 -6
- package/dist/index.js +29 -29
- package/dist/index.mjs +35 -25
- 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":
|
|
@@ -8346,15 +8344,16 @@ class SceneTree extends MainLoop {
|
|
|
8346
8344
|
console.log(`[modern-canvas]`, ...args);
|
|
8347
8345
|
}
|
|
8348
8346
|
}
|
|
8349
|
-
|
|
8347
|
+
_process(delta = 0) {
|
|
8350
8348
|
this.timeline.addTime(delta);
|
|
8351
8349
|
this.emit("processing");
|
|
8352
8350
|
this.root.emit("process", delta);
|
|
8353
8351
|
this.emit("processed");
|
|
8352
|
+
}
|
|
8353
|
+
_render(renderer) {
|
|
8354
8354
|
renderer.program.uniforms.projectionMatrix = this.root.toProjectionArray(true);
|
|
8355
8355
|
this.renderStack.render(renderer);
|
|
8356
8356
|
this._renderScreen(renderer);
|
|
8357
|
-
return this;
|
|
8358
8357
|
}
|
|
8359
8358
|
_renderScreen(renderer) {
|
|
8360
8359
|
renderer.state.reset();
|
|
@@ -8387,7 +8386,7 @@ class SceneTree extends MainLoop {
|
|
|
8387
8386
|
}
|
|
8388
8387
|
__decorateClass$r([
|
|
8389
8388
|
property({ default: false })
|
|
8390
|
-
], SceneTree.prototype, "
|
|
8389
|
+
], SceneTree.prototype, "processPaused");
|
|
8391
8390
|
__decorateClass$r([
|
|
8392
8391
|
property()
|
|
8393
8392
|
], SceneTree.prototype, "backgroundColor");
|
|
@@ -13185,13 +13184,20 @@ class Engine extends SceneTree {
|
|
|
13185
13184
|
await assets.waitUntilLoad();
|
|
13186
13185
|
await this.nextTick();
|
|
13187
13186
|
}
|
|
13187
|
+
async waitAndRender(delta = 0) {
|
|
13188
|
+
this._process(delta);
|
|
13189
|
+
await this.waitUntilLoad();
|
|
13190
|
+
this._render(this.renderer);
|
|
13191
|
+
}
|
|
13188
13192
|
render(delta = 0) {
|
|
13189
|
-
|
|
13193
|
+
this._process(delta);
|
|
13194
|
+
this._render(this.renderer);
|
|
13190
13195
|
}
|
|
13191
|
-
start() {
|
|
13192
|
-
this.
|
|
13193
|
-
|
|
13194
|
-
this.
|
|
13196
|
+
async start() {
|
|
13197
|
+
await this.waitAndRender();
|
|
13198
|
+
super.start((delta) => {
|
|
13199
|
+
this._process(delta);
|
|
13200
|
+
this._render(this.renderer);
|
|
13195
13201
|
});
|
|
13196
13202
|
}
|
|
13197
13203
|
free() {
|
|
@@ -13200,7 +13206,6 @@ class Engine extends SceneTree {
|
|
|
13200
13206
|
this.renderer.free();
|
|
13201
13207
|
}
|
|
13202
13208
|
toPixels() {
|
|
13203
|
-
this.render();
|
|
13204
13209
|
return this.renderer.toPixels();
|
|
13205
13210
|
}
|
|
13206
13211
|
toImageData() {
|
|
@@ -13231,10 +13236,14 @@ class Engine extends SceneTree {
|
|
|
13231
13236
|
}
|
|
13232
13237
|
|
|
13233
13238
|
let engine;
|
|
13234
|
-
let renderLoop;
|
|
13235
13239
|
const queue = [];
|
|
13236
|
-
|
|
13237
|
-
|
|
13240
|
+
let starting = false;
|
|
13241
|
+
async function start(sleep = 100) {
|
|
13242
|
+
if (starting) {
|
|
13243
|
+
return;
|
|
13244
|
+
}
|
|
13245
|
+
starting = true;
|
|
13246
|
+
while (queue.length) {
|
|
13238
13247
|
const cb = queue.shift();
|
|
13239
13248
|
if (cb) {
|
|
13240
13249
|
try {
|
|
@@ -13246,28 +13255,29 @@ async function startRenderLoop(sleep = 100) {
|
|
|
13246
13255
|
await new Promise((r) => setTimeout(r, sleep));
|
|
13247
13256
|
}
|
|
13248
13257
|
}
|
|
13258
|
+
starting = false;
|
|
13249
13259
|
}
|
|
13250
|
-
async function
|
|
13260
|
+
async function task(options) {
|
|
13261
|
+
const { data, width, height, time = 0 } = options;
|
|
13251
13262
|
engine ??= new Engine({ width: 1, height: 1 });
|
|
13252
|
-
|
|
13253
|
-
|
|
13254
|
-
const { data, width, height } = options;
|
|
13263
|
+
engine.root.removeChildren();
|
|
13264
|
+
engine.timeline.currentTime = time;
|
|
13255
13265
|
engine.resize(width, height);
|
|
13256
13266
|
(Array.isArray(data) ? data : [data]).forEach((v) => {
|
|
13257
13267
|
if (v instanceof Node) {
|
|
13258
|
-
root.appendChild(v);
|
|
13268
|
+
engine.root.appendChild(v);
|
|
13259
13269
|
} else {
|
|
13260
|
-
root.appendChild(Node.parse(v));
|
|
13270
|
+
engine.root.appendChild(Node.parse(v));
|
|
13261
13271
|
}
|
|
13262
13272
|
});
|
|
13263
|
-
await engine.waitUntilLoad();
|
|
13264
13273
|
await options.onBeforeRender?.(engine);
|
|
13274
|
+
await engine.waitAndRender();
|
|
13265
13275
|
return engine.toCanvas2D();
|
|
13266
13276
|
}
|
|
13267
13277
|
async function render(options) {
|
|
13268
|
-
renderLoop ??= startRenderLoop();
|
|
13269
13278
|
return new Promise((r) => {
|
|
13270
|
-
queue.push(async () => r(await
|
|
13279
|
+
queue.push(async () => r(await task(options)));
|
|
13280
|
+
start();
|
|
13271
13281
|
});
|
|
13272
13282
|
}
|
|
13273
13283
|
|