@ikeofficial/liquid-glass-js 0.0.0-stage → 0.3.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mattia Bigi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,165 @@
1
- # Temporary Holding Version
1
+ # Liquid Glass JS
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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
+
5
+ ## Playground
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
+
13
+ ```sh
14
+ mise trust
15
+ mise install
16
+ mise run dev
17
+ ```
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.
20
+
21
+ In **Usage**, choose a renderer and a language to copy the corresponding layout and configuration. **Automatic** and **Viewport SVG** examples pass a `viewportSource`. Angular uses a template reference to the scroll pane.
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 example has no viewport source, so forcing **Viewport SVG** falls back to frost.
24
+
25
+ ## Install
26
+
27
+ ```sh
28
+ npm install @ikeofficial/liquid-glass-js
29
+ ```
30
+
31
+ The package includes minified ESM and CSS, TypeScript declarations, and an [agent skill](skills/liquid-glass-js/SKILL.md). Frameworks are optional peers of their respective adapters. Installing the core alone adds zero dependencies. The playground and build tools use separate development dependencies.
32
+
33
+ ## Publishing
34
+
35
+ The **Publish to npm** GitHub Actions workflow publishes `@ikeofficial/liquid-glass-js` to npmjs.com. Add an npm granular access token with permission to publish this package and bypass 2FA as the `NPM_TOKEN` repository secret under GitHub Settings → Secrets and variables → Actions. Do not commit the token. npm plans to remove direct publishing with granular tokens in January 2027; migrate to [trusted publishing](https://docs.npmjs.com/trusted-publishers/) before then.
36
+
37
+ Update the version in `package.json`, then run **Publish to npm** from the Actions tab. Each published npm version must be new. To build a local archive, run `mise run install` and `mise run pack`.
38
+
39
+ ## License
40
+
41
+ [MIT](LICENSE)
42
+
43
+ ## Plain JavaScript
44
+
45
+ ```js
46
+ import { liquidGlass } from "@ikeofficial/liquid-glass-js";
47
+ import "@ikeofficial/liquid-glass-js/style.css";
48
+
49
+ const item = document.querySelector("#item");
50
+ const glass = liquidGlass(item, { mode: "auto", viewportSource: "#feed", radius: 30 });
51
+
52
+ glass.update({ chroma: 0.2 });
53
+ glass.destroy();
54
+ ```
55
+
56
+ The call returns a controller. Reapplying to the same element updates the existing controller. `update(options)` merges options. Use `update(options, { replace: true })` to reset omitted options. Call `destroy()` when the element unmounts. Read `glass.renderer` for the active renderer or listen on the host for `liquidglass:rendererchange`.
57
+
58
+ For plain HTML, copy the `src/` folder from the repository and serve it over HTTP. Load `liquid-glass.css` with a stylesheet link and import `liquidGlass` from the folder’s `liquid-glass.js` in a module script.
59
+
60
+ ## Angular
61
+
62
+ Add `LiquidGlassDirective` to a standalone component’s imports and load the shared stylesheet globally, for example via your Angular workspace’s styles list. Angular 20 or later within the package’s peer range.
63
+
64
+ ```ts
65
+ import { Component } from "@angular/core";
66
+ import { LiquidGlassDirective } from "@ikeofficial/liquid-glass-js/angular";
67
+
68
+ @Component({
69
+ imports: [LiquidGlassDirective],
70
+ template: `
71
+ <div class="glass-shell">
72
+ <main #feed class="glass-source">Scrollable content</main>
73
+ <button class="glass-bar"
74
+ [liquidGlass]="{ mode: 'viewport', viewportSource: feed, radius: 24 }">
75
+ Continue
76
+ </button>
77
+ </div>
78
+ `,
79
+ styles: `
80
+ .glass-shell { position: relative; isolation: isolate; }
81
+ .glass-source { height: 24rem; overflow: auto; }
82
+ .glass-bar {
83
+ position: absolute; inset: 1rem 1rem auto; min-height: 3rem;
84
+ border: 0; background: transparent; color: inherit;
85
+ }
86
+ `,
87
+ })
88
+ export class Action {}
89
+ ```
90
+
91
+ Use `mode: 'auto'` with the same source to prefer native backdrop refraction. A selector such as `viewportSource: '#feed'` also works.
92
+
93
+ ## React
94
+
95
+ ```jsx
96
+ import { useLiquidGlass } from "@ikeofficial/liquid-glass-js/react";
97
+ import "@ikeofficial/liquid-glass-js/style.css";
98
+
99
+ export function Action() {
100
+ const ref = useLiquidGlass({ mode: "auto", radius: 22 });
101
+ return <button ref={ref}>Continue</button>;
102
+ }
103
+ ```
104
+
105
+ The hook returns a callback ref for a DOM element. In TypeScript, you can narrow it with `useLiquidGlass<HTMLButtonElement>()`.
106
+
107
+ ## Vue
108
+
109
+ ```vue
110
+ <script setup>
111
+ import { vLiquidGlass } from "@ikeofficial/liquid-glass-js/vue";
112
+ import "@ikeofficial/liquid-glass-js/style.css";
113
+ </script>
114
+
115
+ <template>
116
+ <button v-liquid-glass="{ mode: 'auto', radius: 22 }">Continue</button>
117
+ </template>
118
+ ```
119
+
120
+ The directive can also be registered globally with `app.directive("liquid-glass", vLiquidGlass)`.
121
+
122
+ ## Rendering modes
123
+
124
+ | Mode | Behavior |
125
+ | --- | --- |
126
+ | `auto` (default when `mode` is omitted) | Native backdrop refraction, then viewport SVG if a usable source is configured, then frosted glass |
127
+ | `viewport` | SVG refraction of the declared source. Uses frost when the source or filter is unavailable |
128
+ | `backdrop` | Native backdrop refraction where supported. Uses frost otherwise |
129
+ | `frost` | CSS blur, tint, and highlights |
130
+ | `off` | Disables glass and restores author styling |
131
+
132
+ `viewportSource` accepts a same-document HTML element or a selector resolved in the lens’s document or shadow root. Give the source a bounded, axis-aligned viewport and place the lens in an overlapping sibling layer. The source must be outside the lens subtree and the lens must be outside the source subtree. The source’s own scrolling moves the scene under the lens while the filter stays in place. Call `glass.refresh()` after changing their relative position or replacing a selector target without an options update.
133
+
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.
135
+
136
+ 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.
137
+
138
+ The `content` and `sampled` modes and the media `backdrop` option have been removed. For local artwork, position it in an HTML source layer behind the lens and use `viewportSource`. The native-control examples use Tailwind CSS v4 and the shared glass stylesheet.
139
+
140
+ ## Options
141
+
142
+ | Option | Default | Effect |
143
+ | --- | --- | --- |
144
+ | `mode` | `"auto"` | Auto, viewport, backdrop, frost, or off |
145
+ | `viewportSource` | `null` | HTML element or selector for the scroll pane or scene in auto and viewport modes |
146
+ | `radius` | 24 | Corner radius in CSS pixels. Set size with your CSS |
147
+ | `refraction` | 18 | Requested edge displacement in CSS pixels. Zero disables distortion |
148
+ | `bevel` | 24 | Width of the refracted edge in CSS pixels |
149
+ | `curvature` | 2 | Shape of the optical bevel, 0.25–8 |
150
+ | `chroma` | 0 | Color-channel spread, 0–1 |
151
+ | `blur` | 2 | Frost in CSS pixels |
152
+ | `saturation` | 1.35 | Color saturation multiplier |
153
+ | `tint` | 0.14 | Tint opacity, 0–1. Set `--liquid-glass-tint-rgb` as an RGB triplet |
154
+ | `glow` | 0.23 | Interior highlight opacity, 0–1 |
155
+ | `edgeHighlight` | 0.85 | Rim light intensity, 0–1 |
156
+ | `lightAngle` | 145 | Rim gradient angle in degrees |
157
+ | `interactive` | `true` | Pointer-tracking highlight |
158
+
159
+ ## Agent skill
160
+
161
+ Copy [`skills/liquid-glass-js`](skills/liquid-glass-js) into your project’s `.agents/skills/` directory. Invoke `$liquid-glass-js` and provide a checkout or tarball path.
162
+
163
+ ## References
164
+
165
+ The content-rendering approach draws on [Aave’s Building Glass for the Web](https://aave.com/design/building-glass-for-the-web) and the browser measurements reported by [gentpan/liquidglass](https://github.com/gentpan/liquidglass). The playground uses original generated photography.
@@ -0,0 +1,8 @@
1
+ import { type LiquidGlassOptions } from "@ikeofficial/liquid-glass-js";
2
+ import * as i0 from "@angular/core";
3
+ export declare class LiquidGlassDirective {
4
+ readonly liquidGlass: import("@angular/core").InputSignal<"" | LiquidGlassOptions | null>;
5
+ constructor();
6
+ static ɵfac: i0.ɵɵFactoryDeclaration<LiquidGlassDirective, never>;
7
+ static ɵdir: i0.ɵɵDirectiveDeclaration<LiquidGlassDirective, "[liquidGlass]", never, { "liquidGlass": { "alias": "liquidGlass"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
8
+ }
@@ -0,0 +1 @@
1
+ import{afterRenderEffect as o,DestroyRef as n,Directive as u,ElementRef as c,inject as r,input as d,NgZone as p}from"@angular/core";import{liquidGlass as m}from"@ikeofficial/liquid-glass-js";import*as e from"@angular/core";class s{liquidGlass=d("",...ngDevMode?[{debugName:"liquidGlass"}]:[]);constructor(){const{nativeElement:a}=r(c),l=r(p);let t;o({write:()=>{const i=this.liquidGlass()||{};l.runOutsideAngular(()=>{t?t.update(i,{replace:!0}):t=m(a,i)})}}),r(n).onDestroy(()=>t?.destroy())}static \u0275fac=e.\u0275\u0275ngDeclareFactory({minVersion:"12.0.0",version:"20.3.35",ngImport:e,type:s,deps:[],target:e.\u0275\u0275FactoryTarget.Directive});static \u0275dir=e.\u0275\u0275ngDeclareDirective({minVersion:"17.1.0",version:"20.3.35",type:s,isStandalone:!0,selector:"[liquidGlass]",inputs:{liquidGlass:{classPropertyName:"liquidGlass",publicName:"liquidGlass",isSignal:!0,isRequired:!1,transformFunction:null}},ngImport:e})}e.\u0275\u0275ngDeclareClassMetadata({minVersion:"12.0.0",version:"20.3.35",ngImport:e,type:s,decorators:[{type:u,args:[{selector:"[liquidGlass]",standalone:!0}]}],ctorParameters:()=>[],propDecorators:{liquidGlass:[{type:e.Input,args:[{isSignal:!0,alias:"liquidGlass",required:!1}]}]}});export{s as LiquidGlassDirective};
@@ -0,0 +1 @@
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}}
@@ -0,0 +1,45 @@
1
+ export type LiquidGlassMode = "auto" | "viewport" | "backdrop" | "frost" | "off";
2
+ export type LiquidGlassRenderer = "viewport" | "backdrop" | "frost" | "off";
3
+
4
+ export interface LiquidGlassOptions {
5
+ /** Auto (default) tries native backdrop, viewport SVG, then frost. */
6
+ mode?: LiquidGlassMode;
7
+ /** Viewport SVG source in auto or viewport mode. A selector resolves in the lens’s document or shadow root. */
8
+ viewportSource?: string | HTMLElement | null;
9
+ /** Uniform corner radius in CSS pixels. Defaults to 24. */
10
+ radius?: number;
11
+ /** Blur in CSS pixels. Defaults to 2. */
12
+ blur?: number;
13
+ /** Maximum edge displacement in CSS pixels. Defaults to 18. */
14
+ refraction?: number;
15
+ /** Width of the refractive edge in CSS pixels. Defaults to 24. */
16
+ bevel?: number;
17
+ /** Falloff exponent from 0.25 to 8. Defaults to 2. */
18
+ curvature?: number;
19
+ /** Chromatic spread from 0 to 1. Defaults to 0. */
20
+ chroma?: number;
21
+ /** Saturation multiplier. Defaults to 1.35. */
22
+ saturation?: number;
23
+ /** Tint opacity from 0 to 1. Defaults to 0.14. */
24
+ tint?: number;
25
+ /** Interior highlight opacity from 0 to 1. Defaults to 0.23. */
26
+ glow?: number;
27
+ /** Rim highlight intensity from 0 to 1. Defaults to 0.85. */
28
+ edgeHighlight?: number;
29
+ /** Rim gradient angle in degrees. Defaults to 145. */
30
+ lightAngle?: number;
31
+ /** Enable pointer-tracking highlights. Defaults to true. */
32
+ interactive?: boolean;
33
+ }
34
+
35
+ export interface LiquidGlassController {
36
+ /** The active renderer after the last scheduled paint. */
37
+ readonly renderer: LiquidGlassRenderer;
38
+ /** Merge changes, or reset omitted options to their defaults with replace. */
39
+ update(options: LiquidGlassOptions, behavior?: { replace?: boolean }): void;
40
+ /** Recheck the renderer and source geometry after changing their relative position. */
41
+ refresh(): void;
42
+ destroy(): void;
43
+ }
44
+
45
+ export function liquidGlass(element: HTMLElement, options?: LiquidGlassOptions): LiquidGlassController;
@@ -0,0 +1 @@
1
+ import{lensGeometry as Y}from"./optics.js";import{resolveOptions as N}from"./options.js";import{browserEngine as j,makeSvgLens as I}from"./renderers/svg.js";import{makeViewportLens as J}from"./renderers/viewport.js";const C=new WeakMap,y="liquid-glass";function $(t,F={}){const i=t?.ownerDocument?.defaultView;if(!i||!(t instanceof i.HTMLElement))throw new TypeError("liquidGlass requires an HTML element");const k=C.get(t);if(k)return k.update(F),k;let r=N(i,F);const P=j(i),B=P==="blink"&&i.CSS?.supports("backdrop-filter",'url("#glass")'),q=i.matchMedia("(prefers-reduced-motion: reduce)"),M=i.matchMedia("(prefers-reduced-transparency: reduce), (forced-colors: active)"),m=new Map,W=t.classList.contains(y),L=new i.ResizeObserver(u);let w,E,x,c=null,l=null,g=null,p,f="off",v=!1;function s(e,n){const o="--liquid-glass-"+e;t.style.getPropertyValue(o)!==String(n)&&(m.has(o)||m.set(o,[t.style.getPropertyValue(o),t.style.getPropertyPriority(o)]),t.style.setProperty(o,n))}function R(){for(const[e,[n,o]]of m)t.style.setProperty(e,n,o);m.clear()}function u(){!v&&r.mode!=="off"&&l===null&&(l=i.requestAnimationFrame(X))}function a(e,n=""){e!=="off"&&s("lens",e==="backdrop"?n:""),f!==e&&(f=e,i.queueMicrotask(()=>{!v&&f===e&&t.dispatchEvent(new i.CustomEvent("liquidglass:rendererchange",{detail:{renderer:e}}))}))}function b(){w?.dispose(),w=void 0}function H(e){(!(e.target instanceof i.Node)||!c?.contains(e.target))&&u()}function d(e){e!==c&&(E?.dispose(),E=void 0,c&&L.unobserve(c),!c&&e&&(i.addEventListener("scroll",H,!0),i.addEventListener("resize",u)),c=e,c&&L.observe(c),c||(i.removeEventListener("scroll",H,!0),i.removeEventListener("resize",u)))}function D(){const e=t.getRootNode();let n=r.viewportSource;if(typeof n=="string")try{n=e.querySelector(n)}catch{return null}return!(n instanceof i.HTMLElement)||n.getRootNode()!==e||n.contains(t)||t.contains(n)?null:n}function O(){const e=D();if(d(e),!e?.isConnected){a("frost");return}E??=J(t,e,P),f!=="viewport"&&a("frost");const n=r;E.render(r,o=>{r===n&&a(o?"viewport":"frost")})}function X(){l=null;const{mode:e,refraction:n}=r,{clientWidth:o,clientHeight:S}=t;if(M.matches||e==="frost"||!n||!t.isConnected||!o||!S){b(),d(null),a("frost");return}if(B&&(e==="auto"||e==="backdrop")){x=Y(o,S,r,x),w??=I(t);const A=r;w.render(x,r,G=>{r===A&&(G?(d(null),a("backdrop",G)):e==="auto"?O():(d(null),a("frost")))});return}b(),e==="viewport"||e==="auto"?O():(d(null),a("frost"))}function h(){p=void 0,r.mode!=="off"&&(s("light-x",""),s("light-y",""))}function T(e){r.mode==="off"||!r.interactive||q.matches||e.pointerType==="touch"||(p={x:e.clientX,y:e.clientY},g===null&&(g=i.requestAnimationFrame(()=>{if(g=null,!p)return;const{width:n,height:o,left:S,top:A}=t.getBoundingClientRect();!n||!o||(s("light-x",(p.x-S)/n*100+"%"),s("light-y",(p.y-A)/o*100+"%"))})))}function V(){if(r.mode==="off"){l!==null&&i.cancelAnimationFrame(l),l=null,p=void 0,b(),d(null),R(),t.classList.remove(y),a("off");return}t.classList.add(y),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||h(),f==="off"&&a("frost"),u()}const z={get renderer(){return f},update(e,{replace:n=!1}={}){v||(r=N(i,e,n?void 0:r),V())},refresh:u,destroy(){v||(v=!0,l!==null&&i.cancelAnimationFrame(l),g!==null&&i.cancelAnimationFrame(g),b(),d(null),L.disconnect(),t.removeEventListener("pointermove",T),t.removeEventListener("pointerleave",h),q.removeEventListener("change",h),M.removeEventListener("change",u),R(),W?t.classList.add(y):t.classList.remove(y),C.delete(t),f="off")}};return C.set(t,z),t.addEventListener("pointermove",T,{passive:!0}),t.addEventListener("pointerleave",h),q.addEventListener("change",h),M.addEventListener("change",u),L.observe(t),V(),z}export{$ as liquidGlass};
@@ -0,0 +1 @@
1
+ function A(a){const o=Math.max(0,Math.min(1,a));return o*o*(3-2*o)}function R(a,o,{radius:z,refraction:F,bevel:C,curvature:N},P){const i=Math.min(z,a/2,o/2),X=Math.min(C,a/2,o/2),r=X*(.45+.55*Math.min(1,.625*(F/X))),Y=Math.min(i,r),p=r-Y,j=.14+.035*N,G=.8*(1-j)/1.5,M=Math.min(F,r*G),H=[a,o,i,r,N,M].join("/");if(P?.key===H)return P;const W=Math.min(1,512/Math.max(a,o)),e=Math.max(1,Math.round(a*W)),l=Math.max(1,Math.round(o*W)),d=new Float32Array(e*l*2),D=a/e,E=o/l;for(let n=0;n<Math.ceil(l/2);n++){const s=i-(n+.5)*E,c=l-n-1;for(let t=0;t<Math.ceil(e/2);t++){let k=function(K,L,O,Q){const q=2*(K*e+L);d[q]=O*B,d[q+1]=Q*B};const m=i-(t+.5)*D,u=Math.max(0,m),h=Math.max(0,s),x=u&&h?Math.hypot(u,h):u+h,J=i-x-Math.min(Math.max(m,s),0),B=I(J,Math.max(-m,-s));if(!B)continue;const f=e-t-1,b=f===t?0:x?u/x:+(m>s),y=c===n?0:x?h/x:+(s>m);k(n,t,b,y),f!==t&&k(n,f,-b,y),c!==n&&k(c,t,b,-y),c!==n&&f!==t&&k(c,f,-b,-y)}}function I(n,s){if(n<=0||n>=r||!M)return 0;const c=p?Y+p*A(s/(2*p)):r;if(n>=c)return 0;const t=c*j;return Math.min(M,c*G)/M*A(n/t)*(1-A((n-t)/(c-t)))}return{width:a,height:o,columns:e,rows:l,offsets:d,strength:M,key:H}}export{R as lensGeometry};
@@ -0,0 +1 @@
1
+ const u=Object.freeze({mode:"auto",viewportSource: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}),s={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 l(r,i,a=u){const e={...a};for(const t of Object.keys(u))i[t]!==void 0&&(e[t]=i[t]);for(const[t,[c,f]]of Object.entries(s)){const n=e[t];if(!Number.isFinite(n)||n<c||n>f)throw new RangeError("Invalid liquidGlass option: "+t)}if(!["auto","viewport","backdrop","frost","off"].includes(e.mode))throw new TypeError('mode must be "auto", "viewport", "backdrop", "frost", or "off"');if(typeof e.interactive!="boolean")throw new TypeError("interactive must be a boolean");const o=e.viewportSource;if(o!==null&&typeof o!="string"&&(!(o instanceof r.HTMLElement)||o.ownerDocument!==r.document))throw new TypeError("viewportSource must be a selector, a same-document HTML element, or null");return e}export{l as resolveOptions};
@@ -0,0 +1 @@
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 D}from"../optics.js";import{appendRefraction as I,attrs as P,filterId as S,filterRoot as A,makeMapRequest as G,setDisplacement as W,svg as w}from"./svg.js";const v=new WeakMap;function M(i,n,t){let e=v.get(i);if(!e){const{style:l}=i,r=i.ownerDocument.defaultView.getComputedStyle(i).filter;e={value:l.getPropertyValue("filter"),priority:l.getPropertyPriority("filter"),base:r&&r!=="none"?r:"",lenses:new Map},v.set(i,e)}e.lenses.set(n,'url("#'+t+'")'),O(i,e)}function O(i,{base:n,lenses:t,priority:e}){const l=[n,...t.values()].filter(Boolean).join(" ");i.style.getPropertyValue("filter")!==l&&i.style.setProperty("filter",l,e)}function T(i,n){const t=v.get(i);t?.lenses.delete(n)&&(t.lenses.size?O(i,t):(i.style.setProperty("filter",t.value,t.priority),v.delete(i)))}function U(i,n){const t=i.getBoundingClientRect(),e=n.getBoundingClientRect();if(t.right<=e.left||t.bottom<=e.top||t.left>=e.right||t.top>=e.bottom)return null;const{offsetWidth:l,offsetHeight:r}=n;if(!l||!r||!e.width||!e.height||!t.width||!t.height)return null;const u=l/e.width,d=r/e.height;return{viewport:{x:0,y:0,width:l,height:r},lens:{x:(t.left-e.left)*u,y:(t.top-e.top)*d,width:t.width*u,height:t.height*d}}}function L(i,n,t){const e={},l=n.ownerDocument,r=l.defaultView,{root:u,defs:d}=A(n),s=G(l,B);let a,V,k,o,h,b,j,R,m;const x=t==="webkit";function B(p=U(i,n)){const{options:C,applied:f}=V;if(!p||s.failed||!n.isConnected||!i.isConnected){r.clearTimeout(m),T(n,e),k=void 0,f(!1);return}if(!s.url||s.key!==a.key)return;const{viewport:c,lens:g}=p,{chroma:y}=C,F=[...Object.values(c),...Object.values(g),a.key,y].join("/");if(F===k){f(!0);return}k=F,R!==!!y&&(R=!!y,o=w(l,"filter",{id:S(),filterUnits:"userSpaceOnUse",primitiveUnits:"userSpaceOnUse","color-interpolation-filters":"sRGB"}),b=w(l,"feFlood",{"flood-color":"#808000",result:"neutral"}),h=w(l,"feImage",{preserveAspectRatio:"none",result:"lens"}),o.append(b,h,w(l,"feComposite",{in:"lens",in2:"neutral",operator:"over",result:"offsets"})),j=I(o,R),d.replaceChildren(o));const q=h.getAttribute("href")!==s.url;P(o,c),P(b,c),P(h,{...g,href:s.url}),W(j,a.strength,y),x&&(o.id=S()),M(n,e,o.id),x&&q&&(r.clearTimeout(m),m=r.setTimeout(()=>{o.id=S(),M(n,e,o.id)},94)),f(!0)}return{render(p,C){V={options:p,applied:C};const f=U(i,n);if(f){const{width:c,height:g}=f.lens;a=D(c,g,p,a),s.requestMap(a)}B(f)},dispose(){s.cancel(),r.clearTimeout(m),T(n,e),u.remove()}}}export{L as makeViewportLens};
@@ -0,0 +1,4 @@
1
+ import { type RefCallback } from "react";
2
+ import { type LiquidGlassOptions } from "@ikeofficial/liquid-glass-js";
3
+ /** Attach the material to an ordinary DOM element using a callback ref. */
4
+ export declare function useLiquidGlass<T extends HTMLElement = HTMLElement>(options?: LiquidGlassOptions): RefCallback<T>;
@@ -0,0 +1 @@
1
+ "use client";import{useEffect as n,useRef as s,useState as c}from"react";import{liquidGlass as o}from"@ikeofficial/liquid-glass-js";function a(r){const[e,l]=c(null),t=s(null);return n(()=>{if(!e)return;const u=o(e);return t.current=u,()=>{u.destroy(),t.current=null}},[e]),n(()=>{t.current?.update(r??{},{replace:!0})},[e,r]),l}export{a as useLiquidGlass};
@@ -0,0 +1,3 @@
1
+ import type { ObjectDirective } from "vue";
2
+ import { type LiquidGlassOptions } from "@ikeofficial/liquid-glass-js";
3
+ export declare const vLiquidGlass: ObjectDirective<HTMLElement, LiquidGlassOptions | undefined>;
@@ -0,0 +1 @@
1
+ import{liquidGlass as r}from"@ikeofficial/liquid-glass-js";const t=new WeakMap,d={mounted(e,{value:o}){t.set(e,r(e,o))},updated(e,{value:o}){t.get(e)?.update(o??{},{replace:!0})},beforeUnmount(e){t.get(e)?.destroy(),t.delete(e)}};export{d as vLiquidGlass};
package/package.json CHANGED
@@ -1,6 +1,82 @@
1
1
  {
2
2
  "name": "@ikeofficial/liquid-glass-js",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.3.0",
4
+ "description": "Refractive, interactive glass surfaces for the web",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./build/core/liquid-glass.d.ts",
9
+ "default": "./build/core/liquid-glass.js"
10
+ },
11
+ "./style.css": "./build/core/liquid-glass.css",
12
+ "./angular": {
13
+ "types": "./build/angular/index.d.ts",
14
+ "default": "./build/angular/index.js"
15
+ },
16
+ "./react": {
17
+ "types": "./build/react/index.d.ts",
18
+ "default": "./build/react/index.js"
19
+ },
20
+ "./vue": {
21
+ "types": "./build/vue/index.d.ts",
22
+ "default": "./build/vue/index.js"
23
+ }
24
+ },
25
+ "types": "./build/core/liquid-glass.d.ts",
26
+ "files": [
27
+ "skills/liquid-glass-js",
28
+ "build"
29
+ ],
30
+ "sideEffects": [
31
+ "**/*.css"
32
+ ],
33
+ "keywords": [
34
+ "liquid-glass",
35
+ "backdrop-filter",
36
+ "refraction",
37
+ "vanilla-js"
38
+ ],
39
+ "peerDependencies": {
40
+ "@angular/core": ">=20 <23",
41
+ "react": "^18.0.0 || ^19.0.0",
42
+ "vue": "^3.3.0"
43
+ },
44
+ "peerDependenciesMeta": {
45
+ "@angular/core": {
46
+ "optional": true
47
+ },
48
+ "react": {
49
+ "optional": true
50
+ },
51
+ "vue": {
52
+ "optional": true
53
+ }
54
+ },
55
+ "devDependencies": {
56
+ "@angular/compiler": "20.3.35",
57
+ "@angular/compiler-cli": "20.3.35",
58
+ "@angular/core": "20.3.35",
59
+ "@angular/platform-browser": "20.3.35",
60
+ "@types/react": "19.3.0",
61
+ "esbuild": "^0.28.2",
62
+ "jsdom": "29.1.1",
63
+ "react": "19.3.1",
64
+ "react-dom": "19.3.1",
65
+ "rxjs": "7.8.2",
66
+ "tailwindcss": "4.3.3",
67
+ "typescript": "5.9.3",
68
+ "vue": "3.5.45"
69
+ },
70
+ "repository": {
71
+ "type": "git",
72
+ "url": "https://github.com/bigimattia/liquidglass-js.git"
73
+ },
74
+ "publishConfig": {
75
+ "registry": "https://registry.npmjs.org",
76
+ "access": "public"
77
+ },
78
+ "scripts": {
79
+ "prepack": "mise run build"
80
+ },
81
+ "license": "MIT"
82
+ }
@@ -0,0 +1,25 @@
1
+ ---
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 viewport or live-page refraction.
4
+ ---
5
+
6
+ ## Install
7
+
8
+ - Install the supplied `ikeofficial-liquid-glass-js-*.tgz` using the target project’s package manager. From a library checkout, run `mise run install` and `mise run pack` to build the archive in `dist/`. If neither source nor archive is available, ask for its location.
9
+ - Always load `@ikeofficial/liquid-glass-js/style.css`. In Angular, add it to the app’s global styles. For plain HTML without a bundler, copy the library’s `src/` folder to public assets, link `liquid-glass.css`, and import the ES module `liquid-glass.js`.
10
+
11
+ ## Attach to an existing element
12
+
13
+ - JavaScript uses `const glass = liquidGlass(element, options)` from `@ikeofficial/liquid-glass-js`. Call `glass.update(changes)` when tuning and `glass.destroy()` when unmounting.
14
+ - Angular imports the standalone `LiquidGlassDirective` from `@ikeofficial/liquid-glass-js/angular` and uses `[liquidGlass]="options"`.
15
+ - React imports `useLiquidGlass` from `@ikeofficial/liquid-glass-js/react` and passes its return value to the element’s `ref`.
16
+ - Vue imports `vLiquidGlass` from `@ikeofficial/liquid-glass-js/vue` and uses `v-liquid-glass="options"` on the element.
17
+
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
+
20
+ ## Choose the renderer
21
+
22
+ - Omitting `mode` selects `auto`. Use `{ viewportSource: source }` to try native backdrop refraction, then viewport SVG when the source is usable, then frost.
23
+ - `{ mode: "viewport", viewportSource: source }` selects viewport SVG explicitly. Supply a same-tree HTML element or selector. Use a bounded scroll pane and position the lens above it in a separate layer. In Angular, a template reference such as `#feed` can be passed as `viewportSource: feed`.
24
+ - `{ mode: "backdrop" }` selects native backdrop refraction when available. `{ mode: "frost" }` selects CSS frost directly. `{ mode: "off" }` disables the material and restores author styling.
25
+ - Call `glass.refresh()` after moving the lens relative to the source or replacing its selector target. Run `mise run dev` and use the **Usage** renderer picker to get a matching JavaScript, Angular, React, or Vue example. Verify the effect over live text and detailed artwork.