@ikeofficial/liquid-glass-js 0.3.1 → 0.3.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.
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# Liquid Glass JS
|
|
2
2
|
|
|
3
|
-
A dependency-free glass material for ordinary HTML elements. It can refract
|
|
3
|
+
A dependency-free glass material for ordinary HTML elements. It can blur a live backdrop, refract a declared media source, or apply SVG displacement to a small HTML scene. Angular, React and Vue bind the same JavaScript core to their lifecycle.
|
|
4
4
|
|
|
5
5
|
## Playground
|
|
6
6
|
|
|
7
7
|
Try the [interactive demo on GitHub Pages](https://bigimattia.github.io/liquidglass-js/).
|
|
8
8
|
|
|
9
|
-

|
|
10
10
|
|
|
11
11
|
To run the playground locally:
|
|
12
12
|
|
|
@@ -16,9 +16,9 @@ mise install
|
|
|
16
16
|
mise run dev
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
Open [the local playground](http://127.0.0.1:4173/demo/) to
|
|
19
|
+
Open [the local playground](http://127.0.0.1:4173/demo/) to drag a glass lens over an image and see live content beneath a pinned glass bar. **Automatic** chooses native backdrop refraction in Chromium and CSS frost in Firefox and Safari. Select **Viewport SVG** to try displacement on the declared HTML source. **Advanced** adds radius, bevel, curvature, chroma, blur, and tint opacity.
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
Expand **Usage** beneath the playground and choose a language to copy the live page example with the current mode and settings. The **Viewport SVG** example identifies the HTML element behind the glass with `source`.
|
|
22
22
|
|
|
23
23
|
The native-controls showcase has its own renderer picker. Select Button, Switch, Slider, Segmented, or Media and copy the Tailwind markup or the matching JavaScript, Angular, Vue, or React configuration. The Media preview uses a shared WebGL canvas for the video and its controls. The copyable configurations use the library's sampled-media API for individual lenses.
|
|
24
24
|
|
|
@@ -46,9 +46,9 @@ Update the version in `package.json`, then run **Publish to npm** from the Actio
|
|
|
46
46
|
import { liquidGlass } from "@ikeofficial/liquid-glass-js";
|
|
47
47
|
import "@ikeofficial/liquid-glass-js/style.css";
|
|
48
48
|
|
|
49
|
-
const glass = liquidGlass("item", {
|
|
49
|
+
const glass = liquidGlass("item", { options: { radius: 30 } });
|
|
50
50
|
|
|
51
|
-
glass.update({ options: {
|
|
51
|
+
glass.update({ options: { blur: 6 } });
|
|
52
52
|
glass.destroy();
|
|
53
53
|
```
|
|
54
54
|
|
|
@@ -70,7 +70,7 @@ import { LiquidGlassDirective } from "@ikeofficial/liquid-glass-js/angular";
|
|
|
70
70
|
<div class="glass-shell">
|
|
71
71
|
<main class="glass-source"><div #feed>Scrollable content</div></main>
|
|
72
72
|
<button class="glass-bar"
|
|
73
|
-
[liquidGlass]="{ source: feed, options: { radius: 24 } }">
|
|
73
|
+
[liquidGlass]="{ mode: 'viewport', source: feed, options: { radius: 24 } }">
|
|
74
74
|
Continue
|
|
75
75
|
</button>
|
|
76
76
|
</div>
|
|
@@ -122,11 +122,14 @@ The directive can also be registered globally with `app.directive("liquid-glass"
|
|
|
122
122
|
|
|
123
123
|
| Mode | Behavior |
|
|
124
124
|
| --- | --- |
|
|
125
|
-
| `auto` (default when `mode` is omitted) | Sampled WebGL for
|
|
125
|
+
| `auto` (default when `mode` is omitted) | Sampled WebGL for an explicit, usable media source. Otherwise native backdrop displacement in Chromium or CSS frost in Firefox and Safari |
|
|
126
|
+
| `viewport` | Explicit SVG displacement on a bounded HTML `source`. Use for small, controlled scenes |
|
|
127
|
+
| `sampled` | Sample an explicit image, video, or canvas with WebGL. Use frost if sampling is unavailable |
|
|
128
|
+
| `backdrop` | Use native backdrop displacement where supported, with CSS frost as fallback |
|
|
126
129
|
| `frost` | CSS blur, tint, and highlights |
|
|
127
130
|
| `off` | Disables glass and restores author styling |
|
|
128
131
|
|
|
129
|
-
`source` accepts an HTML element, an ID, or a selector resolved in the lens’s document or shadow root. Keep the source axis-aligned and place the lens in an overlapping layer. The source and lens must be in separate subtrees. For
|
|
132
|
+
`source` accepts an HTML element, an ID, or a selector resolved in the lens’s document or shadow root. Keep the source axis-aligned and place the lens in an overlapping layer. The source and lens must be in separate subtrees for viewport mode. For an explicit viewport scene that scrolls in Safari, declare the content wrapper inside the scroll container as the source. Put `overflow: auto` on the outer container and place the pinned lens outside it. Call `glass.refresh()` after changing the relative position or replacing a selector target without an options update.
|
|
130
133
|
|
|
131
134
|
Viewport SVG applies a CSS filter to the source, which creates a stacking context and can change positioning for fixed descendants. Keep fixed overlays outside that source. The source may contain ordinary text, images, and interactive HTML. Native video compositing varies by browser. Use an ordinary lens host with available `::before` and `::after` pseudo-elements.
|
|
132
135
|
|
|
@@ -140,7 +143,7 @@ For automatic media refraction, place a same-origin or CORS-enabled image, video
|
|
|
140
143
|
|
|
141
144
|
| Option | Default | Effect |
|
|
142
145
|
| --- | --- | --- |
|
|
143
|
-
| `mode` | `"auto"` |
|
|
146
|
+
| `mode` | `"auto"` | Renderer selection from the table above |
|
|
144
147
|
| `source` | `null` | ID, selector, or element behind the glass |
|
|
145
148
|
| `options` | — | Optional optical adjustments listed below |
|
|
146
149
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export type LiquidGlassMode = "auto" | "frost" | "off";
|
|
2
1
|
export type LiquidGlassRenderer = "viewport" | "backdrop" | "sampled" | "frost" | "off";
|
|
2
|
+
export type LiquidGlassMode = "auto" | LiquidGlassRenderer;
|
|
3
3
|
|
|
4
4
|
export interface LiquidGlassOptions {
|
|
5
|
-
/** Auto (default) prefers
|
|
5
|
+
/** Auto (default) prefers sampled media, then native displacement where supported, then CSS frost. */
|
|
6
6
|
mode?: LiquidGlassMode;
|
|
7
7
|
/** Element behind the lens. IDs and selectors resolve in the lens's document or shadow root. */
|
|
8
8
|
source?: string | HTMLElement | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{lensGeometry as
|
|
1
|
+
import{lensGeometry as Y}from"./optics.js";import{resolveOptions as j}from"./options.js";import{browserEngine as ee,makeSvgLens as te}from"./renderers/svg.js";import{makeViewportLens as ne}from"./renderers/viewport.js";import{makeSampledLens as re}from"./renderers/sampled.js";const H=new WeakMap,S="liquid-glass";function J(t,d){if(typeof d!="string")return d;const x=t?.getElementById?.(d);if(x)return x;try{return t?.querySelector(d)}catch{return null}}function le(t,d={}){t=J(globalThis.document,t);const i=t?.ownerDocument?.defaultView;if(!i||!(t instanceof i.HTMLElement))throw new TypeError("liquidGlass requires an HTML element");const A=H.get(t);if(A)return A.update(d),A;let n=j(i,d);const O=ee(i),K=O==="blink"&&i.CSS?.supports("backdrop-filter",'url("#glass")'),C=i.matchMedia("(prefers-reduced-motion: reduce)"),P=i.matchMedia("(prefers-reduced-transparency: reduce), (forced-colors: active)"),b=new Map,Q=t.classList.contains(S),k=new i.ResizeObserver(a);let q,F,v,R,M,T,u=null,c=null,y=null,m,f="off",g=!1;function s(e,o){const r="--liquid-glass-"+e;t.style.getPropertyValue(r)!==String(o)&&(b.has(r)||b.set(r,[t.style.getPropertyValue(r),t.style.getPropertyPriority(r)]),t.style.setProperty(r,o))}function G(){for(const[e,[o,r]]of b)t.style.setProperty(e,o,r);b.clear()}function a(){!g&&n.mode!=="off"&&c===null&&(c=i.requestAnimationFrame(B))}function U(){g||n.mode==="off"||(c!==null&&i.cancelAnimationFrame(c),B())}function l(e,o=""){e!=="off"&&s("lens",e==="backdrop"?o:""),f!==e&&(f=e,i.queueMicrotask(()=>{!g&&f===e&&t.dispatchEvent(new i.CustomEvent("liquidglass:rendererchange",{detail:{renderer:e}}))}))}function L(){q?.dispose(),q=void 0}function h(){v&&(v.dispose(),v=R=M=void 0)}function N(e){if(!e)return null;const o=t.getRootNode();return e=J(o,e),e instanceof i.HTMLElement&&e.getRootNode()===o?e:null}function Z(e,o){const r=N(n.source??n.backdrop??(n.mode==="auto"?n.viewportSource:null));return!r?.isConnected||!["img","video","canvas"].includes(r.localName)||t.contains(r)?(h(),!1):(r!==R&&(h(),R=r,v=re(t,r,a,U)),M=Y(e,o,n,M,"viewport"),v.render(M,n)?(p(null),l("sampled"),!0):(v.hide(),!1))}function z(e){(!(e.target instanceof i.Node)||!u?.contains(e.target))&&a()}function p(e){e!==u&&(F?.dispose(),F=void 0,u&&k.unobserve(u),!u&&e&&(i.addEventListener("scroll",z,!0),i.addEventListener("resize",a)),u=e,u&&k.observe(u),u||(i.removeEventListener("scroll",z,!0),i.removeEventListener("resize",a)))}function _(){const e=N(n.source??n.viewportSource);return!e||e.contains(t)||t.contains(e)?null:e}function $(){const e=_();if(p(e?.isConnected?e:null),!u){l("frost");return}F??=ne(t,u,O),f!=="viewport"&&l("frost");const o=n;F.render(n,r=>{n===o&&l(r?"viewport":"frost")})}function B(){c=null;const{mode:e,refraction:o}=n,{clientWidth:r,clientHeight:E}=t;if(P.matches||e==="frost"||!o||!t.isConnected||!r||!E){L(),h(),p(null),l("frost");return}if(e==="sampled"||e==="auto"){if(Z(r,E)){L();return}}else h();if(K&&(e==="auto"||e==="backdrop")){p(null),f!=="backdrop"&&l("frost"),T=Y(r,E,n,T),q??=te(t);const V=n;q.render(T,n,X=>{n===V&&l(X?"backdrop":"frost",X)});return}L(),e==="viewport"?$():(p(null),l("frost"))}function w(){m=void 0,n.mode!=="off"&&(s("light-x",""),s("light-y",""))}function W(e){n.mode==="off"||!n.interactive||C.matches||e.pointerType==="touch"||(m={x:e.clientX,y:e.clientY},y===null&&(y=i.requestAnimationFrame(()=>{if(y=null,!m)return;const{width:o,height:r,left:E,top:V}=t.getBoundingClientRect();!o||!r||(s("light-x",(m.x-E)/o*100+"%"),s("light-y",(m.y-V)/r*100+"%"))})))}function D(){if(n.mode==="off"){c!==null&&i.cancelAnimationFrame(c),c=null,m=void 0,L(),h(),p(null),G(),t.classList.remove(S),l("off");return}t.classList.add(S),s("radius",n.radius+"px"),s("blur",n.blur+"px"),s("saturation",n.saturation),s("tint",n.tint),s("glow",n.glow),s("edge",n.edgeHighlight),s("angle",n.lightAngle+"deg"),n.interactive||w(),f==="off"&&l("frost"),a()}const I={get renderer(){return f},update(e,{replace:o=!1}={}){g||(n=j(i,e,o?void 0:n),D())},refresh:a,destroy(){g||(g=!0,c!==null&&i.cancelAnimationFrame(c),y!==null&&i.cancelAnimationFrame(y),L(),h(),p(null),k.disconnect(),t.removeEventListener("pointermove",W),t.removeEventListener("pointerleave",w),C.removeEventListener("change",w),P.removeEventListener("change",a),G(),Q?t.classList.add(S):t.classList.remove(S),H.delete(t),f="off")}};return H.set(t,I),t.addEventListener("pointermove",W,{passive:!0}),t.addEventListener("pointerleave",w),C.addEventListener("change",w),P.addEventListener("change",a),k.observe(t),D(),I}export{le as liquidGlass};
|
package/package.json
CHANGED
|
@@ -20,6 +20,8 @@ Use an ordinary HTML host with geometry supplied by the app’s CSS and availabl
|
|
|
20
20
|
## Choose the source
|
|
21
21
|
|
|
22
22
|
- `liquidGlass("lens-id", { source: "source-id" })` uses automatic renderer selection. An HTML element or a selector also works. Source selectors resolve in the lens's document or shadow root.
|
|
23
|
-
-
|
|
23
|
+
- For regular page HTML, start with `liquidGlass("lens-id")`. Automatic mode uses native backdrop displacement in Chromium and CSS backdrop blur, saturation, tint, and highlights in Firefox and Safari.
|
|
24
|
+
- For targeted refraction, pass a same-origin or CORS-enabled image, video, or canvas as `source`. Keep it borderless and axis-aligned with `object-fit: fill` or centered `cover` or `contain`. Automatic mode tries sampled WebGL first. Use `mode: "sampled"` to select this path explicitly with frost as fallback.
|
|
25
|
+
- Use `{ mode: "viewport", source: "feed" }` to refract a small HTML scene explicitly. Put the lens above the bounded source in a separate layer. With Angular, pass a template reference such as `{ mode: "viewport", source: feed }`.
|
|
24
26
|
- Set `mode: "frost"` for CSS frost or `mode: "off"` to disable glass. Set optional optical adjustments under `options`, for example `{ source: "feed", options: { radius: 24 } }`.
|
|
25
|
-
- Call `glass.refresh()` after moving the lens relative to the source or replacing its selector target. Run `mise run dev` and use **Usage** for matching JavaScript, Angular, React, and Vue examples.
|
|
27
|
+
- Call `glass.refresh()` after moving the lens relative to the source, redrawing a source canvas, or replacing its selector target. Run `mise run dev` and use **Usage** for live HTML examples or **Controls** for explicit media and matching JavaScript, Angular, React, and Vue examples.
|