liquid-gl 1.0.6 → 2.0.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.
Files changed (3) hide show
  1. package/README.md +135 -41
  2. package/liquidGL.js +2304 -183
  3. package/package.json +3 -13
package/README.md CHANGED
@@ -2,17 +2,60 @@
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
- **v1.0.6**
5
+ **v2.0.1**
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
+ > [!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.
12
+ >
13
+ > | Rasteriser | Median | Min | Max | Worst single stall |
14
+ > | :------------ | :------ | :------ | :------- | :----------------- |
15
+ > | NaughtyDOM | 55.5 ms | 54.1 ms | 57.5 ms | 37.8 ms |
16
+ > | `html2canvas` | 86.3 ms | 85.3 ms | 134.8 ms | 16.2 ms |
17
+ >
18
+ > Measured over 7 alternating runs of the full home page at `resolution: 2` (2880×10036 output), Chrome 150.
19
+ >
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
+
10
22
  `liquidGL` turns any fixed-position element into a perfectly refracted, glossy "glass pane" rendered in WebGL.
11
23
 
12
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>
13
25
 
14
26
  <a href="https://liquidgl.naughtyduk.com/demos/demo-1.html" target="_blank" rel="noopener noreferrer"><strong>DEMO 1</strong></a> | <a href="https://liquidgl.naughtyduk.com/demos/demo-2.html" target="_blank" rel="noopener noreferrer"><strong>DEMO 2</strong></a> | <a href="https://liquidgl.naughtyduk.com/demos/demo-3.html" target="_blank" rel="noopener noreferrer"><strong>DEMO 3</strong></a> | <a href="https://liquidgl.naughtyduk.com/demos/demo-4.html" target="_blank" rel="noopener noreferrer"><strong>DEMO 4</strong></a> | <a href="https://liquidgl.naughtyduk.com/demos/demo-5.html" target="_blank" rel="noopener noreferrer"><strong>DEMO 5</strong></a>
15
27
 
28
+ ---
29
+
30
+ ## What's new in v2.0.1
31
+
32
+ **Changes**
33
+
34
+ - **Built-in DOM snapshotter** — the `html2canvas` dependency has been replaced with an integrated rasteriser. The package now installs with no runtime dependencies.
35
+
36
+ ---
37
+
38
+ ## What's new in v2.0.0
39
+
40
+ **New features**
41
+
42
+ - **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).
43
+ - **Configurable tilt easing** — the new `tiltEase` option sets the settle duration, in milliseconds, of the tilt on both hover-in and hover-out.
44
+
45
+ **Bug fixes**
46
+
47
+ - **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.
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
+ - **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.
50
+ - **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
+
52
+ **Performance**
53
+
54
+ - 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.
55
+ - The snapshot bounding box is read once per frame and shared across every lens, instead of twice per lens per frame, removing repeated forced layout from the render loop.
56
+
57
+ ---
58
+
16
59
  ## Install from npm
17
60
 
18
61
  ```sh
@@ -28,7 +71,7 @@ const glassEffect = liquidGL({
28
71
  });
29
72
  ```
30
73
 
31
- > `html2canvas` is installed automatically as a package dependency. `three` is optional and only required when using `liquidGL` with 3D model workflows.
74
+ > `liquidGL` renders with raw WebGL and snapshots the page with its own built-in rasteriser, so it has no runtime dependencies.
32
75
 
33
76
  ---
34
77
 
