@cazala/party 0.1.0 → 0.1.1

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.js CHANGED
@@ -3481,6 +3481,12 @@ class WebGPUEngine extends AbstractEngine {
3481
3481
  writable: true,
3482
3482
  value: null
3483
3483
  });
3484
+ Object.defineProperty(this, "didSwapchainWarmup", {
3485
+ enumerable: true,
3486
+ configurable: true,
3487
+ writable: true,
3488
+ value: false
3489
+ });
3484
3490
  Object.defineProperty(this, "animate", {
3485
3491
  enumerable: true,
3486
3492
  configurable: true,
@@ -3569,6 +3575,12 @@ class WebGPUEngine extends AbstractEngine {
3569
3575
  this.resources.canvas.width = size.width;
3570
3576
  this.resources.canvas.height = size.height;
3571
3577
  this.render.ensureTargets(this.resources, size.width, size.height);
3578
+ // Safari/WebKit workaround:
3579
+ // On WebKit's WebGPU implementation, the first present can stay blank until the canvas
3580
+ // experiences a "real" resize (even 1px). Apps have been working around this by
3581
+ // jiggling size once after starting. We do it here, once, after the final canvas size
3582
+ // is set and before the first present.
3583
+ await this.warmupSwapchainIfNeeded(size.width, size.height);
3572
3584
  // Configure grid storage + uniforms
3573
3585
  this.grid.configure(this.view.getSnapshot(), this.resources, program);
3574
3586
  // Seed module uniforms on GPU
@@ -3660,6 +3672,50 @@ class WebGPUEngine extends AbstractEngine {
3660
3672
  });
3661
3673
  });
3662
3674
  }
3675
+ isWebKitWebGPU() {
3676
+ // We specifically want WebKit's WebGPU, not Chromium/Blink.
3677
+ // - On iOS, *all* browsers use WebKit, so we treat them as WebKit.
3678
+ // - On macOS, Safari is WebKit; Chrome/Edge/Opera are not (even though their UA includes "AppleWebKit").
3679
+ try {
3680
+ if (typeof navigator === "undefined")
3681
+ return false;
3682
+ const ua = navigator.userAgent || "";
3683
+ const isIOS = /iPad|iPhone|iPod/.test(ua);
3684
+ if (isIOS)
3685
+ return true;
3686
+ const isAppleWebKit = /AppleWebKit\//.test(ua);
3687
+ const isSafari = /Safari\//.test(ua);
3688
+ const isChromiumLike = /(Chrome|Chromium|Edg|OPR)\//.test(ua);
3689
+ return isAppleWebKit && isSafari && !isChromiumLike;
3690
+ }
3691
+ catch {
3692
+ return false;
3693
+ }
3694
+ }
3695
+ async warmupSwapchainIfNeeded(width, height) {
3696
+ if (this.didSwapchainWarmup)
3697
+ return;
3698
+ if (!this.isWebKitWebGPU())
3699
+ return;
3700
+ if (height <= 1)
3701
+ return;
3702
+ this.didSwapchainWarmup = true;
3703
+ // 1px "resize" to force WebKit to fully bind the swapchain/currentTexture.
3704
+ // We wait a couple of animation frames to match real-world workarounds that proved reliable.
3705
+ try {
3706
+ this.resources.canvas.width = width;
3707
+ this.resources.canvas.height = height - 1;
3708
+ await this.waitForNextTick();
3709
+ this.resources.canvas.width = width;
3710
+ this.resources.canvas.height = height;
3711
+ await this.waitForNextTick();
3712
+ // Re-ensure targets (idempotent) in case any implementation ties resources to canvas size.
3713
+ this.render.ensureTargets(this.resources, width, height);
3714
+ }
3715
+ catch {
3716
+ // If anything goes wrong, fail open: rendering may still work on other browsers.
3717
+ }
3718
+ }
3663
3719
  // Override export to use module registry
3664
3720
  export() {
3665
3721
  const settings = {};