modern-canvas 0.24.9 → 0.24.11

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/Engine.d.ts CHANGED
@@ -71,13 +71,23 @@ export declare class Engine extends SceneTree {
71
71
  start(): Promise<void>;
72
72
  /**
73
73
  * Largest dimension (in device pixels) a single offscreen render pass can
74
- * allocate. The root scene renders into a RenderTarget texture (plus a
75
- * stencil renderbuffer when masks are used) sized to the canvas, so any
76
- * export larger than these GPU limits throws
77
- * `texImage2D: width or height out of range`. Oversized exports are tiled
78
- * within this budget instead.
74
+ * allocate. Capped by the GPU's MAX_TEXTURE_SIZE / MAX_RENDERBUFFER_SIZE /
75
+ * MAX_VIEWPORT_DIMS *and* crucially the actual WebGL drawing-buffer size,
76
+ * which the browser/GPU often clamps far below MAX_TEXTURE_SIZE (tied to
77
+ * screen size / VRAM, e.g. ~5760 on a laptop while MAX_TEXTURE_SIZE is 16384).
78
+ * The export reads pixels back from the drawing buffer, so anything beyond it
79
+ * is lost/garbled. Oversized exports are tiled within this budget instead.
79
80
  */
80
81
  protected _maxExportPassSize(): number;
82
+ protected _maxDrawingBufferCache: number;
83
+ /**
84
+ * Probe the real drawing-buffer cap on the *renderer's own* GL context (its
85
+ * attributes — preserveDrawingBuffer / stencil / antialias — lower the cap vs
86
+ * a bare context, so a throwaway probe overestimates). Temporarily sizes the
87
+ * canvas (default framebuffer only, not the FBO textures) to `cap` and reads
88
+ * `drawingBufferWidth/Height`, then restores. Cached per engine.
89
+ */
90
+ protected _maxDrawingBufferSize(cap: number): number;
81
91
  /** Tile budget in logical units (the GPU limit is in device pixels). */
82
92
  protected _exportTileLimit(): number;
83
93
  /** Resize the renderer + root viewport without triggering a render. */
package/dist/index.js CHANGED
@@ -9633,8 +9633,18 @@ var Ja = "WeakRef" in globalThis, Ya = class extends e {
9633
9633
  });
9634
9634
  }
9635
9635
  _maxExportPassSize() {
9636
- let e = this.gl, t = this.renderer.texture.maxTextureSize || e.getParameter(e.MAX_TEXTURE_SIZE) || 4096, n = e.getParameter(e.MAX_RENDERBUFFER_SIZE) || t, r = e.getParameter(e.MAX_VIEWPORT_DIMS), i = r && r.length >= 2 ? Math.min(r[0], r[1]) : t;
9637
- return Math.max(1, Math.min(t, n, i));
9636
+ let e = this.gl, t = this.renderer.texture.maxTextureSize || e.getParameter(e.MAX_TEXTURE_SIZE) || 4096, n = e.getParameter(e.MAX_RENDERBUFFER_SIZE) || t, r = e.getParameter(e.MAX_VIEWPORT_DIMS), i = r && r.length >= 2 ? Math.min(r[0], r[1]) : t, a = Math.max(1, Math.min(t, n, i));
9637
+ return this._maxDrawingBufferSize(a);
9638
+ }
9639
+ _maxDrawingBufferCache = 0;
9640
+ _maxDrawingBufferSize(e) {
9641
+ if (this._maxDrawingBufferCache) return this._maxDrawingBufferCache;
9642
+ let t = e;
9643
+ try {
9644
+ let n = this.gl, r = n.canvas, i = r.width, a = r.height;
9645
+ r.width = e, r.height = e, t = Math.min(n.drawingBufferWidth || e, n.drawingBufferHeight || e), r.width = i, r.height = a;
9646
+ } catch {}
9647
+ return this._maxDrawingBufferCache = Math.max(1, Math.min(e, t));
9638
9648
  }
9639
9649
  _exportTileLimit() {
9640
9650
  let e = this.pixelRatio || 1;
@@ -9712,7 +9722,7 @@ async function no(e = 100) {
9712
9722
  }
9713
9723
  }
9714
9724
  async function ro(e) {
9715
- let { debug: t = !1, fonts: n, width: r, height: i, data: a, keyframes: o = [], onBefore: s, onKeyframe: c, ...l } = e, u = Math.floor(r), d = Math.floor(i), f = to();
9725
+ let { debug: t = !1, fonts: n, width: r, height: i, data: a, keyframes: o = [], onBefore: s, onKeyframe: c, ...l } = e, u = Math.max(1, Math.floor(r)), d = Math.max(1, Math.floor(i)), f = to();
9716
9726
  if (f.resetProperties(), f.setProperties(l), f.debug = t, f.fonts = n, f.timeline.currentTime = 0, f.resizeForExport(u, d), f.root.removeChildren(!0), f.root.append(a), await s?.(f), await f.waitUntilProcessed(), o.length) {
9717
9727
  let e = o.length, t = o[e - 1];
9718
9728
  for (let n = 0; n < e; n++) {
@@ -9731,13 +9741,25 @@ async function ro(e) {
9731
9741
  };
9732
9742
  }
9733
9743
  async function io(e) {
9734
- return new Promise((t) => {
9735
- $a.push(async () => t(await ro(e).then((e) => e.toCanvas2D()))), no();
9744
+ return new Promise((t, n) => {
9745
+ $a.push(async () => {
9746
+ try {
9747
+ t(await ro(e).then((e) => e.toCanvas2D()));
9748
+ } catch (e) {
9749
+ n(e);
9750
+ }
9751
+ }), no();
9736
9752
  });
9737
9753
  }
9738
9754
  async function ao(e) {
9739
- return new Promise((t) => {
9740
- $a.push(async () => t(await ro(e).then((e) => e.pixels))), no();
9755
+ return new Promise((t, n) => {
9756
+ $a.push(async () => {
9757
+ try {
9758
+ t(await ro(e).then((e) => e.pixels));
9759
+ } catch (e) {
9760
+ n(e);
9761
+ }
9762
+ }), no();
9741
9763
  });
9742
9764
  }
9743
9765
  //#endregion
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-canvas",
3
3
  "type": "module",
4
- "version": "0.24.9",
4
+ "version": "0.24.11",
5
5
  "packageManager": "pnpm@10.19.0",
6
6
  "description": "A JavaScript WebGL rendering engine. only the ESM.",
7
7
  "author": "wxm",