liquid-gl 2.2.2 → 2.2.4

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/README.md CHANGED
@@ -2,12 +2,12 @@
2
2
 
3
3
  <a href="https://liquidgl.naughtyduk.com"><img src="https://raw.githubusercontent.com/naughtyduk/liquidGL/main/assets/liquidGL-npm-preview.gif" alt="liquidGL" width="100%" height="auto"/></a>
4
4
 
5
- ### v2.2.2
5
+ ### v2.2.4
6
6
 
7
- > [!NOTE]
7
+ > **NOTE**
8
8
  > `liquidGL` is free to use for both non-commercial and commercial purposes.
9
9
 
10
- > [!WARNING]
10
+ > **WARNING**
11
11
  > **v2.0.1 changed snapshot capture.** `liquidGL` now snapshots the page with its own built-in rasteriser, so `html2canvas` is no longer a dependency. Nothing needs to change in your code.
12
12
  >
13
13
  > | Rasteriser | Median | Min | Max | Worst single stall |
@@ -29,6 +29,8 @@
29
29
 
30
30
  **Features**
31
31
 
32
+ - **2.2.4 - HD Glass on Mobile** — Snapshot capture is no longer hard capped by the device's screen resolution, and is instead capped by the GPU texture limit set by the browser, allowing for higher quality glass on mobile devices.
33
+
32
34
  - **2.2.0 - WebGPU rendering** — `liquidGL` now renders with WebGPU where available, with an automatic fallback chain of WebGPU → WebGL2 → WebGL1 → CSS `backdrop-filter`. Nothing to configure, the chain is fully automatic. Choose where the chain starts with the new `engine` option (`'auto'`, `'webgpu'`, `'webgl2'`, `'webgl'`), or test quickly via the URL parameter `?liquidGL-engine=webgl2`.
33
35
 
34
36
  - **2.2.0 - Helper GUI is now a separate file** — the dev GUI no longer ships in the main bundle. Import `liquid-gl/liquidGL-helper.js` in development to keep using `helper: true`. If the module is missing you'll get a console error and everything else works as normal.
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * Author: NaughtyDuk© – https://liquidgl.naughtyduk.com
6
6
  * Licence: MIT
7
- * Version: v2.2.2
7
+ * Version: v2.2.4
8
8
  */
9
9
 