@@ -38,17 +81,18 @@ const glassEffect = liquidGL({
38
81
 
39
82
  ### Key Features
40
83
 
41
- | Feature | Supported | Feature | Supported |
42
- | :------------------------------------- | :-------: | :----------------------- | :-------: |
43
- | Real-time Refraction (static content) | ✅ | Magnification Control | ✅ |
44
- | Real-time Refraction (video) | ✅ | Dynamic Element Support | ✅ |
45
- | Real-time Refraction (text animations) | ✅ | GSAP-Ready Animations | ✅ |
46
- | Real-time Refraction (CSS animations) | ❌ | Lightweight & Performant | ✅ |
47
- | Adjustable Bevel | ✅ | Seamless Scroll Sync | ✅ |
48
- | Frosted Glass Effect | ✅ | Auto-Resize Handling | ✅ |
49
- | Dynamic Shadows | ✅ | Auto Video Refraction | ✅ |
50
- | Specular Highlights | ✅ | Animate Lenses | ✅ |
51
- | Interactive Tilt Effect | ✅ | `on.init` Callback | ✅ |
84
+ | Feature | Supported | Feature | Supported |
85
+ | :------------------------------------- | :-------: | :------------------------------- | :-------: |
86
+ | Real-time Refraction (static content) | ✅ | Magnification Control | ✅ |
87
+ | Real-time Refraction (video) | ✅ | Dynamic Element Support | ✅ |
88
+ | Real-time Refraction (text animations) | ✅ | GSAP-Ready Animations | ✅ |
89
+ | Real-time Refraction (CSS animations) | ❌ | Lightweight & Performant | ✅ |
90
+ | Adjustable Bevel | ✅ | Seamless Scroll Sync | ✅ |
91
+ | Frosted Glass Effect | ✅ | Auto-Resize Handling | ✅ |
92
+ | Dynamic Shadows | ✅ | Auto Video Refraction | ✅ |
93
+ | Specular Highlights | ✅ | Animate Lenses | ✅ |
94
+ | Interactive Tilt Effect `[UPDATED]` | ✅ | `on.init` Callback | ✅ |
95
+ | Chromatic Aberration `[NEW]` | ✅ | Configurable Tilt Easing `[NEW]` | ✅ |
52
96
 
53
97
  ---
54
98
 
@@ -79,6 +123,7 @@ const glassEffect = liquidGL({
79
123
  target: ".liquidGL",
80
124
  resolution: 2.0,
81
125
  refraction: 0.01,
126
+ aberration: 0,
82
127
  bevelDepth: 0.08,
83
128
  bevelWidth: 0.15,
84
129
  frost: 0,
@@ -87,6 +132,7 @@ const glassEffect = liquidGL({
87
132
  reveal: "fade",
88
133
  tilt: false,
89
134
  tiltFactor: 5,
135
+ tiltEase: 400,
90
136
  magnify: 1,
91
137
  on: {
92
138
  init(instance) {
@@ -125,36 +171,58 @@ liquidGL.registerDynamic(mySplitText.lines);
125
171
 
126
172
  > Simply call `liquidGL.syncWith()` after initialising `liquidGL`.
127
173
 
174
+ When installed from npm, pass your libraries in directly. Imported modules are not attached to `window`, so the helper cannot auto-detect them the way it does with browser script tags.
175
+
128
176
  ```js
177
+ import liquidGL from "liquid-gl";
178
+ import Lenis from "lenis";
179
+ import gsap from "gsap";
180
+ import ScrollTrigger from "gsap/ScrollTrigger";
181
+
182
+ gsap.registerPlugin(ScrollTrigger);
183
+
129
184
  const glassEffect = liquidGL({
130
185
  target: ".liquidGL",
131
186
  });
132
187
 
133
- const { lenis, locomotiveScroll } = liquidGL.syncWith();
188
+ const lenis = new Lenis();
189
+
190
+ liquidGL.syncWith({ gsap, lenis });
134
191
  ```
135
192
 
136
- > Make sure to include the scroll library scripts before your main script. The `syncWith()` helper must be called **after** `liquidGL()` has been called.
193
+ Passing `gsap` lets `liquidGL` drive its render loop from the GSAP ticker and keep `ScrollTrigger` updating on scroll. `ScrollTrigger` is read from the `gsap` object once registered, or you can pass it explicitly as `ScrollTrigger`.
194
+
195
+ | Option | Type | Description |
196
+ | ------------------ | ------ | -------------------------------------------------------------------------------------- |
197
+ | `gsap` | object | The `gsap` module. Enables ticker-driven rendering and `ScrollTrigger` sync. |
198
+ | `ScrollTrigger` | object | Optional. Only needed if `ScrollTrigger` has not been registered on the `gsap` object. |
199
+ | `lenis` | object | An existing `Lenis` instance. |
200
+ | `locomotiveScroll` | object | An existing `LocomotiveScroll` instance. |
201
+
202
+ > `syncWith()` must be called **after** `liquidGL()`. Passing `gsap: false` opts out of the GSAP ticker and uses a `requestAnimationFrame` loop instead.
137
203
 
138
204
  ---
139
205
 
140
206
  ## Parameters
141
207
 
142
- | Option | Type | Default | Description |
143
- | ------------ | -------- | ------------- | ------------------------------------------------------------------------------------------------ |
144
- | `target` | string | `'.liquidGL'` | **Required.** CSS selector for the element(s) to glassify. |
145
- | `snapshot` | string | `'body'` | CSS selector for the element to snapshot. |
146
- | `resolution` | number | `2.0` | Resolution of the background snapshot (clamped 0.1–3.0). Higher is sharper but uses more memory. |
147
- | `refraction` | number | `0.01` | Base refraction offset applied across the pane (0–1). |
148
- | `bevelDepth` | number | `0.08` | Additional refraction on the edge to simulate depth (0–1). |
149
- | `bevelWidth` | number | `0.15` | Width of the bevel zone as a fraction of the shortest side (0–1). |
150
- | `frost` | number | `0` | Blur radius in pixels for a frosted look. `0` is clear. |
151
- | `shadow` | boolean | `true` | Toggles a subtle drop-shadow under the pane. |
152
- | `specular` | boolean | `true` | Enables animated specular highlights that move with time. |
153
- | `reveal` | string | `'fade'` | Reveal animation.<br>- `'none'`: Renders immediately.<br>- `'fade'`: Smoothly fades in. |
154
- | `tilt` | boolean | `false` | Enables 3D tilt interaction on cursor movement. |
155
- | `tiltFactor` | number | `5` | Depth of the tilt in degrees (0–25 recommended). |
156
- | `magnify` | number | `1` | Magnification factor of the lens (clamped 0.0013.0). `1` is no magnification. |
157
- | `on.init` | function | `—` | Callback that runs once the first render completes. Receives the lens instance. |
208
+ | Option | Type | Default | Description |
209
+ | ------------ | -------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
210
+ | `target` | string | `'.liquidGL'` | **Required.** CSS selector for the element(s) to glassify. |
211
+ | `snapshot` | string | `'body'` | CSS selector for the element to snapshot. |
212
+ | `resolution` | number | `2.0` | Resolution of the background snapshot (clamped 0.1–3.0). Higher is sharper but uses more memory. |
213
+ | `refraction` | number | `0.01` | Base refraction offset applied across the pane (0–1). |
214
+ | `aberration` | number | `0` | Chromatic aberration strength (0–1). Scales with the refraction offset, so dispersion is strongest at the bevel. `0` disables it and skips the extra texture samples. |
215
+ | `bevelDepth` | number | `0.08` | Additional refraction on the edge to simulate depth (0–1). |
216
+ | `bevelWidth` | number | `0.15` | Width of the bevel zone as a fraction of the shortest side (0–1). |
217
+ | `frost` | number | `0` | Blur radius in pixels for a frosted look. `0` is clear. |
218
+ | `shadow` | boolean | `true` | Toggles a subtle drop-shadow under the pane. |
219
+ | `specular` | boolean | `true` | Enables animated specular highlights that move with time. |
220
+ | `reveal` | string | `'fade'` | Reveal animation.<br>- `'none'`: Renders immediately.<br>- `'fade'`: Smoothly fades in. |
221
+ | `tilt` | boolean | `false` | Enables 3D tilt interaction on cursor movement. |
222
+ | `tiltFactor` | number | `5` | Depth of the tilt in degrees (0–25 recommended). |
223
+ | `tiltEase` | number | `400` | Duration in ms for the tilt to settle, applied symmetrically on hover-in and hover-out. `0` applies the tilt instantly. |
224
+ | `magnify` | number | `1` | Magnification factor of the lens (clamped 0.001–3.0). `1` is no magnification. |
225
+ | `on.init` | function | `—` | Callback that runs once the first render completes. Receives the lens instance. |
158
226
 
159
227
  > The `target` parameter is required; all others are optional.
160
228
 
@@ -174,22 +242,23 @@ const { lenis, locomotiveScroll } = liquidGL.syncWith();
174
242
 
175
243
  ## FAQ
176
244
 
177
- | Question | Answer |
178
- | :----------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
179
- | Is there a resize handler? | Yes resize is handled in the library and debounced to 250ms for performance. |
180
- | 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. |
181
- | 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. |
182
- | 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 |
183
- | 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`. |
184
- | 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. |
185
- | 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. |
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. |
186
255
 
187
256
  ---
188
257
 
189
258
  ## Important Notes
190
259
 
191
260
  - For dynamic content to be refracted in real-time, you must register the element(s) with `liquidGL.registerDynamic()`. It is crucial to set the initial state of your animations **before** calling `liquidGL()` to ensure they are captured correctly.
192
- - The library ignores `fixed` position elements, this is to prevent a known bug between html2canvas and mobile browsers from surfacing which can prevent the snapshot from running. This is a safety net that shouldn't interfere with your use of the library.
261
+ - The library ignores `fixed` position elements, this is to prevent a known snapshotting bug on mobile browsers from surfacing which can prevent the snapshot from running. This is a safety net that shouldn't interfere with your use of the library.
193
262
  - You can have multiple instances on one page **but they must share the same `z-index` value**. If you specify different `z-index` values, `liquidGL` will use the highest `z-index` for all elements with the `target` selector. This is because the effect uses a shared canvas to prevent WebGL context issues, there is no work around to this unfortunately.
194
263
  - To improve performance on complex pages, you can snapshot a smaller, specific element like a background container instead of the whole page. Use the `snapshot` option with a CSS selector (e.g., `snapshot: '.my-background'`). This reduces texture memory and improves performance.
195
264
  - The initial capture is asynchronous. Call `liquidGL()` inside a `DOMContentLoaded` or `load` handler to ensure content is available to the snapshot.
@@ -231,6 +300,31 @@ The `liquidGL` library is compatible with all WebGL enabled browsers on desktop,
231
300
 
232
301
  ---
233
302
 
303
+ ## Contributors
304
+
305
+ Thank you to the following people for their contributions to `liquidGL`.
306
+
307
+ <table>
308
+ <tr>
309
+ <td align="center" width="140">
310
+ <a href="https://github.com/codedgar">
311
+ <img src="https://github.com/codedgar.png?size=100" width="100" height="100" alt="Edgar Pérez" /><br />
312
+ <sub><b>Edgar Pérez</b></sub><br />
313
+ <sub>@codedgar</sub>
314
+ </a>
315
+ </td>
316
+ <td align="center" width="140">
317
+ <a href="https://github.com/AbhinavRobinson">
318
+ <img src="https://github.com/AbhinavRobinson.png?size=100" width="100" height="100" alt="Abhinav Robinson" /><br />
319
+ <sub><b>Abhinav Robinson</b></sub><br />
320
+ <sub>@AbhinavRobinson</sub>
321
+ </a>
322
+ </td>
323
+ </tr>
324
+ </table>
325
+
326
+ ---
327
+
234
328
  ## License
235
329
 
236
330
  MIT © NaughtyDuk