shaders 2.5.118 → 2.5.119

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.
@@ -769,6 +769,10 @@ function shaderRenderer() {
769
769
  let pendingNodeRemoval = false;
770
770
  let globalEventUnregister = null;
771
771
  let unloadHandler = null;
772
+ let windowResizeHandler = null;
773
+ let cachedMaxTextureDim = 8192;
774
+ let lastRequestedWidth = 0;
775
+ let lastRequestedHeight = 0;
772
776
  let enablePerformanceTracking = true;
773
777
  const performanceTracker = new PerformanceTracker();
774
778
  let pendingRegistrationQueue = [];
@@ -784,9 +788,22 @@ function shaderRenderer() {
784
788
  let previousTextures = /* @__PURE__ */ new Set();
785
789
  let pendingResize = null;
786
790
  let isResizeScheduled = false;
791
+ const clampToTextureCap = (w, h) => {
792
+ const pr = renderer?.getPixelRatio?.() ?? 1;
793
+ const gpuCssCap = Math.max(1, Math.floor(cachedMaxTextureDim / pr) - 1);
794
+ const capW = Math.min(w, window.innerWidth, gpuCssCap);
795
+ const capH = Math.min(h, window.innerHeight, gpuCssCap);
796
+ const scale = Math.min(capW / w, capH / h, 1);
797
+ return {
798
+ width: Math.max(1, Math.round(w * scale)),
799
+ height: Math.max(1, Math.round(h * scale))
800
+ };
801
+ };
787
802
  const updateRendererDimensions = (width, height) => {
788
803
  if (width <= 0 || height <= 0) return;
789
- if (width === currentWidth && height === currentHeight) return;
804
+ if (width === lastRequestedWidth && height === lastRequestedHeight) return;
805
+ lastRequestedWidth = width;
806
+ lastRequestedHeight = height;
790
807
  pendingResize = {
791
808
  width,
792
809
  height
@@ -796,8 +813,9 @@ function shaderRenderer() {
796
813
  requestAnimationFrame(() => {
797
814
  isResizeScheduled = false;
798
815
  if (!pendingResize) return;
799
- const { width: width$1, height: height$1 } = pendingResize;
816
+ const raw = pendingResize;
800
817
  pendingResize = null;
818
+ const { width: width$1, height: height$1 } = clampToTextureCap(raw.width, raw.height);
801
819
  currentWidth = width$1;
802
820
  currentHeight = height$1;
803
821
  if (!hasInitialDimensions) {
@@ -2099,6 +2117,16 @@ function shaderRenderer() {
2099
2117
  cleanup();
2100
2118
  };
2101
2119
  window.addEventListener("beforeunload", unloadHandler);
2120
+ windowResizeHandler = () => {
2121
+ if (lastRequestedWidth > 0 && lastRequestedHeight > 0) {
2122
+ const rawW = lastRequestedWidth;
2123
+ const rawH = lastRequestedHeight;
2124
+ lastRequestedWidth = 0;
2125
+ lastRequestedHeight = 0;
2126
+ updateRendererDimensions(rawW, rawH);
2127
+ }
2128
+ };
2129
+ window.addEventListener("resize", windowResizeHandler, { passive: true });
2102
2130
  if (localAbortController.signal.aborted) return;
2103
2131
  if (context) {
2104
2132
  console.log("[Shaders] Using provided WebGL context");
@@ -2166,16 +2194,19 @@ function shaderRenderer() {
2166
2194
  cachedCanvasRect = rect;
2167
2195
  isVisible = !shouldObserveElement || rect.width > 0 && rect.height > 0 && rect.top < window.innerHeight && rect.bottom > 0 && rect.left < window.innerWidth && rect.right > 0;
2168
2196
  shouldAnimate = true;
2169
- const width = rect.width > 0 ? rect.width : canvas.width;
2170
- const height = rect.height > 0 ? rect.height : canvas.height;
2171
- const roundedWidth = Math.round(width);
2172
- const roundedHeight = Math.round(height);
2173
- if (roundedWidth > 0 && roundedHeight > 0) {
2174
- currentWidth = roundedWidth;
2175
- currentHeight = roundedHeight;
2197
+ const rawWidth = rect.width > 0 ? rect.width : canvas.width;
2198
+ const rawHeight = rect.height > 0 ? rect.height : canvas.height;
2199
+ const roundedRawWidth = Math.round(rawWidth);
2200
+ const roundedRawHeight = Math.round(rawHeight);
2201
+ if (roundedRawWidth > 0 && roundedRawHeight > 0) {
2202
+ lastRequestedWidth = roundedRawWidth;
2203
+ lastRequestedHeight = roundedRawHeight;
2204
+ const { width: clampedWidth, height: clampedHeight } = clampToTextureCap(roundedRawWidth, roundedRawHeight);
2205
+ currentWidth = clampedWidth;
2206
+ currentHeight = clampedHeight;
2176
2207
  hasInitialDimensions = true;
2177
- renderer.setSize(roundedWidth, roundedHeight, false);
2178
- const aspectRatio = roundedWidth / roundedHeight;
2208
+ renderer.setSize(clampedWidth, clampedHeight, false);
2209
+ const aspectRatio = clampedWidth / clampedHeight;
2179
2210
  const frustumHeight = 2;
2180
2211
  const frustumWidth = frustumHeight * aspectRatio;
2181
2212
  camera.left = -frustumWidth / 2;
@@ -2188,6 +2219,22 @@ function shaderRenderer() {
2188
2219
  } else hasInitialDimensions = false;
2189
2220
  if (shouldAnimate) startAnimation();
2190
2221
  if (!localAbortController.signal.aborted) {
2222
+ try {
2223
+ if (renderer.backend?.isWebGPUBackend === true) {
2224
+ const lim = (renderer.backend?.device)?.limits?.maxTextureDimension2D;
2225
+ if (typeof lim === "number" && lim > 0) cachedMaxTextureDim = lim;
2226
+ } else {
2227
+ const lim = renderer.capabilities?.maxTextureSize;
2228
+ if (typeof lim === "number" && lim > 0) cachedMaxTextureDim = lim;
2229
+ }
2230
+ } catch {}
2231
+ if (lastRequestedWidth > 0 && lastRequestedHeight > 0) {
2232
+ const rawW = lastRequestedWidth;
2233
+ const rawH = lastRequestedHeight;
2234
+ lastRequestedWidth = 0;
2235
+ lastRequestedHeight = 0;
2236
+ updateRendererDimensions(rawW, rawH);
2237
+ }
2191
2238
  isInitialized = true;
2192
2239
  isRendererReady = true;
2193
2240
  processQueuedRegistrations();
@@ -2221,6 +2268,10 @@ function shaderRenderer() {
2221
2268
  window.removeEventListener("beforeunload", unloadHandler);
2222
2269
  unloadHandler = null;
2223
2270
  }
2271
+ if (windowResizeHandler) {
2272
+ window.removeEventListener("resize", windowResizeHandler);
2273
+ windowResizeHandler = null;
2274
+ }
2224
2275
  stopAnimation();
2225
2276
  disposePreviousTextures();
2226
2277
  currentTextures.forEach((texture$1) => {
@@ -1 +1 @@
1
- {"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,KAAK,IAAI,EAMT,cAAc,EACjB,MAAM,cAAc,CAAA;AACrB,OAAO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yBA7OE,OAAO,CAAC,IAAI,CAAC;+BAmMb,gBAAgB;;eAgnBmB,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC;;2BArBpE,QAAQ,GAAG,OAAO,GAAG,IAAI;;qCAwBhB,OAAO,KAAG,OAAO;2BAK3B,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI;;;mCA95EZ,MAAM,KAAG,QAAQ,EAAE;oCA+CzC,IAAI,YACF,QAAQ,UACV,MAAM,kBACE,GAAG,CAAC,MAAM,CAAC,gBACb,IAAI,KACnB,IAAI;0CA0VK,IAAI,YACF,QAAQ,KACnB,IAAI;;;;EA4hEV"}
@@ -48,7 +48,7 @@ async function createShader(canvas, preset, options) {
48
48
  if (isExternalUser()) {
49
49
  const checkRendering = () => {
50
50
  if (renderer.getPerformanceStats().fps > 0) {
51
- telemetryCollector = startTelemetry(renderer, "2.5.118", options?.disableTelemetry || false, false);
51
+ telemetryCollector = startTelemetry(renderer, "2.5.119", options?.disableTelemetry || false, false);
52
52
  if (telemetryCollector) telemetryCollector.start();
53
53
  telemetryStartTimeout = null;
54
54
  } else telemetryStartTimeout = setTimeout(checkRendering, 500);
@@ -89,7 +89,7 @@ const Shader = ({ children, disableTelemetry = false, colorSpace = "p3-linear",
89
89
  return;
90
90
  }
91
91
  if (rendererRef.current.getPerformanceStats().fps > 0) {
92
- telemetryCollectorRef.current = startTelemetry(rendererRef.current, "2.5.118", disableTelemetry, isPreview);
92
+ telemetryCollectorRef.current = startTelemetry(rendererRef.current, "2.5.119", disableTelemetry, isPreview);
93
93
  if (telemetryCollectorRef.current) telemetryCollectorRef.current.start();
94
94
  telemetryStartTimeoutRef.current = null;
95
95
  } else telemetryStartTimeoutRef.current = window.setTimeout(checkRendering, 500);