10
10
  (() => {
@@ -127,8 +127,8 @@
127
127
 
128
128
  @media (max-width: 768px) {
129
129
  .lil-gui.root.liquidgl-helper {
130
- top: 1rem !important;
131
- right: 1rem !important;
130
+ top: 0.5rem !important;
131
+ right: 0.5rem !important;
132
132
  }
133
133
  }
134
134
  `;
@@ -149,6 +149,7 @@
149
149
  });
150
150
  gui.domElement.classList.add("liquidgl-helper");
151
151
  gui.$title.style.cursor = "default";
152
+ gui.close();
152
153
 
153
154
  const topOffset = 1 + instanceIndex * 3;
154
155
  gui.domElement.style.top = `${topOffset}rem`;
package/liquidGL.js CHANGED
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * Author: NaughtyDuk© – https://liquidgl.naughtyduk.com
6
6
  * Licence: MIT
7
- * Version: v2.2.2
7
+ * Version: v2.2.4
8
8
  */
9
9
 
10
10
  const liquidGL = (() => {
@@ -2822,7 +2822,7 @@ fn fs() -> @location(0) vec4<f32> {
2822
2822
 
2823
2823
  drawLens(lens, p) {
2824
2824
  const cx = Math.max(0, p.x);
2825
- const cy = Math.max(0, p.y);
2825
+ const cy = Math.max(0, this.canvas.height - p.y - p.h);
2826
2826
  const cw = Math.min(this.canvas.width - cx, p.w);
2827
2827
  const ch = Math.min(this.canvas.height - cy, p.h);
2828
2828
  if (cw <= 0 || ch <= 0) return;
@@ -2914,7 +2914,10 @@ fn fs() -> @location(0) vec4<f32> {
2914
2914
  pass.setVertexBuffer(0, this._vb);
2915
2915
  rects.forEach(({ x, y, w, h }) => {
2916
2916
  const cx = Math.max(0, Math.min(this.canvas.width, x));
2917
- const cy = Math.max(0, Math.min(this.canvas.height, y));
2917
+ const cy = Math.max(
2918
+ 0,
2919
+ Math.min(this.canvas.height, this.canvas.height - y - h),
2920
+ );
2918
2921
  const cw = Math.max(0, Math.min(this.canvas.width - cx, w));
2919
2922
  const ch = Math.max(0, Math.min(this.canvas.height - cy, h));
2920
2923
  if (cw > 0 && ch > 0) {
@@ -2958,6 +2961,7 @@ fn fs() -> @location(0) vec4<f32> {
2958
2961
  if (!this.snapshotTarget) this.snapshotTarget = document.body;
2959
2962
 
2960
2963
  this._isScrolling = false;
2964
+ this._pendingViewportResize = false;
2961
2965
  let lastScrollY = window.scrollY;
2962
2966
  let scrollTimeout;
2963
2967
  const scrollCheck = () => {
@@ -2967,6 +2971,10 @@ fn fs() -> @location(0) vec4<f32> {
2967
2971
  clearTimeout(scrollTimeout);
2968
2972
  scrollTimeout = setTimeout(() => {
2969
2973
  this._isScrolling = false;
2974
+ if (this._pendingViewportResize) {
2975
+ this._pendingViewportResize = false;
2976
+ onResize();
2977
+ }
2970
2978
  }, 200);
2971
2979
  }
2972
2980
  requestAnimationFrame(scrollCheck);
@@ -2974,7 +2982,12 @@ fn fs() -> @location(0) vec4<f32> {
2974
2982
  requestAnimationFrame(scrollCheck);
2975
2983
 
2976
2984
  const onResize = debounce(() => {
2977
- if (this._capturing || this._isScrolling) return;
2985
+ if (this._capturing) return;
2986
+ if (this._isScrolling) {
2987
+ this._pendingViewportResize = true;
2988
+ return;
2989
+ }
2990
+ this._pendingViewportResize = false;
2978
2991
 
2979
2992
  if (window.visualViewport && window.visualViewport.scale !== 1) {
2980
2993
  return;
@@ -3152,8 +3165,6 @@ fn fs() -> @location(0) vec4<f32> {
3152
3165
  const fullW = this.snapshotTarget.scrollWidth;
3153
3166
  const fullH = this.snapshotTarget.scrollHeight;
3154
3167
  const maxTex = (this.backend && this.backend.maxTextureSize) || 8192;
3155
- const MAX_MOBILE_DIM = 4096;
3156
- const isMobileSafari = /iPad|iPhone|iPod/.test(navigator.userAgent);
3157
3168
 
3158
3169
  let scale = Math.min(
3159
3170
  this._snapshotResolution,
@@ -3161,12 +3172,7 @@ fn fs() -> @location(0) vec4<f32> {
3161
3172
  maxTex / fullH,
3162
3173
  );
3163
3174
 
3164
- if (isMobileSafari) {
3165
- const over = (Math.max(fullW, fullH) * scale) / MAX_MOBILE_DIM;
3166
- if (over > 1) scale = scale / over;
3167
- }
3168
-
3169
- const maxArea = isMobileSafari ? 4096 * 4096 : 16384 * 16384;
3175
+ const maxArea = maxTex * maxTex;
3170
3176
  if (fullW * fullH * scale * scale > maxArea) {
3171
3177
  scale = Math.sqrt(maxArea / (fullW * fullH));
3172
3178
  console.warn(
@@ -3333,6 +3339,13 @@ fn fs() -> @location(0) vec4<f32> {
3333
3339
  const backend = this.backend;
3334
3340
  if (!backend || !this.hasTexture) return;
3335
3341
 
3342
+ const dprNow = Math.min(2, window.devicePixelRatio || 1);
3343
+ const bufW = Math.trunc(innerWidth * dprNow);
3344
+ const bufH = Math.trunc(innerHeight * dprNow);
3345
+ if (this.canvas.width !== bufW || this.canvas.height !== bufH) {
3346
+ this._resizeCanvas();
3347
+ }
3348
+
3336
3349
  this.lenses.forEach((ln) => {
3337
3350
  if (ln._isSticky && !ln._mirrorActive) ln.updateMetrics();
3338
3351
  });
@@ -4235,16 +4248,24 @@ fn fs() -> @location(0) vec4<f32> {
4235
4248
  ? this._baseRect
4236
4249
  : this.el.getBoundingClientRect();
4237
4250
 
4251
+ const vv = window.visualViewport;
4252
+ const vpX = vv && Math.abs(vv.scale - 1) < 0.01 ? vv.offsetLeft : 0;
4253
+ const vpY = vv && Math.abs(vv.scale - 1) < 0.01 ? vv.offsetTop : 0;
4254
+
4238
4255
  const prev = this.rectPx;
4239
4256
  if (
4240
4257
  prev &&
4241
4258
  rect.left === prev.left &&
4242
4259
  rect.top === prev.top &&
4243
4260
  rect.width === prev.width &&
4244
- rect.height === prev.height
4261
+ rect.height === prev.height &&
4262
+ vpX === this._vpOffsetX &&
4263
+ vpY === this._vpOffsetY
4245
4264
  ) {
4246
4265
  return;
4247
4266
  }
4267
+ this._vpOffsetX = vpX;
4268
+ this._vpOffsetY = vpY;
4248
4269
 
4249
4270
  this.rectPx = {
4250
4271
  left: rect.left,
@@ -4362,8 +4383,11 @@ fn fs() -> @location(0) vec4<f32> {
4362
4383
  this._mirrorActive && this._baseRect
4363
4384
  ? this._baseRect
4364
4385
  : this.el.getBoundingClientRect();
4365
- this._shadowEl.style.left = `${r.left}px`;
4366
- this._shadowEl.style.top = `${r.top}px`;
4386
+ const vv = window.visualViewport;
4387
+ const ox = vv && Math.abs(vv.scale - 1) < 0.01 ? vv.offsetLeft : 0;
4388
+ const oy = vv && Math.abs(vv.scale - 1) < 0.01 ? vv.offsetTop : 0;
4389
+ this._shadowEl.style.left = `${r.left + ox}px`;
4390
+ this._shadowEl.style.top = `${r.top + oy}px`;
4367
4391
  this._shadowEl.style.width = `${r.width}px`;
4368
4392
  this._shadowEl.style.height = `${r.height}px`;
4369
4393
  this._shadowEl.style.borderRadius = `${this.radiusCss}px`;
@@ -4380,7 +4404,7 @@ fn fs() -> @location(0) vec4<f32> {
4380
4404
  zIndex: effectiveZ(this.el) - 2,
4381
4405
  boxShadow: SHADOW_VAL,
4382
4406
  willChange: "transform, width, height",
4383
- opacity: this.revealTypeIndex === 1 ? 0 : 1,
4407
+ opacity: this._revealProgress ?? 1,
4384
4408
  });
4385
4409
  document.body.appendChild(this._shadowEl);
4386
4410
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "liquid-gl",
3
- "version": "2.2.2",
3
+ "version": "v2.2.4",
4
4
  "description": "Liquid Glass - Powered by WebGPU/WebGL.",
5
5
  "type": "module",
6
6
  "main": "./liquidGL.js",