liquid-gl 2.0.1 → 2.0.2

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.
Files changed (3) hide show
  1. package/README.md +24 -21
  2. package/liquidGL.js +18 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -2,13 +2,13 @@
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.0.1**
5
+ **v2.0.2**
6
6
 
7
7
  > [!NOTE]
8
8
  > `liquidGL` is free to use for both non-commercial and commercial purposes. _BETA_ has now ended and the library is now ready for production use.
9
9
 
10
10
  > [!WARNING]
11
- > **v2.0.1 changes 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.
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 |
14
14
  > | :------------ | :------ | :------ | :------- | :----------------- |
@@ -19,7 +19,7 @@
19
19
  >
20
20
  > **v2.0.0 changed tilt behaviour.** The tilt interaction now eases symmetrically over the new `tiltEase` option (default `400`ms) in both directions, replacing the previous hard-coded `0.12s` ease-in and `0.4s` ease-out. If you depended on the old timing, set `tiltEase` explicitly. All other defaults are unchanged and existing configurations render identically.
21
21
 
22
- `liquidGL` turns any fixed-position element into a perfectly refracted, glossy "glass pane" rendered in WebGL.
22
+ `liquidGL` turns any fixed or sticky-positioned element into a perfectly refracted, glossy "glass pane" rendered in WebGL.
23
23
 
24
24
  <a href="https://liquidgl.naughtyduk.com" target="_blank" rel="noopener noreferrer"><img src="https://raw.githubusercontent.com/naughtyduk/liquidGL/main/assets/try-it-out-npm.png" alt="Try It Out" width="120"></a>
25
25
 
@@ -27,28 +27,32 @@
27
27
 
28
28
  ---
29
29
 
30
- ## What's new in v2.0.1
30
+ ## What's New
31
31
 
32
- **Changes**
32
+ **Features**
33
33
 
34
- - **Built-in DOM snapshotter** — the `html2canvas` dependency has been replaced with an integrated rasteriser. The package now installs with no runtime dependencies.
34
+ - **Sticky positioning support** — `position: sticky` elements can now be glassified. Sticky lenses are measured every animation frame, so the glass pane tracks the element through its flowing and stuck phases, then releases with it at the end of its containing block — inside nested scroll containers as well as the main document.
35
35
 
36
- ---
37
-
38
- ## What's new in v2.0.0
39
-
40
- **New features**
36
+ - **Built-in DOM snapshotter** — the `html2canvas` dependency has been replaced with an integrated rasteriser. Capture no longer depends on a third-party library.
41
37
 
42
38
  - **Chromatic aberration** — the new `aberration` option disperses the red and blue channels either side of the refraction vector, blue displaced further than red, matching the way real glass disperses shorter wavelengths more strongly. Dispersion scales with the refraction offset, so it concentrates at the bevelled edge and vanishes at the flat centre. Defaults to `0` (off).
39
+
43
40
  - **Configurable tilt easing** — the new `tiltEase` option sets the settle duration, in milliseconds, of the tilt on both hover-in and hover-out.
44
41
 
42
+ ---
43
+
45
44
  **Bug fixes**
46
45
 
47
46
  - **Refraction drift caused by ignored elements** — elements marked `data-liquid-ignore` were removed from the snapshot entirely, collapsing them out of layout and shifting every element below them. Ignored elements now retain their layout box, so the refraction stays aligned with the live page.
47
+
48
48
  - **Lens and content diverging during tilt** — the pane could separate from its content mid-tilt because the element was being measured while transformed. Metrics are now taken from the untilted box.
49
+
49
50
  - **Tilt snapping on hover** — the refraction jumped straight to its new angle on hover-in while easing on hover-out. Both directions now share a single curve and duration, and cursor movement during entry retargets the in-flight ease rather than snapping.
51
+
50
52
  - **Displacement while pinch-zoomed** — the pane drifted diagonally away from its element when the page was pinch-zoomed, because `visualViewport` offsets were applied twice. Offset compensation is now correctly gated.
51
53
 
54
+ ---
55
+
52
56
  **Performance**
53
57
 
54
58
  - Video frames are no longer re-composited or re-uploaded when neither the frame time nor the destination region has changed. Paused, ended and unmoved videos now cost nothing per frame.
@@ -242,16 +246,15 @@ Passing `gsap` lets `liquidGL` drive its render loop from the GSAP ticker and ke
242
246
 
243
247
  ## FAQ
244
248
 
