@ikeofficial/liquid-glass-js 0.2.1 → 0.3.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.
package/README.md CHANGED
@@ -1,16 +1,26 @@
1
1
  # Liquid Glass JS
2
2
 
3
- A dependency-free glass material for ordinary HTML elements. It can bend the element’s own text, CSS and images, sample an image, canvas or video behind it, or refract the live page backdrop. Angular, React and Vue bind the same JavaScript core to their lifecycle.
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.
4
4
 
5
5
  ## Playground
6
6
 
7
+ Try the [interactive demo on GitHub Pages](https://bigimattia.github.io/liquidglass-js/).
8
+
9
+ ![Automatic mode using viewport SVG to bend a grid in the live scroll pane](docs/images/playground.png)
10
+
11
+ To run the playground locally:
12
+
7
13
  ```sh
8
14
  mise trust
9
15
  mise install
10
16
  mise run dev
11
17
  ```
12
18
 
13
- Open [the local playground](http://127.0.0.1:4173/demo/). Drag the lens or focus it and use the arrow keys. Compare the photo, grid and typography scenes and change the optical settings. Select Button, Switch, Slider, Segmented, or Media in the native-controls showcase to try the control and copy Tailwind HTML, JavaScript, Angular, Vue, or React source. The usage panel includes examples for all four entry points.
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.
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`.
22
+
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.
14
24
 
15
25
  ## Install
16
26
 
@@ -36,10 +46,9 @@ Update the version in `package.json`, then run **Publish to npm** from the Actio
36
46
  import { liquidGlass } from "@ikeofficial/liquid-glass-js";
37
47
  import "@ikeofficial/liquid-glass-js/style.css";
38
48
 
39
- const item = document.querySelector("#item");
40
- const glass = liquidGlass(item, { mode: "content", radius: 30, refraction: 18 });
49
+ const glass = liquidGlass("item", { source: "feed", options: { radius: 30 } });
41
50
 
42
- glass.update({ chroma: 0.2 });
51
+ glass.update({ options: { chroma: 0.2 } });
43
52
  glass.destroy();
44
53
  ```
45
54
 
@@ -57,12 +66,28 @@ import { LiquidGlassDirective } from "@ikeofficial/liquid-glass-js/angular";
57
66
 
58
67
  @Component({
59
68
  imports: [LiquidGlassDirective],
60
- template: '<button [liquidGlass]="{ mode: \'content\', radius: 22 }">Continue</button>',
69
+ template: `
70
+ <div class="glass-shell">
71
+ <main class="glass-source"><div #feed>Scrollable content</div></main>
72
+ <button class="glass-bar"
73
+ [liquidGlass]="{ source: feed, options: { radius: 24 } }">
74
+ Continue
75
+ </button>
76
+ </div>
77
+ `,
78
+ styles: `
79
+ .glass-shell { position: relative; isolation: isolate; }
80
+ .glass-source { height: 24rem; overflow: auto; }
81
+ .glass-bar {
82
+ position: absolute; inset: 1rem 1rem auto; min-height: 3rem;
83
+ border: 0; background: transparent; color: inherit;
84
+ }
85
+ `,
61
86
  })
62
87
  export class Action {}
63
88
  ```
64
89
 
65
- A bare `liquidGlass` attribute uses the defaults.
90
+ An element ID or selector such as `source: '#feed'` also works.
66
91
 
67
92
  ## React
68
93
 
@@ -71,7 +96,7 @@ import { useLiquidGlass } from "@ikeofficial/liquid-glass-js/react";
71
96
  import "@ikeofficial/liquid-glass-js/style.css";
72
97
 
73
98
  export function Action() {
74
- const ref = useLiquidGlass({ mode: "content", radius: 22 });
99
+ const ref = useLiquidGlass({ options: { radius: 22 } });
75
100
  return <button ref={ref}>Continue</button>;
76
101
  }
77
102
  ```
@@ -87,7 +112,7 @@ import "@ikeofficial/liquid-glass-js/style.css";
87
112
  </script>
88
113
 
89
114
  <template>
90
- <button v-liquid-glass="{ mode: 'content', radius: 22 }">Continue</button>
115
+ <button v-liquid-glass="{ options: { radius: 22 } }">Continue</button>
91
116
  </template>
92
117
  ```
93
118
 
@@ -95,30 +120,34 @@ The directive can also be registered globally with `app.directive("liquid-glass"
95
120
 
96
121
  ## Rendering modes
97
122
 
98
- | Options | What bends | Browser behavior |
99
- | --- | --- | --- |
100
- | `{ mode: "content" }` | The host’s rendered pixels, including its CSS background and descendants | SVG element filter in Chromium, Firefox and WebKit |
101
- | Default, or `{ mode: "auto" }` | Live page pixels when supported, otherwise the supplied backdrop | SVG refraction in Chromium, sampled media when supplied, then CSS frost |
102
- | `{ mode: "backdrop" }` | Arbitrary page pixels behind the host | SVG refraction in Chromium. CSS frost in other engines. A supplied backdrop retains its sample-first behavior. |
103
- | `{ mode: "sampled", backdrop: media }` | A supplied `<img>`, `<canvas>`, or `<video>` behind the host | Shared WebGL renderer where available, with Canvas 2D fallback |
104
- | `{ mode: "frost" }` | No displacement | CSS tint, blur and highlights where supported |
123
+ | Mode | Behavior |
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 |
126
+ | `frost` | CSS blur, tint, and highlights |
127
+ | `off` | Disables glass and restores author styling |
128
+
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.
105
130
 
106
- Use an ordinary HTML host with available `::before` and `::after` pseudo-elements. For content mode, put the artwork inside the host or use a CSS background. The filter refracts pixels only inside the lens silhouette. Use a decorative presentation layer for labels that must stay sharp, and keep the filtered host compact on mobile. The playground clips the aligned scene copy at the parent after refraction, so the glass outline stays stable as the optical settings change.
131
+ 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.
107
132
 
108
- A sampled media element must sit visually behind the lens in the same document, axis-aligned, without padding or borders. Images and videos support `object-fit: fill` or centered `cover` or `contain`. Use a same-origin or CORS-enabled source. The library resamples on resize, scroll, and media load. Video uses `requestVideoFrameCallback()` when available. Call `glass.refresh()` after moving the lens programmatically or redrawing a canvas.
133
+ On WebKit, Viewport SVG positions its filter relative to the source's bounding box and limits the displacement passes to the lens with room for the warp. It uses frost when the source's estimated raster exceeds 8,388,608 device pixels or 4,096 device pixels on either side. The estimate uses the larger of the layout and displayed dimensions, scaled by the device pixel ratio.
109
134
 
110
- Automatic mode requires an explicit `backdrop` element for the sampled fallback. Use `mode: "sampled"` when the video or image should drive refraction on every browser. For the native-control snippets, load Tailwind CSS v4 and the shared glass stylesheet. The Media example also needs a same-origin video and poster, or a video served with CORS enabled and loaded with `crossorigin="anonymous"`.
135
+ The SVG renderers use an internally generated PNG data URL and fall back to frost if it cannot load. Reduced motion disables pointer tracking. Reduced transparency and forced colors use a solid treatment. The `liquid-glass` class with the shared stylesheet gives you a CSS-only treatment.
111
136
 
112
- The SVG modes use an internally generated PNG data URL. Where CSP disallows `data:` images, use a sampled backdrop or frost. Reduced motion disables pointer tracking. Reduced transparency and forced colors use a solid treatment. A CSS-only treatment is also available by applying the `liquid-glass` class with the shared stylesheet.
137
+ For automatic media refraction, place a same-origin or CORS-enabled image, video, or canvas behind the lens and call `liquidGlass("play-glass", { source: "player-video" })`. Use a borderless, axis-aligned source with `object-fit: fill`, centered `cover`, or centered `contain`. Video repaints with its frames. Call `glass.refresh()` after redrawing a canvas or repositioning the media with a transform. The native-control examples use Tailwind CSS v4 and the shared glass stylesheet.
113
138
 
114
139
  ## Options
115
140
 
116
141
  | Option | Default | Effect |
117
142
  | --- | --- | --- |
118
- | `mode` | `"auto"` | Auto, content, backdrop, sampled, or frost |
119
- | `backdrop` | `null` | Optional image, canvas or video source for auto, backdrop, and sampled modes |
143
+ | `mode` | `"auto"` | Automatic, frosted glass, or off |
144
+ | `source` | `null` | ID, selector, or element behind the glass |
145
+ | `options` | — | Optional optical adjustments listed below |
146
+
147
+ | Optical option | Default | Effect |
148
+ | --- | --- | --- |
120
149
  | `radius` | 24 | Corner radius in CSS pixels. Set size with your CSS |
121
- | `refraction` | 18 | Requested edge displacement in CSS pixels, bounded by the lens size. Zero disables distortion |
150
+ | `refraction` | 18 | Requested edge displacement in CSS pixels. The bevel limits the effective displacement. Zero disables distortion |
122
151
  | `bevel` | 24 | Width of the refracted edge in CSS pixels |
123
152
  | `curvature` | 2 | Shape of the optical bevel, 0.25–8 |
124
153
  | `chroma` | 0 | Color-channel spread, 0–1 |
@@ -1 +1 @@
1
- :where(.liquid-glass){--liquid-glass-lens: ;--liquid-glass-content-filter: none;--liquid-glass-overlay-filter: var(--liquid-glass-lens) blur(var(--liquid-glass-blur, 2px)) saturate(var(--liquid-glass-saturation, 1.35));--liquid-glass-light-x: 25%;--liquid-glass-light-y: 0%;position:relative;z-index:0;border-radius:var(--liquid-glass-radius, 24px);filter:var(--liquid-glass-content-filter)}:where(.liquid-glass):before,:where(.liquid-glass):after{content:"";position:absolute;inset:0;border-radius:inherit;pointer-events:none}:where(.liquid-glass):before{z-index:-1;background:radial-gradient(ellipse at var(--liquid-glass-light-x) var(--liquid-glass-light-y),rgb(255 255 255 / var(--liquid-glass-glow, .23)),transparent 72%),rgb(var(--liquid-glass-tint-rgb, 255 255 255) / var(--liquid-glass-tint, .14));-webkit-backdrop-filter:var(--liquid-glass-overlay-filter);backdrop-filter:var(--liquid-glass-overlay-filter)}:where(.liquid-glass):after{padding:1px;opacity:calc(var(--liquid-glass-edge, .85) * var(--liquid-glass-css-rim, 1));background:radial-gradient(ellipse at var(--liquid-glass-light-x) var(--liquid-glass-light-y),rgb(255 255 255 / .95),transparent 64%),linear-gradient(var(--liquid-glass-angle, 145deg),rgb(255 255 255 / .55),rgb(255 255 255 / .11) 50%,rgb(255 255 255 / .42));mask:linear-gradient(#000 0 0) content-box,linear-gradient(#000 0 0);mask-composite:exclude}:where(.liquid-glass:active):before{box-shadow:inset 0 0 18px #ffffff2b}:where(.liquid-glass>.liquid-glass-backdrop){position:absolute;inset:0;width:100%;height:100%;z-index:-2;border-radius:inherit;pointer-events:none}@media(prefers-reduced-transparency:reduce),(forced-colors:active){:where(.liquid-glass){filter:none}:where(.liquid-glass):before{background:var(--liquid-glass-solid, Canvas);-webkit-backdrop-filter:none;backdrop-filter:none}:where(.liquid-glass):after{background:currentColor}:where(.liquid-glass>.liquid-glass-backdrop){visibility:hidden}}
1
+ :where(.liquid-glass){--liquid-glass-lens: ;--liquid-glass-overlay-filter: var(--liquid-glass-lens) blur(var(--liquid-glass-blur, 2px)) saturate(var(--liquid-glass-saturation, 1.35));--liquid-glass-light-x: 25%;--liquid-glass-light-y: 0%;position:relative;z-index:0;border-radius:var(--liquid-glass-radius, 24px)}:where(.liquid-glass):before,:where(.liquid-glass):after{content:"";position:absolute;inset:0;border-radius:inherit;pointer-events:none}:where(.liquid-glass):before{z-index:-1;background:radial-gradient(ellipse at var(--liquid-glass-light-x) var(--liquid-glass-light-y),rgb(255 255 255 / var(--liquid-glass-glow, .23)),transparent 72%),rgb(var(--liquid-glass-tint-rgb, 255 255 255) / var(--liquid-glass-tint, .14));-webkit-backdrop-filter:var(--liquid-glass-overlay-filter);backdrop-filter:var(--liquid-glass-overlay-filter)}:where(.liquid-glass):after{padding:1px;opacity:var(--liquid-glass-edge, .85);background:radial-gradient(ellipse at var(--liquid-glass-light-x) var(--liquid-glass-light-y),rgb(255 255 255 / .95),transparent 64%),linear-gradient(var(--liquid-glass-angle, 145deg),rgb(255 255 255 / .55),rgb(255 255 255 / .11) 50%,rgb(255 255 255 / .42));mask:linear-gradient(#000 0 0) content-box,linear-gradient(#000 0 0);mask-composite:exclude}:where(.liquid-glass:active):before{box-shadow:inset 0 0 18px #ffffff2b}@media(prefers-reduced-transparency:reduce),(forced-colors:active){:where(.liquid-glass):before{background:var(--liquid-glass-solid, Canvas);-webkit-backdrop-filter:none;backdrop-filter:none}:where(.liquid-glass):after{background:currentColor}}:where(.liquid-glass-sampled){position:absolute;inset:0;width:100%;height:100%;pointer-events:none;border-radius:inherit;z-index:-2}
@@ -1,11 +1,15 @@
1
- export type LiquidGlassMode = "auto" | "content" | "backdrop" | "sampled" | "frost";
2
- export type LiquidGlassRenderer = "content" | "backdrop" | "sampled" | "frost";
1
+ export type LiquidGlassMode = "auto" | "frost" | "off";
2
+ export type LiquidGlassRenderer = "viewport" | "backdrop" | "sampled" | "frost" | "off";
3
3
 
4
4
  export interface LiquidGlassOptions {
5
- /** Auto (default) prefers live backdrop refraction, then a supplied backdrop, then frost. */
5
+ /** Auto (default) prefers supplied media, then native backdrop, viewport SVG, or frost. */
6
6
  mode?: LiquidGlassMode;
7
- /** Optional image, canvas, or video displayed behind a lens in auto, sampled, or backdrop mode. */
8
- backdrop?: HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | null;
7
+ /** Element behind the lens. IDs and selectors resolve in the lens's document or shadow root. */
8
+ source?: string | HTMLElement | null;
9
+ options?: LiquidGlassOptics;
10
+ }
11
+
12
+ export interface LiquidGlassOptics {
9
13
  /** Uniform corner radius in CSS pixels. Defaults to 24. */
10
14
  radius?: number;
11
15
  /** Blur in CSS pixels. Defaults to 2. */
@@ -37,9 +41,9 @@ export interface LiquidGlassController {
37
41
  readonly renderer: LiquidGlassRenderer;
38
42
  /** Merge changes, or reset omitted options to their defaults with replace. */
39
43
  update(options: LiquidGlassOptions, behavior?: { replace?: boolean }): void;
40
- /** Resample an explicit backdrop after changing position or drawing new canvas content. */
44
+ /** Recheck the renderer and source geometry after changing their relative position. */
41
45
  refresh(): void;
42
46
  destroy(): void;
43
47
  }
44
48
 
45
- export function liquidGlass(element: HTMLElement, options?: LiquidGlassOptions): LiquidGlassController;
49
+ export function liquidGlass(element: string | HTMLElement, options?: LiquidGlassOptions): LiquidGlassController;
@@ -1 +1 @@
1
- import{lensGeometry as te}from"./optics.js";import{resolveOptions as K}from"./options.js";import{makeBackdropLens as ne}from"./renderers/sampled.js";import{browserEngine as re,makeSvgLens as ie}from"./renderers/svg.js";const H=new WeakMap,R="liquid-glass";function le(t,z={}){const O=t?.ownerDocument,n=O?.defaultView;if(!n||!(t instanceof n.HTMLElement))throw new TypeError("liquidGlass requires an HTML element");const C=H.get(t);if(C)return C.update(z),C;let r=K(n,z);const T=re(n),Q=T==="blink"&&n.CSS?.supports("backdrop-filter",'url("#glass")'),S=n.matchMedia("(prefers-reduced-motion: reduce)"),w=n.matchMedia("(prefers-reduced-transparency: reduce), (forced-colors: active)"),V=new Map,U=t.classList.contains(R),q=new n.ResizeObserver(a);let M,P,l,x,c,A,v=null,p=null,g,m="frost",h=!1;function s(e,i){const o="--liquid-glass-"+e;t.style.getPropertyValue(o)!==String(i)&&(V.has(o)||V.set(o,[t.style.getPropertyValue(o),t.style.getPropertyPriority(o)]),t.style.setProperty(o,i))}function a(){!h&&v===null&&(v=n.requestAnimationFrame(Z))}function f(e,i=""){s("overlay-filter",e==="content"?"none":""),s("css-rim",e==="content"||e==="sampled"?0:""),s("content-filter",e==="content"?i:""),s("lens",e==="backdrop"?i:""),m!==e&&(m=e,n.queueMicrotask(()=>{!h&&m===e&&t.dispatchEvent(new n.CustomEvent("liquidglass:rendererchange",{detail:{renderer:e}}))}))}function y(){M?.dispose(),M=void 0,P=void 0}function Z(){v=null;const{mode:e,refraction:i,radius:o,bevel:d,curvature:u,lightAngle:$}=r,E=e==="content",j=Q&&(e==="auto"||e==="backdrop"),D=j&&e==="auto",b=E?t.offsetWidth:t.clientWidth,k=E?t.offsetHeight:t.clientHeight;if(w.matches||e==="frost"||!i||!t.isConnected||!b||!k){f("frost"),y(),l?.canvas.remove();return}const X=E?Math.min(n.devicePixelRatio||1,2):1,Y=[b,k,Math.min(o,b/2,k/2),d,u,$,X].join("/");Y!==x?.key&&(x={...te(b,k,r,X),width:b,height:k,key:Y});function I(){return c?(l??=ne(O),l.canvas.parentNode||t.prepend(l.canvas),l.render(c,x,r)?(f("sampled"),!0):(l.canvas.remove(),!1)):(l?.canvas.remove(),!1)}if(!D&&I()){y();return}if(!E&&!j){f("frost"),y();return}const F=E?"content":"backdrop";P!==F&&(y(),M=ie(t,T,F),P=F,l?.canvas.remove(),f("frost"));const ee=r;M.render(x,r,J=>{r===ee&&(J?(l?.canvas.remove(),f(F,J)):(!D||!I())&&f("frost"))})}function L(){g=void 0,s("light-x",""),s("light-y","")}function B(e){!r.interactive||S.matches||e.pointerType==="touch"||(g={x:e.clientX,y:e.clientY},p===null&&(p=n.requestAnimationFrame(()=>{if(p=null,!g)return;const{width:i,height:o,left:d,top:u}=t.getBoundingClientRect();!i||!o||(s("light-x",(g.x-d)/i*100+"%"),s("light-y",(g.y-u)/o*100+"%"))})))}function G(e){c!==e&&(c&&(q.unobserve(c),c.removeEventListener("load",a),A?.(),A=void 0),c=e,c?(q.observe(c),c.addEventListener("load",a),c.localName==="video"&&(A=_(c)),n.addEventListener("scroll",a,!0),n.addEventListener("resize",a)):(n.removeEventListener("scroll",a,!0),n.removeEventListener("resize",a)))}function _(e){const i=["loadeddata","seeked","resize"];for(const u of i)e.addEventListener(u,a);function o(){w.matches||a(),d=e.requestVideoFrameCallback(o)}let d=e.requestVideoFrameCallback?.(o);return()=>{d!==void 0&&e.cancelVideoFrameCallback(d);for(const u of i)e.removeEventListener(u,a)}}function W(){t.classList.add(R),s("radius",r.radius+"px"),s("blur",r.blur+"px"),s("saturation",r.saturation),s("tint",r.tint),s("glow",r.glow),s("edge",r.edgeHighlight),s("angle",r.lightAngle+"deg"),r.interactive||L(),G(r.refraction&&["auto","backdrop","sampled"].includes(r.mode)?r.backdrop:null),a()}const N={get renderer(){return m},update(e,{replace:i=!1}={}){h||(r=K(n,e,i?void 0:r),W())},refresh:a,destroy(){if(!h){h=!0,v!==null&&n.cancelAnimationFrame(v),p!==null&&n.cancelAnimationFrame(p),y(),l?.canvas.remove(),G(null),q.disconnect(),t.removeEventListener("pointermove",B),t.removeEventListener("pointerleave",L),S.removeEventListener("change",L),w.removeEventListener("change",a);for(const[e,[i,o]]of V)t.style.setProperty(e,i,o);U||t.classList.remove(R),H.delete(t),m="frost"}}};return H.set(t,N),t.addEventListener("pointermove",B,{passive:!0}),t.addEventListener("pointerleave",L),S.addEventListener("change",L),w.addEventListener("change",a),q.observe(t),W(),N}export{le as liquidGlass};
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 +1 @@
1
- const nt=192,ot=1.5,h=new Map;function tt(t){if(h.has(t))return h.get(t);const n=new Float32Array(193),a=1.3+t*.55,l=Math.tan(Math.acos(1/1.5));n[0]=1;for(let r=1;r<192;r++){const c=1-r/192,I=c**(a-1)*(1-c**a)**(1/a-1),M=Math.atan(I),o=Math.tan(M-Math.asin(Math.sin(M)/1.5));n[r]=.72*o/l+.28*c*c*(3-2*c)}return h.size===32&&h.delete(h.keys().next().value),h.set(t,n),n}function st(t,n,{radius:a,bevel:l,curvature:r,lightAngle:c=145},I=1){const M=Math.min(I,512/Math.max(t,n)),o=Math.max(1,Math.round(t*M)),i=Math.max(1,Math.round(n*M)),N=new Uint8Array(o*i),P=new Uint8Array(o*i),H=new Float32Array(o*i*2),U=t/2,k=n/2,W=Math.min(a,U,k),J=Math.min(l,U,k),v=t/o,z=n/i,G=Math.max(v,z),X=tt(r),j=c*Math.PI/180,K=-Math.sin(j),L=Math.cos(j),O=Math.ceil(o/2),Q=Math.ceil(i/2);for(let s=0;s<Q;s++){const x=W-(s+.5)*z,f=i-s-1;for(let e=0;e<O;e++){let w=function(_,$,C,D){const A=_*o+$;N[A]=R,F&&(H[2*A]=C*F,H[2*A+1]=D*F);const E=-C*K-D*L;P[A]=Z*(.19+.81*Math.max(E,-E*.64))};const d=W-(e+.5)*v,g=Math.max(0,d),u=Math.max(0,x),m=g&&u?Math.hypot(g,u):g+u,Y=W-m-Math.min(Math.max(d,x),0);if(Y<=-G/2)continue;const R=Math.min(1,.5+Y/G)*255,p=o-e-1,S=p===e?0:m?g/m:+(d>x),b=f===s?0:m?u/m:+(x>d),q=Math.max(0,Y),B=Math.min(192,q*192/J),y=Math.floor(B),F=X[y]+(X[Math.min(192,y+1)]-X[y])*(B-y),T=Math.max(0,1-q/2.1),V=Math.max(0,1-q/10),Z=255*(.78*T**2+.22*V**2);w(s,e,S,b),p!==e&&w(s,p,-S,b),f!==s&&w(f,e,S,-b),f!==s&&p!==e&&w(f,p,-S,-b)}}return{columns:o,rows:i,offsets:H,coverage:N,highlights:P}}function et(t,n,a,l){return Math.min(t,Math.min(a,l)*.48/(1+n))}export{st as lensGeometry,et as lensStrength};
1
+ function L(a){const t=Math.max(0,Math.min(1,a));return t*t*(3-2*t)}function $(a,t,{radius:C,refraction:N,bevel:D,curvature:P},X,B="backdrop"){const i=Math.min(C,a/2,t/2),u=B==="backdrop",E=Math.min(a,t),Y=Math.min(D,E*(u?.24:.5)),r=Y*(.45+.55*Math.min(1,.625*(N/Y))),j=Math.min(i,r),S=r-j,z=B==="sampled",p=z?.14+.035*P:.34+.03*P,G=.8*(1-p),I=p*(u?.8:1),H=(z?G:Math.min(I,G))/1.5,M=Math.min(N,r*H),W=[B,a,t,i,r,p,M].join("/");if(X?.key===W)return X;const J=u?Math.min(1,1.5*t/a):1,K=u?Math.min(1,1.5*a/t):1,q=Math.min(1,512/Math.max(a,t)),m=Math.max(1,Math.round(a*q)),l=Math.max(1,Math.round(t*q)),A=new Float32Array(m*l*2),O=a/m,Q=t/l;for(let n=0;n<Math.ceil(l/2);n++){const s=i-(n+.5)*Q,c=l-n-1;for(let o=0;o<Math.ceil(m/2);o++){let d=function(U,V,Z,_){const v=2*(U*m+V);A[v]=Z*F*J,A[v+1]=_*F*K};const e=i-(o+.5)*O,b=Math.max(0,e),k=Math.max(0,s),x=b&&k?Math.hypot(b,k):b+k,T=i-x-Math.min(Math.max(e,s),0),F=R(T,Math.max(-e,-s));if(!F)continue;const f=m-o-1,h=f===o?0:x?b/x:+(e>s),y=c===n?0:x?k/x:+(s>e);d(n,o,h,y),f!==o&&d(n,f,-h,y),c!==n&&d(c,o,h,-y),c!==n&&f!==o&&d(c,f,-h,-y)}}function R(n,s){if(n<=0||n>=r||!M)return 0;const c=S?j+S*L(s/(2*S)):r;if(n>=c)return 0;const o=c*p;return Math.min(M,c*H)/M*L(n/o)*(1-L((n-o)/(c-o)))}return{width:a,height:t,columns:m,rows:l,offsets:A,strength:M,key:W}}export{$ as lensGeometry};
@@ -1 +1 @@
1
- const a=Object.freeze({mode:"auto",backdrop:null,radius:24,blur:2,refraction:18,bevel:24,curvature:2,chroma:0,saturation:1.35,tint:.14,glow:.23,edgeHighlight:.85,lightAngle:145,interactive:!0}),u={radius:[0,1/0],blur:[0,1/0],refraction:[0,1/0],bevel:[.5,1/0],curvature:[.25,8],chroma:[0,1],saturation:[0,1/0],tint:[0,1],glow:[0,1],edgeHighlight:[0,1],lightAngle:[-1/0,1/0]};function f(o,i,c=a){const e={...c};for(const t of Object.keys(a))i[t]!==void 0&&(e[t]=i[t]);for(const[t,[s,l]]of Object.entries(u)){const r=e[t];if(!Number.isFinite(r)||r<s||r>l)throw new RangeError("Invalid liquidGlass option: "+t)}if(!["auto","content","backdrop","sampled","frost"].includes(e.mode))throw new TypeError('mode must be "auto", "content", "backdrop", "sampled", or "frost"');if(typeof e.interactive!="boolean")throw new TypeError("interactive must be a boolean");const n=e.backdrop;if(n!==null&&(!(n instanceof o.HTMLImageElement||n instanceof o.HTMLCanvasElement||n instanceof o.HTMLVideoElement)||n.ownerDocument!==o.document))throw new TypeError("backdrop must be an image, canvas, or video from the same document, or null");return e}export{f as resolveOptions};
1
+ const f=Object.freeze({mode:"auto",source:null,viewportSource:null,backdrop:null,radius:24,blur:2,refraction:18,bevel:24,curvature:2,chroma:0,saturation:1.35,tint:.14,glow:.23,edgeHighlight:.85,lightAngle:145,interactive:!0}),a={radius:[0,1/0],blur:[0,1/0],refraction:[0,1/0],bevel:[.5,1/0],curvature:[.25,8],chroma:[0,1],saturation:[0,1/0],tint:[0,1],glow:[0,1],edgeHighlight:[0,1],lightAngle:[-1/0,1/0]};function d(c,r,s=f){const o={...s},n=r.options;if(n!==void 0&&(!n||typeof n!="object"||Array.isArray(n)))throw new TypeError("options must be an object");for(const e of["mode","source","viewportSource","backdrop"])r[e]!==void 0&&(o[e]=r[e]);r.source!==void 0&&(o.viewportSource=o.backdrop=null);for(const e of[...Object.keys(a),"interactive"]){const t=n?.[e]!==void 0?n[e]:r[e];t!==void 0&&(o[e]=t)}for(const[e,[t,l]]of Object.entries(a)){const u=o[e];if(!Number.isFinite(u)||u<t||u>l)throw new RangeError("Invalid liquidGlass option: "+e)}if(!["auto","viewport","backdrop","sampled","frost","off"].includes(o.mode))throw new TypeError('mode must be "auto", "viewport", "backdrop", "sampled", "frost", or "off"');if(typeof o.interactive!="boolean")throw new TypeError("interactive must be a boolean");for(const e of["source","viewportSource"]){const t=o[e];if(t!==null&&typeof t!="string"&&(!(t instanceof c.HTMLElement)||t.ownerDocument!==c.document))throw new TypeError(e+" must be an ID, selector, same-document HTML element, or null")}const i=o.backdrop;if(i!==null&&typeof i!="string"&&(!(i instanceof c.HTMLElement)||i.ownerDocument!==c.document||!["img","video","canvas"].includes(i.localName)))throw new TypeError("backdrop must be a selector, a same-document image, video, canvas, or null");return o}export{d as resolveOptions};
@@ -1 +1 @@
1
- import{lensStrength as L}from"../optics.js";import{drawWebGl as V}from"./webgl.js";function z(s){const i=s.createElement("canvas");i.className="liquid-glass-backdrop",i.setAttribute("aria-hidden","true");const m=i.getContext("2d"),r=s.createElement("canvas"),a=r.getContext("2d");let p;function v(t,o,w){const{columns:e,rows:h,offsets:u,coverage:N,highlights:R}=o,{refraction:q,chroma:B,edgeHighlight:A}=w;if(!m||!a||!t.isConnected)return!1;const n=t.getBoundingClientRect(),l=i.getBoundingClientRect();if(!l.width||!l.height||!n.width||!n.height||n.right<=l.left||n.left>=l.right||n.bottom<=l.top||n.top>=l.bottom||t.localName==="img"&&(!t.complete||!t.naturalWidth)||t.localName==="canvas"&&(!t.width||!t.height)||t.localName==="video"&&(t.readyState<2||!t.videoWidth))return!1;(!p||i.width!==e||i.height!==h)&&(i.width=r.width=e,i.height=r.height=h,p=m.createImageData(e,h));const x=e/l.width,b=h/l.height,I=L(q,B,o.width,o.height),F=I*e/o.width,G=I*h/o.height;let k=n.left,D=n.top,M=n.width,C=n.height;if(t.localName!=="canvas"){const d=t.naturalWidth??t.videoWidth,f=t.naturalHeight??t.videoHeight,g=s.defaultView.getComputedStyle(t).objectFit;if(g==="cover"||g==="contain"){const W=(g==="cover"?Math.max:Math.min)(M/d,C/f),H=W*d,c=W*f;k+=(M-H)/2,D+=(C-c)/2,M=H,C=c}else if(g!=="fill")return!1}if(a.clearRect(0,0,e,h),a.save(),a.beginPath(),a.rect((n.left-l.left)*x,(n.top-l.top)*b,n.width*x,n.height*b),a.clip(),a.drawImage(t,(k-l.left)*x,(D-l.top)*b,M*x,C*b),a.restore(),V(s,r,o,I,w,m))return!0;let E;try{E=a.getImageData(0,0,e,h).data}catch(d){if(d.name!=="SecurityError")throw d;return r.width=e,!1}for(let d=0,f=0;d<h;d++)for(let g=0;g<e;g++,f++){const P=u[f*2]*F,W=u[f*2+1]*G,H=R[f]*A/255;for(let c=0;c<4;c++){const j=c===0?1-B:c===2?1+B:1,S=X(E,e,h,g+P*j,d+W*j,c);p.data[f*4+c]=c===3?S*N[f]/255:S+(255-S)*H}}return m.putImageData(p,0,0),!0}return{canvas:i,render:v}}function X(s,i,m,r,a,p){r=Math.max(0,Math.min(i-1,r)),a=Math.max(0,Math.min(m-1,a));const v=Math.floor(r),t=Math.floor(a),o=r-v,w=a-t,e=(t*i+v)*4+p,h=o?4:0,u=w?i*4:0,N=s[e]*(1-o)+s[e+h]*o,R=s[e+u]*(1-o)+s[e+u+h]*o;return N*(1-w)+R*w}export{z as makeBackdropLens};
1
+ import{drawWebGl as O}from"./webgl.js";function W(s,e,t){if(s.localName==="canvas")return t;const u=e.videoWidth??e.naturalWidth,d=e.videoHeight??e.naturalHeight;if(!u||!d)return null;const a=s.ownerDocument.defaultView.getComputedStyle(s).objectFit||"fill";if(a==="fill")return t;if(a!=="cover"&&a!=="contain")return null;const i=Math[a==="cover"?"max":"min"](t.width/u,t.height/d),g=u*i,l=d*i;return{left:t.left+(t.width-g)/2,top:t.top+(t.height-l)/2,width:g,height:l}}function H(s,e,t,u){const d=s.ownerDocument,a=d.defaultView,i=d.createElement("canvas");i.className="liquid-glass-sampled",i.setAttribute("aria-hidden","true");const g=i.getContext("2d"),l=d.createElement("canvas"),c=l.getContext("2d"),k=new a.AbortController,{signal:f}=k,n=e.localName==="video"?e:null;let h,p,v;const R=new a.ResizeObserver(t);R.observe(e);function E(){f.aborted||n.paused||n.ended||p!==void 0||v!==void 0||(n.requestVideoFrameCallback?p=n.requestVideoFrameCallback(()=>{p=void 0,u(),E()}):v=a.requestAnimationFrame(()=>{v=void 0,u(),E()}))}if(n){for(const b of["loadeddata","seeked","resize","emptied","pause","ended"])n.addEventListener(b,t,{signal:f});n.addEventListener("play",E,{signal:f}),E()}else e.addEventListener("load",t,{signal:f});const y=e.getRootNode();y.addEventListener("scroll",t,{capture:!0,passive:!0,signal:f}),y!==d&&d.addEventListener("scroll",t,{capture:!0,passive:!0,signal:f}),a.addEventListener("resize",t,{signal:f});function V(){return!n||n.readyState>=2?e:n.poster?(h?.src!==n.poster&&(h=new a.Image,n.crossOrigin!==null&&(h.crossOrigin=n.crossOrigin),h.addEventListener("load",t,{signal:f}),h.src=n.poster),h.complete?h:null):null}return{render(b,q){if(!g||!c||!e.isConnected)return!1;const N=V();if(!N||e.localName==="img"&&!e.complete||e.localName==="canvas"&&(!e.width||!e.height))return!1;const r=s.getBoundingClientRect(),o=e.getBoundingClientRect();if(!r.width||!r.height||!o.width||!o.height||r.right<=o.left||r.bottom<=o.top||r.left>=o.right||r.top>=o.bottom)return!1;const w=W(e,N,o);if(!w)return!1;const{columns:m,rows:C,strength:A}=b;(i.width!==m||i.height!==C||l.width!==m||l.height!==C)&&(i.width=l.width=m,i.height=l.height=C);const F=m/r.width,L=C/r.height;c.clearRect(0,0,m,C),c.save(),c.beginPath(),c.rect((o.left-r.left)*F,(o.top-r.top)*L,o.width*F,o.height*L),c.clip();try{c.drawImage(N,(w.left-r.left)*F,(w.top-r.top)*L,w.width*F,w.height*L)}catch(S){if(S.name!=="InvalidStateError")throw S;return!1}finally{c.restore()}return O(d,l,b,A,q,g)?(i.parentNode!==s&&s.prepend(i),!0):(l.width=m,!1)},hide(){i.remove()},dispose(){k.abort(),R.disconnect(),p!==void 0&&n.cancelVideoFrameCallback?.(p),v!==void 0&&a.cancelAnimationFrame(v),i.remove()}}}export{H as makeSampledLens};
@@ -1 +1 @@
1
- import{lensStrength as X}from"../optics.js";const Y="http://www.w3.org/2000/svg",K=new WeakMap,S={x:0,y:0,width:1,height:1};let W=0;function $(n){const{userAgentData:r,userAgent:t}=n.navigator;return r?.brands.some(({brand:s})=>s==="Chromium")||/\b(?:Chrome|Chromium)\//.test(t)?"blink":/Firefox\//.test(t)?"gecko":/AppleWebKit\//.test(t)?"webkit":"unknown"}function C(n,r){for(const[t,s]of Object.entries(r)){const e=String(s);n.getAttribute(t)!==e&&n.setAttribute(t,e)}return n}function I(n,r,t){return C(n.createElementNS(Y,r),t)}function z(n,r,t,s){if(!s)return{unit:1,xScale:1,yScale:1};if(n==="webkit"){const e=Math.min(r,t);return{unit:e,xScale:e/r,yScale:e/t}}return{unit:n==="gecko"?Math.hypot(r,t)/Math.SQRT2:r,xScale:1,yScale:1}}function J(n,r,t,s){K.has(n)||K.set(n,{entries:new Map,canvas:n.createElement("canvas")});const{entries:e,canvas:i}=K.get(n),c=[r,t,s.key].join("/");let a=e.get(c);if(a)return e.delete(c),e.set(c,a),a;const{columns:g,rows:h,offsets:p,coverage:l,highlights:b,width:f,height:o}=s,{xScale:d,yScale:y}=z(r,f,o,t);i.width=g,i.height=h;const v=i.getContext("2d");if(a={url:null,ready:Promise.resolve(null)},v){const R=v.createImageData(g,h),x=R.data;for(let m=0;m<l.length;m++){const u=4*m;x[u]=127.5+127.5*p[2*m]*d,x[u+1]=127.5+127.5*p[2*m+1]*y,x[u+2]=b[m],x[u+3]=t?l[m]:255}v.putImageData(R,0,0);const M=i.toDataURL(),O=new n.defaultView.Image;O.src=M,a.ready=O.decode().then(()=>(a.url=M,M),()=>null)}return e.size>=32&&e.delete(e.keys().next().value),e.set(c,a),a}function Z(n,r,t){const s=I(n,"filter",{...S,id:"liquid-glass-"+ ++W,primitiveUnits:r?"objectBoundingBox":"userSpaceOnUse","color-interpolation-filters":"sRGB"});function e(f,o){const d=I(n,f,o);return s.append(d),d}r&&e("feFlood",{...S,"flood-color":"rgb(128,128,0)",result:"neutral"});const i=e("feImage",{...S,preserveAspectRatio:"none",result:r?"shape":"offsets"});r&&e("feComposite",{...S,in:"shape",in2:"neutral",operator:"over",result:"offsets"});const c=t.blur?"frosted":"SourceGraphic",a=t.blur?e("feGaussianBlur",{in:"SourceGraphic",result:c}):null;function g(f){return e("feDisplacementMap",{in:c,in2:"offsets",xChannelSelector:"R",yChannelSelector:"G",result:f})}const h=[];if(t.chroma){const f=["red","green","blue"];for(const[o,d]of f.entries()){h.push(g(d));const y=Array(20).fill(0);y[o*6]=1,y[19]=1,e("feColorMatrix",{in:d,values:y.join(" "),result:d+"Only"})}e("feBlend",{in:"redOnly",in2:"greenOnly",mode:"screen",result:"redGreen"}),e("feBlend",{in:"redGreen",in2:"blueOnly",mode:"screen",result:"rgb"}),e("feComposite",{in:"rgb",in2:"green",operator:"in",result:"warped"})}else h.push(g("warped"));let p="warped";const l=t.saturation?e("feColorMatrix",{in:p,type:"saturate",result:"saturated"}):null;l&&(p="saturated");const b=t.rim?e("feColorMatrix",{...S,in:"offsets",result:"rim"}):null;return b&&(e("feComposite",{...S,in:"rim",in2:p,operator:"atop",result:"lit"}),p="lit"),r&&(e("feComposite",{...S,in:p,in2:"shape",operator:"in",result:"interior"}),e("feComposite",{in:"SourceGraphic",in2:"shape",operator:"out",result:"exterior"}),e("feComposite",{in:"interior",in2:"exterior",operator:"arithmetic",k2:1,k3:1})),{graph:s,map:i,displacements:h,blur:a,saturation:l,rim:b}}function ee(n,r,t){const s=n.ownerDocument,e=s.defaultView,i=t==="content",c=I(s,"svg",{width:0,height:0,"aria-hidden":"true"});c.style.cssText="position:absolute;overflow:hidden;pointer-events:none";const a=n.getRootNode();(a===s?s.body:a).append(c);const g=I(s,"defs",{});c.append(g);let h,p=0,l,b=!1,f,o,d,y,v,R=!1;function x(u=!1){u&&(o.graph.id="liquid-glass-"+ ++W),f.apply('url("#'+o.graph.id+'")')}function M(){if(!l)return;const{geometry:u,options:q}=f,{width:w,height:k,key:B}=u,{refraction:D,chroma:T,blur:j,saturation:U,edgeHighlight:E}=q,L=[l,B,D,T,i?j:0,i?U:1,i?E:0];if(y?.every((G,A)=>G===L[A])){x();return}y=L;const F={chroma:!!T,blur:i&&!!j,saturation:i&&U!==1,rim:i&&!!E},N=Object.values(F).join("/");d!==N&&(d=N,o=Z(s,i,F),g.replaceChildren(o.graph));const{unit:H}=z(r,w,k,i),P=2*X(D,T,w,k)/H;if(i){const G=18/w,A=18/k;C(o.graph,{x:-G,y:-A,width:1+2*G,height:1+2*A})}const Q=o.map.getAttribute("href")!==l;C(o.map,{href:l,width:i?1:w,height:i?1:k});for(const[G,A]of o.displacements.entries())C(A,{scale:P*(F.chroma?1+(G-1)*T:1)});o.blur&&C(o.blur,{stdDeviation:j/w+" "+j/k}),o.saturation&&C(o.saturation,{values:U}),o.rim&&C(o.rim,{values:"0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 "+E+" 0 0"});const V=i&&r==="webkit";x(V),V&&Q&&(e.clearTimeout(v),v=e.setTimeout(()=>x(!0),94))}function O(u,q,w){if(f={geometry:u,options:q,apply:w},h!==u.key){h=u.key,b=!1;const k=++p,B=J(s,r,i,u);B.url?l=B.url:B.ready.then(D=>{R||k!==p||(D?(l=D,M()):l||(b=!0,f.apply("")))})}b?w(""):M()}function m(){R=!0,e.clearTimeout(v),c.remove()}return{render:O,dispose:m}}export{$ as browserEngine,ee as makeSvgLens};
1
+ const y="http://www.w3.org/2000/svg",x=new WeakMap;let k=0;function q(t){const{userAgentData:s,userAgent:e}=t.navigator;return s?.brands.some(({brand:r})=>r==="Chromium")||/\b(?:Chrome|Chromium)\//.test(e)?"blink":/Firefox\//.test(e)?"gecko":/AppleWebKit\//.test(e)?"webkit":"unknown"}function w(t,s){for(const[e,r]of Object.entries(s)){const n=String(r);t.getAttribute(e)!==n&&t.setAttribute(e,n)}return t}function g(t,s,e){return w(t.createElementNS(y,s),e)}function v(t){const s=t.ownerDocument,e=g(s,"svg",{width:0,height:0,"aria-hidden":"true"});e.style.cssText="position:absolute;overflow:hidden;pointer-events:none";const r=g(s,"defs",{});e.append(r);const n=t.getRootNode();return(n===s?s.body:n).append(e),{root:e,defs:r}}function b(){return"liquid-glass-"+ ++k}function D(t,s){x.has(t)||x.set(t,{entries:new Map,canvas:t.createElement("canvas")});const{entries:e,canvas:r}=x.get(t),{key:n}=s;let o=e.get(n);if(o)return e.delete(n),e.set(n,o),o;const{columns:a,rows:i,offsets:u}=s;r.width=a,r.height=i;const l=r.getContext("2d");if(o={url:null,ready:Promise.resolve(null)},l){const c=l.createImageData(a,i),p=c.data;for(let d=0;d<a*i;d++){const h=4*d;p[h]=128+127*u[2*d],p[h+1]=128+127*u[2*d+1],p[h+3]=255}l.putImageData(c,0,0);const f=r.toDataURL(),m=new t.defaultView.Image;m.src=f,o.ready=m.decode().then(()=>(o.url=f,f),()=>null)}return e.size>=32&&e.delete(e.keys().next().value),e.set(n,o),o.ready.then(c=>{!c&&e.get(n)===o&&e.delete(n)}),o}function C(t,s){function e(o,a){const i=g(t.ownerDocument,o,a);return t.append(i),i}function r(o){return e("feDisplacementMap",{in:"SourceGraphic",in2:"offsets",xChannelSelector:"R",yChannelSelector:"G",result:o})}if(!s)return[r("warped")];const n=[];for(const[o,a]of["red","green","blue"].entries()){n.push(r(a));const i=Array(20).fill(0);i[o*6]=i[19]=1,e("feColorMatrix",{in:a,values:i.join(" "),result:a+"Only"})}return e("feBlend",{in:"redOnly",in2:"greenOnly",mode:"screen",result:"redGreen"}),e("feBlend",{in:"redGreen",in2:"blueOnly",mode:"screen",result:"rgb"}),e("feComposite",{in:"rgb",in2:"green",operator:"in",result:"warped"}),n}function M(t,s,e){const r=2*s/(1+e);for(const[n,o]of t.entries())w(o,{scale:r*(t.length===1?1:1+(n-1)*e)})}function R(t,s){let e,r=0;const n={url:null,key:null,failed:!1,requestMap:o,cancel:a};function o(i){if(e===i.key)return;e=i.key,n.failed=!1;const u=++r,l=D(t,i);if(l.url){n.url=l.url,n.key=i.key;return}l.ready.then(c=>{u===r&&(n.url=c,n.key=i.key,n.failed=!c,s())})}function a(){r++}return n}function A(t){const{root:s,defs:e}=v(t),r=R(t.ownerDocument,l);let n,o,a,i,u;function l(){const{geometry:c,options:p,apply:f}=n;if(r.failed){f("");return}if(!r.url||r.key!==c.key)return;const{width:m,height:d}=c,{chroma:h}=p;u!==!!h&&(u=!!h,o=g(t.ownerDocument,"filter",{id:b(),x:0,y:0,width:1,height:1,primitiveUnits:"userSpaceOnUse","color-interpolation-filters":"sRGB"}),a=g(t.ownerDocument,"feImage",{x:0,y:0,preserveAspectRatio:"none",result:"offsets"}),o.append(a),i=C(o,u),e.replaceChildren(o)),w(a,{href:r.url,width:m,height:d}),M(i,c.strength,h),f('url("#'+o.id+'")')}return{render(c,p,f){n={geometry:c,options:p,apply:f},r.requestMap(c),l()},dispose(){r.cancel(),s.remove()}}}export{C as appendRefraction,w as attrs,q as browserEngine,b as filterId,v as filterRoot,R as makeMapRequest,A as makeSvgLens,M as setDisplacement,g as svg};
@@ -0,0 +1 @@
1
+ import{lensGeometry as J}from"../optics.js";import{appendRefraction as K,attrs as k,filterId as D,filterRoot as N,makeMapRequest as Q,setDisplacement as X,svg as g}from"./svg.js";const R=new WeakMap,Y=8*1024*1024,I=4096;function O(i,n,o){let e=R.get(i);if(!e){const{style:t}=i,r=i.ownerDocument.defaultView.getComputedStyle(i).filter;e={value:t.getPropertyValue("filter"),priority:t.getPropertyPriority("filter"),base:r&&r!=="none"?r:"",lenses:new Map},R.set(i,e)}e.lenses.set(n,'url("#'+o+'")'),U(i,e)}function U(i,{base:n,lenses:o,priority:e}){const t=[n,...o.values()].filter(Boolean).join(" ");i.style.getPropertyValue("filter")!==t&&i.style.setProperty("filter",t,e)}function W(i,n){const o=R.get(i);o?.lenses.delete(n)&&(o.lenses.size?U(i,o):(i.style.setProperty("filter",o.value,o.priority),R.delete(i)))}function H(i,n,o){const e=i.getBoundingClientRect(),t=n.getBoundingClientRect();if(e.right<=t.left||e.bottom<=t.top||e.left>=t.right||e.top>=t.bottom)return null;const{offsetWidth:r,offsetHeight:f}=n;if(!r||!f||!t.width||!t.height||!e.width||!e.height)return null;if(o){const a=n.ownerDocument.defaultView.devicePixelRatio||1,w=Math.ceil(Math.max(r,t.width)*a),u=Math.ceil(Math.max(f,t.height)*a);if(w>I||u>I||w*u>Y)return null}const d=r/t.width,l=f/t.height;return{viewport:{x:0,y:0,width:r,height:f},lens:{x:(e.left-t.left)*d,y:(e.top-t.top)*l,width:e.width*d,height:e.height*l}}}function Z({width:i,height:n},o,e){const t=Math.ceil(e+2),r=Math.max(0,Math.floor(o.x-t)),f=Math.max(0,Math.floor(o.y-t)),d=Math.min(i,Math.ceil(o.x+o.width+t)),l=Math.min(n,Math.ceil(o.y+o.height+t));return{x:r/i,y:f/n,width:(d-r)/i,height:(l-f)/n}}function tt(i,n,o){const e={},t=n.ownerDocument,r=t.defaultView,{root:f,defs:d}=N(n),l=Q(t,T);let a,w,u,s,x,C,F,S,P,M;const c=o==="webkit";function T(y=H(i,n,c)){const{options:B,applied:p}=w;if(!y||l.failed||!n.isConnected||!i.isConnected){r.clearTimeout(M),W(n,e),u=void 0,p(!1);return}if(!l.url||l.key!==a.key)return;const{viewport:m,lens:h}=y,{chroma:v}=B,q=[...Object.values(m),...Object.values(h),a.key,v].join("/");if(q===u){p(!0);return}if(u=q,P!==!!v){P=!!v;const b=c?"objectBoundingBox":"userSpaceOnUse";s=g(t,"filter",{id:D(),filterUnits:b,primitiveUnits:b,"color-interpolation-filters":"sRGB"}),C=g(t,"feFlood",{"flood-color":"#808000",result:"neutral"}),x=g(t,"feImage",{preserveAspectRatio:"none",result:"lens"}),s.append(C,x,g(t,"feComposite",{in:"lens",in2:"neutral",operator:"over",result:"offsets"}));const L=s.childElementCount-1;F=K(s,P),c&&(S=[...s.children].slice(L),s.append(g(t,"feComposite",{in:"SourceGraphic",in2:"neutral",operator:"out",result:"outside"}),g(t,"feComposite",{in:"warped",in2:"outside",operator:"arithmetic",k2:1,k3:1}))),d.replaceChildren(s)}const z=x.getAttribute("href")!==l.url,{width:V,height:j}=m,A=c?{x:0,y:0,width:1,height:1}:m,E=c?{x:h.x/V,y:h.y/j,width:h.width/V,height:h.height/j}:h;k(s,A);const G=c?Z(m,h,a.strength):A;if(k(C,G),S)for(const b of S)k(b,G);k(x,{...E,href:l.url}),X(F,a.strength/(c?Math.max(V,j):1),v),c&&(s.id=D()),O(n,e,s.id),c&&z&&(r.clearTimeout(M),M=r.setTimeout(()=>{s.id=D(),O(n,e,s.id)},94)),p(!0)}return{render(y,B){w={options:y,applied:B};const p=H(i,n,c);if(p){const{width:m,height:h}=p.lens;a=J(m,h,y,a,"viewport"),l.requestMap(a)}T(p)},dispose(){l.cancel(),r.clearTimeout(M),W(n,e),f.remove()}}}export{tt as makeViewportLens};
@@ -1,28 +1,39 @@
1
- const u=new WeakMap,D=`
1
+ const x=new WeakMap,D=`
2
2
  attribute vec2 position;
3
3
  varying vec2 uv;
4
4
  void main() {
5
5
  gl_Position = vec4(position, 0.0, 1.0);
6
6
  uv = vec2(position.x + 1.0, 1.0 - position.y) * 0.5;
7
7
  }
8
- `,b=`
8
+ `,v=`
9
+ #ifdef GL_FRAGMENT_PRECISION_HIGH
10
+ precision highp float;
11
+ #else
9
12
  precision mediump float;
13
+ #endif
10
14
  varying vec2 uv;
11
15
  uniform sampler2D plate;
12
16
  uniform sampler2D lens;
13
17
  uniform vec2 strength;
14
18
  uniform float chroma;
15
- uniform float rim;
19
+ uniform vec4 plateRect;
20
+ uniform vec3 rounded;
16
21
 
17
22
  void main() {
23
+ if (rounded.z > 0.0) {
24
+ vec2 halfSize = rounded.xy * 0.5;
25
+ vec2 q = abs((uv - 0.5) * rounded.xy) - halfSize + rounded.z;
26
+ if (length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) > rounded.z) discard;
27
+ }
18
28
  vec4 map = texture2D(lens, uv);
19
29
  vec2 offset = (map.rg * 255.0 - 128.0) / 127.0 * strength;
20
- vec4 color = texture2D(plate, uv + offset);
30
+ vec2 point = plateRect.xy + uv * plateRect.zw;
31
+ offset *= plateRect.zw;
32
+ vec4 color = texture2D(plate, point + offset);
21
33
  if (chroma > 0.0) {
22
- color.r = texture2D(plate, uv + offset * (1.0 - chroma)).r;
23
- color.b = texture2D(plate, uv + offset * (1.0 + chroma)).b;
34
+ color.r = texture2D(plate, point + offset * (1.0 - chroma)).r;
35
+ color.b = texture2D(plate, point + offset * (1.0 + chroma)).b;
24
36
  }
25
- color.rgb = mix(color.rgb, vec3(1.0), map.b * rim);
26
- gl_FragColor = vec4(color.rgb, color.a * map.a);
37
+ gl_FragColor = color;
27
38
  }
28
- `;function v(e){const t=e.createProgram();for(const[a,n]of[[e.VERTEX_SHADER,D],[e.FRAGMENT_SHADER,b]]){const s=e.createShader(a);e.shaderSource(s,n),e.compileShader(s),e.attachShader(t,s),e.deleteShader(s)}if(e.linkProgram(t),!e.getProgramParameter(t,e.LINK_STATUS))return e.deleteProgram(t),null;e.useProgram(t);const r=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,r),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-1,-1,3,-1,-1,3]),e.STATIC_DRAW);const o=e.getAttribLocation(t,"position");e.enableVertexAttribArray(o),e.vertexAttribPointer(o,2,e.FLOAT,!1,0,0);for(const[a,n]of["plate","lens"].entries())e.activeTexture(e.TEXTURE0+a),e.bindTexture(e.TEXTURE_2D,e.createTexture()),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.uniform1i(e.getUniformLocation(t,n),a);return e.pixelStorei(e.UNPACK_COLORSPACE_CONVERSION_WEBGL,e.NONE),{strength:e.getUniformLocation(t,"strength"),chroma:e.getUniformLocation(t,"chroma"),rim:e.getUniformLocation(t,"rim")}}function L(e){const t=e.createElement("canvas"),r=t.getContext("webgl",{antialias:!1,depth:!1,stencil:!1,premultipliedAlpha:!1});if(!r)return null;let o=v(r),a;return t.addEventListener("webglcontextlost",n=>{n.preventDefault(),o=null}),t.addEventListener("webglcontextrestored",()=>{o=v(r),a=void 0}),function(s,m,T,{chroma:A,edgeHighlight:d},R){if(!o||r.isContextLost())return!1;const{width:_,height:x,columns:f,rows:E,offsets:h,coverage:p,highlights:U}=m;(t.width!==f||t.height!==E)&&(t.width=f,t.height=E),r.viewport(0,0,f,E),r.activeTexture(r.TEXTURE0);try{r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,s)}catch(c){if(c.name!=="SecurityError")throw c;return!1}if(a!==m){const c=new Uint8ClampedArray(f*E*4);for(let i=0;i<p.length;i++)c[4*i]=128+127*h[2*i],c[4*i+1]=128+127*h[2*i+1],c[4*i+2]=U[i],c[4*i+3]=p[i];r.activeTexture(r.TEXTURE1),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,f,E,0,r.RGBA,r.UNSIGNED_BYTE,c),a=m}return r.uniform2f(o.strength,T/_,T/x),r.uniform1f(o.chroma,A),r.uniform1f(o.rim,d),r.drawArrays(r.TRIANGLES,0,3),R.clearRect(0,0,f,E),R.drawImage(t,0,0),!0}}function P(e,t,r,o,a,n){return u.has(e)||u.set(e,L(e)),u.get(e)?.(t,r,o,a,n)??!1}export{P as drawWebGl};
39
+ `;function A(t){const e=t.createProgram();for(const[n,s]of[[t.VERTEX_SHADER,D],[t.FRAGMENT_SHADER,v]]){const i=t.createShader(n);t.shaderSource(i,s),t.compileShader(i),t.attachShader(e,i),t.deleteShader(i)}if(t.linkProgram(e),!t.getProgramParameter(e,t.LINK_STATUS))return t.deleteProgram(e),null;t.useProgram(e);const r=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,r),t.bufferData(t.ARRAY_BUFFER,new Float32Array([-1,-1,3,-1,-1,3]),t.STATIC_DRAW);const a=t.getAttribLocation(e,"position");t.enableVertexAttribArray(a),t.vertexAttribPointer(a,2,t.FLOAT,!1,0,0);for(const[n,s]of["plate","lens"].entries())t.activeTexture(t.TEXTURE0+n),t.bindTexture(t.TEXTURE_2D,t.createTexture()),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.uniform1i(t.getUniformLocation(e,s),n);t.pixelStorei(t.UNPACK_COLORSPACE_CONVERSION_WEBGL,t.NONE);const o=t.getUniformLocation(e,"plateRect");return t.uniform4f(o,0,0,1,1),{strength:t.getUniformLocation(e,"strength"),chroma:t.getUniformLocation(e,"chroma"),plateRect:o,rounded:t.getUniformLocation(e,"rounded")}}const U=new WeakMap;function l(t){let e=U.get(t);if(e)return e;const{columns:r,rows:a,offsets:o}=t;e=new Uint8ClampedArray(r*a*4);for(let n=0;n<r*a;n++)e[4*n]=128+127*o[2*n],e[4*n+1]=128+127*o[2*n+1],e[4*n+3]=255;return U.set(t,e),e}function w(t){const e=t.createElement("canvas"),r=e.getContext("webgl",{antialias:!1,depth:!1,stencil:!1,premultipliedAlpha:!1});if(!r)return null;let a=A(r),o;return e.addEventListener("webglcontextlost",n=>{n.preventDefault(),a=null}),e.addEventListener("webglcontextrestored",()=>{a=A(r),o=void 0}),function(s,i,_,{chroma:E},m){if(!a||r.isContextLost())return!1;const{width:c,height:p,columns:f,rows:T}=i;(e.width!==f||e.height!==T)&&(e.width=f,e.height=T),r.viewport(0,0,f,T),r.activeTexture(r.TEXTURE0);try{r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,s)}catch(R){if(R.name!=="SecurityError")throw R;return!1}o!==i.key&&(r.activeTexture(r.TEXTURE1),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,f,T,0,r.RGBA,r.UNSIGNED_BYTE,l(i)),o=i.key);const u=_/(1+E);return r.uniform2f(a.strength,u/c,u/p),r.uniform1f(a.chroma,E),r.drawArrays(r.TRIANGLES,0,3),m.clearRect(0,0,f,T),m.drawImage(e,0,0),!0}}function X(t,e,r,a,o,n){return x.has(t)||x.set(t,w(t)),x.get(t)?.(e,r,a,o,n)??!1}function I(t){const e=t.getContext("webgl",{alpha:!1,antialias:!1,depth:!1}),r=e&&A(e);if(!r)return null;const a=new WeakMap,o=e.createTexture();return e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,o),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,1,1,0,e.RGBA,e.UNSIGNED_BYTE,new Uint8Array([128,128,0,255])),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),function(s,i,_){if(e.isContextLost())return!1;e.activeTexture(e.TEXTURE0);try{e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,s)}catch(E){if(E.name==="SecurityError"||E.name==="InvalidStateError")return!1;throw E}e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,o),e.viewport(0,0,t.width,t.height),e.uniform4fv(r.plateRect,i),e.uniform2f(r.strength,0,0),e.uniform3f(r.rounded,0,0,0),e.drawArrays(e.TRIANGLES,0,3);for(const{viewport:E,plateRect:m,geometry:c,radius:p}of _){const{columns:f,rows:T,strength:u,width:R,height:h}=c;let d=a.get(c);d?e.bindTexture(e.TEXTURE_2D,d):(d=e.createTexture(),a.set(c,d),e.bindTexture(e.TEXTURE_2D,d),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,f,T,0,e.RGBA,e.UNSIGNED_BYTE,l(c))),e.viewport(...E),e.uniform4fv(r.plateRect,m),e.uniform2f(r.strength,u/R,u/h),e.uniform3f(r.rounded,R,h,p),e.drawArrays(e.TRIANGLES,0,3)}return!0}}export{X as drawWebGl,I as makeVideoCompositor};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikeofficial/liquid-glass-js",
3
- "version": "0.2.1",
3
+ "version": "0.3.1",
4
4
  "description": "Refractive, interactive glass surfaces for the web",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: liquid-glass-js
