@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 the native page backdrop or the contents of a declared scroll pane. Angular, React and Vue bind the same JavaScript core to their lifecycle.
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
- ![Automatic mode using viewport SVG to bend a grid in the live scroll pane](docs/images/playground.png)
9
+ ![Glass playground with a grid in the live scroll pane](docs/images/playground.png)
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 refract the contents of a live scroll pane. The renderer starts at **Automatic**. Switch between photo, grid, and typography artwork inside the pane and scroll it beneath the pinned glass. **Simple** shows one refraction slider. **Advanced** adds radius, bevel, curvature, chroma, blur, and tint opacity.
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
- In **Usage**, choose a mode and a language to copy the corresponding layout and configuration. The **Automatic** example identifies the element behind the glass with `source`.
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", { source: "feed", options: { radius: 30 } });
49
+ const glass = liquidGlass("item", { options: { radius: 30 } });
50
50
 
51
- glass.update({ options: { chroma: 0.2 } });
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 a usable media source, then native backdrop, viewport SVG, or frosted glass. WebKit uses frosted glass for independently scrolling HTML sources |
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 a scrolling scene that needs Safari support, 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. Safari can lose the displacement after deeper scrolling when the filter is attached directly to the scroll container. Call `glass.refresh()` after changing the relative position or replacing a selector target without an options update.
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"` | Automatic, frosted glass, or off |
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 supplied media, then native backdrop, viewport SVG, or frost. */
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 D}from"./optics.js";import{resolveOptions as I}from"./options.js";import{browserEngine as te,makeSvgLens as ne}from"./renderers/svg.js";import{makeViewportLens as re}from"./renderers/viewport.js";import{makeSampledLens as oe}from"./renderers/sampled.js";const W=new WeakMap,b="liquid-glass";function U(t,p){if(typeof p!="string")return p;const M=t?.getElementById?.(p);if(M)return M;try{return t?.querySelector(p)}catch{return null}}function ae(t,p={}){t=U(globalThis.document,t);const i=t?.ownerDocument?.defaultView;if(!i||!(t instanceof i.HTMLElement))throw new TypeError("liquidGlass requires an HTML element");const x=W.get(t);if(x)return x.update(p),x;let n=I(i,p);const S=te(i),j=S==="blink"&&i.CSS?.supports("backdrop-filter",'url("#glass")'),H=i.matchMedia("(prefers-reduced-motion: reduce)"),P=i.matchMedia("(prefers-reduced-transparency: reduce), (forced-colors: active)"),k=new Map,J=t.classList.contains(b),q=new i.ResizeObserver(a);let A,C,m,R,F,T,u=null,l=null,w=null,g,v="off",h=!1;function s(e,r){const o="--liquid-glass-"+e;t.style.getPropertyValue(o)!==String(r)&&(k.has(o)||k.set(o,[t.style.getPropertyValue(o),t.style.getPropertyPriority(o)]),t.style.setProperty(o,r))}function N(){for(const[e,[r,o]]of k)t.style.setProperty(e,r,o);k.clear()}function a(){!h&&n.mode!=="off"&&l===null&&(l=i.requestAnimationFrame(B))}function Q(){h||n.mode==="off"||(l!==null&&i.cancelAnimationFrame(l),B())}function c(e,r=""){e!=="off"&&s("lens",e==="backdrop"?r:""),v!==e&&(v=e,i.queueMicrotask(()=>{!h&&v===e&&t.dispatchEvent(new i.CustomEvent("liquidglass:rendererchange",{detail:{renderer:e}}))}))}function L(){A?.dispose(),A=void 0}function y(){m&&(m.dispose(),m=R=F=void 0)}function O(e){if(!e)return null;const r=t.getRootNode();return e=U(r,e),e instanceof i.HTMLElement&&e.getRootNode()===r?e:null}function Z(e,r){const o=O(n.source??n.backdrop??(n.mode==="auto"?n.viewportSource:null));return!o?.isConnected||!["img","video","canvas"].includes(o.localName)||t.contains(o)?(y(),!1):(o!==R&&(y(),R=o,m=oe(t,o,a,Q)),F=D(e,r,n,F,"viewport"),m.render(F,n)?(d(null),c("sampled"),!0):(m.hide(),!1))}function G(e){(S==="webkit"&&n.mode==="auto"||!(e.target instanceof i.Node)||!u?.contains(e.target))&&a()}function d(e){e!==u&&(C?.dispose(),C=void 0,u&&q.unobserve(u),!u&&e&&(i.addEventListener("scroll",G,!0),i.addEventListener("resize",a)),u=e,u&&q.observe(u),u||(i.removeEventListener("scroll",G,!0),i.removeEventListener("resize",a)))}function _(){const e=O(n.source??n.viewportSource);return!e||e.contains(t)||t.contains(e)?null:e}function ee(e){for(let r=e;r&&!r.contains(t);r=r.parentElement){const{overflowX:o,overflowY:f}=i.getComputedStyle(r);if(r.scrollWidth>r.clientWidth&&/^(auto|scroll)$/.test(o)||r.scrollHeight>r.clientHeight&&/^(auto|scroll)$/.test(f))return!0}return!1}function z(){const e=_(),r=S==="webkit"&&n.mode==="auto"&&e?.isConnected&&(e.localName==="video"||ee(e));if(d(r?null:e),!e?.isConnected||r){c("frost");return}C??=re(t,e,S),v!=="viewport"&&c("frost");const o=n;C.render(n,f=>{n===o&&c(f?"viewport":"frost")})}function B(){l=null;const{mode:e,refraction:r}=n,{clientWidth:o,clientHeight:f}=t;if(P.matches||e==="frost"||!r||!t.isConnected||!o||!f){L(),y(),d(null),c("frost");return}if(e==="sampled"||e==="auto"){if(Z(o,f)){L();return}}else y();if(j&&(e==="auto"||e==="backdrop")){T=D(o,f,n,T),A??=ne(t);const V=n;A.render(T,n,$=>{n===V&&($?(d(null),c("backdrop",$)):e==="auto"?z():(d(null),c("frost")))});return}L(),e==="viewport"||e==="auto"?z():(d(null),c("frost"))}function E(){g=void 0,n.mode!=="off"&&(s("light-x",""),s("light-y",""))}function K(e){n.mode==="off"||!n.interactive||H.matches||e.pointerType==="touch"||(g={x:e.clientX,y:e.clientY},w===null&&(w=i.requestAnimationFrame(()=>{if(w=null,!g)return;const{width:r,height:o,left:f,top:V}=t.getBoundingClientRect();!r||!o||(s("light-x",(g.x-f)/r*100+"%"),s("light-y",(g.y-V)/o*100+"%"))})))}function X(){if(n.mode==="off"){l!==null&&i.cancelAnimationFrame(l),l=null,g=void 0,L(),y(),d(null),N(),t.classList.remove(b),c("off");return}t.classList.add(b),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||E(),v==="off"&&c("frost"),a()}const Y={get renderer(){return v},update(e,{replace:r=!1}={}){h||(n=I(i,e,r?void 0:n),X())},refresh:a,destroy(){h||(h=!0,l!==null&&i.cancelAnimationFrame(l),w!==null&&i.cancelAnimationFrame(w),L(),y(),d(null),q.disconnect(),t.removeEventListener("pointermove",K),t.removeEventListener("pointerleave",E),H.removeEventListener("change",E),P.removeEventListener("change",a),N(),J?t.classList.add(b):t.classList.remove(b),W.delete(t),v="off")}};return W.set(t,Y),t.addEventListener("pointermove",K,{passive:!0}),t.addEventListener("pointerleave",E),H.addEventListener("change",E),P.addEventListener("change",a),q.observe(t),X(),Y}export{ae as liquidGlass};
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikeofficial/liquid-glass-js",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "Refractive, interactive glass surfaces for the web",
5
5
  "type": "module",
6
6
  "exports": {
@@ -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
- - Use an image, video, or canvas as `source` for sampled refraction. For an HTML scene, put the lens above the bounded source in a separate layer. With Angular, pass a template reference such as `{ source: feed }`.
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.