245
- | Question | Answer |
246
- | :----------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
247
- | Is there a resize handler? | Yes resize is handled in the library and debounced to 250ms for performance. |
248
- | Does the effect work on mobile? | Yes the library handles all 3 versions of WebGL and provides a frosted CSS `backdrop-filter` as a backup for older devices. |
249
- | I have a preloader, how should I initialise `liquidGL()`? | Add the `data-liquid-ignore` attribute to your preloader's top-level container to exclude it from the snapshot. You can then call `liquidGL()` inside a `DOMContentLoaded` listener as you normally would. |
250
- | What is the correct way to use `liquidGL` with page animations? | Lets say you have a preloader, above the fold intro animations and scroll animations on your page. You would:<br><br>1) set the `data-liquid-ignore` attribute on your preloader<br>2) animate your preloader and set up your initial animation states<br>3) then call `liquidGL();`<br>4) optionally, in the `on.init();` callback, you can run post snapshot scripts, such as animating the `target` element |
251
- | Can I use `liquidGL` on multiple elements? | Yes, any element which has the class declared as your `target` will be glassified. Note **all elements must use the same `z-index`** due to shared canvas optimisations, if you use different `z-index` values for multiple targets, the highest value will be used by `liquidGL`. |
252
- | Will the library exceed WebGL contexts or have other performance issues? | No, the library uses a shared canvas for all instances, we have tested up to 30 elements on one page and we were not able to cause performance problems or crashes. |
253
- | Are there any animation limitations? | It depends on what you're trying to do, rotation and scale are expensive CPU/GPU processes, additionally `shadow` `specular` and `tilt` should be used with care when you have lots of instances or complex animations as they can clog the render pipeline. |
254
- | Why does `liquidGL` use its own snapshotter rather than `snapdom`? | We evaluated `snapdom` and chose not to adopt it. It is faster at capture in isolation, but it rasterises through `foreignObject`, which introduces correctness problems that matter for a full-page background snapshot: CSS `background-image` does not paint inside `foreignObject` on WebKit, Chromium clips the output beyond the first viewport on long pages, and only in-viewport content is rasterised, so off-screen dynamic elements need re-capturing. The built-in rasteriser paints directly to a canvas, so none of those limits apply, and it ships as part of the library rather than as an extra dependency. |
249
+ | Question | Answer |
250
+ | :----------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
251
+ | Is there a resize handler? | Yes resize is handled in the library and debounced to 250ms for performance. |
252
+ | Does the effect work on mobile? | Yes the library handles all 3 versions of WebGL and provides a frosted CSS `backdrop-filter` as a backup for older devices. |
253
+ | I have a preloader, how should I initialise `liquidGL()`? | Add the `data-liquid-ignore` attribute to your preloader's top-level container to exclude it from the snapshot. You can then call `liquidGL()` inside a `DOMContentLoaded` listener as you normally would. |
254
+ | What is the correct way to use `liquidGL` with page animations? | Lets say you have a preloader, above the fold intro animations and scroll animations on your page. You would:<br><br>1) set the `data-liquid-ignore` attribute on your preloader<br>2) animate your preloader and set up your initial animation states<br>3) then call `liquidGL();`<br>4) optionally, in the `on.init();` callback, you can run post snapshot scripts, such as animating the `target` element |
255
+ | Can I use `liquidGL` on multiple elements? | Yes, any element which has the class declared as your `target` will be glassified. Note **all elements must use the same `z-index`** due to shared canvas optimisations, if you use different `z-index` values for multiple targets, the highest value will be used by `liquidGL`. |
256
+ | Will the library exceed WebGL contexts or have other performance issues? | No, the library uses a shared canvas for all instances, we have tested up to 30 elements on one page and we were not able to cause performance problems or crashes. |
257
+ | Are there any animation limitations? | It depends on what you're trying to do, rotation and scale are expensive CPU/GPU processes, additionally `shadow` `specular` and `tilt` should be used with care when you have lots of instances or complex animations as they can clog the render pipeline. |
255
258
 
256
259
  ---
257
260
 
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.0.1
7
+ * Version: v2.0.2
8
8
  */
9
9
 
10
10
  const liquidGL = (() => {
@@ -2384,6 +2384,10 @@ const liquidGL = (() => {
2384
2384
  const gl = this.gl;
2385
2385
  if (!this.texture) return;
2386
2386
 
2387
+ this.lenses.forEach((ln) => {
2388
+ if (ln._isSticky && !ln._mirrorActive) ln.updateMetrics();
2389
+ });
2390
+
2387
2391
  if (this._isScrolling) {
2388
2392
  this._scrollUpdateCounter++;
2389
2393
  }
@@ -3401,6 +3405,8 @@ const liquidGL = (() => {
3401
3405
  ? "relative"
3402
3406
  : this.el.style.position;
3403
3407
 
3408
+ this._isSticky = /sticky/.test(window.getComputedStyle(this.el).position);
3409
+
3404
3410
  const bgCol = window.getComputedStyle(this.el).backgroundColor;
3405
3411
  const rgbaMatch = bgCol.match(/rgba?\(([^)]+)\)/);
3406
3412
  this._bgColorComponents = null;
@@ -3438,6 +3444,17 @@ const liquidGL = (() => {
3438
3444
  ? this._baseRect
3439
3445
  : this.el.getBoundingClientRect();
3440
3446
 
3447
+ const prev = this.rectPx;
3448
+ if (
3449
+ prev &&
3450
+ rect.left === prev.left &&
3451
+ rect.top === prev.top &&
3452
+ rect.width === prev.width &&
3453
+ rect.height === prev.height
3454
+ ) {
3455
+ return;
3456
+ }
3457
+
3441
3458
  this.rectPx = {
3442
3459
  left: rect.left,
3443
3460
  top: rect.top,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "liquid-gl",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "Ultra-light glassmorphism for the web.",
5
5
  "type": "module",
6
6
  "main": "./liquidGL.js",