3
- description: Install and integrate the Liquid Glass JS library with plain JavaScript, Angular, React, or Vue. Use when a user requests this library or wants to tune its element, image, or live-page refraction.
3
+ description: Install and integrate the Liquid Glass JS library with plain JavaScript, Angular, React, or Vue. Use when a user requests this library or wants to tune its viewport or live-page refraction.
4
4
  ---
5
5
 
6
6
  ## Install
@@ -17,9 +17,9 @@ description: Install and integrate the Liquid Glass JS library with plain JavaSc
17
17
 
18
18
  Use an ordinary HTML host with geometry supplied by the app’s CSS and available `::before` and `::after` pseudo-elements. The adapters clean themselves up and treat a new options object as the complete configuration.
19
19
 
20
- ## Choose the surface to refract
20
+ ## Choose the source
21
21
 
22
- - `{ mode: "content" }` bends the host’s own rendered pixels across browsers. Put the artwork inside the element or paint it via its CSS background. Use a decorative layer when text must stay optically sharp.
23
- - `{ mode: "sampled", backdrop: media }` samples a same-origin or CORS-enabled image, canvas, or video behind the lens. Use an axis-aligned, borderless source and `object-fit: fill` or centered `cover` or `contain`. Call `glass.refresh()` after changing position or redrawing a canvas.
24
- - Automatic mode (the default) refracts live page pixels in Chromium and falls back to the supplied backdrop or CSS frost. Use `{ mode: "backdrop" }` without a source to select live page refraction explicitly. `{ mode: "frost" }` uses CSS directly. Use sampled or frost mode if CSP prevents the generated SVG-map image.
25
- - Use the target project’s own markup and geometry. Check focus, contrast, and the effect over detailed artwork. Run `mise run dev` in the library checkout for the playground and framework examples.
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 }`.
24
+ - 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.